@uipath/filesystem 0.1.5
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/browser.d.ts +25 -0
- package/dist/index.browser.d.ts +5 -0
- package/dist/index.browser.js +18575 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +739 -0
- package/dist/interfaces.d.ts +41 -0
- package/dist/node.d.ts +20 -0
- package/package.json +54 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,739 @@
|
|
|
1
|
+
// src/node.ts
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import * as fs6 from "node:fs/promises";
|
|
4
|
+
import * as os2 from "node:os";
|
|
5
|
+
import * as path2 from "node:path";
|
|
6
|
+
|
|
7
|
+
// ../../node_modules/open/index.js
|
|
8
|
+
import process8 from "node:process";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import childProcess3 from "node:child_process";
|
|
12
|
+
import fs5, { constants as fsConstants2 } from "node:fs/promises";
|
|
13
|
+
|
|
14
|
+
// ../../node_modules/wsl-utils/index.js
|
|
15
|
+
import { promisify as promisify2 } from "node:util";
|
|
16
|
+
import childProcess2 from "node:child_process";
|
|
17
|
+
import fs4, { constants as fsConstants } from "node:fs/promises";
|
|
18
|
+
|
|
19
|
+
// ../../node_modules/wsl-utils/node_modules/is-wsl/index.js
|
|
20
|
+
import process2 from "node:process";
|
|
21
|
+
import os from "node:os";
|
|
22
|
+
import fs3 from "node:fs";
|
|
23
|
+
|
|
24
|
+
// ../../node_modules/is-inside-container/index.js
|
|
25
|
+
import fs2 from "node:fs";
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/is-inside-container/node_modules/is-docker/index.js
|
|
28
|
+
import fs from "node:fs";
|
|
29
|
+
var isDockerCached;
|
|
30
|
+
function hasDockerEnv() {
|
|
31
|
+
try {
|
|
32
|
+
fs.statSync("/.dockerenv");
|
|
33
|
+
return true;
|
|
34
|
+
} catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function hasDockerCGroup() {
|
|
39
|
+
try {
|
|
40
|
+
return fs.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function isDocker() {
|
|
46
|
+
if (isDockerCached === undefined) {
|
|
47
|
+
isDockerCached = hasDockerEnv() || hasDockerCGroup();
|
|
48
|
+
}
|
|
49
|
+
return isDockerCached;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ../../node_modules/is-inside-container/index.js
|
|
53
|
+
var cachedResult;
|
|
54
|
+
var hasContainerEnv = () => {
|
|
55
|
+
try {
|
|
56
|
+
fs2.statSync("/run/.containerenv");
|
|
57
|
+
return true;
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
function isInsideContainer() {
|
|
63
|
+
if (cachedResult === undefined) {
|
|
64
|
+
cachedResult = hasContainerEnv() || isDocker();
|
|
65
|
+
}
|
|
66
|
+
return cachedResult;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ../../node_modules/wsl-utils/node_modules/is-wsl/index.js
|
|
70
|
+
var isWsl = () => {
|
|
71
|
+
if (process2.platform !== "linux") {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (os.release().toLowerCase().includes("microsoft")) {
|
|
75
|
+
if (isInsideContainer()) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
if (fs3.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft")) {
|
|
82
|
+
return !isInsideContainer();
|
|
83
|
+
}
|
|
84
|
+
} catch {}
|
|
85
|
+
if (fs3.existsSync("/proc/sys/fs/binfmt_misc/WSLInterop") || fs3.existsSync("/run/WSL")) {
|
|
86
|
+
return !isInsideContainer();
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
var is_wsl_default = process2.env.__IS_WSL_TEST__ ? isWsl : isWsl();
|
|
91
|
+
|
|
92
|
+
// ../../node_modules/powershell-utils/index.js
|
|
93
|
+
import process3 from "node:process";
|
|
94
|
+
import { Buffer } from "node:buffer";
|
|
95
|
+
import { promisify } from "node:util";
|
|
96
|
+
import childProcess from "node:child_process";
|
|
97
|
+
var execFile = promisify(childProcess.execFile);
|
|
98
|
+
var powerShellPath = () => `${process3.env.SYSTEMROOT || process3.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
99
|
+
var executePowerShell = async (command, options = {}) => {
|
|
100
|
+
const {
|
|
101
|
+
powerShellPath: psPath,
|
|
102
|
+
...execFileOptions
|
|
103
|
+
} = options;
|
|
104
|
+
const encodedCommand = executePowerShell.encodeCommand(command);
|
|
105
|
+
return execFile(psPath ?? powerShellPath(), [
|
|
106
|
+
...executePowerShell.argumentsPrefix,
|
|
107
|
+
encodedCommand
|
|
108
|
+
], {
|
|
109
|
+
encoding: "utf8",
|
|
110
|
+
...execFileOptions
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
executePowerShell.argumentsPrefix = [
|
|
114
|
+
"-NoProfile",
|
|
115
|
+
"-NonInteractive",
|
|
116
|
+
"-ExecutionPolicy",
|
|
117
|
+
"Bypass",
|
|
118
|
+
"-EncodedCommand"
|
|
119
|
+
];
|
|
120
|
+
executePowerShell.encodeCommand = (command) => Buffer.from(command, "utf16le").toString("base64");
|
|
121
|
+
executePowerShell.escapeArgument = (value) => `'${String(value).replaceAll("'", "''")}'`;
|
|
122
|
+
|
|
123
|
+
// ../../node_modules/wsl-utils/utilities.js
|
|
124
|
+
function parseMountPointFromConfig(content) {
|
|
125
|
+
for (const line of content.split(`
|
|
126
|
+
`)) {
|
|
127
|
+
if (/^\s*#/.test(line)) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
|
|
131
|
+
if (!match) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
return match.groups.mountPoint.trim().replaceAll(/^["']|["']$/g, "");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ../../node_modules/wsl-utils/index.js
|
|
139
|
+
var execFile2 = promisify2(childProcess2.execFile);
|
|
140
|
+
var wslDrivesMountPoint = (() => {
|
|
141
|
+
const defaultMountPoint = "/mnt/";
|
|
142
|
+
let mountPoint;
|
|
143
|
+
return async function() {
|
|
144
|
+
if (mountPoint) {
|
|
145
|
+
return mountPoint;
|
|
146
|
+
}
|
|
147
|
+
const configFilePath = "/etc/wsl.conf";
|
|
148
|
+
let isConfigFileExists = false;
|
|
149
|
+
try {
|
|
150
|
+
await fs4.access(configFilePath, fsConstants.F_OK);
|
|
151
|
+
isConfigFileExists = true;
|
|
152
|
+
} catch {}
|
|
153
|
+
if (!isConfigFileExists) {
|
|
154
|
+
return defaultMountPoint;
|
|
155
|
+
}
|
|
156
|
+
const configContent = await fs4.readFile(configFilePath, { encoding: "utf8" });
|
|
157
|
+
const parsedMountPoint = parseMountPointFromConfig(configContent);
|
|
158
|
+
if (parsedMountPoint === undefined) {
|
|
159
|
+
return defaultMountPoint;
|
|
160
|
+
}
|
|
161
|
+
mountPoint = parsedMountPoint;
|
|
162
|
+
mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
|
|
163
|
+
return mountPoint;
|
|
164
|
+
};
|
|
165
|
+
})();
|
|
166
|
+
var powerShellPathFromWsl = async () => {
|
|
167
|
+
const mountPoint = await wslDrivesMountPoint();
|
|
168
|
+
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
|
169
|
+
};
|
|
170
|
+
var powerShellPath2 = is_wsl_default ? powerShellPathFromWsl : powerShellPath;
|
|
171
|
+
var canAccessPowerShellPromise;
|
|
172
|
+
var canAccessPowerShell = async () => {
|
|
173
|
+
canAccessPowerShellPromise ??= (async () => {
|
|
174
|
+
try {
|
|
175
|
+
const psPath = await powerShellPath2();
|
|
176
|
+
await fs4.access(psPath, fsConstants.X_OK);
|
|
177
|
+
return true;
|
|
178
|
+
} catch {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
})();
|
|
182
|
+
return canAccessPowerShellPromise;
|
|
183
|
+
};
|
|
184
|
+
var wslDefaultBrowser = async () => {
|
|
185
|
+
const psPath = await powerShellPath2();
|
|
186
|
+
const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
187
|
+
const { stdout } = await executePowerShell(command, { powerShellPath: psPath });
|
|
188
|
+
return stdout.trim();
|
|
189
|
+
};
|
|
190
|
+
var convertWslPathToWindows = async (path) => {
|
|
191
|
+
if (/^[a-z]+:\/\//i.test(path)) {
|
|
192
|
+
return path;
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
const { stdout } = await execFile2("wslpath", ["-aw", path], { encoding: "utf8" });
|
|
196
|
+
return stdout.trim();
|
|
197
|
+
} catch {
|
|
198
|
+
return path;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// ../../node_modules/define-lazy-prop/index.js
|
|
203
|
+
function defineLazyProperty(object, propertyName, valueGetter) {
|
|
204
|
+
const define = (value) => Object.defineProperty(object, propertyName, { value, enumerable: true, writable: true });
|
|
205
|
+
Object.defineProperty(object, propertyName, {
|
|
206
|
+
configurable: true,
|
|
207
|
+
enumerable: true,
|
|
208
|
+
get() {
|
|
209
|
+
const result = valueGetter();
|
|
210
|
+
define(result);
|
|
211
|
+
return result;
|
|
212
|
+
},
|
|
213
|
+
set(value) {
|
|
214
|
+
define(value);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
return object;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ../../node_modules/default-browser/index.js
|
|
221
|
+
import { promisify as promisify6 } from "node:util";
|
|
222
|
+
import process6 from "node:process";
|
|
223
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
224
|
+
|
|
225
|
+
// ../../node_modules/default-browser-id/index.js
|
|
226
|
+
import { promisify as promisify3 } from "node:util";
|
|
227
|
+
import process4 from "node:process";
|
|
228
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
229
|
+
var execFileAsync = promisify3(execFile3);
|
|
230
|
+
async function defaultBrowserId() {
|
|
231
|
+
if (process4.platform !== "darwin") {
|
|
232
|
+
throw new Error("macOS only");
|
|
233
|
+
}
|
|
234
|
+
const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
|
|
235
|
+
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
|
|
236
|
+
const browserId = match?.groups.id ?? "com.apple.Safari";
|
|
237
|
+
if (browserId === "com.apple.safari") {
|
|
238
|
+
return "com.apple.Safari";
|
|
239
|
+
}
|
|
240
|
+
return browserId;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ../../node_modules/run-applescript/index.js
|
|
244
|
+
import process5 from "node:process";
|
|
245
|
+
import { promisify as promisify4 } from "node:util";
|
|
246
|
+
import { execFile as execFile4, execFileSync } from "node:child_process";
|
|
247
|
+
var execFileAsync2 = promisify4(execFile4);
|
|
248
|
+
async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
|
|
249
|
+
if (process5.platform !== "darwin") {
|
|
250
|
+
throw new Error("macOS only");
|
|
251
|
+
}
|
|
252
|
+
const outputArguments = humanReadableOutput ? [] : ["-ss"];
|
|
253
|
+
const execOptions = {};
|
|
254
|
+
if (signal) {
|
|
255
|
+
execOptions.signal = signal;
|
|
256
|
+
}
|
|
257
|
+
const { stdout } = await execFileAsync2("osascript", ["-e", script, outputArguments], execOptions);
|
|
258
|
+
return stdout.trim();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// ../../node_modules/bundle-name/index.js
|
|
262
|
+
async function bundleName(bundleId) {
|
|
263
|
+
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string
|
|
264
|
+
tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ../../node_modules/default-browser/windows.js
|
|
268
|
+
import { promisify as promisify5 } from "node:util";
|
|
269
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
270
|
+
var execFileAsync3 = promisify5(execFile5);
|
|
271
|
+
var windowsBrowserProgIds = {
|
|
272
|
+
MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
|
|
273
|
+
MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
|
|
274
|
+
MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" },
|
|
275
|
+
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
|
|
276
|
+
ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
|
|
277
|
+
ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" },
|
|
278
|
+
ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" },
|
|
279
|
+
ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" },
|
|
280
|
+
BraveHTML: { name: "Brave", id: "com.brave.Browser" },
|
|
281
|
+
BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
|
|
282
|
+
BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" },
|
|
283
|
+
BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" },
|
|
284
|
+
FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
|
|
285
|
+
OperaStable: { name: "Opera", id: "com.operasoftware.Opera" },
|
|
286
|
+
VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" },
|
|
287
|
+
"IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" }
|
|
288
|
+
};
|
|
289
|
+
var _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
|
|
290
|
+
|
|
291
|
+
class UnknownBrowserError extends Error {
|
|
292
|
+
}
|
|
293
|
+
async function defaultBrowser(_execFileAsync = execFileAsync3) {
|
|
294
|
+
const { stdout } = await _execFileAsync("reg", [
|
|
295
|
+
"QUERY",
|
|
296
|
+
" HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
|
|
297
|
+
"/v",
|
|
298
|
+
"ProgId"
|
|
299
|
+
]);
|
|
300
|
+
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
301
|
+
if (!match) {
|
|
302
|
+
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
303
|
+
}
|
|
304
|
+
const { id } = match.groups;
|
|
305
|
+
const dotIndex = id.lastIndexOf(".");
|
|
306
|
+
const hyphenIndex = id.lastIndexOf("-");
|
|
307
|
+
const baseIdByDot = dotIndex === -1 ? undefined : id.slice(0, dotIndex);
|
|
308
|
+
const baseIdByHyphen = hyphenIndex === -1 ? undefined : id.slice(0, hyphenIndex);
|
|
309
|
+
return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? { name: id, id };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// ../../node_modules/default-browser/index.js
|
|
313
|
+
var execFileAsync4 = promisify6(execFile6);
|
|
314
|
+
var titleize = (string) => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
|
|
315
|
+
async function defaultBrowser2() {
|
|
316
|
+
if (process6.platform === "darwin") {
|
|
317
|
+
const id = await defaultBrowserId();
|
|
318
|
+
const name = await bundleName(id);
|
|
319
|
+
return { name, id };
|
|
320
|
+
}
|
|
321
|
+
if (process6.platform === "linux") {
|
|
322
|
+
const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
|
|
323
|
+
const id = stdout.trim();
|
|
324
|
+
const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
|
|
325
|
+
return { name, id };
|
|
326
|
+
}
|
|
327
|
+
if (process6.platform === "win32") {
|
|
328
|
+
return defaultBrowser();
|
|
329
|
+
}
|
|
330
|
+
throw new Error("Only macOS, Linux, and Windows are supported");
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// ../../node_modules/is-in-ssh/index.js
|
|
334
|
+
import process7 from "node:process";
|
|
335
|
+
var isInSsh = Boolean(process7.env.SSH_CONNECTION || process7.env.SSH_CLIENT || process7.env.SSH_TTY);
|
|
336
|
+
var is_in_ssh_default = isInSsh;
|
|
337
|
+
|
|
338
|
+
// ../../node_modules/open/index.js
|
|
339
|
+
var fallbackAttemptSymbol = Symbol("fallbackAttempt");
|
|
340
|
+
var __dirname2 = import.meta.url ? path.dirname(fileURLToPath(import.meta.url)) : "";
|
|
341
|
+
var localXdgOpenPath = path.join(__dirname2, "xdg-open");
|
|
342
|
+
var { platform, arch } = process8;
|
|
343
|
+
var tryEachApp = async (apps, opener) => {
|
|
344
|
+
if (apps.length === 0) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const errors = [];
|
|
348
|
+
for (const app of apps) {
|
|
349
|
+
try {
|
|
350
|
+
return await opener(app);
|
|
351
|
+
} catch (error) {
|
|
352
|
+
errors.push(error);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
throw new AggregateError(errors, "Failed to open in all supported apps");
|
|
356
|
+
};
|
|
357
|
+
var baseOpen = async (options) => {
|
|
358
|
+
options = {
|
|
359
|
+
wait: false,
|
|
360
|
+
background: false,
|
|
361
|
+
newInstance: false,
|
|
362
|
+
allowNonzeroExitCode: false,
|
|
363
|
+
...options
|
|
364
|
+
};
|
|
365
|
+
const isFallbackAttempt = options[fallbackAttemptSymbol] === true;
|
|
366
|
+
delete options[fallbackAttemptSymbol];
|
|
367
|
+
if (Array.isArray(options.app)) {
|
|
368
|
+
return tryEachApp(options.app, (singleApp) => baseOpen({
|
|
369
|
+
...options,
|
|
370
|
+
app: singleApp,
|
|
371
|
+
[fallbackAttemptSymbol]: true
|
|
372
|
+
}));
|
|
373
|
+
}
|
|
374
|
+
let { name: app, arguments: appArguments = [] } = options.app ?? {};
|
|
375
|
+
appArguments = [...appArguments];
|
|
376
|
+
if (Array.isArray(app)) {
|
|
377
|
+
return tryEachApp(app, (appName) => baseOpen({
|
|
378
|
+
...options,
|
|
379
|
+
app: {
|
|
380
|
+
name: appName,
|
|
381
|
+
arguments: appArguments
|
|
382
|
+
},
|
|
383
|
+
[fallbackAttemptSymbol]: true
|
|
384
|
+
}));
|
|
385
|
+
}
|
|
386
|
+
if (app === "browser" || app === "browserPrivate") {
|
|
387
|
+
const ids = {
|
|
388
|
+
"com.google.chrome": "chrome",
|
|
389
|
+
"google-chrome.desktop": "chrome",
|
|
390
|
+
"com.brave.browser": "brave",
|
|
391
|
+
"org.mozilla.firefox": "firefox",
|
|
392
|
+
"firefox.desktop": "firefox",
|
|
393
|
+
"com.microsoft.msedge": "edge",
|
|
394
|
+
"com.microsoft.edge": "edge",
|
|
395
|
+
"com.microsoft.edgemac": "edge",
|
|
396
|
+
"microsoft-edge.desktop": "edge",
|
|
397
|
+
"com.apple.safari": "safari"
|
|
398
|
+
};
|
|
399
|
+
const flags = {
|
|
400
|
+
chrome: "--incognito",
|
|
401
|
+
brave: "--incognito",
|
|
402
|
+
firefox: "--private-window",
|
|
403
|
+
edge: "--inPrivate"
|
|
404
|
+
};
|
|
405
|
+
let browser;
|
|
406
|
+
if (is_wsl_default) {
|
|
407
|
+
const progId = await wslDefaultBrowser();
|
|
408
|
+
const browserInfo = _windowsBrowserProgIdMap.get(progId);
|
|
409
|
+
browser = browserInfo ?? {};
|
|
410
|
+
} else {
|
|
411
|
+
browser = await defaultBrowser2();
|
|
412
|
+
}
|
|
413
|
+
if (browser.id in ids) {
|
|
414
|
+
const browserName = ids[browser.id.toLowerCase()];
|
|
415
|
+
if (app === "browserPrivate") {
|
|
416
|
+
if (browserName === "safari") {
|
|
417
|
+
throw new Error("Safari doesn't support opening in private mode via command line");
|
|
418
|
+
}
|
|
419
|
+
appArguments.push(flags[browserName]);
|
|
420
|
+
}
|
|
421
|
+
return baseOpen({
|
|
422
|
+
...options,
|
|
423
|
+
app: {
|
|
424
|
+
name: apps[browserName],
|
|
425
|
+
arguments: appArguments
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
throw new Error(`${browser.name} is not supported as a default browser`);
|
|
430
|
+
}
|
|
431
|
+
let command;
|
|
432
|
+
const cliArguments = [];
|
|
433
|
+
const childProcessOptions = {};
|
|
434
|
+
let shouldUseWindowsInWsl = false;
|
|
435
|
+
if (is_wsl_default && !isInsideContainer() && !is_in_ssh_default && !app) {
|
|
436
|
+
shouldUseWindowsInWsl = await canAccessPowerShell();
|
|
437
|
+
}
|
|
438
|
+
if (platform === "darwin") {
|
|
439
|
+
command = "open";
|
|
440
|
+
if (options.wait) {
|
|
441
|
+
cliArguments.push("--wait-apps");
|
|
442
|
+
}
|
|
443
|
+
if (options.background) {
|
|
444
|
+
cliArguments.push("--background");
|
|
445
|
+
}
|
|
446
|
+
if (options.newInstance) {
|
|
447
|
+
cliArguments.push("--new");
|
|
448
|
+
}
|
|
449
|
+
if (app) {
|
|
450
|
+
cliArguments.push("-a", app);
|
|
451
|
+
}
|
|
452
|
+
} else if (platform === "win32" || shouldUseWindowsInWsl) {
|
|
453
|
+
command = await powerShellPath2();
|
|
454
|
+
cliArguments.push(...executePowerShell.argumentsPrefix);
|
|
455
|
+
if (!is_wsl_default) {
|
|
456
|
+
childProcessOptions.windowsVerbatimArguments = true;
|
|
457
|
+
}
|
|
458
|
+
if (is_wsl_default && options.target) {
|
|
459
|
+
options.target = await convertWslPathToWindows(options.target);
|
|
460
|
+
}
|
|
461
|
+
const encodedArguments = ["$ProgressPreference = 'SilentlyContinue';", "Start"];
|
|
462
|
+
if (options.wait) {
|
|
463
|
+
encodedArguments.push("-Wait");
|
|
464
|
+
}
|
|
465
|
+
if (app) {
|
|
466
|
+
encodedArguments.push(executePowerShell.escapeArgument(app));
|
|
467
|
+
if (options.target) {
|
|
468
|
+
appArguments.push(options.target);
|
|
469
|
+
}
|
|
470
|
+
} else if (options.target) {
|
|
471
|
+
encodedArguments.push(executePowerShell.escapeArgument(options.target));
|
|
472
|
+
}
|
|
473
|
+
if (appArguments.length > 0) {
|
|
474
|
+
appArguments = appArguments.map((argument) => executePowerShell.escapeArgument(argument));
|
|
475
|
+
encodedArguments.push("-ArgumentList", appArguments.join(","));
|
|
476
|
+
}
|
|
477
|
+
options.target = executePowerShell.encodeCommand(encodedArguments.join(" "));
|
|
478
|
+
if (!options.wait) {
|
|
479
|
+
childProcessOptions.stdio = "ignore";
|
|
480
|
+
}
|
|
481
|
+
} else {
|
|
482
|
+
if (app) {
|
|
483
|
+
command = app;
|
|
484
|
+
} else {
|
|
485
|
+
const isBundled = !__dirname2 || __dirname2 === "/";
|
|
486
|
+
let exeLocalXdgOpen = false;
|
|
487
|
+
try {
|
|
488
|
+
await fs5.access(localXdgOpenPath, fsConstants2.X_OK);
|
|
489
|
+
exeLocalXdgOpen = true;
|
|
490
|
+
} catch {}
|
|
491
|
+
const useSystemXdgOpen = process8.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
|
|
492
|
+
command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
|
|
493
|
+
}
|
|
494
|
+
if (appArguments.length > 0) {
|
|
495
|
+
cliArguments.push(...appArguments);
|
|
496
|
+
}
|
|
497
|
+
if (!options.wait) {
|
|
498
|
+
childProcessOptions.stdio = "ignore";
|
|
499
|
+
childProcessOptions.detached = true;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (platform === "darwin" && appArguments.length > 0) {
|
|
503
|
+
cliArguments.push("--args", ...appArguments);
|
|
504
|
+
}
|
|
505
|
+
if (options.target) {
|
|
506
|
+
cliArguments.push(options.target);
|
|
507
|
+
}
|
|
508
|
+
const subprocess = childProcess3.spawn(command, cliArguments, childProcessOptions);
|
|
509
|
+
if (options.wait) {
|
|
510
|
+
return new Promise((resolve, reject) => {
|
|
511
|
+
subprocess.once("error", reject);
|
|
512
|
+
subprocess.once("close", (exitCode) => {
|
|
513
|
+
if (!options.allowNonzeroExitCode && exitCode !== 0) {
|
|
514
|
+
reject(new Error(`Exited with code ${exitCode}`));
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
resolve(subprocess);
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
if (isFallbackAttempt) {
|
|
522
|
+
return new Promise((resolve, reject) => {
|
|
523
|
+
subprocess.once("error", reject);
|
|
524
|
+
subprocess.once("spawn", () => {
|
|
525
|
+
subprocess.once("close", (exitCode) => {
|
|
526
|
+
subprocess.off("error", reject);
|
|
527
|
+
if (exitCode !== 0) {
|
|
528
|
+
reject(new Error(`Exited with code ${exitCode}`));
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
subprocess.unref();
|
|
532
|
+
resolve(subprocess);
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
subprocess.unref();
|
|
538
|
+
return new Promise((resolve, reject) => {
|
|
539
|
+
subprocess.once("error", reject);
|
|
540
|
+
subprocess.once("spawn", () => {
|
|
541
|
+
subprocess.off("error", reject);
|
|
542
|
+
resolve(subprocess);
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
};
|
|
546
|
+
var open = (target, options) => {
|
|
547
|
+
if (typeof target !== "string") {
|
|
548
|
+
throw new TypeError("Expected a `target`");
|
|
549
|
+
}
|
|
550
|
+
return baseOpen({
|
|
551
|
+
...options,
|
|
552
|
+
target
|
|
553
|
+
});
|
|
554
|
+
};
|
|
555
|
+
function detectArchBinary(binary) {
|
|
556
|
+
if (typeof binary === "string" || Array.isArray(binary)) {
|
|
557
|
+
return binary;
|
|
558
|
+
}
|
|
559
|
+
const { [arch]: archBinary } = binary;
|
|
560
|
+
if (!archBinary) {
|
|
561
|
+
throw new Error(`${arch} is not supported`);
|
|
562
|
+
}
|
|
563
|
+
return archBinary;
|
|
564
|
+
}
|
|
565
|
+
function detectPlatformBinary({ [platform]: platformBinary }, { wsl } = {}) {
|
|
566
|
+
if (wsl && is_wsl_default) {
|
|
567
|
+
return detectArchBinary(wsl);
|
|
568
|
+
}
|
|
569
|
+
if (!platformBinary) {
|
|
570
|
+
throw new Error(`${platform} is not supported`);
|
|
571
|
+
}
|
|
572
|
+
return detectArchBinary(platformBinary);
|
|
573
|
+
}
|
|
574
|
+
var apps = {
|
|
575
|
+
browser: "browser",
|
|
576
|
+
browserPrivate: "browserPrivate"
|
|
577
|
+
};
|
|
578
|
+
defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
|
|
579
|
+
darwin: "google chrome",
|
|
580
|
+
win32: "chrome",
|
|
581
|
+
linux: ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]
|
|
582
|
+
}, {
|
|
583
|
+
wsl: {
|
|
584
|
+
ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
|
|
585
|
+
x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
|
|
586
|
+
}
|
|
587
|
+
}));
|
|
588
|
+
defineLazyProperty(apps, "brave", () => detectPlatformBinary({
|
|
589
|
+
darwin: "brave browser",
|
|
590
|
+
win32: "brave",
|
|
591
|
+
linux: ["brave-browser", "brave"]
|
|
592
|
+
}, {
|
|
593
|
+
wsl: {
|
|
594
|
+
ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
|
|
595
|
+
x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
|
|
596
|
+
}
|
|
597
|
+
}));
|
|
598
|
+
defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
|
|
599
|
+
darwin: "firefox",
|
|
600
|
+
win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
|
|
601
|
+
linux: "firefox"
|
|
602
|
+
}, {
|
|
603
|
+
wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
|
|
604
|
+
}));
|
|
605
|
+
defineLazyProperty(apps, "edge", () => detectPlatformBinary({
|
|
606
|
+
darwin: "microsoft edge",
|
|
607
|
+
win32: "msedge",
|
|
608
|
+
linux: ["microsoft-edge", "microsoft-edge-dev"]
|
|
609
|
+
}, {
|
|
610
|
+
wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
|
|
611
|
+
}));
|
|
612
|
+
defineLazyProperty(apps, "safari", () => detectPlatformBinary({
|
|
613
|
+
darwin: "Safari"
|
|
614
|
+
}));
|
|
615
|
+
var open_default = open;
|
|
616
|
+
|
|
617
|
+
// src/node.ts
|
|
618
|
+
class NodeFileSystem {
|
|
619
|
+
path = {
|
|
620
|
+
join: path2.join,
|
|
621
|
+
resolve: path2.resolve,
|
|
622
|
+
relative: path2.relative,
|
|
623
|
+
dirname: path2.dirname,
|
|
624
|
+
isAbsolute: path2.isAbsolute,
|
|
625
|
+
basename: path2.basename
|
|
626
|
+
};
|
|
627
|
+
env = {
|
|
628
|
+
cwd: process.cwd,
|
|
629
|
+
homedir: os2.homedir,
|
|
630
|
+
tmpdir: os2.tmpdir,
|
|
631
|
+
getenv: (key) => process.env[key]
|
|
632
|
+
};
|
|
633
|
+
utils = {
|
|
634
|
+
open: async (url) => {
|
|
635
|
+
await open_default(url);
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
async readFile(path3, options) {
|
|
639
|
+
try {
|
|
640
|
+
if (options) {
|
|
641
|
+
return await fs6.readFile(path3, "utf-8");
|
|
642
|
+
}
|
|
643
|
+
return await fs6.readFile(path3);
|
|
644
|
+
} catch (error) {
|
|
645
|
+
if (this.isEnoent(error))
|
|
646
|
+
return null;
|
|
647
|
+
throw error;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
async writeFile(filePath, data) {
|
|
651
|
+
const dir = path2.dirname(filePath);
|
|
652
|
+
if (dir) {
|
|
653
|
+
await fs6.mkdir(dir, { recursive: true });
|
|
654
|
+
}
|
|
655
|
+
await fs6.writeFile(filePath, data);
|
|
656
|
+
}
|
|
657
|
+
async readdir(dirPath) {
|
|
658
|
+
try {
|
|
659
|
+
return await fs6.readdir(dirPath);
|
|
660
|
+
} catch (error) {
|
|
661
|
+
if (this.isEnoent(error))
|
|
662
|
+
return [];
|
|
663
|
+
throw error;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
async stat(filePath) {
|
|
667
|
+
try {
|
|
668
|
+
const stats = await fs6.stat(filePath);
|
|
669
|
+
return {
|
|
670
|
+
isFile: () => stats.isFile(),
|
|
671
|
+
isDirectory: () => stats.isDirectory(),
|
|
672
|
+
size: stats.size,
|
|
673
|
+
mtimeMs: stats.mtimeMs
|
|
674
|
+
};
|
|
675
|
+
} catch (error) {
|
|
676
|
+
if (this.isEnoent(error))
|
|
677
|
+
return null;
|
|
678
|
+
throw error;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
async exists(filePath) {
|
|
682
|
+
return existsSync(filePath);
|
|
683
|
+
}
|
|
684
|
+
async mkdir(dirPath) {
|
|
685
|
+
await fs6.mkdir(dirPath, { recursive: true });
|
|
686
|
+
}
|
|
687
|
+
async rm(filePath) {
|
|
688
|
+
await fs6.rm(filePath, { recursive: true, force: true });
|
|
689
|
+
}
|
|
690
|
+
async rename(oldPath, newPath) {
|
|
691
|
+
await fs6.rename(oldPath, newPath);
|
|
692
|
+
}
|
|
693
|
+
async getTempDir() {
|
|
694
|
+
return await fs6.mkdtemp(path2.join(os2.tmpdir(), "uipath-fs-"));
|
|
695
|
+
}
|
|
696
|
+
async copyDirectory(sourcePath, destPath) {
|
|
697
|
+
const sourceStats = await this.stat(sourcePath);
|
|
698
|
+
if (!sourceStats) {
|
|
699
|
+
throw new Error(`Source directory does not exist: ${sourcePath}`);
|
|
700
|
+
}
|
|
701
|
+
if (!sourceStats.isDirectory()) {
|
|
702
|
+
throw new Error(`Source path is not a directory: ${sourcePath}`);
|
|
703
|
+
}
|
|
704
|
+
await this.mkdir(destPath);
|
|
705
|
+
const entries = await this.readdir(sourcePath);
|
|
706
|
+
for (const entry of entries) {
|
|
707
|
+
const srcEntry = path2.join(sourcePath, entry);
|
|
708
|
+
const destEntry = path2.join(destPath, entry);
|
|
709
|
+
const entryStats = await this.stat(srcEntry);
|
|
710
|
+
if (!entryStats)
|
|
711
|
+
continue;
|
|
712
|
+
if (entryStats.isDirectory()) {
|
|
713
|
+
await this.copyDirectory(srcEntry, destEntry);
|
|
714
|
+
} else if (entryStats.isFile()) {
|
|
715
|
+
const content = await this.readFile(srcEntry);
|
|
716
|
+
if (content !== null) {
|
|
717
|
+
await this.writeFile(destEntry, content);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
isEnoent(error) {
|
|
723
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// src/index.ts
|
|
728
|
+
var fsInstance = new NodeFileSystem;
|
|
729
|
+
var getFileSystem = () => {
|
|
730
|
+
return fsInstance;
|
|
731
|
+
};
|
|
732
|
+
var getFileSystemAsync = async () => {
|
|
733
|
+
return fsInstance;
|
|
734
|
+
};
|
|
735
|
+
export {
|
|
736
|
+
getFileSystemAsync,
|
|
737
|
+
getFileSystem,
|
|
738
|
+
NodeFileSystem
|
|
739
|
+
};
|