Skip to content

Commit bc5d35b

Browse files
authored
chore(maintenance): cleaned up package.json files (#1504)
* chore: clean up package.json files * docs: documented script * chore: updated version command in make-release * chore: updated cache * chore: updated version number in make-release
1 parent f475bd0 commit bc5d35b

File tree

19 files changed

+714
-835
lines changed

19 files changed

+714
-835
lines changed

Diff for: .github/actions/cached-node-modules/action.yml

+12-8
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,26 @@ runs:
1515
id: cache-node-modules
1616
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
1717
with:
18-
path: "./node_modules"
18+
path: '**/node_modules'
1919
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
2020
# if one of them changes the cache is invalidated/discarded
2121
key: ${{ inputs.nodeVersion }}-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
2222
- name: Install dependencies
2323
# We can skip the installation if there was a cache hit
2424
if: steps.cache-node-modules.outputs.cache-hit != 'true'
25-
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
26-
run: npm ci --foreground-scripts
25+
run: npm ci
2726
shell: bash
2827
- name: Build packages
29-
# If there's a cache hit we still need to manually build the packages
30-
# this would otherwise have been done automatically as a part of the
31-
# post-install npm hook
32-
if: steps.cache-node-modules.outputs.cache-hit == 'true'
28+
# Regardless of whether the cache was hit or not, we need to build the packages.
29+
#
30+
# We build the shared package first, then the others in parallel to speed up the process
31+
# even though we could just run `npm run build` in the root folder and build them in
32+
# sequence, but still in the correct order.
3333
run: |
3434
npm run build -w packages/commons
35-
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics & npm run build -w packages/parameters & npm run build -w packages/idempotency
35+
npm run build -w packages/logger & \
36+
npm run build -w packages/tracer & \
37+
npm run build -w packages/metrics & \
38+
npm run build -w packages/parameters & \
39+
npm run build -w packages/idempotency
3640
shell: bash

Diff for: .github/scripts/release_patch_package_json.js

+48-42
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
1+
/**
2+
* This script is used to update the package.json file of an utility to include pre-release suffixes
3+
* and remove fields that are not needed in the tarball that will be published to npm.
4+
*
5+
* We read the original package.json file and extract all the fields. Then, if the is an
6+
* alpha or beta package, we update the version number to include a suffix. Finally, we write the updated
7+
* package.json file to disk that includes the patched version number and all the fields we want to keep.
8+
*
9+
* The file will be restored to its original state after the release is complete.
10+
*/
111
const { readFileSync, writeFileSync } = require('node:fs');
12+
const { join, resolve } = require('node:path');
213

3-
const outDir = './lib';
4-
const betaPackages = [
5-
'@aws-lambda-powertools/parameters',
6-
];
14+
if (process.argv.length < 3) {
15+
console.error('Usage: node release_patch_package_json.js <package_path>\n');
16+
process.exit(1);
17+
}
18+
const basePath = resolve(process.argv[2]);
19+
const packageJsonPath = join(basePath, 'package.json');
20+
const alphaPackages = ['@aws-lambda-powertools/idempotency'];
21+
const betaPackages = ['@aws-lambda-powertools/parameters'];
722

8-
/**
9-
* This script is used to create a new package.json file for the tarball that will be published to npm.
10-
*
11-
* The original package.json file is read and the following fields are extracted:
12-
* - name
13-
* - version
14-
* - description
15-
* - author
16-
* - license
17-
* - homepage
18-
* - repository
19-
* - bugs
20-
* - keywords
21-
* - dependencies
22-
* - devDependencies
23-
*
24-
* For beta packages, the version number is updated to include a beta suffix.
25-
*
26-
* The new package.json file is written to the lib folder, which is the folder that will be packed and published to npm.
27-
* For beta packages, the original package.json file is also temporarily updated with the new beta version number so that
28-
* the version number in the registry is correct and matches the tarball.
29-
*/
3023
(() => {
3124
try {
3225
// Read the original package.json file
33-
const pkgJson = JSON.parse(readFileSync('./package.json', 'utf8'))
26+
const pkgJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
3427
// Extract the fields we want to keep
3528
const {
3629
name,
@@ -43,12 +36,19 @@ const betaPackages = [
4336
bugs,
4437
keywords,
4538
dependencies,
46-
devDependencies,
39+
exports,
40+
typesVersions,
41+
main,
42+
types,
43+
files,
44+
private,
4745
} = pkgJson;
4846

4947
let version = originalVersion;
50-
// Add a beta suffix to the version
51-
if (betaPackages.includes(name)) {
48+
// If the package is an alpha or beta package, update the version number to include a suffix
49+
if (alphaPackages.includes(name)) {
50+
version = `${version}-alpha`;
51+
} else if (betaPackages.includes(name)) {
5252
version = `${version}-beta`;
5353
}
5454

@@ -64,21 +64,27 @@ const betaPackages = [
6464
bugs,
6565
keywords,
6666
dependencies,
67-
devDependencies,
68-
main: './index.js',
69-
types: './index.d.ts',
67+
main,
68+
types,
69+
files,
7070
};
7171

72-
// Write the new package.json file inside the folder that will be packed
73-
writeFileSync(`${outDir}/package.json`, JSON.stringify(newPkgJson, null, 2));
74-
75-
if (betaPackages.includes(name)) {
76-
// Temporarily update the original package.json file with the new beta version.
77-
// This version number will be picked up during the `npm publish` step, so that
78-
// the version number in the registry is correct and matches the tarball.
79-
// The original package.json file will be restored by lerna after the publish step.
80-
writeFileSync('package.json', JSON.stringify({ ...pkgJson, version }, null, 2));
72+
// Not all utilities have these fields, so only add them if they exist to avoid
73+
// having empty or undefined fields in the package.json file.
74+
if (exports) {
75+
newPkgJson.exports = exports;
76+
}
77+
if (typesVersions) {
78+
newPkgJson.typesVersions = typesVersions;
8179
}
80+
if (private) {
81+
newPkgJson.private = private;
82+
}
83+
84+
// Temporarily update the original package.json file.
85+
// This version will be picked up during the `npm publish` step, so that
86+
// the version number and metadata in the registry are correct and match the tarball.
87+
writeFileSync('package.json', JSON.stringify(newPkgJson, null, 2));
8288
} catch (err) {
8389
throw err;
8490
}

Diff for: .github/workflows/make-release.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ jobs:
3434
uses: ./.github/actions/cached-node-modules
3535
- name: Version
3636
run: |
37-
npm run version
38-
git push --tags
37+
npx lerna version --conventional-commits --force-publish --no-commit-hooks --yes
3938
- name: Publish to npm
4039
run: |
4140
npx lerna publish from-git --yes
4241
- name: Set release version
4342
id: set-release-version
4443
run: |
45-
RELEASE=$(npm view @aws-lambda-powertools/tracer version)
46-
echo RELEASE_VERSION="$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
44+
VERSION=$(cat lerna.json | jq .version -r)
45+
echo RELEASE_VERSION="$VERSION" >> "$GITHUB_OUTPUT"
4746
4847
# NOTE: Watch out for the depth limit of 4 nested workflow_calls.
4948
# publish_layer -> reusable_deploy_layer_stack -> reusable_update_layer_arn_docs

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ You can use the library in both TypeScript and JavaScript code bases.
3535
* **[Logger](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger/)** - Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context
3636
* **[Metrics](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
3737
* **[Parameters (beta)](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/)** - High-level functions to retrieve one or more parameters from AWS SSM Parameter Store, AWS Secrets Manager, AWS AppConfig, and Amazon DynamoDB
38+
* **[Idempotency (beta)](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/idempotency/)** - Class method decorator, Middy middleware, and function wrapper to make your Lambda functions idempotent and prevent duplicate execution based on payload content
3839

3940
## Getting started
4041

@@ -73,6 +74,8 @@ Or refer to the installation guide of each utility:
7374

7475
👉 [Installation guide for the **Parameters** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/#getting-started)
7576

77+
👉 [Installation guide for the **Idempotency** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/idempotency/#getting-started)
78+
7679
### Examples
7780

7881
* [CDK](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples/cdk)

Diff for: docs/snippets/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docs",
3-
"version": "0.0.1",
3+
"version": "1.9.0",
44
"description": "A collection code snippets for the Powertools for AWS Lambda (TypeScript) docs",
55
"author": {
66
"name": "Amazon Web Services",
@@ -9,13 +9,13 @@
99
"scripts": {
1010
"test": "echo 'Not Applicable'",
1111
"test:e2e": "echo 'Not Applicable'",
12-
"package": "echo 'Not applicable'",
1312
"build": "echo 'Not Applicable'",
1413
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
1514
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern ."
1615
},
1716
"lint-staged": {
18-
"*.ts": "npm run lint-fix"
17+
"*.ts": "npm run lint-fix",
18+
"*.js": "npm run lint-fix"
1919
},
2020
"license": "MIT-0",
2121
"repository": {

Diff for: examples/cdk/package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@
1212
"cdk-app": "bin/cdk-app.js"
1313
},
1414
"scripts": {
15-
"build": "tsc --skipLibCheck",
16-
"watch": "tsc -w",
15+
"build": "echo 'Not applicable, run `npx cdk synth` instead to build the stack'",
1716
"test": "npm run test:unit",
1817
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
1918
"lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .",
20-
"package": "echo 'Not applicable'",
21-
"package-bundle": "echo 'Not applicable'",
2219
"test:unit": "export POWERTOOLS_DEV=true && npm run build && jest --silent",
2320
"test:e2e": "echo 'To be implemented ...'",
2421
"cdk": "cdk"
2522
},
2623
"lint-staged": {
27-
"*.ts": "npm run lint-fix"
24+
"*.ts": "npm run lint-fix",
25+
"*.js": "npm run lint-fix"
2826
},
2927
"devDependencies": {
3028
"@aws-lambda-powertools/logger": "^1.9.0",

Diff for: examples/sam/package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
"description": "This project contains source code and supporting files for a serverless application that you can deploy with the [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html). The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API.",
1010
"license": "MIT-0",
1111
"scripts": {
12-
"build": "sam build --beta-features",
12+
"build": "echo 'Not applicable, run `sam build --beta-features` instead to build the stack'",
1313
"test": "npm run test:unit",
1414
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
1515
"lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .",
16-
"package": "echo 'Not applicable'",
17-
"package-bundle": "echo 'Not applicable'",
1816
"test:unit": "export POWERTOOLS_DEV=true && npm run build && jest --silent",
1917
"test:e2e": "echo 'To be implemented ...'"
2018
},
2119
"lint-staged": {
22-
"*.ts": "npm run lint-fix"
20+
"*.ts": "npm run lint-fix",
21+
"*.js": "npm run lint-fix"
2322
},
2423
"devDependencies": {
2524
"@types/aws-lambda": "^8.10.109",

Diff for: examples/sam/template.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ Resources:
9898
BuildProperties:
9999
Minify: true
100100
Target: "ES2020"
101-
ExperimentalDecorators: true
102101
Sourcemap: true
103102
External:
104103
- "@aws-sdk/lib-dynamodb"

Diff for: layers/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
"private": true,
88
"description": "This CDK app is meant to be used to publish Powertools for AWS Lambda (TypeScript) Lambda Layer. It is composed of a single stack deploying the Layer into the target account.",
99
"scripts": {
10-
"build": "tsc",
11-
"watch": "tsc -w",
10+
"build": "echo 'Not applicable, run `npx cdk synth` instead to build the stack'",
1211
"test": "echo 'Not applicable'",
1312
"cdk": "cdk",
1413
"package": "echo 'Not applicable'",
1514
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
1615
"lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .",
1716
"test:unit": "jest --group=unit",
18-
"test:e2e": "RUNTIME=nodejs14x jest --group=e2e"
17+
"test:e2e": "jest --group=e2e"
1918
},
2019
"lint-staged": {
2120
"*.ts": "npm run lint-fix",

Diff for: lerna.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"packages/logger",
66
"packages/metrics",
77
"packages/parameters",
8+
"packages/idempotency",
89
"examples/cdk",
910
"examples/sam",
1011
"layers"

Diff for: package-bundler.sh

-44
This file was deleted.

0 commit comments

Comments
 (0)