Skip to content

Commit

Permalink
Rename the package from opn to open
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 26, 2019
1 parent 6f68b21 commit eca88d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
7 changes: 3 additions & 4 deletions package.json
@@ -1,9 +1,9 @@
{
"name": "opn",
"name": "open",
"version": "5.5.0",
"description": "A better node-open. Opens stuff like websites, files, executables. Cross-platform.",
"description": "Open stuff like URLs, files, executables. Cross-platform.",
"license": "MIT",
"repository": "sindresorhus/opn",
"repository": "sindresorhus/open",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
Expand All @@ -22,7 +22,6 @@
"keywords": [
"app",
"open",
"opn",
"opener",
"opens",
"launch",
Expand Down
21 changes: 11 additions & 10 deletions readme.md
@@ -1,45 +1,46 @@
# opn
# open

> A better [node-open](https://github.com/pwnall/node-open). Opens stuff like websites, files, executables. Cross-platform.
> Open stuff like URLs, files, executables. Cross-platform.
If need this for Electron, use [`shell.openItem()`](https://electronjs.org/docs/api/shell#shellopenitemfullpath) instead.

Note: The original [`open` package](https://github.com/pwnall/node-open) was recently deprecated in favor of this package, and we got the name, so this package is now named `open` instead of `opn`. If you're upgrading from the original `open` package (`open@0.0.5` or lower), keep in mind that the API is different.

#### Why?

- Actively maintained.
- Supports app arguments.
- Safer as it uses `spawn` instead of `exec`.
- Fixes most of the open `node-open` issues.
- Fixes most of the open original `node-open` issues.
- Includes the latest [`xdg-open` script](http://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18) for Linux.
- Supports WSL paths to Windows apps under `/mnt/*`.


## Install

```
$ npm install opn
$ npm install open
```


## Usage

```js
const open = require('opn');
const open = require('open');

// Opens the image in the default image viewer
(async () => {
await open('unicorn.png', {wait: true});
console.log('The image viewer closed');
console.log('The image viewer app closed');

// Opens the url in the default browser
await open('http://sindresorhus.com');
await open('https://sindresorhus.com');

// Specify the app to open in
await open('http://sindresorhus.com', {app: 'firefox'});
await open('https://sindresorhus.com', {app: 'firefox'});

// Specify app arguments
await open('http://sindresorhus.com', {app: ['google chrome', '--incognito']});
await open('https://sindresorhus.com', {app: ['google chrome', '--incognito']});
})();
```

Expand All @@ -48,7 +49,7 @@ const open = require('opn');

It uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.

### opn(target, [options])
### open(target, [options])

Returns a promise for the [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would 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.

Expand Down
12 changes: 6 additions & 6 deletions test.js
Expand Up @@ -30,19 +30,19 @@ test('open file in default app', async () => {
});

test('wait for the app to close if wait: true', async () => {
await open('http://sindresorhus.com', {wait: true});
await open('https://sindresorhus.com', {wait: true});
});

test('open url in default app', async () => {
await open('http://sindresorhus.com');
await open('https://sindresorhus.com');
});

test('open url in specified app', async () => {
await open('http://sindresorhus.com', {app: firefoxName});
await open('https://sindresorhus.com', {app: firefoxName});
});

test('open url in specified app with arguments', async () => {
await open('http://sindresorhus.com', {app: [chromeName, '--incognito']});
await open('https://sindresorhus.com', {app: [chromeName, '--incognito']});
});

test('return the child process when called', async t => {
Expand All @@ -52,10 +52,10 @@ test('return the child process when called', async t => {

if (isWsl) {
test('open url in specified windows app given a wsl path to the app', async () => {
await open('http://sindresorhus.com', {app: firefoxWslName});
await open('https://sindresorhus.com', {app: firefoxWslName});
});

test('open url in specified windows app with arguments given a wsl path to the app', async () => {
await open('http://sindresorhus.com', {app: [chromeWslName, '--incognito']});
await open('https://sindresorhus.com', {app: [chromeWslName, '--incognito']});
});
}

0 comments on commit eca88d8

Please sign in to comment.