Skip to content

chore(maintenance): cleaned up package.json files #1504

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 14 commits into from
Jun 16, 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
20 changes: 12 additions & 8 deletions .github/actions/cached-node-modules/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ runs:
id: cache-node-modules
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
with:
path: "./node_modules"
path: '**/node_modules'
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
# if one of them changes the cache is invalidated/discarded
key: ${{ inputs.nodeVersion }}-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
- name: Install dependencies
# We can skip the installation if there was a cache hit
if: steps.cache-node-modules.outputs.cache-hit != 'true'
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
run: npm ci --foreground-scripts
run: npm ci
shell: bash
- name: Build packages
# If there's a cache hit we still need to manually build the packages
# this would otherwise have been done automatically as a part of the
# post-install npm hook
if: steps.cache-node-modules.outputs.cache-hit == 'true'
# Regardless of whether the cache was hit or not, we need to build the packages.
#
# We build the shared package first, then the others in parallel to speed up the process
# even though we could just run `npm run build` in the root folder and build them in
# sequence, but still in the correct order.
run: |
npm run build -w packages/commons
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
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
shell: bash
90 changes: 48 additions & 42 deletions .github/scripts/release_patch_package_json.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
/**
* This script is used to update the package.json file of an utility to include pre-release suffixes
* and remove fields that are not needed in the tarball that will be published to npm.
*
* We read the original package.json file and extract all the fields. Then, if the is an
* alpha or beta package, we update the version number to include a suffix. Finally, we write the updated
* package.json file to disk that includes the patched version number and all the fields we want to keep.
*
* The file will be restored to its original state after the release is complete.
*/
const { readFileSync, writeFileSync } = require('node:fs');
const { join, resolve } = require('node:path');

const outDir = './lib';
const betaPackages = [
'@aws-lambda-powertools/parameters',
];
if (process.argv.length < 3) {
console.error('Usage: node release_patch_package_json.js <package_path>\n');
process.exit(1);
}
const basePath = resolve(process.argv[2]);
const packageJsonPath = join(basePath, 'package.json');
const alphaPackages = ['@aws-lambda-powertools/idempotency'];
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'))
const pkgJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
// Extract the fields we want to keep
const {
name,
Expand All @@ -43,12 +36,19 @@ const betaPackages = [
bugs,
keywords,
dependencies,
devDependencies,
exports,
typesVersions,
main,
types,
files,
private,
} = pkgJson;

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

Expand All @@ -64,21 +64,27 @@ const betaPackages = [
bugs,
keywords,
dependencies,
devDependencies,
main: './index.js',
types: './index.d.ts',
main,
types,
files,
};

// 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));
// Not all utilities have these fields, so only add them if they exist to avoid
// having empty or undefined fields in the package.json file.
if (exports) {
newPkgJson.exports = exports;
}
if (typesVersions) {
newPkgJson.typesVersions = typesVersions;
}
if (private) {
newPkgJson.private = private;
}

// Temporarily update the original package.json file.
// This version will be picked up during the `npm publish` step, so that
// the version number and metadata in the registry are correct and match the tarball.
writeFileSync('package.json', JSON.stringify(newPkgJson, null, 2));
} catch (err) {
throw err;
}
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/make-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ jobs:
uses: ./.github/actions/cached-node-modules
- name: Version
run: |
npm run version
git push --tags
npx lerna version --conventional-commits --force-publish --no-commit-hooks --yes
- name: Publish to npm
run: |
npx lerna publish from-git --yes
- name: Set release version
id: set-release-version
run: |
RELEASE=$(npm view @aws-lambda-powertools/tracer version)
echo RELEASE_VERSION="$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
VERSION=$(cat lerna.json | jq .version -r)
echo RELEASE_VERSION="$VERSION" >> "$GITHUB_OUTPUT"

# NOTE: Watch out for the depth limit of 4 nested workflow_calls.
# publish_layer -> reusable_deploy_layer_stack -> reusable_update_layer_arn_docs
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You can use the library in both TypeScript and JavaScript code bases.
* **[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
* **[Metrics](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
* **[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
* **[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

## Getting started

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

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

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

### Examples

* [CDK](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples/cdk)
Expand Down
6 changes: 3 additions & 3 deletions docs/snippets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.0.1",
"version": "1.9.0",
"description": "A collection code snippets for the Powertools for AWS Lambda (TypeScript) docs",
"author": {
"name": "Amazon Web Services",
Expand All @@ -9,13 +9,13 @@
"scripts": {
"test": "echo 'Not Applicable'",
"test:e2e": "echo 'Not Applicable'",
"package": "echo 'Not applicable'",
"build": "echo 'Not Applicable'",
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern ."
},
"lint-staged": {
"*.ts": "npm run lint-fix"
"*.ts": "npm run lint-fix",
"*.js": "npm run lint-fix"
},
"license": "MIT-0",
"repository": {
Expand Down
8 changes: 3 additions & 5 deletions examples/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
"cdk-app": "bin/cdk-app.js"
},
"scripts": {
"build": "tsc --skipLibCheck",
"watch": "tsc -w",
"build": "echo 'Not applicable, run `npx cdk synth` instead to build the stack'",
"test": "npm run test:unit",
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
"lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .",
"package": "echo 'Not applicable'",
"package-bundle": "echo 'Not applicable'",
"test:unit": "export POWERTOOLS_DEV=true && npm run build && jest --silent",
"test:e2e": "echo 'To be implemented ...'",
"cdk": "cdk"
},
"lint-staged": {
"*.ts": "npm run lint-fix"
"*.ts": "npm run lint-fix",
"*.js": "npm run lint-fix"
},
"devDependencies": {
"@aws-lambda-powertools/logger": "^1.9.0",
Expand Down
7 changes: 3 additions & 4 deletions examples/sam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
"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.",
"license": "MIT-0",
"scripts": {
"build": "sam build --beta-features",
"build": "echo 'Not applicable, run `sam build --beta-features` instead to build the stack'",
"test": "npm run test:unit",
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
"lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .",
"package": "echo 'Not applicable'",
"package-bundle": "echo 'Not applicable'",
"test:unit": "export POWERTOOLS_DEV=true && npm run build && jest --silent",
"test:e2e": "echo 'To be implemented ...'"
},
"lint-staged": {
"*.ts": "npm run lint-fix"
"*.ts": "npm run lint-fix",
"*.js": "npm run lint-fix"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.109",
Expand Down
1 change: 0 additions & 1 deletion examples/sam/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ Resources:
BuildProperties:
Minify: true
Target: "ES2020"
ExperimentalDecorators: true
Sourcemap: true
External:
- "@aws-sdk/lib-dynamodb"
Expand Down
5 changes: 2 additions & 3 deletions layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
"private": true,
"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.",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"build": "echo 'Not applicable, run `npx cdk synth` instead to build the stack'",
"test": "echo 'Not applicable'",
"cdk": "cdk",
"package": "echo 'Not applicable'",
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
"lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .",
"test:unit": "jest --group=unit",
"test:e2e": "RUNTIME=nodejs14x jest --group=e2e"
"test:e2e": "jest --group=e2e"
},
"lint-staged": {
"*.ts": "npm run lint-fix",
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"packages/logger",
"packages/metrics",
"packages/parameters",
"packages/idempotency",
"examples/cdk",
"examples/sam",
"layers"
Expand Down
44 changes: 0 additions & 44 deletions package-bundler.sh

This file was deleted.

Loading