Skip to content

Commit 19173f7

Browse files
committed
Remove file size validations from cli and replace in core
1 parent ed55fc7 commit 19173f7

File tree

2 files changed

+0
-56
lines changed

2 files changed

+0
-56
lines changed

packages/app/src/cli/utilities/extensions/locales-configuration.test.ts

-37
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,6 @@ describe('loadLocalesConfig', () => {
4141
})
4242
})
4343

44-
test('Throws if one locale is too big', async () => {
45-
await inTemporaryDirectory(async (tmpDir: string) => {
46-
// Given
47-
const localesPath = joinPath(tmpDir, 'locales')
48-
const enDefault = joinPath(localesPath, 'en.default.json')
49-
const es = joinPath(localesPath, 'es.json')
50-
51-
await mkdir(localesPath)
52-
await writeFile(enDefault, JSON.stringify({hello: 'Hello'}))
53-
const bigArray = new Array(6000).fill('a')
54-
await writeFile(es, JSON.stringify(bigArray))
55-
56-
// When
57-
const got = loadLocalesConfig(tmpDir, 'checkout_ui')
58-
await expect(got).rejects.toThrow(/Error loading checkout_ui/)
59-
})
60-
})
61-
6244
test('Throws if there are no defaults', async () => {
6345
await inTemporaryDirectory(async (tmpDir: string) => {
6446
// Given
@@ -92,23 +74,4 @@ describe('loadLocalesConfig', () => {
9274
await expect(got).rejects.toThrow(/Error loading checkout_ui/)
9375
})
9476
})
95-
96-
test('Throws if bundle is too big', async () => {
97-
await inTemporaryDirectory(async (tmpDir: string) => {
98-
// Given
99-
const localesPath = joinPath(tmpDir, 'locales')
100-
const en = joinPath(localesPath, 'en.default.json')
101-
const es = joinPath(localesPath, 'es.json')
102-
103-
await mkdir(localesPath)
104-
const bigArray = JSON.stringify(new Array(4000).fill('a'))
105-
106-
await writeFile(en, JSON.stringify(bigArray))
107-
await writeFile(es, JSON.stringify(bigArray))
108-
109-
// When
110-
const got = loadLocalesConfig(tmpDir, 'checkout_ui')
111-
await expect(got).rejects.toThrow(/Error loading checkout_ui/)
112-
})
113-
})
11477
})

packages/app/src/cli/utilities/extensions/locales-configuration.ts

-19
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ import {glob} from '@shopify/cli-kit/node/fs'
33
import {AbortError, BugError} from '@shopify/cli-kit/node/error'
44
import fs from 'fs'
55

6-
const L10N_FILE_SIZE_LIMIT = 20 * 1024
7-
const L10N_BUNDLE_SIZE_LIMIT = 256 * 1024
8-
96
export async function loadLocalesConfig(extensionPath: string, extensionIdentifier: string) {
107
const localesPaths = await glob(joinPath(extensionPath, 'locales/*.json'))
118
if (localesPaths.length === 0) return {}
129

1310
// Bundle validations
14-
const totalBundleSize = bundleSize(localesPaths)
1511
const defaultLanguageCode = findDefaultLocale(localesPaths)
1612

1713
if (defaultLanguageCode.length === 0)
@@ -26,20 +22,9 @@ export async function loadLocalesConfig(extensionPath: string, extensionIdentifi
2622
`There must be one (and only one) locale identified as the default locale: e.g. "en.default.json"`,
2723
)
2824

29-
if (totalBundleSize > L10N_BUNDLE_SIZE_LIMIT)
30-
throw new AbortError(
31-
`Error loading ${extensionIdentifier}`,
32-
`Total size of all locale files must be less than ${L10N_BUNDLE_SIZE_LIMIT}`,
33-
)
34-
3525
// Locale validations
3626
for (const locale of localesPaths) {
3727
const size = fs.statSync(locale).size
38-
if (size > L10N_FILE_SIZE_LIMIT)
39-
throw new AbortError(
40-
`Error loading ${extensionIdentifier}`,
41-
`Locale file ${locale} size must be less than ${L10N_FILE_SIZE_LIMIT}`,
42-
)
4328
if (size === 0) throw new AbortError(`Error loading ${extensionIdentifier}`, `Locale file ${locale} can't be empty`)
4429
}
4530

@@ -64,10 +49,6 @@ function getAllLocales(localesPath: string[]) {
6449
return all
6550
}
6651

67-
function bundleSize(localesPaths: string[]) {
68-
return localesPaths.map((locale) => fs.statSync(locale).size).reduce((acc, size) => acc + size, 0)
69-
}
70-
7152
function failIfUnset<T>(value: T | undefined, message: string) {
7253
if (value === undefined) {
7354
throw new BugError(message)

0 commit comments

Comments
 (0)