Skip to content

Commit 3880b9a

Browse files
melissaluuJoshuaWhite1
authored andcommitted
Optimize empty path checking
1 parent ef5e7f6 commit 3880b9a

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

packages/app/src/cli/services/build/steps/include-assets/copy-config-key-entry.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,13 @@ describe('copyConfigKeyEntry', () => {
361361
const outDir = joinPath(tmpDir, 'out')
362362
await mkdir(outDir)
363363
const context = makeContext({assets: ''})
364-
const promise = copyConfigKeyEntry({key: 'assets', baseDir: tmpDir, outputDir: outDir, context})
364+
const promise = copyConfigKeyEntry({
365+
key: 'assets',
366+
baseDir: tmpDir,
367+
outputDir: outDir,
368+
context,
369+
appDirectory: tmpDir,
370+
})
365371
await expect(promise).rejects.toThrow(AbortError)
366372
await expect(promise).rejects.toThrow(`'assets' can't be empty.`)
367373
})
@@ -372,13 +378,19 @@ describe('copyConfigKeyEntry', () => {
372378
const outDir = joinPath(tmpDir, 'out')
373379
await mkdir(outDir)
374380
const context = makeContext({assets: ' '})
375-
const promise = copyConfigKeyEntry({key: 'assets', baseDir: tmpDir, outputDir: outDir, context})
381+
const promise = copyConfigKeyEntry({
382+
key: 'assets',
383+
baseDir: tmpDir,
384+
outputDir: outDir,
385+
context,
386+
appDirectory: tmpDir,
387+
})
376388
await expect(promise).rejects.toThrow(AbortError)
377389
await expect(promise).rejects.toThrow(`'assets' can't be empty.`)
378390
})
379391
})
380392

381-
test('throws with the field name only, not the full configKey, when the key is nested', async () => {
393+
test('throws with the full configKey when the key is nested', async () => {
382394
await inTemporaryDirectory(async (tmpDir) => {
383395
const outDir = joinPath(tmpDir, 'out')
384396
await mkdir(outDir)
@@ -388,9 +400,10 @@ describe('copyConfigKeyEntry', () => {
388400
baseDir: tmpDir,
389401
outputDir: outDir,
390402
context,
403+
appDirectory: tmpDir,
391404
})
392405
await expect(promise).rejects.toThrow(AbortError)
393-
await expect(promise).rejects.toThrow(`'assets' can't be empty.`)
406+
await expect(promise).rejects.toThrow(`'extension_points[].assets' can't be empty.`)
394407
})
395408
})
396409
})

packages/app/src/cli/services/build/steps/include-assets/copy-config-key-entry.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export async function copyConfigKeyEntry(config: {
5151
paths = []
5252
}
5353

54+
for (const sourcePath of paths) {
55+
if (sourcePath.trim() === '') {
56+
throw new AbortError(`'${key}' can't be empty.`)
57+
}
58+
}
59+
5460
if (paths.length === 0) {
5561
outputDebug(`No value for configKey '${key}', skipping\n`, stdout)
5662
return {filesCopied: 0, pathMap: new Map()}
@@ -62,13 +68,6 @@ export async function copyConfigKeyEntry(config: {
6268
// should only be copied once; the pathMap entry is reused for all references.
6369
const uniquePaths = [...new Set(paths)]
6470

65-
const fieldName = key.split('.').pop()?.replace(/\[\]$/, '') ?? key
66-
for (const sourcePath of uniquePaths) {
67-
if (sourcePath.trim() === '') {
68-
throw new AbortError(`'${fieldName}' can't be empty.`)
69-
}
70-
}
71-
7271
// Process sequentially to avoid filesystem race conditions on shared output paths.
7372
const pathMap = new Map<string, string | string[]>()
7473
let filesCopied = 0

0 commit comments

Comments
 (0)