Skip to content

Commit

Permalink
fix(lambda-nodejs): local bundling fails with relative depsLockFilePa…
Browse files Browse the repository at this point in the history
…th (aws#12125)

Ensure it's a file and make it absolute.

Closes aws#12115


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jogold authored and flochaz committed Jan 5, 2021
1 parent 770fe2e commit adfaad0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export class NodejsFunction extends lambda.Function {
if (!fs.existsSync(props.depsLockFilePath)) {
throw new Error(`Lock file at ${props.depsLockFilePath} doesn't exist`);
}
depsLockFilePath = props.depsLockFilePath;
if (!fs.statSync(props.depsLockFilePath).isFile()) {
throw new Error('`depsLockFilePath` should point to a file');
}
depsLockFilePath = path.resolve(props.depsLockFilePath);
} else {
const lockFile = findUp(LockFile.YARN) ?? findUp(LockFile.NPM);
if (!lockFile) {
Expand Down
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ test('throws with non existing lock file', () => {
})).toThrow(/Lock file at \/does\/not\/exist.lock doesn't exist/);
});

test('throws when depsLockFilePath is not a file', () => {
expect(() => new NodejsFunction(stack, 'handler1', {
depsLockFilePath: __dirname,
})).toThrow(/\`depsLockFilePath\` should point to a file/);
});

test('resolves depsLockFilePath to an absolute path', () => {
new NodejsFunction(stack, 'handler1', {
depsLockFilePath: './package.json',
});

expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({
depsLockFilePath: expect.stringMatching(/@aws-cdk\/aws-lambda-nodejs\/package.json$/),
}));
});

test('resolves entry to an absolute path', () => {
// WHEN
new NodejsFunction(stack, 'fn', {
Expand Down

0 comments on commit adfaad0

Please sign in to comment.