From c247a8ff39883e560cc797581bf11c7615750193 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Sun, 3 Mar 2024 20:51:56 -0800 Subject: [PATCH 1/3] feat(shebang): add support for env's split-string option This is useful for passing arguments to node --- lib/rules/shebang.js | 2 +- tests/lib/rules/shebang.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/rules/shebang.js b/lib/rules/shebang.js index c4f9d4ef..a2fc63ec 100644 --- a/lib/rules/shebang.js +++ b/lib/rules/shebang.js @@ -13,7 +13,7 @@ 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)? 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..f122de01 100644 --- a/tests/lib/rules/shebang.js +++ b/tests/lib/rules/shebang.js @@ -41,6 +41,16 @@ 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: "object-bin/bin/c.js", filename: fixture("object-bin/bin/c.js"), From 859d6d1a5ad2a50c2c5b8e2d5a9c760020a0e02c Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Mon, 4 Mar 2024 13:01:21 -0800 Subject: [PATCH 2/3] feat(shebang): support all `env` options --- lib/rules/shebang.js | 3 ++- tests/lib/rules/shebang.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/rules/shebang.js b/lib/rules/shebang.js index a2fc63ec..cee0c1cd 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(?: -S)? 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 f122de01..f2640679 100644 --- a/tests/lib/rules/shebang.js +++ b/tests/lib/rules/shebang.js @@ -51,6 +51,21 @@ ruleTester.run("shebang", rule, { 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"), From 4dfe5627bf7f6a115692ad9117853234d80bba3c Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Mon, 4 Mar 2024 19:08:16 -0800 Subject: [PATCH 3/3] feat(shebang): improve regex performance --- lib/rules/shebang.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/shebang.js b/lib/rules/shebang.js index cee0c1cd..0989d50d 100644 --- a/lib/rules/shebang.js +++ b/lib/rules/shebang.js @@ -14,7 +14,7 @@ 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(?: -\S+)*(?: \S+=\S+)* node(?: [^\r\n]+?)?\n/u + /^#!\/usr\/bin\/env(?: -\S+)*(?: [^\s=-]+=\S+)* node(?: [^\r\n]+?)?\n/u function simulateNodeResolutionAlgorithm(filePath, binField) { const possibilities = [filePath]