Skip to content

chore(parameters): add package to release process #1377

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

Merged
merged 4 commits into from
Mar 20, 2023
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
85 changes: 85 additions & 0 deletions .github/scripts/release_patch_package_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const { readFileSync, writeFileSync } = require('node:fs');

const outDir = './lib';
const betaPackages = [
'@aws-lambda-powertools/parameters',
];

/**
* This script is used to create a new package.json file for the tarball that will be published to npm.
*
* The original package.json file is read and the following fields are extracted:
* - name
* - version
* - description
* - author
* - license
* - homepage
* - repository
* - bugs
* - keywords
* - dependencies
* - devDependencies
*
* For beta packages, the version number is updated to include a beta suffix.
*
* The new package.json file is written to the lib folder, which is the folder that will be packed and published to npm.
* For beta packages, the original package.json file is also temporarily updated with the new beta version number so that
* the version number in the registry is correct and matches the tarball.
*/
(() => {
try {
// Read the original package.json file
const pkgJson = JSON.parse(readFileSync('./package.json', 'utf8'))
// Extract the fields we want to keep
const {
name,
version: originalVersion,
description,
author,
license,
homepage,
repository,
bugs,
keywords,
dependencies,
devDependencies,
} = pkgJson;

let version = originalVersion;
// Add a beta suffix to the version
if (betaPackages.includes(name)) {
version = `${version}-beta`;
}

// Create a new package.json file with the updated version for the tarball
const newPkgJson = {
name,
version,
description,
author,
license,
homepage,
repository,
bugs,
keywords,
dependencies,
devDependencies,
main: './index.js',
types: './index.d.ts',
};

// Write the new package.json file inside the folder that will be packed
writeFileSync(`${outDir}/package.json`, JSON.stringify(newPkgJson, null, 2));

if (betaPackages.includes(name)) {
// Temporarily update the original package.json file with the new beta version.
// This version number will be picked up during the `npm publish` step, so that
// the version number in the registry is correct and matches the tarball.
// The original package.json file will be restored by lerna after the publish step.
writeFileSync('package.json', JSON.stringify({ ...pkgJson, version }, null, 2));
}
} catch (err) {
throw err;
}
})();
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"packages/tracer",
"packages/logger",
"packages/metrics",
"packages/parameters",
"examples/cdk",
"examples/sam",
"layers"
Expand Down
8 changes: 5 additions & 3 deletions packages/parameters/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "@aws-lambda-powertools/parameters",
"version": "1.5.0",
"version": "1.6.0",
"description": "The parameters package for the AWS Lambda Powertools for TypeScript library",
"author": {
"name": "Amazon Web Services",
"url": "https://aws.amazon.com"
},
"publishConfig": {
"access": "public"
"access": "public",
"directory": "lib"
},
"scripts": {
"commit": "commit",
Expand All @@ -24,7 +25,8 @@
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
"package-bundle": "../../package-bundler.sh parameters-bundle ./dist",
"prepare": "npm run build",
"postversion": "git push --tags"
"postversion": "git push --tags",
"prepack": "cp ../../.github/scripts/release_patch_package_json.js . && node release_patch_package_json.js"
},
"lint-staged": {
"*.ts": "npm run lint-fix"
Expand Down