1+ import { jsonc } from 'jsonc'
12import fs , { mkdtempSync , rmSync } from 'node:fs'
23import { tmpdir } from 'node:os'
34import path from 'node:path'
@@ -10,6 +11,8 @@ import { CleanOptions, LocaleContent, LocaleDiff, LocaleOptions, SyncOptions, Tr
1011const SCHEMA_DIRS = [ 'config' , 'blocks' , 'sections' ] as const
1112const STOREFRONT_DIRS = [ 'blocks' , 'layout' , 'sections' , 'snippets' , 'templates' ] as const
1213
14+
15+
1316export async function getLocalesSource ( source : string ) : Promise < LocaleContent > {
1417 if ( isUrl ( source ) ) {
1518 return fetchRemoteLocales ( source )
@@ -45,7 +48,8 @@ function loadLocalLocales(dir: string): LocaleContent {
4548 const filePath = path . join ( dir , file )
4649
4750 try {
48- content [ file ] = JSON . parse ( fs . readFileSync ( filePath , 'utf8' ) )
51+ const fileContent = fs . readFileSync ( filePath , 'utf8' )
52+ content [ file ] = jsonc . parse ( fileContent , { stripComments : true } ) as Record < string , unknown >
4953 } catch ( error ) {
5054 throw new Error ( `Failed to parse JSON file ${ file } : ${ error instanceof Error ? error . message : String ( error ) } ` )
5155 }
@@ -267,7 +271,8 @@ export async function removeUnreferencedStorefrontTranslations(themeDir: string,
267271function removeUnreferencedKeysFromFile ( filePath : string , usedKeys : Set < string > , options ?: LocaleOptions ) : void {
268272 if ( ! fs . existsSync ( filePath ) ) return
269273
270- const content = JSON . parse ( fs . readFileSync ( filePath , 'utf8' ) )
274+ const fileContent = fs . readFileSync ( filePath , 'utf8' )
275+ const content = jsonc . parse ( fileContent , { stripComments : true } ) as Record < string , unknown >
271276 if ( ! content || typeof content !== 'object' ) return
272277
273278 const flattenedContent = flattenObject ( content )
@@ -330,7 +335,8 @@ export async function mergeLocaleFiles(
330335 continue
331336 }
332337
333- const targetContent = JSON . parse ( fs . readFileSync ( targetPath , 'utf8' ) )
338+ const targetFileContent = fs . readFileSync ( targetPath , 'utf8' )
339+ const targetContent = jsonc . parse ( targetFileContent , { stripComments : true } ) as Record < string , unknown >
334340 const diff = compareLocales ( sourceContent , targetContent )
335341
336342 const mergedContent = mode === 'replace-existing'
0 commit comments