Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.

Commit e74cb49

Browse files
danezkhendrikse
andauthoredJan 12, 2023
fix: generate entry file on naming conflicts (#1310)
Co-authored-by: Karin Hendrikse <30577427+khendrikse@users.noreply.github.com>
1 parent ea4008e commit e74cb49

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed
 

‎src/runtimes/node/utils/zip.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ const createZipArchive = async function ({
108108
const destPath = join(destFolder, `${basename(filename, extension)}.zip`)
109109
const { archive, output } = startZip(destPath)
110110

111-
// We don't need an entry file if it would end up with the same path as the
112-
// function's main file.
113-
const needsEntryFile = !isNamedLikeEntryFile(mainFile, { basePath, filename })
114-
115111
// There is a naming conflict with the entry file if one of the supporting
116112
// files (i.e. not the main file) has the path that the entry file needs to
117113
// take.
@@ -121,6 +117,10 @@ const createZipArchive = async function ({
121117
mainFile,
122118
})
123119

120+
// We don't need an entry file if it would end up with the same path as the
121+
// function's main file. Unless we have a file conflict and need to move everything into a subfolder
122+
const needsEntryFile = hasEntryFileConflict || !isNamedLikeEntryFile(mainFile, { basePath, filename })
123+
124124
// If there is a naming conflict, we move all user files (everything other
125125
// than the entry file) to its own sub-directory.
126126
const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : ''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exports.handler = function handler (event, context) {
2+
return import('./func1.mjs').then(m => m.handler(event, context))
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const handler = () => true

‎tests/main.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,28 @@ describe('zip-it-and-ship-it', () => {
13831383
},
13841384
)
13851385

1386+
testMany(
1387+
'Generates a entry file if no entry file needed but naming conflict occurs',
1388+
['bundler_default', 'bundler_nft'],
1389+
async (options) => {
1390+
const fixtureName = 'naming_conflict'
1391+
const opts = merge(options, {
1392+
basePath: join(FIXTURES_DIR, fixtureName),
1393+
})
1394+
const { tmpDir } = await zipNode(fixtureName, {
1395+
opts,
1396+
length: 1,
1397+
})
1398+
1399+
const function2Entry = await importFunctionFile(`${tmpDir}/func1.js`)
1400+
1401+
expect(await function2Entry.handler()).toBe(true)
1402+
1403+
await expect(`${tmpDir}/src/func1.js`).toPathExist()
1404+
await expect(`${tmpDir}/src/func1.mjs`).toPathExist()
1405+
},
1406+
)
1407+
13861408
testMany(
13871409
'Bundles functions from multiple directories when the first argument of `zipFunctions()` is an array',
13881410
['bundler_esbuild', 'bundler_default', 'bundler_nft'],

1 commit comments

Comments
 (1)

github-actions[bot] commented on Jan 12, 2023

@github-actions[bot]
Contributor

⏱ Benchmark results

  • largeDepsEsbuild: 2.1s
  • largeDepsNft: 8.2s
  • largeDepsZisi: 16s
This repository has been archived.