Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 47 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"deepmerge": "^4.3.1",
"fs-extra": "^11.3.0",
"glob": "^11.0.0",
"jsonc": "^2.0.0",
"parse-imports": "^2.2.1",
"smol-toml": "^1.3.1"
},
Expand Down
12 changes: 9 additions & 3 deletions src/utilities/locales.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jsonc } from 'jsonc'
import fs, { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
Expand All @@ -10,6 +11,8 @@ import { CleanOptions, LocaleContent, LocaleDiff, LocaleOptions, SyncOptions, Tr
const SCHEMA_DIRS = ['config', 'blocks', 'sections'] as const
const STOREFRONT_DIRS = ['blocks', 'layout', 'sections', 'snippets', 'templates'] as const



export async function getLocalesSource(source: string): Promise<LocaleContent> {
if (isUrl(source)) {
return fetchRemoteLocales(source)
Expand Down Expand Up @@ -45,7 +48,8 @@ function loadLocalLocales(dir: string): LocaleContent {
const filePath = path.join(dir, file)

try {
content[file] = JSON.parse(fs.readFileSync(filePath, 'utf8'))
const fileContent = fs.readFileSync(filePath, 'utf8')
content[file] = jsonc.parse(fileContent, { stripComments: true }) as Record<string, unknown>
} catch (error) {
throw new Error(`Failed to parse JSON file ${file}: ${error instanceof Error ? error.message : String(error)}`)
}
Expand Down Expand Up @@ -267,7 +271,8 @@ export async function removeUnreferencedStorefrontTranslations(themeDir: string,
function removeUnreferencedKeysFromFile(filePath: string, usedKeys: Set<string>, options?: LocaleOptions): void {
if (!fs.existsSync(filePath)) return

const content = JSON.parse(fs.readFileSync(filePath, 'utf8'))
const fileContent = fs.readFileSync(filePath, 'utf8')
const content = jsonc.parse(fileContent, { stripComments: true }) as Record<string, unknown>
if (!content || typeof content !== 'object') return

const flattenedContent = flattenObject(content)
Expand Down Expand Up @@ -330,7 +335,8 @@ export async function mergeLocaleFiles(
continue
}

const targetContent = JSON.parse(fs.readFileSync(targetPath, 'utf8'))
const targetFileContent = fs.readFileSync(targetPath, 'utf8')
const targetContent = jsonc.parse(targetFileContent, { stripComments: true }) as Record<string, unknown>
const diff = compareLocales(sourceContent, targetContent)

const mergedContent = mode === 'replace-existing'
Expand Down
3 changes: 2 additions & 1 deletion src/utilities/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jsonc } from 'jsonc'
import * as fs from 'node:fs'

import logger from './logger.js'
Expand All @@ -9,7 +10,7 @@ export function getManifest(path: string): Manifest {

if (fs.existsSync(path)) {
const manifestContent = fs.readFileSync(path, 'utf8')
const parsedContent = JSON.parse(manifestContent)
const parsedContent = jsonc.parse(manifestContent, { stripComments: true })
data.collections = parsedContent.collections || {}
data.files.assets = parsedContent.files?.assets || {}
data.files.snippets = parsedContent.files?.snippets || {}
Expand Down
5 changes: 3 additions & 2 deletions src/utilities/package-json.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { jsonc } from 'jsonc'
import fs from "node:fs";
import path from "node:path";

export function getNameFromPackageJson(dir: string): string|undefined {
const pkgPath = path.join(dir, 'package.json');
let name;
if (fs.existsSync(pkgPath)) {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
const pkg = jsonc.parse(fs.readFileSync(pkgPath, 'utf8'), { stripComments: true });
name = pkg.name;
}

Expand All @@ -16,7 +17,7 @@ export function getVersionFromPackageJson(dir: string): string|undefined {
const pkgPath = path.join(dir, 'package.json');
let version;
if (fs.existsSync(pkgPath)) {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
const pkg = jsonc.parse(fs.readFileSync(pkgPath, 'utf8'), { stripComments: true });
version = pkg.version;
}

Expand Down
5 changes: 3 additions & 2 deletions src/utilities/setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jsonc } from 'jsonc'
import path from 'node:path'

import { copyFileIfChanged, writeFileIfChanged } from './files.js'
Expand Down Expand Up @@ -57,7 +58,7 @@ export async function processSettingsSchema(
}

try {
const schema = JSON.parse(node.body)
const schema = jsonc.parse(node.body, { stripComments: true })
if (!Array.isArray(schema)) {
logger.warn(`Invalid schema format in ${setupFile}: Expected an array`)
return []
Expand All @@ -79,7 +80,7 @@ export async function processSettingsData(
}

try {
const data = JSON.parse(node.body)
const data = jsonc.parse(node.body, { stripComments: true })
if (typeof data !== 'object' || data === null) {
logger.warn(`Invalid settings data format in ${setupFile}: Expected an object`)
return {}
Expand Down