Socket
Socket
Sign inDemoInstall

opn

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opn - npm Package Compare versions

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)
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