From 6df2563cb8a1151cacb716cca842a54f82c320b1 Mon Sep 17 00:00:00 2001 From: Cameron Barker Date: Thu, 16 Jan 2025 14:53:15 -0500 Subject: [PATCH] Move localization file size validation to core --- .changeset/pink-guests-clean.md | 5 +++ .../extensions/locales-configuration.test.ts | 37 ------------------- .../extensions/locales-configuration.ts | 19 ---------- 3 files changed, 5 insertions(+), 56 deletions(-) create mode 100644 .changeset/pink-guests-clean.md diff --git a/.changeset/pink-guests-clean.md b/.changeset/pink-guests-clean.md new file mode 100644 index 00000000000..44d10fe44dd --- /dev/null +++ b/.changeset/pink-guests-clean.md @@ -0,0 +1,5 @@ +--- +'@shopify/app': patch +--- + +Remove localization file size validations from the CLI and move them into Shopify's backend. diff --git a/packages/app/src/cli/utilities/extensions/locales-configuration.test.ts b/packages/app/src/cli/utilities/extensions/locales-configuration.test.ts index 2e261d3c2c2..3966264ec5c 100644 --- a/packages/app/src/cli/utilities/extensions/locales-configuration.test.ts +++ b/packages/app/src/cli/utilities/extensions/locales-configuration.test.ts @@ -41,24 +41,6 @@ describe('loadLocalesConfig', () => { }) }) - test('Throws if one locale is too big', async () => { - await inTemporaryDirectory(async (tmpDir: string) => { - // Given - const localesPath = joinPath(tmpDir, 'locales') - const enDefault = joinPath(localesPath, 'en.default.json') - const es = joinPath(localesPath, 'es.json') - - await mkdir(localesPath) - await writeFile(enDefault, JSON.stringify({hello: 'Hello'})) - const bigArray = new Array(6000).fill('a') - await writeFile(es, JSON.stringify(bigArray)) - - // When - const got = loadLocalesConfig(tmpDir, 'checkout_ui') - await expect(got).rejects.toThrow(/Error loading checkout_ui/) - }) - }) - test('Throws if there are no defaults', async () => { await inTemporaryDirectory(async (tmpDir: string) => { // Given @@ -92,23 +74,4 @@ describe('loadLocalesConfig', () => { await expect(got).rejects.toThrow(/Error loading checkout_ui/) }) }) - - test('Throws if bundle is too big', async () => { - await inTemporaryDirectory(async (tmpDir: string) => { - // Given - const localesPath = joinPath(tmpDir, 'locales') - const en = joinPath(localesPath, 'en.default.json') - const es = joinPath(localesPath, 'es.json') - - await mkdir(localesPath) - const bigArray = JSON.stringify(new Array(4000).fill('a')) - - await writeFile(en, JSON.stringify(bigArray)) - await writeFile(es, JSON.stringify(bigArray)) - - // When - const got = loadLocalesConfig(tmpDir, 'checkout_ui') - await expect(got).rejects.toThrow(/Error loading checkout_ui/) - }) - }) }) diff --git a/packages/app/src/cli/utilities/extensions/locales-configuration.ts b/packages/app/src/cli/utilities/extensions/locales-configuration.ts index 7ff92dc83a9..c15c1d4d727 100644 --- a/packages/app/src/cli/utilities/extensions/locales-configuration.ts +++ b/packages/app/src/cli/utilities/extensions/locales-configuration.ts @@ -3,15 +3,11 @@ import {glob} from '@shopify/cli-kit/node/fs' import {AbortError, BugError} from '@shopify/cli-kit/node/error' import fs from 'fs' -const L10N_FILE_SIZE_LIMIT = 20 * 1024 -const L10N_BUNDLE_SIZE_LIMIT = 256 * 1024 - export async function loadLocalesConfig(extensionPath: string, extensionIdentifier: string) { const localesPaths = await glob(joinPath(extensionPath, 'locales/*.json')) if (localesPaths.length === 0) return {} // Bundle validations - const totalBundleSize = bundleSize(localesPaths) const defaultLanguageCode = findDefaultLocale(localesPaths) if (defaultLanguageCode.length === 0) @@ -26,20 +22,9 @@ export async function loadLocalesConfig(extensionPath: string, extensionIdentifi `There must be one (and only one) locale identified as the default locale: e.g. "en.default.json"`, ) - if (totalBundleSize > L10N_BUNDLE_SIZE_LIMIT) - throw new AbortError( - `Error loading ${extensionIdentifier}`, - `Total size of all locale files must be less than ${L10N_BUNDLE_SIZE_LIMIT}`, - ) - // Locale validations for (const locale of localesPaths) { const size = fs.statSync(locale).size - if (size > L10N_FILE_SIZE_LIMIT) - throw new AbortError( - `Error loading ${extensionIdentifier}`, - `Locale file ${locale} size must be less than ${L10N_FILE_SIZE_LIMIT}`, - ) if (size === 0) throw new AbortError(`Error loading ${extensionIdentifier}`, `Locale file ${locale} can't be empty`) } @@ -64,10 +49,6 @@ function getAllLocales(localesPath: string[]) { return all } -function bundleSize(localesPaths: string[]) { - return localesPaths.map((locale) => fs.statSync(locale).size).reduce((acc, size) => acc + size, 0) -} - function failIfUnset(value: T | undefined, message: string) { if (value === undefined) { throw new BugError(message)