-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent imports from folder with same name
See https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/93\#issuecomment-2042201321
- Loading branch information
1 parent
19ee0fa
commit 3aa049b
Showing
5 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import assert from 'node:assert/strict' | ||
import { it, describe } from 'node:test' | ||
import { ImportFromFolderNameError, packLambda } from './packLambda.js' | ||
import path, { dirname } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import fs from 'node:fs/promises' | ||
import os from 'node:os' | ||
|
||
const tmpDir = os.tmpdir() | ||
|
||
void describe('packLambda()', () => { | ||
// See https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/93#issuecomment-2042201321 | ||
void it('should fail if it imports from a folder that has the same name as the handler module', async () => | ||
assert.rejects( | ||
async () => | ||
packLambda({ | ||
sourceFile: path.join( | ||
dirname(fileURLToPath(import.meta.url)), | ||
'test-data', | ||
'module-folder-named-like-handler-bug', | ||
'acme.ts', | ||
), | ||
zipFile: path.join( | ||
await fs.mkdtemp(`${tmpDir}${path.sep}`), | ||
'acme.zip', | ||
), | ||
}), | ||
ImportFromFolderNameError, | ||
)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Lambda's will fail if they import from a folder that has the same name as the | ||
handler. | ||
|
||
`packLambda` should fail in this case. | ||
|
||
See | ||
https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/93#issuecomment-2042201321 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { hello } from './acme/lib.js' | ||
|
||
export const handler = (): string => hello() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const hello = (): string => 'Hello World!' |