From 8e4d98e001eb7dabf5a52315e1b930df276ee266 Mon Sep 17 00:00:00 2001 From: harshitha-cstk Date: Tue, 25 Aug 2026 11:26:56 +0530 Subject: [PATCH 1/2] fix(cli-utilities): read aggregate globalfields.json in readGlobalFieldSchemas readGlobalFieldSchemas ignored the aggregate global_fields/globalfields.json and only read per-uid files, so aggregate-format exports returned 0 global fields. This caused the audit to strip all global-field references from content types, global fields to never import, and content-types/entries to fail with "The referenced Global Field does not exist" (plus image-preset data loss). Now prefer the aggregate globalfields.json when present and fall back to per-uid files, so both export formats load correctly. Shared by the audit and the import global-fields/content-types modules. Fixes DX-7312 Co-Authored-By: Claude Opus 4.8 --- .../src/content-type-utils.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/contentstack-utilities/src/content-type-utils.ts b/packages/contentstack-utilities/src/content-type-utils.ts index 92cfd7377c..0f1292d1c7 100644 --- a/packages/contentstack-utilities/src/content-type-utils.ts +++ b/packages/contentstack-utilities/src/content-type-utils.ts @@ -13,6 +13,20 @@ export function readGlobalFieldSchemas( dirPath: string, ignoredFiles: string[] = DEFAULT_GF_IGNORED_FILES, ): Record[] { + // Global fields may be exported either as a single aggregate file + // (global_fields/globalfields.json, an array) or as one file per uid. + // Prefer the aggregate when present; otherwise fall back to per-uid files. + const aggregatePath = pResolve(dirPath, 'globalfields.json'); + if (existsSync(aggregatePath)) { + try { + const parsed = JSON.parse(readFileSync(aggregatePath, 'utf8')); + if (Array.isArray(parsed)) { + return parsed as Record[]; + } + } catch (error) { + console.warn('Failed to read aggregate global fields file globalfields.json:', error); + } + } return readContentTypeSchemas(dirPath, ignoredFiles); } From 6ffb1c479effb8756afc3e518ad96e7b379a0295 Mon Sep 17 00:00:00 2001 From: harshitha-cstk Date: Tue, 25 Aug 2026 12:18:43 +0530 Subject: [PATCH 2/2] revert --- .../src/content-type-utils.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/packages/contentstack-utilities/src/content-type-utils.ts b/packages/contentstack-utilities/src/content-type-utils.ts index 0f1292d1c7..92cfd7377c 100644 --- a/packages/contentstack-utilities/src/content-type-utils.ts +++ b/packages/contentstack-utilities/src/content-type-utils.ts @@ -13,20 +13,6 @@ export function readGlobalFieldSchemas( dirPath: string, ignoredFiles: string[] = DEFAULT_GF_IGNORED_FILES, ): Record[] { - // Global fields may be exported either as a single aggregate file - // (global_fields/globalfields.json, an array) or as one file per uid. - // Prefer the aggregate when present; otherwise fall back to per-uid files. - const aggregatePath = pResolve(dirPath, 'globalfields.json'); - if (existsSync(aggregatePath)) { - try { - const parsed = JSON.parse(readFileSync(aggregatePath, 'utf8')); - if (Array.isArray(parsed)) { - return parsed as Record[]; - } - } catch (error) { - console.warn('Failed to read aggregate global fields file globalfields.json:', error); - } - } return readContentTypeSchemas(dirPath, ignoredFiles); }