From e8ea4322473621c6340f16be8bb650d2f6f2bcbd Mon Sep 17 00:00:00 2001 From: ptaylor Date: Mon, 20 May 2024 15:59:18 -0700 Subject: [PATCH] add step to test importing the package as cjs and esm --- .github/workflows/main.pr.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/main.pr.yml b/.github/workflows/main.pr.yml index 49900049..ab56a252 100644 --- a/.github/workflows/main.pr.yml +++ b/.github/workflows/main.pr.yml @@ -125,6 +125,23 @@ jobs: run: | yarn test ${t:+-t ${t}} ${m:+-m ${m}} ${{ matrix.args }} + - name: Test importing + continue-on-error: true + if: ${{ steps.source_files_changed.outputs.any_modified == 'true' && matrix.target != 'src' }} + env: + t: "${{ matrix.target }}" + m: "${{ matrix.module }}" + run: | + set -x; + targetdir="./targets${t:+/${t}}${m:+/${m}}"; + pkg_name="$(jq -r '.name' "${targetdir}/package.json")"; + npm link -g "${targetdir}"; + cd /; + # Attempt to import as CommonJS + node -e "require('${pkg_name}')" || true; + # Attempt to import as ESModule + node --input-type=module -e "import '${pkg_name}'" || true; + test-tree-shaking-pull-request: needs: - build-and-test-pull-request