@ohos-ports/open 6.4.0-beta.0 → 8.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +109 -26
- package/index.js +234 -49
- package/license +1 -1
- package/package.json +12 -9
- package/readme.md +95 -25
- package/xdg-open +1 -1
package/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node"/>
|
|
2
1
|
import {ChildProcess} from 'child_process';
|
|
3
2
|
|
|
4
3
|
declare namespace open {
|
|
@@ -24,47 +23,131 @@ declare namespace open {
|
|
|
24
23
|
readonly background?: boolean;
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
|
-
|
|
26
|
+
__macOS only__
|
|
27
|
+
|
|
28
|
+
Open a new instance of the app even it's already running.
|
|
29
|
+
|
|
30
|
+
A new instance is always opened on other platforms.
|
|
31
|
+
|
|
32
|
+
@default false
|
|
33
|
+
*/
|
|
34
|
+
readonly newInstance?: boolean;
|
|
28
35
|
|
|
29
|
-
|
|
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.
|
|
38
|
+
|
|
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.
|
|
30
40
|
|
|
31
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.
|
|
42
|
+
|
|
43
|
+
The app `arguments` are app dependent. Check the app's documentation for what arguments it accepts.
|
|
32
44
|
*/
|
|
33
|
-
readonly app?:
|
|
45
|
+
readonly app?: App | readonly App[];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
|
|
49
|
+
|
|
50
|
+
We do not recommend setting this option. The convention for success is exit code zero.
|
|
51
|
+
|
|
52
|
+
@default false
|
|
53
|
+
*/
|
|
54
|
+
readonly allowNonzeroExitCode?: boolean;
|
|
34
55
|
}
|
|
56
|
+
|
|
57
|
+
interface OpenAppOptions extends Omit<Options, 'app'> {
|
|
58
|
+
/**
|
|
59
|
+
Arguments passed to the app.
|
|
60
|
+
|
|
61
|
+
These arguments are app dependent. Check the app's documentation for what arguments it accepts.
|
|
62
|
+
*/
|
|
63
|
+
readonly arguments?: readonly string[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type AppName =
|
|
67
|
+
| 'chrome'
|
|
68
|
+
| 'firefox'
|
|
69
|
+
| 'edge';
|
|
70
|
+
|
|
71
|
+
type App = {
|
|
72
|
+
name: string | readonly string[];
|
|
73
|
+
arguments?: readonly string[];
|
|
74
|
+
};
|
|
35
75
|
}
|
|
36
76
|
|
|
37
|
-
|
|
38
|
-
|
|
77
|
+
// eslint-disable-next-line no-redeclare
|
|
78
|
+
declare const open: {
|
|
79
|
+
/**
|
|
80
|
+
Open stuff like URLs, files, executables. Cross-platform.
|
|
81
|
+
|
|
82
|
+
Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
|
|
39
83
|
|
|
40
|
-
|
|
84
|
+
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`.
|
|
41
85
|
|
|
42
|
-
@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.
|
|
43
|
-
@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.
|
|
86
|
+
@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.
|
|
87
|
+
@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.
|
|
44
88
|
|
|
45
|
-
@example
|
|
46
|
-
```
|
|
47
|
-
import open = require('open');
|
|
89
|
+
@example
|
|
90
|
+
```
|
|
91
|
+
import open = require('open');
|
|
48
92
|
|
|
49
|
-
// Opens the image in the default image viewer
|
|
50
|
-
(async () => {
|
|
93
|
+
// Opens the image in the default image viewer
|
|
51
94
|
await open('unicorn.png', {wait: true});
|
|
52
95
|
console.log('The image viewer app closed');
|
|
53
96
|
|
|
54
97
|
// Opens the url in the default browser
|
|
55
98
|
await open('https://sindresorhus.com');
|
|
56
99
|
|
|
57
|
-
//
|
|
58
|
-
await open('https://sindresorhus.com', {app: 'firefox'});
|
|
59
|
-
|
|
60
|
-
// Specify app arguments
|
|
61
|
-
await open('https://sindresorhus.com', {app:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
100
|
+
// Opens the URL in a specified browser.
|
|
101
|
+
await open('https://sindresorhus.com', {app: {name: 'firefox'}});
|
|
102
|
+
|
|
103
|
+
// Specify app arguments.
|
|
104
|
+
await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}});
|
|
105
|
+
```
|
|
106
|
+
*/
|
|
107
|
+
(
|
|
108
|
+
target: string,
|
|
109
|
+
options?: open.Options
|
|
110
|
+
): Promise<ChildProcess>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
An object containing auto-detected binary names for common apps. Useful to work around cross-platform differences.
|
|
114
|
+
|
|
115
|
+
@example
|
|
116
|
+
```
|
|
117
|
+
import open = require('open');
|
|
118
|
+
|
|
119
|
+
await open('https://google.com', {
|
|
120
|
+
app: {
|
|
121
|
+
name: open.apps.chrome
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
*/
|
|
126
|
+
apps: Record<open.AppName, string | readonly string[]>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
Open an app. Cross-platform.
|
|
130
|
+
|
|
131
|
+
Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
|
|
132
|
+
|
|
133
|
+
@param name - The app you want to open. Can be either builtin supported `open.apps` names or other name supported in platform.
|
|
134
|
+
@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.
|
|
135
|
+
|
|
136
|
+
@example
|
|
137
|
+
```
|
|
138
|
+
const {apps, openApp} = require('open');
|
|
139
|
+
|
|
140
|
+
// Open Firefox
|
|
141
|
+
await openApp(apps.firefox);
|
|
142
|
+
|
|
143
|
+
// Open Chrome incognito mode
|
|
144
|
+
await openApp(apps.chrome, {arguments: ['--incognito']});
|
|
145
|
+
|
|
146
|
+
// Open Xcode
|
|
147
|
+
await openApp('xcode');
|
|
148
|
+
```
|
|
149
|
+
*/
|
|
150
|
+
openApp: (name: open.App['name'], options?: open.OpenAppOptions) => Promise<ChildProcess>;
|
|
151
|
+
};
|
|
69
152
|
|
|
70
153
|
export = open;
|
package/index.js
CHANGED
|
@@ -1,22 +1,73 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const {promisify} = require('util');
|
|
3
1
|
const path = require('path');
|
|
4
2
|
const childProcess = require('child_process');
|
|
5
3
|
const http = require('http');
|
|
6
|
-
const fs = require('fs');
|
|
4
|
+
const {promises: fs, constants: fsConstants} = require('fs');
|
|
7
5
|
const isWsl = require('is-wsl');
|
|
6
|
+
const isDocker = require('is-docker');
|
|
7
|
+
const defineLazyProperty = require('define-lazy-prop');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
const pExecFile = promisify(childProcess.execFile);
|
|
11
|
-
|
|
12
|
-
// Path to included `xdg-open`
|
|
9
|
+
// Path to included `xdg-open`.
|
|
13
10
|
const localXdgOpenPath = path.join(__dirname, 'xdg-open');
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const {platform, arch} = process;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
Get the mount point for fixed drives in WSL.
|
|
16
|
+
|
|
17
|
+
@inner
|
|
18
|
+
@returns {string} The mount point.
|
|
19
|
+
*/
|
|
20
|
+
const getWslDrivesMountPoint = (() => {
|
|
21
|
+
// Default value for "root" param
|
|
22
|
+
// according to https://docs.microsoft.com/en-us/windows/wsl/wsl-config
|
|
23
|
+
const defaultMountPoint = '/mnt/';
|
|
24
|
+
|
|
25
|
+
let mountPoint;
|
|
26
|
+
|
|
27
|
+
return async function () {
|
|
28
|
+
if (mountPoint) {
|
|
29
|
+
// Return memoized mount point value
|
|
30
|
+
return mountPoint;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const configFilePath = '/etc/wsl.conf';
|
|
34
|
+
|
|
35
|
+
let isConfigFileExists = false;
|
|
36
|
+
try {
|
|
37
|
+
await fs.access(configFilePath, fsConstants.F_OK);
|
|
38
|
+
isConfigFileExists = true;
|
|
39
|
+
} catch {}
|
|
40
|
+
|
|
41
|
+
if (!isConfigFileExists) {
|
|
42
|
+
return defaultMountPoint;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const configContent = await fs.readFile(configFilePath, {encoding: 'utf8'});
|
|
46
|
+
const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
|
|
47
|
+
|
|
48
|
+
if (!configMountPoint) {
|
|
49
|
+
return defaultMountPoint;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
mountPoint = configMountPoint.groups.mountPoint.trim();
|
|
53
|
+
mountPoint = mountPoint.endsWith('/') ? mountPoint : `${mountPoint}/`;
|
|
54
|
+
|
|
55
|
+
return mountPoint;
|
|
56
|
+
};
|
|
57
|
+
})();
|
|
58
|
+
|
|
59
|
+
const pTryEach = async (array, mapper) => {
|
|
60
|
+
let latestError;
|
|
61
|
+
|
|
62
|
+
for (const item of array) {
|
|
63
|
+
try {
|
|
64
|
+
return await mapper(item); // eslint-disable-line no-await-in-loop
|
|
65
|
+
} catch (error) {
|
|
66
|
+
latestError = error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
throw latestError;
|
|
20
71
|
};
|
|
21
72
|
|
|
22
73
|
// --- openharmony: system browser (Haitai/ArkWeb) via Chrome DevTools Protocol ---
|
|
@@ -150,28 +201,40 @@ const openHarmonyCdp = async target => {
|
|
|
150
201
|
return targetInfo;
|
|
151
202
|
};
|
|
152
203
|
|
|
153
|
-
|
|
154
|
-
if (typeof target !== 'string') {
|
|
155
|
-
throw new TypeError('Expected a `target`');
|
|
156
|
-
}
|
|
157
|
-
|
|
204
|
+
const baseOpen = async options => {
|
|
158
205
|
options = {
|
|
159
206
|
wait: false,
|
|
160
207
|
background: false,
|
|
208
|
+
newInstance: false,
|
|
209
|
+
allowNonzeroExitCode: false,
|
|
161
210
|
...options
|
|
162
211
|
};
|
|
163
212
|
|
|
213
|
+
if (Array.isArray(options.app)) {
|
|
214
|
+
return pTryEach(options.app, singleApp => baseOpen({
|
|
215
|
+
...options,
|
|
216
|
+
app: singleApp
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
let {name: app, arguments: appArguments = []} = options.app || {};
|
|
221
|
+
appArguments = [...appArguments];
|
|
222
|
+
|
|
223
|
+
if (Array.isArray(app)) {
|
|
224
|
+
return pTryEach(app, appName => baseOpen({
|
|
225
|
+
...options,
|
|
226
|
+
app: {
|
|
227
|
+
name: appName,
|
|
228
|
+
arguments: appArguments
|
|
229
|
+
}
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
|
|
164
233
|
let command;
|
|
165
|
-
let appArguments = [];
|
|
166
234
|
const cliArguments = [];
|
|
167
235
|
const childProcessOptions = {};
|
|
168
236
|
|
|
169
|
-
if (
|
|
170
|
-
appArguments = options.app.slice(1);
|
|
171
|
-
options.app = options.app[0];
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (process.platform === 'openharmony') {
|
|
237
|
+
if (platform === 'openharmony') {
|
|
175
238
|
// HarmonyOS: open the target in the system browser (Haitai/ArkWeb)
|
|
176
239
|
// through the Chrome DevTools Protocol. The CDP endpoint can be
|
|
177
240
|
// overridden via the `OPEN_OHOS_CDP_ENDPOINT` or `OHOS_BROWSER_CDP`
|
|
@@ -181,14 +244,14 @@ module.exports = async (target, options) => {
|
|
|
181
244
|
// only supported target. The `wait` option has no child process to
|
|
182
245
|
// wait for; the returned promise resolves once the navigation
|
|
183
246
|
// started successfully.
|
|
184
|
-
if (
|
|
247
|
+
if (!options.target) {
|
|
185
248
|
throw new Error('open: opening an application without a URL target is not supported on openharmony (use the CDP-driven system browser instead)');
|
|
186
249
|
}
|
|
187
250
|
|
|
188
|
-
return openHarmonyCdp(target);
|
|
251
|
+
return openHarmonyCdp(options.target);
|
|
189
252
|
}
|
|
190
253
|
|
|
191
|
-
if (
|
|
254
|
+
if (platform === 'darwin') {
|
|
192
255
|
command = 'open';
|
|
193
256
|
|
|
194
257
|
if (options.wait) {
|
|
@@ -199,33 +262,59 @@ module.exports = async (target, options) => {
|
|
|
199
262
|
cliArguments.push('--background');
|
|
200
263
|
}
|
|
201
264
|
|
|
202
|
-
if (options.
|
|
203
|
-
cliArguments.push('
|
|
265
|
+
if (options.newInstance) {
|
|
266
|
+
cliArguments.push('--new');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (app) {
|
|
270
|
+
cliArguments.push('-a', app);
|
|
204
271
|
}
|
|
205
|
-
} else if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
272
|
+
} else if (platform === 'win32' || (isWsl && !isDocker())) {
|
|
273
|
+
const mountPoint = await getWslDrivesMountPoint();
|
|
274
|
+
|
|
275
|
+
command = isWsl ?
|
|
276
|
+
`${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe` :
|
|
277
|
+
`${process.env.SYSTEMROOT}\\System32\\WindowsPowerShell\\v1.0\\powershell`;
|
|
278
|
+
|
|
279
|
+
cliArguments.push(
|
|
280
|
+
'-NoProfile',
|
|
281
|
+
'-NonInteractive',
|
|
282
|
+
'–ExecutionPolicy',
|
|
283
|
+
'Bypass',
|
|
284
|
+
'-EncodedCommand'
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
if (!isWsl) {
|
|
288
|
+
childProcessOptions.windowsVerbatimArguments = true;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const encodedArguments = ['Start'];
|
|
209
292
|
|
|
210
293
|
if (options.wait) {
|
|
211
|
-
|
|
294
|
+
encodedArguments.push('-Wait');
|
|
212
295
|
}
|
|
213
296
|
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
297
|
+
if (app) {
|
|
298
|
+
// Double quote with double quotes to ensure the inner quotes are passed through.
|
|
299
|
+
// Inner quotes are delimited for PowerShell interpretation with backticks.
|
|
300
|
+
encodedArguments.push(`"\`"${app}\`""`, '-ArgumentList');
|
|
301
|
+
if (options.target) {
|
|
302
|
+
appArguments.unshift(options.target);
|
|
218
303
|
}
|
|
219
|
-
|
|
220
|
-
|
|
304
|
+
} else if (options.target) {
|
|
305
|
+
encodedArguments.push(`"${options.target}"`);
|
|
221
306
|
}
|
|
222
307
|
|
|
223
308
|
if (appArguments.length > 0) {
|
|
224
|
-
|
|
309
|
+
appArguments = appArguments.map(arg => `"\`"${arg}\`""`);
|
|
310
|
+
encodedArguments.push(appArguments.join(','));
|
|
225
311
|
}
|
|
312
|
+
|
|
313
|
+
// Using Base64-encoded command, accepted by PowerShell, to allow special characters.
|
|
314
|
+
options.target = Buffer.from(encodedArguments.join(' '), 'utf16le').toString('base64');
|
|
226
315
|
} else {
|
|
227
|
-
if (
|
|
228
|
-
command =
|
|
316
|
+
if (app) {
|
|
317
|
+
command = app;
|
|
229
318
|
} else {
|
|
230
319
|
// When bundled by Webpack, there's no actual package file path and no local `xdg-open`.
|
|
231
320
|
const isBundled = !__dirname || __dirname === '/';
|
|
@@ -233,12 +322,12 @@ module.exports = async (target, options) => {
|
|
|
233
322
|
// Check if local `xdg-open` exists and is executable.
|
|
234
323
|
let exeLocalXdgOpen = false;
|
|
235
324
|
try {
|
|
236
|
-
await
|
|
325
|
+
await fs.access(localXdgOpenPath, fsConstants.X_OK);
|
|
237
326
|
exeLocalXdgOpen = true;
|
|
238
|
-
} catch
|
|
327
|
+
} catch {}
|
|
239
328
|
|
|
240
329
|
const useSystemXdgOpen = process.versions.electron ||
|
|
241
|
-
|
|
330
|
+
platform === 'android' || isBundled || !exeLocalXdgOpen;
|
|
242
331
|
command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath;
|
|
243
332
|
}
|
|
244
333
|
|
|
@@ -254,9 +343,11 @@ module.exports = async (target, options) => {
|
|
|
254
343
|
}
|
|
255
344
|
}
|
|
256
345
|
|
|
257
|
-
|
|
346
|
+
if (options.target) {
|
|
347
|
+
cliArguments.push(options.target);
|
|
348
|
+
}
|
|
258
349
|
|
|
259
|
-
if (
|
|
350
|
+
if (platform === 'darwin' && appArguments.length > 0) {
|
|
260
351
|
cliArguments.push('--args', ...appArguments);
|
|
261
352
|
}
|
|
262
353
|
|
|
@@ -267,7 +358,7 @@ module.exports = async (target, options) => {
|
|
|
267
358
|
subprocess.once('error', reject);
|
|
268
359
|
|
|
269
360
|
subprocess.once('close', exitCode => {
|
|
270
|
-
if (exitCode > 0) {
|
|
361
|
+
if (options.allowNonzeroExitCode && exitCode > 0) {
|
|
271
362
|
reject(new Error(`Exited with code ${exitCode}`));
|
|
272
363
|
return;
|
|
273
364
|
}
|
|
@@ -281,3 +372,97 @@ module.exports = async (target, options) => {
|
|
|
281
372
|
|
|
282
373
|
return subprocess;
|
|
283
374
|
};
|
|
375
|
+
|
|
376
|
+
const open = (target, options) => {
|
|
377
|
+
if (typeof target !== 'string') {
|
|
378
|
+
throw new TypeError('Expected a `target`');
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return baseOpen({
|
|
382
|
+
...options,
|
|
383
|
+
target
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const openApp = (name, options) => {
|
|
388
|
+
if (typeof name !== 'string') {
|
|
389
|
+
throw new TypeError('Expected a `name`');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const {arguments: appArguments = []} = options || {};
|
|
393
|
+
if (appArguments !== undefined && appArguments !== null && !Array.isArray(appArguments)) {
|
|
394
|
+
throw new TypeError('Expected `appArguments` as Array type');
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return baseOpen({
|
|
398
|
+
...options,
|
|
399
|
+
app: {
|
|
400
|
+
name,
|
|
401
|
+
arguments: appArguments
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
function detectArchBinary(binary) {
|
|
407
|
+
if (typeof binary === 'string' || Array.isArray(binary)) {
|
|
408
|
+
return binary;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const {[arch]: archBinary} = binary;
|
|
412
|
+
|
|
413
|
+
if (!archBinary) {
|
|
414
|
+
throw new Error(`${arch} is not supported`);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return archBinary;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function detectPlatformBinary({[platform]: platformBinary}, {wsl}) {
|
|
421
|
+
if (wsl && isWsl) {
|
|
422
|
+
return detectArchBinary(wsl);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (!platformBinary) {
|
|
426
|
+
throw new Error(`${platform} is not supported`);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return detectArchBinary(platformBinary);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const apps = {};
|
|
433
|
+
|
|
434
|
+
defineLazyProperty(apps, 'chrome', () => detectPlatformBinary({
|
|
435
|
+
darwin: 'google chrome',
|
|
436
|
+
win32: 'chrome',
|
|
437
|
+
linux: ['google-chrome', 'google-chrome-stable', 'chromium']
|
|
438
|
+
}, {
|
|
439
|
+
wsl: {
|
|
440
|
+
ia32: '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe',
|
|
441
|
+
x64: ['/mnt/c/Program Files/Google/Chrome/Application/chrome.exe', '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe']
|
|
442
|
+
}
|
|
443
|
+
}));
|
|
444
|
+
|
|
445
|
+
defineLazyProperty(apps, 'firefox', () => detectPlatformBinary({
|
|
446
|
+
darwin: 'firefox',
|
|
447
|
+
win32: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe',
|
|
448
|
+
linux: 'firefox'
|
|
449
|
+
}, {
|
|
450
|
+
wsl: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe'
|
|
451
|
+
}));
|
|
452
|
+
|
|
453
|
+
defineLazyProperty(apps, 'edge', () => detectPlatformBinary({
|
|
454
|
+
darwin: 'microsoft edge',
|
|
455
|
+
win32: 'msedge',
|
|
456
|
+
linux: ['microsoft-edge', 'microsoft-edge-dev']
|
|
457
|
+
}, {
|
|
458
|
+
wsl: '/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'
|
|
459
|
+
}));
|
|
460
|
+
|
|
461
|
+
// On openharmony the system browser (Haitai/ArkWeb, `htbrowser`) is driven
|
|
462
|
+
// via CDP; the value only serves as a label for the available browser.
|
|
463
|
+
defineLazyProperty(apps, 'haitai', () => 'htbrowser');
|
|
464
|
+
|
|
465
|
+
open.apps = apps;
|
|
466
|
+
open.openApp = openApp;
|
|
467
|
+
|
|
468
|
+
module.exports = open;
|
package/license
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/open",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.4.0-beta.1",
|
|
4
4
|
"description": "Open stuff like URLs, files, executables. Cross-platform. OpenHarmony port: opens URLs in the system browser (Haitai/ArkWeb) via CDP.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
9
|
-
"directory": "ports/open/
|
|
9
|
+
"directory": "ports/open/8.4.0"
|
|
10
10
|
},
|
|
11
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
11
12
|
"author": {
|
|
12
13
|
"name": "Sindre Sorhus",
|
|
13
14
|
"email": "sindresorhus@gmail.com",
|
|
14
|
-
"url": "sindresorhus.com"
|
|
15
|
+
"url": "https://sindresorhus.com"
|
|
15
16
|
},
|
|
16
17
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
18
|
+
"node": ">=12"
|
|
18
19
|
},
|
|
19
20
|
"scripts": {
|
|
20
21
|
"test": "xo && tsd"
|
|
@@ -54,12 +55,14 @@
|
|
|
54
55
|
"harmonyos"
|
|
55
56
|
],
|
|
56
57
|
"dependencies": {
|
|
57
|
-
"
|
|
58
|
+
"define-lazy-prop": "^2.0.0",
|
|
59
|
+
"is-docker": "^2.1.1",
|
|
60
|
+
"is-wsl": "^2.2.0"
|
|
58
61
|
},
|
|
59
62
|
"devDependencies": {
|
|
60
|
-
"@types/node": "^
|
|
61
|
-
"ava": "^
|
|
62
|
-
"tsd": "^0.
|
|
63
|
-
"xo": "^0.
|
|
63
|
+
"@types/node": "^15.0.0",
|
|
64
|
+
"ava": "^3.15.0",
|
|
65
|
+
"tsd": "^0.14.0",
|
|
66
|
+
"xo": "^0.39.1"
|
|
64
67
|
}
|
|
65
68
|
}
|
package/readme.md
CHANGED
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
> Open stuff like URLs, files, executables. Cross-platform.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This is meant to be used in command-line tools and scripts, not in the browser.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
If you need this for Electron, use [`shell.openPath()`](https://www.electronjs.org/docs/api/shell#shellopenpathpath) instead.
|
|
8
|
+
|
|
9
|
+
This package does not make any security guarantees. If you pass in untrusted input, it's up to you to properly sanitize it.
|
|
8
10
|
|
|
9
11
|
#### Why?
|
|
10
12
|
|
|
11
13
|
- Actively maintained.
|
|
12
14
|
- Supports app arguments.
|
|
13
15
|
- Safer as it uses `spawn` instead of `exec`.
|
|
14
|
-
- Fixes most of the
|
|
15
|
-
- Includes the latest [`xdg-open` script](
|
|
16
|
-
- Supports WSL paths to Windows apps
|
|
17
|
-
|
|
16
|
+
- Fixes most of the original `node-open` issues.
|
|
17
|
+
- Includes the latest [`xdg-open` script](https://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18) for Linux.
|
|
18
|
+
- Supports WSL paths to Windows apps.
|
|
18
19
|
|
|
19
20
|
## Install
|
|
20
21
|
|
|
@@ -22,28 +23,30 @@ Note: The original [`open` package](https://github.com/pwnall/node-open) was rec
|
|
|
22
23
|
$ npm install open
|
|
23
24
|
```
|
|
24
25
|
|
|
25
|
-
|
|
26
26
|
## Usage
|
|
27
27
|
|
|
28
28
|
```js
|
|
29
29
|
const open = require('open');
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
console.log('The image viewer app quit');
|
|
31
|
+
// Opens the image in the default image viewer and waits for the opened app to quit.
|
|
32
|
+
await open('unicorn.png', {wait: true});
|
|
33
|
+
console.log('The image viewer app quit');
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
// Opens the URL in the default browser.
|
|
36
|
+
await open('https://sindresorhus.com');
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
// Opens the URL in a specified browser.
|
|
39
|
+
await open('https://sindresorhus.com', {app: {name: 'firefox'}});
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
// Specify app arguments.
|
|
42
|
+
await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}});
|
|
43
|
+
|
|
44
|
+
// Open an app
|
|
45
|
+
await open.openApp('xcode');
|
|
46
46
|
|
|
47
|
+
// Open an app with arguments
|
|
48
|
+
await open.openApp(open.apps.chrome, {arguments: ['--incognito']});
|
|
49
|
+
```
|
|
47
50
|
|
|
48
51
|
## API
|
|
49
52
|
|
|
@@ -67,7 +70,7 @@ Type: `object`
|
|
|
67
70
|
|
|
68
71
|
##### wait
|
|
69
72
|
|
|
70
|
-
Type: `boolean
|
|
73
|
+
Type: `boolean`\
|
|
71
74
|
Default: `false`
|
|
72
75
|
|
|
73
76
|
Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
|
|
@@ -78,28 +81,95 @@ On Windows, you have to explicitly specify an app for it to be able to wait.
|
|
|
78
81
|
|
|
79
82
|
##### background <sup>(macOS only)</sup>
|
|
80
83
|
|
|
81
|
-
Type: `boolean
|
|
84
|
+
Type: `boolean`\
|
|
82
85
|
Default: `false`
|
|
83
86
|
|
|
84
87
|
Do not bring the app to the foreground.
|
|
85
88
|
|
|
89
|
+
##### newInstance <sup>(macOS only)</sup>
|
|
90
|
+
|
|
91
|
+
Type: `boolean`\
|
|
92
|
+
Default: `false`
|
|
93
|
+
|
|
94
|
+
Open a new instance of the app even it's already running.
|
|
95
|
+
|
|
96
|
+
A new instance is always opened on other platforms.
|
|
97
|
+
|
|
86
98
|
##### app
|
|
87
99
|
|
|
88
|
-
Type: `string | string[]
|
|
100
|
+
Type: `{name: string | string[], arguments?: string[]} | Array<{name: string | string[], arguments: string[]}>`
|
|
89
101
|
|
|
90
|
-
Specify the app to open the `target` with,
|
|
102
|
+
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.
|
|
91
103
|
|
|
92
|
-
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.
|
|
104
|
+
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.
|
|
93
105
|
|
|
94
106
|
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.
|
|
95
107
|
|
|
108
|
+
The app `arguments` are app dependent. Check the app's documentation for what arguments it accepts.
|
|
109
|
+
|
|
110
|
+
##### allowNonzeroExitCode
|
|
111
|
+
|
|
112
|
+
Type: `boolean`\
|
|
113
|
+
Default: `false`
|
|
114
|
+
|
|
115
|
+
Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
|
|
116
|
+
|
|
117
|
+
We do not recommend setting this option. The convention for success is exit code zero.
|
|
118
|
+
|
|
119
|
+
### open.apps
|
|
120
|
+
|
|
121
|
+
An object containing auto-detected binary names for common apps. Useful to work around [cross-platform differences](#app).
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
const open = require('open');
|
|
125
|
+
|
|
126
|
+
await open('https://google.com', {
|
|
127
|
+
app: {
|
|
128
|
+
name: open.apps.chrome
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### Supported apps
|
|
134
|
+
|
|
135
|
+
- [`chrome`](https://www.google.com/chrome) - Web browser
|
|
136
|
+
- [`firefox`](https://www.mozilla.org/firefox) - Web browser
|
|
137
|
+
- [`edge`](https://www.microsoft.com/edge) - Web browser
|
|
138
|
+
|
|
139
|
+
### open.openApp(name, options?)
|
|
140
|
+
|
|
141
|
+
Open an app.
|
|
142
|
+
|
|
143
|
+
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.
|
|
144
|
+
|
|
145
|
+
#### name
|
|
146
|
+
|
|
147
|
+
Type: `string`
|
|
148
|
+
|
|
149
|
+
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.
|
|
150
|
+
|
|
151
|
+
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.
|
|
152
|
+
|
|
153
|
+
#### options
|
|
154
|
+
|
|
155
|
+
Type: `object`
|
|
156
|
+
|
|
157
|
+
Same options as [`open`](#options) except `app` and with the following additions:
|
|
158
|
+
|
|
159
|
+
##### arguments
|
|
160
|
+
|
|
161
|
+
Type: `string[]`\
|
|
162
|
+
Default: `[]`
|
|
163
|
+
|
|
164
|
+
Arguments passed to the app.
|
|
165
|
+
|
|
166
|
+
These arguments are app dependent. Check the app's documentation for what arguments it accepts.
|
|
96
167
|
|
|
97
168
|
## Related
|
|
98
169
|
|
|
99
170
|
- [open-cli](https://github.com/sindresorhus/open-cli) - CLI for this module
|
|
100
171
|
- [open-editor](https://github.com/sindresorhus/open-editor) - Open files in your editor at a specific line and column
|
|
101
172
|
|
|
102
|
-
|
|
103
173
|
---
|
|
104
174
|
|
|
105
175
|
<div align="center">
|
package/xdg-open
CHANGED
|
@@ -926,7 +926,7 @@ open_generic()
|
|
|
926
926
|
if [ x"$BROWSER" = x"" ]; then
|
|
927
927
|
BROWSER=www-browser:links2:elinks:links:lynx:w3m
|
|
928
928
|
if has_display; then
|
|
929
|
-
BROWSER=x-www-browser:firefox:iceweasel:seamonkey:mozilla:epiphany:konqueror:chromium:chromium-browser:google-chrome:$BROWSER
|
|
929
|
+
BROWSER=x-www-browser:firefox:iceweasel:seamonkey:mozilla:epiphany:konqueror:chromium:chromium-browser:google-chrome:microsoft-edge:$BROWSER
|
|
930
930
|
fi
|
|
931
931
|
fi
|
|
932
932
|
|