Skip to content

Commit 94454a6

Browse files
melissaluuJoshuaWhite1
authored andcommitted
Optimize empty path checking
1 parent 1de0d14 commit 94454a6

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ describe('copyConfigKeyEntry', () => {
340340
})
341341
})
342342

343-
test('throws with the field name only, not the full configKey, when the key is nested', async () => {
343+
test('throws with the full configKey when the key is nested', async () => {
344344
await inTemporaryDirectory(async (tmpDir) => {
345345
const outDir = joinPath(tmpDir, 'out')
346346
await mkdir(outDir)
@@ -352,7 +352,7 @@ describe('copyConfigKeyEntry', () => {
352352
context,
353353
})
354354
await expect(promise).rejects.toThrow(AbortError)
355-
await expect(promise).rejects.toThrow(`'assets' can't be empty.`)
355+
await expect(promise).rejects.toThrow(`'extension_points[].assets' can't be empty.`)
356356
})
357357
})
358358
})

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
@@ -48,6 +48,12 @@ export async function copyConfigKeyEntry(config: {
4848
paths = []
4949
}
5050

51+
for (const sourcePath of paths) {
52+
if (sourcePath.trim() === '') {
53+
throw new AbortError(`'${key}' can't be empty.`)
54+
}
55+
}
56+
5157
if (paths.length === 0) {
5258
outputDebug(`No value for configKey '${key}', skipping\n`, stdout)
5359
return {filesCopied: 0, pathMap: new Map()}
@@ -59,13 +65,6 @@ export async function copyConfigKeyEntry(config: {
5965
// should only be copied once; the pathMap entry is reused for all references.
6066
const uniquePaths = [...new Set(paths)]
6167

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

0 commit comments

Comments
 (0)