Skip to content

Commit

Permalink
make import step non-optional
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt committed May 21, 2024
1 parent 1e1f5e5 commit 05f78c7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/main.pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,32 @@ 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}")";
cp -ar "${targetdir}" "${_tmp}/node_modules/${pkg_name}";
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}";
Expand Down

0 comments on commit 05f78c7

Please sign in to comment.