diff --git a/.github/workflows/main.pr.yml b/.github/workflows/main.pr.yml index 7bb0112b..3aed35f9 100644 --- a/.github/workflows/main.pr.yml +++ b/.github/workflows/main.pr.yml @@ -126,15 +126,14 @@ jobs: 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")"; + 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}")"; @@ -142,10 +141,17 @@ jobs: cd "${_tmp}/node_modules/${pkg_name}"; npm i; cd "${_tmp}/"; - # 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; + 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}";