Skip to content

Commit

Permalink
feat(shebang): add support for env's split-string option (#195)
Browse files Browse the repository at this point in the history
* feat(shebang): add support for env's split-string option

This is useful for passing arguments to node

* feat(shebang): support all `env` options

* feat(shebang): improve regex performance
  • Loading branch information
dudeofawesome authored Mar 5, 2024
1 parent 4778ae8 commit b383b49
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/shebang.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const getNpmignore = require("../util/get-npmignore")

const NODE_SHEBANG = "#!/usr/bin/env node\n"
const SHEBANG_PATTERN = /^(#!.+?)?(\r)?\n/u
const NODE_SHEBANG_PATTERN = /#!\/usr\/bin\/env node(?: [^\r\n]+?)?\n/u
const NODE_SHEBANG_PATTERN =
/^#!\/usr\/bin\/env(?: -\S+)*(?: [^\s=-]+=\S+)* node(?: [^\r\n]+?)?\n/u

function simulateNodeResolutionAlgorithm(filePath, binField) {
const possibilities = [filePath]
Expand Down
25 changes: 25 additions & 0 deletions tests/lib/rules/shebang.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ ruleTester.run("shebang", rule, {
filename: fixture("object-bin/bin/b.js"),
code: "#!/usr/bin/env node\nhello();",
},
{
name: "string-bin/bin/test.js",
filename: fixture("string-bin/bin/test.js"),
code: "#!/usr/bin/env -S node\nhello();",
},
{
name: "string-bin/bin/test.js",
filename: fixture("string-bin/bin/test.js"),
code: "#!/usr/bin/env -S node --loader tsm\nhello();",
},
{
name: "string-bin/bin/test.js",
filename: fixture("string-bin/bin/test.js"),
code: "#!/usr/bin/env --ignore-environment node\nhello();",
},
{
name: "string-bin/bin/test.js",
filename: fixture("string-bin/bin/test.js"),
code: "#!/usr/bin/env -i -S node --loader tsm\nhello();",
},
{
name: "string-bin/bin/test.js",
filename: fixture("string-bin/bin/test.js"),
code: "#!/usr/bin/env --block-signal=SIGINT -S FOO=bar node --loader tsm\nhello();",
},
{
name: "object-bin/bin/c.js",
filename: fixture("object-bin/bin/c.js"),
Expand Down

0 comments on commit b383b49

Please sign in to comment.