Comparing version 2.0.1 to 3.0.0
51
index.js
'use strict'; | ||
var path = require('path'); | ||
var childProcess = require('child_process'); | ||
var objectAssign = require('object-assign'); | ||
module.exports = function (target, app, cb) { | ||
module.exports = function (target, opts, cb) { | ||
if (typeof target !== 'string') { | ||
@@ -10,14 +11,17 @@ throw new Error('Expected a `target`'); | ||
if (typeof app === 'function') { | ||
cb = app; | ||
app = null; | ||
if (typeof opts === 'function') { | ||
cb = opts; | ||
opts = null; | ||
} | ||
opts = objectAssign({wait: true}, opts); | ||
var cmd; | ||
var appArgs; | ||
var args = []; | ||
var cpOpts = {}; | ||
if (Array.isArray(app)) { | ||
appArgs = app.slice(1); | ||
app = app[0]; | ||
if (Array.isArray(opts.app)) { | ||
appArgs = opts.app.slice(1); | ||
opts.app = opts.app[0]; | ||
} | ||
@@ -28,12 +32,12 @@ | ||
if (cb) { | ||
if (cb && opts.wait) { | ||
args.push('-W'); | ||
} | ||
if (app) { | ||
args.push('-a', app); | ||
if (opts.app) { | ||
args.push('-a', opts.app); | ||
} | ||
if (appArgs) { | ||
args.push('--args') | ||
args.push('--args'); | ||
args = args.concat(appArgs); | ||
@@ -46,8 +50,8 @@ } | ||
if (cb) { | ||
if (cb && opts.wait) { | ||
args.push('/wait'); | ||
} | ||
if (app) { | ||
args.push(app); | ||
if (opts.app) { | ||
args.push(opts.app); | ||
} | ||
@@ -59,4 +63,4 @@ | ||
} else { | ||
if (app) { | ||
cmd = app; | ||
if (opts.app) { | ||
cmd = opts.app; | ||
} else { | ||
@@ -69,2 +73,8 @@ cmd = path.join(__dirname, 'xdg-open'); | ||
} | ||
if (!(cb && opts.wait)) { | ||
// xdg-open will block the process unless | ||
// stdio is ignored even if it's unref'd | ||
cpOpts.stdio = 'ignore'; | ||
} | ||
} | ||
@@ -74,11 +84,4 @@ | ||
var opts = {}; | ||
var cp = childProcess.spawn(cmd, args, cpOpts); | ||
if (!cb) { | ||
// xdg-open will block the process unless stdio is ignored even if it's unref()'d | ||
opts.stdio = 'ignore'; | ||
} | ||
var cp = childProcess.spawn(cmd, args, opts); | ||
if (cb) { | ||
@@ -85,0 +88,0 @@ cp.once('error', cb); |
{ | ||
"name": "opn", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "A better node-open. Opens stuff like websites, files, executables. Cross-platform.", | ||
"license": "MIT", | ||
"repository": "sindresorhus/opn", | ||
"bin": "cli.js", | ||
"author": { | ||
@@ -20,3 +19,2 @@ "name": "Sindre Sorhus", | ||
"files": [ | ||
"cli.js", | ||
"index.js", | ||
@@ -26,4 +24,2 @@ "xdg-open" | ||
"keywords": [ | ||
"cli-app", | ||
"cli", | ||
"app", | ||
@@ -56,3 +52,3 @@ "open", | ||
"dependencies": { | ||
"meow": "^3.3.0" | ||
"object-assign": "^3.0.0" | ||
}, | ||
@@ -59,0 +55,0 @@ "devDependencies": { |
@@ -1,2 +0,2 @@ | ||
# opn | ||
# opn [![Build Status](https://travis-ci.org/sindresorhus/opn.svg?branch=master)](https://travis-ci.org/sindresorhus/opn) | ||
@@ -12,3 +12,2 @@ > A better [node-open](https://github.com/pwnall/node-open). Opens stuff like websites, files, executables. Cross-platform. | ||
- Fixes most of the open `node-open` issues | ||
- Comes with a CLI for use in your scripts | ||
- Includes the latest [`xdg-open` script](http://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18) for Linux | ||
@@ -47,3 +46,3 @@ | ||
### opn(target, [app], [callback]) | ||
### opn(target, [options], [callback]) | ||
@@ -54,3 +53,3 @@ Returns the [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You'd normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process. | ||
*Required* | ||
*Required* | ||
Type: `string` | ||
@@ -62,4 +61,17 @@ | ||
#### app | ||
#### options | ||
Type: `object` | ||
##### wait | ||
Type: `boolean` | ||
Default: `true` | ||
Wait for the opened app to exit before calling the `callback`. If `false` it's called immediately when opening the app. | ||
On Windows you have to explicitly specify an app for it to be able to wait. | ||
##### app | ||
Type: `string`, `array` | ||
@@ -75,29 +87,12 @@ | ||
Called when the opened app exits. | ||
Called when the opened app exits, or if `wait: false`, immediately when opening. | ||
On Windows you have to explicitly specify an app for it to be able to wait. | ||
## Related | ||
## CLI | ||
- [opn-cli](https://github.com/sindresorhus/opn-cli) - CLI for this module | ||
``` | ||
$ npm install --global opn | ||
``` | ||
``` | ||
$ opn --help | ||
Usage | ||
$ opn <file|url> [app] [app arguments] | ||
Example | ||
$ opn http://sindresorhus.com | ||
$ opn http://sindresorhus.com firefox | ||
$ opn http://sindresorhus.com 'google chrome' --incognito | ||
$ opn unicorn.png | ||
``` | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27481
5
77
94
+ Addedobject-assign@^3.0.0
+ Addedobject-assign@3.0.0(transitive)
- Removedmeow@^3.3.0
- Removedarray-find-index@1.0.2(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedmap-obj@1.0.1(transitive)
- Removedmeow@3.7.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtrim-newlines@1.0.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)