From c049b94fcd92ae84919b5e519335675deeed0043 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Tue, 28 Apr 2020 14:06:30 +0200 Subject: [PATCH 1/3] build: run build as prepack command This simplifies using npm pack in CI tests. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 192a77bd..979ae7df 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "docs": "( node --version | grep -q 'v12' ) && ( npm run build && runmd --output=README.md README_js.md )", "docs:diff": "npm run docs && git diff --quiet README.md", "build": "./scripts/build.sh", + "prepack": "npm run build", "release": "standard-version --no-verify" }, "repository": { @@ -114,8 +115,7 @@ }, "standard-version": { "scripts": { - "postchangelog": "prettier --write CHANGELOG.md", - "postcommit": "npm run build" + "postchangelog": "prettier --write CHANGELOG.md" } } } From 72af27f52105968ec27e440a55c86139fef93da7 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Tue, 28 Apr 2020 14:28:58 +0200 Subject: [PATCH 2/3] chore: ignore *.tgz files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4d565b4b..67b36b30 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ dist/ # Browserstack browserstack.err local.log +*.tgz From 0912b9b912e2cb5a6835384cd96e74c7eb703c05 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Tue, 28 Apr 2020 14:13:40 +0200 Subject: [PATCH 3/3] test: test imports with npm package contents Especially for publishing CommonJS/ESM/Browser dual packages a lot can go wrong in the actual build and release step, see: https://medium.com/javascript-in-plain-english/is-promise-post-mortem-cab807f18dcc In order to catch regressions with respect to the supported ways of importing this library it makes sense to test this using `npm pack`. Fixes #424 --- .github/workflows/ci.yml | 2 ++ package.json | 1 + scripts/testpack.sh | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100755 scripts/testpack.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 342840f5..763ecfb5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,3 +40,5 @@ jobs: BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }} - run: npm run test:node if: matrix.node-version == '12.x' || matrix.node-version == '14.x' + - run: npm run test:pack + if: matrix.node-version == '14.x' diff --git a/package.json b/package.json index 979ae7df..124d8999 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "test:browser": "wdio run ./wdio.conf.js", "pretest:node": "npm run build", "test:node": "npm-run-all --parallel examples:node:**", + "test:pack": "./scripts/testpack.sh", "prettier:check": "prettier --ignore-path .prettierignore --check '**/*.{js,jsx,json,md}'", "prettier:fix": "prettier --ignore-path .prettierignore --write '**/*.{js,jsx,json,md}'", "bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json", diff --git a/scripts/testpack.sh b/scripts/testpack.sh new file mode 100755 index 00000000..141ec2c9 --- /dev/null +++ b/scripts/testpack.sh @@ -0,0 +1,21 @@ +#!/bin/bash -eu + +# cd to the root dir +ROOT="$(pwd)/$(dirname "$0")/.." +cd "$ROOT" || exit 1 + +npm pack + +mkdir -p ../test-pack + +cp examples/node-commonjs/example.js ../test-pack/commonjs.js +cp examples/node-esmodules/example.mjs ../test-pack/esmodules.mjs + +cd ../test-pack + +npm init -y + +npm install ../uuid/uuid-*.tgz + +node commonjs.js +node esmodules.mjs