Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lambda-nodejs): maximum call stack size exceeded with relative entry file path #8907

Merged
merged 2 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions packages/@aws-cdk/aws-lambda-nodejs/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ export function nodeMajorVersion(): number {
* Find a file by walking up parent directories
*/
export function findUp(name: string, directory: string = process.cwd()): string | undefined {
const { root } = path.parse(directory);
if (directory === root && !fs.existsSync(path.join(directory, name))) {
return undefined;
}
const absoluteDirectory = path.resolve(directory);

if (fs.existsSync(path.join(directory, name))) {
return directory;
}
return findUp(name, path.dirname(directory));

const { root } = path.parse(absoluteDirectory);
if (absoluteDirectory === root) {
return undefined;
}

return findUp(name, path.dirname(absoluteDirectory));
}
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ test('findUp', () => {

// Starting at a specific path
expect(findUp('util.test.ts', path.join(__dirname, 'integ-handlers'))).toMatch(/aws-lambda-nodejs\/test$/);

// Non existing file starting at a non existing relative path
expect(findUp('not-to-be-found.txt', 'non-existing/relative/path')).toBe(undefined);

// Starting at a relative path
expect(findUp('util.test.ts', 'test/integ-handlers')).toMatch(/aws-lambda-nodejs\/test$/);
});