@powerlines/plugin-webpack 0.5.132 → 0.5.134

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 (130) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  2. package/dist/helpers/index.cjs +2 -3
  3. package/dist/helpers/index.d.cts +1 -3
  4. package/dist/helpers/index.d.mts +1 -3
  5. package/dist/helpers/index.mjs +1 -2
  6. package/dist/helpers/unplugin.cjs +11 -2
  7. package/dist/helpers/unplugin.d.cts +6 -2
  8. package/dist/helpers/unplugin.d.mts +6 -2
  9. package/dist/helpers/unplugin.mjs +9 -1
  10. package/dist/index.cjs +8 -50
  11. package/dist/index.d.cts +3 -4
  12. package/dist/index.d.mts +5 -5
  13. package/dist/index.mjs +3 -46
  14. package/dist/powerlines/schemas/fs.cjs +226 -0
  15. package/dist/powerlines/schemas/fs.mjs +224 -0
  16. package/dist/powerlines/src/api.cjs +580 -0
  17. package/dist/powerlines/src/api.mjs +578 -0
  18. package/dist/powerlines/src/internal/babel/module-resolver-plugin.cjs +86 -0
  19. package/dist/powerlines/src/internal/babel/module-resolver-plugin.mjs +84 -0
  20. package/dist/powerlines/src/internal/helpers/environment.cjs +52 -0
  21. package/dist/powerlines/src/internal/helpers/environment.mjs +48 -0
  22. package/dist/powerlines/src/internal/helpers/generate-types.cjs +51 -0
  23. package/dist/powerlines/src/internal/helpers/generate-types.mjs +49 -0
  24. package/dist/powerlines/src/internal/helpers/hooks.cjs +63 -0
  25. package/dist/powerlines/src/internal/helpers/hooks.mjs +61 -0
  26. package/dist/powerlines/src/internal/helpers/install-dependencies.cjs +25 -0
  27. package/dist/powerlines/src/internal/helpers/install-dependencies.mjs +24 -0
  28. package/dist/powerlines/src/internal/helpers/install.cjs +37 -0
  29. package/dist/powerlines/src/internal/helpers/install.mjs +36 -0
  30. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.cjs +98 -0
  31. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.mjs +94 -0
  32. package/dist/powerlines/src/internal/helpers/resolver.cjs +43 -0
  33. package/dist/powerlines/src/internal/helpers/resolver.mjs +41 -0
  34. package/dist/powerlines/src/lib/build/webpack.cjs +47 -0
  35. package/dist/powerlines/src/lib/build/webpack.mjs +45 -0
  36. package/dist/powerlines/src/lib/config-file.cjs +79 -0
  37. package/dist/powerlines/src/lib/config-file.mjs +76 -0
  38. package/dist/powerlines/src/lib/contexts/api-context.cjs +184 -0
  39. package/dist/powerlines/src/lib/contexts/api-context.mjs +182 -0
  40. package/dist/powerlines/src/lib/contexts/context.cjs +933 -0
  41. package/dist/powerlines/src/lib/contexts/context.mjs +931 -0
  42. package/dist/powerlines/src/lib/contexts/environment-context.cjs +160 -0
  43. package/dist/powerlines/src/lib/contexts/environment-context.mjs +159 -0
  44. package/dist/powerlines/src/lib/contexts/plugin-context.cjs +75 -0
  45. package/dist/powerlines/src/lib/contexts/plugin-context.mjs +74 -0
  46. package/dist/powerlines/src/lib/entry.cjs +69 -0
  47. package/dist/powerlines/src/lib/entry.mjs +67 -0
  48. package/dist/powerlines/src/lib/fs/helpers.cjs +85 -0
  49. package/dist/powerlines/src/lib/fs/helpers.mjs +81 -0
  50. package/dist/powerlines/src/lib/fs/storage/base.cjs +196 -0
  51. package/dist/powerlines/src/lib/fs/storage/base.mjs +195 -0
  52. package/dist/powerlines/src/lib/fs/storage/file-system.cjs +170 -0
  53. package/dist/powerlines/src/lib/fs/storage/file-system.mjs +169 -0
  54. package/dist/powerlines/src/lib/fs/storage/virtual.cjs +88 -0
  55. package/dist/powerlines/src/lib/fs/storage/virtual.mjs +87 -0
  56. package/dist/powerlines/src/lib/fs/vfs.cjs +830 -0
  57. package/dist/powerlines/src/lib/fs/vfs.mjs +828 -0
  58. package/dist/powerlines/src/lib/logger.cjs +58 -0
  59. package/dist/powerlines/src/lib/logger.mjs +55 -0
  60. package/dist/powerlines/src/lib/typescript/ts-morph.cjs +104 -0
  61. package/dist/powerlines/src/lib/typescript/ts-morph.mjs +102 -0
  62. package/dist/powerlines/src/lib/typescript/tsconfig.cjs +149 -0
  63. package/dist/powerlines/src/lib/typescript/tsconfig.mjs +144 -0
  64. package/dist/powerlines/src/lib/unplugin/factory.cjs +6 -0
  65. package/dist/powerlines/src/lib/unplugin/factory.mjs +8 -0
  66. package/dist/powerlines/src/lib/unplugin/helpers.cjs +17 -0
  67. package/dist/powerlines/src/lib/unplugin/helpers.mjs +16 -0
  68. package/dist/powerlines/src/lib/unplugin/index.cjs +3 -0
  69. package/dist/powerlines/src/lib/unplugin/index.mjs +5 -0
  70. package/dist/powerlines/src/lib/unplugin/plugin.cjs +128 -0
  71. package/dist/powerlines/src/lib/unplugin/plugin.mjs +127 -0
  72. package/dist/powerlines/src/lib/utilities/file-header.cjs +22 -0
  73. package/dist/powerlines/src/lib/utilities/file-header.mjs +21 -0
  74. package/dist/powerlines/src/lib/utilities/meta.cjs +45 -0
  75. package/dist/powerlines/src/lib/utilities/meta.mjs +41 -0
  76. package/dist/powerlines/src/lib/utilities/source-file.cjs +22 -0
  77. package/dist/powerlines/src/lib/utilities/source-file.mjs +21 -0
  78. package/dist/powerlines/src/plugin-utils/helpers.cjs +148 -0
  79. package/dist/powerlines/src/plugin-utils/helpers.mjs +138 -0
  80. package/dist/powerlines/src/plugin-utils/paths.cjs +36 -0
  81. package/dist/powerlines/src/plugin-utils/paths.mjs +35 -0
  82. package/dist/powerlines/src/types/babel.d.mts +4 -0
  83. package/dist/powerlines/src/types/build.cjs +15 -0
  84. package/dist/powerlines/src/types/build.d.cts +149 -0
  85. package/dist/powerlines/src/types/build.d.mts +149 -0
  86. package/dist/powerlines/src/types/build.mjs +14 -0
  87. package/dist/powerlines/src/types/commands.cjs +16 -0
  88. package/dist/powerlines/src/types/commands.d.cts +8 -0
  89. package/dist/powerlines/src/types/commands.d.mts +9 -0
  90. package/dist/powerlines/src/types/commands.mjs +15 -0
  91. package/dist/powerlines/src/types/config.d.cts +377 -0
  92. package/dist/powerlines/src/types/config.d.mts +379 -0
  93. package/dist/powerlines/src/types/context.d.cts +403 -0
  94. package/dist/powerlines/src/types/context.d.mts +405 -0
  95. package/dist/powerlines/src/types/fs.d.cts +486 -0
  96. package/dist/powerlines/src/types/fs.d.mts +486 -0
  97. package/dist/powerlines/src/types/hooks.d.mts +2 -0
  98. package/dist/powerlines/src/types/plugin.cjs +32 -0
  99. package/dist/powerlines/src/types/plugin.d.cts +231 -0
  100. package/dist/powerlines/src/types/plugin.d.mts +231 -0
  101. package/dist/powerlines/src/types/plugin.mjs +31 -0
  102. package/dist/powerlines/src/types/resolved.d.cts +82 -0
  103. package/dist/powerlines/src/types/resolved.d.mts +83 -0
  104. package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
  105. package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
  106. package/dist/types/index.cjs +0 -2
  107. package/dist/types/index.d.cts +1 -2
  108. package/dist/types/index.d.mts +1 -2
  109. package/dist/types/index.mjs +0 -3
  110. package/dist/types/plugin.cjs +0 -1
  111. package/dist/types/plugin.d.cts +12 -1
  112. package/dist/types/plugin.d.mts +12 -1
  113. package/dist/types/plugin.mjs +0 -2
  114. package/package.json +5 -5
  115. package/dist/helpers-B15z10jN.mjs +0 -1
  116. package/dist/helpers-LF26RHol.cjs +0 -0
  117. package/dist/index-9iG2qHLe.d.mts +0 -1
  118. package/dist/index-D4ELpJXS.d.cts +0 -1
  119. package/dist/index-D6CnpA_r.d.cts +0 -1
  120. package/dist/index-DL0uimUT.d.mts +0 -1
  121. package/dist/plugin-C5bG6Zu0.d.mts +0 -1772
  122. package/dist/plugin-Cl1J-dKa.d.cts +0 -1769
  123. package/dist/plugin-ifZVa20V.mjs +0 -1
  124. package/dist/plugin-pBKbb5K9.cjs +0 -0
  125. package/dist/types-U3zd8PTP.mjs +0 -1
  126. package/dist/types-o3zWarRp.cjs +0 -0
  127. package/dist/unplugin-Bo9KoKSB.d.cts +0 -7
  128. package/dist/unplugin-Ct4wZxE5.d.mts +0 -7
  129. package/dist/unplugin-GJmHohOE.mjs +0 -4617
  130. package/dist/unplugin-bKYETUU8.cjs +0 -4661
@@ -0,0 +1,830 @@
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ const require_paths = require('../../plugin-utils/paths.cjs');
3
+ const require_fs = require('../../../schemas/fs.cjs');
4
+ const require_logger = require('../logger.cjs');
5
+ const require_helpers = require('./helpers.cjs');
6
+ const require_file_system = require('./storage/file-system.cjs');
7
+ const require_virtual = require('./storage/virtual.cjs');
8
+ let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
9
+ let __stryke_path_join_paths = require("@stryke/path/join-paths");
10
+ let __stryke_convert_to_array = require("@stryke/convert/to-array");
11
+ let __stryke_fs_resolve = require("@stryke/fs/resolve");
12
+ let __stryke_path_append = require("@stryke/path/append");
13
+ let __stryke_path_replace = require("@stryke/path/replace");
14
+ let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
15
+ let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
16
+ let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
17
+ let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
18
+ let __stryke_fs_exists = require("@stryke/fs/exists");
19
+ let __stryke_hash_murmurhash = require("@stryke/hash/murmurhash");
20
+ let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
21
+ let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
22
+ let __stryke_path_is_type = require("@stryke/path/is-type");
23
+ let flat_cache = require("flat-cache");
24
+ let __stryke_capnp = require("@stryke/capnp");
25
+ __stryke_capnp = require_rolldown_runtime.__toESM(__stryke_capnp);
26
+ let __stryke_fs_buffer = require("@stryke/fs/buffer");
27
+ let __stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
28
+ let __stryke_type_checks_is_regexp = require("@stryke/type-checks/is-regexp");
29
+ let node_buffer = require("node:buffer");
30
+ let node_url = require("node:url");
31
+ let prettier = require("prettier");
32
+
33
+ //#region ../powerlines/src/lib/fs/vfs.ts
34
+ /**
35
+ * Represents a virtual file system (VFS) that stores files and their associated metadata in virtual memory.
36
+ *
37
+ * @remarks
38
+ * This class provides methods to manage virtual files, check their existence, retrieve their content, and manipulate the virtual file system. It allows for efficient file management and retrieval without relying on the actual file system.
39
+ */
40
+ var VirtualFileSystem = class VirtualFileSystem {
41
+ /**
42
+ * A map of virtual file IDs to their associated metadata.
43
+ */
44
+ #metadata;
45
+ /**
46
+ * A map of virtual file IDs to their underlying file paths.
47
+ */
48
+ #ids;
49
+ /**
50
+ * A map of underlying file paths to their virtual file IDs.
51
+ */
52
+ #paths;
53
+ /**
54
+ * The unified volume that combines the virtual file system with the real file system.
55
+ *
56
+ * @remarks
57
+ * This volume allows for seamless access to both virtual and real files.
58
+ */
59
+ #storage = { "": new require_file_system.FileSystemStorageAdapter() };
60
+ /**
61
+ * A cache for module resolution results.
62
+ */
63
+ #resolverCache;
64
+ /**
65
+ * Indicator specifying if the virtual file system (VFS) is disposed
66
+ */
67
+ #isDisposed = false;
68
+ /**
69
+ * The context of the virtual file system.
70
+ */
71
+ #context;
72
+ /**
73
+ * The file system's logging function.
74
+ */
75
+ #log;
76
+ /**
77
+ * Normalizes a given module id by resolving it against the built-ins path.
78
+ *
79
+ * @param id - The module id to normalize.
80
+ * @returns The normalized module id.
81
+ */
82
+ #normalizeId(id) {
83
+ let normalized = id;
84
+ if ((0, __stryke_path_is_parent_path.isParentPath)(normalized, this.#context.builtinsPath)) normalized = (0, __stryke_path_replace.replacePath)(normalized, this.#context.builtinsPath);
85
+ return require_helpers.normalizeId(normalized, this.#context.config.output.builtinPrefix);
86
+ }
87
+ /**
88
+ * Normalizes a given path by resolving it against the project root, workspace root, and built-ins path.
89
+ *
90
+ * @param path - The path to normalize.
91
+ * @returns The normalized path.
92
+ */
93
+ #normalizePath(path) {
94
+ return require_helpers.normalizePath(path.includes("{") || path.includes("}") ? require_paths.replacePathTokens(this.#context, path) : path, this.#context.builtinsPath, this.#context.config.output.builtinPrefix);
95
+ }
96
+ /**
97
+ * Builds a regular expression from a string pattern for path matching.
98
+ *
99
+ * @param path - The string pattern to convert.
100
+ * @returns A regular expression for matching paths.
101
+ */
102
+ #buildRegex(path) {
103
+ const token = "::GLOBSTAR::";
104
+ return /* @__PURE__ */ new RegExp(`^${this.#normalizePath(path).replace(/\*\*/g, token).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(new RegExp(token, "g"), ".*")}$`);
105
+ }
106
+ /**
107
+ * Gets the storage adapter and relative key for a given key.
108
+ *
109
+ * @remarks
110
+ * The `key` can be either a path or a storage adapter name.
111
+ *
112
+ * @param key - The key to get the storage adapter for.
113
+ * @returns The storage adapter and relative key for the given key.
114
+ */
115
+ #getStorage(key) {
116
+ const found = Object.entries(this.#storage).find(([, adapter]) => adapter.name === key || adapter.preset && adapter.preset.toLowerCase() === key?.toLowerCase());
117
+ if (found) return {
118
+ base: found[0],
119
+ relativeKey: "",
120
+ adapter: found[1]
121
+ };
122
+ const path = this.resolveSync(this.#normalizePath(key)) || key;
123
+ for (const base of Object.keys(this.#storage).filter(Boolean).sort().reverse()) if ((0, __stryke_path_is_parent_path.isParentPath)(path, base)) return {
124
+ base,
125
+ relativeKey: (0, __stryke_path_replace.replacePath)(path, base),
126
+ adapter: this.#storage[base]
127
+ };
128
+ return {
129
+ base: "",
130
+ relativeKey: path,
131
+ adapter: this.#storage[""]
132
+ };
133
+ }
134
+ /**
135
+ * Gets all storage adapters that match a given base key.
136
+ *
137
+ * @param base - The base key to match storage adapters against.
138
+ * @param includeParent - Whether to include parent storage adapters.
139
+ * @returns An array of storage adapters that match the given base key.
140
+ */
141
+ #getStorages(base = "", includeParent = false) {
142
+ return Object.keys(this.#storage).sort().reverse().filter((key) => (0, __stryke_path_is_parent_path.isParentPath)(key, base) || includeParent && (0, __stryke_path_is_parent_path.isParentPath)(base, key)).map((key) => ({
143
+ relativeBase: base.length > key.length ? base.slice(key.length) : void 0,
144
+ base: key,
145
+ adapter: this.#storage[key]
146
+ }));
147
+ }
148
+ /**
149
+ * Creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
150
+ *
151
+ * @param context - The context of the virtual file system, typically containing options and logging functions.
152
+ * @returns A promise that resolves to a new virtual file system instance.
153
+ */
154
+ static async create(context) {
155
+ if (!context.config.skipCache && (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)(context.dataPath, "fs.bin"))) {
156
+ const buffer = await (0, __stryke_fs_buffer.readFileBuffer)((0, __stryke_path_join_paths.joinPaths)(context.dataPath, "fs.bin"));
157
+ const fs = new __stryke_capnp.Message(buffer, false).getRoot(require_fs.FileSystem);
158
+ const result = new VirtualFileSystem(context, fs);
159
+ if (fs._hasStorage() && fs.storage.length > 0) await Promise.all(fs.storage.values().map(async (file) => {
160
+ await result.write(file.path, file.code);
161
+ }));
162
+ }
163
+ return new VirtualFileSystem(context, new __stryke_capnp.Message().initRoot(require_fs.FileSystem));
164
+ }
165
+ /**
166
+ * Synchronously creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
167
+ *
168
+ * @param context - The context of the virtual file system, typically containing options and logging functions.
169
+ * @returns A new virtual file system instance.
170
+ */
171
+ static createSync(context) {
172
+ if (!context.config.skipCache && (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)(context.dataPath, "fs.bin"))) {
173
+ const buffer = (0, __stryke_fs_buffer.readFileBufferSync)((0, __stryke_path_join_paths.joinPaths)(context.dataPath, "fs.bin"));
174
+ const fs = new __stryke_capnp.Message(buffer, false).getRoot(require_fs.FileSystem);
175
+ const result = new VirtualFileSystem(context, fs);
176
+ if (fs._hasStorage() && fs.storage.length > 0) fs.storage.values().map((file) => {
177
+ result.writeSync(file.path, file.code);
178
+ });
179
+ }
180
+ return new VirtualFileSystem(context, new __stryke_capnp.Message().initRoot(require_fs.FileSystem));
181
+ }
182
+ /**
183
+ * A map of file ids to their metadata.
184
+ */
185
+ get metadata() {
186
+ return new Proxy(this.#metadata, { get: (target, prop) => {
187
+ return target[this.#normalizeId(prop)];
188
+ } });
189
+ }
190
+ /**
191
+ * A map of file paths to their module ids.
192
+ */
193
+ get ids() {
194
+ return new Proxy(this.#paths, { get: (target, prop) => {
195
+ return target[this.#normalizePath(prop)];
196
+ } });
197
+ }
198
+ /**
199
+ * A map of module ids to their file paths.
200
+ */
201
+ get paths() {
202
+ return new Proxy(this.#paths, { get: (target, prop) => {
203
+ return target[this.#normalizeId(prop)];
204
+ } });
205
+ }
206
+ /**
207
+ * Gets the resolver cache.
208
+ */
209
+ get resolverCache() {
210
+ if (!this.#resolverCache) this.#resolverCache = (0, flat_cache.create)({
211
+ cacheId: "module-resolution",
212
+ cacheDir: this.#context.cachePath,
213
+ ttl: 3600 * 1e3,
214
+ lruSize: 5e3,
215
+ persistInterval: 100
216
+ });
217
+ return this.#resolverCache;
218
+ }
219
+ /**
220
+ * Creates a new instance of the {@link VirtualFileSystem}.
221
+ *
222
+ * @param context - The context of the virtual file system, typically containing options and logging functions.
223
+ * @param fs - A buffer containing the serialized virtual file system data.
224
+ */
225
+ constructor(context, fs) {
226
+ this.#context = context;
227
+ if ((0, __stryke_type_checks_is_set_object.isSetObject)(this.#context.config.output.storage)) this.#storage = {
228
+ ...this.#storage,
229
+ ...this.#context.config.output.storage
230
+ };
231
+ this.#storage.virtual ??= new require_virtual.VirtualStorageAdapter({ base: "/_virtual" });
232
+ if (this.#context.config.output.storage !== "fs") {
233
+ this.#storage[this.#context.artifactsPath] ??= new require_virtual.VirtualStorageAdapter({ base: this.#context.artifactsPath });
234
+ this.#storage[this.#context.builtinsPath] ??= new require_virtual.VirtualStorageAdapter({ base: this.#context.builtinsPath });
235
+ this.#storage[this.#context.entryPath] ??= new require_virtual.VirtualStorageAdapter({ base: this.#context.entryPath });
236
+ }
237
+ this.#metadata = {};
238
+ if (fs._hasMetadata()) {
239
+ this.#metadata = fs.metadata.values().reduce((ret, metadata) => {
240
+ ret[metadata.id] = {
241
+ id: metadata.id,
242
+ type: metadata.type,
243
+ timestamp: metadata.timestamp || Date.now(),
244
+ properties: metadata._hasProperties() ? metadata.properties.values().reduce((ret$1, item) => {
245
+ ret$1[item.key] = item.value;
246
+ return ret$1;
247
+ }, {}) : {}
248
+ };
249
+ return ret;
250
+ }, {});
251
+ if (context.config.skipCache !== true) Object.entries(this.#metadata).filter(([, value]) => value.type === "entry").forEach(([id, value]) => {
252
+ this.#context.entry ??= [];
253
+ this.#context.entry.push({
254
+ file: id,
255
+ name: value.properties.name,
256
+ output: value.properties.output,
257
+ input: value.properties["input.file"] ? {
258
+ file: value.properties["input.file"],
259
+ name: value.properties["input.name"]
260
+ } : void 0
261
+ });
262
+ });
263
+ }
264
+ this.#ids = {};
265
+ this.#paths = {};
266
+ if (fs._hasIds()) {
267
+ this.#ids = fs.ids.values().reduce((ret, identifier) => {
268
+ ret[identifier.path] ??= identifier.id;
269
+ return ret;
270
+ }, {});
271
+ this.#paths = fs.ids.values().reduce((ret, identifier) => {
272
+ ret[identifier.id] ??= identifier.path;
273
+ return ret;
274
+ }, {});
275
+ }
276
+ this.#log = require_logger.extendLog(this.#context.log, "file-system");
277
+ }
278
+ /**
279
+ * Asynchronously checks if a file exists in the virtual file system (VFS).
280
+ *
281
+ * @param path - The path to the file.
282
+ * @returns A promise that resolves to `true` if the file exists, otherwise `false`.
283
+ */
284
+ async exists(path) {
285
+ const { relativeKey, adapter } = this.#getStorage(path);
286
+ return adapter.exists(relativeKey);
287
+ }
288
+ /**
289
+ * Synchronously checks if a file exists in the virtual file system (VFS).
290
+ *
291
+ * @param path - The path to the file.
292
+ * @returns `true` if the file exists, otherwise `false`.
293
+ */
294
+ existsSync(path) {
295
+ const { relativeKey, adapter } = this.#getStorage(path);
296
+ return adapter.existsSync(relativeKey);
297
+ }
298
+ /**
299
+ * Checks if a file is virtual in the virtual file system (VFS).
300
+ *
301
+ * @param path - The path to the file.
302
+ * @returns `true` if the file is virtual, otherwise `false`.
303
+ */
304
+ isVirtual(path) {
305
+ const resolved = this.resolveSync(path);
306
+ if (!resolved) return false;
307
+ return this.#getStorage(resolved)?.adapter?.name === "virtual";
308
+ }
309
+ /**
310
+ * Checks if a path is a directory in the virtual file system (VFS).
311
+ *
312
+ * @param path - The path to check.
313
+ * @returns `true` if the path is a directory, otherwise `false`.
314
+ */
315
+ isDirectorySync(path) {
316
+ const resolved = this.resolveSync(path);
317
+ if (!resolved) return false;
318
+ return !!(this.existsSync(resolved) && this.#getStorage(resolved)?.adapter?.isDirectorySync(resolved));
319
+ }
320
+ /**
321
+ * Checks if a path is a directory in the virtual file system (VFS).
322
+ *
323
+ * @param path - The path to check.
324
+ * @returns `true` if the path is a directory, otherwise `false`.
325
+ */
326
+ async isDirectory(path) {
327
+ const resolved = await this.resolve(path);
328
+ if (!resolved) return false;
329
+ return !!(await this.exists(resolved) && await this.#getStorage(resolved)?.adapter?.isDirectory(resolved));
330
+ }
331
+ /**
332
+ * Checks if a path is a file in the virtual file system (VFS).
333
+ *
334
+ * @param path - The path to check.
335
+ * @returns `true` if the path is a file, otherwise `false`.
336
+ */
337
+ isFileSync(path) {
338
+ const resolved = this.resolveSync(path);
339
+ if (!resolved) return false;
340
+ return this.#getStorage(resolved)?.adapter?.isFileSync(resolved) ?? false;
341
+ }
342
+ /**
343
+ * Checks if a path is a file in the virtual file system (VFS).
344
+ *
345
+ * @param path - The path to check.
346
+ * @returns `true` if the path is a file, otherwise `false`.
347
+ */
348
+ async isFile(path) {
349
+ const resolved = await this.resolve(path);
350
+ if (!resolved) return false;
351
+ return await this.#getStorage(resolved)?.adapter?.isFile(resolved) ?? false;
352
+ }
353
+ /**
354
+ * Lists files in a given path.
355
+ *
356
+ * @param path - The path to list files from.
357
+ * @returns An array of file names in the specified path.
358
+ */
359
+ listSync(path) {
360
+ return (0, __stryke_helpers_get_unique.getUnique)(this.#getStorages(path, true).map((storage) => storage.adapter.listSync(storage.relativeBase ? storage.base ? (0, __stryke_path_append.appendPath)(storage.relativeBase, storage.base) : storage.relativeBase : storage.base)).flat());
361
+ }
362
+ /**
363
+ * Lists files in a given path.
364
+ *
365
+ * @param path - The path to list files from.
366
+ * @returns An array of file names in the specified path.
367
+ */
368
+ async list(path) {
369
+ return (0, __stryke_helpers_get_unique.getUnique)((await Promise.all(this.#getStorages(path, true).map(async (storage) => storage.adapter.list(storage.relativeBase ? storage.base ? (0, __stryke_path_append.appendPath)(storage.relativeBase, storage.base) : storage.relativeBase : storage.base)))).flat());
370
+ }
371
+ /**
372
+ * Removes a file in the virtual file system (VFS).
373
+ *
374
+ * @param path - The path to create the directory at.
375
+ */
376
+ async remove(path) {
377
+ const normalizedPath = this.#normalizePath(path);
378
+ this.#log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
379
+ const { relativeKey, adapter } = this.#getStorage(normalizedPath);
380
+ if ((0, __stryke_path_file_path_fns.hasFileExtension)(normalizedPath)) await adapter.remove(relativeKey);
381
+ else await adapter.clear(relativeKey);
382
+ const id = this.#ids[normalizedPath];
383
+ if (id && this.#metadata[id]) {
384
+ delete this.#metadata[id];
385
+ delete this.#ids[normalizedPath];
386
+ delete this.#paths[id];
387
+ }
388
+ }
389
+ /**
390
+ * Removes a file in the virtual file system (VFS).
391
+ *
392
+ * @param path - The path to create the directory at.
393
+ */
394
+ removeSync(path) {
395
+ const normalizedPath = this.#normalizePath(path);
396
+ this.#log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
397
+ const { relativeKey, adapter } = this.#getStorage(normalizedPath);
398
+ if ((0, __stryke_path_file_path_fns.hasFileExtension)(normalizedPath)) adapter.removeSync(relativeKey);
399
+ else adapter.clearSync(relativeKey);
400
+ const id = this.#ids[normalizedPath];
401
+ if (id && this.#metadata[id]) {
402
+ delete this.#metadata[id];
403
+ delete this.#ids[normalizedPath];
404
+ delete this.#paths[id];
405
+ }
406
+ }
407
+ /**
408
+ * Glob files in the virtual file system (VFS) based on the provided pattern(s).
409
+ *
410
+ * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
411
+ * @returns An array of file paths matching the provided pattern(s)
412
+ */
413
+ async glob(patterns) {
414
+ const results = [];
415
+ for (const pattern of require_helpers.normalizeGlobPatterns(this.#context.workspaceConfig.workspaceRoot, patterns)) {
416
+ const normalized = this.#normalizePath(pattern);
417
+ if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
418
+ if (this.isDirectorySync(normalized)) results.push(...await this.list(normalized));
419
+ else {
420
+ const resolved = await this.resolve(normalized);
421
+ if (resolved && !results.includes(resolved)) results.push(resolved);
422
+ }
423
+ continue;
424
+ }
425
+ const absPattern = (0, __stryke_path_is_type.isAbsolutePath)(normalized) ? normalized : this.#normalizePath((0, __stryke_path_join_paths.joinPaths)(this.#context.workspaceConfig.workspaceRoot, normalized));
426
+ const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
427
+ const baseDir = firstGlobIdx === -1 ? (0, __stryke_path_file_path_fns.findFilePath)(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
428
+ await Promise.all((await this.list(baseDir && (0, __stryke_path_is_type.isAbsolutePath)(baseDir) ? baseDir : this.#context.workspaceConfig.workspaceRoot)).map(async (file) => {
429
+ if (this.#buildRegex(absPattern).test(file)) {
430
+ const resolved = this.resolveSync(file);
431
+ if (resolved && !results.includes(resolved)) results.push(resolved);
432
+ }
433
+ }));
434
+ }
435
+ return results;
436
+ }
437
+ /**
438
+ * Synchronously glob files in the virtual file system (VFS) based on the provided pattern(s).
439
+ *
440
+ * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
441
+ * @returns An array of file paths matching the provided pattern(s)
442
+ */
443
+ globSync(patterns) {
444
+ const results = [];
445
+ for (const pattern of require_helpers.normalizeGlobPatterns(this.#context.workspaceConfig.workspaceRoot, patterns)) {
446
+ const normalized = this.#normalizePath(pattern);
447
+ if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
448
+ if (this.isDirectorySync(normalized)) results.push(...this.listSync(normalized));
449
+ else {
450
+ const resolved = this.resolveSync(normalized);
451
+ if (resolved && !results.includes(resolved)) results.push(resolved);
452
+ }
453
+ continue;
454
+ }
455
+ const absPattern = (0, __stryke_path_is_type.isAbsolutePath)(normalized) ? normalized : this.#normalizePath((0, __stryke_path_join_paths.joinPaths)(this.#context.workspaceConfig.workspaceRoot, normalized));
456
+ const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
457
+ const baseDir = firstGlobIdx === -1 ? (0, __stryke_path_file_path_fns.findFilePath)(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
458
+ const files = this.listSync(baseDir && (0, __stryke_path_is_type.isAbsolutePath)(baseDir) ? baseDir : this.#context.workspaceConfig.workspaceRoot);
459
+ for (const file of files) if (this.#buildRegex(absPattern).test(file)) {
460
+ const resolved = this.resolveSync(file);
461
+ if (resolved && !results.includes(resolved)) results.push(resolved);
462
+ }
463
+ }
464
+ return results;
465
+ }
466
+ /**
467
+ * Copies a file from one path to another in the virtual file system (VFS).
468
+ *
469
+ * @param srcPath - The source path to copy
470
+ * @param destPath - The destination path to copy to
471
+ */
472
+ async copy(srcPath, destPath) {
473
+ const src = srcPath instanceof URL ? (0, node_url.fileURLToPath)(srcPath) : srcPath;
474
+ const dest = destPath instanceof URL ? (0, node_url.fileURLToPath)(destPath) : destPath;
475
+ if (!(0, __stryke_type_checks_is_set_string.isSetString)(src) && (!(0, __stryke_type_checks_is_set_object.isSetObject)(src) || !(0, __stryke_type_checks_is_set_string.isSetString)(src.input)) || !(0, __stryke_type_checks_is_set_string.isSetString)(dest)) return;
476
+ const sourceStr = (0, __stryke_type_checks_is_string.isString)(src) ? src : src.input ? src.input : this.#context.workspaceConfig.workspaceRoot;
477
+ const source = await this.resolve(sourceStr);
478
+ if (!source) return;
479
+ if (this.isDirectorySync(source) || (0, __stryke_type_checks_is_set_string.isSetString)(src) && src.includes("*") || (0, __stryke_type_checks_is_set_object.isSetObject)(src) && (0, __stryke_type_checks_is_set_string.isSetString)(src.glob)) await Promise.all((await this.glob(src)).map(async (file) => {
480
+ return this.copy(file, (0, __stryke_path_append.appendPath)((0, __stryke_path_replace.replacePath)(file, sourceStr), dest));
481
+ }));
482
+ else {
483
+ const content = await this.read(source);
484
+ if (content !== void 0) await this.write(this.#normalizePath(dest), content, { skipFormat: true });
485
+ }
486
+ }
487
+ /**
488
+ * Synchronously copies a file from one path to another in the virtual file system (VFS).
489
+ *
490
+ * @param srcPath - The source path to copy
491
+ * @param destPath - The destination path to copy to
492
+ */
493
+ copySync(srcPath, destPath) {
494
+ const src = srcPath instanceof URL ? (0, node_url.fileURLToPath)(srcPath) : srcPath;
495
+ const dest = destPath instanceof URL ? (0, node_url.fileURLToPath)(destPath) : destPath;
496
+ if (!(0, __stryke_type_checks_is_set_string.isSetString)(src) && (!(0, __stryke_type_checks_is_set_object.isSetObject)(src) || !(0, __stryke_type_checks_is_set_string.isSetString)(src.input)) || !(0, __stryke_type_checks_is_set_string.isSetString)(dest)) return;
497
+ const sourceStr = (0, __stryke_type_checks_is_string.isString)(src) ? src : src.input ? src.input : this.#context.workspaceConfig.workspaceRoot;
498
+ const source = this.resolveSync(sourceStr);
499
+ if (!source) return;
500
+ if (this.isDirectorySync(source) || (0, __stryke_type_checks_is_set_string.isSetString)(src) && src.includes("*") || (0, __stryke_type_checks_is_set_object.isSetObject)(src) && (0, __stryke_type_checks_is_set_string.isSetString)(src.glob)) this.globSync(src).map((file) => {
501
+ return this.copySync(file, (0, __stryke_path_append.appendPath)((0, __stryke_path_file_path_fns.findFilePath)((0, __stryke_path_replace.replacePath)(file, sourceStr)), dest));
502
+ });
503
+ else {
504
+ const content = this.readSync(source);
505
+ if (content !== void 0) this.writeSync(this.#normalizePath((0, __stryke_path_file_path_fns.hasFileExtension)(dest) ? dest : (0, __stryke_path_append.appendPath)((0, __stryke_path_file_path_fns.findFileName)(source), dest)), content, { skipFormat: true });
506
+ }
507
+ }
508
+ /**
509
+ * Moves a file (or files) from one path to another in the virtual file system (VFS).
510
+ *
511
+ * @param srcPath - The source path to move
512
+ * @param destPath - The destination path to move to
513
+ */
514
+ async move(srcPath, destPath) {
515
+ if ((0, __stryke_path_file_path_fns.hasFileExtension)(srcPath)) {
516
+ await this.copy(srcPath, destPath);
517
+ await this.remove(srcPath);
518
+ } else await Promise.all((await this.list(srcPath)).map(async (file) => {
519
+ await this.copy(file, destPath);
520
+ await this.remove(file);
521
+ }));
522
+ }
523
+ /**
524
+ * Synchronously moves a file (or files) from one path to another in the virtual file system (VFS).
525
+ *
526
+ * @param srcPath - The source path to move
527
+ * @param destPath - The destination path to move to
528
+ */
529
+ moveSync(srcPath, destPath) {
530
+ if ((0, __stryke_path_file_path_fns.hasFileExtension)(srcPath)) {
531
+ this.copySync(srcPath, destPath);
532
+ this.removeSync(srcPath);
533
+ } else this.listSync(srcPath).forEach((file) => {
534
+ this.copySync(file, destPath);
535
+ this.removeSync(file);
536
+ });
537
+ }
538
+ /**
539
+ * Asynchronously reads a file from the virtual file system (VFS).
540
+ *
541
+ * @param path - The path or ID of the file to read.
542
+ * @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
543
+ */
544
+ async read(path) {
545
+ const filePath = await this.resolve(path);
546
+ if (!filePath) return;
547
+ const { relativeKey, adapter } = this.#getStorage(filePath);
548
+ this.#log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
549
+ return await adapter.get(relativeKey) ?? void 0;
550
+ }
551
+ /**
552
+ * Synchronously reads a file from the virtual file system (VFS).
553
+ *
554
+ * @param path - The path or ID of the file to read.
555
+ * @returns The contents of the file as a string, or undefined if the file does not exist.
556
+ */
557
+ readSync(path) {
558
+ const filePath = this.resolveSync(path);
559
+ if (!filePath) return;
560
+ const { relativeKey, adapter } = this.#getStorage(filePath);
561
+ this.#log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
562
+ return adapter.getSync(relativeKey) ?? void 0;
563
+ }
564
+ /**
565
+ * Writes a file to the virtual file system (VFS).
566
+ *
567
+ * @param path - The path to the file.
568
+ * @param data - The contents of the file.
569
+ * @param options - Optional parameters for writing the file.
570
+ * @returns A promise that resolves when the file is written.
571
+ */
572
+ async write(path, data = "", options = {}) {
573
+ let code = data;
574
+ if (!options.skipFormat) {
575
+ const resolvedConfig = await (0, prettier.resolveConfig)(this.#normalizePath(path));
576
+ if (resolvedConfig) code = await (0, prettier.format)(data, {
577
+ absolutePath: this.#normalizePath(path),
578
+ ...resolvedConfig
579
+ });
580
+ }
581
+ const { relativeKey, adapter } = this.#getStorage(options.storage || path);
582
+ this.#log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Writing ${this.#normalizePath(relativeKey)} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${(0, __stryke_string_format_pretty_bytes.prettyBytes)(new node_buffer.Blob((0, __stryke_convert_to_array.toArray)(code)).size)})`);
583
+ const id = options?.meta?.id || this.#normalizeId(relativeKey);
584
+ this.#metadata[id] = {
585
+ variant: "normal",
586
+ timestamp: Date.now(),
587
+ ...options.meta ?? {}
588
+ };
589
+ this.#paths[id] = this.#normalizePath(relativeKey);
590
+ this.#ids[this.#normalizePath(relativeKey)] = id;
591
+ return adapter.set(relativeKey, code);
592
+ }
593
+ /**
594
+ * Synchronously writes a file to the virtual file system (VFS).
595
+ *
596
+ * @param path - The file to write.
597
+ * @param data - The contents of the file.
598
+ * @param options - Optional parameters for writing the file.
599
+ */
600
+ writeSync(path, data = "", options = {}) {
601
+ const { relativeKey, adapter } = this.#getStorage(options.storage || path);
602
+ this.#log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Writing ${this.#normalizePath(relativeKey)} file to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${(0, __stryke_string_format_pretty_bytes.prettyBytes)(new node_buffer.Blob((0, __stryke_convert_to_array.toArray)(data)).size)})`);
603
+ const id = options?.meta?.id || this.#normalizeId(relativeKey);
604
+ this.#metadata[id] = {
605
+ variant: "normal",
606
+ timestamp: Date.now(),
607
+ ...options.meta ?? {}
608
+ };
609
+ this.#paths[id] = this.#normalizePath(relativeKey);
610
+ this.#ids[this.#normalizePath(relativeKey)] = id;
611
+ return adapter.setSync(relativeKey, data);
612
+ }
613
+ /**
614
+ * Synchronously creates a directory at the specified path.
615
+ *
616
+ * @param dirPath - The path of the directory to create.
617
+ */
618
+ mkdirSync(dirPath) {
619
+ return this.#getStorage(dirPath)?.adapter?.mkdirSync(dirPath);
620
+ }
621
+ /**
622
+ * Creates a directory at the specified path.
623
+ *
624
+ * @param path - The path of the directory to create.
625
+ */
626
+ async mkdir(path) {
627
+ return this.#getStorage(path)?.adapter?.mkdir(path);
628
+ }
629
+ /**
630
+ * Retrieves the metadata of a file in the virtual file system (VFS).
631
+ *
632
+ * @param pathOrId - The path or ID of the file to retrieve metadata for.
633
+ * @returns The metadata of the file, or undefined if the file does not exist.
634
+ */
635
+ getMetadata(pathOrId) {
636
+ const resolved = this.resolveSync(pathOrId);
637
+ if (resolved && this.metadata[resolved]) return this.metadata[resolved];
638
+ }
639
+ /**
640
+ * Resolves a given module ID using the configured aliases.
641
+ *
642
+ * @remarks
643
+ * This function can be used to map module IDs to different paths based on the alias configuration.
644
+ *
645
+ * @param id - The module ID to resolve.
646
+ * @returns The resolved module ID - after applying any configured aliases (this will be the same as the input ID if no aliases match).
647
+ */
648
+ resolveAlias(id) {
649
+ let path = id;
650
+ if (this.#context.config.build.alias) {
651
+ if (Array.isArray(this.#context.config.build.alias) && this.#context.config.build.alias.length > 0) {
652
+ const found = this.#context.config.build.alias.filter((alias) => (0, __stryke_type_checks_is_set_string.isSetString)(alias.find) && (alias.find === path || path.startsWith(`${alias.find}/`)) || (0, __stryke_type_checks_is_regexp.isRegExp)(alias.find) && alias.find.test(path));
653
+ if (found.length > 0) {
654
+ const alias = found.reduce((ret, current) => {
655
+ return ((0, __stryke_type_checks_is_set_string.isSetString)(ret.find) ? ret.find.length : (0, __stryke_type_checks_is_regexp.isRegExp)(ret.find) ? ret.find.source.length : 0) > ((0, __stryke_type_checks_is_set_string.isSetString)(current.find) ? current.find.length : (0, __stryke_type_checks_is_regexp.isRegExp)(current.find) ? current.find.source.length : 0) ? ret : current;
656
+ });
657
+ if ((0, __stryke_type_checks_is_set_string.isSetString)(alias.find)) path = path.replace(/* @__PURE__ */ new RegExp(`^${alias.find}`), alias.replacement);
658
+ else if ((0, __stryke_type_checks_is_regexp.isRegExp)(alias.find)) path = path.replace(alias.find, alias.replacement);
659
+ }
660
+ } else if ((0, __stryke_type_checks_is_set_object.isSetObject)(this.#context.config.build.alias)) {
661
+ const found = Object.keys(this.#context.config.build.alias).filter((key) => key === path || path.startsWith(`${key}/`));
662
+ if (found.length > 0) {
663
+ const alias = found.reduce((ret, current) => {
664
+ return ret.length > current.length ? ret : current;
665
+ });
666
+ path = path.replace(/* @__PURE__ */ new RegExp(`^${alias}`), this.#context.config.build.alias[alias]);
667
+ }
668
+ }
669
+ }
670
+ return path;
671
+ }
672
+ /**
673
+ * A helper function to resolve modules in the virtual file system (VFS).
674
+ *
675
+ * @remarks
676
+ * This function can be used to resolve modules relative to the project root directory.
677
+ *
678
+ * @example
679
+ * ```ts
680
+ * const resolved = await context.resolvePath("some-module", "/path/to/importer");
681
+ * ```
682
+ *
683
+ * @param id - The module to resolve.
684
+ * @param importer - An optional path to the importer module.
685
+ * @param options - Additional resolution options.
686
+ * @returns A promise that resolves to the resolved module path.
687
+ */
688
+ async resolve(id, importer, options = {}) {
689
+ let path = id;
690
+ if (path.includes("{") || path.includes("}")) path = require_paths.replacePathTokens(this.#context, path);
691
+ if (options.skipAlias !== true) path = this.resolveAlias(path);
692
+ if ((0, __stryke_path_is_type.isAbsolutePath)(path)) return path;
693
+ const resolverCacheKey = (0, __stryke_hash_murmurhash.murmurhash)({
694
+ path: this.#normalizeId(path),
695
+ importer,
696
+ options
697
+ });
698
+ let result;
699
+ if (!this.#context.config.skipCache) {
700
+ result = this.resolverCache.get(resolverCacheKey);
701
+ if (result) return result;
702
+ }
703
+ result = this.paths[this.#normalizeId(path)];
704
+ if (!result) {
705
+ const paths = options.paths ?? [];
706
+ if (importer && !paths.includes(importer)) paths.push(importer);
707
+ paths.push(this.#context.workspaceConfig.workspaceRoot);
708
+ paths.push((0, __stryke_path_append.appendPath)(this.#context.config.projectRoot, this.#context.workspaceConfig.workspaceRoot));
709
+ paths.push((0, __stryke_path_append.appendPath)(this.#context.config.sourceRoot, this.#context.workspaceConfig.workspaceRoot));
710
+ paths.push(...Object.keys(this.#context.tsconfig?.options?.paths ?? {}).filter((tsconfigPath) => path.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig?.options?.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => (0, __stryke_path_append.appendPath)(tsconfigPath, this.#context.workspaceConfig.workspaceRoot)));
711
+ for (const combination of (0, __stryke_fs_resolve.getResolutionCombinations)(path, { paths })) {
712
+ const { relativeKey, adapter } = this.#getStorage(combination);
713
+ if (await adapter.exists(relativeKey)) {
714
+ result = combination;
715
+ break;
716
+ }
717
+ }
718
+ if (!result) try {
719
+ result = await (0, __stryke_fs_resolve.resolve)(path, {
720
+ ...options,
721
+ paths
722
+ });
723
+ } catch {}
724
+ }
725
+ if (result && !this.#context.config.skipCache) this.resolverCache.set(resolverCacheKey, result);
726
+ return result;
727
+ }
728
+ /**
729
+ * A synchronous helper function to resolve modules using the Jiti resolver
730
+ *
731
+ * @remarks
732
+ * This function can be used to resolve modules relative to the project root directory.
733
+ *
734
+ * @example
735
+ * ```ts
736
+ * const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
737
+ * ```
738
+ *
739
+ * @param id - The module to resolve.
740
+ * @param importer - An optional path to the importer module.
741
+ * @param options - Additional resolution options.
742
+ * @returns The resolved module path.
743
+ */
744
+ resolveSync(id, importer, options = {}) {
745
+ let path = id;
746
+ if (path.includes("{") || path.includes("}")) path = require_paths.replacePathTokens(this.#context, path);
747
+ if (options.skipAlias !== true) path = this.resolveAlias(path);
748
+ if ((0, __stryke_path_is_type.isAbsolutePath)(path)) return path;
749
+ let result;
750
+ if (!this.#context.config.skipCache) {
751
+ result = this.resolverCache.get(this.#normalizeId(path));
752
+ if (result) return result;
753
+ }
754
+ result = this.paths[this.#normalizeId(path)];
755
+ if (!result) {
756
+ const paths = options.paths ?? [];
757
+ if (importer && !paths.includes(importer)) paths.push(importer);
758
+ paths.push(this.#context.workspaceConfig.workspaceRoot);
759
+ paths.push((0, __stryke_path_append.appendPath)(this.#context.config.projectRoot, this.#context.workspaceConfig.workspaceRoot));
760
+ paths.push((0, __stryke_path_append.appendPath)(this.#context.config.sourceRoot, this.#context.workspaceConfig.workspaceRoot));
761
+ paths.push(...Object.keys(this.#context.tsconfig?.options?.paths ?? {}).filter((tsconfigPath) => path.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig?.options?.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => (0, __stryke_path_append.appendPath)(tsconfigPath, this.#context.workspaceConfig.workspaceRoot)));
762
+ for (const combination of (0, __stryke_fs_resolve.getResolutionCombinations)(path, { paths })) {
763
+ const { relativeKey, adapter } = this.#getStorage(combination);
764
+ if (adapter.existsSync(relativeKey)) {
765
+ result = combination;
766
+ break;
767
+ }
768
+ }
769
+ if (!result) try {
770
+ result = (0, __stryke_fs_resolve.resolveSync)(path, {
771
+ ...options,
772
+ paths
773
+ });
774
+ } catch {}
775
+ }
776
+ if (result && !this.#context.config.skipCache) this.resolverCache.set(this.#normalizeId(path), result);
777
+ return result;
778
+ }
779
+ /**
780
+ * Disposes of the virtual file system (VFS) by saving its state to disk.
781
+ */
782
+ async dispose() {
783
+ if (!this.#isDisposed) {
784
+ this.#isDisposed = true;
785
+ this.#log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, "Disposing virtual file system...");
786
+ await this.remove((0, __stryke_path_join_paths.joinPaths)(this.#context.dataPath, "fs.bin"));
787
+ const message = new __stryke_capnp.Message();
788
+ const fs = message.initRoot(require_fs.FileSystem);
789
+ const paths = await this.list();
790
+ const storage = fs._initStorage(paths.length);
791
+ await Promise.all(paths.map(async (path, index) => {
792
+ const code = await this.read(path);
793
+ const fd = storage.get(index);
794
+ fd.path = path;
795
+ fd.code = code || "";
796
+ }));
797
+ const ids = fs._initIds(Object.keys(this.ids).length);
798
+ Object.entries(this.ids).filter(([, path]) => path).forEach(([id, path], index) => {
799
+ const fileId = ids.get(index);
800
+ fileId.id = id;
801
+ fileId.path = path;
802
+ });
803
+ const metadata = fs._initMetadata(Object.keys(this.metadata).length);
804
+ Object.entries(this.metadata).filter(([, value]) => value).forEach(([id, value], index) => {
805
+ const fileMetadata = metadata.get(index);
806
+ fileMetadata.id = id;
807
+ fileMetadata.type = value.type;
808
+ fileMetadata.timestamp = value.timestamp ?? BigInt(Date.now());
809
+ if (value.properties) {
810
+ const props = fileMetadata._initProperties(Object.keys(value.properties).length);
811
+ Object.entries(value.properties).filter(([, val]) => (0, __stryke_type_checks_is_set_string.isSetString)(val)).forEach(([key, val], index$1) => {
812
+ const prop = props.get(index$1);
813
+ prop.key = key;
814
+ prop.value = val;
815
+ });
816
+ }
817
+ });
818
+ await (0, __stryke_fs_buffer.writeFileBuffer)((0, __stryke_path_join_paths.joinPaths)(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
819
+ if (!this.#context.config.skipCache) this.#resolverCache.save(true);
820
+ await Promise.all(this.#getStorages().map(async (storage$1) => storage$1.adapter.dispose()));
821
+ this.#log(__storm_software_config_tools_types.LogLevelLabel.TRACE, "Virtual file system has been disposed.");
822
+ }
823
+ }
824
+ async [Symbol.asyncDispose]() {
825
+ return this.dispose();
826
+ }
827
+ };
828
+
829
+ //#endregion
830
+ exports.VirtualFileSystem = VirtualFileSystem;