Skip to content

Migrate to a modern Node version #33

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
/* eslint sort-keys: ["error", "asc"] */

module.exports = {
"env": {
"node": true
},
"extends": "eslint:recommended",
"rules": {
"indent": "off",
"linebreak-style": [
"error",
"unix",
],
"no-console": "off",
"no-octal": "off",
"no-unused-vars": "warn",
"quotes": [
"error",
"double",
],
"semi": [
"error",
"never",
],
}
}
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Configuration
sudo: false
language: node_js

node_js:
- "0.10"
- "0.8"
- "stable"
- "lts/*"

before_script:
- "npm run lint"
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ since symlinks are not suitable for this purpose there.

On Unix systems, you should use a symbolic link instead.

[![Build Status](https://img.shields.io/travis/ForbesLindesay/cmd-shim/master.svg)](https://travis-ci.org/ForbesLindesay/cmd-shim)
[![Dependency Status](https://img.shields.io/david/ForbesLindesay/cmd-shim.svg)](https://david-dm.org/ForbesLindesay/cmd-shim)
[![Build Status](https://img.shields.io/travis/npm/cmd-shim/master.svg)](https://travis-ci.org/npm/cmd-shim)
[![Dependency Status](https://img.shields.io/david/npm/cmd-shim.svg)](https://david-dm.org/npm/cmd-shim)
[![NPM version](https://img.shields.io/npm/v/cmd-shim.svg)](https://www.npmjs.com/package/cmd-shim)

## Installation
Expand All @@ -17,7 +17,7 @@ npm install cmd-shim

## API

### cmdShim(from, to, cb)
### `cmdShim(from, to, cb)`

Create a cmd shim at `to` for the command line program at `from`.
e.g.
Expand All @@ -29,7 +29,7 @@ cmdShim(__dirname + '/cli.js', '/usr/bin/command-name', function (err) {
});
```

### cmdShim.ifExists(from, to, cb)
### `cmdShim.ifExists(from, to, cb)`

The same as above, but will just continue if the file does not exist.
Source:
Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var fs = require("graceful-fs")

var mkdir = require("mkdirp")
, path = require("path")
, shebangExpr = /^#\!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+)(.*)$/
, shebangExpr = /^#!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+)(.*)$/

function cmdShimIfExists (from, to, cb) {
fs.stat(from, function (er) {
Expand Down Expand Up @@ -132,12 +132,12 @@ function writeShim_ (from, to, prog, args, cb) {

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"
+ "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"
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.0.2",
"description": "Used in npm for command line application support",
"scripts": {
"lint": "eslint **/*.js",
"test": "tap test/*.js"
},
"repository": {
Expand All @@ -15,7 +16,8 @@
"mkdirp": "~0.5.0"
},
"devDependencies": {
"tap": "~0.4.11",
"rimraf": "~2.2.8"
"eslint": "~4.19.1",
"rimraf": "~2.6.2",
"tap": "~12.0.1"
}
}
}
30 changes: 15 additions & 15 deletions test/00-setup.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
var test = require('tap').test
var mkdirp = require('mkdirp')
var fs = require('fs')
var path = require('path')
var fixtures = path.resolve(__dirname, 'fixtures')
var test = require("tap").test
var mkdirp = require("mkdirp")
var fs = require("fs")
var path = require("path")
var 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'
"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"
}

var cmdShim = require('../')
var cmdShim = require("../")

test('create fixture', function (t) {
test("create fixture", function (t) {
mkdirp(fixtures, function (er) {
if (er)
throw er
t.pass('made dir')
t.pass("made dir")
Object.keys(froms).forEach(function (f) {
t.test('write ' + f, function (t) {
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.pass("wrote " + f)
t.end()
})
})
Expand Down
78 changes: 39 additions & 39 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
var test = require('tap').test
var mkdirp = require('mkdirp')
var fs = require('fs')
var path = require('path')
var fixtures = path.resolve(__dirname, 'fixtures')
var test = require("tap").test
var mkdirp = require("mkdirp")
var fs = require("fs")
var path = require("path")
var fixtures = path.resolve(__dirname, "fixtures")

var cmdShim = require('../')
var cmdShim = require("../")

test('no shebang', function (t) {
var from = path.resolve(fixtures, 'from.exe')
var to = path.resolve(fixtures, 'exe.shim')
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'),
t.equal(fs.readFileSync(to, "utf8"),
"\"$basedir/from.exe\" \"$@\"\nexit $?\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
t.equal(fs.readFileSync(to + ".cmd", "utf8"),
"@\"%~dp0\\from.exe\" %*\r\n")
t.end()
})
})

test('env shebang', function (t) {
var from = path.resolve(fixtures, 'from.env')
var to = path.resolve(fixtures, 'env.shim')
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'))
console.error("%j", fs.readFileSync(to, "utf8"))
console.error("%j", fs.readFileSync(to + ".cmd", "utf8"))

t.equal(fs.readFileSync(to, 'utf8'),
t.equal(fs.readFileSync(to, "utf8"),
"#!/bin/sh"+
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+
"\n"+
Expand All @@ -46,7 +46,7 @@ test('env shebang', function (t) {
"\nfi"+
"\nexit $ret"+
"\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
t.equal(fs.readFileSync(to + ".cmd", "utf8"),
"@IF EXIST \"%~dp0\\node.exe\" (\r"+
"\n \"%~dp0\\node.exe\" \"%~dp0\\from.env\" %*\r"+
"\n) ELSE (\r"+
Expand All @@ -58,16 +58,16 @@ test('env shebang', function (t) {
})
})

test('env shebang with args', function (t) {
var from = path.resolve(fixtures, 'from.env.args')
var to = path.resolve(fixtures, 'env.args.shim')
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'))
console.error("%j", fs.readFileSync(to, "utf8"))
console.error("%j", fs.readFileSync(to + ".cmd", "utf8"))

t.equal(fs.readFileSync(to, 'utf8'),
t.equal(fs.readFileSync(to, "utf8"),
"#!/bin/sh"+
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+
"\n"+
Expand All @@ -84,7 +84,7 @@ test('env shebang with args', function (t) {
"\nfi"+
"\nexit $ret"+
"\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
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"+
Expand All @@ -96,16 +96,16 @@ test('env shebang with args', function (t) {
})
})

test('explicit shebang', function (t) {
var from = path.resolve(fixtures, 'from.sh')
var to = path.resolve(fixtures, 'sh.shim')
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'))
console.error("%j", fs.readFileSync(to, "utf8"))
console.error("%j", fs.readFileSync(to + ".cmd", "utf8"))

t.equal(fs.readFileSync(to, 'utf8'),
t.equal(fs.readFileSync(to, "utf8"),
"#!/bin/sh" +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
"\n" +
Expand All @@ -123,7 +123,7 @@ test('explicit shebang', function (t) {
"\nexit $ret" +
"\n")

t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
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" +
Expand All @@ -135,16 +135,16 @@ test('explicit shebang', function (t) {
})
})

test('explicit shebang with args', function (t) {
var from = path.resolve(fixtures, 'from.sh.args')
var to = path.resolve(fixtures, 'sh.args.shim')
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'))
console.error("%j", fs.readFileSync(to, "utf8"))
console.error("%j", fs.readFileSync(to + ".cmd", "utf8"))

t.equal(fs.readFileSync(to, 'utf8'),
t.equal(fs.readFileSync(to, "utf8"),
"#!/bin/sh" +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
"\n" +
Expand All @@ -162,7 +162,7 @@ test('explicit shebang with args', function (t) {
"\nexit $ret" +
"\n")

t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
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" +
Expand Down
12 changes: 6 additions & 6 deletions test/zz-cleanup.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var test = require('tap').test
var path = require('path')
var fixtures = path.resolve(__dirname, 'fixtures')
var rimraf = require('rimraf')
var test = require("tap").test
var path = require("path")
var fixtures = path.resolve(__dirname, "fixtures")
var rimraf = require("rimraf")

test('cleanup', function(t) {
test("cleanup", function(t) {
rimraf(fixtures, function(er) {
if (er)
throw er
t.pass('cleaned up')
t.pass("cleaned up")
t.end()
})
})