@rsbuild/core 1.4.0 → 1.4.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.
@@ -1,153 +0,0 @@
1
- import { ChildProcess } from 'child_process';
2
-
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.
11
-
12
- @default false
13
- */
14
- readonly wait?: boolean;
15
-
16
- /**
17
- __macOS only__
18
-
19
- Do not bring the app to the foreground.
20
-
21
- @default false
22
- */
23
- readonly background?: boolean;
24
-
25
- /**
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;
35
-
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.
40
-
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.
44
- */
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;
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
- };
75
- }
76
-
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.
83
-
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`.
85
-
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.
88
-
89
- @example
90
- ```
91
- import open = require('open');
92
-
93
- // Opens the image in the default image viewer
94
- await open('unicorn.png', {wait: true});
95
- console.log('The image viewer app closed');
96
-
97
- // Opens the url in the default browser
98
- await open('https://sindresorhus.com');
99
-
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
- };
152
-
153
- export { open as default };
@@ -1,409 +0,0 @@
1
- (() => {
2
- var __webpack_modules__ = {
3
- 932: (module) => {
4
- "use strict";
5
- module.exports = (object, propertyName, fn) => {
6
- const define = (value) =>
7
- Object.defineProperty(object, propertyName, {
8
- value,
9
- enumerable: true,
10
- writable: true,
11
- });
12
- Object.defineProperty(object, propertyName, {
13
- configurable: true,
14
- enumerable: true,
15
- get() {
16
- const result = fn();
17
- define(result);
18
- return result;
19
- },
20
- set(value) {
21
- define(value);
22
- },
23
- });
24
- return object;
25
- };
26
- },
27
- 293: (module, __unused_webpack_exports, __nccwpck_require__) => {
28
- "use strict";
29
- const fs = __nccwpck_require__(896);
30
- let isDocker;
31
- function hasDockerEnv() {
32
- try {
33
- fs.statSync("/.dockerenv");
34
- return true;
35
- } catch (_) {
36
- return false;
37
- }
38
- }
39
- function hasDockerCGroup() {
40
- try {
41
- return fs
42
- .readFileSync("/proc/self/cgroup", "utf8")
43
- .includes("docker");
44
- } catch (_) {
45
- return false;
46
- }
47
- }
48
- module.exports = () => {
49
- if (isDocker === undefined) {
50
- isDocker = hasDockerEnv() || hasDockerCGroup();
51
- }
52
- return isDocker;
53
- };
54
- },
55
- 622: (module, __unused_webpack_exports, __nccwpck_require__) => {
56
- "use strict";
57
- const os = __nccwpck_require__(857);
58
- const fs = __nccwpck_require__(896);
59
- const isDocker = __nccwpck_require__(293);
60
- const isWsl = () => {
61
- if (process.platform !== "linux") {
62
- return false;
63
- }
64
- if (os.release().toLowerCase().includes("microsoft")) {
65
- if (isDocker()) {
66
- return false;
67
- }
68
- return true;
69
- }
70
- try {
71
- return fs
72
- .readFileSync("/proc/version", "utf8")
73
- .toLowerCase()
74
- .includes("microsoft")
75
- ? !isDocker()
76
- : false;
77
- } catch (_) {
78
- return false;
79
- }
80
- };
81
- if (process.env.__IS_WSL_TEST__) {
82
- module.exports = isWsl;
83
- } else {
84
- module.exports = isWsl();
85
- }
86
- },
87
- 820: (module, __unused_webpack_exports, __nccwpck_require__) => {
88
- const path = __nccwpck_require__(928);
89
- const childProcess = __nccwpck_require__(317);
90
- const { promises: fs, constants: fsConstants } = __nccwpck_require__(896);
91
- const isWsl = __nccwpck_require__(622);
92
- const isDocker = __nccwpck_require__(293);
93
- const defineLazyProperty = __nccwpck_require__(932);
94
- const localXdgOpenPath = __nccwpck_require__.ab + "xdg-open";
95
- const { platform, arch } = process;
96
- const hasContainerEnv = () => {
97
- try {
98
- fs.statSync("/run/.containerenv");
99
- return true;
100
- } catch {
101
- return false;
102
- }
103
- };
104
- let cachedResult;
105
- function isInsideContainer() {
106
- if (cachedResult === undefined) {
107
- cachedResult = hasContainerEnv() || isDocker();
108
- }
109
- return cachedResult;
110
- }
111
- const getWslDrivesMountPoint = (() => {
112
- const defaultMountPoint = "/mnt/";
113
- let mountPoint;
114
- return async function () {
115
- if (mountPoint) {
116
- return mountPoint;
117
- }
118
- const configFilePath = "/etc/wsl.conf";
119
- let isConfigFileExists = false;
120
- try {
121
- await fs.access(configFilePath, fsConstants.F_OK);
122
- isConfigFileExists = true;
123
- } catch {}
124
- if (!isConfigFileExists) {
125
- return defaultMountPoint;
126
- }
127
- const configContent = await fs.readFile(configFilePath, {
128
- encoding: "utf8",
129
- });
130
- const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(
131
- configContent,
132
- );
133
- if (!configMountPoint) {
134
- return defaultMountPoint;
135
- }
136
- mountPoint = configMountPoint.groups.mountPoint.trim();
137
- mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
138
- return mountPoint;
139
- };
140
- })();
141
- const pTryEach = async (array, mapper) => {
142
- let latestError;
143
- for (const item of array) {
144
- try {
145
- return await mapper(item);
146
- } catch (error) {
147
- latestError = error;
148
- }
149
- }
150
- throw latestError;
151
- };
152
- const baseOpen = async (options) => {
153
- options = {
154
- wait: false,
155
- background: false,
156
- newInstance: false,
157
- allowNonzeroExitCode: false,
158
- ...options,
159
- };
160
- if (Array.isArray(options.app)) {
161
- return pTryEach(options.app, (singleApp) =>
162
- baseOpen({ ...options, app: singleApp }),
163
- );
164
- }
165
- let { name: app, arguments: appArguments = [] } = options.app || {};
166
- appArguments = [...appArguments];
167
- if (Array.isArray(app)) {
168
- return pTryEach(app, (appName) =>
169
- baseOpen({
170
- ...options,
171
- app: { name: appName, arguments: appArguments },
172
- }),
173
- );
174
- }
175
- let command;
176
- const cliArguments = [];
177
- const childProcessOptions = {};
178
- if (platform === "darwin") {
179
- command = "open";
180
- if (options.wait) {
181
- cliArguments.push("--wait-apps");
182
- }
183
- if (options.background) {
184
- cliArguments.push("--background");
185
- }
186
- if (options.newInstance) {
187
- cliArguments.push("--new");
188
- }
189
- if (app) {
190
- cliArguments.push("-a", app);
191
- }
192
- } else if (
193
- platform === "win32" ||
194
- (isWsl && !isInsideContainer() && !app)
195
- ) {
196
- const mountPoint = await getWslDrivesMountPoint();
197
- command = isWsl
198
- ? `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`
199
- : `${process.env.SYSTEMROOT}\\System32\\WindowsPowerShell\\v1.0\\powershell`;
200
- cliArguments.push(
201
- "-NoProfile",
202
- "-NonInteractive",
203
- "–ExecutionPolicy",
204
- "Bypass",
205
- "-EncodedCommand",
206
- );
207
- if (!isWsl) {
208
- childProcessOptions.windowsVerbatimArguments = true;
209
- }
210
- const encodedArguments = ["Start"];
211
- if (options.wait) {
212
- encodedArguments.push("-Wait");
213
- }
214
- if (app) {
215
- encodedArguments.push(`"\`"${app}\`""`, "-ArgumentList");
216
- if (options.target) {
217
- appArguments.unshift(options.target);
218
- }
219
- } else if (options.target) {
220
- encodedArguments.push(`"${options.target}"`);
221
- }
222
- if (appArguments.length > 0) {
223
- appArguments = appArguments.map((arg) => `"\`"${arg}\`""`);
224
- encodedArguments.push(appArguments.join(","));
225
- }
226
- options.target = Buffer.from(
227
- encodedArguments.join(" "),
228
- "utf16le",
229
- ).toString("base64");
230
- } else {
231
- if (app) {
232
- command = app;
233
- } else {
234
- const isBundled = !__dirname || __dirname === "/";
235
- let exeLocalXdgOpen = false;
236
- try {
237
- await fs.access(
238
- __nccwpck_require__.ab + "xdg-open",
239
- fsConstants.X_OK,
240
- );
241
- exeLocalXdgOpen = true;
242
- } catch {}
243
- const useSystemXdgOpen =
244
- process.versions.electron ||
245
- platform === "android" ||
246
- isBundled ||
247
- !exeLocalXdgOpen;
248
- command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
249
- }
250
- if (appArguments.length > 0) {
251
- cliArguments.push(...appArguments);
252
- }
253
- if (!options.wait) {
254
- childProcessOptions.stdio = "ignore";
255
- childProcessOptions.detached = true;
256
- }
257
- }
258
- if (options.target) {
259
- cliArguments.push(options.target);
260
- }
261
- if (platform === "darwin" && appArguments.length > 0) {
262
- cliArguments.push("--args", ...appArguments);
263
- }
264
- const subprocess = childProcess.spawn(
265
- command,
266
- cliArguments,
267
- childProcessOptions,
268
- );
269
- if (options.wait) {
270
- return new Promise((resolve, reject) => {
271
- subprocess.once("error", reject);
272
- subprocess.once("close", (exitCode) => {
273
- if (!options.allowNonzeroExitCode && exitCode > 0) {
274
- reject(new Error(`Exited with code ${exitCode}`));
275
- return;
276
- }
277
- resolve(subprocess);
278
- });
279
- });
280
- }
281
- subprocess.unref();
282
- return subprocess;
283
- };
284
- const open = (target, options) => {
285
- if (typeof target !== "string") {
286
- throw new TypeError("Expected a `target`");
287
- }
288
- return baseOpen({ ...options, target });
289
- };
290
- const openApp = (name, options) => {
291
- if (typeof name !== "string") {
292
- throw new TypeError("Expected a `name`");
293
- }
294
- const { arguments: appArguments = [] } = options || {};
295
- if (
296
- appArguments !== undefined &&
297
- appArguments !== null &&
298
- !Array.isArray(appArguments)
299
- ) {
300
- throw new TypeError("Expected `appArguments` as Array type");
301
- }
302
- return baseOpen({ ...options, app: { name, arguments: appArguments } });
303
- };
304
- function detectArchBinary(binary) {
305
- if (typeof binary === "string" || Array.isArray(binary)) {
306
- return binary;
307
- }
308
- const { [arch]: archBinary } = binary;
309
- if (!archBinary) {
310
- throw new Error(`${arch} is not supported`);
311
- }
312
- return archBinary;
313
- }
314
- function detectPlatformBinary({ [platform]: platformBinary }, { wsl }) {
315
- if (wsl && isWsl) {
316
- return detectArchBinary(wsl);
317
- }
318
- if (!platformBinary) {
319
- throw new Error(`${platform} is not supported`);
320
- }
321
- return detectArchBinary(platformBinary);
322
- }
323
- const apps = {};
324
- defineLazyProperty(apps, "chrome", () =>
325
- detectPlatformBinary(
326
- {
327
- darwin: "google chrome",
328
- win32: "chrome",
329
- linux: ["google-chrome", "google-chrome-stable", "chromium"],
330
- },
331
- {
332
- wsl: {
333
- ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
334
- x64: [
335
- "/mnt/c/Program Files/Google/Chrome/Application/chrome.exe",
336
- "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
337
- ],
338
- },
339
- },
340
- ),
341
- );
342
- defineLazyProperty(apps, "firefox", () =>
343
- detectPlatformBinary(
344
- {
345
- darwin: "firefox",
346
- win32: "C:\\Program Files\\Mozilla Firefox\\firefox.exe",
347
- linux: "firefox",
348
- },
349
- { wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe" },
350
- ),
351
- );
352
- defineLazyProperty(apps, "edge", () =>
353
- detectPlatformBinary(
354
- {
355
- darwin: "microsoft edge",
356
- win32: "msedge",
357
- linux: ["microsoft-edge", "microsoft-edge-dev"],
358
- },
359
- {
360
- wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
361
- },
362
- ),
363
- );
364
- open.apps = apps;
365
- open.openApp = openApp;
366
- module.exports = open;
367
- },
368
- 317: (module) => {
369
- "use strict";
370
- module.exports = require("child_process");
371
- },
372
- 896: (module) => {
373
- "use strict";
374
- module.exports = require("fs");
375
- },
376
- 857: (module) => {
377
- "use strict";
378
- module.exports = require("os");
379
- },
380
- 928: (module) => {
381
- "use strict";
382
- module.exports = require("path");
383
- },
384
- };
385
- var __webpack_module_cache__ = {};
386
- function __nccwpck_require__(moduleId) {
387
- var cachedModule = __webpack_module_cache__[moduleId];
388
- if (cachedModule !== undefined) {
389
- return cachedModule.exports;
390
- }
391
- var module = (__webpack_module_cache__[moduleId] = { exports: {} });
392
- var threw = true;
393
- try {
394
- __webpack_modules__[moduleId](
395
- module,
396
- module.exports,
397
- __nccwpck_require__,
398
- );
399
- threw = false;
400
- } finally {
401
- if (threw) delete __webpack_module_cache__[moduleId];
402
- }
403
- return module.exports;
404
- }
405
- if (typeof __nccwpck_require__ !== "undefined")
406
- __nccwpck_require__.ab = __dirname + "/";
407
- var __webpack_exports__ = __nccwpck_require__(820);
408
- module.exports = __webpack_exports__;
409
- })();
@@ -1 +0,0 @@
1
- {"name":"open","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"version":"8.4.2","funding":"https://github.com/sponsors/sindresorhus","license":"MIT","types":"index.d.ts","type":"commonjs"}