@rsbuild/core 1.6.7-canary-57e2a56d-20251120152633 → 1.6.8

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/dist/0~open.js CHANGED
@@ -1,9 +1,9 @@
1
- let isDockerCached, cachedResult, mountPoint, defaultMountPoint;
1
+ let isDockerCached, cachedResult, canAccessPowerShellPromise, mountPoint, defaultMountPoint;
2
2
  import { __webpack_require__ } from "./rslib-runtime.js";
3
- import { Buffer } from "node:buffer";
4
3
  import node_child_process, { execFile } from "node:child_process";
5
4
  import promises, { constants } from "node:fs/promises";
6
- import { node_fs, node_process, node_os, external_node_util_promisify } from "./169.js";
5
+ import { Buffer } from "node:buffer";
6
+ import { node_fs, node_process, node_os, external_node_util_promisify } from "./506.js";
7
7
  function hasDockerEnv() {
8
8
  try {
9
9
  return node_fs.statSync('/.dockerenv'), !0;
@@ -38,7 +38,24 @@ let isWsl = ()=>{
38
38
  } catch {
39
39
  return !1;
40
40
  }
41
- }, is_wsl = node_process.env.__IS_WSL_TEST__ ? isWsl : isWsl(), wslDrivesMountPoint = (defaultMountPoint = '/mnt/', async function() {
41
+ }, is_wsl = node_process.env.__IS_WSL_TEST__ ? isWsl : isWsl(), powershell_utils_execFile = external_node_util_promisify(node_child_process.execFile), powerShellPath = ()=>`${node_process.env.SYSTEMROOT || node_process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`, executePowerShell = async (command, options = {})=>{
42
+ let { powerShellPath: psPath, ...execFileOptions } = options, encodedCommand = executePowerShell.encodeCommand(command);
43
+ return powershell_utils_execFile(psPath ?? powerShellPath(), [
44
+ ...executePowerShell.argumentsPrefix,
45
+ encodedCommand
46
+ ], {
47
+ encoding: 'utf8',
48
+ ...execFileOptions
49
+ });
50
+ };
51
+ executePowerShell.argumentsPrefix = [
52
+ '-NoProfile',
53
+ '-NonInteractive',
54
+ '-ExecutionPolicy',
55
+ 'Bypass',
56
+ '-EncodedCommand'
57
+ ], executePowerShell.encodeCommand = (command)=>Buffer.from(command, 'utf16le').toString('base64'), executePowerShell.escapeArgument = (value)=>`'${String(value).replaceAll('\'', '\'\'')}'`;
58
+ let wsl_utils_execFile = external_node_util_promisify(node_child_process.execFile), wslDrivesMountPoint = (defaultMountPoint = '/mnt/', async function() {
42
59
  if (mountPoint) return mountPoint;
43
60
  let configFilePath = '/etc/wsl.conf', isConfigFileExists = !1;
44
61
  try {
@@ -52,7 +69,32 @@ let isWsl = ()=>{
52
69
  }), powerShellPathFromWsl = async ()=>{
53
70
  let mountPoint = await wslDrivesMountPoint();
54
71
  return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
55
- }, powerShellPath = async ()=>is_wsl ? powerShellPathFromWsl() : `${node_process.env.SYSTEMROOT || node_process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
72
+ }, wsl_utils_powerShellPath = is_wsl ? powerShellPathFromWsl : powerShellPath, wsl_utils_canAccessPowerShell = async ()=>canAccessPowerShellPromise ??= (async ()=>{
73
+ try {
74
+ let psPath = await wsl_utils_powerShellPath();
75
+ return await promises.access(psPath, constants.X_OK), !0;
76
+ } catch {
77
+ return !1;
78
+ }
79
+ })(), wslDefaultBrowser = async ()=>{
80
+ let psPath = await wsl_utils_powerShellPath(), command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`, { stdout } = await executePowerShell(command, {
81
+ powerShellPath: psPath
82
+ });
83
+ return stdout.trim();
84
+ }, convertWslPathToWindows = async (path)=>{
85
+ if (/^[a-z]+:\/\//i.test(path)) return path;
86
+ try {
87
+ let { stdout } = await wsl_utils_execFile('wslpath', [
88
+ '-aw',
89
+ path
90
+ ], {
91
+ encoding: 'utf8'
92
+ });
93
+ return stdout.trim();
94
+ } catch {
95
+ return path;
96
+ }
97
+ };
56
98
  function defineLazyProperty(object, propertyName, valueGetter) {
57
99
  let define = (value)=>Object.defineProperty(object, propertyName, {
58
100
  value,
@@ -99,30 +141,38 @@ async function bundleName(bundleId) {
99
141
  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")`);
100
142
  }
101
143
  let windows_execFileAsync = external_node_util_promisify(execFile), windowsBrowserProgIds = {
102
- AppXq0fevzme2pys62n3e0fbqa7peapykr8v: {
103
- name: 'Edge',
104
- id: 'com.microsoft.edge.old'
105
- },
106
- MSEdgeDHTML: {
107
- name: 'Edge',
108
- id: 'com.microsoft.edge'
109
- },
110
144
  MSEdgeHTM: {
111
145
  name: 'Edge',
112
146
  id: 'com.microsoft.edge'
113
147
  },
114
- 'IE.HTTP': {
115
- name: 'Internet Explorer',
116
- id: 'com.microsoft.ie'
148
+ MSEdgeBHTML: {
149
+ name: 'Edge Beta',
150
+ id: 'com.microsoft.edge.beta'
117
151
  },
118
- FirefoxURL: {
119
- name: 'Firefox',
120
- id: 'org.mozilla.firefox'
152
+ MSEdgeDHTML: {
153
+ name: 'Edge Dev',
154
+ id: 'com.microsoft.edge.dev'
155
+ },
156
+ AppXq0fevzme2pys62n3e0fbqa7peapykr8v: {
157
+ name: 'Edge',
158
+ id: 'com.microsoft.edge.old'
121
159
  },
122
160
  ChromeHTML: {
123
161
  name: 'Chrome',
124
162
  id: 'com.google.chrome'
125
163
  },
164
+ ChromeBHTML: {
165
+ name: 'Chrome Beta',
166
+ id: 'com.google.chrome.beta'
167
+ },
168
+ ChromeDHTML: {
169
+ name: 'Chrome Dev',
170
+ id: 'com.google.chrome.dev'
171
+ },
172
+ ChromiumHTM: {
173
+ name: 'Chromium',
174
+ id: 'org.chromium.Chromium'
175
+ },
126
176
  BraveHTML: {
127
177
  name: 'Brave',
128
178
  id: 'com.brave.Browser'
@@ -131,11 +181,31 @@ let windows_execFileAsync = external_node_util_promisify(execFile), windowsBrows
131
181
  name: 'Brave Beta',
132
182
  id: 'com.brave.Browser.beta'
133
183
  },
184
+ BraveDHTML: {
185
+ name: 'Brave Dev',
186
+ id: 'com.brave.Browser.dev'
187
+ },
134
188
  BraveSSHTM: {
135
189
  name: 'Brave Nightly',
136
190
  id: 'com.brave.Browser.nightly'
191
+ },
192
+ FirefoxURL: {
193
+ name: 'Firefox',
194
+ id: 'org.mozilla.firefox'
195
+ },
196
+ OperaStable: {
197
+ name: 'Opera',
198
+ id: 'com.operasoftware.Opera'
199
+ },
200
+ VivaldiHTM: {
201
+ name: 'Vivaldi',
202
+ id: 'com.vivaldi.Vivaldi'
203
+ },
204
+ 'IE.HTTP': {
205
+ name: 'Internet Explorer',
206
+ id: 'com.microsoft.ie'
137
207
  }
138
- };
208
+ }, _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
139
209
  class UnknownBrowserError extends Error {
140
210
  }
141
211
  async function defaultBrowser(_execFileAsync = windows_execFileAsync) {
@@ -173,89 +243,87 @@ async function default_browser_defaultBrowser() {
173
243
  if ('win32' === node_process.platform) return defaultBrowser();
174
244
  throw Error('Only macOS, Linux, and Windows are supported');
175
245
  }
176
- let external_node_path_ = __webpack_require__("node:path"), external_node_url_ = __webpack_require__("node:url"), open_execFile = external_node_util_promisify(node_child_process.execFile), open_dirname = external_node_path_.default.dirname((0, external_node_url_.fileURLToPath)(import.meta.url)), localXdgOpenPath = external_node_path_.default.join(open_dirname, 'xdg-open'), { platform: platform, arch: arch } = node_process;
177
- async function getWindowsDefaultBrowserFromWsl() {
178
- let powershellPath = await powerShellPath(), rawCommand = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`, encodedCommand = Buffer.from(rawCommand, 'utf16le').toString('base64'), { stdout } = await open_execFile(powershellPath, [
179
- '-NoProfile',
180
- '-NonInteractive',
181
- '-ExecutionPolicy',
182
- 'Bypass',
183
- '-EncodedCommand',
184
- encodedCommand
185
- ], {
186
- encoding: 'utf8'
187
- }), progId = stdout.trim(), browserMap = {
188
- ChromeHTML: 'com.google.chrome',
189
- BraveHTML: 'com.brave.Browser',
190
- MSEdgeHTM: 'com.microsoft.edge',
191
- FirefoxURL: 'org.mozilla.firefox'
192
- };
193
- return browserMap[progId] ? {
194
- id: browserMap[progId]
195
- } : {};
196
- }
197
- let pTryEach = async (array, mapper)=>{
198
- let latestError;
199
- for (let item of array)try {
200
- return await mapper(item);
246
+ let isInSsh = !!(node_process.env.SSH_CONNECTION || node_process.env.SSH_CLIENT || node_process.env.SSH_TTY), external_node_path_ = __webpack_require__("node:path"), external_node_url_ = __webpack_require__("node:url"), fallbackAttemptSymbol = Symbol('fallbackAttempt'), open_dirname = import.meta.url ? external_node_path_.default.dirname((0, external_node_url_.fileURLToPath)(import.meta.url)) : '', localXdgOpenPath = external_node_path_.default.join(open_dirname, 'xdg-open'), { platform: platform, arch: arch } = node_process, tryEachApp = async (apps, opener)=>{
247
+ if (0 === apps.length) return;
248
+ let errors = [];
249
+ for (let app of apps)try {
250
+ return await opener(app);
201
251
  } catch (error) {
202
- latestError = error;
252
+ errors.push(error);
203
253
  }
204
- throw latestError;
254
+ throw AggregateError(errors, 'Failed to open in all supported apps');
205
255
  }, baseOpen = async (options)=>{
206
- let command;
207
- if (Array.isArray((options = {
256
+ let command, isFallbackAttempt = !0 === (options = {
208
257
  wait: !1,
209
258
  background: !1,
210
259
  newInstance: !1,
211
260
  allowNonzeroExitCode: !1,
212
261
  ...options
213
- }).app)) return pTryEach(options.app, (singleApp)=>baseOpen({
262
+ })[fallbackAttemptSymbol];
263
+ if (delete options[fallbackAttemptSymbol], Array.isArray(options.app)) return tryEachApp(options.app, (singleApp)=>baseOpen({
214
264
  ...options,
215
- app: singleApp
265
+ app: singleApp,
266
+ [fallbackAttemptSymbol]: !0
216
267
  }));
217
268
  let { name: app, arguments: appArguments = [] } = options.app ?? {};
218
269
  if (appArguments = [
219
270
  ...appArguments
220
- ], Array.isArray(app)) return pTryEach(app, (appName)=>baseOpen({
271
+ ], Array.isArray(app)) return tryEachApp(app, (appName)=>baseOpen({
221
272
  ...options,
222
273
  app: {
223
274
  name: appName,
224
275
  arguments: appArguments
225
- }
276
+ },
277
+ [fallbackAttemptSymbol]: !0
226
278
  }));
227
279
  if ('browser' === app || 'browserPrivate' === app) {
228
- let ids = {
280
+ let browser, ids = {
229
281
  'com.google.chrome': 'chrome',
230
282
  'google-chrome.desktop': 'chrome',
231
- 'com.brave.Browser': 'brave',
283
+ 'com.brave.browser': 'brave',
232
284
  'org.mozilla.firefox': 'firefox',
233
285
  'firefox.desktop': 'firefox',
234
286
  'com.microsoft.msedge': 'edge',
235
287
  'com.microsoft.edge': 'edge',
236
288
  'com.microsoft.edgemac': 'edge',
237
- 'microsoft-edge.desktop': 'edge'
238
- }, browser = is_wsl ? await getWindowsDefaultBrowserFromWsl() : await default_browser_defaultBrowser();
289
+ 'microsoft-edge.desktop': 'edge',
290
+ 'com.apple.safari': 'safari'
291
+ };
292
+ if (is_wsl) {
293
+ let progId = await wslDefaultBrowser();
294
+ browser = _windowsBrowserProgIdMap.get(progId) ?? {};
295
+ } else browser = await default_browser_defaultBrowser();
239
296
  if (browser.id in ids) {
240
- let browserName = ids[browser.id];
241
- return 'browserPrivate' === app && appArguments.push({
242
- chrome: '--incognito',
243
- brave: '--incognito',
244
- firefox: '--private-window',
245
- edge: '--inPrivate'
246
- }[browserName]), baseOpen({
297
+ let browserName = ids[browser.id.toLowerCase()];
298
+ if ('browserPrivate' === app) {
299
+ if ('safari' === browserName) throw Error('Safari doesn\'t support opening in private mode via command line');
300
+ appArguments.push({
301
+ chrome: '--incognito',
302
+ brave: '--incognito',
303
+ firefox: '--private-window',
304
+ edge: '--inPrivate'
305
+ }[browserName]);
306
+ }
307
+ return baseOpen({
247
308
  ...options,
248
309
  app: {
249
- name: apps[browserName],
310
+ name: open_apps[browserName],
250
311
  arguments: appArguments
251
312
  }
252
313
  });
253
314
  }
254
315
  throw Error(`${browser.name} is not supported as a default browser`);
255
316
  }
256
- let cliArguments = [], childProcessOptions = {};
257
- if ('darwin' === platform) command = 'open', options.wait && cliArguments.push('--wait-apps'), options.background && cliArguments.push('--background'), options.newInstance && cliArguments.push('--new'), app && cliArguments.push('-a', app);
258
- else if ('win32' !== platform && (!is_wsl || isInsideContainer() || app)) {
317
+ let cliArguments = [], childProcessOptions = {}, shouldUseWindowsInWsl = !1;
318
+ if (!is_wsl || isInsideContainer() || isInSsh || app || (shouldUseWindowsInWsl = await wsl_utils_canAccessPowerShell()), 'darwin' === platform) command = 'open', options.wait && cliArguments.push('--wait-apps'), options.background && cliArguments.push('--background'), options.newInstance && cliArguments.push('--new'), app && cliArguments.push('-a', app);
319
+ else if ('win32' === platform || shouldUseWindowsInWsl) {
320
+ command = await wsl_utils_powerShellPath(), cliArguments.push(...executePowerShell.argumentsPrefix), is_wsl || (childProcessOptions.windowsVerbatimArguments = !0), is_wsl && options.target && (options.target = await convertWslPathToWindows(options.target));
321
+ let encodedArguments = [
322
+ '$ProgressPreference = \'SilentlyContinue\';',
323
+ 'Start'
324
+ ];
325
+ options.wait && encodedArguments.push('-Wait'), app ? (encodedArguments.push(executePowerShell.escapeArgument(app)), options.target && appArguments.push(options.target)) : options.target && encodedArguments.push(executePowerShell.escapeArgument(options.target)), appArguments.length > 0 && encodedArguments.push('-ArgumentList', (appArguments = appArguments.map((argument)=>executePowerShell.escapeArgument(argument))).join(',')), options.target = executePowerShell.encodeCommand(encodedArguments.join(' ')), options.wait || (childProcessOptions.stdio = 'ignore');
326
+ } else {
259
327
  if (app) command = app;
260
328
  else {
261
329
  let exeLocalXdgOpen = !1;
@@ -265,20 +333,24 @@ let pTryEach = async (array, mapper)=>{
265
333
  command = node_process.versions.electron ?? ('android' === platform || !open_dirname || '/' === open_dirname || !exeLocalXdgOpen) ? 'xdg-open' : localXdgOpenPath;
266
334
  }
267
335
  appArguments.length > 0 && cliArguments.push(...appArguments), options.wait || (childProcessOptions.stdio = 'ignore', childProcessOptions.detached = !0);
268
- } else {
269
- command = await powerShellPath(), cliArguments.push('-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand'), is_wsl || (childProcessOptions.windowsVerbatimArguments = !0);
270
- let encodedArguments = [
271
- 'Start'
272
- ];
273
- options.wait && encodedArguments.push('-Wait'), app ? (encodedArguments.push(`"\`"${app}\`""`), options.target && appArguments.push(options.target)) : options.target && encodedArguments.push(`"${options.target}"`), appArguments.length > 0 && encodedArguments.push('-ArgumentList', (appArguments = appArguments.map((argument)=>`"\`"${argument}\`""`)).join(',')), options.target = Buffer.from(encodedArguments.join(' '), 'utf16le').toString('base64');
274
336
  }
275
337
  'darwin' === platform && appArguments.length > 0 && cliArguments.push('--args', ...appArguments), options.target && cliArguments.push(options.target);
276
338
  let subprocess = node_child_process.spawn(command, cliArguments, childProcessOptions);
277
339
  return options.wait ? new Promise((resolve, reject)=>{
278
340
  subprocess.once('error', reject), subprocess.once('close', (exitCode)=>{
279
- !options.allowNonzeroExitCode && exitCode > 0 ? reject(Error(`Exited with code ${exitCode}`)) : resolve(subprocess);
341
+ options.allowNonzeroExitCode || 0 === exitCode ? resolve(subprocess) : reject(Error(`Exited with code ${exitCode}`));
280
342
  });
281
- }) : (subprocess.unref(), subprocess);
343
+ }) : isFallbackAttempt ? new Promise((resolve, reject)=>{
344
+ subprocess.once('error', reject), subprocess.once('spawn', ()=>{
345
+ subprocess.once('close', (exitCode)=>{
346
+ (subprocess.off('error', reject), 0 !== exitCode) ? reject(Error(`Exited with code ${exitCode}`)) : (subprocess.unref(), resolve(subprocess));
347
+ });
348
+ });
349
+ }) : (subprocess.unref(), new Promise((resolve, reject)=>{
350
+ subprocess.once('error', reject), subprocess.once('spawn', ()=>{
351
+ subprocess.off('error', reject), resolve(subprocess);
352
+ });
353
+ }));
282
354
  };
283
355
  function detectArchBinary(binary) {
284
356
  if ('string' == typeof binary || Array.isArray(binary)) return binary;
@@ -286,19 +358,23 @@ function detectArchBinary(binary) {
286
358
  if (!archBinary) throw Error(`${arch} is not supported`);
287
359
  return archBinary;
288
360
  }
289
- function detectPlatformBinary({ [platform]: platformBinary }, { wsl }) {
361
+ function detectPlatformBinary({ [platform]: platformBinary }, { wsl } = {}) {
290
362
  if (wsl && is_wsl) return detectArchBinary(wsl);
291
363
  if (!platformBinary) throw Error(`${platform} is not supported`);
292
364
  return detectArchBinary(platformBinary);
293
365
  }
294
- let apps = {};
295
- defineLazyProperty(apps, 'chrome', ()=>detectPlatformBinary({
366
+ let open_apps = {
367
+ browser: 'browser',
368
+ browserPrivate: 'browserPrivate'
369
+ };
370
+ defineLazyProperty(open_apps, 'chrome', ()=>detectPlatformBinary({
296
371
  darwin: 'google chrome',
297
372
  win32: 'chrome',
298
373
  linux: [
299
374
  'google-chrome',
300
375
  'google-chrome-stable',
301
- 'chromium'
376
+ 'chromium',
377
+ 'chromium-browser'
302
378
  ]
303
379
  }, {
304
380
  wsl: {
@@ -308,7 +384,7 @@ defineLazyProperty(apps, 'chrome', ()=>detectPlatformBinary({
308
384
  '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'
309
385
  ]
310
386
  }
311
- })), defineLazyProperty(apps, 'brave', ()=>detectPlatformBinary({
387
+ })), defineLazyProperty(open_apps, 'brave', ()=>detectPlatformBinary({
312
388
  darwin: 'brave browser',
313
389
  win32: 'brave',
314
390
  linux: [
@@ -323,13 +399,13 @@ defineLazyProperty(apps, 'chrome', ()=>detectPlatformBinary({
323
399
  '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe'
324
400
  ]
325
401
  }
326
- })), defineLazyProperty(apps, 'firefox', ()=>detectPlatformBinary({
402
+ })), defineLazyProperty(open_apps, 'firefox', ()=>detectPlatformBinary({
327
403
  darwin: 'firefox',
328
404
  win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
329
405
  linux: 'firefox'
330
406
  }, {
331
407
  wsl: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe'
332
- })), defineLazyProperty(apps, 'edge', ()=>detectPlatformBinary({
408
+ })), defineLazyProperty(open_apps, 'edge', ()=>detectPlatformBinary({
333
409
  darwin: 'microsoft edge',
334
410
  win32: 'msedge',
335
411
  linux: [
@@ -338,7 +414,9 @@ defineLazyProperty(apps, 'chrome', ()=>detectPlatformBinary({
338
414
  ]
339
415
  }, {
340
416
  wsl: '/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'
341
- })), defineLazyProperty(apps, 'browser', ()=>'browser'), defineLazyProperty(apps, 'browserPrivate', ()=>'browserPrivate');
417
+ })), defineLazyProperty(open_apps, 'safari', ()=>detectPlatformBinary({
418
+ darwin: 'Safari'
419
+ }));
342
420
  let node_modules_open = (target, options)=>{
343
421
  if ('string' != typeof target) throw TypeError('Expected a `target`');
344
422
  return baseOpen({
@@ -346,4 +424,4 @@ let node_modules_open = (target, options)=>{
346
424
  target
347
425
  });
348
426
  };
349
- export { apps, node_modules_open };
427
+ export { node_modules_open, open_apps };