Comparing version 3.0.3 to 4.0.0
40
index.js
@@ -5,13 +5,9 @@ 'use strict'; | ||
var objectAssign = require('object-assign'); | ||
var Promise = require('pinkie-promise'); | ||
module.exports = function (target, opts, cb) { | ||
module.exports = function (target, opts) { | ||
if (typeof target !== 'string') { | ||
throw new Error('Expected a `target`'); | ||
return Promise.reject(new Error('Expected a `target`')); | ||
} | ||
if (typeof opts === 'function') { | ||
cb = opts; | ||
opts = null; | ||
} | ||
opts = objectAssign({wait: true}, opts); | ||
@@ -32,3 +28,3 @@ | ||
if (cb && opts.wait) { | ||
if (opts.wait) { | ||
args.push('-W'); | ||
@@ -50,3 +46,3 @@ } | ||
if (cb && opts.wait) { | ||
if (opts.wait) { | ||
args.push('/wait'); | ||
@@ -73,3 +69,3 @@ } | ||
if (!(cb && opts.wait)) { | ||
if (!opts.wait) { | ||
// xdg-open will block the process unless | ||
@@ -85,18 +81,20 @@ // stdio is ignored even if it's unref'd | ||
if (cb) { | ||
cp.once('error', cb); | ||
if (opts.wait) { | ||
return new Promise(function (resolve, reject) { | ||
cp.once('error', reject); | ||
cp.once('close', function (code) { | ||
if (code > 0) { | ||
cb(new Error('Exited with code ' + code)); | ||
return; | ||
} | ||
cp.once('close', function (code) { | ||
if (code > 0) { | ||
reject(new Error('Exited with code ' + code)); | ||
return; | ||
} | ||
cb(); | ||
resolve(cp); | ||
}); | ||
}); | ||
} else { | ||
cp.unref(); | ||
} | ||
return cp; | ||
cp.unref(); | ||
return Promise.resolve(cp); | ||
}; |
{ | ||
"name": "opn", | ||
"version": "3.0.3", | ||
"version": "4.0.0", | ||
"description": "A better node-open. Opens stuff like websites, files, executables. Cross-platform.", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "xo && ava" | ||
}, | ||
@@ -51,7 +51,9 @@ "files": [ | ||
"dependencies": { | ||
"object-assign": "^4.0.1" | ||
"object-assign": "^4.0.1", | ||
"pinkie-promise": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
@@ -25,15 +25,17 @@ # opn | ||
```js | ||
var opn = require('opn'); | ||
const opn = require('opn'); | ||
opn('unicorn.png'); | ||
// opens the image in the default image viewer | ||
opn('unicorn.png').then(() => { | ||
// image viewer closed | ||
}); | ||
// opens the url in the default browser | ||
opn('http://sindresorhus.com'); | ||
// opens the url in the default browser | ||
// specify the app to open in | ||
opn('http://sindresorhus.com', {app: 'firefox'}); | ||
// specify the app to open in | ||
// specify app arguments | ||
opn('http://sindresorhus.com', {app: ['google chrome', '--incognito']}); | ||
// specify app arguments | ||
``` | ||
@@ -46,5 +48,5 @@ | ||
### opn(target, [options], [callback]) | ||
### opn(target, [options]) | ||
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. | ||
Returns a promise for 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. | ||
@@ -81,9 +83,3 @@ #### target | ||
#### callback(error) | ||
Type: `function` | ||
Called when the opened app exits, or if `wait: false`, immediately when opening. | ||
## Related | ||
@@ -90,0 +86,0 @@ |
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
27448
2
2
75
90
+ Addedpinkie-promise@^2.0.0
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)