Skip to content

Commit

Permalink
fix(lambda-nodejs): local bundling fails with relative depsLockFilePath
Browse files Browse the repository at this point in the history
Ensure it's a file and make it absolute.

Closes aws#12115
  • Loading branch information
jogold committed Dec 17, 2020
1 parent d10ea63 commit fc224dc
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 fc224dc

Please sign in to comment.