From 2dd8328593142466332e24d6b4b095f633f16dd7 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/hashbang.js | 3 ++- tests/lib/rules/hashbang.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/rules/hashbang.js b/lib/rules/hashbang.js index 5c472053..8baee0a0 100644 --- a/lib/rules/hashbang.js +++ b/lib/rules/hashbang.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/hashbang.js b/tests/lib/rules/hashbang.js index f0e0f9c1..f2640679 100644 --- a/tests/lib/rules/hashbang.js +++ b/tests/lib/rules/hashbang.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"),