Skip to content

feat(global-fields): switch to per-file export/import format#307

Merged
cs-raj merged 4 commits into
v2-devfrom
enhc/DX-9464
Jul 24, 2026
Merged

feat(global-fields): switch to per-file export/import format#307
cs-raj merged 4 commits into
v2-devfrom
enhc/DX-9464

Conversation

@cs-raj

@cs-raj cs-raj commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Global fields are now exported as individual {uid}.json files instead of a single globalfields.json array
  • Import reads the directory and loads all per-file schemas using readGlobalFieldSchemas
  • Audit cross-reference validation updated to use the same directory-scan approach
  • Output format now consistent with how content types are handled

Background

Previously, all global fields were collected into a single globalfields.json array file during export. This created a monolithic file that grew unbounded and made partial reads, diffs, and targeted lookups impractical. The new per-file format stores each global field as global_fields/{uid}.json, making the export directory self-describing and consistent with the content types module.

Changes

Export (contentstack-export)

File Change
src/export/modules/global-fields.ts Removed bulk array accumulation; each field now written to {uid}.json immediately in sanitizeAttribs
src/config/index.ts fileName retained for type compatibility; comment clarifies it is not used at runtime

Import (contentstack-import)

File Change
src/import/modules/global-fields.ts Replaced fsUtil.readFile(fileName) with readGlobalFieldSchemas(dirPath)
src/import/modules/content-types.ts Same replacement for the global field pre-load in analyzeImportData; added globalfields.json to the content-types directory ignore list to prevent stale files being picked up as content types
src/config/index.ts fileName comment updated

Import Setup (contentstack-import-setup)

File Change
src/config/index.ts fileName comment updated

Audit (contentstack-audit)

File Change
src/audit-base-command.ts getCtAndGfSchema now calls readGlobalFieldSchemas(gfDirPath) instead of reading a single JSON file; removed unused readFileSync import
src/config/index.ts fileName comment updated

Behaviour

Scenario Before After
Export output global_fields/globalfields.json (array of all fields) global_fields/{uid}.json per field
Import input Single array file read via fsUtil.readFile Directory scan via readGlobalFieldSchemas
Audit input Single array file read via fs.readFileSync Directory scan via readGlobalFieldSchemas
Empty stack export Wrote empty [] array file Writes nothing (directory created but empty)

Dependencies

Requires readGlobalFieldSchemas exported from @contentstack/cli-utilities — available in the companion PR to the cli repo. Run npm run setup from the workspace root before type-checking.

Test plan

  • Export a stack with global fields — verify global_fields/ contains individual {uid}.json files
  • Export a stack with no global fields — verify global_fields/ directory is created but empty
  • Import from a per-file export — verify all global fields are created correctly
  • Run cm:stacks:audit — verify global field cross-references resolve correctly
  • npx tsc --noEmit passes in all four packages after npm run setup

🤖 Generated with Claude Code

Replaces the bulk-array globalfields.json export with individual {uid}.json
files per global field, consistent with how content types are handled.

Export writes each global field to global_fields/{uid}.json instead of
collecting all into a single array file. Import and content-types modules
now use readGlobalFieldSchemas to scan the directory and read all per-file
schemas. The audit base command is updated to use the same function when
loading global field schemas for cross-reference validation.

The globalfields.json fileName config values are retained for type
compatibility but are no longer read or written at runtime.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cs-raj
cs-raj requested a review from a team as a code owner July 22, 2026 19:37
@github-actions

Copy link
Copy Markdown

🔒 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 3 57 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

⚠️ Warning: The following vulnerabilities have exceeded their SLA thresholds (days since publication).

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 1 90 / 365 days ⚠️ Warning
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 57
  • Medium without fixes: 1
  • Low without fixes: 0

⚠️ BUILD PASSED WITH WARNINGS - SLA breaches detected for issues without available fixes

Consider reviewing these vulnerabilities when fixes become available.

@github-actions

Copy link
Copy Markdown

🔒 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 3 57 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

⚠️ Warning: The following vulnerabilities have exceeded their SLA thresholds (days since publication).

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 1 90 / 365 days ⚠️ Warning
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 57
  • Medium without fixes: 1
  • Low without fixes: 0

⚠️ BUILD PASSED WITH WARNINGS - SLA breaches detected for issues without available fixes

Consider reviewing these vulnerabilities when fixes become available.

harshitha-cstk
harshitha-cstk previously approved these changes Jul 23, 2026
netrajpatel
netrajpatel previously approved these changes Jul 23, 2026
…json stubs, add per-uid file assertions across export/import/audit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cs-raj
cs-raj dismissed stale reviews from netrajpatel and harshitha-cstk via 471180b July 23, 2026 09:56
@github-actions

Copy link
Copy Markdown

🔒 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 3 57 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

⚠️ Warning: The following vulnerabilities have exceeded their SLA thresholds (days since publication).

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 1 90 / 365 days ⚠️ Warning
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 57
  • Medium without fixes: 1
  • Low without fixes: 0

⚠️ BUILD PASSED WITH WARNINGS - SLA breaches detected for issues without available fixes

Consider reviewing these vulnerabilities when fixes become available.

@github-actions

Copy link
Copy Markdown

🔒 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 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

⚠️ Warning: The following vulnerabilities have exceeded their SLA thresholds (days since publication).

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 1 90 / 365 days ⚠️ Warning
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 0
  • Medium without fixes: 1
  • Low without fixes: 0

⚠️ BUILD PASSED WITH WARNINGS - SLA breaches detected for issues without available fixes

Consider reviewing these vulnerabilities when fixes become available.

@cs-raj
cs-raj merged commit 79af654 into v2-dev Jul 24, 2026
9 of 11 checks passed
@cs-raj
cs-raj deleted the enhc/DX-9464 branch July 24, 2026 06:04
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.

4 participants