Skip to content

Commit 7f5995e

Browse files
committed
Require Node.js 14 and move to ESM
1 parent 3b79981 commit 7f5995e

File tree

7 files changed

+210
-250
lines changed

7 files changed

+210
-250
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 18
14+
- 16
1315
- 14
14-
- 12
1516
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v1
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-node@v3
1819
with:
1920
node-version: ${{ matrix.node-version }}
2021
- run: npm install

index.d.ts

Lines changed: 105 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,171 +1,157 @@
1-
import {ChildProcess} from 'child_process';
1+
import {type ChildProcess} from 'node:child_process';
22

3-
declare namespace open {
4-
interface Options {
5-
/**
6-
Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
7-
8-
Note that it waits for the app to exit, not just for the window to close.
9-
10-
On Windows, you have to explicitly specify an app for it to be able to wait.
3+
export type Options = {
4+
/**
5+
Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
116
12-
@default false
13-
*/
14-
readonly wait?: boolean;
7+
Note that it waits for the app to exit, not just for the window to close.
158
16-
/**
17-
__macOS only__
9+
On Windows, you have to explicitly specify an app for it to be able to wait.
1810
19-
Do not bring the app to the foreground.
11+
@default false
12+
*/
13+
readonly wait?: boolean;
2014

21-
@default false
22-
*/
23-
readonly background?: boolean;
15+
/**
16+
__macOS only__
2417
25-
/**
26-
__macOS only__
18+
Do not bring the app to the foreground.
2719
28-
Open a new instance of the app even it's already running.
20+
@default false
21+
*/
22+
readonly background?: boolean;
2923

30-
A new instance is always opened on other platforms.
24+
/**
25+
__macOS only__
3126
32-
@default false
33-
*/
34-
readonly newInstance?: boolean;
27+
Open a new instance of the app even it's already running.
3528
36-
/**
37-
Specify the `name` of the app to open the `target` with, and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown.
29+
A new instance is always opened on other platforms.
3830
39-
The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use [`open.apps`](#openapps) which auto-detects the correct binary to use.
31+
@default false
32+
*/
33+
readonly newInstance?: boolean;
4034

41-
You may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome.
35+
/**
36+
Specify the `name` of the app to open the `target` with, and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown.
4237
43-
The app `arguments` are app dependent. Check the app's documentation for what arguments it accepts.
44-
*/
45-
readonly app?: App | readonly App[];
38+
The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use `apps` which auto-detects the correct binary to use.
4639
47-
/**
48-
Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
40+
You may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome.
4941
50-
We do not recommend setting this option. The convention for success is exit code zero.
42+
The app `arguments` are app dependent. Check the app's documentation for what arguments it accepts.
43+
*/
44+
readonly app?: App | readonly App[];
5145

52-
@default false
53-
*/
54-
readonly allowNonzeroExitCode?: boolean;
55-
}
46+
/**
47+
Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
5648
57-
interface OpenAppOptions extends Omit<Options, 'app'> {
58-
/**
59-
Arguments passed to the app.
49+
We do not recommend setting this option. The convention for success is exit code zero.
6050
61-
These arguments are app dependent. Check the app's documentation for what arguments it accepts.
62-
*/
63-
readonly arguments?: readonly string[];
64-
}
51+
@default false
52+
*/
53+
readonly allowNonzeroExitCode?: boolean;
54+
};
6555

66-
type AppName =
67-
| 'chrome'
68-
| 'firefox'
69-
| 'edge'
70-
| 'browser'
71-
| 'browserPrivate';
56+
export type OpenAppOptions = {
57+
/**
58+
Arguments passed to the app.
7259
73-
type App = {
74-
name: string | readonly string[];
75-
arguments?: readonly string[];
76-
};
77-
}
60+
These arguments are app dependent. Check the app's documentation for what arguments it accepts.
61+
*/
62+
readonly arguments?: readonly string[];
63+
} & Omit<Options, 'app'>;
64+
65+
export type AppName =
66+
| 'chrome'
67+
| 'firefox'
68+
| 'edge'
69+
| 'browser'
70+
| 'browserPrivate';
71+
72+
export type App = {
73+
name: string | readonly string[];
74+
arguments?: readonly string[];
75+
};
7876

7977
/**
8078
An object containing auto-detected binary names for common apps. Useful to work around cross-platform differences.
8179
8280
@example
8381
```
84-
import open from 'open';
82+
import open, {apps} from 'open';
8583
8684
await open('https://google.com', {
8785
app: {
88-
name: open.apps.chrome
86+
name: apps.chrome
8987
}
9088
});
9189
```
9290
*/
93-
declare const apps: Record<open.AppName, string | readonly string[]>;
91+
export const apps: Record<AppName, string | readonly string[]>;
9492

95-
// eslint-disable-next-line no-redeclare
96-
declare const open: {
97-
/**
98-
Open stuff like URLs, files, executables. Cross-platform.
99-
100-
Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
93+
/**
94+
Open stuff like URLs, files, executables. Cross-platform.
10195
102-
There is a caveat for [double-quotes on Windows](https://github.com/sindresorhus/open#double-quotes-on-windows) where all double-quotes are stripped from the `target`.
96+
Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
10397
104-
@param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. For example, URLs open in your default browser.
105-
@returns 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.
98+
There is a caveat for [double-quotes on Windows](https://github.com/sindresorhus/open#double-quotes-on-windows) where all double-quotes are stripped from the `target`.
10699
107-
@example
108-
```
109-
import open from 'open';
100+
@param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. For example, URLs open in your default browser.
101+
@returns 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.
110102
111-
// Opens the image in the default image viewer.
112-
await open('unicorn.png', {wait: true});
113-
console.log('The image viewer app quit');
103+
@example
104+
```
105+
import open, {apps} from 'open';
114106
115-
// Opens the URL in the default browser.
116-
await open('https://sindresorhus.com');
107+
// Opens the image in the default image viewer.
108+
await open('unicorn.png', {wait: true});
109+
console.log('The image viewer app quit');
117110
118-
// Opens the URL in a specified browser.
119-
await open('https://sindresorhus.com', {app: {name: 'firefox'}});
111+
// Opens the URL in the default browser.
112+
await open('https://sindresorhus.com');
120113
121-
// Specify app arguments.
122-
await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}});
114+
// Opens the URL in a specified browser.
115+
await open('https://sindresorhus.com', {app: {name: 'firefox'}});
123116
124-
// Opens the URL in the default browser in incognito mode.
125-
await open('https://sindresorhus.com', {app: {name: open.apps.browserPrivate}});
126-
```
127-
*/
128-
(
129-
target: string,
130-
options?: open.Options
131-
): Promise<ChildProcess>;
117+
// Specify app arguments.
118+
await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}});
132119
133-
/**
134-
An object containing auto-detected binary names for common apps. Useful to work around cross-platform differences.
135-
*/
136-
apps: typeof apps;
137-
138-
/**
139-
Open an app. Cross-platform.
120+
// Opens the URL in the default browser in incognito mode.
121+
await open('https://sindresorhus.com', {app: {name: apps.browserPrivate}});
122+
```
123+
*/
124+
export default function open(
125+
target: string,
126+
options?: Options
127+
): Promise<ChildProcess>;
140128

141-
Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
129+
/**
130+
Open an app. Cross-platform.
142131
143-
@param name - The app you want to open. Can be either builtin supported `open.apps` names or other name supported in platform.
144-
@returns 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.
132+
Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
145133
146-
@example
147-
```
148-
import open from 'open';
149-
const {apps, openApp} = open;
134+
@param name - The app you want to open. Can be either builtin supported `apps` names or other name supported in platform.
135+
@returns 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.
150136
151-
// Open Firefox.
152-
await openApp(apps.firefox);
137+
@example
138+
```
139+
import open, {openApp, apps} from 'open';
153140
154-
// Open Chrome in incognito mode.
155-
await openApp(apps.chrome, {arguments: ['--incognito']});
141+
// Open Firefox.
142+
await openApp(apps.firefox);
156143
157-
// Open default browser.
158-
await openApp(apps.browser);
144+
// Open Chrome in incognito mode.
145+
await openApp(apps.chrome, {arguments: ['--incognito']});
159146
160-
// Open default browser in incognito mode.
161-
await openApp(apps.browserPrivate);
147+
// Open default browser.
148+
await openApp(apps.browser);
162149
163-
// Open Xcode.
164-
await openApp('xcode');
165-
```
166-
*/
167-
openApp: (name: open.App['name'], options?: open.OpenAppOptions) => Promise<ChildProcess>;
168-
};
150+
// Open default browser in incognito mode.
151+
await openApp(apps.browserPrivate);
169152
170-
export {apps};
171-
export default open;
153+
// Open Xcode.
154+
await openApp('xcode');
155+
```
156+
*/
157+
export function openApp(name: App['name'], options?: OpenAppOptions): Promise<ChildProcess>;

0 commit comments

Comments
 (0)