Skip to content

Commit

Permalink
chore: forward merge 'master' into 'v2-main' (#18016)
Browse files Browse the repository at this point in the history
Automated action from aws/cdk-ops
  • Loading branch information
mergify[bot] authored Dec 14, 2021
2 parents 61b515c + 9622fd0 commit 44c1ca9
Show file tree
Hide file tree
Showing 35 changed files with 443 additions and 515 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('lambda', () => {
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'my-api');
const handler = new lambda.Function(stack, 'Handler', {
runtime: lambda.Runtime.PYTHON_2_7,
runtime: lambda.Runtime.PYTHON_3_9,
handler: 'boom',
code: lambda.Code.fromInline('foo'),
});
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-cloudformation/test/resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ testDeprecated('custom resource is added twice, lambda is added once', () => {
'Arn',
],
},
'Runtime': 'python2.7',
'Runtime': 'python3.9',
'Timeout': 300,
},
'DependsOn': [
Expand Down Expand Up @@ -208,7 +208,7 @@ class TestCustomResource extends Construct {
const singletonLambda = new lambda.SingletonFunction(this, 'Lambda', {
uuid: 'TestCustomResourceProvider',
code: new lambda.InlineCode('def hello(): pass'),
runtime: lambda.Runtime.PYTHON_2_7,
runtime: lambda.Runtime.PYTHON_3_9,
handler: 'index.hello',
timeout: cdk.Duration.minutes(5),
});
Expand Down
14 changes: 7 additions & 7 deletions packages/@aws-cdk/aws-events-targets/test/lambda/lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test('adding same singleton lambda function as target mutiple times creates perm
const fn = new lambda.SingletonFunction(stack, 'MyLambda', {
code: new lambda.InlineCode('foo'),
handler: 'bar',
runtime: lambda.Runtime.PYTHON_2_7,
runtime: lambda.Runtime.PYTHON_3_9,
uuid: 'uuid',
});
const rule = new events.Rule(stack, 'Rule', {
Expand All @@ -133,7 +133,7 @@ test('lambda handler and cloudwatch event across stacks', () => {
const fn = new lambda.Function(lambdaStack, 'MyLambda', {
code: new lambda.InlineCode('foo'),
handler: 'bar',
runtime: lambda.Runtime.PYTHON_2_7,
runtime: lambda.Runtime.PYTHON_3_9,
});

const eventStack = new cdk.Stack(app, 'EventStack');
Expand All @@ -156,7 +156,7 @@ test('use a Dead Letter Queue for the rule target', () => {
const fn = new lambda.Function(stack, 'MyLambda', {
code: new lambda.InlineCode('foo'),
handler: 'bar',
runtime: lambda.Runtime.PYTHON_2_7,
runtime: lambda.Runtime.PYTHON_3_9,
});

const queue = new sqs.Queue(stack, 'Queue');
Expand Down Expand Up @@ -248,7 +248,7 @@ test('throw an error when using a Dead Letter Queue for the rule target in a dif
const fn = new lambda.Function(stack1, 'MyLambda', {
code: new lambda.InlineCode('foo'),
handler: 'bar',
runtime: lambda.Runtime.PYTHON_2_7,
runtime: lambda.Runtime.PYTHON_3_9,
});

const queue = new sqs.Queue(stack2, 'Queue');
Expand Down Expand Up @@ -285,7 +285,7 @@ test('must display a warning when using a Dead Letter Queue from another account
const fn = new lambda.Function(stack1, 'MyLambda', {
code: new lambda.InlineCode('foo'),
handler: 'bar',
runtime: lambda.Runtime.PYTHON_2_7,
runtime: lambda.Runtime.PYTHON_3_9,
});

const queue = sqs.Queue.fromQueueArn(stack2, 'Queue', 'arn:aws:sqs:eu-west-1:444455556666:queue1');
Expand Down Expand Up @@ -334,7 +334,7 @@ test('specifying retry policy', () => {
const fn = new lambda.Function(stack, 'MyLambda', {
code: new lambda.InlineCode('foo'),
handler: 'bar',
runtime: lambda.Runtime.PYTHON_2_7,
runtime: lambda.Runtime.PYTHON_3_9,
});

// WHEN
Expand Down Expand Up @@ -375,6 +375,6 @@ function newTestLambda(scope: constructs.Construct, suffix = '') {
return new lambda.Function(scope, `MyLambda${suffix}`, {
code: new lambda.InlineCode('foo'),
handler: 'bar',
runtime: lambda.Runtime.PYTHON_2_7,
runtime: lambda.Runtime.PYTHON_3_9,
});
}
17 changes: 11 additions & 6 deletions packages/@aws-cdk/aws-lambda-nodejs/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Construct } from 'constructs';
import { Bundling } from './bundling';
import { PackageManager } from './package-manager';
import { BundlingOptions } from './types';
import { callsites, findUp } from './util';
import { callsites, findUpMultiple } from './util';

/**
* Properties for a NodejsFunction
Expand Down Expand Up @@ -134,15 +134,20 @@ function findLockFile(depsLockFilePath?: string): string {
return path.resolve(depsLockFilePath);
}

const lockFile = findUp(PackageManager.PNPM.lockFile)
?? findUp(PackageManager.YARN.lockFile)
?? findUp(PackageManager.NPM.lockFile);
const lockFiles = findUpMultiple([
PackageManager.PNPM.lockFile,
PackageManager.YARN.lockFile,
PackageManager.NPM.lockFile,
]);

if (!lockFile) {
if (lockFiles.length === 0) {
throw new Error('Cannot find a package lock file (`pnpm-lock.yaml`, `yarn.lock` or `package-lock.json`). Please specify it with `depsFileLockPath`.');
}
if (lockFiles.length > 1) {
throw new Error(`Multiple package lock files found: ${lockFiles.join(', ')}. Please specify the desired one with \`depsFileLockPath\`.`);
}

return lockFile;
return lockFiles[0];
}

/**
Expand Down
25 changes: 20 additions & 5 deletions packages/@aws-cdk/aws-lambda-nodejs/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,34 @@ export function callsites(): CallSite[] {
* Find a file by walking up parent directories
*/
export function findUp(name: string, directory: string = process.cwd()): string | undefined {
return findUpMultiple([name], directory)[0];
}

/**
* Find the lowest of multiple files by walking up parent directories. If
* multiple files exist at the same level, they will all be returned.
*/
export function findUpMultiple(names: string[], directory: string = process.cwd()): string[] {
const absoluteDirectory = path.resolve(directory);

const file = path.join(directory, name);
if (fs.existsSync(file)) {
return file;
const files = [];
for (const name of names) {
const file = path.join(directory, name);
if (fs.existsSync(file)) {
files.push(file);
}
}

if (files.length > 0) {
return files;
}

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

return findUp(name, path.dirname(absoluteDirectory));
return findUpMultiple(names, path.dirname(absoluteDirectory));
}

/**
Expand Down
45 changes: 44 additions & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/test/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as child_process from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import { callsites, exec, extractDependencies, findUp } from '../lib/util';
import { callsites, exec, extractDependencies, findUp, findUpMultiple } from '../lib/util';

beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -33,6 +33,49 @@ describe('findUp', () => {
});
});

describe('findUpMultiple', () => {
test('Starting at process.cwd()', () => {
const files = findUpMultiple(['README.md', 'package.json']);
expect(files).toHaveLength(2);
expect(files[0]).toMatch(/aws-lambda-nodejs\/README\.md$/);
expect(files[1]).toMatch(/aws-lambda-nodejs\/package\.json$/);
});

test('Non existing files', () => {
expect(findUpMultiple(['non-existing-file.unknown', 'non-existing-file.unknown2'])).toEqual([]);
});

test('Existing and non existing files', () => {
const files = findUpMultiple(['non-existing-file.unknown', 'README.md']);
expect(files).toHaveLength(1);
expect(files[0]).toMatch(/aws-lambda-nodejs\/README\.md$/);
});

test('Starting at a specific path', () => {
const files = findUpMultiple(['util.test.ts', 'function.test.ts'], path.join(__dirname, 'integ-handlers'));
expect(files).toHaveLength(2);
expect(files[0]).toMatch(/aws-lambda-nodejs\/test\/util\.test\.ts$/);
expect(files[1]).toMatch(/aws-lambda-nodejs\/test\/function\.test\.ts$/);
});

test('Non existing files starting at a non existing relative path', () => {
expect(findUpMultiple(['not-to-be-found.txt', 'not-to-be-found2.txt'], 'non-existing/relative/path')).toEqual([]);
});

test('Starting at a relative path', () => {
const files = findUpMultiple(['util.test.ts', 'function.test.ts'], 'test/integ-handlers');
expect(files).toHaveLength(2);
expect(files[0]).toMatch(/aws-lambda-nodejs\/test\/util\.test\.ts$/);
expect(files[1]).toMatch(/aws-lambda-nodejs\/test\/function\.test\.ts$/);
});

test('Files on multiple levels', () => {
const files = findUpMultiple(['README.md', 'util.test.ts'], path.join(__dirname, 'integ-handlers'));
expect(files).toHaveLength(1);
expect(files[0]).toMatch(/aws-lambda-nodejs\/test\/util\.test\.ts$/);
});
});

describe('exec', () => {
test('normal execution', () => {
const spawnSyncMock = jest.spyOn(child_process, 'spawnSync').mockReturnValue({
Expand Down
Loading

0 comments on commit 44c1ca9

Please sign in to comment.