Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop env's -S flag. (#54) #55

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const unlink = promisify(fs.unlink)
const {dirname, relative} = require('path')
const mkdir = require('mkdirp-infer-owner')
const toBatchSyntax = require('./lib/to-batch-syntax')
const shebangExpr = /^#\!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+=[^ \t]+\s+)*\s*([^ \t]+)(.*)$/
const shebangExpr = /^#\!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+=[^ \t]+\s+)*\s*(?:-S)?\s*([^ \t]+)(.*)$/

const cmdShimIfExists = (from, to) =>
stat(from).then(() => cmdShim(from, to), () => {})
Expand Down
69 changes: 69 additions & 0 deletions tap-snapshots/test-basic.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,72 @@ esac
exec "$basedir/from.exe" "$@"

`

exports[`test/basic.js TAP shebang with -S > cmd 1`] = `
@ECHO off\\r
GOTO start\\r
:find_dp0\\r
SET dp0=%~dp0\\r
EXIT /b\\r
:start\\r
SETLOCAL\\r
CALL :find_dp0\\r
\\r
IF EXIST "%dp0%\\node.exe" (\\r
SET "_prog=%dp0%\\node.exe"\\r
) ELSE (\\r
SET "_prog=node"\\r
SET PATHEXT=%PATHEXT:;.JS;=;%\\r
)\\r
\\r
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" --expose_gc "%dp0%\\from.env.S" %*\\r

`

exports[`test/basic.js TAP shebang with -S > ps1 1`] = `
#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent

$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "$basedir/node$exe" --expose_gc "$basedir/from.env.S" $args
} else {
& "$basedir/node$exe" --expose_gc "$basedir/from.env.S" $args
}
$ret=$LASTEXITCODE
} else {
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "node$exe" --expose_gc "$basedir/from.env.S" $args
} else {
& "node$exe" --expose_gc "$basedir/from.env.S" $args
}
$ret=$LASTEXITCODE
}
exit $ret

`

exports[`test/basic.js TAP shebang with -S > shell 1`] = `
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;;
esac

if [ -x "$basedir/node" ]; then
exec "$basedir/node" --expose_gc "$basedir/from.env.S" "$@"
else
exec node --expose_gc "$basedir/from.env.S" "$@"
fi

`
1 change: 1 addition & 0 deletions test/00-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const froms = {
'from.env': '#!/usr/bin/env node\nconsole.log(/hi/)\n',
'from.env.args': '#!/usr/bin/env node --expose_gc\ngc()\n',
'from.env.variables': '#!/usr/bin/env NODE_PATH=./lib:$NODE_PATH node',
'from.env.S': '#!/usr/bin/env -S node --expose_gc\ngc()\n',
'from.sh': '#!/usr/bin/sh\necho hi\n',
'from.sh.args': '#!/usr/bin/sh -x\necho hi\n'
}
Expand Down
10 changes: 10 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,13 @@ test('explicit shebang with args', function (t) {
matchSnapshot(t, fs.readFileSync(to + '.ps1', 'utf8'), 'ps1')
})
})

test('shebang with -S', function (t) {
var from = path.resolve(fixtures, 'from.env.S')
var to = path.resolve(fixtures, 'env.S.shim')
return cmdShim(from, to).then(() => {
matchSnapshot(t, fs.readFileSync(to, 'utf8'), 'shell')
matchSnapshot(t, fs.readFileSync(to + '.cmd', 'utf8'), 'cmd')
matchSnapshot(t, fs.readFileSync(to + '.ps1', 'utf8'), 'ps1')
})
});