Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zkochan/cmd-shim

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zkochan/cmd-shim - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

205

index.js

@@ -0,1 +1,2 @@

'use strict'
// On windows, create a .cmd file.

@@ -14,17 +15,13 @@ // Read the #! in the file to see what it uses. The vast majority

var fs = require("graceful-fs")
const fs = require('mz/fs')
var mkdir = require("mkdirp")
, path = require("path")
, shebangExpr = /^#\!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+)(.*)$/
const mkdir = require('mkdirp-promise/lib/node4')
const path = require('path')
const shebangExpr = /^#!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+)(.*)$/
function cmdShimIfExists (from, to, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = {}
}
fs.stat(from, function (er) {
if (er) return cb()
cmdShim(from, to, opts, cb)
})
function cmdShimIfExists (src, to, opts) {
opts = opts || {}
return fs.stat(src)
.then(() => cmdShim(src, to, opts))
.catch(() => {})
}

@@ -34,33 +31,19 @@

// Any problems will surface later.
function rm (path, cb) {
fs.unlink(path, function(er) {
cb()
})
function rm (path) {
return fs.unlink(path).catch(() => {})
}
function cmdShim (from, to, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = {}
}
fs.stat(from, function (er, stat) {
if (er)
return cb(er)
cmdShim_(from, to, opts, cb)
})
function cmdShim (src, to, opts) {
opts = opts || {}
return fs.stat(src)
.then(() => cmdShim_(src, to, opts))
}
function cmdShim_ (from, to, opts, cb) {
var then = times(2, next, cb)
rm(to, then)
rm(to + ".cmd", then)
function next(er) {
writeShim(from, to, opts, cb)
}
function cmdShim_ (src, to, opts) {
return Promise.all([rm(to), rm(`${to}.cmd`)])
.then(() => writeShim(src, to, opts))
}
function writeShim (from, to, opts, cb) {
var defaultArgs = opts && opts.preserveSymlinks ? "--preserve-symlinks" : ""
function writeShim (src, to, opts) {
const defaultArgs = opts && opts.preserveSymlinks ? '--preserve-symlinks' : ''
// make a cmd file and a sh script

@@ -70,36 +53,36 @@ // First, check if the bin is a #! of some sort.

// sort of script, and just call it directly.
mkdir(path.dirname(to), function (er) {
if (er)
return cb(er)
fs.readFile(from, "utf8", function (er, data) {
if (er) return writeShim_(from, to, null, defaultArgs, cb)
var firstLine = data.trim().split(/\r*\n/)[0]
, shebang = firstLine.match(shebangExpr)
if (!shebang) return writeShim_(from, to, null, defaultArgs, cb)
var prog = shebang[1]
, args = shebang[2] && (defaultArgs && (shebang[2] + " " + defaultArgs) || shebang[2]) || defaultArgs
return writeShim_(from, to, prog, args, cb)
return mkdir(path.dirname(to))
.then(() => {
return fs.readFile(src, 'utf8')
.then(data => {
const firstLine = data.trim().split(/\r*\n/)[0]
const shebang = firstLine.match(shebangExpr)
if (!shebang) return writeShim_(src, to, null, defaultArgs)
const prog = shebang[1]
const args = shebang[2] && (defaultArgs && (shebang[2] + ' ' + defaultArgs) || shebang[2]) || defaultArgs
return writeShim_(src, to, prog, args)
})
.catch(() => writeShim_(src, to, null, defaultArgs))
})
})
}
function writeShim_ (from, to, prog, args, cb) {
var shTarget = path.relative(path.dirname(to), from)
, target = shTarget.split("/").join("\\")
, longProg
, shProg = prog && prog.split("\\").join("/")
, shLongProg
shTarget = shTarget.split("\\").join("/")
args = args || ""
function writeShim_ (src, to, prog, args) {
let shTarget = path.relative(path.dirname(to), src)
let target = shTarget.split('/').join('\\')
let longProg
let shProg = prog && prog.split('\\').join('/')
let shLongProg
shTarget = shTarget.split('\\').join('/')
args = args || ''
if (!prog) {
prog = "\"%~dp0\\" + target + "\""
shProg = "\"$basedir/" + shTarget + "\""
args = ""
target = ""
shTarget = ""
prog = `"%~dp0\\${target}"`
shProg = `"$basedir/${shTarget}"`
args = ''
target = ''
shTarget = ''
} else {
longProg = "\"%~dp0\\" + prog + ".exe\""
shLongProg = "\"$basedir/" + prog + "\""
target = "\"%~dp0\\" + target + "\""
shTarget = "\"$basedir/" + shTarget + "\""
longProg = `"%~dp0\\${prog}.exe"`
shLongProg = '"$basedir/' + prog + '"'
target = `"%~dp0\\${target}"`
shTarget = `"$basedir/${shTarget}"`
}

@@ -114,13 +97,13 @@

// )
var cmd
let cmd
if (longProg) {
cmd = "@IF EXIST " + longProg + " (\r\n"
+ " " + longProg + " " + args + " " + target + " %*\r\n"
+ ") ELSE (\r\n"
+ " @SETLOCAL\r\n"
+ " @SET PATHEXT=%PATHEXT:;.JS;=;%\r\n"
+ " " + prog + " " + args + " " + target + " %*\r\n"
+ ")"
cmd = '@IF EXIST ' + longProg + ' (\r\n' +
' ' + longProg + ' ' + args + ' ' + target + ' %*\r\n' +
') ELSE (\r\n' +
' @SETLOCAL\r\n' +
' @SET PATHEXT=%PATHEXT:;.JS;=;%\r\n' +
' ' + prog + ' ' + args + ' ' + target + ' %*\r\n' +
')'
} else {
cmd = "@" + prog + " " + args + " " + target + " %*\r\n"
cmd = `@${prog} ${args} ${target} %*\r\n`
}

@@ -144,51 +127,39 @@

var sh = "#!/bin/sh\n"
let sh = '#!/bin/sh\n'
if (shLongProg) {
sh = sh
+ "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n"
+ "\n"
+ "case `uname` in\n"
+ " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n"
+ "esac\n"
+ "\n"
sh = sh +
"basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n" +
'\n' +
'case `uname` in\n' +
' *CYGWIN*) basedir=`cygpath -w "$basedir"`;;\n' +
'esac\n' +
'\n'
sh = sh
+ "if [ -x "+shLongProg+" ]; then\n"
+ " " + shLongProg + " " + args + " " + shTarget + " \"$@\"\n"
+ " ret=$?\n"
+ "else \n"
+ " " + shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ " ret=$?\n"
+ "fi\n"
+ "exit $ret\n"
sh = sh +
'if [ -x ' + shLongProg + ' ]; then\n' +
' ' + shLongProg + ' ' + args + ' ' + shTarget + ' "$@"\n' +
' ret=$?\n' +
'else \n' +
' ' + shProg + ' ' + args + ' ' + shTarget + ' "$@"\n' +
' ret=$?\n' +
'fi\n' +
'exit $ret\n'
} else {
sh = shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ "exit $?\n"
sh = shProg + ' ' + args + ' ' + shTarget + ' "$@"\n' +
'exit $?\n'
}
var then = times(2, next, cb)
fs.writeFile(to + ".cmd", cmd, "utf8", then)
fs.writeFile(to, sh, "utf8", then)
function next () {
chmodShim(to, cb)
}
return Promise.all([
fs.writeFile(to + '.cmd', cmd, 'utf8'),
fs.writeFile(to, sh, 'utf8')
])
.then(() => chmodShim(to))
}
function chmodShim (to, cb) {
var then = times(2, cb, cb)
fs.chmod(to, 0755, then)
fs.chmod(to + ".cmd", 0755, then)
function chmodShim (to) {
return Promise.all([
fs.chmod(to, 0o755),
fs.chmod(`${to}.cmd`, 0o755)
])
}
function times(n, ok, cb) {
var errState = null
return function(er) {
if (!errState) {
if (er)
cb(errState = er)
else if (--n === 0)
ok()
}
}
}
{
"name": "@zkochan/cmd-shim",
"version": "1.0.0",
"description": "Used in npm for command line application support",
"version": "2.0.0",
"description": "Used in pnpm for command line application support",
"author": {
"name": "Zoltan Kochan",
"email": "zoltan.kochan@gmail.com",
"url": "http://kochan.io"
},
"scripts": {
"test": "tap test/*.js && mos test"
"test:unit": "tape test/*.js | tap-diff",
"test": "standard && npm run test:unit && mos test",
"md": "mos"
},

@@ -14,10 +21,23 @@ "repository": {

"dependencies": {
"graceful-fs": "^4.1.2",
"mkdirp": "~0.5.0"
"mkdirp": "^0.5.1",
"mkdirp-promise": "^4.0.0",
"mz": "^2.5.0"
},
"devDependencies": {
"mos": "^1.3.1",
"mos-plugin-readme": "^1.0.4",
"rimraf": "~2.2.8",
"tap": "~0.4.11"
"standard": "^8.5.0",
"tap-diff": "^0.1.1",
"tape": "^4.6.2",
"tape-promise": "^2.0.0"
},
"engines": {
"node": ">=4"
},
"mos": {
"plugins": [
"readme"
]
}
}
# @zkochan/cmd-shim
The cmd-shim used in npm to create executable scripts on Windows,
since symlinks are not suitable for this purpose there.
> Used in pnpm for command line application support
On Unix systems, you should use a symbolic link instead.
<!--@shields('travis', 'npm')-->

@@ -12,2 +9,7 @@ [![Build Status](https://img.shields.io/travis/zkochan/cmd-shim/master.svg)](https://travis-ci.org/zkochan/cmd-shim) [![npm version](https://img.shields.io/npm/v/@zkochan/cmd-shim.svg)](https://www.npmjs.com/package/@zkochan/cmd-shim)

The cmd-shim used in [pnpm](https://github.com/rstacruz/pnpm) to create executable scripts on Windows,
since symlinks are not suitable for this purpose there.
On Unix systems, you should use a symbolic link instead.
## Installation

@@ -21,3 +23,3 @@

### cmdShim(from, to, opts?, cb)
### `cmdShim(src, to, opts?): Promise<void>`

@@ -28,31 +30,23 @@ Create a cmd shim at `to` for the command line program at `from`.

```javascript
var cmdShim = require('@zkochan/cmd-shim');
cmdShim(__dirname + '/cli.js', '/usr/bin/command-name', function (err) {
if (err) throw err;
});
const cmdShim = require('@zkochan/cmd-shim')
cmdShim(__dirname + '/cli.js', '/usr/bin/command-name')
.catch(err => console.error(err))
```
### cmdShim.ifExists(from, to, opts?, cb)
### `cmdShim.ifExists(src, to, opts?): Promise<void>`
The same as above, but will just continue if the file does not exist.
Source:
```javascript
function cmdShimIfExists (from, to, cb) {
fs.stat(from, function (er) {
if (er) return cb()
cmdShim(from, to, cb)
})
}
```
#### Arguments:
### opts
- `opts.preserveSymlinks` - _Boolean_ - if true, `--preserve-symlinks` is added to the options passed to NodeJS.
```javascript
var cmdShim = require('@zkochan/cmd-shim');
cmdShim(__dirname + '/cli.js', '/usr/bin/command-name', { preserveSymlinks: true }, function (err) {
if (err) throw err;
});
const cmdShim = require('@zkochan/cmd-shim')
cmdShim(__dirname + '/cli.js', '/usr/bin/command-name', { preserveSymlinks: true })
.catch(err => console.error(err))
```
## License
[BSD-2-Clause](./LICENSE) © [Zoltan Kochan](http://kochan.io)

@@ -1,34 +0,32 @@

var test = require('tap').test
var mkdirp = require('mkdirp')
var fs = require('fs')
var path = require('path')
var fixtures = path.resolve(__dirname, 'fixtures')
'use strict'
const tape = require('tape')
const promisifyTape = require('tape-promise').default
const test = promisifyTape(tape)
const mkdirp = require('mkdirp-promise/lib/node4')
const fs = require('fs')
const path = require('path')
const fixtures = path.resolve(__dirname, 'fixtures')
var froms = {
'from.exe': 'exe',
'from.env': '#!/usr/bin/env node\nconsole.log(/hi/)\n',
'from.env.args': '#!/usr/bin/env node --expose_gc\ngc()\n',
'from.sh': '#!/usr/bin/sh\necho hi\n',
'from.sh.args': '#!/usr/bin/sh -x\necho hi\n'
const srcs = {
'src.exe': 'exe',
'src.env': '#!/usr/bin/env node\nconsole.log(/hi/)\n',
'src.env.args': '#!/usr/bin/env node --expose_gc\ngc()\n',
'src.sh': '#!/usr/bin/sh\necho hi\n',
'src.sh.args': '#!/usr/bin/sh -x\necho hi\n'
}
var cmdShim = require('../')
test('create fixture', function (t) {
mkdirp(fixtures, function (er) {
if (er)
throw er
t.pass('made dir')
Object.keys(froms).forEach(function (f) {
t.test('write ' + f, function (t) {
fs.writeFile(path.resolve(fixtures, f), froms[f], function (er) {
if (er)
throw er
t.pass('wrote ' + f)
t.end()
return mkdirp(fixtures)
.then(() => {
t.pass('made dir')
Object.keys(srcs).forEach(function (f) {
t.test('write ' + f, function (t) {
fs.writeFile(path.resolve(fixtures, f), srcs[f], function (er) {
if (er) { throw er }
t.pass('wrote ' + f)
t.end()
})
})
})
})
t.end()
})
})

@@ -1,213 +0,208 @@

var test = require('tap').test
var mkdirp = require('mkdirp')
var fs = require('fs')
var path = require('path')
var fixtures = path.resolve(__dirname, 'fixtures')
'use strict'
const tape = require('tape')
const promisifyTape = require('tape-promise').default
const test = promisifyTape(tape)
const fs = require('fs')
const path = require('path')
const fixtures = path.resolve(__dirname, 'fixtures')
var cmdShim = require('../')
const cmdShim = require('../')
test('no shebang', function (t) {
var from = path.resolve(fixtures, 'from.exe')
var to = path.resolve(fixtures, 'exe.shim')
cmdShim(from, to, function(er) {
if (er)
throw er
t.equal(fs.readFileSync(to, 'utf8'),
"\"$basedir/from.exe\" \"$@\"\nexit $?\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
"@\"%~dp0\\from.exe\" %*\r\n")
t.end()
})
const src = path.resolve(fixtures, 'src.exe')
const to = path.resolve(fixtures, 'exe.shim')
return cmdShim(src, to)
.then(function () {
t.equal(fs.readFileSync(to, 'utf8'),
'"$basedir/src.exe" "$@"\nexit $?\n')
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
'@"%~dp0\\src.exe" %*\r\n')
})
})
test('env shebang', function (t) {
var from = path.resolve(fixtures, 'from.env')
var to = path.resolve(fixtures, 'env.shim')
cmdShim(from, to, function(er) {
if (er)
throw er
console.error('%j', fs.readFileSync(to, 'utf8'))
console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
const src = path.resolve(fixtures, 'src.env')
const to = path.resolve(fixtures, 'env.shim')
return cmdShim(src, to)
.then(() => {
console.error('%j', fs.readFileSync(to, 'utf8'))
console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
t.equal(fs.readFileSync(to, 'utf8'),
"#!/bin/sh"+
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+
"\n"+
"\ncase `uname` in"+
"\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+
"\nesac"+
"\n"+
"\nif [ -x \"$basedir/node\" ]; then"+
"\n \"$basedir/node\" \"$basedir/from.env\" \"$@\""+
"\n ret=$?"+
"\nelse "+
"\n node \"$basedir/from.env\" \"$@\""+
"\n ret=$?"+
"\nfi"+
"\nexit $ret"+
"\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
"@IF EXIST \"%~dp0\\node.exe\" (\r"+
"\n \"%~dp0\\node.exe\" \"%~dp0\\from.env\" %*\r"+
"\n) ELSE (\r"+
"\n @SETLOCAL\r"+
"\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
"\n node \"%~dp0\\from.env\" %*\r"+
"\n)")
t.end()
})
t.equal(fs.readFileSync(to, 'utf8'),
'#!/bin/sh' +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
'\n' +
'\ncase `uname` in' +
'\n *CYGWIN*) basedir=`cygpath -w "$basedir"`;;' +
'\nesac' +
'\n' +
'\nif [ -x "$basedir/node" ]; then' +
'\n "$basedir/node" "$basedir/src.env" "$@"' +
'\n ret=$?' +
'\nelse ' +
'\n node "$basedir/src.env" "$@"' +
'\n ret=$?' +
'\nfi' +
'\nexit $ret' +
'\n')
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
'@IF EXIST "%~dp0\\node.exe" (\r' +
'\n "%~dp0\\node.exe" "%~dp0\\src.env" %*\r' +
'\n) ELSE (\r' +
'\n @SETLOCAL\r' +
'\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r' +
'\n node "%~dp0\\src.env" %*\r' +
'\n)')
t.end()
})
})
test('env shebang with default args', function (t) {
var from = path.resolve(fixtures, 'from.env')
var to = path.resolve(fixtures, 'env.shim')
cmdShim(from, to, { preserveSymlinks: true }, function(er) {
if (er)
throw er
console.error('%j', fs.readFileSync(to, 'utf8'))
console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
const src = path.resolve(fixtures, 'src.env')
const to = path.resolve(fixtures, 'env.shim')
return cmdShim(src, to, { preserveSymlinks: true })
.then(() => {
console.error('%j', fs.readFileSync(to, 'utf8'))
console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
t.equal(fs.readFileSync(to, 'utf8'),
"#!/bin/sh"+
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+
"\n"+
"\ncase `uname` in"+
"\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+
"\nesac"+
"\n"+
"\nif [ -x \"$basedir/node\" ]; then"+
"\n \"$basedir/node\" --preserve-symlinks \"$basedir/from.env\" \"$@\""+
"\n ret=$?"+
"\nelse "+
"\n node --preserve-symlinks \"$basedir/from.env\" \"$@\""+
"\n ret=$?"+
"\nfi"+
"\nexit $ret"+
"\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
"@IF EXIST \"%~dp0\\node.exe\" (\r"+
"\n \"%~dp0\\node.exe\" --preserve-symlinks \"%~dp0\\from.env\" %*\r"+
"\n) ELSE (\r"+
"\n @SETLOCAL\r"+
"\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
"\n node --preserve-symlinks \"%~dp0\\from.env\" %*\r"+
"\n)")
t.end()
})
t.equal(fs.readFileSync(to, 'utf8'),
'#!/bin/sh' +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
'\n' +
'\ncase `uname` in' +
'\n *CYGWIN*) basedir=`cygpath -w "$basedir"`;;' +
'\nesac' +
'\n' +
'\nif [ -x "$basedir/node" ]; then' +
'\n "$basedir/node" --preserve-symlinks "$basedir/src.env" "$@"' +
'\n ret=$?' +
'\nelse ' +
'\n node --preserve-symlinks "$basedir/src.env" "$@"' +
'\n ret=$?' +
'\nfi' +
'\nexit $ret' +
'\n')
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
'@IF EXIST "%~dp0\\node.exe" (\r' +
'\n "%~dp0\\node.exe" --preserve-symlinks "%~dp0\\src.env" %*\r' +
'\n) ELSE (\r' +
'\n @SETLOCAL\r' +
'\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r' +
'\n node --preserve-symlinks "%~dp0\\src.env" %*\r' +
'\n)')
t.end()
})
})
test('env shebang with args', function (t) {
var from = path.resolve(fixtures, 'from.env.args')
var to = path.resolve(fixtures, 'env.args.shim')
cmdShim(from, to, function(er) {
if (er)
throw er
console.error('%j', fs.readFileSync(to, 'utf8'))
console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
const src = path.resolve(fixtures, 'src.env.args')
const to = path.resolve(fixtures, 'env.args.shim')
return cmdShim(src, to)
.then(() => {
console.error('%j', fs.readFileSync(to, 'utf8'))
console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
t.equal(fs.readFileSync(to, 'utf8'),
"#!/bin/sh"+
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+
"\n"+
"\ncase `uname` in"+
"\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+
"\nesac"+
"\n"+
"\nif [ -x \"$basedir/node\" ]; then"+
"\n \"$basedir/node\" --expose_gc \"$basedir/from.env.args\" \"$@\""+
"\n ret=$?"+
"\nelse "+
"\n node --expose_gc \"$basedir/from.env.args\" \"$@\""+
"\n ret=$?"+
"\nfi"+
"\nexit $ret"+
"\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
"@IF EXIST \"%~dp0\\node.exe\" (\r"+
"\n \"%~dp0\\node.exe\" --expose_gc \"%~dp0\\from.env.args\" %*\r"+
"\n) ELSE (\r"+
"\n @SETLOCAL\r"+
"\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
"\n node --expose_gc \"%~dp0\\from.env.args\" %*\r"+
"\n)")
t.end()
})
t.equal(fs.readFileSync(to, 'utf8'),
'#!/bin/sh' +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
'\n' +
'\ncase `uname` in' +
'\n *CYGWIN*) basedir=`cygpath -w "$basedir"`;;' +
'\nesac' +
'\n' +
'\nif [ -x "$basedir/node" ]; then' +
'\n "$basedir/node" --expose_gc "$basedir/src.env.args" "$@"' +
'\n ret=$?' +
'\nelse ' +
'\n node --expose_gc "$basedir/src.env.args" "$@"' +
'\n ret=$?' +
'\nfi' +
'\nexit $ret' +
'\n')
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
'@IF EXIST "%~dp0\\node.exe" (\r' +
'\n "%~dp0\\node.exe" --expose_gc "%~dp0\\src.env.args" %*\r' +
'\n) ELSE (\r' +
'\n @SETLOCAL\r' +
'\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r' +
'\n node --expose_gc "%~dp0\\src.env.args" %*\r' +
'\n)')
t.end()
})
})
test('explicit shebang', function (t) {
var from = path.resolve(fixtures, 'from.sh')
var to = path.resolve(fixtures, 'sh.shim')
cmdShim(from, to, function(er) {
if (er)
throw er
console.error('%j', fs.readFileSync(to, 'utf8'))
console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
const src = path.resolve(fixtures, 'src.sh')
const to = path.resolve(fixtures, 'sh.shim')
return cmdShim(src, to)
.then(() => {
console.error('%j', fs.readFileSync(to, 'utf8'))
console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
t.equal(fs.readFileSync(to, 'utf8'),
"#!/bin/sh" +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
"\n" +
"\ncase `uname` in" +
"\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" +
"\nesac" +
"\n" +
"\nif [ -x \"$basedir//usr/bin/sh\" ]; then" +
"\n \"$basedir//usr/bin/sh\" \"$basedir/from.sh\" \"$@\"" +
"\n ret=$?" +
"\nelse " +
"\n /usr/bin/sh \"$basedir/from.sh\" \"$@\"" +
"\n ret=$?" +
"\nfi" +
"\nexit $ret" +
"\n")
t.equal(fs.readFileSync(to, 'utf8'),
'#!/bin/sh' +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
'\n' +
'\ncase `uname` in' +
'\n *CYGWIN*) basedir=`cygpath -w "$basedir"`;;' +
'\nesac' +
'\n' +
'\nif [ -x "$basedir//usr/bin/sh" ]; then' +
'\n "$basedir//usr/bin/sh" "$basedir/src.sh" "$@"' +
'\n ret=$?' +
'\nelse ' +
'\n /usr/bin/sh "$basedir/src.sh" "$@"' +
'\n ret=$?' +
'\nfi' +
'\nexit $ret' +
'\n')
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
"@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" +
"\n \"%~dp0\\/usr/bin/sh.exe\" \"%~dp0\\from.sh\" %*\r" +
"\n) ELSE (\r" +
"\n @SETLOCAL\r"+
"\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
"\n /usr/bin/sh \"%~dp0\\from.sh\" %*\r" +
"\n)")
t.end()
})
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
'@IF EXIST "%~dp0\\/usr/bin/sh.exe" (\r' +
'\n "%~dp0\\/usr/bin/sh.exe" "%~dp0\\src.sh" %*\r' +
'\n) ELSE (\r' +
'\n @SETLOCAL\r' +
'\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r' +
'\n /usr/bin/sh "%~dp0\\src.sh" %*\r' +
'\n)')
t.end()
})
})
test('explicit shebang with args', function (t) {
var from = path.resolve(fixtures, 'from.sh.args')
var to = path.resolve(fixtures, 'sh.args.shim')
cmdShim(from, to, function(er) {
if (er)
throw er
console.error('%j', fs.readFileSync(to, 'utf8'))
console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
const src = path.resolve(fixtures, 'src.sh.args')
const to = path.resolve(fixtures, 'sh.args.shim')
return cmdShim(src, to)
.then(() => {
console.error('%j', fs.readFileSync(to, 'utf8'))
console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
t.equal(fs.readFileSync(to, 'utf8'),
"#!/bin/sh" +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
"\n" +
"\ncase `uname` in" +
"\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" +
"\nesac" +
"\n" +
"\nif [ -x \"$basedir//usr/bin/sh\" ]; then" +
"\n \"$basedir//usr/bin/sh\" -x \"$basedir/from.sh.args\" \"$@\"" +
"\n ret=$?" +
"\nelse " +
"\n /usr/bin/sh -x \"$basedir/from.sh.args\" \"$@\"" +
"\n ret=$?" +
"\nfi" +
"\nexit $ret" +
"\n")
t.equal(fs.readFileSync(to, 'utf8'),
'#!/bin/sh' +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
'\n' +
'\ncase `uname` in' +
'\n *CYGWIN*) basedir=`cygpath -w "$basedir"`;;' +
'\nesac' +
'\n' +
'\nif [ -x "$basedir//usr/bin/sh" ]; then' +
'\n "$basedir//usr/bin/sh" -x "$basedir/src.sh.args" "$@"' +
'\n ret=$?' +
'\nelse ' +
'\n /usr/bin/sh -x "$basedir/src.sh.args" "$@"' +
'\n ret=$?' +
'\nfi' +
'\nexit $ret' +
'\n')
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
"@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" +
"\n \"%~dp0\\/usr/bin/sh.exe\" -x \"%~dp0\\from.sh.args\" %*\r" +
"\n) ELSE (\r" +
"\n @SETLOCAL\r"+
"\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
"\n /usr/bin/sh -x \"%~dp0\\from.sh.args\" %*\r" +
"\n)")
t.end()
})
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
'@IF EXIST "%~dp0\\/usr/bin/sh.exe" (\r' +
'\n "%~dp0\\/usr/bin/sh.exe" -x "%~dp0\\src.sh.args" %*\r' +
'\n) ELSE (\r' +
'\n @SETLOCAL\r' +
'\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r' +
'\n /usr/bin/sh -x "%~dp0\\src.sh.args" %*\r' +
'\n)')
t.end()
})
})

@@ -1,10 +0,12 @@

var test = require('tap').test
var path = require('path')
var fixtures = path.resolve(__dirname, 'fixtures')
var rimraf = require('rimraf')
'use strict'
const tape = require('tape')
const promisifyTape = require('tape-promise').default
const test = promisifyTape(tape)
const path = require('path')
const fixtures = path.resolve(__dirname, 'fixtures')
const rimraf = require('rimraf')
test('cleanup', function(t) {
rimraf(fixtures, function(er) {
if (er)
throw er
test('cleanup', function (t) {
rimraf(fixtures, function (er) {
if (er) { throw er }
t.pass('cleaned up')

@@ -11,0 +13,0 @@ t.end()

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc