diff --git a/.github/scripts/release_patch_package_json.js b/.github/scripts/release_patch_package_json.js new file mode 100644 index 0000000000..7900a1a9a5 --- /dev/null +++ b/.github/scripts/release_patch_package_json.js @@ -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; + } +})(); diff --git a/lerna.json b/lerna.json index ea913fecdd..83f9e908c0 100644 --- a/lerna.json +++ b/lerna.json @@ -4,6 +4,7 @@ "packages/tracer", "packages/logger", "packages/metrics", + "packages/parameters", "examples/cdk", "examples/sam", "layers" diff --git a/packages/parameters/package.json b/packages/parameters/package.json index bee6d71f11..55f6381ac6 100644 --- a/packages/parameters/package.json +++ b/packages/parameters/package.json @@ -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", @@ -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"