Skip to content

Commit 23e1073

Browse files
authored
chore(maintenance): migrate layers package to biome (#2806)
1 parent 5910bd4 commit 23e1073

File tree

9 files changed

+65
-71
lines changed

9 files changed

+65
-71
lines changed

layers/bin/layers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22
import 'source-map-support/register';
33
import { App } from 'aws-cdk-lib';
4-
import { LayerPublisherStack } from '../src/layer-publisher-stack';
54
import { CanaryStack } from 'layers/src/canary-stack';
5+
import { LayerPublisherStack } from '../src/layer-publisher-stack';
66

77
const SSM_PARAM_LAYER_ARN = '/layers/powertools-layer-arn';
88

layers/cdk.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"app": "npx ts-node --prefer-ts-exts bin/layers.ts",
33
"watch": {
4-
"include": [
5-
"**"
6-
],
4+
"include": ["**"],
75
"exclude": [
86
"README.md",
97
"cdk*.json",
@@ -24,9 +22,6 @@
2422
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
2523
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
2624
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
27-
"@aws-cdk/core:target-partitions": [
28-
"aws",
29-
"aws-cn"
30-
]
25+
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"]
3126
}
3227
}

layers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"jest": "jest --detectOpenHandles",
1313
"cdk": "cdk",
1414
"package": "echo 'Not applicable'",
15-
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
16-
"lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .",
15+
"lint": "biome lint .",
16+
"lint:fix": "biome check --write .",
1717
"test:unit": "jest --group=unit",
1818
"test:e2e": "jest --group=e2e",
1919
"createLayerFolder": "cdk synth --context BuildFromLocal=true"

layers/src/canary-stack.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { CustomResource, Duration, Stack, StackProps } from 'aws-cdk-lib';
2-
import { Construct } from 'constructs';
3-
import { LayerVersion, Runtime, Tracing } from 'aws-cdk-lib/aws-lambda';
4-
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
51
import { randomUUID } from 'node:crypto';
6-
import { Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam';
7-
import { Provider } from 'aws-cdk-lib/custom-resources';
8-
import { StringParameter } from 'aws-cdk-lib/aws-ssm';
92
import path from 'node:path';
3+
import { CustomResource, Duration, Stack, type StackProps } from 'aws-cdk-lib';
4+
import { Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam';
5+
import { LayerVersion, Runtime, Tracing } from 'aws-cdk-lib/aws-lambda';
106
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
7+
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
8+
import { StringParameter } from 'aws-cdk-lib/aws-ssm';
9+
import { Provider } from 'aws-cdk-lib/custom-resources';
10+
import type { Construct } from 'constructs';
1111

1212
export interface CanaryStackProps extends StackProps {
1313
readonly layerName: string;

layers/src/layer-publisher-stack.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { CfnOutput, RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib';
1+
import { execSync } from 'node:child_process';
2+
import { randomUUID } from 'node:crypto';
3+
import { join, resolve, sep } from 'node:path';
4+
import { CfnOutput, RemovalPolicy, Stack, type StackProps } from 'aws-cdk-lib';
25
import {
36
CfnLayerVersionPermission,
47
Code,
58
LayerVersion,
69
Runtime,
710
} from 'aws-cdk-lib/aws-lambda';
811
import { StringParameter } from 'aws-cdk-lib/aws-ssm';
9-
import { Construct } from 'constructs';
10-
import { execSync } from 'node:child_process';
11-
import { randomUUID } from 'node:crypto';
12-
import { join, resolve, sep } from 'node:path';
12+
import type { Construct } from 'constructs';
1313

1414
export interface LayerPublisherStackProps extends StackProps {
1515
readonly layerName?: string;
@@ -217,7 +217,7 @@ export class LayerPublisherStack extends Stack {
217217

218218
new CfnOutput(this, 'LatestLayerArn', {
219219
value: this.lambdaLayerVersion.layerVersionArn,
220-
exportName: props?.layerName ?? `LambdaPowerToolsForTypeScriptLayerARN`,
220+
exportName: props?.layerName ?? 'LambdaPowerToolsForTypeScriptLayerARN',
221221
});
222222
}
223223
}

layers/tests/e2e/layerPublisher.class.test.functionCode.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { join } from 'node:path';
21
import { readFile } from 'node:fs/promises';
2+
import { join } from 'node:path';
3+
import { BatchProcessor, EventType } from '@aws-lambda-powertools/batch';
4+
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
35
import { Logger } from '@aws-lambda-powertools/logger';
46
import { Metrics } from '@aws-lambda-powertools/metrics';
5-
import { Tracer } from '@aws-lambda-powertools/tracer';
6-
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
7-
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
8-
import { BatchProcessor, EventType } from '@aws-lambda-powertools/batch';
9-
import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm';
10-
import { SecretsProvider } from '@aws-lambda-powertools/parameters/secrets';
117
import { AppConfigProvider } from '@aws-lambda-powertools/parameters/appconfig';
128
import { DynamoDBProvider } from '@aws-lambda-powertools/parameters/dynamodb';
13-
import { SSMClient } from '@aws-sdk/client-ssm';
14-
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
9+
import { SecretsProvider } from '@aws-lambda-powertools/parameters/secrets';
10+
import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm';
11+
import { Tracer } from '@aws-lambda-powertools/tracer';
1512
import { AppConfigDataClient } from '@aws-sdk/client-appconfigdata';
13+
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
14+
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
15+
import { SSMClient } from '@aws-sdk/client-ssm';
1616

1717
const logger = new Logger({
1818
logLevel: 'DEBUG',
@@ -91,7 +91,7 @@ export const handler = async (): Promise<void> => {
9191
'batch',
9292
]) {
9393
const moduleVersion = await getVersionFromModule(moduleName);
94-
if (moduleVersion != expectedVersion) {
94+
if (moduleVersion !== expectedVersion) {
9595
throw new Error(
9696
`Package version mismatch (${moduleName}): ${moduleVersion} != ${expectedVersion}`
9797
);

layers/tests/e2e/layerPublisher.test.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
*
44
* @group e2e/layers/all
55
*/
6-
import { App } from 'aws-cdk-lib';
7-
import { LayerVersion } from 'aws-cdk-lib/aws-lambda';
8-
import { LayerPublisherStack } from '../../src/layer-publisher-stack';
6+
import { join } from 'node:path';
97
import {
10-
TestStack,
118
TestInvocationLogs,
12-
invokeFunctionOnce,
9+
TestStack,
1310
generateTestUniqueName,
11+
invokeFunctionOnce,
1412
} from '@aws-lambda-powertools/testing-utils';
1513
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
14+
import { App } from 'aws-cdk-lib';
15+
import { LayerVersion } from 'aws-cdk-lib/aws-lambda';
16+
import packageJson from '../../package.json';
17+
import { LayerPublisherStack } from '../../src/layer-publisher-stack';
1618
import {
1719
RESOURCE_NAME_PREFIX,
1820
SETUP_TIMEOUT,
1921
TEARDOWN_TIMEOUT,
2022
} from './constants';
21-
import { join } from 'node:path';
22-
import packageJson from '../../package.json';
2323

2424
jest.spyOn(console, 'log').mockImplementation();
2525

@@ -39,7 +39,7 @@ function assertLogs(
3939
*
4040
* The lambda function is invoked once and the logs are collected. The goal of the test is to verify that the layer creation and usage works as expected.
4141
*/
42-
describe(`Layers E2E tests`, () => {
42+
describe('Layers E2E tests', () => {
4343
const testStack = new TestStack({
4444
stackNameProps: {
4545
stackNamePrefix: RESOURCE_NAME_PREFIX,
@@ -96,7 +96,7 @@ describe(`Layers E2E tests`, () => {
9696
);
9797

9898
// Add a lambda function for each output format to the test stack
99-
cases.forEach((outputFormat) => {
99+
for (const outputFormat of cases) {
100100
new TestNodejsFunction(
101101
testStack,
102102
{
@@ -120,7 +120,7 @@ describe(`Layers E2E tests`, () => {
120120
...(outputFormat === 'ESM' && { outputFormat: 'ESM' }),
121121
}
122122
);
123-
});
123+
}
124124

125125
// Deploy the test stack
126126
await testStack.deploy();
@@ -141,28 +141,31 @@ describe(`Layers E2E tests`, () => {
141141
describe.each(cases)(
142142
'utilities tests for %s output format',
143143
(outputFormat) => {
144-
let invocationLogs: TestInvocationLogs;
145-
beforeAll(() => {
144+
it('should have no errors in the logs, which indicates the pacakges version matches the expected one', () => {
146145
const maybeInvocationLogs = invocationLogsMap.get(outputFormat);
147146
assertLogs(maybeInvocationLogs);
148-
invocationLogs = maybeInvocationLogs;
149-
});
150-
151-
it('should have no errors in the logs, which indicates the pacakges version matches the expected one', () => {
147+
const invocationLogs = maybeInvocationLogs;
152148
const logs = invocationLogs.getFunctionLogs('ERROR');
153149

154150
expect(logs.length).toBe(0);
155151
});
156152

157153
it('should have one warning related to missing Metrics namespace', () => {
154+
const maybeInvocationLogs = invocationLogsMap.get(outputFormat);
155+
assertLogs(maybeInvocationLogs);
156+
const invocationLogs = maybeInvocationLogs;
158157
const logs = invocationLogs.getFunctionLogs('WARN');
159158

160159
expect(logs.length).toBe(1);
161160
expect(logs[0]).toContain('Namespace should be defined, default used');
162161
});
163162

164163
it('should have one info log related to coldstart metric', () => {
164+
const maybeInvocationLogs = invocationLogsMap.get(outputFormat);
165+
assertLogs(maybeInvocationLogs);
166+
const invocationLogs = maybeInvocationLogs;
165167
const logs = invocationLogs.getFunctionLogs();
168+
166169
const emfLogEntry = logs.find((log) =>
167170
log.match(
168171
/{"_aws":{"Timestamp":\d+,"CloudWatchMetrics":\[\{"Namespace":"\S+","Dimensions":\[\["service"\]\],"Metrics":\[\{"Name":"ColdStart","Unit":"Count"\}\]\}\]},"service":"\S+","ColdStart":1}/
@@ -173,6 +176,9 @@ describe(`Layers E2E tests`, () => {
173176
});
174177

175178
it('should have one debug log with tracer subsegment info', () => {
179+
const maybeInvocationLogs = invocationLogsMap.get(outputFormat);
180+
assertLogs(maybeInvocationLogs);
181+
const invocationLogs = maybeInvocationLogs;
176182
const logs = invocationLogs.getFunctionLogs('DEBUG');
177183

178184
expect(logs.length).toBe(1);

layers/tests/tsconfig.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{
2-
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"rootDir": "../",
5-
"noEmit": true
6-
},
7-
"include": [
8-
"../src/**/*",
9-
"../package.json",
10-
"./**/*",
11-
]
12-
}
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "../",
5+
"noEmit": true
6+
},
7+
"include": ["../src/**/*", "../package.json", "./**/*"]
8+
}

layers/tsconfig.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{
2-
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"outDir": "./lib",
5-
"rootDir": "./",
6-
"resolveJsonModule": true
7-
},
8-
"include": [
9-
"./src/**/*",
10-
"./bin/**/*"
11-
],
12-
}
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./lib",
5+
"rootDir": "./",
6+
"resolveJsonModule": true
7+
},
8+
"include": ["./src/**/*", "./bin/**/*"]
9+
}

0 commit comments

Comments
 (0)