@rspack/dev-server 2.0.0-beta.1 → 2.0.0-beta.2
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/README.md +4 -3
- package/client/clients/WebSocketClient.d.ts +17 -0
- package/client/clients/WebSocketClient.js +28 -28
- package/client/index.d.ts +17 -0
- package/client/index.js +224 -363
- package/client/modules/logger/Logger.d.ts +40 -0
- package/client/modules/logger/Logger.js +123 -0
- package/client/modules/logger/createConsoleLogger.d.ts +12 -0
- package/client/modules/logger/createConsoleLogger.js +119 -0
- package/client/modules/logger/index.d.ts +18 -0
- package/client/modules/logger/index.js +20 -712
- package/client/modules/types.d.ts +45 -0
- package/client/modules/types.js +17 -0
- package/client/overlay.d.ts +44 -0
- package/client/overlay.js +241 -290
- package/client/progress.d.ts +11 -0
- package/client/progress.js +178 -111
- package/client/socket.d.ts +15 -0
- package/client/socket.js +19 -46
- package/client/utils/ansiHTML.d.ts +30 -0
- package/client/utils/ansiHTML.js +106 -153
- package/client/utils/log.d.ts +13 -0
- package/client/utils/log.js +7 -17
- package/client/utils/sendMessage.d.ts +11 -0
- package/client/utils/sendMessage.js +6 -15
- package/dist/0~launch-editor.js +618 -0
- package/dist/0~open.js +547 -0
- package/dist/0~p-retry.js +158 -0
- package/dist/131.js +1398 -0
- package/dist/getPort.d.ts +4 -1
- package/dist/index.js +1 -5
- package/dist/rslib-runtime.js +66 -0
- package/dist/server.d.ts +7 -7
- package/dist/servers/WebsocketServer.d.ts +8 -1
- package/dist/types.d.ts +7 -5
- package/package.json +55 -58
- package/dist/config.js +0 -2
- package/dist/getPort.js +0 -141
- package/dist/server.js +0 -1971
- package/dist/servers/BaseServer.js +0 -20
- package/dist/servers/WebsocketServer.js +0 -72
- package/dist/types.js +0 -5
package/dist/0~open.js
ADDED
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import node_process from "node:process";
|
|
2
|
+
import node_child_process, { execFile } from "node:child_process";
|
|
3
|
+
import promises, { constants } from "node:fs/promises";
|
|
4
|
+
import { Buffer } from "node:buffer";
|
|
5
|
+
import { node_fs, node_os, node_path, promisify, fileURLToPath } from "./131.js";
|
|
6
|
+
let isDockerCached;
|
|
7
|
+
function hasDockerEnv() {
|
|
8
|
+
try {
|
|
9
|
+
node_fs.statSync('/.dockerenv');
|
|
10
|
+
return true;
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function hasDockerCGroup() {
|
|
16
|
+
try {
|
|
17
|
+
return node_fs.readFileSync('/proc/self/cgroup', 'utf8').includes('docker');
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function isDocker() {
|
|
23
|
+
if (void 0 === isDockerCached) isDockerCached = hasDockerEnv() || hasDockerCGroup();
|
|
24
|
+
return isDockerCached;
|
|
25
|
+
}
|
|
26
|
+
let cachedResult;
|
|
27
|
+
const hasContainerEnv = ()=>{
|
|
28
|
+
try {
|
|
29
|
+
node_fs.statSync('/run/.containerenv');
|
|
30
|
+
return true;
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
function isInsideContainer() {
|
|
36
|
+
if (void 0 === cachedResult) cachedResult = hasContainerEnv() || isDocker();
|
|
37
|
+
return cachedResult;
|
|
38
|
+
}
|
|
39
|
+
const isWsl = ()=>{
|
|
40
|
+
if ('linux' !== node_process.platform) return false;
|
|
41
|
+
if (node_os.release().toLowerCase().includes('microsoft')) {
|
|
42
|
+
if (isInsideContainer()) return false;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
return node_fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft') ? !isInsideContainer() : false;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const is_wsl = node_process.env.__IS_WSL_TEST__ ? isWsl : isWsl();
|
|
52
|
+
const powershell_utils_execFile = promisify(node_child_process.execFile);
|
|
53
|
+
const powerShellPath = ()=>`${node_process.env.SYSTEMROOT || node_process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
54
|
+
const executePowerShell = async (command, options = {})=>{
|
|
55
|
+
const { powerShellPath: psPath, ...execFileOptions } = options;
|
|
56
|
+
const encodedCommand = executePowerShell.encodeCommand(command);
|
|
57
|
+
return powershell_utils_execFile(psPath ?? powerShellPath(), [
|
|
58
|
+
...executePowerShell.argumentsPrefix,
|
|
59
|
+
encodedCommand
|
|
60
|
+
], {
|
|
61
|
+
encoding: 'utf8',
|
|
62
|
+
...execFileOptions
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
executePowerShell.argumentsPrefix = [
|
|
66
|
+
'-NoProfile',
|
|
67
|
+
'-NonInteractive',
|
|
68
|
+
'-ExecutionPolicy',
|
|
69
|
+
'Bypass',
|
|
70
|
+
'-EncodedCommand'
|
|
71
|
+
];
|
|
72
|
+
executePowerShell.encodeCommand = (command)=>Buffer.from(command, 'utf16le').toString('base64');
|
|
73
|
+
executePowerShell.escapeArgument = (value)=>`'${String(value).replaceAll('\'', '\'\'')}'`;
|
|
74
|
+
function parseMountPointFromConfig(content) {
|
|
75
|
+
for (const line of content.split('\n')){
|
|
76
|
+
if (/^\s*#/.test(line)) continue;
|
|
77
|
+
const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
|
|
78
|
+
if (match) return match.groups.mountPoint.trim().replaceAll(/^["']|["']$/g, '');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const wsl_utils_execFile = promisify(node_child_process.execFile);
|
|
82
|
+
const wslDrivesMountPoint = (()=>{
|
|
83
|
+
const defaultMountPoint = '/mnt/';
|
|
84
|
+
let mountPoint;
|
|
85
|
+
return async function() {
|
|
86
|
+
if (mountPoint) return mountPoint;
|
|
87
|
+
const configFilePath = '/etc/wsl.conf';
|
|
88
|
+
let isConfigFileExists = false;
|
|
89
|
+
try {
|
|
90
|
+
await promises.access(configFilePath, constants.F_OK);
|
|
91
|
+
isConfigFileExists = true;
|
|
92
|
+
} catch {}
|
|
93
|
+
if (!isConfigFileExists) return defaultMountPoint;
|
|
94
|
+
const configContent = await promises.readFile(configFilePath, {
|
|
95
|
+
encoding: 'utf8'
|
|
96
|
+
});
|
|
97
|
+
const parsedMountPoint = parseMountPointFromConfig(configContent);
|
|
98
|
+
if (void 0 === parsedMountPoint) return defaultMountPoint;
|
|
99
|
+
mountPoint = parsedMountPoint;
|
|
100
|
+
mountPoint = mountPoint.endsWith('/') ? mountPoint : `${mountPoint}/`;
|
|
101
|
+
return mountPoint;
|
|
102
|
+
};
|
|
103
|
+
})();
|
|
104
|
+
const powerShellPathFromWsl = async ()=>{
|
|
105
|
+
const mountPoint = await wslDrivesMountPoint();
|
|
106
|
+
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
|
107
|
+
};
|
|
108
|
+
const wsl_utils_powerShellPath = is_wsl ? powerShellPathFromWsl : powerShellPath;
|
|
109
|
+
let canAccessPowerShellPromise;
|
|
110
|
+
const wsl_utils_canAccessPowerShell = async ()=>{
|
|
111
|
+
canAccessPowerShellPromise ??= (async ()=>{
|
|
112
|
+
try {
|
|
113
|
+
const psPath = await wsl_utils_powerShellPath();
|
|
114
|
+
await promises.access(psPath, constants.X_OK);
|
|
115
|
+
return true;
|
|
116
|
+
} catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
})();
|
|
120
|
+
return canAccessPowerShellPromise;
|
|
121
|
+
};
|
|
122
|
+
const wslDefaultBrowser = async ()=>{
|
|
123
|
+
const psPath = await wsl_utils_powerShellPath();
|
|
124
|
+
const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
125
|
+
const { stdout } = await executePowerShell(command, {
|
|
126
|
+
powerShellPath: psPath
|
|
127
|
+
});
|
|
128
|
+
return stdout.trim();
|
|
129
|
+
};
|
|
130
|
+
const convertWslPathToWindows = async (path)=>{
|
|
131
|
+
if (/^[a-z]+:\/\//i.test(path)) return path;
|
|
132
|
+
try {
|
|
133
|
+
const { stdout } = await wsl_utils_execFile('wslpath', [
|
|
134
|
+
'-aw',
|
|
135
|
+
path
|
|
136
|
+
], {
|
|
137
|
+
encoding: 'utf8'
|
|
138
|
+
});
|
|
139
|
+
return stdout.trim();
|
|
140
|
+
} catch {
|
|
141
|
+
return path;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
function defineLazyProperty(object, propertyName, valueGetter) {
|
|
145
|
+
const define = (value)=>Object.defineProperty(object, propertyName, {
|
|
146
|
+
value,
|
|
147
|
+
enumerable: true,
|
|
148
|
+
writable: true
|
|
149
|
+
});
|
|
150
|
+
Object.defineProperty(object, propertyName, {
|
|
151
|
+
configurable: true,
|
|
152
|
+
enumerable: true,
|
|
153
|
+
get () {
|
|
154
|
+
const result = valueGetter();
|
|
155
|
+
define(result);
|
|
156
|
+
return result;
|
|
157
|
+
},
|
|
158
|
+
set (value) {
|
|
159
|
+
define(value);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return object;
|
|
163
|
+
}
|
|
164
|
+
const execFileAsync = promisify(execFile);
|
|
165
|
+
async function defaultBrowserId() {
|
|
166
|
+
if ('darwin' !== node_process.platform) throw new Error('macOS only');
|
|
167
|
+
const { stdout } = await execFileAsync('defaults', [
|
|
168
|
+
'read',
|
|
169
|
+
'com.apple.LaunchServices/com.apple.launchservices.secure',
|
|
170
|
+
'LSHandlers'
|
|
171
|
+
]);
|
|
172
|
+
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
|
|
173
|
+
return match?.groups.id ?? 'com.apple.Safari';
|
|
174
|
+
}
|
|
175
|
+
const run_applescript_execFileAsync = promisify(execFile);
|
|
176
|
+
async function runAppleScript(script, { humanReadableOutput = true } = {}) {
|
|
177
|
+
if ('darwin' !== node_process.platform) throw new Error('macOS only');
|
|
178
|
+
const outputArguments = humanReadableOutput ? [] : [
|
|
179
|
+
'-ss'
|
|
180
|
+
];
|
|
181
|
+
const { stdout } = await run_applescript_execFileAsync("osascript", [
|
|
182
|
+
'-e',
|
|
183
|
+
script,
|
|
184
|
+
outputArguments
|
|
185
|
+
]);
|
|
186
|
+
return stdout.trim();
|
|
187
|
+
}
|
|
188
|
+
async function bundleName(bundleId) {
|
|
189
|
+
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string\ntell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
190
|
+
}
|
|
191
|
+
const windows_execFileAsync = promisify(execFile);
|
|
192
|
+
const windowsBrowserProgIds = {
|
|
193
|
+
MSEdgeHTM: {
|
|
194
|
+
name: 'Edge',
|
|
195
|
+
id: 'com.microsoft.edge'
|
|
196
|
+
},
|
|
197
|
+
MSEdgeBHTML: {
|
|
198
|
+
name: 'Edge Beta',
|
|
199
|
+
id: 'com.microsoft.edge.beta'
|
|
200
|
+
},
|
|
201
|
+
MSEdgeDHTML: {
|
|
202
|
+
name: 'Edge Dev',
|
|
203
|
+
id: 'com.microsoft.edge.dev'
|
|
204
|
+
},
|
|
205
|
+
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: {
|
|
206
|
+
name: 'Edge',
|
|
207
|
+
id: 'com.microsoft.edge.old'
|
|
208
|
+
},
|
|
209
|
+
ChromeHTML: {
|
|
210
|
+
name: 'Chrome',
|
|
211
|
+
id: 'com.google.chrome'
|
|
212
|
+
},
|
|
213
|
+
ChromeBHTML: {
|
|
214
|
+
name: 'Chrome Beta',
|
|
215
|
+
id: 'com.google.chrome.beta'
|
|
216
|
+
},
|
|
217
|
+
ChromeDHTML: {
|
|
218
|
+
name: 'Chrome Dev',
|
|
219
|
+
id: 'com.google.chrome.dev'
|
|
220
|
+
},
|
|
221
|
+
ChromiumHTM: {
|
|
222
|
+
name: 'Chromium',
|
|
223
|
+
id: 'org.chromium.Chromium'
|
|
224
|
+
},
|
|
225
|
+
BraveHTML: {
|
|
226
|
+
name: 'Brave',
|
|
227
|
+
id: 'com.brave.Browser'
|
|
228
|
+
},
|
|
229
|
+
BraveBHTML: {
|
|
230
|
+
name: 'Brave Beta',
|
|
231
|
+
id: 'com.brave.Browser.beta'
|
|
232
|
+
},
|
|
233
|
+
BraveDHTML: {
|
|
234
|
+
name: 'Brave Dev',
|
|
235
|
+
id: 'com.brave.Browser.dev'
|
|
236
|
+
},
|
|
237
|
+
BraveSSHTM: {
|
|
238
|
+
name: 'Brave Nightly',
|
|
239
|
+
id: 'com.brave.Browser.nightly'
|
|
240
|
+
},
|
|
241
|
+
FirefoxURL: {
|
|
242
|
+
name: 'Firefox',
|
|
243
|
+
id: 'org.mozilla.firefox'
|
|
244
|
+
},
|
|
245
|
+
OperaStable: {
|
|
246
|
+
name: 'Opera',
|
|
247
|
+
id: 'com.operasoftware.Opera'
|
|
248
|
+
},
|
|
249
|
+
VivaldiHTM: {
|
|
250
|
+
name: 'Vivaldi',
|
|
251
|
+
id: 'com.vivaldi.Vivaldi'
|
|
252
|
+
},
|
|
253
|
+
'IE.HTTP': {
|
|
254
|
+
name: 'Internet Explorer',
|
|
255
|
+
id: 'com.microsoft.ie'
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
const _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
|
|
259
|
+
class UnknownBrowserError extends Error {
|
|
260
|
+
}
|
|
261
|
+
async function defaultBrowser(_execFileAsync = windows_execFileAsync) {
|
|
262
|
+
const { stdout } = await _execFileAsync('reg', [
|
|
263
|
+
'QUERY',
|
|
264
|
+
' HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice',
|
|
265
|
+
'/v',
|
|
266
|
+
'ProgId'
|
|
267
|
+
]);
|
|
268
|
+
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
269
|
+
if (!match) throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
270
|
+
const { id } = match.groups;
|
|
271
|
+
const dotIndex = id.lastIndexOf('.');
|
|
272
|
+
const hyphenIndex = id.lastIndexOf('-');
|
|
273
|
+
const baseIdByDot = -1 === dotIndex ? void 0 : id.slice(0, dotIndex);
|
|
274
|
+
const baseIdByHyphen = -1 === hyphenIndex ? void 0 : id.slice(0, hyphenIndex);
|
|
275
|
+
return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? {
|
|
276
|
+
name: id,
|
|
277
|
+
id
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
const default_browser_execFileAsync = promisify(execFile);
|
|
281
|
+
const titleize = (string)=>string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x)=>x.toUpperCase());
|
|
282
|
+
async function default_browser_defaultBrowser() {
|
|
283
|
+
if ('darwin' === node_process.platform) {
|
|
284
|
+
const id = await defaultBrowserId();
|
|
285
|
+
const name = await bundleName(id);
|
|
286
|
+
return {
|
|
287
|
+
name,
|
|
288
|
+
id
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
if ('linux' === node_process.platform) {
|
|
292
|
+
const { stdout } = await default_browser_execFileAsync('xdg-mime', [
|
|
293
|
+
'query',
|
|
294
|
+
'default',
|
|
295
|
+
'x-scheme-handler/http'
|
|
296
|
+
]);
|
|
297
|
+
const id = stdout.trim();
|
|
298
|
+
const name = titleize(id.replace(/.desktop$/, '').replace('-', ' '));
|
|
299
|
+
return {
|
|
300
|
+
name,
|
|
301
|
+
id
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
if ('win32' === node_process.platform) return defaultBrowser();
|
|
305
|
+
throw new Error('Only macOS, Linux, and Windows are supported');
|
|
306
|
+
}
|
|
307
|
+
const isInSsh = Boolean(node_process.env.SSH_CONNECTION || node_process.env.SSH_CLIENT || node_process.env.SSH_TTY);
|
|
308
|
+
const is_in_ssh = isInSsh;
|
|
309
|
+
const fallbackAttemptSymbol = Symbol('fallbackAttempt');
|
|
310
|
+
const open_dirname = import.meta.url ? node_path.dirname(fileURLToPath(import.meta.url)) : '';
|
|
311
|
+
const localXdgOpenPath = node_path.join(open_dirname, 'xdg-open');
|
|
312
|
+
const { platform: platform, arch: arch } = node_process;
|
|
313
|
+
const tryEachApp = async (apps, opener)=>{
|
|
314
|
+
if (0 === apps.length) return;
|
|
315
|
+
const errors = [];
|
|
316
|
+
for (const app of apps)try {
|
|
317
|
+
return await opener(app);
|
|
318
|
+
} catch (error) {
|
|
319
|
+
errors.push(error);
|
|
320
|
+
}
|
|
321
|
+
throw new AggregateError(errors, 'Failed to open in all supported apps');
|
|
322
|
+
};
|
|
323
|
+
const baseOpen = async (options)=>{
|
|
324
|
+
options = {
|
|
325
|
+
wait: false,
|
|
326
|
+
background: false,
|
|
327
|
+
newInstance: false,
|
|
328
|
+
allowNonzeroExitCode: false,
|
|
329
|
+
...options
|
|
330
|
+
};
|
|
331
|
+
const isFallbackAttempt = true === options[fallbackAttemptSymbol];
|
|
332
|
+
delete options[fallbackAttemptSymbol];
|
|
333
|
+
if (Array.isArray(options.app)) return tryEachApp(options.app, (singleApp)=>baseOpen({
|
|
334
|
+
...options,
|
|
335
|
+
app: singleApp,
|
|
336
|
+
[fallbackAttemptSymbol]: true
|
|
337
|
+
}));
|
|
338
|
+
let { name: app, arguments: appArguments = [] } = options.app ?? {};
|
|
339
|
+
appArguments = [
|
|
340
|
+
...appArguments
|
|
341
|
+
];
|
|
342
|
+
if (Array.isArray(app)) return tryEachApp(app, (appName)=>baseOpen({
|
|
343
|
+
...options,
|
|
344
|
+
app: {
|
|
345
|
+
name: appName,
|
|
346
|
+
arguments: appArguments
|
|
347
|
+
},
|
|
348
|
+
[fallbackAttemptSymbol]: true
|
|
349
|
+
}));
|
|
350
|
+
if ('browser' === app || 'browserPrivate' === app) {
|
|
351
|
+
const ids = {
|
|
352
|
+
'com.google.chrome': 'chrome',
|
|
353
|
+
'google-chrome.desktop': 'chrome',
|
|
354
|
+
'com.brave.browser': 'brave',
|
|
355
|
+
'org.mozilla.firefox': 'firefox',
|
|
356
|
+
'firefox.desktop': 'firefox',
|
|
357
|
+
'com.microsoft.msedge': 'edge',
|
|
358
|
+
'com.microsoft.edge': 'edge',
|
|
359
|
+
'com.microsoft.edgemac': 'edge',
|
|
360
|
+
'microsoft-edge.desktop': 'edge',
|
|
361
|
+
'com.apple.safari': 'safari'
|
|
362
|
+
};
|
|
363
|
+
const flags = {
|
|
364
|
+
chrome: '--incognito',
|
|
365
|
+
brave: '--incognito',
|
|
366
|
+
firefox: '--private-window',
|
|
367
|
+
edge: '--inPrivate'
|
|
368
|
+
};
|
|
369
|
+
let browser;
|
|
370
|
+
if (is_wsl) {
|
|
371
|
+
const progId = await wslDefaultBrowser();
|
|
372
|
+
const browserInfo = _windowsBrowserProgIdMap.get(progId);
|
|
373
|
+
browser = browserInfo ?? {};
|
|
374
|
+
} else browser = await default_browser_defaultBrowser();
|
|
375
|
+
if (browser.id in ids) {
|
|
376
|
+
const browserName = ids[browser.id.toLowerCase()];
|
|
377
|
+
if ('browserPrivate' === app) {
|
|
378
|
+
if ('safari' === browserName) throw new Error('Safari doesn\'t support opening in private mode via command line');
|
|
379
|
+
appArguments.push(flags[browserName]);
|
|
380
|
+
}
|
|
381
|
+
return baseOpen({
|
|
382
|
+
...options,
|
|
383
|
+
app: {
|
|
384
|
+
name: open_apps[browserName],
|
|
385
|
+
arguments: appArguments
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
throw new Error(`${browser.name} is not supported as a default browser`);
|
|
390
|
+
}
|
|
391
|
+
let command;
|
|
392
|
+
const cliArguments = [];
|
|
393
|
+
const childProcessOptions = {};
|
|
394
|
+
let shouldUseWindowsInWsl = false;
|
|
395
|
+
if (is_wsl && !isInsideContainer() && !is_in_ssh && !app) shouldUseWindowsInWsl = await wsl_utils_canAccessPowerShell();
|
|
396
|
+
if ('darwin' === platform) {
|
|
397
|
+
command = 'open';
|
|
398
|
+
if (options.wait) cliArguments.push('--wait-apps');
|
|
399
|
+
if (options.background) cliArguments.push('--background');
|
|
400
|
+
if (options.newInstance) cliArguments.push('--new');
|
|
401
|
+
if (app) cliArguments.push('-a', app);
|
|
402
|
+
} else if ('win32' === platform || shouldUseWindowsInWsl) {
|
|
403
|
+
command = await wsl_utils_powerShellPath();
|
|
404
|
+
cliArguments.push(...executePowerShell.argumentsPrefix);
|
|
405
|
+
if (!is_wsl) childProcessOptions.windowsVerbatimArguments = true;
|
|
406
|
+
if (is_wsl && options.target) options.target = await convertWslPathToWindows(options.target);
|
|
407
|
+
const encodedArguments = [
|
|
408
|
+
'$ProgressPreference = \'SilentlyContinue\';',
|
|
409
|
+
'Start'
|
|
410
|
+
];
|
|
411
|
+
if (options.wait) encodedArguments.push('-Wait');
|
|
412
|
+
if (app) {
|
|
413
|
+
encodedArguments.push(executePowerShell.escapeArgument(app));
|
|
414
|
+
if (options.target) appArguments.push(options.target);
|
|
415
|
+
} else if (options.target) encodedArguments.push(executePowerShell.escapeArgument(options.target));
|
|
416
|
+
if (appArguments.length > 0) {
|
|
417
|
+
appArguments = appArguments.map((argument)=>executePowerShell.escapeArgument(argument));
|
|
418
|
+
encodedArguments.push('-ArgumentList', appArguments.join(','));
|
|
419
|
+
}
|
|
420
|
+
options.target = executePowerShell.encodeCommand(encodedArguments.join(' '));
|
|
421
|
+
if (!options.wait) childProcessOptions.stdio = 'ignore';
|
|
422
|
+
} else {
|
|
423
|
+
if (app) command = app;
|
|
424
|
+
else {
|
|
425
|
+
const isBundled = !open_dirname || '/' === open_dirname;
|
|
426
|
+
let exeLocalXdgOpen = false;
|
|
427
|
+
try {
|
|
428
|
+
await promises.access(localXdgOpenPath, constants.X_OK);
|
|
429
|
+
exeLocalXdgOpen = true;
|
|
430
|
+
} catch {}
|
|
431
|
+
const useSystemXdgOpen = node_process.versions.electron ?? ('android' === platform || isBundled || !exeLocalXdgOpen);
|
|
432
|
+
command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath;
|
|
433
|
+
}
|
|
434
|
+
if (appArguments.length > 0) cliArguments.push(...appArguments);
|
|
435
|
+
if (!options.wait) {
|
|
436
|
+
childProcessOptions.stdio = 'ignore';
|
|
437
|
+
childProcessOptions.detached = true;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if ('darwin' === platform && appArguments.length > 0) cliArguments.push('--args', ...appArguments);
|
|
441
|
+
if (options.target) cliArguments.push(options.target);
|
|
442
|
+
const subprocess = node_child_process.spawn(command, cliArguments, childProcessOptions);
|
|
443
|
+
if (options.wait) return new Promise((resolve, reject)=>{
|
|
444
|
+
subprocess.once('error', reject);
|
|
445
|
+
subprocess.once('close', (exitCode)=>{
|
|
446
|
+
if (!options.allowNonzeroExitCode && 0 !== exitCode) return void reject(new Error(`Exited with code ${exitCode}`));
|
|
447
|
+
resolve(subprocess);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
if (isFallbackAttempt) return new Promise((resolve, reject)=>{
|
|
451
|
+
subprocess.once('error', reject);
|
|
452
|
+
subprocess.once('spawn', ()=>{
|
|
453
|
+
subprocess.once('close', (exitCode)=>{
|
|
454
|
+
subprocess.off('error', reject);
|
|
455
|
+
if (0 !== exitCode) return void reject(new Error(`Exited with code ${exitCode}`));
|
|
456
|
+
subprocess.unref();
|
|
457
|
+
resolve(subprocess);
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
subprocess.unref();
|
|
462
|
+
return new Promise((resolve, reject)=>{
|
|
463
|
+
subprocess.once('error', reject);
|
|
464
|
+
subprocess.once('spawn', ()=>{
|
|
465
|
+
subprocess.off('error', reject);
|
|
466
|
+
resolve(subprocess);
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
};
|
|
470
|
+
const open_open = (target, options)=>{
|
|
471
|
+
if ('string' != typeof target) throw new TypeError('Expected a `target`');
|
|
472
|
+
return baseOpen({
|
|
473
|
+
...options,
|
|
474
|
+
target
|
|
475
|
+
});
|
|
476
|
+
};
|
|
477
|
+
function detectArchBinary(binary) {
|
|
478
|
+
if ('string' == typeof binary || Array.isArray(binary)) return binary;
|
|
479
|
+
const { [arch]: archBinary } = binary;
|
|
480
|
+
if (!archBinary) throw new Error(`${arch} is not supported`);
|
|
481
|
+
return archBinary;
|
|
482
|
+
}
|
|
483
|
+
function detectPlatformBinary({ [platform]: platformBinary }, { wsl } = {}) {
|
|
484
|
+
if (wsl && is_wsl) return detectArchBinary(wsl);
|
|
485
|
+
if (!platformBinary) throw new Error(`${platform} is not supported`);
|
|
486
|
+
return detectArchBinary(platformBinary);
|
|
487
|
+
}
|
|
488
|
+
const open_apps = {
|
|
489
|
+
browser: 'browser',
|
|
490
|
+
browserPrivate: 'browserPrivate'
|
|
491
|
+
};
|
|
492
|
+
defineLazyProperty(open_apps, 'chrome', ()=>detectPlatformBinary({
|
|
493
|
+
darwin: 'google chrome',
|
|
494
|
+
win32: 'chrome',
|
|
495
|
+
linux: [
|
|
496
|
+
'google-chrome',
|
|
497
|
+
'google-chrome-stable',
|
|
498
|
+
'chromium',
|
|
499
|
+
'chromium-browser'
|
|
500
|
+
]
|
|
501
|
+
}, {
|
|
502
|
+
wsl: {
|
|
503
|
+
ia32: '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe',
|
|
504
|
+
x64: [
|
|
505
|
+
'/mnt/c/Program Files/Google/Chrome/Application/chrome.exe',
|
|
506
|
+
'/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'
|
|
507
|
+
]
|
|
508
|
+
}
|
|
509
|
+
}));
|
|
510
|
+
defineLazyProperty(open_apps, 'brave', ()=>detectPlatformBinary({
|
|
511
|
+
darwin: 'brave browser',
|
|
512
|
+
win32: 'brave',
|
|
513
|
+
linux: [
|
|
514
|
+
'brave-browser',
|
|
515
|
+
'brave'
|
|
516
|
+
]
|
|
517
|
+
}, {
|
|
518
|
+
wsl: {
|
|
519
|
+
ia32: '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe',
|
|
520
|
+
x64: [
|
|
521
|
+
'/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe',
|
|
522
|
+
'/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe'
|
|
523
|
+
]
|
|
524
|
+
}
|
|
525
|
+
}));
|
|
526
|
+
defineLazyProperty(open_apps, 'firefox', ()=>detectPlatformBinary({
|
|
527
|
+
darwin: 'firefox',
|
|
528
|
+
win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
|
|
529
|
+
linux: 'firefox'
|
|
530
|
+
}, {
|
|
531
|
+
wsl: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe'
|
|
532
|
+
}));
|
|
533
|
+
defineLazyProperty(open_apps, 'edge', ()=>detectPlatformBinary({
|
|
534
|
+
darwin: 'microsoft edge',
|
|
535
|
+
win32: 'msedge',
|
|
536
|
+
linux: [
|
|
537
|
+
'microsoft-edge',
|
|
538
|
+
'microsoft-edge-dev'
|
|
539
|
+
]
|
|
540
|
+
}, {
|
|
541
|
+
wsl: '/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'
|
|
542
|
+
}));
|
|
543
|
+
defineLazyProperty(open_apps, 'safari', ()=>detectPlatformBinary({
|
|
544
|
+
darwin: 'Safari'
|
|
545
|
+
}));
|
|
546
|
+
const node_modules_open = open_open;
|
|
547
|
+
export { node_modules_open };
|