add support for env -S = env --split-string, to parse multiple arguments
- Dominant language
- JavaScript
- Stars
- 24
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
actual
```
> shebangCommand('#!/usr/bin/env -S node -v');
'-S'
```
expected
```
> shebangCommand('#!/usr/bin/env -S node -v');
['node', '-v']
```
man env
```
-S, --split-string=S
process and split S into separate arguments; used to pass multiple arguments on shebang lines
```
currently, these shebang parsers fail
- https://www.npmjs.com/package/shebang-command
- https://www.npmjs.com/package/shebang
- https://www.npmjs.com/package/shebang-file
related issues
- https://github.com/pnpm/pnpm/issues/5575
- https://github.com/pnpm/cmd-shim/pull/42
quickfix
```js
function parseShebang(fileText) {
// based on https://github.com/pnpm/cmd-shim
// see also https://github.com/npm/cmd-shim
// examples:
// "#!/bin/sh" -> ["/bin/sh", ""]
// "#! /usr/bin/bash a b c" -> ["/usr/bin/bash", " a b c"]
// "#! /usr/bin/env -S bash a b c" -> ["bash", " a b c"]
// "#! /usr/bin/env -Sbash a b c" -> ["bash", " a b c"]
const shebangExpr = /^#!\s*(?:\/usr\/bin\/env\s+(?:-S)?)?\s*(\S+)(.*)$/;
let firstLineEnd = fileText.indexOf('\n');
if (firstLineEnd == -1) firstLineEnd = fileText.length;
const firstLine = fileText.slice(0, firstLineEnd).trimRight();
const shebang = firstLine.match(shebangExpr);
if (!shebang) return null;
const [_, arg0, args] = shebang;
return [arg0, args];
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the shebangCommand entry point used in the examples and inspect the package's existing parser tests. Cover /usr/bin/env -S forms so the command and multiple arguments match the expected ['node', '-v'] result, then run the test suite.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100