From b383b4971df4f4b67099655797b654b36d6a8fdf Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Tue, 5 Mar 2024 01:24:36 -0800 Subject: [PATCH] feat(shebang): add support for env's split-string option (#195) * 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 --- lib/rules/shebang.js | 3 ++- tests/lib/rules/shebang.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/rules/shebang.js b/lib/rules/shebang.js index c4f9d4ef..0989d50d 100644 --- a/lib/rules/shebang.js +++ b/lib/rules/shebang.js @@ -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] diff --git a/tests/lib/rules/shebang.js b/tests/lib/rules/shebang.js index f0e0f9c1..f2640679 100644 --- a/tests/lib/rules/shebang.js +++ b/tests/lib/rules/shebang.js @@ -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"),