virrun 2.31.1 → 2.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +29 -55
  3. package/dist/cli.js +2 -14
  4. package/dist/{createVirrun-Cg9BQxg_.js → createVirrun-B3b8HpM_.js} +512 -143
  5. package/dist/createVirrun-B6jYdgVI.js +23361 -0
  6. package/dist/createVirrun-B7d3DDOh.js +23361 -0
  7. package/dist/createVirrun-BRWPPzzC.js +23370 -0
  8. package/dist/createVirrun-Bx6rca4K.js +23364 -0
  9. package/dist/{createVirrun-C8zMQHAQ.js → createVirrun-CirfmuYa.js} +507 -144
  10. package/dist/createVirrun-D6vtkrkN.js +23357 -0
  11. package/dist/{createVirrun-rH3O-itW.js → createVirrun-F5Gqe026.js} +4497 -166
  12. package/dist/createVirrun-GQ4IRIfZ.js +23361 -0
  13. package/dist/createVirrun-oOCnOtt0.js +23519 -0
  14. package/dist/index.d.ts +3207 -45
  15. package/dist/index.js +22 -2
  16. package/dist/mainCommand-B99KFsCA.js +26295 -0
  17. package/dist/mainCommand-BuOZ5_tl.js +25784 -0
  18. package/dist/mainCommand-BwiSo5oU.js +26276 -0
  19. package/dist/mainCommand-BziUFOd-.js +26786 -0
  20. package/dist/mainCommand-C6beIti-.js +26748 -0
  21. package/dist/mainCommand-CNii8Hw2.js +26790 -0
  22. package/dist/mainCommand-CshwG7mT.js +26277 -0
  23. package/dist/mainCommand-D-8tCgpQ.js +26275 -0
  24. package/dist/mainCommand-D6J0bW3I.js +26290 -0
  25. package/dist/mainCommand-Dka4ZkbD.js +26786 -0
  26. package/dist/mainCommand-KhyFmO-q.js +26508 -0
  27. package/dist/mainCommand-WMKpWxk1.js +26731 -0
  28. package/dist/mainCommand-asfHvyFh.js +26323 -0
  29. package/dist/mainCommand-ePTFrlMi.js +26315 -0
  30. package/dist/mainCommand-nqEH0Sdn.js +26785 -0
  31. package/dist/mainCommand-pfsJR4Jj.js +26787 -0
  32. package/dist/mainCommand-sh3BgZHx.js +26522 -0
  33. package/dist/mainCommand-w8tHehgL.js +26785 -0
  34. package/package.json +13 -7
  35. package/schema.json +24 -0
@@ -1,21 +1,21 @@
1
1
  import { createRequire } from "node:module";
2
- import { constants, tmpdir } from "node:os";
3
2
  import { execFileSync, spawn } from "node:child_process";
4
- import "vue";
5
- import "@vueuse/core";
6
- import { mkdtempSync } from "node:fs";
3
+ import { appendFileSync, chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from "node:fs";
4
+ import { constants, homedir, tmpdir } from "node:os";
7
5
  import { dirname, isAbsolute, join, relative, resolve } from "node:path";
8
- import { create } from "@platformatic/vfs";
6
+ import { createHash } from "node:crypto";
9
7
  import process$1 from "node:process";
10
8
  import { runInThisContext } from "node:vm";
11
9
  import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
12
- //#region src/models/source/SourceType.ts
13
- let SourceType = /* @__PURE__ */ function(SourceType) {
14
- SourceType["Dir"] = "dir";
15
- SourceType["Files"] = "files";
16
- SourceType["Git"] = "git";
17
- return SourceType;
18
- }({});
10
+ //#region \0rolldown/runtime.js
11
+ var __commonJSMin$1 = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
12
+ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
13
+ //#endregion
14
+ //#region src/services/cli/parseCliCommand.ts
15
+ const parseCliCommand = (argv) => {
16
+ const separatorIndex = argv.indexOf("--");
17
+ return separatorIndex === -1 ? [...argv] : argv.slice(separatorIndex + 1);
18
+ };
19
19
  //#endregion
20
20
  //#region src/models/virrun/BackendType.ts
21
21
  let BackendType = /* @__PURE__ */ function(BackendType) {
@@ -26,71 +26,13 @@ let BackendType = /* @__PURE__ */ function(BackendType) {
26
26
  return BackendType;
27
27
  }({});
28
28
  //#endregion
29
- //#region src/services/exec/toExitCode.ts
30
- const toExitCode = (code, signal) => code ?? (signal ? 128 + constants.signals[signal] : 0);
31
- //#endregion
32
- //#region src/services/exec/createNativeBackend.ts
33
- const createNativeBackend = () => ({
34
- exec: (command, options) => new Promise((resolve, reject) => {
35
- const [file, ...args] = Array.isArray(command) ? command : [command];
36
- const child = spawn(file, args, {
37
- cwd: options.cwd === "" ? void 0 : options.cwd,
38
- shell: !Array.isArray(command),
39
- stdio: options.stdio
40
- });
41
- let stdout = "";
42
- let stderr = "";
43
- child.stdout?.on("data", (chunk) => {
44
- stdout += chunk.toString();
45
- });
46
- child.stderr?.on("data", (chunk) => {
47
- stderr += chunk.toString();
48
- });
49
- child.on("error", reject);
50
- child.on("close", (code, signal) => {
51
- resolve({
52
- exitCode: toExitCode(code, signal),
53
- stderr,
54
- stdout
55
- });
56
- });
57
- }),
58
- name: "native"
59
- });
60
- //#endregion
61
- //#region src/services/exec/buildBwrapArgs.ts
62
- const buildBwrapArgs = (command, cwd, { network = false, overlayDirs = [] } = {}) => {
63
- const dir = cwd === "" ? process.cwd() : cwd;
64
- const commandArgs = Array.isArray(command) ? [...command] : [
65
- "/bin/sh",
66
- "-c",
67
- command
68
- ];
69
- const overlays = [dir, ...overlayDirs].flatMap((overlayDir) => [
70
- "--overlay-src",
71
- overlayDir,
72
- "--tmp-overlay",
73
- overlayDir
74
- ]);
75
- return [
76
- "--unshare-all",
77
- ...network ? ["--share-net"] : [],
78
- "--die-with-parent",
79
- "--ro-bind",
80
- "/",
81
- "/",
82
- "--dev",
83
- "/dev",
84
- "--proc",
85
- "/proc",
86
- "--tmpfs",
87
- "/tmp",
88
- ...overlays,
89
- "--chdir",
90
- dir,
91
- "--",
92
- ...commandArgs
93
- ];
29
+ //#region src/services/configuration/matchesRoute.ts
30
+ const matchesRoute = (command, route) => {
31
+ const commandTokens = typeof command === "string" ? command.split(/\s+/u).filter((token) => token !== "") : command;
32
+ return route.some((entry) => {
33
+ const entryTokens = entry.split(/\s+/u).filter((token) => token !== "");
34
+ return entryTokens.length > 0 && entryTokens.every((token, index) => commandTokens[index] === token);
35
+ });
94
36
  };
95
37
  //#endregion
96
38
  //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
@@ -18679,20 +18621,232 @@ const exhaustiveGuard = (value) => {
18679
18621
  throw new InvalidOperationError("Read", exhaustiveGuard.name, JSON.stringify(value));
18680
18622
  };
18681
18623
  //#endregion
18682
- //#region src/services/exec/isOsBackendSupported.ts
18624
+ //#region src/services/exec/bwrap/buildBwrapArgs.ts
18625
+ const buildBwrapArgs = (command, cwd, { bindDirs = [], isNetworkEnabled = false } = {}, { lowerDirs = [], upperDir, workDir } = {}) => {
18626
+ if (upperDir === void 0 !== (workDir === void 0)) throw new InvalidOperationError(Operation.Create, buildBwrapArgs.name, "a persistent overlay needs both upperDir and workDir");
18627
+ const dir = cwd === "" ? process.cwd() : cwd;
18628
+ const commandArgs = Array.isArray(command) ? [...command] : [
18629
+ "/bin/sh",
18630
+ "-c",
18631
+ command
18632
+ ];
18633
+ const topOverlay = upperDir !== void 0 && workDir !== void 0 ? [
18634
+ "--overlay",
18635
+ upperDir,
18636
+ workDir,
18637
+ dir
18638
+ ] : ["--tmp-overlay", dir];
18639
+ return [
18640
+ "--unshare-all",
18641
+ ...isNetworkEnabled ? ["--share-net"] : [],
18642
+ "--die-with-parent",
18643
+ "--ro-bind",
18644
+ "/",
18645
+ "/",
18646
+ "--dev",
18647
+ "/dev",
18648
+ "--proc",
18649
+ "/proc",
18650
+ "--tmpfs",
18651
+ "/tmp",
18652
+ "--overlay-src",
18653
+ dir,
18654
+ ...lowerDirs.flatMap((lowerDir) => ["--overlay-src", lowerDir]),
18655
+ ...topOverlay,
18656
+ ...bindDirs.flatMap((bindDir) => [
18657
+ "--bind",
18658
+ bindDir,
18659
+ bindDir
18660
+ ]),
18661
+ "--chdir",
18662
+ dir,
18663
+ "--",
18664
+ ...commandArgs
18665
+ ];
18666
+ };
18667
+ //#endregion
18668
+ //#region src/services/exec/util/constants.ts
18669
+ const GITIGNORE_FILENAME = ".gitignore";
18670
+ const VIRRUN_CACHE_DIRECTORY_NAME = ".virrun";
18671
+ const VIRRUN_GITIGNORE_ENTRY = `/${VIRRUN_CACHE_DIRECTORY_NAME}/`;
18672
+ const VIRRUN_STORE_DIRECTORY_NAME = "store";
18673
+ const VIRRUN_PNPM_STORE_DIRECTORY_NAME = "pnpm";
18674
+ const VIRRUN_COREPACK_STORE_DIRECTORY_NAME = "corepack";
18675
+ const VIRRUN_SNAPSHOTS_DIRECTORY_NAME = "snapshots";
18676
+ const VIRRUN_SNAPSHOT_UPPER_DIRECTORY_NAME = "upper";
18677
+ const VIRRUN_SNAPSHOT_WORK_DIRECTORY_NAME = "work";
18678
+ const PNPM_LOCKFILE_FILENAME = "pnpm-lock.yaml";
18679
+ const VIRRUN_CONFIGURATION_FILENAME = "virrun.config.json";
18680
+ const COREPACK_HOME_KEY = "COREPACK_HOME";
18681
+ const VIRRUN_CACHE_HOME_KEY = "VIRRUN_CACHE_HOME";
18682
+ const PNPM_CONFIG_PACKAGE_IMPORT_METHOD_KEY = "PNPM_CONFIG_PACKAGE_IMPORT_METHOD";
18683
+ const PNPM_CONFIG_PACKAGE_IMPORT_METHOD_VALUE = "copy";
18684
+ const PNPM_CONFIG_STORE_DIR_KEY = "PNPM_CONFIG_STORE_DIR";
18685
+ const VIRRUN_TEMP_DIR_PREFIX = "virrun-temp-";
18686
+ //#endregion
18687
+ //#region src/services/exec/os/isOsBackendSupported.ts
18683
18688
  let isSupported;
18684
18689
  const isOsBackendSupported = () => {
18685
18690
  if (isSupported !== void 0) return isSupported;
18686
- if (process.platform !== "linux") {
18687
- isSupported = false;
18688
- return isSupported;
18689
- }
18690
- const dir = mkdtempSync(join(tmpdir(), "os-support-"));
18691
- isSupported = getResult(() => execFileSync("bwrap", buildBwrapArgs("true", dir), { stdio: "pipe" })).match(() => true, () => false);
18691
+ else if (process.platform === "linux") {
18692
+ const dir = mkdtempSync(join(tmpdir(), VIRRUN_TEMP_DIR_PREFIX));
18693
+ isSupported = getResult(() => withFinalizer(() => execFileSync("bwrap", buildBwrapArgs("true", dir), { stdio: "pipe" }), () => {
18694
+ rmSync(dir, {
18695
+ force: true,
18696
+ recursive: true
18697
+ });
18698
+ })).match(() => true, () => false);
18699
+ } else if (process.platform === "win32") isSupported = getResult(() => execFileSync("wsl.exe", [
18700
+ "--exec",
18701
+ "mktemp",
18702
+ "-d"
18703
+ ], { stdio: "pipe" })).map((stdout) => stdout.toString().trim()).andThen((wslDir) => getResult(() => withFinalizer(() => execFileSync("wsl.exe", [
18704
+ "--exec",
18705
+ "bwrap",
18706
+ ...buildBwrapArgs("true", wslDir)
18707
+ ], { stdio: "pipe" }), () => {
18708
+ getResult(() => execFileSync("wsl.exe", [
18709
+ "--exec",
18710
+ "rm",
18711
+ "-rf",
18712
+ wslDir
18713
+ ], { stdio: "pipe" })).unwrapOr(void 0);
18714
+ }))).match(() => true, () => false);
18715
+ else isSupported = false;
18692
18716
  return isSupported;
18693
18717
  };
18694
18718
  //#endregion
18695
- //#region src/services/exec/parseBwrapExitCode.ts
18719
+ //#region src/services/configuration/resolveCommandBackend.ts
18720
+ const resolveCommandBackend = (command, configuration) => {
18721
+ if (configuration === void 0 || !matchesRoute(command, configuration.route)) return "native";
18722
+ if (configuration.backend === "os" && !isOsBackendSupported()) return configuration.fallback;
18723
+ return configuration.backend;
18724
+ };
18725
+ //#endregion
18726
+ //#region src/services/configuration/parseVirrunConfiguration.ts
18727
+ const isBackendType = (value) => typeof value === "string" && Object.values(BackendType).includes(value);
18728
+ const isStringArray = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
18729
+ const toBackendType = (value, field) => {
18730
+ if (isBackendType(value)) return value;
18731
+ throw new InvalidOperationError(Operation.Read, parseVirrunConfiguration.name, `\`${field}\` must be one of: ${Object.values(BackendType).join(", ")}`);
18732
+ };
18733
+ const parseVirrunConfiguration = (content) => {
18734
+ const result = getResult(() => JSON.parse(content));
18735
+ if (result.isErr()) throw new InvalidOperationError(Operation.Read, parseVirrunConfiguration.name, `not valid JSON: ${result.error.message}`);
18736
+ const value = result.value;
18737
+ if (typeof value !== "object" || value === null || Array.isArray(value)) throw new InvalidOperationError(Operation.Read, parseVirrunConfiguration.name, "must be a JSON object");
18738
+ const { backend = "auto", fallback = "native", route = [] } = value;
18739
+ if (!isStringArray(route)) throw new InvalidOperationError(Operation.Read, parseVirrunConfiguration.name, "`route` must be an array of strings");
18740
+ return {
18741
+ backend: toBackendType(backend, "backend"),
18742
+ fallback: toBackendType(fallback, "fallback"),
18743
+ route
18744
+ };
18745
+ };
18746
+ //#endregion
18747
+ //#region src/services/exec/util/resolveCwd.ts
18748
+ const resolveCwd = (cwd) => cwd === "" ? process.cwd() : cwd;
18749
+ //#endregion
18750
+ //#region ../../node_modules/.pnpm/empathic@2.0.1/node_modules/empathic/resolve.mjs
18751
+ /**
18752
+ * Resolve an absolute path from {@link root}, but only
18753
+ * if {@link input} isn't already absolute.
18754
+ *
18755
+ * @param input The path to resolve.
18756
+ * @param root The base path; default = process.cwd()
18757
+ * @returns The resolved absolute path.
18758
+ */
18759
+ function absolute(input, root) {
18760
+ return isAbsolute(input) ? input : resolve(root || ".", input);
18761
+ }
18762
+ //#endregion
18763
+ //#region ../../node_modules/.pnpm/empathic@2.0.1/node_modules/empathic/walk.mjs
18764
+ /**
18765
+ * Get all parent directories of {@link base}.
18766
+ * Stops after {@link Options['last']} is processed.
18767
+ *
18768
+ * @returns An array of absolute paths of all parent directories.
18769
+ */
18770
+ function up(base, options) {
18771
+ let { last, cwd } = options || {};
18772
+ let tmp = absolute(base, cwd);
18773
+ let root = absolute(last || "/", cwd);
18774
+ let prev, arr = [];
18775
+ while (prev !== root) {
18776
+ arr.push(tmp);
18777
+ tmp = dirname(prev = tmp);
18778
+ if (tmp === prev) break;
18779
+ }
18780
+ return arr;
18781
+ }
18782
+ //#endregion
18783
+ //#region ../../node_modules/.pnpm/empathic@2.0.1/node_modules/empathic/find.mjs
18784
+ /**
18785
+ * Find a file by name, walking parent directories until found.
18786
+ *
18787
+ * > [NOTE]
18788
+ * > This function only returns a value for file matches.
18789
+ * > A directory match with the same name will be ignored.
18790
+ *
18791
+ * @param name The file name to find.
18792
+ * @returns The absolute path to the file, if found.
18793
+ */
18794
+ function file(name, options) {
18795
+ let dir, tmp;
18796
+ for (dir of up(options && options.cwd || "", options)) try {
18797
+ tmp = join(dir, name);
18798
+ if (statSync(tmp).isFile()) return tmp;
18799
+ } catch {}
18800
+ }
18801
+ //#endregion
18802
+ //#region src/services/configuration/resolveVirrunConfiguration.ts
18803
+ const resolveVirrunConfiguration = (cwd) => {
18804
+ const configurationFile = file(VIRRUN_CONFIGURATION_FILENAME, { cwd: resolveCwd(cwd) });
18805
+ if (configurationFile === void 0) return void 0;
18806
+ return parseVirrunConfiguration(readFileSync(configurationFile, "utf8"));
18807
+ };
18808
+ //#endregion
18809
+ //#region src/models/source/SourceType.ts
18810
+ let SourceType = /* @__PURE__ */ function(SourceType) {
18811
+ SourceType["Dir"] = "dir";
18812
+ SourceType["Files"] = "files";
18813
+ SourceType["Git"] = "git";
18814
+ return SourceType;
18815
+ }({});
18816
+ //#endregion
18817
+ //#region src/services/exec/util/toExitCode.ts
18818
+ const toExitCode = (code, signal) => code ?? (signal ? 128 + constants.signals[signal] : 0);
18819
+ //#endregion
18820
+ //#region src/services/exec/native/createNativeBackend.ts
18821
+ const createNativeBackend = () => ({
18822
+ exec: (command, options) => new Promise((resolve, reject) => {
18823
+ const [file, ...args] = Array.isArray(command) ? command : [command];
18824
+ const child = spawn(file, args, {
18825
+ cwd: options.cwd === "" ? void 0 : options.cwd,
18826
+ shell: !Array.isArray(command),
18827
+ stdio: options.stdio
18828
+ });
18829
+ let stdout = "";
18830
+ let stderr = "";
18831
+ child.stdout?.on("data", (chunk) => {
18832
+ stdout += chunk.toString();
18833
+ });
18834
+ child.stderr?.on("data", (chunk) => {
18835
+ stderr += chunk.toString();
18836
+ });
18837
+ child.on("error", reject);
18838
+ child.on("close", (code, signal) => {
18839
+ resolve({
18840
+ exitCode: toExitCode(code, signal),
18841
+ stderr,
18842
+ stdout
18843
+ });
18844
+ });
18845
+ }),
18846
+ name: "native"
18847
+ });
18848
+ //#endregion
18849
+ //#region src/services/exec/bwrap/parseBwrapExitCode.ts
18696
18850
  const parseBwrapExitCode = (status) => {
18697
18851
  for (const line of status.split("\n")) {
18698
18852
  const result = getResult(() => JSON.parse(line));
@@ -18700,53 +18854,255 @@ const parseBwrapExitCode = (status) => {
18700
18854
  }
18701
18855
  };
18702
18856
  //#endregion
18703
- //#region src/services/exec/createOsBackend.ts
18704
- const createOsBackend = () => {
18705
- if (!isOsBackendSupported()) throw new InvalidOperationError(Operation.Create, createOsBackend.name, "requires Linux + bubblewrap");
18857
+ //#region src/services/exec/bwrap/constants.ts
18858
+ const WSL_BWRAP_STATUS_BEGIN = "\n__VIRRUN_BWRAP_STATUS_BEGIN__\n";
18859
+ const WSL_BWRAP_STATUS_END = "\n__VIRRUN_BWRAP_STATUS_END__\n";
18860
+ //#endregion
18861
+ //#region src/services/exec/bwrap/parseBwrapStderrStatus.ts
18862
+ const parseBwrapStderrStatus = (stderr) => {
18863
+ const beginIndex = stderr.lastIndexOf(WSL_BWRAP_STATUS_BEGIN);
18864
+ const endIndex = stderr.lastIndexOf(WSL_BWRAP_STATUS_END);
18865
+ if (beginIndex === -1 || endIndex === -1 || endIndex < beginIndex) return {
18866
+ status: "",
18867
+ stderr
18868
+ };
18869
+ const statusStartIndex = beginIndex + 31;
18706
18870
  return {
18707
- exec: (command, options) => new Promise((resolve, reject) => {
18708
- const stdio = [
18709
- options.stdio,
18710
- options.stdio,
18711
- options.stdio,
18712
- "pipe"
18713
- ];
18714
- const child = spawn("bwrap", [
18715
- "--json-status-fd",
18716
- "3",
18717
- ...buildBwrapArgs(command, options.cwd, options)
18718
- ], {
18719
- shell: false,
18720
- stdio
18721
- });
18722
- let stdout = "";
18723
- let stderr = "";
18724
- let status = "";
18725
- child.stdout?.on("data", (chunk) => {
18726
- stdout += chunk.toString();
18727
- });
18728
- child.stderr?.on("data", (chunk) => {
18729
- stderr += chunk.toString();
18730
- });
18731
- child.stdio[3]?.on("data", (chunk) => {
18732
- status += chunk.toString();
18733
- });
18734
- child.on("error", reject);
18735
- child.on("close", () => {
18736
- const exitCode = parseBwrapExitCode(status);
18737
- if (exitCode === void 0) reject(new InvalidOperationError(Operation.Create, createOsBackend.name, "bubblewrap failed to set up the sandbox"));
18738
- else resolve({
18739
- exitCode,
18740
- stderr,
18741
- stdout
18742
- });
18871
+ status: stderr.slice(statusStartIndex, endIndex),
18872
+ stderr: `${stderr.slice(0, beginIndex)}${stderr.slice(endIndex + 29)}`
18873
+ };
18874
+ };
18875
+ //#endregion
18876
+ //#region src/services/exec/bwrap/createBwrapBackend.ts
18877
+ const createBwrapBackend = (createBwrapArgs, createBwrapCommand, errorName) => ({
18878
+ exec: (command, options) => new Promise((resolve, reject) => {
18879
+ const bwrapCommand = createBwrapCommand(createBwrapArgs(command, options.cwd, options), options);
18880
+ const [file, ...args] = bwrapCommand.command;
18881
+ const stdio = bwrapCommand.statusSource === "fd" ? [
18882
+ options.stdio,
18883
+ options.stdio,
18884
+ options.stdio,
18885
+ "pipe"
18886
+ ] : [
18887
+ options.stdio,
18888
+ options.stdio,
18889
+ "pipe"
18890
+ ];
18891
+ const child = spawn(file, args, {
18892
+ env: {
18893
+ ...process.env,
18894
+ ...options.env
18895
+ },
18896
+ shell: false,
18897
+ stdio
18898
+ });
18899
+ let stdout = "";
18900
+ let stderr = "";
18901
+ let status = "";
18902
+ child.stdout?.on("data", (chunk) => {
18903
+ stdout += chunk.toString();
18904
+ });
18905
+ child.stderr?.on("data", (chunk) => {
18906
+ stderr += chunk.toString();
18907
+ });
18908
+ child.stdio[3]?.on("data", (chunk) => {
18909
+ status += chunk.toString();
18910
+ });
18911
+ child.on("error", reject);
18912
+ child.on("close", () => {
18913
+ const bwrapStderr = bwrapCommand.statusSource === "stderr" ? parseBwrapStderrStatus(stderr) : {
18914
+ status,
18915
+ stderr
18916
+ };
18917
+ const exitCode = parseBwrapExitCode(bwrapStderr.status);
18918
+ if (exitCode === void 0) reject(new InvalidOperationError(Operation.Create, errorName, "bubblewrap failed to set up the sandbox"));
18919
+ else resolve({
18920
+ exitCode,
18921
+ stderr: bwrapStderr.stderr,
18922
+ stdout
18743
18923
  });
18744
- }),
18745
- name: "os"
18924
+ });
18925
+ }),
18926
+ name: "os"
18927
+ });
18928
+ //#endregion
18929
+ //#region src/services/exec/bwrap/createLinuxOsBackend.ts
18930
+ const createLinuxOsBackend = (errorName) => createBwrapBackend((command, cwd, options) => buildBwrapArgs(command, cwd, options, options.overlayLayers), (bwrapArgs) => ({
18931
+ command: [
18932
+ "bwrap",
18933
+ "--json-status-fd",
18934
+ "3",
18935
+ ...bwrapArgs
18936
+ ],
18937
+ statusSource: "fd"
18938
+ }), errorName);
18939
+ //#endregion
18940
+ //#region src/services/exec/wsl/readWslPath.ts
18941
+ const wslPaths = /* @__PURE__ */ new Map();
18942
+ const readWslPath = (path) => {
18943
+ const wslPath = wslPaths.get(path);
18944
+ if (wslPath) return wslPath;
18945
+ const newWslPath = execFileSync("wsl.exe", [
18946
+ "--exec",
18947
+ "wslpath",
18948
+ "-a",
18949
+ path
18950
+ ], {
18951
+ encoding: "utf8",
18952
+ stdio: "pipe"
18953
+ }).trim();
18954
+ wslPaths.set(path, newWslPath);
18955
+ return newWslPath;
18956
+ };
18957
+ //#endregion
18958
+ //#region src/services/exec/wsl/createWslBwrapArgs.ts
18959
+ const readWslOverlayLayers = ({ lowerDirs, upperDir, workDir }) => ({
18960
+ lowerDirs: lowerDirs?.map((lowerDir) => readWslPath(lowerDir)),
18961
+ upperDir: upperDir === void 0 ? void 0 : readWslPath(upperDir),
18962
+ workDir: workDir === void 0 ? void 0 : readWslPath(workDir)
18963
+ });
18964
+ const createWslBwrapArgs = (command, cwd, { bindDirs = [], isNetworkEnabled = false, overlayLayers } = {}) => {
18965
+ return buildBwrapArgs(command, readWslPath(resolveCwd(cwd)), {
18966
+ bindDirs: bindDirs.map((bindDir) => readWslPath(bindDir)),
18967
+ isNetworkEnabled
18968
+ }, overlayLayers === void 0 ? void 0 : readWslOverlayLayers(overlayLayers));
18969
+ };
18970
+ //#endregion
18971
+ //#region src/services/exec/wsl/createWslEnvArgs.ts
18972
+ const WSL_PATH_ENV_KEYS = /* @__PURE__ */ new Set([COREPACK_HOME_KEY, PNPM_CONFIG_STORE_DIR_KEY]);
18973
+ const createWslEnvArgs = ({ env = {} }) => Object.entries(env).map(([key, value]) => `${key}=${WSL_PATH_ENV_KEYS.has(key) ? readWslPath(value) : value}`);
18974
+ //#endregion
18975
+ //#region src/services/exec/wsl/createWslOsBackend.ts
18976
+ const createWslOsBackend = (errorName) => createBwrapBackend(createWslBwrapArgs, (bwrapArgs, options) => ({
18977
+ command: [
18978
+ "wsl.exe",
18979
+ "--exec",
18980
+ "env",
18981
+ ...createWslEnvArgs(options),
18982
+ "sh",
18983
+ "-c",
18984
+ [
18985
+ `status="$(mktemp)"`,
18986
+ `bwrap --json-status-fd 3 "$@" 3>"$status"`,
18987
+ `bwrapExitCode=$?`,
18988
+ `printf '${WSL_BWRAP_STATUS_BEGIN.replaceAll("\n", String.raw`\n`)}' >&2`,
18989
+ `cat "$status" >&2`,
18990
+ `printf '${WSL_BWRAP_STATUS_END.replaceAll("\n", String.raw`\n`)}' >&2`,
18991
+ `rm -f "$status"`,
18992
+ `exit "$bwrapExitCode"`
18993
+ ].join("; "),
18994
+ "virrun-bwrap",
18995
+ ...bwrapArgs
18996
+ ],
18997
+ statusSource: "stderr"
18998
+ }), errorName);
18999
+ //#endregion
19000
+ //#region src/services/exec/os/createOsBackend.ts
19001
+ const createOsBackend = () => {
19002
+ if (!isOsBackendSupported()) throw new InvalidOperationError(Operation.Create, createOsBackend.name, "requires Linux/WSL + bubblewrap");
19003
+ if (process.platform === "linux") return createLinuxOsBackend(createOsBackend.name);
19004
+ else if (process.platform === "win32") return createWslOsBackend(createOsBackend.name);
19005
+ throw new InvalidOperationError(Operation.Create, createOsBackend.name, "requires Linux/WSL + bubblewrap");
19006
+ };
19007
+ //#endregion
19008
+ //#region src/services/exec/snapshot/removeSnapshotLocation.ts
19009
+ const makeTraversable = (dir) => {
19010
+ chmodSync(dir, 448);
19011
+ for (const entry of readdirSync(dir, { withFileTypes: true })) if (entry.isDirectory()) makeTraversable(join(dir, entry.name));
19012
+ };
19013
+ const removeSnapshotLocation = ({ dir }) => {
19014
+ if (existsSync(dir)) makeTraversable(dir);
19015
+ rmSync(dir, {
19016
+ force: true,
19017
+ recursive: true
19018
+ });
19019
+ };
19020
+ //#endregion
19021
+ //#region src/services/exec/snapshot/computeLockfileHash.ts
19022
+ const computeLockfileHash = (cwd) => {
19023
+ const dir = resolveCwd(cwd);
19024
+ const lockfile = join(dir, PNPM_LOCKFILE_FILENAME);
19025
+ if (!existsSync(lockfile)) throw new InvalidOperationError(Operation.Read, computeLockfileHash.name, `no ${PNPM_LOCKFILE_FILENAME} in ${dir}`);
19026
+ return createHash("sha256").update(readFileSync(lockfile)).digest("hex");
19027
+ };
19028
+ //#endregion
19029
+ //#region src/services/exec/util/getGlobalCacheDirectory.ts
19030
+ const getGlobalCacheDirectory = () => process.env["VIRRUN_CACHE_HOME"] || join(homedir(), ".virrun");
19031
+ //#endregion
19032
+ //#region src/services/exec/snapshot/resolveSnapshotLocation.ts
19033
+ const resolveSnapshotLocation = (cwd) => {
19034
+ const hash = computeLockfileHash(cwd);
19035
+ const snapshotDir = join(getGlobalCacheDirectory(), VIRRUN_SNAPSHOTS_DIRECTORY_NAME, hash);
19036
+ const upperDir = join(snapshotDir, VIRRUN_SNAPSHOT_UPPER_DIRECTORY_NAME);
19037
+ return {
19038
+ dir: snapshotDir,
19039
+ exists: existsSync(upperDir),
19040
+ hash,
19041
+ upperDir,
19042
+ workDir: join(snapshotDir, VIRRUN_SNAPSHOT_WORK_DIRECTORY_NAME)
19043
+ };
19044
+ };
19045
+ //#endregion
19046
+ //#region src/services/exec/snapshot/createSnapshot.ts
19047
+ const createSnapshot = (backend, command, options) => {
19048
+ const location = resolveSnapshotLocation(options.cwd);
19049
+ const { upperDir, workDir } = location;
19050
+ return getResultAsync(async () => {
19051
+ mkdirSync(upperDir, { recursive: true });
19052
+ mkdirSync(workDir, { recursive: true });
19053
+ const { exitCode, stderr } = await backend.exec(command, {
19054
+ ...options,
19055
+ overlayLayers: {
19056
+ upperDir,
19057
+ workDir
19058
+ }
19059
+ });
19060
+ if (exitCode !== 0) throw new InvalidOperationError(Operation.Create, createSnapshot.name, `snapshot setup command exited with ${exitCode}: ${stderr}`);
19061
+ return {
19062
+ ...location,
19063
+ exists: true
19064
+ };
19065
+ }).match((value) => value, (error) => {
19066
+ removeSnapshotLocation(location);
19067
+ throw error;
19068
+ });
19069
+ };
19070
+ //#endregion
19071
+ //#region src/services/exec/snapshot/forkSnapshot.ts
19072
+ const forkSnapshot = (backend, command, options) => {
19073
+ const { exists, upperDir } = resolveSnapshotLocation(options.cwd);
19074
+ if (!exists) throw new InvalidOperationError(Operation.Read, forkSnapshot.name, "no captured snapshot to fork; run createSnapshot first");
19075
+ return backend.exec(command, {
19076
+ ...options,
19077
+ overlayLayers: { lowerDirs: [upperDir] }
19078
+ });
19079
+ };
19080
+ //#endregion
19081
+ //#region src/services/exec/util/getRepoCacheDirectory.ts
19082
+ const getRepoCacheDirectory = (cwd) => join(resolveCwd(cwd), VIRRUN_CACHE_DIRECTORY_NAME);
19083
+ //#endregion
19084
+ //#region src/services/exec/store/createSharedPackageStoreOptions.ts
19085
+ const ensureGitIgnoreEntry = (cwd) => {
19086
+ const gitignore = join(cwd, GITIGNORE_FILENAME);
19087
+ const gitignoreContent = existsSync(gitignore) ? readFileSync(gitignore, "utf8") : "";
19088
+ if (gitignoreContent.split(/\r?\n/u).includes(VIRRUN_GITIGNORE_ENTRY)) return;
19089
+ appendFileSync(gitignore, `${gitignoreContent.endsWith("\n") || gitignoreContent === "" ? "" : "\n"}${VIRRUN_GITIGNORE_ENTRY}\n`);
19090
+ };
19091
+ const createSharedPackageStoreOptions = (cwd) => {
19092
+ const dir = resolveCwd(cwd);
19093
+ const storeDir = join(getRepoCacheDirectory(dir), VIRRUN_STORE_DIRECTORY_NAME, VIRRUN_PNPM_STORE_DIRECTORY_NAME);
19094
+ mkdirSync(storeDir, { recursive: true });
19095
+ ensureGitIgnoreEntry(dir);
19096
+ return {
19097
+ bindDirs: [storeDir],
19098
+ env: {
19099
+ [PNPM_CONFIG_PACKAGE_IMPORT_METHOD_KEY]: PNPM_CONFIG_PACKAGE_IMPORT_METHOD_VALUE,
19100
+ [PNPM_CONFIG_STORE_DIR_KEY]: storeDir
19101
+ }
18746
19102
  };
18747
19103
  };
18748
19104
  //#endregion
18749
- //#region src/services/exec/tokenizeShellCommand.ts
19105
+ //#region src/services/exec/vfs/tokenizeShellCommand.ts
18750
19106
  const SHELL_OPERATORS = /* @__PURE__ */ new Set([
18751
19107
  "$",
18752
19108
  "&",
@@ -18791,7 +19147,7 @@ const tokenizeShellCommand = (input) => {
18791
19147
  return tokens;
18792
19148
  };
18793
19149
  //#endregion
18794
- //#region src/services/exec/parseNodeInvocation.ts
19150
+ //#region src/services/exec/vfs/parseNodeInvocation.ts
18795
19151
  const parseNodeInvocation = (command) => {
18796
19152
  const tokens = typeof command === "string" ? tokenizeShellCommand(command) : [...command];
18797
19153
  if (!tokens) return void 0;
@@ -18817,35 +19173,4003 @@ var ExitSignalError = class extends Error {
18817
19173
  }
18818
19174
  };
18819
19175
  //#endregion
18820
- //#region src/services/vfs/createPlatformaticFsProvider.ts
18821
- const createPlatformaticFsProvider = ({ overlay = false } = {}) => {
18822
- const vfs = create({
18823
- moduleHooks: true,
18824
- overlay
18825
- });
18826
- return {
18827
- dispose: () => {
18828
- if (vfs.mounted) vfs.unmount();
18829
- },
18830
- exists: (path) => vfs.existsSync(path),
18831
- mkdir: (path) => {
18832
- vfs.mkdirSync(path, { recursive: true });
18833
- },
18834
- mount: (prefix) => {
18835
- vfs.mount(prefix);
18836
- },
18837
- name: "platformatic",
18838
- readFile: (path) => vfs.readFileSync(path, "utf8"),
18839
- unmount: () => {
18840
- vfs.unmount();
18841
- },
18842
- writeFile: (path, data) => {
18843
- vfs.writeFileSync(path, data);
19176
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/errors.js
19177
+ var require_errors = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
19178
+ /**
19179
+ * Creates a filesystem error with the proper structure.
19180
+ * Mirrors the UVException format from Node.js internals.
19181
+ * @param {string} code The error code (e.g., 'ENOENT')
19182
+ * @param {string} syscall The system call name
19183
+ * @param {string} [path] The path that caused the error
19184
+ * @param {string} [message] The error message
19185
+ * @returns {Error}
19186
+ */
19187
+ function createFsError(code, syscall, path, message) {
19188
+ const msg = message || `${code}: ${getErrorDescription(code)}, ${syscall}${path ? ` '${path}'` : ""}`;
19189
+ const err = new Error(msg);
19190
+ err.code = code;
19191
+ err.syscall = syscall;
19192
+ if (path !== void 0) err.path = path;
19193
+ Error.captureStackTrace(err, createFsError);
19194
+ return err;
19195
+ }
19196
+ function getErrorDescription(code) {
19197
+ switch (code) {
19198
+ case "ENOENT": return "no such file or directory";
19199
+ case "ENOTDIR": return "not a directory";
19200
+ case "ENOTEMPTY": return "directory not empty";
19201
+ case "EISDIR": return "illegal operation on a directory";
19202
+ case "EBADF": return "bad file descriptor";
19203
+ case "EEXIST": return "file already exists";
19204
+ case "EROFS": return "read-only file system";
19205
+ case "EINVAL": return "invalid argument";
19206
+ case "ELOOP": return "too many levels of symbolic links";
19207
+ default: return "unknown error";
19208
+ }
19209
+ }
19210
+ function createENOENT(syscall, path) {
19211
+ const err = createFsError("ENOENT", syscall, path);
19212
+ Error.captureStackTrace(err, createENOENT);
19213
+ return err;
19214
+ }
19215
+ function createENOTDIR(syscall, path) {
19216
+ const err = createFsError("ENOTDIR", syscall, path);
19217
+ Error.captureStackTrace(err, createENOTDIR);
19218
+ return err;
19219
+ }
19220
+ function createENOTEMPTY(syscall, path) {
19221
+ const err = createFsError("ENOTEMPTY", syscall, path);
19222
+ Error.captureStackTrace(err, createENOTEMPTY);
19223
+ return err;
19224
+ }
19225
+ function createEISDIR(syscall, path) {
19226
+ const err = createFsError("EISDIR", syscall, path);
19227
+ Error.captureStackTrace(err, createEISDIR);
19228
+ return err;
19229
+ }
19230
+ function createEBADF(syscall) {
19231
+ const err = createFsError("EBADF", syscall);
19232
+ Error.captureStackTrace(err, createEBADF);
19233
+ return err;
19234
+ }
19235
+ function createEEXIST(syscall, path) {
19236
+ const err = createFsError("EEXIST", syscall, path);
19237
+ Error.captureStackTrace(err, createEEXIST);
19238
+ return err;
19239
+ }
19240
+ function createEROFS(syscall, path) {
19241
+ const err = createFsError("EROFS", syscall, path);
19242
+ Error.captureStackTrace(err, createEROFS);
19243
+ return err;
19244
+ }
19245
+ function createEINVAL(syscall, path) {
19246
+ const err = createFsError("EINVAL", syscall, path);
19247
+ Error.captureStackTrace(err, createEINVAL);
19248
+ return err;
19249
+ }
19250
+ function createELOOP(syscall, path) {
19251
+ const err = createFsError("ELOOP", syscall, path);
19252
+ Error.captureStackTrace(err, createELOOP);
19253
+ return err;
19254
+ }
19255
+ var ERR_METHOD_NOT_IMPLEMENTED = class extends Error {
19256
+ constructor(method) {
19257
+ super(`The ${method} method is not implemented`);
19258
+ this.code = "ERR_METHOD_NOT_IMPLEMENTED";
19259
+ }
19260
+ };
19261
+ var ERR_INVALID_STATE = class extends Error {
19262
+ constructor(message) {
19263
+ super(`Invalid state: ${message}`);
19264
+ this.code = "ERR_INVALID_STATE";
19265
+ }
19266
+ };
19267
+ var ERR_INVALID_ARG_VALUE = class extends TypeError {
19268
+ constructor(name, value, reason) {
19269
+ super(`The argument '${name}' ${reason}. Received ${typeof value === "string" ? `'${value}'` : String(value)}`);
19270
+ this.code = "ERR_INVALID_ARG_VALUE";
19271
+ }
19272
+ };
19273
+ module.exports = {
19274
+ createENOENT,
19275
+ createENOTDIR,
19276
+ createENOTEMPTY,
19277
+ createEISDIR,
19278
+ createEBADF,
19279
+ createEEXIST,
19280
+ createEROFS,
19281
+ createEINVAL,
19282
+ createELOOP,
19283
+ ERR_METHOD_NOT_IMPLEMENTED,
19284
+ ERR_INVALID_STATE,
19285
+ ERR_INVALID_ARG_VALUE
19286
+ };
19287
+ }));
19288
+ //#endregion
19289
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/provider.js
19290
+ var require_provider = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
19291
+ const { ERR_METHOD_NOT_IMPLEMENTED, createEROFS } = require_errors();
19292
+ var VirtualProvider = class {
19293
+ get readonly() {
19294
+ return false;
19295
+ }
19296
+ get supportsSymlinks() {
19297
+ return false;
19298
+ }
19299
+ get supportsWatch() {
19300
+ return false;
19301
+ }
19302
+ async open(path, flags, mode) {
19303
+ throw new ERR_METHOD_NOT_IMPLEMENTED("open");
19304
+ }
19305
+ openSync(path, flags, mode) {
19306
+ throw new ERR_METHOD_NOT_IMPLEMENTED("openSync");
19307
+ }
19308
+ async stat(path, options) {
19309
+ throw new ERR_METHOD_NOT_IMPLEMENTED("stat");
19310
+ }
19311
+ statSync(path, options) {
19312
+ throw new ERR_METHOD_NOT_IMPLEMENTED("statSync");
19313
+ }
19314
+ async lstat(path, options) {
19315
+ return this.stat(path, options);
19316
+ }
19317
+ lstatSync(path, options) {
19318
+ return this.statSync(path, options);
19319
+ }
19320
+ async readdir(path, options) {
19321
+ throw new ERR_METHOD_NOT_IMPLEMENTED("readdir");
19322
+ }
19323
+ readdirSync(path, options) {
19324
+ throw new ERR_METHOD_NOT_IMPLEMENTED("readdirSync");
19325
+ }
19326
+ async mkdir(path, options) {
19327
+ if (this.readonly) throw createEROFS("mkdir", path);
19328
+ throw new ERR_METHOD_NOT_IMPLEMENTED("mkdir");
19329
+ }
19330
+ mkdirSync(path, options) {
19331
+ if (this.readonly) throw createEROFS("mkdir", path);
19332
+ throw new ERR_METHOD_NOT_IMPLEMENTED("mkdirSync");
19333
+ }
19334
+ async rmdir(path) {
19335
+ if (this.readonly) throw createEROFS("rmdir", path);
19336
+ throw new ERR_METHOD_NOT_IMPLEMENTED("rmdir");
19337
+ }
19338
+ rmdirSync(path) {
19339
+ if (this.readonly) throw createEROFS("rmdir", path);
19340
+ throw new ERR_METHOD_NOT_IMPLEMENTED("rmdirSync");
19341
+ }
19342
+ async unlink(path) {
19343
+ if (this.readonly) throw createEROFS("unlink", path);
19344
+ throw new ERR_METHOD_NOT_IMPLEMENTED("unlink");
19345
+ }
19346
+ unlinkSync(path) {
19347
+ if (this.readonly) throw createEROFS("unlink", path);
19348
+ throw new ERR_METHOD_NOT_IMPLEMENTED("unlinkSync");
19349
+ }
19350
+ async rename(oldPath, newPath) {
19351
+ if (this.readonly) throw createEROFS("rename", oldPath);
19352
+ throw new ERR_METHOD_NOT_IMPLEMENTED("rename");
19353
+ }
19354
+ renameSync(oldPath, newPath) {
19355
+ if (this.readonly) throw createEROFS("rename", oldPath);
19356
+ throw new ERR_METHOD_NOT_IMPLEMENTED("renameSync");
19357
+ }
19358
+ async readFile(path, options) {
19359
+ const handle = await this.open(path, "r");
19360
+ try {
19361
+ return await handle.readFile(options);
19362
+ } finally {
19363
+ await handle.close();
19364
+ }
19365
+ }
19366
+ readFileSync(path, options) {
19367
+ const handle = this.openSync(path, "r");
19368
+ try {
19369
+ return handle.readFileSync(options);
19370
+ } finally {
19371
+ handle.closeSync();
19372
+ }
19373
+ }
19374
+ async writeFile(path, data, options) {
19375
+ if (this.readonly) throw createEROFS("open", path);
19376
+ const handle = await this.open(path, "w", options?.mode);
19377
+ try {
19378
+ await handle.writeFile(data, options);
19379
+ } finally {
19380
+ await handle.close();
19381
+ }
19382
+ }
19383
+ writeFileSync(path, data, options) {
19384
+ if (this.readonly) throw createEROFS("open", path);
19385
+ const handle = this.openSync(path, "w", options?.mode);
19386
+ try {
19387
+ handle.writeFileSync(data, options);
19388
+ } finally {
19389
+ handle.closeSync();
19390
+ }
19391
+ }
19392
+ async appendFile(path, data, options) {
19393
+ if (this.readonly) throw createEROFS("open", path);
19394
+ const handle = await this.open(path, "a", options?.mode);
19395
+ try {
19396
+ await handle.writeFile(data, options);
19397
+ } finally {
19398
+ await handle.close();
19399
+ }
19400
+ }
19401
+ appendFileSync(path, data, options) {
19402
+ if (this.readonly) throw createEROFS("open", path);
19403
+ const handle = this.openSync(path, "a", options?.mode);
19404
+ try {
19405
+ handle.writeFileSync(data, options);
19406
+ } finally {
19407
+ handle.closeSync();
19408
+ }
19409
+ }
19410
+ async exists(path) {
19411
+ try {
19412
+ await this.stat(path);
19413
+ return true;
19414
+ } catch {
19415
+ return false;
19416
+ }
19417
+ }
19418
+ existsSync(path) {
19419
+ try {
19420
+ this.statSync(path);
19421
+ return true;
19422
+ } catch {
19423
+ return false;
19424
+ }
19425
+ }
19426
+ async copyFile(src, dest, mode) {
19427
+ if (this.readonly) throw createEROFS("copyfile", dest);
19428
+ const content = await this.readFile(src);
19429
+ await this.writeFile(dest, content);
19430
+ }
19431
+ copyFileSync(src, dest, mode) {
19432
+ if (this.readonly) throw createEROFS("copyfile", dest);
19433
+ const content = this.readFileSync(src);
19434
+ this.writeFileSync(dest, content);
19435
+ }
19436
+ internalModuleStat(path) {
19437
+ try {
19438
+ if (this.statSync(path).isDirectory()) return 1;
19439
+ return 0;
19440
+ } catch {
19441
+ return -2;
19442
+ }
19443
+ }
19444
+ async realpath(path, options) {
19445
+ await this.stat(path);
19446
+ return path;
19447
+ }
19448
+ realpathSync(path, options) {
19449
+ this.statSync(path);
19450
+ return path;
19451
+ }
19452
+ async access(path, mode) {
19453
+ await this.stat(path);
19454
+ }
19455
+ accessSync(path, mode) {
19456
+ this.statSync(path);
19457
+ }
19458
+ async readlink(path, options) {
19459
+ throw new ERR_METHOD_NOT_IMPLEMENTED("readlink");
19460
+ }
19461
+ readlinkSync(path, options) {
19462
+ throw new ERR_METHOD_NOT_IMPLEMENTED("readlinkSync");
19463
+ }
19464
+ async symlink(target, path, type) {
19465
+ if (this.readonly) throw createEROFS("symlink", path);
19466
+ throw new ERR_METHOD_NOT_IMPLEMENTED("symlink");
19467
+ }
19468
+ symlinkSync(target, path, type) {
19469
+ if (this.readonly) throw createEROFS("symlink", path);
19470
+ throw new ERR_METHOD_NOT_IMPLEMENTED("symlinkSync");
19471
+ }
19472
+ watch(path, options) {
19473
+ throw new ERR_METHOD_NOT_IMPLEMENTED("watch");
19474
+ }
19475
+ watchAsync(path, options) {
19476
+ throw new ERR_METHOD_NOT_IMPLEMENTED("watchAsync");
19477
+ }
19478
+ watchFile(path, options) {
19479
+ throw new ERR_METHOD_NOT_IMPLEMENTED("watchFile");
19480
+ }
19481
+ unwatchFile(path, listener) {
19482
+ throw new ERR_METHOD_NOT_IMPLEMENTED("unwatchFile");
19483
+ }
19484
+ };
19485
+ module.exports = { VirtualProvider };
19486
+ }));
19487
+ //#endregion
19488
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/file_handle.js
19489
+ var require_file_handle = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
19490
+ const { Buffer: Buffer$3 } = __require("node:buffer");
19491
+ const { createEBADF, ERR_METHOD_NOT_IMPLEMENTED, ERR_INVALID_STATE } = require_errors();
19492
+ const kPath = Symbol("kPath");
19493
+ const kFlags = Symbol("kFlags");
19494
+ const kMode = Symbol("kMode");
19495
+ const kPosition = Symbol("kPosition");
19496
+ const kClosed = Symbol("kClosed");
19497
+ var VirtualFileHandle = class {
19498
+ constructor(path, flags, mode) {
19499
+ this[kPath] = path;
19500
+ this[kFlags] = flags;
19501
+ this[kMode] = mode ?? 420;
19502
+ this[kPosition] = 0;
19503
+ this[kClosed] = false;
19504
+ }
19505
+ get path() {
19506
+ return this[kPath];
19507
+ }
19508
+ get flags() {
19509
+ return this[kFlags];
19510
+ }
19511
+ get mode() {
19512
+ return this[kMode];
19513
+ }
19514
+ get position() {
19515
+ return this[kPosition];
19516
+ }
19517
+ set position(pos) {
19518
+ this[kPosition] = pos;
19519
+ }
19520
+ get closed() {
19521
+ return this[kClosed];
19522
+ }
19523
+ #checkClosed() {
19524
+ if (this[kClosed]) throw createEBADF("read");
19525
+ }
19526
+ async read(buffer, offset, length, position) {
19527
+ this.#checkClosed();
19528
+ throw new ERR_METHOD_NOT_IMPLEMENTED("read");
19529
+ }
19530
+ readSync(buffer, offset, length, position) {
19531
+ this.#checkClosed();
19532
+ throw new ERR_METHOD_NOT_IMPLEMENTED("readSync");
19533
+ }
19534
+ async write(buffer, offset, length, position) {
19535
+ this.#checkClosed();
19536
+ throw new ERR_METHOD_NOT_IMPLEMENTED("write");
19537
+ }
19538
+ writeSync(buffer, offset, length, position) {
19539
+ this.#checkClosed();
19540
+ throw new ERR_METHOD_NOT_IMPLEMENTED("writeSync");
19541
+ }
19542
+ async readFile(options) {
19543
+ this.#checkClosed();
19544
+ throw new ERR_METHOD_NOT_IMPLEMENTED("readFile");
19545
+ }
19546
+ readFileSync(options) {
19547
+ this.#checkClosed();
19548
+ throw new ERR_METHOD_NOT_IMPLEMENTED("readFileSync");
19549
+ }
19550
+ async writeFile(data, options) {
19551
+ this.#checkClosed();
19552
+ throw new ERR_METHOD_NOT_IMPLEMENTED("writeFile");
19553
+ }
19554
+ writeFileSync(data, options) {
19555
+ this.#checkClosed();
19556
+ throw new ERR_METHOD_NOT_IMPLEMENTED("writeFileSync");
19557
+ }
19558
+ async stat(options) {
19559
+ this.#checkClosed();
19560
+ throw new ERR_METHOD_NOT_IMPLEMENTED("stat");
19561
+ }
19562
+ statSync(options) {
19563
+ this.#checkClosed();
19564
+ throw new ERR_METHOD_NOT_IMPLEMENTED("statSync");
19565
+ }
19566
+ async truncate(len) {
19567
+ this.#checkClosed();
19568
+ throw new ERR_METHOD_NOT_IMPLEMENTED("truncate");
19569
+ }
19570
+ truncateSync(len) {
19571
+ this.#checkClosed();
19572
+ throw new ERR_METHOD_NOT_IMPLEMENTED("truncateSync");
19573
+ }
19574
+ async close() {
19575
+ this[kClosed] = true;
19576
+ }
19577
+ closeSync() {
19578
+ this[kClosed] = true;
19579
+ }
19580
+ };
19581
+ var MemoryFileHandle = class extends VirtualFileHandle {
19582
+ #content;
19583
+ #entry;
19584
+ #getStats;
19585
+ #checkClosed() {
19586
+ if (this.closed) throw createEBADF("read");
19587
+ }
19588
+ constructor(path, flags, mode, content, entry, getStats) {
19589
+ super(path, flags, mode);
19590
+ this.#content = content;
19591
+ this.#entry = entry;
19592
+ this.#getStats = getStats;
19593
+ if (flags === "w" || flags === "w+") {
19594
+ this.#content = Buffer$3.alloc(0);
19595
+ if (entry) entry.content = this.#content;
19596
+ } else if (flags === "a" || flags === "a+") this.position = this.#content.length;
19597
+ }
19598
+ get content() {
19599
+ if (this.#entry?.isDynamic && this.#entry.isDynamic()) return this.#entry.getContentSync();
19600
+ return this.#content;
19601
+ }
19602
+ async getContentAsync() {
19603
+ if (this.#entry?.getContentAsync) return this.#entry.getContentAsync();
19604
+ return this.#content;
19605
+ }
19606
+ readSync(buffer, offset, length, position) {
19607
+ this.#checkClosed();
19608
+ const content = this.content;
19609
+ const readPos = position !== null && position !== void 0 ? position : this.position;
19610
+ const available = content.length - readPos;
19611
+ if (available <= 0) return 0;
19612
+ const bytesToRead = Math.min(length, available);
19613
+ content.copy(buffer, offset, readPos, readPos + bytesToRead);
19614
+ if (position === null || position === void 0) this.position = readPos + bytesToRead;
19615
+ return bytesToRead;
19616
+ }
19617
+ async read(buffer, offset, length, position) {
19618
+ return {
19619
+ bytesRead: this.readSync(buffer, offset, length, position),
19620
+ buffer
19621
+ };
19622
+ }
19623
+ writeSync(buffer, offset, length, position) {
19624
+ this.#checkClosed();
19625
+ const writePos = position !== null && position !== void 0 ? position : this.position;
19626
+ const data = buffer.subarray(offset, offset + length);
19627
+ if (writePos + length > this.#content.length) {
19628
+ const newContent = Buffer$3.alloc(writePos + length);
19629
+ this.#content.copy(newContent, 0, 0, this.#content.length);
19630
+ this.#content = newContent;
19631
+ }
19632
+ data.copy(this.#content, writePos);
19633
+ if (this.#entry) {
19634
+ this.#entry.content = this.#content;
19635
+ this.#entry.mtime = Date.now();
19636
+ }
19637
+ if (position === null || position === void 0) this.position = writePos + length;
19638
+ return length;
19639
+ }
19640
+ async write(buffer, offset, length, position) {
19641
+ return {
19642
+ bytesWritten: this.writeSync(buffer, offset, length, position),
19643
+ buffer
19644
+ };
19645
+ }
19646
+ readFileSync(options) {
19647
+ this.#checkClosed();
19648
+ const content = this.content;
19649
+ const encoding = typeof options === "string" ? options : options?.encoding;
19650
+ if (encoding) return content.toString(encoding);
19651
+ return Buffer$3.from(content);
19652
+ }
19653
+ async readFile(options) {
19654
+ this.#checkClosed();
19655
+ const content = await this.getContentAsync();
19656
+ const encoding = typeof options === "string" ? options : options?.encoding;
19657
+ if (encoding) return content.toString(encoding);
19658
+ return Buffer$3.from(content);
19659
+ }
19660
+ writeFileSync(data, options) {
19661
+ this.#checkClosed();
19662
+ const buffer = typeof data === "string" ? Buffer$3.from(data, options?.encoding) : data;
19663
+ if (this.flags === "a" || this.flags === "a+") {
19664
+ const newContent = Buffer$3.alloc(this.#content.length + buffer.length);
19665
+ this.#content.copy(newContent, 0);
19666
+ buffer.copy(newContent, this.#content.length);
19667
+ this.#content = newContent;
19668
+ } else this.#content = Buffer$3.from(buffer);
19669
+ if (this.#entry) {
19670
+ this.#entry.content = this.#content;
19671
+ this.#entry.mtime = Date.now();
19672
+ }
19673
+ this.position = this.#content.length;
19674
+ }
19675
+ async writeFile(data, options) {
19676
+ this.writeFileSync(data, options);
19677
+ }
19678
+ statSync(options) {
19679
+ this.#checkClosed();
19680
+ if (this.#getStats) return this.#getStats(this.#content.length);
19681
+ throw new ERR_INVALID_STATE("stats not available");
19682
+ }
19683
+ async stat(options) {
19684
+ return this.statSync(options);
19685
+ }
19686
+ truncateSync(len = 0) {
19687
+ this.#checkClosed();
19688
+ if (len < this.#content.length) this.#content = this.#content.subarray(0, len);
19689
+ else if (len > this.#content.length) {
19690
+ const newContent = Buffer$3.alloc(len);
19691
+ this.#content.copy(newContent, 0, 0, this.#content.length);
19692
+ this.#content = newContent;
19693
+ }
19694
+ if (this.#entry) {
19695
+ this.#entry.content = this.#content;
19696
+ this.#entry.mtime = Date.now();
19697
+ }
19698
+ }
19699
+ async truncate(len) {
19700
+ this.truncateSync(len);
19701
+ }
19702
+ };
19703
+ module.exports = {
19704
+ VirtualFileHandle,
19705
+ MemoryFileHandle
19706
+ };
19707
+ }));
19708
+ //#endregion
19709
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/stats.js
19710
+ var require_stats = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
19711
+ const S_IFMT = 61440;
19712
+ const S_IFREG = 32768;
19713
+ const S_IFDIR = 16384;
19714
+ const S_IFLNK = 40960;
19715
+ const kDefaultBlockSize = 4096;
19716
+ var VirtualStats = class {
19717
+ constructor(props) {
19718
+ this.dev = props.dev ?? 0;
19719
+ this.mode = props.mode;
19720
+ this.nlink = props.nlink ?? 1;
19721
+ this.uid = props.uid ?? process.getuid?.() ?? 0;
19722
+ this.gid = props.gid ?? process.getgid?.() ?? 0;
19723
+ this.rdev = props.rdev ?? 0;
19724
+ this.blksize = props.blksize ?? kDefaultBlockSize;
19725
+ this.ino = props.ino ?? 0;
19726
+ this.size = props.size;
19727
+ this.blocks = props.blocks ?? Math.ceil(props.size / 512);
19728
+ this.atimeMs = props.atimeMs;
19729
+ this.mtimeMs = props.mtimeMs;
19730
+ this.ctimeMs = props.ctimeMs;
19731
+ this.birthtimeMs = props.birthtimeMs;
19732
+ this.atime = new Date(this.atimeMs);
19733
+ this.mtime = new Date(this.mtimeMs);
19734
+ this.ctime = new Date(this.ctimeMs);
19735
+ this.birthtime = new Date(this.birthtimeMs);
19736
+ }
19737
+ isFile() {
19738
+ return (this.mode & S_IFMT) === S_IFREG;
19739
+ }
19740
+ isDirectory() {
19741
+ return (this.mode & S_IFMT) === S_IFDIR;
19742
+ }
19743
+ isSymbolicLink() {
19744
+ return (this.mode & S_IFMT) === S_IFLNK;
19745
+ }
19746
+ isBlockDevice() {
19747
+ return false;
19748
+ }
19749
+ isCharacterDevice() {
19750
+ return false;
19751
+ }
19752
+ isFIFO() {
19753
+ return false;
19754
+ }
19755
+ isSocket() {
19756
+ return false;
19757
+ }
19758
+ };
19759
+ function createFileStats(size, options = {}) {
19760
+ const now = Date.now();
19761
+ return new VirtualStats({
19762
+ mode: (options.mode ?? 420) | S_IFREG,
19763
+ size,
19764
+ atimeMs: options.atimeMs ?? now,
19765
+ mtimeMs: options.mtimeMs ?? now,
19766
+ ctimeMs: options.ctimeMs ?? now,
19767
+ birthtimeMs: options.birthtimeMs ?? now
19768
+ });
19769
+ }
19770
+ function createDirectoryStats(options = {}) {
19771
+ const now = Date.now();
19772
+ return new VirtualStats({
19773
+ mode: (options.mode ?? 493) | S_IFDIR,
19774
+ size: kDefaultBlockSize,
19775
+ blocks: 8,
19776
+ atimeMs: options.atimeMs ?? now,
19777
+ mtimeMs: options.mtimeMs ?? now,
19778
+ ctimeMs: options.ctimeMs ?? now,
19779
+ birthtimeMs: options.birthtimeMs ?? now
19780
+ });
19781
+ }
19782
+ function createSymlinkStats(size, options = {}) {
19783
+ const now = Date.now();
19784
+ return new VirtualStats({
19785
+ mode: (options.mode ?? 511) | S_IFLNK,
19786
+ size,
19787
+ atimeMs: options.atimeMs ?? now,
19788
+ mtimeMs: options.mtimeMs ?? now,
19789
+ ctimeMs: options.ctimeMs ?? now,
19790
+ birthtimeMs: options.birthtimeMs ?? now
19791
+ });
19792
+ }
19793
+ module.exports = {
19794
+ VirtualStats,
19795
+ createFileStats,
19796
+ createDirectoryStats,
19797
+ createSymlinkStats,
19798
+ S_IFMT,
19799
+ S_IFREG,
19800
+ S_IFDIR,
19801
+ S_IFLNK
19802
+ };
19803
+ }));
19804
+ //#endregion
19805
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/watcher.js
19806
+ var require_watcher = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
19807
+ const { EventEmitter } = __require("node:events");
19808
+ const { basename, join: join$1 } = __require("node:path");
19809
+ var VFSWatcher = class extends EventEmitter {
19810
+ #vfs;
19811
+ #path;
19812
+ #interval;
19813
+ #timer = null;
19814
+ #lastStats;
19815
+ #closed = false;
19816
+ #persistent;
19817
+ #recursive;
19818
+ #trackedFiles;
19819
+ #signal;
19820
+ #abortHandler = null;
19821
+ constructor(provider, path, options = {}) {
19822
+ super();
19823
+ this.#vfs = provider;
19824
+ this.#path = path;
19825
+ this.#interval = options.interval ?? 100;
19826
+ this.#persistent = options.persistent !== false;
19827
+ this.#recursive = options.recursive === true;
19828
+ this.#trackedFiles = /* @__PURE__ */ new Map();
19829
+ this.#signal = options.signal;
19830
+ if (this.#signal) {
19831
+ if (this.#signal.aborted) {
19832
+ this.close();
19833
+ return;
19834
+ }
19835
+ this.#abortHandler = () => this.close();
19836
+ this.#signal.addEventListener("abort", this.#abortHandler, { once: true });
19837
+ }
19838
+ this.#lastStats = this.#getStats();
19839
+ if (this.#recursive && this.#lastStats?.isDirectory()) this.#buildFileList(this.#path, "");
19840
+ this.#startPolling();
19841
+ }
19842
+ #getStats() {
19843
+ try {
19844
+ return this.#vfs.statSync(this.#path);
19845
+ } catch {
19846
+ return null;
19847
+ }
19848
+ }
19849
+ #startPolling() {
19850
+ if (this.#closed) return;
19851
+ this.#timer = setInterval(() => this.#poll(), this.#interval);
19852
+ if (!this.#persistent && this.#timer.unref) this.#timer.unref();
19853
+ }
19854
+ #poll() {
19855
+ if (this.#closed) return;
19856
+ if (this.#recursive && this.#trackedFiles.size > 0) {
19857
+ for (const [filePath, info] of this.#trackedFiles) {
19858
+ const newStats = this.#getStatsFor(filePath);
19859
+ if (this.#statsChanged(info.stats, newStats)) {
19860
+ const eventType = this.#determineEventType(info.stats, newStats);
19861
+ this.emit("change", eventType, info.relativePath);
19862
+ info.stats = newStats;
19863
+ }
19864
+ }
19865
+ return;
19866
+ }
19867
+ const newStats = this.#getStats();
19868
+ if (this.#statsChanged(this.#lastStats, newStats)) {
19869
+ const eventType = this.#determineEventType(this.#lastStats, newStats);
19870
+ const filename = basename(this.#path);
19871
+ this.emit("change", eventType, filename);
19872
+ }
19873
+ this.#lastStats = newStats;
19874
+ }
19875
+ #getStatsFor(filePath) {
19876
+ try {
19877
+ return this.#vfs.statSync(filePath);
19878
+ } catch {
19879
+ return null;
19880
+ }
19881
+ }
19882
+ #buildFileList(dirPath, relativePath) {
19883
+ try {
19884
+ const entries = this.#vfs.readdirSync(dirPath, { withFileTypes: true });
19885
+ for (const entry of entries) {
19886
+ const fullPath = join$1(dirPath, entry.name);
19887
+ const relPath = relativePath ? join$1(relativePath, entry.name) : entry.name;
19888
+ if (entry.isDirectory()) this.#buildFileList(fullPath, relPath);
19889
+ else {
19890
+ const stats = this.#getStatsFor(fullPath);
19891
+ this.#trackedFiles.set(fullPath, {
19892
+ stats,
19893
+ relativePath: relPath
19894
+ });
19895
+ }
19896
+ }
19897
+ } catch {}
19898
+ }
19899
+ #statsChanged(oldStats, newStats) {
19900
+ if (oldStats === null !== (newStats === null)) return true;
19901
+ if (oldStats === null && newStats === null) return false;
19902
+ if (oldStats.mtimeMs !== newStats.mtimeMs) return true;
19903
+ if (oldStats.size !== newStats.size) return true;
19904
+ return false;
19905
+ }
19906
+ #determineEventType(oldStats, newStats) {
19907
+ if (oldStats === null !== (newStats === null)) return "rename";
19908
+ return "change";
19909
+ }
19910
+ close() {
19911
+ if (this.#closed) return;
19912
+ this.#closed = true;
19913
+ if (this.#timer) {
19914
+ clearInterval(this.#timer);
19915
+ this.#timer = null;
19916
+ }
19917
+ this.#trackedFiles.clear();
19918
+ if (this.#signal && this.#abortHandler) this.#signal.removeEventListener("abort", this.#abortHandler);
19919
+ this.emit("close");
19920
+ }
19921
+ unref() {
19922
+ this.#timer?.unref?.();
19923
+ return this;
19924
+ }
19925
+ ref() {
19926
+ this.#timer?.ref?.();
19927
+ return this;
19928
+ }
19929
+ };
19930
+ var VFSStatWatcher = class extends EventEmitter {
19931
+ #vfs;
19932
+ #path;
19933
+ #interval;
19934
+ #persistent;
19935
+ #closed = false;
19936
+ #timer = null;
19937
+ #lastStats;
19938
+ #listeners;
19939
+ constructor(provider, path, options = {}) {
19940
+ super();
19941
+ this.#vfs = provider;
19942
+ this.#path = path;
19943
+ this.#interval = options.interval ?? 5007;
19944
+ this.#persistent = options.persistent !== false;
19945
+ this.#listeners = /* @__PURE__ */ new Set();
19946
+ this.#lastStats = this.#getStats();
19947
+ this.#startPolling();
19948
+ }
19949
+ #getStats() {
19950
+ try {
19951
+ return this.#vfs.statSync(this.#path);
19952
+ } catch {
19953
+ const { createFileStats } = require_stats();
19954
+ return createFileStats(0, {
19955
+ mode: 0,
19956
+ mtimeMs: 0,
19957
+ ctimeMs: 0,
19958
+ birthtimeMs: 0
19959
+ });
19960
+ }
19961
+ }
19962
+ #startPolling() {
19963
+ if (this.#closed) return;
19964
+ this.#timer = setInterval(() => this.#poll(), this.#interval);
19965
+ if (!this.#persistent && this.#timer.unref) this.#timer.unref();
19966
+ }
19967
+ #poll() {
19968
+ if (this.#closed) return;
19969
+ const newStats = this.#getStats();
19970
+ if (this.#statsChanged(this.#lastStats, newStats)) {
19971
+ const prevStats = this.#lastStats;
19972
+ this.#lastStats = newStats;
19973
+ this.emit("change", newStats, prevStats);
19974
+ }
19975
+ }
19976
+ #statsChanged(oldStats, newStats) {
19977
+ if (oldStats.mtimeMs !== newStats.mtimeMs) return true;
19978
+ if (oldStats.ctimeMs !== newStats.ctimeMs) return true;
19979
+ if (oldStats.size !== newStats.size) return true;
19980
+ return false;
19981
+ }
19982
+ addListener(listener) {
19983
+ this.#listeners.add(listener);
19984
+ this.on("change", listener);
19985
+ }
19986
+ removeListener(listener) {
19987
+ const had = this.#listeners.has(listener);
19988
+ this.#listeners.delete(listener);
19989
+ super.removeListener("change", listener);
19990
+ return had;
19991
+ }
19992
+ hasNoListeners() {
19993
+ return this.#listeners.size === 0;
19994
+ }
19995
+ stop() {
19996
+ if (this.#closed) return;
19997
+ this.#closed = true;
19998
+ if (this.#timer) {
19999
+ clearInterval(this.#timer);
20000
+ this.#timer = null;
20001
+ }
20002
+ this.emit("stop");
20003
+ }
20004
+ unref() {
20005
+ this.#timer?.unref?.();
20006
+ return this;
20007
+ }
20008
+ ref() {
20009
+ this.#timer?.ref?.();
20010
+ return this;
20011
+ }
20012
+ };
20013
+ var VFSWatchAsyncIterable = class {
20014
+ #watcher;
20015
+ #closed = false;
20016
+ #pendingEvents = [];
20017
+ #pendingResolvers = [];
20018
+ constructor(provider, path, options = {}) {
20019
+ this.#watcher = new VFSWatcher(provider, path, options);
20020
+ this.#watcher.on("change", (eventType, filename) => {
20021
+ const event = {
20022
+ eventType,
20023
+ filename
20024
+ };
20025
+ if (this.#pendingResolvers.length > 0) this.#pendingResolvers.shift()({
20026
+ value: event,
20027
+ done: false
20028
+ });
20029
+ else this.#pendingEvents.push(event);
20030
+ });
20031
+ this.#watcher.on("close", () => {
20032
+ this.#closed = true;
20033
+ while (this.#pendingResolvers.length > 0) this.#pendingResolvers.shift()({
20034
+ value: void 0,
20035
+ done: true
20036
+ });
20037
+ });
20038
+ }
20039
+ [Symbol.asyncIterator]() {
20040
+ return this;
20041
+ }
20042
+ next() {
20043
+ if (this.#closed) return Promise.resolve({
20044
+ value: void 0,
20045
+ done: true
20046
+ });
20047
+ if (this.#pendingEvents.length > 0) {
20048
+ const event = this.#pendingEvents.shift();
20049
+ return Promise.resolve({
20050
+ value: event,
20051
+ done: false
20052
+ });
20053
+ }
20054
+ return new Promise((resolve) => {
20055
+ this.#pendingResolvers.push(resolve);
20056
+ });
20057
+ }
20058
+ return() {
20059
+ this.#watcher.close();
20060
+ return Promise.resolve({
20061
+ value: void 0,
20062
+ done: true
20063
+ });
20064
+ }
20065
+ throw(error) {
20066
+ this.#watcher.close();
20067
+ return Promise.resolve({
20068
+ value: void 0,
20069
+ done: true
20070
+ });
20071
+ }
20072
+ };
20073
+ module.exports = {
20074
+ VFSWatcher,
20075
+ VFSStatWatcher,
20076
+ VFSWatchAsyncIterable
20077
+ };
20078
+ }));
20079
+ //#endregion
20080
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/providers/memory.js
20081
+ var require_memory = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
20082
+ const { Buffer: Buffer$2 } = __require("node:buffer");
20083
+ const { posix: pathPosix$2 } = __require("node:path");
20084
+ const { VirtualProvider } = require_provider();
20085
+ const { MemoryFileHandle } = require_file_handle();
20086
+ const { VFSWatcher, VFSStatWatcher, VFSWatchAsyncIterable } = require_watcher();
20087
+ const { ERR_INVALID_STATE } = require_errors();
20088
+ const { createENOENT, createENOTDIR, createENOTEMPTY, createEISDIR, createEEXIST, createEINVAL, createELOOP, createEROFS } = require_errors();
20089
+ const { createFileStats, createDirectoryStats, createSymlinkStats } = require_stats();
20090
+ const UV_DIRENT_FILE = 1;
20091
+ const UV_DIRENT_DIR = 2;
20092
+ const UV_DIRENT_LINK = 3;
20093
+ var VirtualDirent = class {
20094
+ #name;
20095
+ #type;
20096
+ #parentPath;
20097
+ constructor(name, type, parentPath) {
20098
+ this.#name = name;
20099
+ this.#type = type;
20100
+ this.#parentPath = parentPath;
20101
+ }
20102
+ get name() {
20103
+ return this.#name;
20104
+ }
20105
+ get parentPath() {
20106
+ return this.#parentPath;
20107
+ }
20108
+ get path() {
20109
+ return this.#parentPath;
20110
+ }
20111
+ isFile() {
20112
+ return this.#type === UV_DIRENT_FILE;
20113
+ }
20114
+ isDirectory() {
20115
+ return this.#type === UV_DIRENT_DIR;
20116
+ }
20117
+ isSymbolicLink() {
20118
+ return this.#type === UV_DIRENT_LINK;
20119
+ }
20120
+ isBlockDevice() {
20121
+ return false;
20122
+ }
20123
+ isCharacterDevice() {
20124
+ return false;
20125
+ }
20126
+ isFIFO() {
20127
+ return false;
20128
+ }
20129
+ isSocket() {
20130
+ return false;
20131
+ }
20132
+ };
20133
+ const kRoot = Symbol("kRoot");
20134
+ const kReadonly = Symbol("kReadonly");
20135
+ const kStatWatchers = Symbol("kStatWatchers");
20136
+ const TYPE_FILE = 0;
20137
+ const TYPE_DIR = 1;
20138
+ const TYPE_SYMLINK = 2;
20139
+ const kMaxSymlinkDepth = 40;
20140
+ var MemoryEntry = class {
20141
+ constructor(type, options = {}) {
20142
+ this.type = type;
20143
+ this.mode = options.mode ?? (type === TYPE_DIR ? 493 : 420);
20144
+ this.content = null;
20145
+ this.contentProvider = null;
20146
+ this.target = null;
20147
+ this.children = null;
20148
+ this.populate = null;
20149
+ this.populated = true;
20150
+ const now = Date.now();
20151
+ this.mtime = now;
20152
+ this.ctime = now;
20153
+ this.birthtime = now;
20154
+ }
20155
+ getContentSync() {
20156
+ if (this.contentProvider !== null) {
20157
+ const result = this.contentProvider();
20158
+ if (result && typeof result.then === "function") throw new ERR_INVALID_STATE("cannot use sync API with async content provider");
20159
+ return typeof result === "string" ? Buffer$2.from(result) : result;
20160
+ }
20161
+ return this.content;
20162
+ }
20163
+ async getContentAsync() {
20164
+ if (this.contentProvider !== null) {
20165
+ const result = await this.contentProvider();
20166
+ return typeof result === "string" ? Buffer$2.from(result) : result;
20167
+ }
20168
+ return this.content;
20169
+ }
20170
+ isDynamic() {
20171
+ return this.contentProvider !== null;
20172
+ }
20173
+ isFile() {
20174
+ return this.type === TYPE_FILE;
20175
+ }
20176
+ isDirectory() {
20177
+ return this.type === TYPE_DIR;
20178
+ }
20179
+ isSymbolicLink() {
20180
+ return this.type === TYPE_SYMLINK;
20181
+ }
20182
+ };
20183
+ var MemoryProvider = class extends VirtualProvider {
20184
+ constructor() {
20185
+ super();
20186
+ this[kRoot] = new MemoryEntry(TYPE_DIR);
20187
+ this[kRoot].children = /* @__PURE__ */ new Map();
20188
+ this[kReadonly] = false;
20189
+ this[kStatWatchers] = /* @__PURE__ */ new Map();
20190
+ }
20191
+ get readonly() {
20192
+ return this[kReadonly];
20193
+ }
20194
+ get supportsWatch() {
20195
+ return true;
20196
+ }
20197
+ setReadOnly() {
20198
+ this[kReadonly] = true;
20199
+ }
20200
+ get supportsSymlinks() {
20201
+ return true;
20202
+ }
20203
+ #normalizePath(path) {
20204
+ let normalized = path.replace(/\\/g, "/");
20205
+ if (!normalized.startsWith("/")) normalized = "/" + normalized;
20206
+ return pathPosix$2.normalize(normalized);
20207
+ }
20208
+ #splitPath(path) {
20209
+ if (path === "/") return [];
20210
+ return path.slice(1).split("/");
20211
+ }
20212
+ #getParentPath(path) {
20213
+ if (path === "/") return null;
20214
+ return pathPosix$2.dirname(path);
20215
+ }
20216
+ #getBaseName(path) {
20217
+ return pathPosix$2.basename(path);
20218
+ }
20219
+ #resolveSymlinkTarget(symlinkPath, target) {
20220
+ if (target.startsWith("/")) return this.#normalizePath(target);
20221
+ const parentPath = this.#getParentPath(symlinkPath) || "/";
20222
+ return this.#normalizePath(pathPosix$2.join(parentPath, target));
20223
+ }
20224
+ #lookupEntry(path, followSymlinks = true, depth = 0) {
20225
+ const normalized = this.#normalizePath(path);
20226
+ if (normalized === "/") return {
20227
+ entry: this[kRoot],
20228
+ resolvedPath: "/"
20229
+ };
20230
+ const segments = this.#splitPath(normalized);
20231
+ let current = this[kRoot];
20232
+ let currentPath = "/";
20233
+ for (let i = 0; i < segments.length; i++) {
20234
+ const segment = segments[i];
20235
+ if (current.isSymbolicLink() && followSymlinks) {
20236
+ if (depth >= kMaxSymlinkDepth) return {
20237
+ entry: null,
20238
+ resolvedPath: null,
20239
+ eloop: true
20240
+ };
20241
+ const targetPath = this.#resolveSymlinkTarget(currentPath, current.target);
20242
+ const result = this.#lookupEntry(targetPath, true, depth + 1);
20243
+ if (result.eloop) return result;
20244
+ if (!result.entry) return {
20245
+ entry: null,
20246
+ resolvedPath: null
20247
+ };
20248
+ current = result.entry;
20249
+ currentPath = result.resolvedPath;
20250
+ }
20251
+ if (!current.isDirectory()) return {
20252
+ entry: null,
20253
+ resolvedPath: null
20254
+ };
20255
+ this.#ensurePopulated(current, currentPath);
20256
+ const entry = current.children.get(segment);
20257
+ if (!entry) return {
20258
+ entry: null,
20259
+ resolvedPath: null
20260
+ };
20261
+ currentPath = pathPosix$2.join(currentPath, segment);
20262
+ current = entry;
20263
+ }
20264
+ if (current.isSymbolicLink() && followSymlinks) {
20265
+ if (depth >= kMaxSymlinkDepth) return {
20266
+ entry: null,
20267
+ resolvedPath: null,
20268
+ eloop: true
20269
+ };
20270
+ const targetPath = this.#resolveSymlinkTarget(currentPath, current.target);
20271
+ return this.#lookupEntry(targetPath, true, depth + 1);
20272
+ }
20273
+ return {
20274
+ entry: current,
20275
+ resolvedPath: currentPath
20276
+ };
20277
+ }
20278
+ #getEntry(path, syscall, followSymlinks = true) {
20279
+ const result = this.#lookupEntry(path, followSymlinks);
20280
+ if (result.eloop) throw createELOOP(syscall, path);
20281
+ if (!result.entry) throw createENOENT(syscall, path);
20282
+ return result.entry;
20283
+ }
20284
+ #ensureParent(path, create, syscall) {
20285
+ const parentPath = this.#getParentPath(path);
20286
+ if (parentPath === null) return this[kRoot];
20287
+ const segments = this.#splitPath(parentPath);
20288
+ let current = this[kRoot];
20289
+ for (let i = 0; i < segments.length; i++) {
20290
+ const segment = segments[i];
20291
+ if (current.isSymbolicLink()) {
20292
+ const currentPath = pathPosix$2.join("/", ...segments.slice(0, i));
20293
+ const targetPath = this.#resolveSymlinkTarget(currentPath, current.target);
20294
+ const result = this.#lookupEntry(targetPath, true, 0);
20295
+ if (!result.entry) throw createENOENT(syscall, path);
20296
+ current = result.entry;
20297
+ }
20298
+ if (!current.isDirectory()) throw createENOTDIR(syscall, path);
20299
+ const currentPath = pathPosix$2.join("/", ...segments.slice(0, i));
20300
+ this.#ensurePopulated(current, currentPath);
20301
+ let entry = current.children.get(segment);
20302
+ if (!entry) if (create) {
20303
+ entry = new MemoryEntry(TYPE_DIR);
20304
+ entry.children = /* @__PURE__ */ new Map();
20305
+ current.children.set(segment, entry);
20306
+ } else throw createENOENT(syscall, path);
20307
+ current = entry;
20308
+ }
20309
+ if (!current.isDirectory()) throw createENOTDIR(syscall, path);
20310
+ const finalPath = pathPosix$2.join("/", ...segments);
20311
+ this.#ensurePopulated(current, finalPath);
20312
+ return current;
20313
+ }
20314
+ #createStats(entry, size) {
20315
+ const options = {
20316
+ mode: entry.mode,
20317
+ mtimeMs: entry.mtime,
20318
+ ctimeMs: entry.ctime,
20319
+ birthtimeMs: entry.birthtime
20320
+ };
20321
+ if (entry.isFile()) return createFileStats(size !== void 0 ? size : entry.content.length, options);
20322
+ else if (entry.isDirectory()) return createDirectoryStats(options);
20323
+ else if (entry.isSymbolicLink()) return createSymlinkStats(entry.target.length, options);
20324
+ throw new ERR_INVALID_STATE("Unknown entry type");
20325
+ }
20326
+ #ensurePopulated(entry, path) {
20327
+ if (entry.isDirectory() && !entry.populated && entry.populate) {
20328
+ entry.populate({
20329
+ addFile: (name, content, opts) => {
20330
+ const fileEntry = new MemoryEntry(TYPE_FILE, opts);
20331
+ if (typeof content === "function") {
20332
+ fileEntry.content = Buffer$2.alloc(0);
20333
+ fileEntry.contentProvider = content;
20334
+ } else fileEntry.content = typeof content === "string" ? Buffer$2.from(content) : content;
20335
+ entry.children.set(name, fileEntry);
20336
+ },
20337
+ addDirectory: (name, populate, opts) => {
20338
+ const dirEntry = new MemoryEntry(TYPE_DIR, opts);
20339
+ dirEntry.children = /* @__PURE__ */ new Map();
20340
+ if (typeof populate === "function") {
20341
+ dirEntry.populate = populate;
20342
+ dirEntry.populated = false;
20343
+ }
20344
+ entry.children.set(name, dirEntry);
20345
+ },
20346
+ addSymlink: (name, target, opts) => {
20347
+ const symlinkEntry = new MemoryEntry(TYPE_SYMLINK, opts);
20348
+ symlinkEntry.target = target;
20349
+ entry.children.set(name, symlinkEntry);
20350
+ }
20351
+ });
20352
+ entry.populated = true;
20353
+ }
20354
+ }
20355
+ openSync(path, flags, mode) {
20356
+ const normalized = this.#normalizePath(path);
20357
+ const isCreate = flags === "w" || flags === "w+" || flags === "a" || flags === "a+";
20358
+ if (this.readonly && isCreate) throw createEROFS("open", path);
20359
+ let entry;
20360
+ try {
20361
+ entry = this.#getEntry(normalized, "open");
20362
+ } catch (err) {
20363
+ if (err.code === "ENOENT" && isCreate) {
20364
+ const parent = this.#ensureParent(normalized, true, "open");
20365
+ const name = this.#getBaseName(normalized);
20366
+ entry = new MemoryEntry(TYPE_FILE, { mode });
20367
+ entry.content = Buffer$2.alloc(0);
20368
+ parent.children.set(name, entry);
20369
+ } else throw err;
20370
+ }
20371
+ if (entry.isDirectory()) throw createEISDIR("open", path);
20372
+ if (entry.isSymbolicLink()) throw createEINVAL("open", path);
20373
+ const getStats = (size) => this.#createStats(entry, size);
20374
+ return new MemoryFileHandle(normalized, flags, mode ?? entry.mode, entry.content, entry, getStats);
20375
+ }
20376
+ async open(path, flags, mode) {
20377
+ return this.openSync(path, flags, mode);
20378
+ }
20379
+ statSync(path, options) {
20380
+ const entry = this.#getEntry(path, "stat", true);
20381
+ return this.#createStats(entry);
20382
+ }
20383
+ async stat(path, options) {
20384
+ return this.statSync(path, options);
20385
+ }
20386
+ lstatSync(path, options) {
20387
+ const entry = this.#getEntry(path, "lstat", false);
20388
+ return this.#createStats(entry);
20389
+ }
20390
+ async lstat(path, options) {
20391
+ return this.lstatSync(path, options);
20392
+ }
20393
+ readdirSync(path, options) {
20394
+ const entry = this.#getEntry(path, "scandir", true);
20395
+ if (!entry.isDirectory()) throw createENOTDIR("scandir", path);
20396
+ this.#ensurePopulated(entry, path);
20397
+ const names = [...entry.children.keys()];
20398
+ if (options?.withFileTypes) {
20399
+ const normalized = this.#normalizePath(path);
20400
+ const dirents = [];
20401
+ for (const name of names) {
20402
+ const childEntry = entry.children.get(name);
20403
+ let type;
20404
+ if (childEntry.isSymbolicLink()) type = UV_DIRENT_LINK;
20405
+ else if (childEntry.isDirectory()) type = UV_DIRENT_DIR;
20406
+ else type = UV_DIRENT_FILE;
20407
+ dirents.push(new VirtualDirent(name, type, normalized));
20408
+ }
20409
+ return dirents;
20410
+ }
20411
+ return names;
20412
+ }
20413
+ async readdir(path, options) {
20414
+ return this.readdirSync(path, options);
20415
+ }
20416
+ mkdirSync(path, options) {
20417
+ if (this.readonly) throw createEROFS("mkdir", path);
20418
+ const normalized = this.#normalizePath(path);
20419
+ const recursive = options?.recursive === true;
20420
+ const existing = this.#lookupEntry(normalized, true);
20421
+ if (existing.entry) {
20422
+ if (existing.entry.isDirectory() && recursive) return;
20423
+ throw createEEXIST("mkdir", path);
20424
+ }
20425
+ if (recursive) {
20426
+ const segments = this.#splitPath(normalized);
20427
+ let current = this[kRoot];
20428
+ for (const segment of segments) {
20429
+ let entry = current.children.get(segment);
20430
+ if (!entry) {
20431
+ entry = new MemoryEntry(TYPE_DIR, { mode: options?.mode });
20432
+ entry.children = /* @__PURE__ */ new Map();
20433
+ current.children.set(segment, entry);
20434
+ } else if (!entry.isDirectory()) throw createENOTDIR("mkdir", path);
20435
+ current = entry;
20436
+ }
20437
+ } else {
20438
+ const parent = this.#ensureParent(normalized, false, "mkdir");
20439
+ const name = this.#getBaseName(normalized);
20440
+ const entry = new MemoryEntry(TYPE_DIR, { mode: options?.mode });
20441
+ entry.children = /* @__PURE__ */ new Map();
20442
+ parent.children.set(name, entry);
20443
+ }
20444
+ return recursive ? normalized : void 0;
20445
+ }
20446
+ async mkdir(path, options) {
20447
+ return this.mkdirSync(path, options);
20448
+ }
20449
+ rmdirSync(path) {
20450
+ if (this.readonly) throw createEROFS("rmdir", path);
20451
+ const normalized = this.#normalizePath(path);
20452
+ const entry = this.#getEntry(normalized, "rmdir", true);
20453
+ if (!entry.isDirectory()) throw createENOTDIR("rmdir", path);
20454
+ if (entry.children.size > 0) throw createENOTEMPTY("rmdir", path);
20455
+ const parent = this.#ensureParent(normalized, false, "rmdir");
20456
+ const name = this.#getBaseName(normalized);
20457
+ parent.children.delete(name);
20458
+ }
20459
+ async rmdir(path) {
20460
+ this.rmdirSync(path);
20461
+ }
20462
+ unlinkSync(path) {
20463
+ if (this.readonly) throw createEROFS("unlink", path);
20464
+ const normalized = this.#normalizePath(path);
20465
+ if (this.#getEntry(normalized, "unlink", false).isDirectory()) throw createEISDIR("unlink", path);
20466
+ const parent = this.#ensureParent(normalized, false, "unlink");
20467
+ const name = this.#getBaseName(normalized);
20468
+ parent.children.delete(name);
20469
+ }
20470
+ async unlink(path) {
20471
+ this.unlinkSync(path);
20472
+ }
20473
+ renameSync(oldPath, newPath) {
20474
+ if (this.readonly) throw createEROFS("rename", oldPath);
20475
+ const normalizedOld = this.#normalizePath(oldPath);
20476
+ const normalizedNew = this.#normalizePath(newPath);
20477
+ const entry = this.#getEntry(normalizedOld, "rename", false);
20478
+ const oldParent = this.#ensureParent(normalizedOld, false, "rename");
20479
+ const oldName = this.#getBaseName(normalizedOld);
20480
+ oldParent.children.delete(oldName);
20481
+ const newParent = this.#ensureParent(normalizedNew, true, "rename");
20482
+ const newName = this.#getBaseName(normalizedNew);
20483
+ newParent.children.set(newName, entry);
20484
+ }
20485
+ async rename(oldPath, newPath) {
20486
+ this.renameSync(oldPath, newPath);
20487
+ }
20488
+ readlinkSync(path, options) {
20489
+ const normalized = this.#normalizePath(path);
20490
+ const entry = this.#getEntry(normalized, "readlink", false);
20491
+ if (!entry.isSymbolicLink()) throw createEINVAL("readlink", path);
20492
+ return entry.target;
20493
+ }
20494
+ async readlink(path, options) {
20495
+ return this.readlinkSync(path, options);
20496
+ }
20497
+ symlinkSync(target, path, type) {
20498
+ if (this.readonly) throw createEROFS("symlink", path);
20499
+ const normalized = this.#normalizePath(path);
20500
+ if (this.#lookupEntry(normalized, false).entry) throw createEEXIST("symlink", path);
20501
+ const parent = this.#ensureParent(normalized, true, "symlink");
20502
+ const name = this.#getBaseName(normalized);
20503
+ const entry = new MemoryEntry(TYPE_SYMLINK);
20504
+ entry.target = target;
20505
+ parent.children.set(name, entry);
20506
+ }
20507
+ async symlink(target, path, type) {
20508
+ this.symlinkSync(target, path, type);
20509
+ }
20510
+ realpathSync(path, options) {
20511
+ const result = this.#lookupEntry(path, true, 0);
20512
+ if (result.eloop) throw createELOOP("realpath", path);
20513
+ if (!result.entry) throw createENOENT("realpath", path);
20514
+ return result.resolvedPath;
20515
+ }
20516
+ async realpath(path, options) {
20517
+ return this.realpathSync(path, options);
20518
+ }
20519
+ watch(path, options) {
20520
+ const normalized = this.#normalizePath(path);
20521
+ return new VFSWatcher(this, normalized, options);
20522
+ }
20523
+ watchAsync(path, options) {
20524
+ const normalized = this.#normalizePath(path);
20525
+ return new VFSWatchAsyncIterable(this, normalized, options);
20526
+ }
20527
+ watchFile(path, options, listener) {
20528
+ const normalized = this.#normalizePath(path);
20529
+ let watcher = this[kStatWatchers].get(normalized);
20530
+ if (!watcher) {
20531
+ watcher = new VFSStatWatcher(this, normalized, options);
20532
+ this[kStatWatchers].set(normalized, watcher);
20533
+ }
20534
+ if (listener) watcher.addListener(listener);
20535
+ return watcher;
20536
+ }
20537
+ unwatchFile(path, listener) {
20538
+ const normalized = this.#normalizePath(path);
20539
+ const watcher = this[kStatWatchers].get(normalized);
20540
+ if (!watcher) return;
20541
+ if (listener) watcher.removeListener(listener);
20542
+ else watcher.removeAllListeners("change");
20543
+ if (watcher.hasNoListeners()) {
20544
+ watcher.stop();
20545
+ this[kStatWatchers].delete(normalized);
20546
+ }
20547
+ }
20548
+ };
20549
+ module.exports = { MemoryProvider };
20550
+ }));
20551
+ //#endregion
20552
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/router.js
20553
+ var require_router = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
20554
+ const { isAbsolute: isAbsolute$1, posix: pathPosix$1 } = __require("node:path");
20555
+ function splitPath(normalizedPath) {
20556
+ if (normalizedPath === "/") return [];
20557
+ return normalizedPath.slice(1).split("/");
20558
+ }
20559
+ function getParentPath(normalizedPath) {
20560
+ if (normalizedPath === "/") return null;
20561
+ return pathPosix$1.dirname(normalizedPath);
20562
+ }
20563
+ function getBaseName(normalizedPath) {
20564
+ return pathPosix$1.basename(normalizedPath);
20565
+ }
20566
+ function isPathSeparator(char) {
20567
+ return char === "/" || char === "\\";
20568
+ }
20569
+ function isUnderMountPoint(normalizedPath, mountPoint) {
20570
+ if (normalizedPath === mountPoint) return true;
20571
+ if (!normalizedPath.startsWith(mountPoint)) return false;
20572
+ return isPathSeparator(normalizedPath[mountPoint.length]) || isPathSeparator(mountPoint[mountPoint.length - 1]);
20573
+ }
20574
+ function getRelativePath(normalizedPath, mountPoint) {
20575
+ if (normalizedPath === mountPoint) return "/";
20576
+ if (mountPoint === "/") return normalizedPath;
20577
+ return normalizedPath.slice(mountPoint.length);
20578
+ }
20579
+ module.exports = {
20580
+ splitPath,
20581
+ getParentPath,
20582
+ getBaseName,
20583
+ isUnderMountPoint,
20584
+ getRelativePath,
20585
+ isAbsolutePath: isAbsolute$1
20586
+ };
20587
+ }));
20588
+ //#endregion
20589
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/fd.js
20590
+ var require_fd = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
20591
+ const kFd = Symbol("kFd");
20592
+ const kEntry = Symbol("kEntry");
20593
+ let nextFd = 1e4;
20594
+ const openFDs = /* @__PURE__ */ new Map();
20595
+ var VirtualFD = class {
20596
+ constructor(fd, entry) {
20597
+ this[kFd] = fd;
20598
+ this[kEntry] = entry;
20599
+ }
20600
+ get fd() {
20601
+ return this[kFd];
20602
+ }
20603
+ get entry() {
20604
+ return this[kEntry];
20605
+ }
20606
+ };
20607
+ function openVirtualFd(entry) {
20608
+ const fd = nextFd++;
20609
+ const vfd = new VirtualFD(fd, entry);
20610
+ openFDs.set(fd, vfd);
20611
+ return fd;
20612
+ }
20613
+ function getVirtualFd(fd) {
20614
+ return openFDs.get(fd);
20615
+ }
20616
+ function closeVirtualFd(fd) {
20617
+ return openFDs.delete(fd);
20618
+ }
20619
+ module.exports = {
20620
+ VirtualFD,
20621
+ openVirtualFd,
20622
+ getVirtualFd,
20623
+ closeVirtualFd
20624
+ };
20625
+ }));
20626
+ //#endregion
20627
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/streams.js
20628
+ var require_streams = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
20629
+ const { Readable } = __require("node:stream");
20630
+ const { createEBADF } = require_errors();
20631
+ const { getVirtualFd } = require_fd();
20632
+ var VirtualReadStream = class extends Readable {
20633
+ #vfs;
20634
+ #path;
20635
+ #fd = null;
20636
+ #end;
20637
+ #pos;
20638
+ #content = null;
20639
+ #destroyed = false;
20640
+ #autoClose;
20641
+ constructor(vfs, filePath, options = {}) {
20642
+ const { start = 0, end = Infinity, highWaterMark = 64 * 1024, encoding, ...streamOptions } = options;
20643
+ super({
20644
+ ...streamOptions,
20645
+ highWaterMark,
20646
+ encoding
20647
+ });
20648
+ this.#vfs = vfs;
20649
+ this.#path = filePath;
20650
+ this.#end = end;
20651
+ this.#pos = start;
20652
+ this.#autoClose = options.autoClose !== false;
20653
+ process.nextTick(() => this.#openFile());
20654
+ }
20655
+ get path() {
20656
+ return this.#path;
20657
+ }
20658
+ #openFile() {
20659
+ try {
20660
+ this.#fd = this.#vfs.openSync(this.#path);
20661
+ this.emit("open", this.#fd);
20662
+ this.emit("ready");
20663
+ } catch (err) {
20664
+ this.destroy(err);
20665
+ }
20666
+ }
20667
+ _read(size) {
20668
+ if (this.#destroyed || this.#fd === null) return;
20669
+ if (this.#content === null) try {
20670
+ const vfd = getVirtualFd(this.#fd);
20671
+ if (!vfd) {
20672
+ this.destroy(createEBADF("read"));
20673
+ return;
20674
+ }
20675
+ this.#content = vfd.entry.readFileSync();
20676
+ } catch (err) {
20677
+ this.destroy(err);
20678
+ return;
20679
+ }
20680
+ const endPos = this.#end === Infinity ? this.#content.length : this.#end + 1;
20681
+ const remaining = Math.min(endPos, this.#content.length) - this.#pos;
20682
+ if (remaining <= 0) {
20683
+ this.push(null);
20684
+ return;
20685
+ }
20686
+ const bytesToRead = Math.min(size, remaining);
20687
+ const chunk = this.#content.subarray(this.#pos, this.#pos + bytesToRead);
20688
+ this.#pos += bytesToRead;
20689
+ this.push(chunk);
20690
+ if (this.#pos >= endPos || this.#pos >= this.#content.length) this.push(null);
20691
+ }
20692
+ #close() {
20693
+ if (this.#fd !== null) {
20694
+ try {
20695
+ this.#vfs.closeSync(this.#fd);
20696
+ } catch {}
20697
+ this.#fd = null;
20698
+ }
20699
+ }
20700
+ _destroy(err, callback) {
20701
+ this.#destroyed = true;
20702
+ if (this.#autoClose) this.#close();
20703
+ callback(err);
20704
+ }
20705
+ };
20706
+ module.exports = { VirtualReadStream };
20707
+ }));
20708
+ //#endregion
20709
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/module_hooks.js
20710
+ var require_module_hooks = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
20711
+ const path$2 = __require("node:path");
20712
+ const { dirname, extname, isAbsolute, resolve } = path$2;
20713
+ const pathPosix = path$2.posix;
20714
+ const { pathToFileURL, fileURLToPath } = __require("node:url");
20715
+ const { createENOENT } = require_errors();
20716
+ const kEmptyObject = Object.freeze(Object.create(null));
20717
+ const NodeModule = __require("node:module");
20718
+ const builtinSet = new Set(NodeModule.builtinModules);
20719
+ const ESM_EXTENSIONS = [
20720
+ ".js",
20721
+ ".json",
20722
+ ".node",
20723
+ ".mjs",
20724
+ ".cjs"
20725
+ ];
20726
+ const CJS_EXTENSIONS = [
20727
+ ".js",
20728
+ ".json",
20729
+ ".node"
20730
+ ];
20731
+ const ESM_INDEX_FILES = [
20732
+ "index.js",
20733
+ "index.mjs",
20734
+ "index.cjs",
20735
+ "index.json"
20736
+ ];
20737
+ const CJS_INDEX_FILES = [
20738
+ "index.js",
20739
+ "index.json",
20740
+ "index.node"
20741
+ ];
20742
+ const CJS_CONDITIONS = [
20743
+ "require",
20744
+ "node",
20745
+ "default"
20746
+ ];
20747
+ function isNodeBuiltin(name) {
20748
+ if (typeof NodeModule.isBuiltin === "function") return NodeModule.isBuiltin(name);
20749
+ const bare = name.startsWith("node:") ? name.slice(5) : name;
20750
+ return builtinSet.has(bare);
20751
+ }
20752
+ function normalizeVFSPath(inputPath) {
20753
+ if (process.platform === "win32" && /^V:[/\\]/.test(inputPath)) inputPath = "/" + inputPath.slice(3).replace(/\\/g, "/");
20754
+ if (inputPath.startsWith("/")) return pathPosix.normalize(inputPath);
20755
+ return path$2.normalize(inputPath);
20756
+ }
20757
+ function joinVFSParts(...parts) {
20758
+ if (parts[0]?.startsWith("/")) return pathPosix.resolve(...parts);
20759
+ return resolve(...parts);
20760
+ }
20761
+ function dirnameVFS(p) {
20762
+ if (p.startsWith("/")) return pathPosix.dirname(p);
20763
+ return dirname(p);
20764
+ }
20765
+ function vfsPathToURL(vfsPath) {
20766
+ if (vfsPath.startsWith("/") && process.platform === "win32") return "file:///V:" + encodeURI(vfsPath);
20767
+ return pathToFileURL(vfsPath).href;
20768
+ }
20769
+ function urlToVFSPath(url) {
20770
+ const parsed = new URL(url);
20771
+ const pathname = decodeURIComponent(parsed.pathname);
20772
+ if (process.platform === "win32" && pathname.startsWith("/V:/")) return pathname.slice(3);
20773
+ if (process.platform === "win32" && pathname.startsWith("/") && !/^\/[A-Za-z]:/.test(pathname)) return pathname;
20774
+ return fileURLToPath(url);
20775
+ }
20776
+ const activeVFSList = [];
20777
+ let originalReadFileSync = null;
20778
+ let originalRealpathSync = null;
20779
+ let originalLstatSync = null;
20780
+ let originalStatSync = null;
20781
+ let originalReaddirSync = null;
20782
+ let originalExistsSync = null;
20783
+ let originalWatch = null;
20784
+ let originalWatchFile = null;
20785
+ let originalUnwatchFile = null;
20786
+ let hooksInstalled = false;
20787
+ function registerVFS(vfs) {
20788
+ if (activeVFSList.indexOf(vfs) === -1) {
20789
+ activeVFSList.push(vfs);
20790
+ if (!hooksInstalled) installHooks();
20791
+ }
20792
+ }
20793
+ function deregisterVFS(vfs) {
20794
+ const index = activeVFSList.indexOf(vfs);
20795
+ if (index !== -1) activeVFSList.splice(index, 1);
20796
+ }
20797
+ function findVFSForStat(filename) {
20798
+ const normalized = normalizeVFSPath(filename);
20799
+ for (let i = 0; i < activeVFSList.length; i++) {
20800
+ const vfs = activeVFSList[i];
20801
+ if (vfs.shouldHandle(normalized)) {
20802
+ const result = vfs.internalModuleStat(normalized);
20803
+ if (vfs.mounted || result >= 0) return {
20804
+ vfs,
20805
+ result
20806
+ };
20807
+ }
20808
+ }
20809
+ return null;
20810
+ }
20811
+ function findVFSForRead(filename, options) {
20812
+ const normalized = normalizeVFSPath(filename);
20813
+ for (let i = 0; i < activeVFSList.length; i++) {
20814
+ const vfs = activeVFSList[i];
20815
+ if (vfs.shouldHandle(normalized)) {
20816
+ if (vfs.existsSync(normalized)) {
20817
+ if (vfs.internalModuleStat(normalized) !== 0) return null;
20818
+ try {
20819
+ return {
20820
+ vfs,
20821
+ content: vfs.readFileSync(normalized, options)
20822
+ };
20823
+ } catch (e) {
20824
+ if (vfs.mounted) throw e;
20825
+ }
20826
+ } else if (vfs.mounted) throw createENOENT("open", filename);
20827
+ }
20828
+ }
20829
+ return null;
20830
+ }
20831
+ function findVFSForExists(filename) {
20832
+ const normalized = normalizeVFSPath(filename);
20833
+ for (let i = 0; i < activeVFSList.length; i++) {
20834
+ const vfs = activeVFSList[i];
20835
+ if (vfs.shouldHandle(normalized)) {
20836
+ const exists = vfs.existsSync(normalized);
20837
+ if (vfs.mounted || exists) return {
20838
+ vfs,
20839
+ exists
20840
+ };
20841
+ }
20842
+ }
20843
+ return null;
20844
+ }
20845
+ function findVFSForRealpath(filename) {
20846
+ const normalized = normalizeVFSPath(filename);
20847
+ for (let i = 0; i < activeVFSList.length; i++) {
20848
+ const vfs = activeVFSList[i];
20849
+ if (vfs.shouldHandle(normalized)) {
20850
+ if (vfs.existsSync(normalized)) try {
20851
+ return {
20852
+ vfs,
20853
+ realpath: vfs.realpathSync(normalized)
20854
+ };
20855
+ } catch (e) {
20856
+ if (vfs.mounted) throw e;
20857
+ }
20858
+ else if (vfs.mounted) throw createENOENT("realpath", filename);
20859
+ }
20860
+ }
20861
+ return null;
20862
+ }
20863
+ function findVFSForFsStat(filename) {
20864
+ const normalized = normalizeVFSPath(filename);
20865
+ for (let i = 0; i < activeVFSList.length; i++) {
20866
+ const vfs = activeVFSList[i];
20867
+ if (vfs.shouldHandle(normalized)) {
20868
+ if (vfs.existsSync(normalized)) try {
20869
+ return {
20870
+ vfs,
20871
+ stats: vfs.statSync(normalized)
20872
+ };
20873
+ } catch (e) {
20874
+ if (vfs.mounted) throw e;
20875
+ }
20876
+ else if (vfs.mounted) throw createENOENT("stat", filename);
20877
+ }
20878
+ }
20879
+ return null;
20880
+ }
20881
+ function findVFSForReaddir(dirname, options) {
20882
+ const normalized = normalizeVFSPath(dirname);
20883
+ for (let i = 0; i < activeVFSList.length; i++) {
20884
+ const vfs = activeVFSList[i];
20885
+ if (vfs.shouldHandle(normalized)) {
20886
+ if (vfs.existsSync(normalized)) try {
20887
+ return {
20888
+ vfs,
20889
+ entries: vfs.readdirSync(normalized, options)
20890
+ };
20891
+ } catch (e) {
20892
+ if (vfs.mounted) throw e;
20893
+ }
20894
+ else if (vfs.mounted) throw createENOENT("scandir", dirname);
20895
+ }
20896
+ }
20897
+ return null;
20898
+ }
20899
+ function findVFSForWatch(filename) {
20900
+ const normalized = normalizeVFSPath(filename);
20901
+ for (let i = 0; i < activeVFSList.length; i++) {
20902
+ const vfs = activeVFSList[i];
20903
+ if (vfs.shouldHandle(normalized)) {
20904
+ if (vfs.overlay) {
20905
+ if (vfs.existsSync(normalized)) return { vfs };
20906
+ continue;
20907
+ }
20908
+ return { vfs };
20909
+ }
20910
+ }
20911
+ return null;
20912
+ }
20913
+ const VFS_FORMAT_MAP = {
20914
+ "__proto__": null,
20915
+ ".cjs": "commonjs",
20916
+ ".js": null,
20917
+ ".json": "json",
20918
+ ".mjs": "module",
20919
+ ".node": "addon",
20920
+ ".wasm": "wasm"
20921
+ };
20922
+ function getVFSPackageType(vfs, filePath) {
20923
+ let currentDir = dirnameVFS(filePath);
20924
+ let lastDir;
20925
+ while (currentDir !== lastDir) {
20926
+ if (currentDir.endsWith("/node_modules") || currentDir.endsWith("\\node_modules")) break;
20927
+ const pjsonPath = normalizeVFSPath(joinVFSParts(currentDir, "package.json"));
20928
+ if (vfs.shouldHandle(pjsonPath) && vfs.internalModuleStat(pjsonPath) === 0) try {
20929
+ const content = vfs.readFileSync(pjsonPath, "utf8");
20930
+ const parsed = JSON.parse(content);
20931
+ if (parsed.type === "module" || parsed.type === "commonjs") return parsed.type;
20932
+ return "none";
20933
+ } catch {}
20934
+ lastDir = currentDir;
20935
+ currentDir = dirnameVFS(currentDir);
20936
+ }
20937
+ return "none";
20938
+ }
20939
+ function getVFSFormat(vfs, filePath) {
20940
+ const ext = extname(filePath);
20941
+ if (ext === ".js") return getVFSPackageType(vfs, filePath) === "module" ? "module" : "commonjs";
20942
+ return VFS_FORMAT_MAP[ext] ?? "commonjs";
20943
+ }
20944
+ function matchWildcardPattern(keys, subpath) {
20945
+ for (let i = 0; i < keys.length; i++) {
20946
+ const key = keys[i];
20947
+ const starIdx = key.indexOf("*");
20948
+ if (starIdx === -1) continue;
20949
+ const prefix = key.slice(0, starIdx);
20950
+ const suffix = key.slice(starIdx + 1);
20951
+ if (subpath.startsWith(prefix) && (suffix === "" || subpath.endsWith(suffix)) && subpath.length >= prefix.length + suffix.length) return {
20952
+ key,
20953
+ patternMatch: subpath.slice(prefix.length, suffix.length > 0 ? -suffix.length : void 0)
20954
+ };
20955
+ }
20956
+ return null;
20957
+ }
20958
+ function expandPattern(value, patternMatch) {
20959
+ return patternMatch !== null ? value.replace(/\*/g, patternMatch) : value;
20960
+ }
20961
+ function findVFSForPath(normalizedPath) {
20962
+ for (let i = 0; i < activeVFSList.length; i++) if (activeVFSList[i].shouldHandle(normalizedPath)) return activeVFSList[i];
20963
+ return null;
20964
+ }
20965
+ function makeResolveResult(vfs, filePath) {
20966
+ return {
20967
+ url: vfsPathToURL(filePath),
20968
+ format: getVFSFormat(vfs, filePath),
20969
+ shortCircuit: true
20970
+ };
20971
+ }
20972
+ function tryExtensions(vfs, basePath, extensions) {
20973
+ for (let i = 0; i < extensions.length; i++) {
20974
+ const candidate = basePath + extensions[i];
20975
+ if (vfs.internalModuleStat(candidate) === 0) return candidate;
20976
+ }
20977
+ return null;
20978
+ }
20979
+ function tryIndexFiles(vfs, dirPath, indexFiles) {
20980
+ for (let i = 0; i < indexFiles.length; i++) {
20981
+ const candidate = normalizeVFSPath(joinVFSParts(dirPath, indexFiles[i]));
20982
+ if (vfs.internalModuleStat(candidate) === 0) return candidate;
20983
+ }
20984
+ return null;
20985
+ }
20986
+ function resolveMainField(vfs, dirPath, main, extensions, indexFiles) {
20987
+ const mainPath = normalizeVFSPath(joinVFSParts(dirPath, main));
20988
+ const mainStat = vfs.internalModuleStat(mainPath);
20989
+ if (mainStat === 0) return mainPath;
20990
+ const withExt = tryExtensions(vfs, mainPath, extensions);
20991
+ if (withExt) return withExt;
20992
+ if (mainStat === 1) return tryIndexFiles(vfs, mainPath, indexFiles);
20993
+ return null;
20994
+ }
20995
+ function resolveExportTarget(vfs, pkgDir, target, patternMatch, extensions) {
20996
+ if (typeof target !== "string") return null;
20997
+ const resolved = normalizeVFSPath(joinVFSParts(pkgDir, expandPattern(target, patternMatch)));
20998
+ if (vfs.internalModuleStat(resolved) === 0) return resolved;
20999
+ return extensions ? tryExtensions(vfs, resolved, extensions) : null;
21000
+ }
21001
+ function resolveConditionsToPath(vfs, pkgDir, condMap, conditions, patternMatch, extensions) {
21002
+ const keys = Object.getOwnPropertyNames(condMap);
21003
+ for (let i = 0; i < keys.length; i++) {
21004
+ const key = keys[i];
21005
+ if (key === "default" || conditions.indexOf(key) !== -1) {
21006
+ const value = condMap[key];
21007
+ if (typeof value === "string") {
21008
+ const result = resolveExportTarget(vfs, pkgDir, value, patternMatch, extensions);
21009
+ if (result) return result;
21010
+ continue;
21011
+ }
21012
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
21013
+ const result = resolveConditionsToPath(vfs, pkgDir, value, conditions, patternMatch, extensions);
21014
+ if (result) return result;
21015
+ continue;
21016
+ }
21017
+ }
21018
+ }
21019
+ return null;
21020
+ }
21021
+ function resolveExportsToPath(vfs, pkgDir, packageSubpath, exports$1, conditions, extensions) {
21022
+ if (typeof exports$1 === "string") {
21023
+ if (packageSubpath === ".") return resolveExportTarget(vfs, pkgDir, exports$1, null, extensions);
21024
+ return null;
21025
+ }
21026
+ if (typeof exports$1 !== "object" || exports$1 === null) return null;
21027
+ const keys = Object.getOwnPropertyNames(exports$1);
21028
+ if (keys.length === 0) return null;
21029
+ if (keys[0] !== "" && keys[0][0] !== ".") {
21030
+ if (packageSubpath !== ".") return null;
21031
+ return resolveConditionsToPath(vfs, pkgDir, exports$1, conditions, null, extensions);
21032
+ }
21033
+ let target = exports$1[packageSubpath];
21034
+ let patternMatch = null;
21035
+ if (target === void 0) {
21036
+ const match = matchWildcardPattern(keys, packageSubpath);
21037
+ if (match) {
21038
+ patternMatch = match.patternMatch;
21039
+ target = exports$1[match.key];
21040
+ }
21041
+ }
21042
+ if (target === void 0) return null;
21043
+ if (typeof target === "string") return resolveExportTarget(vfs, pkgDir, target, patternMatch, extensions);
21044
+ if (typeof target === "object" && target !== null && !Array.isArray(target)) return resolveConditionsToPath(vfs, pkgDir, target, conditions, patternMatch, extensions);
21045
+ return null;
21046
+ }
21047
+ function resolveDirectoryEntry(vfs, dirPath, context) {
21048
+ const pjsonPath = normalizeVFSPath(joinVFSParts(dirPath, "package.json"));
21049
+ if (vfs.internalModuleStat(pjsonPath) === 0) try {
21050
+ const content = vfs.readFileSync(pjsonPath, "utf8");
21051
+ const parsed = JSON.parse(content);
21052
+ if (parsed.exports != null) {
21053
+ const resolved = resolveExportsToPath(vfs, dirPath, ".", parsed.exports, context.conditions || [], null);
21054
+ if (resolved) return makeResolveResult(vfs, resolved);
21055
+ }
21056
+ if (parsed.main) {
21057
+ const mainResult = resolveMainField(vfs, dirPath, parsed.main, ESM_EXTENSIONS, ESM_INDEX_FILES);
21058
+ if (mainResult) return makeResolveResult(vfs, mainResult);
21059
+ }
21060
+ } catch {}
21061
+ const indexResult = tryIndexFiles(vfs, dirPath, ESM_INDEX_FILES);
21062
+ return indexResult ? makeResolveResult(vfs, indexResult) : null;
21063
+ }
21064
+ function parsePackageName(specifier) {
21065
+ let separatorIndex = specifier.indexOf("/");
21066
+ if (specifier[0] === "@") {
21067
+ if (separatorIndex === -1) return {
21068
+ packageName: specifier,
21069
+ packageSubpath: "."
21070
+ };
21071
+ separatorIndex = specifier.indexOf("/", separatorIndex + 1);
21072
+ }
21073
+ const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
21074
+ let packageSubpath = separatorIndex === -1 ? "." : "." + specifier.slice(separatorIndex);
21075
+ if (packageSubpath === "./") packageSubpath = ".";
21076
+ return {
21077
+ packageName,
21078
+ packageSubpath
21079
+ };
21080
+ }
21081
+ function urlToPath(urlOrPath) {
21082
+ if (urlOrPath.startsWith("file:")) return fileURLToPath(urlOrPath);
21083
+ return urlOrPath;
21084
+ }
21085
+ function resolveVFSPath(checkPath, context, nextResolve, specifier) {
21086
+ const normalized = normalizeVFSPath(checkPath);
21087
+ for (let i = 0; i < activeVFSList.length; i++) {
21088
+ const vfs = activeVFSList[i];
21089
+ if (!vfs.shouldHandle(normalized)) continue;
21090
+ const stat = vfs.internalModuleStat(normalized);
21091
+ if (stat === 0) return makeResolveResult(vfs, normalized);
21092
+ const withExt = tryExtensions(vfs, normalized, ESM_EXTENSIONS);
21093
+ if (withExt) return makeResolveResult(vfs, withExt);
21094
+ if (stat === 1) {
21095
+ const resolved = resolveDirectoryEntry(vfs, normalized, context);
21096
+ if (resolved) return resolved;
21097
+ }
21098
+ }
21099
+ return nextResolve(specifier, context);
21100
+ }
21101
+ function resolvePackageInVFS(vfs, startDir, packageName, packageSubpath, context) {
21102
+ let currentDir = startDir;
21103
+ let lastDir;
21104
+ const conditions = context.conditions || [];
21105
+ while (currentDir !== lastDir) {
21106
+ const pkgDir = normalizeVFSPath(joinVFSParts(currentDir, "node_modules", packageName));
21107
+ if (vfs.shouldHandle(pkgDir) && vfs.internalModuleStat(pkgDir) === 1) {
21108
+ const pjsonPath = normalizeVFSPath(joinVFSParts(pkgDir, "package.json"));
21109
+ if (vfs.internalModuleStat(pjsonPath) === 0) try {
21110
+ const parsed = JSON.parse(vfs.readFileSync(pjsonPath, "utf8"));
21111
+ if (parsed.exports != null) {
21112
+ const resolved = resolveExportsToPath(vfs, pkgDir, packageSubpath, parsed.exports, conditions, null);
21113
+ if (resolved) return makeResolveResult(vfs, resolved);
21114
+ }
21115
+ if (packageSubpath === ".") {
21116
+ if (parsed.main) {
21117
+ const mainResult = resolveMainField(vfs, pkgDir, parsed.main, ESM_EXTENSIONS, ESM_INDEX_FILES);
21118
+ if (mainResult) return makeResolveResult(vfs, mainResult);
21119
+ }
21120
+ const indexResult = tryIndexFiles(vfs, pkgDir, ESM_INDEX_FILES);
21121
+ if (indexResult) return makeResolveResult(vfs, indexResult);
21122
+ } else {
21123
+ const subResolved = normalizeVFSPath(joinVFSParts(pkgDir, packageSubpath));
21124
+ if (vfs.internalModuleStat(subResolved) === 0) return makeResolveResult(vfs, subResolved);
21125
+ const withExt = tryExtensions(vfs, subResolved, ESM_EXTENSIONS);
21126
+ if (withExt) return makeResolveResult(vfs, withExt);
21127
+ }
21128
+ } catch {}
21129
+ }
21130
+ lastDir = currentDir;
21131
+ currentDir = dirnameVFS(currentDir);
21132
+ }
21133
+ return null;
21134
+ }
21135
+ function resolveCJSPackageInVFS(vfs, startDir, packageName, packageSubpath) {
21136
+ let currentDir = startDir;
21137
+ let lastDir;
21138
+ while (currentDir !== lastDir) {
21139
+ const pkgDir = normalizeVFSPath(joinVFSParts(currentDir, "node_modules", packageName));
21140
+ if (vfs.shouldHandle(pkgDir) && vfs.internalModuleStat(pkgDir) === 1) {
21141
+ const pjsonPath = normalizeVFSPath(joinVFSParts(pkgDir, "package.json"));
21142
+ let parsed = null;
21143
+ if (vfs.internalModuleStat(pjsonPath) === 0) try {
21144
+ parsed = JSON.parse(vfs.readFileSync(pjsonPath, "utf8"));
21145
+ } catch {}
21146
+ if (parsed?.exports != null) {
21147
+ const exportsResult = resolveExportsToPath(vfs, pkgDir, packageSubpath, parsed.exports, CJS_CONDITIONS, CJS_EXTENSIONS);
21148
+ if (exportsResult) return exportsResult;
21149
+ }
21150
+ if (packageSubpath === ".") {
21151
+ if (parsed?.main) {
21152
+ const mainResult = resolveMainField(vfs, pkgDir, parsed.main, CJS_EXTENSIONS, CJS_INDEX_FILES);
21153
+ if (mainResult) return mainResult;
21154
+ }
21155
+ const idxResult = tryIndexFiles(vfs, pkgDir, CJS_INDEX_FILES);
21156
+ if (idxResult) return idxResult;
21157
+ } else {
21158
+ const subResolved = normalizeVFSPath(joinVFSParts(pkgDir, packageSubpath));
21159
+ const subStat = vfs.internalModuleStat(subResolved);
21160
+ if (subStat === 0) return subResolved;
21161
+ const withExt = tryExtensions(vfs, subResolved, CJS_EXTENSIONS);
21162
+ if (withExt) return withExt;
21163
+ if (subStat === 1) {
21164
+ const subPjsonPath = normalizeVFSPath(joinVFSParts(subResolved, "package.json"));
21165
+ if (vfs.internalModuleStat(subPjsonPath) === 0) try {
21166
+ const subParsed = JSON.parse(vfs.readFileSync(subPjsonPath, "utf8"));
21167
+ if (subParsed.main) {
21168
+ const mainResult = resolveMainField(vfs, subResolved, subParsed.main, CJS_EXTENSIONS, CJS_INDEX_FILES);
21169
+ if (mainResult) return mainResult;
21170
+ }
21171
+ } catch {}
21172
+ const subIdx = tryIndexFiles(vfs, subResolved, CJS_INDEX_FILES);
21173
+ if (subIdx) return subIdx;
21174
+ }
21175
+ }
21176
+ }
21177
+ lastDir = currentDir;
21178
+ currentDir = dirnameVFS(currentDir);
21179
+ }
21180
+ return null;
21181
+ }
21182
+ function resolveImportTarget(vfs, baseDir, value, patternMatch, context, nextResolve) {
21183
+ const expanded = expandPattern(value, patternMatch);
21184
+ if (!expanded.startsWith(".") && !expanded.startsWith("/")) return resolveBareSpecifier(expanded, context, nextResolve);
21185
+ const resolved = normalizeVFSPath(joinVFSParts(baseDir, expanded));
21186
+ if (vfs.internalModuleStat(resolved) === 0) return makeResolveResult(vfs, resolved);
21187
+ return null;
21188
+ }
21189
+ function resolveImportConditions(vfs, baseDir, condMap, conditions, patternMatch, context, nextResolve) {
21190
+ const keys = Object.getOwnPropertyNames(condMap);
21191
+ for (let i = 0; i < keys.length; i++) {
21192
+ const key = keys[i];
21193
+ if (key === "default" || conditions.indexOf(key) !== -1) {
21194
+ const value = condMap[key];
21195
+ if (typeof value === "string") {
21196
+ const result = resolveImportTarget(vfs, baseDir, value, patternMatch, context, nextResolve);
21197
+ if (result) return result;
21198
+ continue;
21199
+ }
21200
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
21201
+ const result = resolveImportConditions(vfs, baseDir, value, conditions, patternMatch, context, nextResolve);
21202
+ if (result) return result;
21203
+ continue;
21204
+ }
21205
+ }
21206
+ }
21207
+ return null;
21208
+ }
21209
+ function resolveHashImport(specifier, context, nextResolve) {
21210
+ if (!context.parentURL) return nextResolve(specifier, context);
21211
+ let parentPath;
21212
+ try {
21213
+ parentPath = urlToPath(context.parentURL);
21214
+ } catch {
21215
+ return nextResolve(specifier, context);
21216
+ }
21217
+ const parentNorm = normalizeVFSPath(parentPath);
21218
+ const parentVfs = findVFSForPath(parentNorm);
21219
+ if (!parentVfs) return nextResolve(specifier, context);
21220
+ const conditions = context.conditions || [];
21221
+ let currentDir = dirnameVFS(parentNorm);
21222
+ let lastDir;
21223
+ while (currentDir !== lastDir) {
21224
+ const pjsonPath = normalizeVFSPath(joinVFSParts(currentDir, "package.json"));
21225
+ if (parentVfs.shouldHandle(pjsonPath) && parentVfs.internalModuleStat(pjsonPath) === 0) try {
21226
+ const parsed = JSON.parse(parentVfs.readFileSync(pjsonPath, "utf8"));
21227
+ if (parsed.imports) {
21228
+ let target = parsed.imports[specifier];
21229
+ let patternMatch = null;
21230
+ if (target === void 0) {
21231
+ const match = matchWildcardPattern(Object.getOwnPropertyNames(parsed.imports), specifier);
21232
+ if (match) {
21233
+ patternMatch = match.patternMatch;
21234
+ target = parsed.imports[match.key];
21235
+ }
21236
+ }
21237
+ if (target !== void 0) {
21238
+ if (typeof target === "string") {
21239
+ const result = resolveImportTarget(parentVfs, currentDir, target, patternMatch, context, nextResolve);
21240
+ if (result) return result;
21241
+ }
21242
+ if (typeof target === "object" && target !== null && !Array.isArray(target)) {
21243
+ const result = resolveImportConditions(parentVfs, currentDir, target, conditions, patternMatch, context, nextResolve);
21244
+ if (result) return result;
21245
+ }
21246
+ }
21247
+ break;
21248
+ }
21249
+ } catch {}
21250
+ lastDir = currentDir;
21251
+ currentDir = dirnameVFS(currentDir);
21252
+ }
21253
+ return nextResolve(specifier, context);
21254
+ }
21255
+ function resolveCJSImportTarget(vfs, startDir, baseDir, value, patternMatch) {
21256
+ const expanded = expandPattern(value, patternMatch);
21257
+ if (!expanded.startsWith(".") && !expanded.startsWith("/")) {
21258
+ const { packageName, packageSubpath } = parsePackageName(expanded);
21259
+ return resolveCJSPackageInVFS(vfs, startDir, packageName, packageSubpath);
21260
+ }
21261
+ const resolved = normalizeVFSPath(joinVFSParts(baseDir, expanded));
21262
+ if (vfs.internalModuleStat(resolved) === 0) return resolved;
21263
+ return tryExtensions(vfs, resolved, CJS_EXTENSIONS);
21264
+ }
21265
+ function resolveCJSImportConditions(vfs, startDir, baseDir, condMap, patternMatch) {
21266
+ const keys = Object.getOwnPropertyNames(condMap);
21267
+ for (let i = 0; i < keys.length; i++) {
21268
+ const key = keys[i];
21269
+ if (key === "default" || CJS_CONDITIONS.indexOf(key) !== -1) {
21270
+ const value = condMap[key];
21271
+ if (typeof value === "string") {
21272
+ const result = resolveCJSImportTarget(vfs, startDir, baseDir, value, patternMatch);
21273
+ if (result) return result;
21274
+ continue;
21275
+ }
21276
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
21277
+ const result = resolveCJSImportConditions(vfs, startDir, baseDir, value, patternMatch);
21278
+ if (result) return result;
21279
+ continue;
21280
+ }
21281
+ }
21282
+ }
21283
+ return null;
21284
+ }
21285
+ function resolveCJSHashImport(specifier, parentDir) {
21286
+ const parentNorm = normalizeVFSPath(parentDir);
21287
+ const parentVfs = findVFSForPath(parentNorm);
21288
+ if (!parentVfs) return null;
21289
+ let currentDir = parentNorm;
21290
+ let lastDir;
21291
+ while (currentDir !== lastDir) {
21292
+ const pjsonPath = normalizeVFSPath(joinVFSParts(currentDir, "package.json"));
21293
+ if (parentVfs.shouldHandle(pjsonPath) && parentVfs.internalModuleStat(pjsonPath) === 0) try {
21294
+ const parsed = JSON.parse(parentVfs.readFileSync(pjsonPath, "utf8"));
21295
+ if (parsed.imports) {
21296
+ let target = parsed.imports[specifier];
21297
+ let patternMatch = null;
21298
+ if (target === void 0) {
21299
+ const match = matchWildcardPattern(Object.getOwnPropertyNames(parsed.imports), specifier);
21300
+ if (match) {
21301
+ patternMatch = match.patternMatch;
21302
+ target = parsed.imports[match.key];
21303
+ }
21304
+ }
21305
+ if (target !== void 0) {
21306
+ if (typeof target === "string") return resolveCJSImportTarget(parentVfs, parentNorm, currentDir, target, patternMatch);
21307
+ if (typeof target === "object" && target !== null && !Array.isArray(target)) return resolveCJSImportConditions(parentVfs, parentNorm, currentDir, target, patternMatch);
21308
+ }
21309
+ break;
21310
+ }
21311
+ } catch {}
21312
+ lastDir = currentDir;
21313
+ currentDir = dirnameVFS(currentDir);
21314
+ }
21315
+ return null;
21316
+ }
21317
+ function resolveBareSpecifier(specifier, context, nextResolve) {
21318
+ if (isNodeBuiltin(specifier)) return nextResolve(specifier, context);
21319
+ if (specifier[0] === "#") return resolveHashImport(specifier, context, nextResolve);
21320
+ if (!context.parentURL) return nextResolve(specifier, context);
21321
+ let parentPath;
21322
+ try {
21323
+ parentPath = urlToPath(context.parentURL);
21324
+ } catch {
21325
+ return nextResolve(specifier, context);
21326
+ }
21327
+ const parentNorm = normalizeVFSPath(parentPath);
21328
+ const parentVfs = findVFSForPath(parentNorm);
21329
+ const { packageName, packageSubpath } = parsePackageName(specifier);
21330
+ if (parentVfs) {
21331
+ const result = resolvePackageInVFS(parentVfs, dirnameVFS(parentNorm), packageName, packageSubpath, context);
21332
+ if (result) return result;
21333
+ } else for (let i = 0; i < activeVFSList.length; i++) {
21334
+ const vfs = activeVFSList[i];
21335
+ const mp = vfs.mountPoint;
21336
+ if (!mp) continue;
21337
+ const result = resolvePackageInVFS(vfs, mp, packageName, packageSubpath, context);
21338
+ if (result) return result;
21339
+ }
21340
+ return nextResolve(specifier, context);
21341
+ }
21342
+ function vfsResolveHook(specifier, context, nextResolve) {
21343
+ if (isNodeBuiltin(specifier)) return nextResolve(specifier, context);
21344
+ let checkPath;
21345
+ if (specifier.startsWith("file:")) checkPath = urlToVFSPath(specifier);
21346
+ else if (isAbsolute(specifier)) checkPath = specifier;
21347
+ else if (specifier[0] === ".") if (context.parentURL) checkPath = resolve(dirname(urlToPath(context.parentURL)), specifier);
21348
+ else return nextResolve(specifier, context);
21349
+ else return resolveBareSpecifier(specifier, context, nextResolve);
21350
+ return resolveVFSPath(checkPath, context, nextResolve, specifier);
21351
+ }
21352
+ function vfsLoadHook(url, context, nextLoad) {
21353
+ if (url.startsWith("node:")) return nextLoad(url, context);
21354
+ if (!url.startsWith("file:")) return nextLoad(url, context);
21355
+ const normalized = normalizeVFSPath(urlToVFSPath(url));
21356
+ for (let i = 0; i < activeVFSList.length; i++) {
21357
+ const vfs = activeVFSList[i];
21358
+ if (vfs.shouldHandle(normalized) && vfs.existsSync(normalized)) {
21359
+ if (vfs.internalModuleStat(normalized) !== 0) return nextLoad(url, context);
21360
+ try {
21361
+ const content = vfs.readFileSync(normalized, "utf8");
21362
+ return {
21363
+ format: context.format || getVFSFormat(vfs, normalized),
21364
+ source: content,
21365
+ shortCircuit: true
21366
+ };
21367
+ } catch (e) {
21368
+ if (vfs.mounted) throw e;
21369
+ }
21370
+ }
21371
+ }
21372
+ return nextLoad(url, context);
21373
+ }
21374
+ function installModuleHooks() {
21375
+ if (typeof NodeModule.registerHooks === "function") NodeModule.registerHooks({
21376
+ resolve: vfsResolveHook,
21377
+ load: vfsLoadHook
21378
+ });
21379
+ const origResolveFilename = NodeModule._resolveFilename;
21380
+ NodeModule._resolveFilename = function(request, parent, isMain, options) {
21381
+ if (request.startsWith("node:")) return origResolveFilename.call(this, request, parent, isMain, options);
21382
+ let checkPath;
21383
+ if (isAbsolute(request)) checkPath = request;
21384
+ else if (request[0] === ".") {
21385
+ if (parent?.filename) checkPath = resolve(dirname(parent.filename), request);
21386
+ }
21387
+ if (checkPath) {
21388
+ const normalized = normalizeVFSPath(checkPath);
21389
+ for (let i = 0; i < activeVFSList.length; i++) {
21390
+ const vfs = activeVFSList[i];
21391
+ if (!vfs.shouldHandle(normalized)) continue;
21392
+ const stat = vfs.internalModuleStat(normalized);
21393
+ if (stat === 0) return normalized;
21394
+ const withExt = tryExtensions(vfs, normalized, CJS_EXTENSIONS);
21395
+ if (withExt) return withExt;
21396
+ if (stat === 1) {
21397
+ const pjsonPath = normalizeVFSPath(resolve(normalized, "package.json"));
21398
+ if (vfs.internalModuleStat(pjsonPath) === 0) try {
21399
+ const parsed = JSON.parse(vfs.readFileSync(pjsonPath, "utf8"));
21400
+ if (parsed.main) {
21401
+ const mainResult = resolveMainField(vfs, normalized, parsed.main, CJS_EXTENSIONS, CJS_INDEX_FILES);
21402
+ if (mainResult) return mainResult;
21403
+ }
21404
+ } catch {}
21405
+ const idxResult = tryIndexFiles(vfs, normalized, CJS_INDEX_FILES);
21406
+ if (idxResult) return idxResult;
21407
+ }
21408
+ }
21409
+ }
21410
+ if (request[0] === "#") {
21411
+ const found = resolveCJSHashImport(request, parent?.filename ? dirname(parent.filename) : process.cwd());
21412
+ if (found) return found;
21413
+ }
21414
+ if (!isAbsolute(request) && request[0] !== "." && request[0] !== "#" && !isNodeBuiltin(request)) {
21415
+ const parentNorm = normalizeVFSPath(parent?.filename ? dirname(parent.filename) : process.cwd());
21416
+ const { packageName, packageSubpath } = parsePackageName(request);
21417
+ let matched = false;
21418
+ for (let i = 0; i < activeVFSList.length; i++) {
21419
+ const vfs = activeVFSList[i];
21420
+ if (!vfs.shouldHandle(parentNorm)) continue;
21421
+ matched = true;
21422
+ const found = resolveCJSPackageInVFS(vfs, parentNorm, packageName, packageSubpath);
21423
+ if (found) return found;
21424
+ }
21425
+ if (!matched) for (let i = 0; i < activeVFSList.length; i++) {
21426
+ const vfs = activeVFSList[i];
21427
+ const mp = vfs.mountPoint;
21428
+ if (!mp) continue;
21429
+ const found = resolveCJSPackageInVFS(vfs, mp, packageName, packageSubpath);
21430
+ if (found) return found;
21431
+ }
21432
+ }
21433
+ return origResolveFilename.call(this, request, parent, isMain, options);
21434
+ };
21435
+ const origJsHandler = NodeModule._extensions[".js"];
21436
+ NodeModule._extensions[".js"] = function(module$1, filename) {
21437
+ const normalized = normalizeVFSPath(filename);
21438
+ for (let i = 0; i < activeVFSList.length; i++) {
21439
+ const vfs = activeVFSList[i];
21440
+ if (vfs.shouldHandle(normalized) && vfs.existsSync(normalized)) {
21441
+ const content = vfs.readFileSync(normalized, "utf8");
21442
+ module$1._compile(content, filename);
21443
+ return;
21444
+ }
21445
+ }
21446
+ return origJsHandler.call(this, module$1, filename);
21447
+ };
21448
+ const origJsonHandler = NodeModule._extensions[".json"];
21449
+ NodeModule._extensions[".json"] = function(module$2, filename) {
21450
+ const normalized = normalizeVFSPath(filename);
21451
+ for (let i = 0; i < activeVFSList.length; i++) {
21452
+ const vfs = activeVFSList[i];
21453
+ if (vfs.shouldHandle(normalized) && vfs.existsSync(normalized)) {
21454
+ const content = vfs.readFileSync(normalized, "utf8");
21455
+ module$2.exports = JSON.parse(content);
21456
+ return;
21457
+ }
21458
+ }
21459
+ return origJsonHandler.call(this, module$2, filename);
21460
+ };
21461
+ }
21462
+ function installFsPatches() {
21463
+ const fs = __require("node:fs");
21464
+ originalReadFileSync = fs.readFileSync;
21465
+ originalRealpathSync = fs.realpathSync;
21466
+ originalLstatSync = fs.lstatSync;
21467
+ originalStatSync = fs.statSync;
21468
+ fs.readFileSync = function readFileSync(path, options) {
21469
+ if (typeof path === "string") {
21470
+ const vfsResult = findVFSForRead(path, options);
21471
+ if (vfsResult !== null) return vfsResult.content;
21472
+ }
21473
+ return originalReadFileSync.call(fs, path, options);
21474
+ };
21475
+ fs.realpathSync = function realpathSync(path, options) {
21476
+ if (typeof path === "string") {
21477
+ const vfsResult = findVFSForRealpath(path);
21478
+ if (vfsResult !== null) return vfsResult.realpath;
21479
+ }
21480
+ return originalRealpathSync.call(fs, path, options);
21481
+ };
21482
+ if (originalRealpathSync.native) fs.realpathSync.native = originalRealpathSync.native;
21483
+ fs.lstatSync = function lstatSync(path, options) {
21484
+ if (typeof path === "string") {
21485
+ const vfsResult = findVFSForFsStat(path);
21486
+ if (vfsResult !== null) return vfsResult.stats;
21487
+ }
21488
+ return originalLstatSync.call(fs, path, options);
21489
+ };
21490
+ fs.statSync = function statSync(path, options) {
21491
+ if (typeof path === "string") {
21492
+ const vfsResult = findVFSForFsStat(path);
21493
+ if (vfsResult !== null) return vfsResult.stats;
21494
+ }
21495
+ return originalStatSync.call(fs, path, options);
21496
+ };
21497
+ originalReaddirSync = fs.readdirSync;
21498
+ fs.readdirSync = function readdirSync(path, options) {
21499
+ if (typeof path === "string") {
21500
+ const vfsResult = findVFSForReaddir(path, options);
21501
+ if (vfsResult !== null) return vfsResult.entries;
21502
+ }
21503
+ return originalReaddirSync.call(fs, path, options);
21504
+ };
21505
+ originalExistsSync = fs.existsSync;
21506
+ fs.existsSync = function existsSync(path) {
21507
+ if (typeof path === "string") {
21508
+ const vfsResult = findVFSForExists(path);
21509
+ if (vfsResult !== null) return vfsResult.exists;
21510
+ }
21511
+ return originalExistsSync.call(fs, path);
21512
+ };
21513
+ const originalReadlinkSync = fs.readlinkSync;
21514
+ fs.readlinkSync = function readlinkSync(path, options) {
21515
+ if (typeof path === "string") {
21516
+ const vfsResult = findVFSForRealpath(path);
21517
+ if (vfsResult !== null) return vfsResult.realpath;
21518
+ }
21519
+ return originalReadlinkSync.call(fs, path, options);
21520
+ };
21521
+ const originalAccessSync = fs.accessSync;
21522
+ fs.accessSync = function accessSync(path, mode) {
21523
+ if (typeof path === "string") {
21524
+ const vfsResult = findVFSForExists(path);
21525
+ if (vfsResult !== null) {
21526
+ if (!vfsResult.exists) throw createENOENT("access", path);
21527
+ return;
21528
+ }
21529
+ }
21530
+ return originalAccessSync.call(fs, path, mode);
21531
+ };
21532
+ const originalAccess = fs.access;
21533
+ fs.access = function access(path, mode, callback) {
21534
+ if (typeof mode === "function") {
21535
+ callback = mode;
21536
+ mode = fs.constants.F_OK;
21537
+ }
21538
+ if (typeof path === "string") {
21539
+ const vfsResult = findVFSForExists(path);
21540
+ if (vfsResult !== null) {
21541
+ const err = vfsResult.exists ? null : createENOENT("access", path);
21542
+ if (callback) process.nextTick(callback, err);
21543
+ return;
21544
+ }
21545
+ }
21546
+ return originalAccess.call(fs, path, mode, callback);
21547
+ };
21548
+ const originalStat = fs.stat;
21549
+ fs.stat = function stat(path, options, callback) {
21550
+ if (typeof options === "function") {
21551
+ callback = options;
21552
+ options = void 0;
21553
+ }
21554
+ if (typeof path === "string") try {
21555
+ const vfsResult = findVFSForFsStat(path);
21556
+ if (vfsResult !== null) {
21557
+ if (callback) process.nextTick(callback, null, vfsResult.stats);
21558
+ return;
21559
+ }
21560
+ } catch (err) {
21561
+ if (callback) process.nextTick(callback, err);
21562
+ return;
21563
+ }
21564
+ return originalStat.call(fs, path, options, callback);
21565
+ };
21566
+ const originalLstat = fs.lstat;
21567
+ fs.lstat = function lstat(path, options, callback) {
21568
+ if (typeof options === "function") {
21569
+ callback = options;
21570
+ options = void 0;
21571
+ }
21572
+ if (typeof path === "string") try {
21573
+ const vfsResult = findVFSForFsStat(path);
21574
+ if (vfsResult !== null) {
21575
+ if (callback) process.nextTick(callback, null, vfsResult.stats);
21576
+ return;
21577
+ }
21578
+ } catch (err) {
21579
+ if (callback) process.nextTick(callback, err);
21580
+ return;
21581
+ }
21582
+ return originalLstat.call(fs, path, options, callback);
21583
+ };
21584
+ const originalReadFile = fs.readFile;
21585
+ fs.readFile = function readFile(path, options, callback) {
21586
+ if (typeof options === "function") {
21587
+ callback = options;
21588
+ options = void 0;
21589
+ }
21590
+ if (typeof path === "string") try {
21591
+ const vfsResult = findVFSForRead(path, options);
21592
+ if (vfsResult !== null) {
21593
+ if (callback) process.nextTick(callback, null, vfsResult.content);
21594
+ return;
21595
+ }
21596
+ } catch (err) {
21597
+ if (callback) process.nextTick(callback, err);
21598
+ return;
21599
+ }
21600
+ return originalReadFile.call(fs, path, options, callback);
21601
+ };
21602
+ const originalCreateReadStream = fs.createReadStream;
21603
+ fs.createReadStream = function createReadStream(path, options) {
21604
+ if (typeof path === "string") try {
21605
+ const vfsResult = findVFSForRead(path, options);
21606
+ if (vfsResult !== null) {
21607
+ const { Readable } = __require("node:stream");
21608
+ const stream = new Readable({ read() {} });
21609
+ stream.push(vfsResult.content);
21610
+ stream.push(null);
21611
+ return stream;
21612
+ }
21613
+ } catch (err) {
21614
+ const { Readable } = __require("node:stream");
21615
+ const stream = new Readable({ read() {} });
21616
+ process.nextTick(() => stream.destroy(err));
21617
+ return stream;
21618
+ }
21619
+ return originalCreateReadStream.call(fs, path, options);
21620
+ };
21621
+ const originalReaddir = fs.readdir;
21622
+ fs.readdir = function readdir(path, options, callback) {
21623
+ if (typeof options === "function") {
21624
+ callback = options;
21625
+ options = void 0;
21626
+ }
21627
+ if (typeof path === "string") try {
21628
+ const vfsResult = findVFSForReaddir(path, options);
21629
+ if (vfsResult !== null) {
21630
+ if (callback) process.nextTick(callback, null, vfsResult.entries);
21631
+ return;
21632
+ }
21633
+ } catch (err) {
21634
+ if (callback) process.nextTick(callback, err);
21635
+ return;
21636
+ }
21637
+ return originalReaddir.call(fs, path, options, callback);
21638
+ };
21639
+ const originalReadlink = fs.readlink;
21640
+ fs.readlink = function readlink(path, options, callback) {
21641
+ if (typeof options === "function") {
21642
+ callback = options;
21643
+ options = void 0;
21644
+ }
21645
+ if (typeof path === "string") try {
21646
+ const vfsResult = findVFSForRealpath(path);
21647
+ if (vfsResult !== null) {
21648
+ if (callback) process.nextTick(callback, null, vfsResult.realpath);
21649
+ return;
21650
+ }
21651
+ } catch (err) {
21652
+ if (callback) process.nextTick(callback, err);
21653
+ return;
21654
+ }
21655
+ return originalReadlink.call(fs, path, options, callback);
21656
+ };
21657
+ const originalRealpath = fs.realpath;
21658
+ fs.realpath = function realpath(path, options, callback) {
21659
+ if (typeof options === "function") {
21660
+ callback = options;
21661
+ options = void 0;
21662
+ }
21663
+ if (typeof path === "string") try {
21664
+ const vfsResult = findVFSForRealpath(path);
21665
+ if (vfsResult !== null) {
21666
+ if (callback) process.nextTick(callback, null, vfsResult.realpath);
21667
+ return;
21668
+ }
21669
+ } catch (err) {
21670
+ if (callback) process.nextTick(callback, err);
21671
+ return;
21672
+ }
21673
+ return originalRealpath.call(fs, path, options, callback);
21674
+ };
21675
+ if (originalRealpath.native) fs.realpath.native = originalRealpath.native;
21676
+ const origPAccess = fs.promises.access;
21677
+ fs.promises.access = async function access(path, mode) {
21678
+ if (typeof path === "string") {
21679
+ const vfsResult = findVFSForExists(path);
21680
+ if (vfsResult !== null) {
21681
+ if (!vfsResult.exists) throw createENOENT("access", path);
21682
+ return;
21683
+ }
21684
+ }
21685
+ return origPAccess.call(fs.promises, path, mode);
21686
+ };
21687
+ const origPReadFile = fs.promises.readFile;
21688
+ fs.promises.readFile = async function readFile(path, options) {
21689
+ if (typeof path === "string") {
21690
+ const vfsResult = findVFSForRead(path, options);
21691
+ if (vfsResult !== null) return vfsResult.content;
21692
+ }
21693
+ return origPReadFile.call(fs.promises, path, options);
21694
+ };
21695
+ const origPStat = fs.promises.stat;
21696
+ fs.promises.stat = async function stat(path, options) {
21697
+ if (typeof path === "string") {
21698
+ const vfsResult = findVFSForFsStat(path);
21699
+ if (vfsResult !== null) return vfsResult.stats;
21700
+ }
21701
+ return origPStat.call(fs.promises, path, options);
21702
+ };
21703
+ const origPLstat = fs.promises.lstat;
21704
+ fs.promises.lstat = async function lstat(path, options) {
21705
+ if (typeof path === "string") {
21706
+ const vfsResult = findVFSForFsStat(path);
21707
+ if (vfsResult !== null) return vfsResult.stats;
21708
+ }
21709
+ return origPLstat.call(fs.promises, path, options);
21710
+ };
21711
+ const origPReaddir = fs.promises.readdir;
21712
+ fs.promises.readdir = async function readdir(path, options) {
21713
+ if (typeof path === "string") {
21714
+ const vfsResult = findVFSForReaddir(path, options);
21715
+ if (vfsResult !== null) return vfsResult.entries;
21716
+ }
21717
+ return origPReaddir.call(fs.promises, path, options);
21718
+ };
21719
+ const origPReadlink = fs.promises.readlink;
21720
+ fs.promises.readlink = async function readlink(path, options) {
21721
+ if (typeof path === "string") {
21722
+ const vfsResult = findVFSForRealpath(path);
21723
+ if (vfsResult !== null) return vfsResult.realpath;
21724
+ }
21725
+ return origPReadlink.call(fs.promises, path, options);
21726
+ };
21727
+ const origPRealpath = fs.promises.realpath;
21728
+ fs.promises.realpath = async function realpath(path, options) {
21729
+ if (typeof path === "string") {
21730
+ const vfsResult = findVFSForRealpath(path);
21731
+ if (vfsResult !== null) return vfsResult.realpath;
21732
+ }
21733
+ return origPRealpath.call(fs.promises, path, options);
21734
+ };
21735
+ originalWatch = fs.watch;
21736
+ fs.watch = function watch(filename, options, listener) {
21737
+ if (typeof options === "function") {
21738
+ listener = options;
21739
+ options = kEmptyObject;
21740
+ } else options ??= kEmptyObject;
21741
+ if (typeof filename === "string") {
21742
+ const vfsResult = findVFSForWatch(filename);
21743
+ if (vfsResult !== null) return vfsResult.vfs.watch(filename, options, listener);
21744
+ }
21745
+ return originalWatch.call(fs, filename, options, listener);
21746
+ };
21747
+ originalWatchFile = fs.watchFile;
21748
+ fs.watchFile = function watchFile(filename, options, listener) {
21749
+ if (typeof options === "function") {
21750
+ listener = options;
21751
+ options = kEmptyObject;
21752
+ } else options ??= kEmptyObject;
21753
+ if (typeof filename === "string") {
21754
+ const vfsResult = findVFSForWatch(filename);
21755
+ if (vfsResult !== null) return vfsResult.vfs.watchFile(filename, options, listener);
21756
+ }
21757
+ return originalWatchFile.call(fs, filename, options, listener);
21758
+ };
21759
+ originalUnwatchFile = fs.unwatchFile;
21760
+ fs.unwatchFile = function unwatchFile(filename, listener) {
21761
+ if (typeof filename === "string") {
21762
+ const vfsResult = findVFSForWatch(filename);
21763
+ if (vfsResult !== null) {
21764
+ vfsResult.vfs.unwatchFile(filename, listener);
21765
+ return;
21766
+ }
21767
+ }
21768
+ return originalUnwatchFile.call(fs, filename, listener);
21769
+ };
21770
+ }
21771
+ function installHooks() {
21772
+ if (hooksInstalled) return;
21773
+ installModuleHooks();
21774
+ installFsPatches();
21775
+ hooksInstalled = true;
21776
+ }
21777
+ module.exports = {
21778
+ registerVFS,
21779
+ deregisterVFS,
21780
+ findVFSForStat,
21781
+ findVFSForRead
21782
+ };
21783
+ }));
21784
+ //#endregion
21785
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/file_system.js
21786
+ var require_file_system = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
21787
+ const path$1 = __require("node:path");
21788
+ const pathPosix = path$1.posix;
21789
+ const { isAbsolute, resolve: resolvePath } = path$1;
21790
+ const { MemoryProvider } = require_memory();
21791
+ const { isUnderMountPoint, getRelativePath } = require_router();
21792
+ const { openVirtualFd, getVirtualFd, closeVirtualFd } = require_fd();
21793
+ const { createENOENT, createENOTDIR, createEBADF, ERR_INVALID_STATE } = require_errors();
21794
+ const { VirtualReadStream } = require_streams();
21795
+ const kEmptyObject = Object.freeze(Object.create(null));
21796
+ function normalizeVFSPath(inputPath) {
21797
+ if (inputPath.startsWith("/")) return pathPosix.normalize(inputPath);
21798
+ return path$1.normalize(inputPath);
21799
+ }
21800
+ function joinVFSPath(base, part) {
21801
+ if (base.startsWith("/")) return pathPosix.join(base, part);
21802
+ return path$1.join(base, part);
21803
+ }
21804
+ const kProvider = Symbol("kProvider");
21805
+ const kMountPoint = Symbol("kMountPoint");
21806
+ const kMounted = Symbol("kMounted");
21807
+ const kOverlay = Symbol("kOverlay");
21808
+ const kModuleHooks = Symbol("kModuleHooks");
21809
+ const kPromises = Symbol("kPromises");
21810
+ const kVirtualCwd = Symbol("kVirtualCwd");
21811
+ const kVirtualCwdEnabled = Symbol("kVirtualCwdEnabled");
21812
+ const kOriginalChdir = Symbol("kOriginalChdir");
21813
+ const kOriginalCwd = Symbol("kOriginalCwd");
21814
+ let registerVFS;
21815
+ let deregisterVFS;
21816
+ function loadModuleHooks() {
21817
+ if (!registerVFS) {
21818
+ const hooks = require_module_hooks();
21819
+ registerVFS = hooks.registerVFS;
21820
+ deregisterVFS = hooks.deregisterVFS;
21821
+ }
21822
+ }
21823
+ var VirtualFileSystem = class {
21824
+ constructor(providerOrOptions, options = kEmptyObject) {
21825
+ let provider = null;
21826
+ if (providerOrOptions !== void 0 && providerOrOptions !== null) {
21827
+ if (typeof providerOrOptions.openSync === "function") provider = providerOrOptions;
21828
+ else if (typeof providerOrOptions === "object") {
21829
+ options = providerOrOptions;
21830
+ provider = null;
21831
+ }
21832
+ }
21833
+ if (options.moduleHooks !== void 0 && typeof options.moduleHooks !== "boolean") throw new TypeError("options.moduleHooks must be a boolean");
21834
+ if (options.virtualCwd !== void 0 && typeof options.virtualCwd !== "boolean") throw new TypeError("options.virtualCwd must be a boolean");
21835
+ if (options.overlay !== void 0 && typeof options.overlay !== "boolean") throw new TypeError("options.overlay must be a boolean");
21836
+ this[kProvider] = provider ?? new MemoryProvider();
21837
+ this[kMountPoint] = null;
21838
+ this[kMounted] = false;
21839
+ this[kOverlay] = options.overlay === true;
21840
+ this[kModuleHooks] = options.moduleHooks !== false;
21841
+ this[kPromises] = null;
21842
+ this[kVirtualCwdEnabled] = options.virtualCwd === true;
21843
+ this[kVirtualCwd] = null;
21844
+ this[kOriginalChdir] = null;
21845
+ this[kOriginalCwd] = null;
21846
+ }
21847
+ get provider() {
21848
+ return this[kProvider];
21849
+ }
21850
+ get mountPoint() {
21851
+ return this[kMountPoint];
21852
+ }
21853
+ get mounted() {
21854
+ return this[kMounted];
21855
+ }
21856
+ get readonly() {
21857
+ return this[kProvider].readonly;
21858
+ }
21859
+ get overlay() {
21860
+ return this[kOverlay];
21861
+ }
21862
+ get virtualCwdEnabled() {
21863
+ return this[kVirtualCwdEnabled];
21864
+ }
21865
+ cwd() {
21866
+ if (!this[kVirtualCwdEnabled]) throw new ERR_INVALID_STATE("virtual cwd is not enabled");
21867
+ return this[kVirtualCwd];
21868
+ }
21869
+ chdir(dirPath) {
21870
+ if (!this[kVirtualCwdEnabled]) throw new ERR_INVALID_STATE("virtual cwd is not enabled");
21871
+ const providerPath = this.#toProviderPath(dirPath);
21872
+ if (!this[kProvider].statSync(providerPath).isDirectory()) throw createENOTDIR("chdir", dirPath);
21873
+ this[kVirtualCwd] = this.#toMountedPath(providerPath);
21874
+ }
21875
+ resolvePath(inputPath) {
21876
+ if (isAbsolute(inputPath)) return normalizeVFSPath(inputPath);
21877
+ if (this[kVirtualCwdEnabled] && this[kVirtualCwd] !== null) return normalizeVFSPath(`${this[kVirtualCwd]}/${inputPath}`);
21878
+ return resolvePath(inputPath);
21879
+ }
21880
+ mount(prefix) {
21881
+ if (this[kMounted]) throw new ERR_INVALID_STATE("VFS is already mounted");
21882
+ this[kMountPoint] = normalizeVFSPath(prefix);
21883
+ this[kMounted] = true;
21884
+ if (this[kModuleHooks]) {
21885
+ loadModuleHooks();
21886
+ registerVFS(this);
21887
+ }
21888
+ if (this[kVirtualCwdEnabled]) this.#hookProcessCwd();
21889
+ process.emit("vfs-mount", {
21890
+ mountPoint: this[kMountPoint],
21891
+ overlay: this[kOverlay],
21892
+ readonly: this[kProvider].readonly
21893
+ });
21894
+ return this;
21895
+ }
21896
+ unmount() {
21897
+ if (this[kMounted]) process.emit("vfs-unmount", {
21898
+ mountPoint: this[kMountPoint],
21899
+ overlay: this[kOverlay],
21900
+ readonly: this[kProvider].readonly
21901
+ });
21902
+ this.#unhookProcessCwd();
21903
+ if (this[kModuleHooks]) {
21904
+ loadModuleHooks();
21905
+ deregisterVFS(this);
21906
+ }
21907
+ this[kMountPoint] = null;
21908
+ this[kMounted] = false;
21909
+ this[kVirtualCwd] = null;
21910
+ }
21911
+ [Symbol.dispose]() {
21912
+ if (this[kMounted]) this.unmount();
21913
+ }
21914
+ #hookProcessCwd() {
21915
+ if (this[kOriginalChdir] !== null) return;
21916
+ const vfs = this;
21917
+ this[kOriginalChdir] = process.chdir;
21918
+ this[kOriginalCwd] = process.cwd;
21919
+ process.chdir = function chdir(directory) {
21920
+ const normalized = isAbsolute(directory) ? normalizeVFSPath(directory) : resolvePath(directory);
21921
+ if (vfs.shouldHandle(normalized)) {
21922
+ vfs.chdir(normalized);
21923
+ return;
21924
+ }
21925
+ return vfs[kOriginalChdir].call(process, directory);
21926
+ };
21927
+ process.cwd = function cwd() {
21928
+ if (vfs[kVirtualCwd] !== null) return vfs[kVirtualCwd];
21929
+ return vfs[kOriginalCwd].call(process);
21930
+ };
21931
+ }
21932
+ #unhookProcessCwd() {
21933
+ if (this[kOriginalChdir] === null) return;
21934
+ process.chdir = this[kOriginalChdir];
21935
+ process.cwd = this[kOriginalCwd];
21936
+ this[kOriginalChdir] = null;
21937
+ this[kOriginalCwd] = null;
21938
+ }
21939
+ #toProviderPath(inputPath) {
21940
+ const resolved = this.resolvePath(inputPath);
21941
+ if (this[kMounted] && this[kMountPoint]) {
21942
+ if (!isUnderMountPoint(resolved, this[kMountPoint])) throw createENOENT("open", inputPath);
21943
+ return getRelativePath(resolved, this[kMountPoint]);
21944
+ }
21945
+ return resolved;
21946
+ }
21947
+ #toMountedPath(providerPath) {
21948
+ if (this[kMounted] && this[kMountPoint]) return joinVFSPath(this[kMountPoint], providerPath);
21949
+ return providerPath;
21950
+ }
21951
+ shouldHandle(inputPath) {
21952
+ if (!this[kMounted] || !this[kMountPoint]) return false;
21953
+ const normalized = normalizeVFSPath(inputPath);
21954
+ if (!isUnderMountPoint(normalized, this[kMountPoint])) return false;
21955
+ if (this[kOverlay]) try {
21956
+ const providerPath = getRelativePath(normalized, this[kMountPoint]);
21957
+ return this[kProvider].existsSync(providerPath);
21958
+ } catch {
21959
+ return false;
21960
+ }
21961
+ return true;
21962
+ }
21963
+ existsSync(filePath) {
21964
+ try {
21965
+ const providerPath = this.#toProviderPath(filePath);
21966
+ return this[kProvider].existsSync(providerPath);
21967
+ } catch {
21968
+ return false;
21969
+ }
21970
+ }
21971
+ statSync(filePath, options) {
21972
+ const providerPath = this.#toProviderPath(filePath);
21973
+ return this[kProvider].statSync(providerPath, options);
21974
+ }
21975
+ lstatSync(filePath, options) {
21976
+ const providerPath = this.#toProviderPath(filePath);
21977
+ return this[kProvider].lstatSync(providerPath, options);
21978
+ }
21979
+ readFileSync(filePath, options) {
21980
+ const providerPath = this.#toProviderPath(filePath);
21981
+ return this[kProvider].readFileSync(providerPath, options);
21982
+ }
21983
+ writeFileSync(filePath, data, options) {
21984
+ const providerPath = this.#toProviderPath(filePath);
21985
+ this[kProvider].writeFileSync(providerPath, data, options);
21986
+ }
21987
+ appendFileSync(filePath, data, options) {
21988
+ const providerPath = this.#toProviderPath(filePath);
21989
+ this[kProvider].appendFileSync(providerPath, data, options);
21990
+ }
21991
+ readdirSync(dirPath, options) {
21992
+ const providerPath = this.#toProviderPath(dirPath);
21993
+ return this[kProvider].readdirSync(providerPath, options);
21994
+ }
21995
+ mkdirSync(dirPath, options) {
21996
+ const providerPath = this.#toProviderPath(dirPath);
21997
+ const result = this[kProvider].mkdirSync(providerPath, options);
21998
+ if (result !== void 0) return this.#toMountedPath(result);
21999
+ }
22000
+ rmdirSync(dirPath) {
22001
+ const providerPath = this.#toProviderPath(dirPath);
22002
+ this[kProvider].rmdirSync(providerPath);
22003
+ }
22004
+ unlinkSync(filePath) {
22005
+ const providerPath = this.#toProviderPath(filePath);
22006
+ this[kProvider].unlinkSync(providerPath);
22007
+ }
22008
+ renameSync(oldPath, newPath) {
22009
+ const oldProviderPath = this.#toProviderPath(oldPath);
22010
+ const newProviderPath = this.#toProviderPath(newPath);
22011
+ this[kProvider].renameSync(oldProviderPath, newProviderPath);
22012
+ }
22013
+ copyFileSync(src, dest, mode) {
22014
+ const srcProviderPath = this.#toProviderPath(src);
22015
+ const destProviderPath = this.#toProviderPath(dest);
22016
+ this[kProvider].copyFileSync(srcProviderPath, destProviderPath, mode);
22017
+ }
22018
+ realpathSync(filePath, options) {
22019
+ const providerPath = this.#toProviderPath(filePath);
22020
+ const realProviderPath = this[kProvider].realpathSync(providerPath, options);
22021
+ return this.#toMountedPath(realProviderPath);
22022
+ }
22023
+ readlinkSync(linkPath, options) {
22024
+ const providerPath = this.#toProviderPath(linkPath);
22025
+ return this[kProvider].readlinkSync(providerPath, options);
22026
+ }
22027
+ symlinkSync(target, path, type) {
22028
+ const providerPath = this.#toProviderPath(path);
22029
+ this[kProvider].symlinkSync(target, providerPath, type);
22030
+ }
22031
+ accessSync(filePath, mode) {
22032
+ const providerPath = this.#toProviderPath(filePath);
22033
+ this[kProvider].accessSync(providerPath, mode);
22034
+ }
22035
+ internalModuleStat(filePath) {
22036
+ try {
22037
+ const providerPath = this.#toProviderPath(filePath);
22038
+ return this[kProvider].internalModuleStat(providerPath);
22039
+ } catch {
22040
+ return -2;
22041
+ }
22042
+ }
22043
+ openSync(filePath, flags = "r", mode) {
22044
+ const providerPath = this.#toProviderPath(filePath);
22045
+ return openVirtualFd(this[kProvider].openSync(providerPath, flags, mode));
22046
+ }
22047
+ closeSync(fd) {
22048
+ const vfd = getVirtualFd(fd);
22049
+ if (!vfd) throw createEBADF("close");
22050
+ vfd.entry.closeSync();
22051
+ closeVirtualFd(fd);
22052
+ }
22053
+ readSync(fd, buffer, offset, length, position) {
22054
+ const vfd = getVirtualFd(fd);
22055
+ if (!vfd) throw createEBADF("read");
22056
+ return vfd.entry.readSync(buffer, offset, length, position);
22057
+ }
22058
+ fstatSync(fd, options) {
22059
+ const vfd = getVirtualFd(fd);
22060
+ if (!vfd) throw createEBADF("fstat");
22061
+ return vfd.entry.statSync(options);
22062
+ }
22063
+ readFile(filePath, options, callback) {
22064
+ if (typeof options === "function") {
22065
+ callback = options;
22066
+ options = void 0;
22067
+ }
22068
+ this[kProvider].readFile(this.#toProviderPath(filePath), options).then((data) => callback(null, data), (err) => callback(err));
22069
+ }
22070
+ writeFile(filePath, data, options, callback) {
22071
+ if (typeof options === "function") {
22072
+ callback = options;
22073
+ options = void 0;
22074
+ }
22075
+ this[kProvider].writeFile(this.#toProviderPath(filePath), data, options).then(() => callback(null), (err) => callback(err));
22076
+ }
22077
+ stat(filePath, options, callback) {
22078
+ if (typeof options === "function") {
22079
+ callback = options;
22080
+ options = void 0;
22081
+ }
22082
+ this[kProvider].stat(this.#toProviderPath(filePath), options).then((stats) => callback(null, stats), (err) => callback(err));
22083
+ }
22084
+ lstat(filePath, options, callback) {
22085
+ if (typeof options === "function") {
22086
+ callback = options;
22087
+ options = void 0;
22088
+ }
22089
+ this[kProvider].lstat(this.#toProviderPath(filePath), options).then((stats) => callback(null, stats), (err) => callback(err));
22090
+ }
22091
+ readdir(dirPath, options, callback) {
22092
+ if (typeof options === "function") {
22093
+ callback = options;
22094
+ options = void 0;
22095
+ }
22096
+ this[kProvider].readdir(this.#toProviderPath(dirPath), options).then((entries) => callback(null, entries), (err) => callback(err));
22097
+ }
22098
+ realpath(filePath, options, callback) {
22099
+ if (typeof options === "function") {
22100
+ callback = options;
22101
+ options = void 0;
22102
+ }
22103
+ this[kProvider].realpath(this.#toProviderPath(filePath), options).then((realPath) => callback(null, this.#toMountedPath(realPath)), (err) => callback(err));
22104
+ }
22105
+ readlink(linkPath, options, callback) {
22106
+ if (typeof options === "function") {
22107
+ callback = options;
22108
+ options = void 0;
22109
+ }
22110
+ this[kProvider].readlink(this.#toProviderPath(linkPath), options).then((target) => callback(null, target), (err) => callback(err));
22111
+ }
22112
+ access(filePath, mode, callback) {
22113
+ if (typeof mode === "function") {
22114
+ callback = mode;
22115
+ mode = void 0;
22116
+ }
22117
+ this[kProvider].access(this.#toProviderPath(filePath), mode).then(() => callback(null), (err) => callback(err));
22118
+ }
22119
+ open(filePath, flags, mode, callback) {
22120
+ if (typeof flags === "function") {
22121
+ callback = flags;
22122
+ flags = "r";
22123
+ mode = void 0;
22124
+ } else if (typeof mode === "function") {
22125
+ callback = mode;
22126
+ mode = void 0;
22127
+ }
22128
+ const providerPath = this.#toProviderPath(filePath);
22129
+ this[kProvider].open(providerPath, flags, mode).then((handle) => {
22130
+ const fd = openVirtualFd(handle);
22131
+ callback(null, fd);
22132
+ }, (err) => callback(err));
22133
+ }
22134
+ close(fd, callback) {
22135
+ const vfd = getVirtualFd(fd);
22136
+ if (!vfd) {
22137
+ process.nextTick(callback, createEBADF("close"));
22138
+ return;
22139
+ }
22140
+ vfd.entry.close().then(() => {
22141
+ closeVirtualFd(fd);
22142
+ callback(null);
22143
+ }, (err) => callback(err));
22144
+ }
22145
+ read(fd, buffer, offset, length, position, callback) {
22146
+ const vfd = getVirtualFd(fd);
22147
+ if (!vfd) {
22148
+ process.nextTick(callback, createEBADF("read"));
22149
+ return;
22150
+ }
22151
+ vfd.entry.read(buffer, offset, length, position).then(({ bytesRead }) => callback(null, bytesRead, buffer), (err) => callback(err));
22152
+ }
22153
+ fstat(fd, options, callback) {
22154
+ if (typeof options === "function") {
22155
+ callback = options;
22156
+ options = void 0;
22157
+ }
22158
+ const vfd = getVirtualFd(fd);
22159
+ if (!vfd) {
22160
+ process.nextTick(callback, createEBADF("fstat"));
22161
+ return;
22162
+ }
22163
+ vfd.entry.stat(options).then((stats) => callback(null, stats), (err) => callback(err));
22164
+ }
22165
+ createReadStream(filePath, options) {
22166
+ return new VirtualReadStream(this, filePath, options);
22167
+ }
22168
+ watch(filePath, options, listener) {
22169
+ if (typeof options === "function") {
22170
+ listener = options;
22171
+ options = {};
22172
+ }
22173
+ const providerPath = this.#toProviderPath(filePath);
22174
+ const watcher = this[kProvider].watch(providerPath, options);
22175
+ if (listener) watcher.on("change", listener);
22176
+ return watcher;
22177
+ }
22178
+ watchFile(filePath, options, listener) {
22179
+ if (typeof options === "function") {
22180
+ listener = options;
22181
+ options = {};
22182
+ }
22183
+ const providerPath = this.#toProviderPath(filePath);
22184
+ return this[kProvider].watchFile(providerPath, options, listener);
22185
+ }
22186
+ unwatchFile(filePath, listener) {
22187
+ const providerPath = this.#toProviderPath(filePath);
22188
+ this[kProvider].unwatchFile(providerPath, listener);
22189
+ }
22190
+ get promises() {
22191
+ if (this[kPromises] === null) this[kPromises] = this.#createPromisesAPI();
22192
+ return this[kPromises];
22193
+ }
22194
+ #createPromisesAPI() {
22195
+ const provider = this[kProvider];
22196
+ const toProviderPath = (p) => this.#toProviderPath(p);
22197
+ const toMountedPath = (p) => this.#toMountedPath(p);
22198
+ return Object.freeze({
22199
+ async readFile(filePath, options) {
22200
+ const providerPath = toProviderPath(filePath);
22201
+ return provider.readFile(providerPath, options);
22202
+ },
22203
+ async writeFile(filePath, data, options) {
22204
+ const providerPath = toProviderPath(filePath);
22205
+ return provider.writeFile(providerPath, data, options);
22206
+ },
22207
+ async appendFile(filePath, data, options) {
22208
+ const providerPath = toProviderPath(filePath);
22209
+ return provider.appendFile(providerPath, data, options);
22210
+ },
22211
+ async stat(filePath, options) {
22212
+ const providerPath = toProviderPath(filePath);
22213
+ return provider.stat(providerPath, options);
22214
+ },
22215
+ async lstat(filePath, options) {
22216
+ const providerPath = toProviderPath(filePath);
22217
+ return provider.lstat(providerPath, options);
22218
+ },
22219
+ async readdir(dirPath, options) {
22220
+ const providerPath = toProviderPath(dirPath);
22221
+ return provider.readdir(providerPath, options);
22222
+ },
22223
+ async mkdir(dirPath, options) {
22224
+ const providerPath = toProviderPath(dirPath);
22225
+ const result = await provider.mkdir(providerPath, options);
22226
+ if (result !== void 0) return toMountedPath(result);
22227
+ },
22228
+ async rmdir(dirPath) {
22229
+ const providerPath = toProviderPath(dirPath);
22230
+ return provider.rmdir(providerPath);
22231
+ },
22232
+ async unlink(filePath) {
22233
+ const providerPath = toProviderPath(filePath);
22234
+ return provider.unlink(providerPath);
22235
+ },
22236
+ async rename(oldPath, newPath) {
22237
+ const oldProviderPath = toProviderPath(oldPath);
22238
+ const newProviderPath = toProviderPath(newPath);
22239
+ return provider.rename(oldProviderPath, newProviderPath);
22240
+ },
22241
+ async copyFile(src, dest, mode) {
22242
+ const srcProviderPath = toProviderPath(src);
22243
+ const destProviderPath = toProviderPath(dest);
22244
+ return provider.copyFile(srcProviderPath, destProviderPath, mode);
22245
+ },
22246
+ async realpath(filePath, options) {
22247
+ const providerPath = toProviderPath(filePath);
22248
+ return toMountedPath(await provider.realpath(providerPath, options));
22249
+ },
22250
+ async readlink(linkPath, options) {
22251
+ const providerPath = toProviderPath(linkPath);
22252
+ return provider.readlink(providerPath, options);
22253
+ },
22254
+ async symlink(target, path, type) {
22255
+ const providerPath = toProviderPath(path);
22256
+ return provider.symlink(target, providerPath, type);
22257
+ },
22258
+ async access(filePath, mode) {
22259
+ const providerPath = toProviderPath(filePath);
22260
+ return provider.access(providerPath, mode);
22261
+ },
22262
+ watch(filePath, options) {
22263
+ const providerPath = toProviderPath(filePath);
22264
+ return provider.watchAsync(providerPath, options);
22265
+ }
22266
+ });
22267
+ }
22268
+ };
22269
+ module.exports = { VirtualFileSystem };
22270
+ }));
22271
+ //#endregion
22272
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/providers/real.js
22273
+ var require_real = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
22274
+ const fs = __require("node:fs");
22275
+ const path = __require("node:path");
22276
+ const { VirtualProvider } = require_provider();
22277
+ const { VirtualFileHandle } = require_file_handle();
22278
+ const { createEBADF, createENOENT, ERR_INVALID_ARG_VALUE } = require_errors();
22279
+ var RealFileHandle = class extends VirtualFileHandle {
22280
+ #fd;
22281
+ #realPath;
22282
+ #checkClosed() {
22283
+ if (this.closed) throw createEBADF("read");
22284
+ }
22285
+ constructor(path, flags, mode, fd, realPath) {
22286
+ super(path, flags, mode);
22287
+ this.#fd = fd;
22288
+ this.#realPath = realPath;
22289
+ }
22290
+ get fd() {
22291
+ return this.#fd;
22292
+ }
22293
+ readSync(buffer, offset, length, position) {
22294
+ this.#checkClosed();
22295
+ return fs.readSync(this.#fd, buffer, offset, length, position);
22296
+ }
22297
+ async read(buffer, offset, length, position) {
22298
+ this.#checkClosed();
22299
+ return new Promise((resolve, reject) => {
22300
+ fs.read(this.#fd, buffer, offset, length, position, (err, bytesRead) => {
22301
+ if (err) reject(err);
22302
+ else resolve({
22303
+ bytesRead,
22304
+ buffer
22305
+ });
22306
+ });
22307
+ });
22308
+ }
22309
+ writeSync(buffer, offset, length, position) {
22310
+ this.#checkClosed();
22311
+ return fs.writeSync(this.#fd, buffer, offset, length, position);
22312
+ }
22313
+ async write(buffer, offset, length, position) {
22314
+ this.#checkClosed();
22315
+ return new Promise((resolve, reject) => {
22316
+ fs.write(this.#fd, buffer, offset, length, position, (err, bytesWritten) => {
22317
+ if (err) reject(err);
22318
+ else resolve({
22319
+ bytesWritten,
22320
+ buffer
22321
+ });
22322
+ });
22323
+ });
22324
+ }
22325
+ readFileSync(options) {
22326
+ this.#checkClosed();
22327
+ return fs.readFileSync(this.#realPath, options);
22328
+ }
22329
+ async readFile(options) {
22330
+ this.#checkClosed();
22331
+ return fs.promises.readFile(this.#realPath, options);
22332
+ }
22333
+ writeFileSync(data, options) {
22334
+ this.#checkClosed();
22335
+ fs.writeFileSync(this.#fd, data, options);
22336
+ }
22337
+ async writeFile(data, options) {
22338
+ this.#checkClosed();
22339
+ return new Promise((resolve, reject) => {
22340
+ fs.writeFile(this.#fd, data, options, (err) => {
22341
+ if (err) reject(err);
22342
+ else resolve();
22343
+ });
22344
+ });
22345
+ }
22346
+ statSync(options) {
22347
+ this.#checkClosed();
22348
+ return fs.fstatSync(this.#fd, options);
22349
+ }
22350
+ async stat(options) {
22351
+ this.#checkClosed();
22352
+ return new Promise((resolve, reject) => {
22353
+ fs.fstat(this.#fd, options, (err, stats) => {
22354
+ if (err) reject(err);
22355
+ else resolve(stats);
22356
+ });
22357
+ });
22358
+ }
22359
+ truncateSync(len = 0) {
22360
+ this.#checkClosed();
22361
+ fs.ftruncateSync(this.#fd, len);
22362
+ }
22363
+ async truncate(len = 0) {
22364
+ this.#checkClosed();
22365
+ return new Promise((resolve, reject) => {
22366
+ fs.ftruncate(this.#fd, len, (err) => {
22367
+ if (err) reject(err);
22368
+ else resolve();
22369
+ });
22370
+ });
22371
+ }
22372
+ closeSync() {
22373
+ if (!this.closed) {
22374
+ fs.closeSync(this.#fd);
22375
+ super.closeSync();
22376
+ }
22377
+ }
22378
+ async close() {
22379
+ if (!this.closed) return new Promise((resolve, reject) => {
22380
+ fs.close(this.#fd, (err) => {
22381
+ if (err) reject(err);
22382
+ else {
22383
+ super.closeSync();
22384
+ resolve();
22385
+ }
22386
+ });
22387
+ });
22388
+ }
22389
+ };
22390
+ var RealFSProvider = class extends VirtualProvider {
22391
+ #rootPath;
22392
+ constructor(rootPath) {
22393
+ super();
22394
+ if (typeof rootPath !== "string" || rootPath === "") throw new ERR_INVALID_ARG_VALUE("rootPath", rootPath, "must be a non-empty string");
22395
+ this.#rootPath = path.resolve(rootPath);
22396
+ }
22397
+ get rootPath() {
22398
+ return this.#rootPath;
22399
+ }
22400
+ get readonly() {
22401
+ return false;
22402
+ }
22403
+ get supportsSymlinks() {
22404
+ return true;
22405
+ }
22406
+ #resolvePath(vfsPath) {
22407
+ if (vfsPath.startsWith(this.#rootPath + path.sep) || vfsPath === this.#rootPath) return path.resolve(vfsPath);
22408
+ let normalized = vfsPath;
22409
+ if (normalized.startsWith("/")) normalized = normalized.slice(1);
22410
+ const realPath = path.resolve(this.#rootPath, normalized);
22411
+ const rootWithSep = this.#rootPath.endsWith(path.sep) ? this.#rootPath : this.#rootPath + path.sep;
22412
+ if (realPath !== this.#rootPath && !realPath.startsWith(rootWithSep)) throw createENOENT("open", vfsPath);
22413
+ return realPath;
22414
+ }
22415
+ openSync(vfsPath, flags, mode) {
22416
+ const realPath = this.#resolvePath(vfsPath);
22417
+ const fd = fs.openSync(realPath, flags, mode);
22418
+ return new RealFileHandle(vfsPath, flags, mode ?? 420, fd, realPath);
22419
+ }
22420
+ async open(vfsPath, flags, mode) {
22421
+ const realPath = this.#resolvePath(vfsPath);
22422
+ return new Promise((resolve, reject) => {
22423
+ fs.open(realPath, flags, mode, (err, fd) => {
22424
+ if (err) reject(err);
22425
+ else resolve(new RealFileHandle(vfsPath, flags, mode ?? 420, fd, realPath));
22426
+ });
22427
+ });
22428
+ }
22429
+ statSync(vfsPath, options) {
22430
+ const realPath = this.#resolvePath(vfsPath);
22431
+ return fs.statSync(realPath, options);
22432
+ }
22433
+ async stat(vfsPath, options) {
22434
+ const realPath = this.#resolvePath(vfsPath);
22435
+ return fs.promises.stat(realPath, options);
22436
+ }
22437
+ lstatSync(vfsPath, options) {
22438
+ const realPath = this.#resolvePath(vfsPath);
22439
+ return fs.lstatSync(realPath, options);
22440
+ }
22441
+ async lstat(vfsPath, options) {
22442
+ const realPath = this.#resolvePath(vfsPath);
22443
+ return fs.promises.lstat(realPath, options);
22444
+ }
22445
+ readdirSync(vfsPath, options) {
22446
+ const realPath = this.#resolvePath(vfsPath);
22447
+ return fs.readdirSync(realPath, options);
22448
+ }
22449
+ async readdir(vfsPath, options) {
22450
+ const realPath = this.#resolvePath(vfsPath);
22451
+ return fs.promises.readdir(realPath, options);
22452
+ }
22453
+ mkdirSync(vfsPath, options) {
22454
+ const realPath = this.#resolvePath(vfsPath);
22455
+ return fs.mkdirSync(realPath, options);
22456
+ }
22457
+ async mkdir(vfsPath, options) {
22458
+ const realPath = this.#resolvePath(vfsPath);
22459
+ return fs.promises.mkdir(realPath, options);
22460
+ }
22461
+ rmdirSync(vfsPath) {
22462
+ const realPath = this.#resolvePath(vfsPath);
22463
+ fs.rmdirSync(realPath);
22464
+ }
22465
+ async rmdir(vfsPath) {
22466
+ const realPath = this.#resolvePath(vfsPath);
22467
+ return fs.promises.rmdir(realPath);
22468
+ }
22469
+ unlinkSync(vfsPath) {
22470
+ const realPath = this.#resolvePath(vfsPath);
22471
+ fs.unlinkSync(realPath);
22472
+ }
22473
+ async unlink(vfsPath) {
22474
+ const realPath = this.#resolvePath(vfsPath);
22475
+ return fs.promises.unlink(realPath);
22476
+ }
22477
+ renameSync(oldVfsPath, newVfsPath) {
22478
+ const oldRealPath = this.#resolvePath(oldVfsPath);
22479
+ const newRealPath = this.#resolvePath(newVfsPath);
22480
+ fs.renameSync(oldRealPath, newRealPath);
22481
+ }
22482
+ async rename(oldVfsPath, newVfsPath) {
22483
+ const oldRealPath = this.#resolvePath(oldVfsPath);
22484
+ const newRealPath = this.#resolvePath(newVfsPath);
22485
+ return fs.promises.rename(oldRealPath, newRealPath);
22486
+ }
22487
+ readlinkSync(vfsPath, options) {
22488
+ const realPath = this.#resolvePath(vfsPath);
22489
+ return fs.readlinkSync(realPath, options);
22490
+ }
22491
+ async readlink(vfsPath, options) {
22492
+ const realPath = this.#resolvePath(vfsPath);
22493
+ return fs.promises.readlink(realPath, options);
22494
+ }
22495
+ symlinkSync(target, vfsPath, type) {
22496
+ const realPath = this.#resolvePath(vfsPath);
22497
+ fs.symlinkSync(target, realPath, type);
22498
+ }
22499
+ async symlink(target, vfsPath, type) {
22500
+ const realPath = this.#resolvePath(vfsPath);
22501
+ return fs.promises.symlink(target, realPath, type);
22502
+ }
22503
+ realpathSync(vfsPath, options) {
22504
+ const realPath = this.#resolvePath(vfsPath);
22505
+ const resolved = fs.realpathSync(realPath, options);
22506
+ if (resolved === this.#rootPath) return "/";
22507
+ const rootWithSep = this.#rootPath + path.sep;
22508
+ if (resolved.startsWith(rootWithSep)) return "/" + resolved.slice(rootWithSep.length).replace(/\\/g, "/");
22509
+ return vfsPath;
22510
+ }
22511
+ async realpath(vfsPath, options) {
22512
+ const realPath = this.#resolvePath(vfsPath);
22513
+ const resolved = await fs.promises.realpath(realPath, options);
22514
+ if (resolved === this.#rootPath) return "/";
22515
+ const rootWithSep = this.#rootPath + path.sep;
22516
+ if (resolved.startsWith(rootWithSep)) return "/" + resolved.slice(rootWithSep.length).replace(/\\/g, "/");
22517
+ return vfsPath;
22518
+ }
22519
+ accessSync(vfsPath, mode) {
22520
+ const realPath = this.#resolvePath(vfsPath);
22521
+ fs.accessSync(realPath, mode);
22522
+ }
22523
+ async access(vfsPath, mode) {
22524
+ const realPath = this.#resolvePath(vfsPath);
22525
+ return fs.promises.access(realPath, mode);
22526
+ }
22527
+ copyFileSync(srcVfsPath, destVfsPath, mode) {
22528
+ const srcRealPath = this.#resolvePath(srcVfsPath);
22529
+ const destRealPath = this.#resolvePath(destVfsPath);
22530
+ fs.copyFileSync(srcRealPath, destRealPath, mode);
22531
+ }
22532
+ async copyFile(srcVfsPath, destVfsPath, mode) {
22533
+ const srcRealPath = this.#resolvePath(srcVfsPath);
22534
+ const destRealPath = this.#resolvePath(destVfsPath);
22535
+ return fs.promises.copyFile(srcRealPath, destRealPath, mode);
22536
+ }
22537
+ };
22538
+ module.exports = {
22539
+ RealFSProvider,
22540
+ RealFileHandle
22541
+ };
22542
+ }));
22543
+ //#endregion
22544
+ //#region ../../node_modules/.pnpm/@platformatic+vfs@0.4.0/node_modules/@platformatic/vfs/lib/providers/sqlite.js
22545
+ var require_sqlite = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
22546
+ const { Buffer: Buffer$1 } = __require("node:buffer");
22547
+ const { posix: pathPosix } = __require("node:path");
22548
+ const { DatabaseSync } = __require("node:sqlite");
22549
+ const { VirtualProvider } = require_provider();
22550
+ const { VirtualFileHandle } = require_file_handle();
22551
+ const { VFSWatcher, VFSStatWatcher, VFSWatchAsyncIterable } = require_watcher();
22552
+ const { createENOENT, createENOTDIR, createENOTEMPTY, createEISDIR, createEEXIST, createEINVAL, createELOOP, createEROFS } = require_errors();
22553
+ const { createFileStats, createDirectoryStats, createSymlinkStats } = require_stats();
22554
+ const UV_DIRENT_FILE = 1;
22555
+ const UV_DIRENT_DIR = 2;
22556
+ const UV_DIRENT_LINK = 3;
22557
+ var VirtualDirent = class {
22558
+ #name;
22559
+ #type;
22560
+ #parentPath;
22561
+ constructor(name, type, parentPath) {
22562
+ this.#name = name;
22563
+ this.#type = type;
22564
+ this.#parentPath = parentPath;
22565
+ }
22566
+ get name() {
22567
+ return this.#name;
22568
+ }
22569
+ get parentPath() {
22570
+ return this.#parentPath;
22571
+ }
22572
+ get path() {
22573
+ return this.#parentPath;
22574
+ }
22575
+ isFile() {
22576
+ return this.#type === UV_DIRENT_FILE;
22577
+ }
22578
+ isDirectory() {
22579
+ return this.#type === UV_DIRENT_DIR;
22580
+ }
22581
+ isSymbolicLink() {
22582
+ return this.#type === UV_DIRENT_LINK;
22583
+ }
22584
+ isBlockDevice() {
22585
+ return false;
22586
+ }
22587
+ isCharacterDevice() {
22588
+ return false;
22589
+ }
22590
+ isFIFO() {
22591
+ return false;
22592
+ }
22593
+ isSocket() {
22594
+ return false;
22595
+ }
22596
+ };
22597
+ const TYPE_FILE = 0;
22598
+ const TYPE_DIR = 1;
22599
+ const TYPE_SYMLINK = 2;
22600
+ const kMaxSymlinkDepth = 40;
22601
+ var SqliteFileHandle = class extends VirtualFileHandle {
22602
+ #content;
22603
+ #updateStmt;
22604
+ #path;
22605
+ #getStats;
22606
+ #checkClosed() {
22607
+ if (this.closed) {
22608
+ const { createEBADF } = require_errors();
22609
+ throw createEBADF("read");
22610
+ }
22611
+ }
22612
+ constructor(path, flags, mode, content, updateStmt, getStats) {
22613
+ super(path, flags, mode);
22614
+ this.#content = content;
22615
+ this.#updateStmt = updateStmt;
22616
+ this.#path = path;
22617
+ this.#getStats = getStats;
22618
+ if (flags === "w" || flags === "w+") {
22619
+ this.#content = Buffer$1.alloc(0);
22620
+ this.#flush();
22621
+ } else if (flags === "a" || flags === "a+") this.position = this.#content.length;
22622
+ }
22623
+ #flush() {
22624
+ const now = Date.now();
22625
+ this.#updateStmt.run(this.#content, now, this.#path);
22626
+ }
22627
+ get content() {
22628
+ return this.#content;
22629
+ }
22630
+ readSync(buffer, offset, length, position) {
22631
+ this.#checkClosed();
22632
+ const content = this.#content;
22633
+ const readPos = position !== null && position !== void 0 ? position : this.position;
22634
+ const available = content.length - readPos;
22635
+ if (available <= 0) return 0;
22636
+ const bytesToRead = Math.min(length, available);
22637
+ content.copy(buffer, offset, readPos, readPos + bytesToRead);
22638
+ if (position === null || position === void 0) this.position = readPos + bytesToRead;
22639
+ return bytesToRead;
22640
+ }
22641
+ async read(buffer, offset, length, position) {
22642
+ return {
22643
+ bytesRead: this.readSync(buffer, offset, length, position),
22644
+ buffer
22645
+ };
22646
+ }
22647
+ writeSync(buffer, offset, length, position) {
22648
+ this.#checkClosed();
22649
+ const writePos = position !== null && position !== void 0 ? position : this.position;
22650
+ const data = buffer.subarray(offset, offset + length);
22651
+ if (writePos + length > this.#content.length) {
22652
+ const newContent = Buffer$1.alloc(writePos + length);
22653
+ this.#content.copy(newContent, 0, 0, this.#content.length);
22654
+ this.#content = newContent;
22655
+ }
22656
+ data.copy(this.#content, writePos);
22657
+ this.#flush();
22658
+ if (position === null || position === void 0) this.position = writePos + length;
22659
+ return length;
22660
+ }
22661
+ async write(buffer, offset, length, position) {
22662
+ return {
22663
+ bytesWritten: this.writeSync(buffer, offset, length, position),
22664
+ buffer
22665
+ };
22666
+ }
22667
+ readFileSync(options) {
22668
+ this.#checkClosed();
22669
+ const content = this.#content;
22670
+ const encoding = typeof options === "string" ? options : options?.encoding;
22671
+ if (encoding) return content.toString(encoding);
22672
+ return Buffer$1.from(content);
22673
+ }
22674
+ async readFile(options) {
22675
+ return this.readFileSync(options);
22676
+ }
22677
+ writeFileSync(data, options) {
22678
+ this.#checkClosed();
22679
+ const buffer = typeof data === "string" ? Buffer$1.from(data, options?.encoding) : data;
22680
+ if (this.flags === "a" || this.flags === "a+") {
22681
+ const newContent = Buffer$1.alloc(this.#content.length + buffer.length);
22682
+ this.#content.copy(newContent, 0);
22683
+ buffer.copy(newContent, this.#content.length);
22684
+ this.#content = newContent;
22685
+ } else this.#content = Buffer$1.from(buffer);
22686
+ this.#flush();
22687
+ this.position = this.#content.length;
22688
+ }
22689
+ async writeFile(data, options) {
22690
+ this.writeFileSync(data, options);
22691
+ }
22692
+ statSync(options) {
22693
+ this.#checkClosed();
22694
+ if (this.#getStats) return this.#getStats(this.#content.length);
22695
+ const { ERR_INVALID_STATE } = require_errors();
22696
+ throw new ERR_INVALID_STATE("stats not available");
22697
+ }
22698
+ async stat(options) {
22699
+ return this.statSync(options);
22700
+ }
22701
+ truncateSync(len = 0) {
22702
+ this.#checkClosed();
22703
+ if (len < this.#content.length) this.#content = this.#content.subarray(0, len);
22704
+ else if (len > this.#content.length) {
22705
+ const newContent = Buffer$1.alloc(len);
22706
+ this.#content.copy(newContent, 0, 0, this.#content.length);
22707
+ this.#content = newContent;
22708
+ }
22709
+ this.#flush();
22710
+ }
22711
+ async truncate(len) {
22712
+ this.truncateSync(len);
22713
+ }
22714
+ };
22715
+ var SqliteProvider = class extends VirtualProvider {
22716
+ #db;
22717
+ #readonly;
22718
+ #statWatchers;
22719
+ #stmtGet;
22720
+ #stmtInsert;
22721
+ #stmtUpdateContent;
22722
+ #stmtDelete;
22723
+ #stmtChildren;
22724
+ #stmtDescendants;
22725
+ constructor(pathOrMemory) {
22726
+ super();
22727
+ this.#readonly = false;
22728
+ this.#statWatchers = /* @__PURE__ */ new Map();
22729
+ this.#db = new DatabaseSync(pathOrMemory ?? ":memory:");
22730
+ this.#db.exec(`
22731
+ CREATE TABLE IF NOT EXISTS entries (
22732
+ path TEXT PRIMARY KEY,
22733
+ parent_path TEXT,
22734
+ name TEXT,
22735
+ type INTEGER NOT NULL,
22736
+ content BLOB,
22737
+ target TEXT,
22738
+ mode INTEGER NOT NULL,
22739
+ mtime REAL NOT NULL,
22740
+ ctime REAL NOT NULL,
22741
+ birthtime REAL NOT NULL
22742
+ );
22743
+ CREATE INDEX IF NOT EXISTS idx_parent ON entries(parent_path);
22744
+ `);
22745
+ if (!this.#db.prepare("SELECT path FROM entries WHERE path = ?").get("/")) {
22746
+ const now = Date.now();
22747
+ this.#db.prepare("INSERT INTO entries (path, parent_path, name, type, content, target, mode, mtime, ctime, birthtime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").run("/", null, "", TYPE_DIR, null, null, 493, now, now, now);
22748
+ }
22749
+ this.#stmtGet = this.#db.prepare("SELECT * FROM entries WHERE path = ?");
22750
+ this.#stmtInsert = this.#db.prepare("INSERT INTO entries (path, parent_path, name, type, content, target, mode, mtime, ctime, birthtime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
22751
+ this.#stmtUpdateContent = this.#db.prepare("UPDATE entries SET content=?, mtime=? WHERE path=?");
22752
+ this.#stmtDelete = this.#db.prepare("DELETE FROM entries WHERE path = ?");
22753
+ this.#stmtChildren = this.#db.prepare("SELECT * FROM entries WHERE parent_path = ?");
22754
+ this.#stmtDescendants = this.#db.prepare("SELECT * FROM entries WHERE path LIKE ? AND path != ?");
22755
+ }
22756
+ get readonly() {
22757
+ return this.#readonly;
22758
+ }
22759
+ get supportsWatch() {
22760
+ return true;
22761
+ }
22762
+ get supportsSymlinks() {
22763
+ return true;
22764
+ }
22765
+ setReadOnly() {
22766
+ this.#readonly = true;
22767
+ }
22768
+ close() {
22769
+ for (const watcher of this.#statWatchers.values()) watcher.stop();
22770
+ this.#statWatchers.clear();
22771
+ this.#db.close();
22772
+ }
22773
+ #normalizePath(path) {
22774
+ let normalized = path.replace(/\\/g, "/");
22775
+ if (!normalized.startsWith("/")) normalized = "/" + normalized;
22776
+ return pathPosix.normalize(normalized);
22777
+ }
22778
+ #getParentPath(path) {
22779
+ if (path === "/") return null;
22780
+ return pathPosix.dirname(path);
22781
+ }
22782
+ #getBaseName(path) {
22783
+ return pathPosix.basename(path);
22784
+ }
22785
+ #resolveSymlinkTarget(symlinkPath, target) {
22786
+ if (target.startsWith("/")) return this.#normalizePath(target);
22787
+ const parentPath = this.#getParentPath(symlinkPath) || "/";
22788
+ return this.#normalizePath(pathPosix.join(parentPath, target));
22789
+ }
22790
+ #getRow(path) {
22791
+ return this.#stmtGet.get(path);
22792
+ }
22793
+ #lookupEntry(path, followSymlinks = true, depth = 0) {
22794
+ const normalized = this.#normalizePath(path);
22795
+ if (normalized === "/") return {
22796
+ row: this.#getRow("/"),
22797
+ resolvedPath: "/"
22798
+ };
22799
+ const segments = normalized.slice(1).split("/");
22800
+ let currentPath = "/";
22801
+ for (let i = 0; i < segments.length; i++) {
22802
+ const segment = segments[i];
22803
+ const nextPath = currentPath === "/" ? "/" + segment : currentPath + "/" + segment;
22804
+ const currentRow = this.#getRow(currentPath);
22805
+ if (!currentRow) return {
22806
+ row: null,
22807
+ resolvedPath: null
22808
+ };
22809
+ if (currentRow.type === TYPE_SYMLINK) {
22810
+ if (depth >= kMaxSymlinkDepth) return {
22811
+ row: null,
22812
+ resolvedPath: null,
22813
+ eloop: true
22814
+ };
22815
+ const targetPath = this.#resolveSymlinkTarget(currentPath, currentRow.target);
22816
+ const result = this.#lookupEntry(targetPath, true, depth + 1);
22817
+ if (result.eloop) return result;
22818
+ if (!result.row) return {
22819
+ row: null,
22820
+ resolvedPath: null
22821
+ };
22822
+ const remaining = segments.slice(i).join("/");
22823
+ const fullPath = result.resolvedPath === "/" ? "/" + remaining : result.resolvedPath + "/" + remaining;
22824
+ return this.#lookupEntry(fullPath, followSymlinks, depth + 1);
22825
+ }
22826
+ if (currentRow.type !== TYPE_DIR) return {
22827
+ row: null,
22828
+ resolvedPath: null
22829
+ };
22830
+ currentPath = nextPath;
22831
+ }
22832
+ const row = this.#getRow(currentPath);
22833
+ if (!row) return {
22834
+ row: null,
22835
+ resolvedPath: null
22836
+ };
22837
+ if (row.type === TYPE_SYMLINK && followSymlinks) {
22838
+ if (depth >= kMaxSymlinkDepth) return {
22839
+ row: null,
22840
+ resolvedPath: null,
22841
+ eloop: true
22842
+ };
22843
+ const targetPath = this.#resolveSymlinkTarget(currentPath, row.target);
22844
+ return this.#lookupEntry(targetPath, true, depth + 1);
22845
+ }
22846
+ return {
22847
+ row,
22848
+ resolvedPath: currentPath
22849
+ };
22850
+ }
22851
+ #getEntry(path, syscall, followSymlinks = true) {
22852
+ const result = this.#lookupEntry(path, followSymlinks);
22853
+ if (result.eloop) throw createELOOP(syscall, path);
22854
+ if (!result.row) throw createENOENT(syscall, path);
22855
+ return result.row;
22856
+ }
22857
+ #ensureParent(path, create, syscall) {
22858
+ const parentPath = this.#getParentPath(path);
22859
+ if (parentPath === null) return this.#getRow("/");
22860
+ const result = this.#lookupEntry(parentPath, true);
22861
+ if (result.row) {
22862
+ if (result.row.type !== TYPE_DIR) throw createENOTDIR(syscall, path);
22863
+ return result.row;
22864
+ }
22865
+ if (create) {
22866
+ const segments = parentPath.slice(1).split("/");
22867
+ let currentPath = "";
22868
+ for (const segment of segments) {
22869
+ currentPath += "/" + segment;
22870
+ const existing = this.#getRow(currentPath);
22871
+ if (!existing) {
22872
+ const now = Date.now();
22873
+ const pp = this.#getParentPath(currentPath);
22874
+ this.#stmtInsert.run(currentPath, pp, segment, TYPE_DIR, null, null, 493, now, now, now);
22875
+ } else if (existing.type !== TYPE_DIR) throw createENOTDIR(syscall, path);
22876
+ }
22877
+ return this.#getRow(parentPath);
22878
+ }
22879
+ throw createENOENT(syscall, path);
22880
+ }
22881
+ #createStats(row, size) {
22882
+ const options = {
22883
+ mode: row.mode,
22884
+ mtimeMs: row.mtime,
22885
+ ctimeMs: row.ctime,
22886
+ birthtimeMs: row.birthtime
22887
+ };
22888
+ if (row.type === TYPE_FILE) {
22889
+ const content = row.content;
22890
+ return createFileStats(size !== void 0 ? size : content ? content.byteLength : 0, options);
22891
+ } else if (row.type === TYPE_DIR) return createDirectoryStats(options);
22892
+ else if (row.type === TYPE_SYMLINK) return createSymlinkStats(row.target.length, options);
22893
+ const { ERR_INVALID_STATE } = require_errors();
22894
+ throw new ERR_INVALID_STATE("Unknown entry type");
22895
+ }
22896
+ openSync(path, flags, mode) {
22897
+ const normalized = this.#normalizePath(path);
22898
+ const isCreate = flags === "w" || flags === "w+" || flags === "a" || flags === "a+";
22899
+ if (this.readonly && isCreate) throw createEROFS("open", path);
22900
+ let row;
22901
+ try {
22902
+ row = this.#getEntry(normalized, "open");
22903
+ } catch (err) {
22904
+ if (err.code === "ENOENT" && isCreate) {
22905
+ this.#ensureParent(normalized, true, "open");
22906
+ const name = this.#getBaseName(normalized);
22907
+ const parentPath = this.#getParentPath(normalized);
22908
+ const now = Date.now();
22909
+ const fileMode = mode ?? 420;
22910
+ this.#stmtInsert.run(normalized, parentPath, name, TYPE_FILE, Buffer$1.alloc(0), null, fileMode, now, now, now);
22911
+ row = this.#getRow(normalized);
22912
+ } else throw err;
22913
+ }
22914
+ if (row.type === TYPE_DIR) throw createEISDIR("open", path);
22915
+ if (row.type === TYPE_SYMLINK) throw createEINVAL("open", path);
22916
+ const content = row.content ? Buffer$1.from(row.content) : Buffer$1.alloc(0);
22917
+ const getStats = (size) => this.#createStats(this.#getRow(normalized) || row, size);
22918
+ return new SqliteFileHandle(normalized, flags, mode ?? row.mode, content, this.#stmtUpdateContent, getStats);
22919
+ }
22920
+ async open(path, flags, mode) {
22921
+ return this.openSync(path, flags, mode);
22922
+ }
22923
+ statSync(path, options) {
22924
+ const row = this.#getEntry(path, "stat", true);
22925
+ return this.#createStats(row);
22926
+ }
22927
+ async stat(path, options) {
22928
+ return this.statSync(path, options);
22929
+ }
22930
+ lstatSync(path, options) {
22931
+ const row = this.#getEntry(path, "lstat", false);
22932
+ return this.#createStats(row);
22933
+ }
22934
+ async lstat(path, options) {
22935
+ return this.lstatSync(path, options);
22936
+ }
22937
+ readdirSync(path, options) {
22938
+ const result = this.#lookupEntry(path, true);
22939
+ if (result.eloop) throw createELOOP("scandir", path);
22940
+ if (!result.row) throw createENOENT("scandir", path);
22941
+ if (result.row.type !== TYPE_DIR) throw createENOTDIR("scandir", path);
22942
+ const children = this.#stmtChildren.all(result.resolvedPath);
22943
+ if (options?.withFileTypes) {
22944
+ const normalized = this.#normalizePath(path);
22945
+ return children.map((child) => {
22946
+ let type;
22947
+ if (child.type === TYPE_SYMLINK) type = UV_DIRENT_LINK;
22948
+ else if (child.type === TYPE_DIR) type = UV_DIRENT_DIR;
22949
+ else type = UV_DIRENT_FILE;
22950
+ return new VirtualDirent(child.name, type, normalized);
22951
+ });
22952
+ }
22953
+ return children.map((child) => child.name);
22954
+ }
22955
+ async readdir(path, options) {
22956
+ return this.readdirSync(path, options);
22957
+ }
22958
+ mkdirSync(path, options) {
22959
+ if (this.readonly) throw createEROFS("mkdir", path);
22960
+ const normalized = this.#normalizePath(path);
22961
+ const recursive = options?.recursive === true;
22962
+ const existing = this.#lookupEntry(normalized, true);
22963
+ if (existing.row) {
22964
+ if (existing.row.type === TYPE_DIR && recursive) return;
22965
+ throw createEEXIST("mkdir", path);
22966
+ }
22967
+ if (recursive) {
22968
+ const segments = normalized.slice(1).split("/");
22969
+ let currentPath = "";
22970
+ for (const segment of segments) {
22971
+ currentPath += "/" + segment;
22972
+ const row = this.#getRow(currentPath);
22973
+ if (!row) {
22974
+ const now = Date.now();
22975
+ const pp = this.#getParentPath(currentPath);
22976
+ this.#stmtInsert.run(currentPath, pp, segment, TYPE_DIR, null, null, options?.mode ?? 493, now, now, now);
22977
+ } else if (row.type !== TYPE_DIR) throw createENOTDIR("mkdir", path);
22978
+ }
22979
+ } else {
22980
+ this.#ensureParent(normalized, false, "mkdir");
22981
+ const name = this.#getBaseName(normalized);
22982
+ const parentPath = this.#getParentPath(normalized);
22983
+ const now = Date.now();
22984
+ this.#stmtInsert.run(normalized, parentPath, name, TYPE_DIR, null, null, options?.mode ?? 493, now, now, now);
22985
+ }
22986
+ return recursive ? normalized : void 0;
22987
+ }
22988
+ async mkdir(path, options) {
22989
+ return this.mkdirSync(path, options);
22990
+ }
22991
+ rmdirSync(path) {
22992
+ if (this.readonly) throw createEROFS("rmdir", path);
22993
+ const normalized = this.#normalizePath(path);
22994
+ if (this.#getEntry(normalized, "rmdir", true).type !== TYPE_DIR) throw createENOTDIR("rmdir", path);
22995
+ if (this.#stmtChildren.all(normalized).length > 0) throw createENOTEMPTY("rmdir", path);
22996
+ this.#stmtDelete.run(normalized);
22997
+ }
22998
+ async rmdir(path) {
22999
+ this.rmdirSync(path);
23000
+ }
23001
+ unlinkSync(path) {
23002
+ if (this.readonly) throw createEROFS("unlink", path);
23003
+ const normalized = this.#normalizePath(path);
23004
+ if (this.#getEntry(normalized, "unlink", false).type === TYPE_DIR) throw createEISDIR("unlink", path);
23005
+ this.#stmtDelete.run(normalized);
23006
+ }
23007
+ async unlink(path) {
23008
+ this.unlinkSync(path);
23009
+ }
23010
+ renameSync(oldPath, newPath) {
23011
+ if (this.readonly) throw createEROFS("rename", oldPath);
23012
+ const normalizedOld = this.#normalizePath(oldPath);
23013
+ const normalizedNew = this.#normalizePath(newPath);
23014
+ const row = this.#getEntry(normalizedOld, "rename", false);
23015
+ this.#ensureParent(normalizedNew, true, "rename");
23016
+ const newName = this.#getBaseName(normalizedNew);
23017
+ const newParentPath = this.#getParentPath(normalizedNew);
23018
+ if (row.type === TYPE_DIR) {
23019
+ this.#db.exec("BEGIN");
23020
+ try {
23021
+ this.#stmtDelete.run(normalizedOld);
23022
+ const now = Date.now();
23023
+ this.#stmtDelete.run(normalizedNew);
23024
+ this.#stmtInsert.run(normalizedNew, newParentPath, newName, row.type, row.content, row.target, row.mode, now, row.ctime, row.birthtime);
23025
+ const prefix = normalizedOld + "/";
23026
+ const descendants = this.#stmtDescendants.all(prefix + "%", normalizedOld);
23027
+ for (const desc of descendants) {
23028
+ const newDescPath = normalizedNew + desc.path.slice(normalizedOld.length);
23029
+ const newDescParent = this.#getParentPath(newDescPath);
23030
+ const descName = this.#getBaseName(newDescPath);
23031
+ this.#stmtDelete.run(desc.path);
23032
+ this.#stmtInsert.run(newDescPath, newDescParent, descName, desc.type, desc.content, desc.target, desc.mode, desc.mtime, desc.ctime, desc.birthtime);
23033
+ }
23034
+ this.#db.exec("COMMIT");
23035
+ } catch (err) {
23036
+ this.#db.exec("ROLLBACK");
23037
+ throw err;
23038
+ }
23039
+ } else {
23040
+ this.#stmtDelete.run(normalizedOld);
23041
+ const now = Date.now();
23042
+ this.#stmtDelete.run(normalizedNew);
23043
+ this.#stmtInsert.run(normalizedNew, newParentPath, newName, row.type, row.content, row.target, row.mode, now, row.ctime, row.birthtime);
23044
+ }
23045
+ }
23046
+ async rename(oldPath, newPath) {
23047
+ this.renameSync(oldPath, newPath);
23048
+ }
23049
+ readlinkSync(path, options) {
23050
+ const normalized = this.#normalizePath(path);
23051
+ const row = this.#getEntry(normalized, "readlink", false);
23052
+ if (row.type !== TYPE_SYMLINK) throw createEINVAL("readlink", path);
23053
+ return row.target;
23054
+ }
23055
+ async readlink(path, options) {
23056
+ return this.readlinkSync(path, options);
23057
+ }
23058
+ symlinkSync(target, path, type) {
23059
+ if (this.readonly) throw createEROFS("symlink", path);
23060
+ const normalized = this.#normalizePath(path);
23061
+ if (this.#lookupEntry(normalized, false).row) throw createEEXIST("symlink", path);
23062
+ this.#ensureParent(normalized, true, "symlink");
23063
+ const name = this.#getBaseName(normalized);
23064
+ const parentPath = this.#getParentPath(normalized);
23065
+ const now = Date.now();
23066
+ this.#stmtInsert.run(normalized, parentPath, name, TYPE_SYMLINK, null, target, 511, now, now, now);
23067
+ }
23068
+ async symlink(target, path, type) {
23069
+ this.symlinkSync(target, path, type);
23070
+ }
23071
+ realpathSync(path, options) {
23072
+ const result = this.#lookupEntry(path, true, 0);
23073
+ if (result.eloop) throw createELOOP("realpath", path);
23074
+ if (!result.row) throw createENOENT("realpath", path);
23075
+ return result.resolvedPath;
23076
+ }
23077
+ async realpath(path, options) {
23078
+ return this.realpathSync(path, options);
23079
+ }
23080
+ watch(path, options) {
23081
+ const normalized = this.#normalizePath(path);
23082
+ return new VFSWatcher(this, normalized, options);
23083
+ }
23084
+ watchAsync(path, options) {
23085
+ const normalized = this.#normalizePath(path);
23086
+ return new VFSWatchAsyncIterable(this, normalized, options);
23087
+ }
23088
+ watchFile(path, options, listener) {
23089
+ const normalized = this.#normalizePath(path);
23090
+ let watcher = this.#statWatchers.get(normalized);
23091
+ if (!watcher) {
23092
+ watcher = new VFSStatWatcher(this, normalized, options);
23093
+ this.#statWatchers.set(normalized, watcher);
23094
+ }
23095
+ if (listener) watcher.addListener(listener);
23096
+ return watcher;
23097
+ }
23098
+ unwatchFile(path, listener) {
23099
+ const normalized = this.#normalizePath(path);
23100
+ const watcher = this.#statWatchers.get(normalized);
23101
+ if (!watcher) return;
23102
+ if (listener) watcher.removeListener(listener);
23103
+ else watcher.removeAllListeners("change");
23104
+ if (watcher.hasNoListeners()) {
23105
+ watcher.stop();
23106
+ this.#statWatchers.delete(normalized);
23107
+ }
23108
+ }
23109
+ };
23110
+ module.exports = { SqliteProvider };
23111
+ }));
23112
+ //#endregion
23113
+ //#region src/services/vfs/createPlatformaticFsProvider.ts
23114
+ var import_vfs = (/* @__PURE__ */ __commonJSMin$1(((exports, module) => {
23115
+ const { VirtualFileSystem } = require_file_system();
23116
+ const { VirtualProvider } = require_provider();
23117
+ const { MemoryProvider } = require_memory();
23118
+ const { RealFSProvider } = require_real();
23119
+ const { SqliteProvider } = require_sqlite();
23120
+ /**
23121
+ * Creates a new VirtualFileSystem instance.
23122
+ * @param {VirtualProvider} [provider] The provider to use (defaults to MemoryProvider)
23123
+ * @param {object} [options] Configuration options
23124
+ * @param {boolean} [options.moduleHooks] Whether to enable require/import hooks (default: true)
23125
+ * @param {boolean} [options.virtualCwd] Whether to enable virtual working directory
23126
+ * @param {boolean} [options.overlay] Whether to enable overlay mode
23127
+ * @returns {VirtualFileSystem}
23128
+ */
23129
+ function create(provider, options) {
23130
+ if (provider != null && !(provider instanceof VirtualProvider) && typeof provider === "object") {
23131
+ options = provider;
23132
+ provider = void 0;
23133
+ }
23134
+ return new VirtualFileSystem(provider, options);
23135
+ }
23136
+ module.exports = {
23137
+ create,
23138
+ VirtualFileSystem,
23139
+ VirtualProvider,
23140
+ MemoryProvider,
23141
+ RealFSProvider,
23142
+ SqliteProvider
23143
+ };
23144
+ })))();
23145
+ const createPlatformaticFsProvider = ({ isOverlayEnabled = false } = {}) => {
23146
+ const vfs = (0, import_vfs.create)({
23147
+ moduleHooks: true,
23148
+ overlay: isOverlayEnabled
23149
+ });
23150
+ return {
23151
+ dispose: () => {
23152
+ if (vfs.mounted) vfs.unmount();
23153
+ },
23154
+ exists: (path) => vfs.existsSync(path),
23155
+ mkdir: (path) => {
23156
+ vfs.mkdirSync(path, { recursive: true });
23157
+ },
23158
+ mount: (prefix) => {
23159
+ vfs.mount(prefix);
23160
+ },
23161
+ name: "platformatic",
23162
+ readFile: (path) => vfs.readFileSync(path, "utf8"),
23163
+ unmount: () => {
23164
+ vfs.unmount();
23165
+ },
23166
+ writeFile: (path, data) => {
23167
+ vfs.writeFileSync(path, data);
18844
23168
  }
18845
23169
  };
18846
23170
  };
18847
23171
  //#endregion
18848
- //#region src/services/exec/runNodeInProcess.ts
23172
+ //#region src/services/exec/vfs/runNodeInProcess.ts
18849
23173
  const runNodeInProcess = ({ code, file }, { cwd, stdio }) => {
18850
23174
  const originalStdoutWrite = process$1.stdout.write.bind(process$1.stdout);
18851
23175
  const originalStderrWrite = process$1.stderr.write.bind(process$1.stderr);
@@ -18854,7 +23178,7 @@ const runNodeInProcess = ({ code, file }, { cwd, stdio }) => {
18854
23178
  const originalRequire = globalThis.require;
18855
23179
  const originalCwd = cwd === "" ? "" : process$1.cwd();
18856
23180
  const baseDir = cwd === "" ? process$1.cwd() : cwd;
18857
- const fs = createPlatformaticFsProvider({ overlay: true });
23181
+ const fs = createPlatformaticFsProvider({ isOverlayEnabled: true });
18858
23182
  const isPipe = stdio === "pipe";
18859
23183
  const require = createRequire(resolve(baseDir, "[eval].js"));
18860
23184
  const cachedBefore = new Set(Object.keys(require.cache));
@@ -18899,7 +23223,7 @@ const runNodeInProcess = ({ code, file }, { cwd, stdio }) => {
18899
23223
  });
18900
23224
  };
18901
23225
  //#endregion
18902
- //#region src/services/exec/createVfsBackend.ts
23226
+ //#region src/services/exec/vfs/createVfsBackend.ts
18903
23227
  const createVfsBackend = () => {
18904
23228
  const native = createNativeBackend();
18905
23229
  return {
@@ -18921,7 +23245,7 @@ const loadDirSource = (source) => Promise.resolve({
18921
23245
  //#endregion
18922
23246
  //#region src/services/source/loadFilesSource.ts
18923
23247
  const loadFilesSource = async (source) => {
18924
- const cwd = await mkdtemp(join(tmpdir(), "sandbox-"));
23248
+ const cwd = await mkdtemp(join(tmpdir(), VIRRUN_TEMP_DIR_PREFIX));
18925
23249
  const dispose = () => rm(cwd, {
18926
23250
  force: true,
18927
23251
  recursive: true
@@ -18999,21 +23323,28 @@ const backendFactories = {
18999
23323
  ["os"]: createOsBackend,
19000
23324
  ["vfs"]: createVfsBackend
19001
23325
  };
19002
- const createVirrun = async (options = {}) => {
19003
- const { backend = "auto", source = {
19004
- dir: "",
19005
- type: "dir"
19006
- } } = options;
23326
+ const createVirrun = async ({ backend = "auto", source = {
23327
+ dir: "",
23328
+ type: "dir"
23329
+ } } = {}) => {
19007
23330
  const execBackend = backendFactories[backend]();
19008
23331
  const { cwd, dispose } = await loadSource(source);
23332
+ const sharedPackageStoreOptions = execBackend.name === "os" ? createSharedPackageStoreOptions(cwd) : {};
23333
+ const toOptions = (stdio) => ({
23334
+ ...sharedPackageStoreOptions,
23335
+ cwd,
23336
+ stdio
23337
+ });
19009
23338
  return {
19010
23339
  backend: execBackend.name,
19011
23340
  dispose,
19012
- exec: (command, stdio = "pipe") => execBackend.exec(command, {
19013
- cwd,
19014
- stdio
19015
- })
23341
+ exec: (command, stdio = "pipe") => execBackend.exec(command, toOptions(stdio)),
23342
+ fork: async (command, stdio = "pipe") => {
23343
+ if (execBackend.name !== "os") return execBackend.exec(command, toOptions(stdio));
23344
+ if (!resolveSnapshotLocation(cwd).exists) await createSnapshot(execBackend, command, toOptions(stdio));
23345
+ return forkSnapshot(execBackend, command, toOptions(stdio));
23346
+ }
19016
23347
  };
19017
23348
  };
19018
23349
  //#endregion
19019
- export { createNativeBackend as _, loadDirSource as a, SourceType as b, createPlatformaticFsProvider as c, tokenizeShellCommand as d, createOsBackend as f, buildBwrapArgs as g, withFinalizerAsync as h, loadFilesSource as i, ExitSignalError as l, isOsBackendSupported as m, loadSource as n, createVfsBackend as o, parseBwrapExitCode as p, loadGitSource as r, runNodeInProcess as s, createVirrun as t, parseNodeInvocation as u, toExitCode as v, BackendType as y };
23350
+ export { VIRRUN_SNAPSHOT_WORK_DIRECTORY_NAME as $, parseBwrapExitCode as A, GITIGNORE_FILENAME as B, createWslBwrapArgs as C, parseBwrapStderrStatus as D, createBwrapBackend as E, resolveCwd as F, VIRRUN_CACHE_DIRECTORY_NAME as G, PNPM_CONFIG_PACKAGE_IMPORT_METHOD_VALUE as H, parseVirrunConfiguration as I, VIRRUN_COREPACK_STORE_DIRECTORY_NAME as J, VIRRUN_CACHE_HOME_KEY as K, resolveCommandBackend as L, toExitCode as M, SourceType as N, WSL_BWRAP_STATUS_BEGIN as O, resolveVirrunConfiguration as P, VIRRUN_SNAPSHOT_UPPER_DIRECTORY_NAME as Q, isOsBackendSupported as R, createWslEnvArgs as S, createLinuxOsBackend as T, PNPM_CONFIG_STORE_DIR_KEY as U, PNPM_CONFIG_PACKAGE_IMPORT_METHOD_KEY as V, PNPM_LOCKFILE_FILENAME as W, VIRRUN_PNPM_STORE_DIRECTORY_NAME as X, VIRRUN_GITIGNORE_ENTRY as Y, VIRRUN_SNAPSHOTS_DIRECTORY_NAME as Z, getGlobalCacheDirectory as _, loadDirSource as a, BackendType as at, createOsBackend as b, createPlatformaticFsProvider as c, tokenizeShellCommand as d, VIRRUN_STORE_DIRECTORY_NAME as et, createSharedPackageStoreOptions as f, resolveSnapshotLocation as g, createSnapshot as h, loadFilesSource as i, matchesRoute as it, createNativeBackend as j, WSL_BWRAP_STATUS_END as k, ExitSignalError as l, forkSnapshot as m, loadSource as n, buildBwrapArgs as nt, createVfsBackend as o, parseCliCommand as ot, getRepoCacheDirectory as p, VIRRUN_CONFIGURATION_FILENAME as q, loadGitSource as r, withFinalizerAsync as rt, runNodeInProcess as s, createVirrun as t, VIRRUN_TEMP_DIR_PREFIX as tt, parseNodeInvocation as u, computeLockfileHash as v, readWslPath as w, createWslOsBackend as x, removeSnapshotLocation as y, COREPACK_HOME_KEY as z };