Skip to content

fix: make guarded require() calls resolve in the ESM bundle - #17

Merged
Alex079 merged 2 commits into
masterfrom
fix/esm-require-path-sep
Oct 18, 2026
Merged

Alex079 merged 2 commits into
masterfrom
fix/esm-require-path-sep

Conversation

@Alex079

@Alex079 Alex079 commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Closes #16

Root cause

dist/index.js is an ESM bundle, but @rollup/plugin-commonjs leaves require calls inside try/catch untouched by default (ignoreTryCatch: true). minimatch@3 loads the path module exactly that way:

var path = (function () { try { return require('path') } catch (e) {}}()) || { sep: '/' };

In an ES module require is undefined, the ReferenceError is swallowed and path.sep becomes '/'. On Windows this disables minimatch's separator normalisation, so @actions/glob gets item paths with backslashes that never match the forward-slash pattern, globber.glob() returns nothing, no directory is added to PATH, and the action still reports success.

Changes

  • rollup.config.js: commonjs({ ignoreTryCatch: false }) so the guarded require() calls are converted to real imports. This also fixes the other silently broken guarded requires (node:crypto, node:http2) that were falling back to their catch branches in the ESM bundle.
  • .github/workflows/ci.yml: new Verify the extracted directory was added to PATH step in the run job, so CI fails if nothing actually lands on PATH instead of only checking that the action exits 0.
  • dist/index.js + sourcemap: rebuilt.

Verification

  • Reproduced the mechanism locally with minimatch@3: with path.sep === '/' the pattern D:/a/_temp/*/content does not match D:\a\_temp\guid\content; with path.sep === '\\' it does.
  • npm test — all 25 tests pass.
  • Ran the packaged dist/index.js against the sample zip; it appended the extracted content directory to GITHUB_PATH.
  • The new CI step runs on ubuntu-latest, windows-latest and macos-latest for each archive type.

Alex079 added 2 commits October 18, 2026 01:19
rollup's commonjs plugin leaves require() calls inside try/catch
untouched by default (ignoreTryCatch). minimatch@3 loads node's path
module that way, so in the ESM output require was undefined, the
ReferenceError was swallowed and path.sep fell back to '/'. On Windows
this disabled minimatch's separator normalisation, so @actions/glob
found nothing, no directory was added to PATH and the action still
reported success.

Set ignoreTryCatch: false so the guarded requires (node:path,
node:crypto, node:http2) become static imports, and assert in CI that
the extracted directory actually lands on PATH.
@Alex079
Alex079 merged commit 12bffbe into master Oct 18, 2026
12 checks passed
@Alex079
Alex079 deleted the fix/esm-require-path-sep branch October 18, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v3.0.0: nothing is added to PATH on Windows (minimatch require('path') left unconverted in ESM bundle)

1 participant