Skip to content

Commit d5e2aea

Browse files
authored
chore(parameters): add package to release process (#1377)
* chore: added release prepack script * chore: add parameters to lerna config * fix: version variable * fix: version suffic
1 parent 720d8a3 commit d5e2aea

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

Diff for: .github/scripts/release_patch_package_json.js

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const { readFileSync, writeFileSync } = require('node:fs');
2+
3+
const outDir = './lib';
4+
const betaPackages = [
5+
'@aws-lambda-powertools/parameters',
6+
];
7+
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+
*/
30+
(() => {
31+
try {
32+
// Read the original package.json file
33+
const pkgJson = JSON.parse(readFileSync('./package.json', 'utf8'))
34+
// Extract the fields we want to keep
35+
const {
36+
name,
37+
version: originalVersion,
38+
description,
39+
author,
40+
license,
41+
homepage,
42+
repository,
43+
bugs,
44+
keywords,
45+
dependencies,
46+
devDependencies,
47+
} = pkgJson;
48+
49+
let version = originalVersion;
50+
// Add a beta suffix to the version
51+
if (betaPackages.includes(name)) {
52+
version = `${version}-beta`;
53+
}
54+
55+
// Create a new package.json file with the updated version for the tarball
56+
const newPkgJson = {
57+
name,
58+
version,
59+
description,
60+
author,
61+
license,
62+
homepage,
63+
repository,
64+
bugs,
65+
keywords,
66+
dependencies,
67+
devDependencies,
68+
main: './index.js',
69+
types: './index.d.ts',
70+
};
71+
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));
81+
}
82+
} catch (err) {
83+
throw err;
84+
}
85+
})();

Diff for: lerna.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"packages/tracer",
55
"packages/logger",
66
"packages/metrics",
7+
"packages/parameters",
78
"examples/cdk",
89
"examples/sam",
910
"layers"

Diff for: packages/parameters/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "@aws-lambda-powertools/parameters",
3-
"version": "1.5.0",
3+
"version": "1.6.0",
44
"description": "The parameters package for the AWS Lambda Powertools for TypeScript library",
55
"author": {
66
"name": "Amazon Web Services",
77
"url": "https://aws.amazon.com"
88
},
99
"publishConfig": {
10-
"access": "public"
10+
"access": "public",
11+
"directory": "lib"
1112
},
1213
"scripts": {
1314
"commit": "commit",
@@ -24,7 +25,8 @@
2425
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
2526
"package-bundle": "../../package-bundler.sh parameters-bundle ./dist",
2627
"prepare": "npm run build",
27-
"postversion": "git push --tags"
28+
"postversion": "git push --tags",
29+
"prepack": "cp ../../.github/scripts/release_patch_package_json.js . && node release_patch_package_json.js"
2830
},
2931
"lint-staged": {
3032
"*.ts": "npm run lint-fix"

0 commit comments

Comments
 (0)