Skip to content

fix(import): align import with single-branch export, import; path resolution and target branch handling#36

Open
cs-raj wants to merge 1 commit intov2-devfrom
enhc/DX-5171
Open

fix(import): align import with single-branch export, import; path resolution and target branch handling#36
cs-raj wants to merge 1 commit intov2-devfrom
enhc/DX-5171

Conversation

@cs-raj
Copy link
Contributor

@cs-raj cs-raj commented Mar 17, 2026

Single-branch export layout and import path/branch handling

Summary

  • Export: Ensures a single-branch export layout: content is written directly under the export directory (no per-branch subfolders). branches.json is written at the export root. Variants export uses the same base path so variant data lives at the export root.
  • Import: Path resolution no longer uses branches.json to set the target branch. The target branch is determined only by --branch / --branch-alias or by defaulting from the target stack. Stack client is created with branch_uid whenever a target branch is set so all API calls (including variants) use the correct branch.
  • Variants: Export already uses the same base path as the main export (branchDir ?? exportDir). Import uses the main import’s contentDir, backupDir, and branchName; no path or branch logic in the variants package.

Background

  • Export now writes a single branch’s content at the export root (no <path>/main, <path>/dev). branches.json at root lists branch metadata (e.g. the exported branch or all stack branches).
  • Import previously could set branchName from branches.json (source stack), which is wrong when importing into another stack. The target branch must come only from --branch / --branch-alias or the target stack default.

Changes

1. Export (contentstack-export)

  • Single-branch layout: Content is written directly under the export directory. branchDir is set to exportDir so there are no per-branch subfolders.
  • Path usage: Export modules and path helpers use branchDir ?? exportDir so all content (stack, entries, assets, etc.) is written at the same root.
  • branches.json: Still written at the export root by setup-branches (one or all branches). Used only for metadata; not used by import to choose the target branch.

2. Variants export (contentstack-variants)

  • Base path: All variant export modules (attributes, audiences, events, experiences, projects, variant-entries) use exportConfig.branchDir ?? exportConfig.exportDir (or equivalent) so variant data is written at the same export root as the rest of the stack.
  • Alignment: With main export setting branchDir = exportDir, variant export writes under that root with no branch subfolders.

3. Import path resolution (contentstack-import)

  • Path resolution: No longer reads branches.json or calls branch selection. Resolved path is always the user-provided content directory (export root). contentDir (and branchDir where used) is set from this resolved path.
  • Target branch: importConfig.branchName is never set from path resolution. It is set only from --branch / --branch-alias in config or from setupBranchConfig() (target stack, e.g. main).
  • Cleanup: Unused imports related to branch selection (e.g. askBranchSelection, readFile in path resolver) removed if applicable.

4. Stack client and branch_uid (contentstack-import)

  • Before: Stack client was recreated with branch_uid only when both branchAlias and branchName were set (e.g. after --branch-alias). Using only --branch or the default branch did not set branch_uid.
  • After: Stack client is recreated with branch_uid: this.importConfig.branchName whenever branchName is set (from --branch, --branch-alias, or default). All import API calls, including variant-entries, use the intended target branch.

5. Variants import (contentstack-variants)

  • No code changes required. Variants import receives ImportConfig from the main import (contentDir, backupDir, branchName). It uses:
    • contentDir for exported variant/personalize content (projects, experiences, events, audiences, attributes).
    • backupDir for mapper and entries data.
    • branchName for API headers (e.g. variant-entries).
  • Behavior is correct for the new export layout as long as the main import sets these from the resolved path and target branch.

Files touched

  • Export: cli-plugins/packages/contentstack-export/ – single-branch layout, path helpers, branchDir usage, setup-branches / module-exporter (as changed in your branch).
  • Variants export: cli-plugins/packages/contentstack-variants/src/export/ – use of branchDir ?? exportDir (or equivalent) for all modules; no new branch subfolders.
  • Import: cli-plugins/packages/contentstack-import/src/utils/import-path-resolver.ts, src/import/module-importer.ts – path resolution, no branch selection, stack client branch_uid when branchName is set.
  • Variants import: No file changes; verified to use contentDir / backupDir / branchName from main import.

(Add or remove specific file paths to match your actual staged changes.)

Testing

  • Export: Run export with and without --branch. Confirm content and branches.json are at the export root and variant export data is under the same root.
  • Import: With --data-dir pointing at that export root, run import with --branch, with --branch-alias, and with neither. Confirm path resolves to the root, no branch prompt from branches.json, and content is imported into the expected target branch (including variant-entries).
  • Variants: Export then import a stack with personalize/variants; confirm variant and personalize data is read from the correct paths and uses the chosen target branch.

@github-actions
Copy link

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 0 25 ✅ Passed
🟡 Medium Severity 0 0 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

✅ BUILD PASSED - All security checks passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants