Skip to content

fix: close the file descriptor when reading a shebang fails - #187

Merged
satazor merged 2 commits into
masterfrom
fix/shebang-close-descriptor
Nov 1, 2026
Merged

satazor merged 2 commits into
masterfrom
fix/shebang-close-descriptor

Conversation

@satazor

@satazor satazor commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

readShebang only closed the file descriptor after a successful read, so it leaked when fs.readSync threw, e.g.: when the file is a directory. The descriptor is now closed in a finally block, and a failure to close it keeps the existing null fallback.

This is based on #184 by @xiehuanyi, who is credited as co-author of the fix. Thank you!

This also adds support for unit tests next to the code they test, as lib/**/*.test.js, while test/ keeps the end-to-end tests:

  • Test files are excluded from the npm package ("!lib/**/*.test.js" in files) and from coverage.
  • They're linted with the same config as test/ (es9, node and jest). ESLint 5 doesn't support extends in overrides, so .eslintrc became .eslintrc.js, which extends the moxy jest addon (it only applies to test files) and applies what es9 adds on top of es6 to lib/**/*.test.js. eslint --print-config confirms that lib/**/*.test.js and test/**/*.test.js now get the same effective config.

Supersedes #184.

satazor and others added 2 commits November 1, 2026 16:27
Unit tests live next to the code they test as `lib/**/*.test.js`, while
`test/` keeps the end-to-end tests. Test files are excluded from the
npm package and from coverage, and are linted with the same config as
`test/`.

ESLint 5 doesn't support `extends` in `overrides`, so the config moves to
.eslintrc.js, extends the jest addon (which only applies to test files)
and applies what es9 adds on top of es6 to `lib/**/*.test.js`.
readShebang only closed the file descriptor after a successful read, so
it leaked when fs.readSync threw, e.g.: when the file is a directory.

Based on #184.

Co-authored-by: Huanyi Xie <74809554+xiehuanyi@users.noreply.github.com>
@satazor
satazor force-pushed the fix/shebang-close-descriptor branch from 90c4ff9 to bd535d7 Compare November 1, 2026 16:28
@satazor
satazor merged commit 9924b88 into master Nov 1, 2026
8 checks passed
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.

1 participant