Fix ESM imports and tree-shaking #76
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build pull request | ||
concurrency: | ||
group: pr-on-${{ github.event_name }}-from-${{ github.ref_name }} | ||
cancel-in-progress: true | ||
on: | ||
pull_request: | ||
branches: | ||
- "master" | ||
jobs: | ||
lint-pull-request: | ||
name: Lint | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Setup node v20.x | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20.x | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- name: Cache node_modules | ||
uses: actions/cache@v4 | ||
with: | ||
key: ${{ join(fromJSON('["${{ runner.os }}", "node_modules", "20.x", "${{ hashFiles('package.json', 'yarn.lock') }"]', '-') }} | ||
Check failure on line 30 in .github/workflows/main.pr.yml GitHub Actions / Build pull requestInvalid workflow file
|
||
path: node_modules | ||
- name: Check if source or test files changed | ||
id: files_changed | ||
uses: tj-actions/changed-files@v44 | ||
with: | ||
files: | | ||
src/**/* | ||
spec/**/* | ||
- name: Lint files | ||
if: ${{ steps.files_changed.outputs.any_modified == 'true' }} | ||
run: | | ||
yarn --ignore-engines --non-interactive | ||
yarn lint:ci | ||
build-and-test-pull-request: | ||
needs: | ||
- lint-pull-request | ||
name: Test ${{ matrix.node }} ${{ join(fromJSON('["${{ matrix.target }}", "${{ matrix.module }}"]'), '/') }} | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node: [16.x, 18.x, 20.x] | ||
target: [es5, es2015, esnext] | ||
module: [cjs, esm, umd] | ||
include: | ||
- {node: 16.x, target: ix} | ||
- {node: 18.x, target: ix} | ||
- {node: 20.x, target: ix} | ||
- {node: 20.x, target: src, args: --coverage} | ||
steps: | ||
- name: Setup node v${{ matrix.node }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- name: Cache targets | ||
uses: actions/cache@v4 | ||
with: | ||
key: ${{ join(fromJSON('["${{ runner.os }}", "targets", "${{ matrix.node }}", "${{ matrix.target }}", "${{ matrix.module }}", "${{ hashFiles('package.json', 'yarn.lock', 'tsconfig.json', 'src/**/*', 'tsconfigs/**/*') }}"]'), '-') }} | ||
path: targets | ||
- name: Cache node_modules | ||
uses: actions/cache@v4 | ||
with: | ||
key: ${{ join(fromJSON('["${{ runner.os }}", "node_modules", "${{ matrix.node }}", "${{ hashFiles('package.json', 'yarn.lock') }}"]'), '-') }} | ||
path: node_modules | ||
- name: Check if test files changed | ||
id: test_files_changed | ||
uses: tj-actions/changed-files@v44 | ||
with: | ||
files: | | ||
spec/**/* | ||
tsconfig.json | ||
tsconfigs/**/* | ||
jest.config.js | ||
jestconfigs/**/* | ||
- name: Check if source files changed | ||
id: source_files_changed | ||
uses: tj-actions/changed-files@v44 | ||
with: | ||
files: | | ||
.npmrc | ||
yarn.lock | ||
package.json | ||
tsconfig.json | ||
src/**/* | ||
gulp/**/* | ||
tsconfigs/**/* | ||
integration/**/* | ||
- name: Install dependencies | ||
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' || steps.test_files_changed.outputs.any_modified == 'true' }} | ||
run: | | ||
yarn --ignore-engines --non-interactive | ||
- name: Build package | ||
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' && matrix.target != 'src' }} | ||
env: | ||
t: "${{ matrix.target }}" | ||
m: "${{ matrix.module }}" | ||
run: | | ||
yarn build ${t:+-t ${t}} ${m:+-m ${m}} | ||
- name: Test package | ||
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' || steps.test_files_changed.outputs.any_modified == 'true' }} | ||
env: | ||
t: "${{ matrix.target }}" | ||
m: "${{ matrix.module }}" | ||
run: | | ||
yarn test ${t:+-t ${t}} ${m:+-m ${m}} ${{ matrix.args }} | ||
- name: Test importing | ||
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' && matrix.target != 'src' }} | ||
env: | ||
t: "${{ matrix.target }}" | ||
m: "${{ matrix.module }}" | ||
run: | | ||
targetdir="./targets${t:+/${t}}${m:+/${m}}"; | ||
pkg_name="$(jq -r '.name' "${targetdir}/package.json")"; | ||
pkg_type="$(jq -r '.type' "${targetdir}/package.json")"; | ||
# Install the package into a temp dir | ||
_tmp="$(mktemp -d)"; | ||
mkdir -p "$(dirname "${_tmp}/node_modules/${pkg_name}")"; | ||
cp -ar "${targetdir}" "${_tmp}/node_modules/${pkg_name}"; | ||
cd "${_tmp}/node_modules/${pkg_name}"; | ||
npm i; | ||
cd "${_tmp}/"; | ||
set -x; | ||
if test "${pkg_type}" = "module"; then | ||
# Test importing as ESModule | ||
node --input-type=module -e "import '${pkg_name}'"; | ||
else | ||
# Test importing as CommonJS | ||
node --input-type=commonjs -e "require('${pkg_name}')"; | ||
# Test importing CommonJS module but allow it to fail | ||
node --input-type=module -e "import '${pkg_name}'" || true; | ||
fi | ||
set +x; | ||
cd /; | ||
rm -rf "${_tmp}"; | ||
test-tree-shaking-pull-request: | ||
needs: | ||
- build-and-test-pull-request | ||
name: Bundle ${{ matrix.bundler }} ${{ join(fromJSON('["${{ matrix.target }}", "${{ matrix.module }}"]'), '/') }} | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
bundler: [esbuild, rollup, webpack] | ||
target: [es5, es2015, esnext] | ||
module: [cjs, esm, umd] | ||
include: | ||
- {bundler: esbuild, target: ix} | ||
- {bundler: rollup, target: ix} | ||
- {bundler: webpack, target: ix} | ||
steps: | ||
- name: Setup node v20.x | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20.x | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- name: Cache targets | ||
uses: actions/cache@v4 | ||
with: | ||
key: ${{ join(fromJSON('["${{ runner.os }}", "targets", "20.x", "${{ matrix.target }}", "${{ matrix.module }}", "${{ hashFiles('package.json', 'yarn.lock', 'tsconfig.json', 'src/**/*', 'tsconfigs/**/*') }}"]'), '-') }} | ||
path: targets | ||
- name: Cache node_modules | ||
uses: actions/cache@v4 | ||
with: | ||
key: ${{ join(fromJSON('["${{ runner.os }}", "node_modules", "20.x", "${{ hashFiles('package.json', 'yarn.lock') }"]', '-') }} | ||
path: node_modules | ||
- name: Test ${{ matrix.bundler }} tree-shaking | ||
env: | ||
t: "${{ matrix.target }}" | ||
m: "${{ matrix.module }}" | ||
run: | | ||
integration/make-files-to-bundle.sh | ||
if test "${t}" != ix; then | ||
yarn build ${t:+-t ${t}} ${m:+-m ${m}} | ||
fi | ||
yarn gulp bundle${t:+:${t}}${m:+:${m}}:${{ matrix.bundler }} |