@powerlines/plugin-esbuild 0.5.0 → 0.6.0

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 (47) hide show
  1. package/package.json +10 -6
  2. package/dist/chunk-54IL5JZD.js +0 -3
  3. package/dist/chunk-54IL5JZD.js.map +0 -1
  4. package/dist/chunk-DKSPBMRI.cjs +0 -1472
  5. package/dist/chunk-DKSPBMRI.cjs.map +0 -1
  6. package/dist/chunk-DXDH2OBY.js +0 -3
  7. package/dist/chunk-DXDH2OBY.js.map +0 -1
  8. package/dist/chunk-EWDQEFTW.js +0 -3
  9. package/dist/chunk-EWDQEFTW.js.map +0 -1
  10. package/dist/chunk-FGTVQNHX.js +0 -1461
  11. package/dist/chunk-FGTVQNHX.js.map +0 -1
  12. package/dist/chunk-MTB74RUM.cjs +0 -4
  13. package/dist/chunk-MTB74RUM.cjs.map +0 -1
  14. package/dist/chunk-R6NPMTZP.cjs +0 -4
  15. package/dist/chunk-R6NPMTZP.cjs.map +0 -1
  16. package/dist/chunk-ZJGSECAJ.cjs +0 -4
  17. package/dist/chunk-ZJGSECAJ.cjs.map +0 -1
  18. package/dist/helpers/index.cjs +0 -13
  19. package/dist/helpers/index.cjs.map +0 -1
  20. package/dist/helpers/index.d.cts +0 -6
  21. package/dist/helpers/index.d.ts +0 -6
  22. package/dist/helpers/index.js +0 -4
  23. package/dist/helpers/index.js.map +0 -1
  24. package/dist/helpers/unplugin.cjs +0 -12
  25. package/dist/helpers/unplugin.cjs.map +0 -1
  26. package/dist/helpers/unplugin.d.cts +0 -9
  27. package/dist/helpers/unplugin.d.ts +0 -9
  28. package/dist/helpers/unplugin.js +0 -3
  29. package/dist/helpers/unplugin.js.map +0 -1
  30. package/dist/index.cjs +0 -107
  31. package/dist/index.cjs.map +0 -1
  32. package/dist/index.d.cts +0 -15
  33. package/dist/index.d.ts +0 -15
  34. package/dist/index.js +0 -95
  35. package/dist/index.js.map +0 -1
  36. package/dist/types/index.cjs +0 -7
  37. package/dist/types/index.cjs.map +0 -1
  38. package/dist/types/index.d.cts +0 -4
  39. package/dist/types/index.d.ts +0 -4
  40. package/dist/types/index.js +0 -4
  41. package/dist/types/index.js.map +0 -1
  42. package/dist/types/plugin.cjs +0 -6
  43. package/dist/types/plugin.cjs.map +0 -1
  44. package/dist/types/plugin.d.cts +0 -9
  45. package/dist/types/plugin.d.ts +0 -9
  46. package/dist/types/plugin.js +0 -3
  47. package/dist/types/plugin.js.map +0 -1
@@ -1,1461 +0,0 @@
1
- import { LogLevelLabel } from '@storm-software/config-tools/types';
2
- import '@stryke/fs/get-workspace-root';
3
- import { match } from 'bundle-require';
4
- import '@storm-software/config-tools/logger/console';
5
- import { toArray } from '@stryke/convert/to-array';
6
- import '@stryke/fs/copy-file';
7
- import '@stryke/fs/exists';
8
- import '@stryke/fs/helpers';
9
- import '@stryke/fs/install';
10
- import '@stryke/fs/list-files';
11
- import '@stryke/fs/package-fns';
12
- import { findFilePath, findFileExtensionSafe } from '@stryke/path/file-path-fns';
13
- import { isParentPath } from '@stryke/path/is-parent-path';
14
- import { joinPaths } from '@stryke/path/join-paths';
15
- import { replacePath } from '@stryke/path/replace';
16
- import '@stryke/type-checks/is-error';
17
- import { isFunction } from '@stryke/type-checks/is-function';
18
- import '@stryke/type-checks/is-number';
19
- import '@stryke/type-checks/is-set';
20
- import { isSetObject } from '@stryke/type-checks/is-set-object';
21
- import { isSetString } from '@stryke/type-checks/is-set-string';
22
- import chalk from 'chalk';
23
- import 'handlebars';
24
- import '@stryke/fs/json';
25
- import '@stryke/path/append';
26
- import defu5 from 'defu';
27
- import 'typescript';
28
- import { titleCase } from '@stryke/string-format/title-case';
29
- import '@stryke/fs/remove-file';
30
- import '@stryke/hash/hash-files';
31
- import '@stryke/helpers/get-unique';
32
- import '@stryke/string-format/kebab-case';
33
- import '@stryke/type-checks/is-undefined';
34
- import '@stryke/fs/write-file';
35
- import { format, resolveConfig } from 'prettier';
36
- import '@stryke/fs/resolve';
37
- import '@storm-software/config-tools/get-config';
38
- import 'c12';
39
- import '@stryke/env/get-env-paths';
40
- import { murmurhash } from '@stryke/hash/murmurhash';
41
- import { omit } from '@stryke/helpers/omit';
42
- import '@stryke/path/join';
43
- import '@stryke/type-checks/is-null';
44
- import { isString } from '@stryke/type-checks/is-string';
45
- import '@stryke/unique-id/uuid';
46
- import '@stryke/convert/parse-type-definition';
47
- import '@storm-software/config-tools/logger';
48
- import '@storm-software/config-tools/utilities/colors';
49
- import '@stryke/helpers/noop';
50
- import 'jiti';
51
- import { bufferToString } from '@stryke/convert/buffer-to-string';
52
- import { isAbsolutePath } from '@stryke/path/is-type';
53
- import { prettyBytes } from '@stryke/string-format/pretty-bytes';
54
- import { isBuffer } from '@stryke/type-checks/is-buffer';
55
- import { Volume } from 'memfs';
56
- import { Blob } from 'node:buffer';
57
- import fs from 'node:fs';
58
- import { Union } from 'unionfs';
59
- import '@stryke/type-checks/is-object';
60
- import '@stryke/fs/is-file';
61
- import '@stryke/fs/read-file';
62
- import '@stryke/fs/semver-fns';
63
- import '@stryke/path/get-parent-path';
64
- import 'node:path';
65
- import '@stryke/string-format/package';
66
- import '@babel/core';
67
- import 'magic-string';
68
- import '@babel/helper-plugin-utils';
69
- import '@babel/types';
70
- import '@donedeal0/superdiff';
71
- import '@stryke/fs/tsconfig';
72
- import '@stryke/json/storm-json';
73
- import 'minimatch';
74
- import { createEsbuildPlugin } from 'unplugin';
75
-
76
- var __defProp = Object.defineProperty;
77
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
78
-
79
- // ../powerlines/src/types/vfs.ts
80
- var __VFS_INIT__ = "__VFS_INIT__";
81
- var __VFS_REVERT__ = "__VFS_REVERT__";
82
- var __VFS_CACHE__ = "__VFS_CACHE__";
83
- var __VFS_RESOLVER__ = "__VFS_RESOLVER__";
84
- var __VFS_VIRTUAL__ = "__VFS_VIRTUAL__";
85
- var __VFS_UNIFIED__ = "__VFS_UNIFIED__";
86
- function resolveEntryInputFile(context, typeDefinition) {
87
- return replacePath(typeDefinition.file, joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot));
88
- }
89
- __name(resolveEntryInputFile, "resolveEntryInputFile");
90
- function resolveEntryOutput(context, typeDefinition) {
91
- return joinPaths(replacePath(replacePath(replacePath(replacePath(typeDefinition.file, joinPaths(context.workspaceConfig.workspaceRoot, context.config.sourceRoot)), joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot)), context.config.sourceRoot), context.config.projectRoot)).replace(`.${findFileExtensionSafe(typeDefinition.file)}`, "");
92
- }
93
- __name(resolveEntryOutput, "resolveEntryOutput");
94
- var BADGE_COLORS = [
95
- "#00A0DD",
96
- "#6FCE4E",
97
- "#FBBF24",
98
- "#F43F5E",
99
- "#3B82F6",
100
- "#A855F7",
101
- "#469592",
102
- "#288EDF",
103
- "#10B981",
104
- "#EF4444",
105
- "#F0EC56",
106
- "#F472B6",
107
- "#22D3EE",
108
- "#EAB308",
109
- "#84CC16",
110
- "#F87171",
111
- "#0EA5E9",
112
- "#D946EF",
113
- "#FACC15",
114
- "#34D399"
115
- ];
116
- var extendLog = /* @__PURE__ */ __name((logFn, name) => {
117
- return (type, ...args) => logFn(type, ` ${chalk.inverse.hex(BADGE_COLORS[name.split("").map((char) => char.charCodeAt(0)).reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length] || BADGE_COLORS[0])(` ${titleCase(name)} `)} ${args.join(" ")} `);
118
- }, "extendLog");
119
- (class {
120
- static {
121
- __name(this, "VirtualFileSystem");
122
- }
123
- /**
124
- * The internal map of virtual files.
125
- */
126
- #builtinIdMap = /* @__PURE__ */ new Map();
127
- /**
128
- * A map of virtual file paths to their underlying file content.
129
- */
130
- #cachedFS = /* @__PURE__ */ new Map();
131
- /**
132
- * A map of virtual file paths to their underlying file content.
133
- */
134
- #cachedResolver = /* @__PURE__ */ new Map();
135
- /**
136
- * The internal map of virtual files.
137
- */
138
- #virtualFS = new Volume();
139
- /**
140
- * The physical file system.
141
- */
142
- #fs = cloneFS(fs);
143
- /**
144
- * The unified volume that combines the virtual file system with the real file system.
145
- *
146
- * @remarks
147
- * This volume allows for seamless access to both virtual and real files.
148
- */
149
- #unifiedFS = new Union();
150
- /**
151
- * Indicator specifying if the file system module is patched
152
- */
153
- #isPatched = false;
154
- /**
155
- * Function to revert require patch
156
- */
157
- #revert;
158
- /**
159
- * The context of the virtual file system.
160
- */
161
- #context;
162
- /**
163
- * The file system's logging function.
164
- */
165
- #log;
166
- /**
167
- * Exposes the internal VFS map for advanced usage.
168
- */
169
- get [__VFS_CACHE__]() {
170
- return this.#cachedFS;
171
- }
172
- /**
173
- * Exposes the internal VFS resolver cache for advanced usage.
174
- */
175
- get [__VFS_RESOLVER__]() {
176
- return this.#cachedResolver;
177
- }
178
- /**
179
- * Exposes the internal VFS map for advanced usage.
180
- */
181
- get [__VFS_VIRTUAL__]() {
182
- return this.#virtualFS;
183
- }
184
- /**
185
- * Exposes the internal UFS map for advanced usage.
186
- */
187
- get [__VFS_UNIFIED__]() {
188
- return this.#unifiedFS;
189
- }
190
- /**
191
- * Creates a new instance of the VirtualFileSystem.
192
- *
193
- * @param context - The context of the virtual file system, typically containing options and logging functions.
194
- * @param serialized - A map of files/file contents to populate in cache
195
- */
196
- constructor(context, serialized) {
197
- this.#context = context;
198
- this.#cachedFS = /* @__PURE__ */ new Map();
199
- this.#builtinIdMap = new Map(Object.entries(serialized?.builtinIdMap ?? {}));
200
- if (!this.#fs.existsSync(this.#context.dataPath)) {
201
- this.#fs.mkdirSync(this.#context.dataPath, {
202
- recursive: true
203
- });
204
- }
205
- if (!this.#fs.existsSync(this.#context.cachePath)) {
206
- this.#fs.mkdirSync(this.#context.cachePath, {
207
- recursive: true
208
- });
209
- }
210
- if (!this.#fs.existsSync(joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
211
- this.#fs.mkdirSync(joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath), {
212
- recursive: true
213
- });
214
- }
215
- this.#unifiedFS = this.#unifiedFS.use(this.#fs);
216
- if (this.#context.config.output.mode !== "fs") {
217
- if (serialized?.virtualFiles && Object.keys(serialized.virtualFiles).length > 0) {
218
- this.#virtualFS = Volume.fromJSON(serialized.virtualFiles);
219
- }
220
- if (!this.#virtualFS.existsSync(this.#context.artifactsPath)) {
221
- this.#virtualFS.mkdirSync(this.#context.artifactsPath, {
222
- recursive: true
223
- });
224
- }
225
- if (!this.#virtualFS.existsSync(this.#context.builtinsPath)) {
226
- this.#virtualFS.mkdirSync(this.#context.builtinsPath, {
227
- recursive: true
228
- });
229
- }
230
- if (!this.#virtualFS.existsSync(this.#context.entryPath)) {
231
- this.#virtualFS.mkdirSync(this.#context.entryPath, {
232
- recursive: true
233
- });
234
- }
235
- if (!this.#virtualFS.existsSync(this.#context.dtsPath)) {
236
- this.#virtualFS.mkdirSync(this.#context.dtsPath, {
237
- recursive: true
238
- });
239
- }
240
- this.#unifiedFS = this.#unifiedFS.use(this.#virtualFS);
241
- } else if (this.#context.config.projectType === "application") {
242
- if (!this.#fs.existsSync(this.#context.artifactsPath)) {
243
- this.#fs.mkdirSync(this.#context.artifactsPath, {
244
- recursive: true
245
- });
246
- }
247
- if (!this.#fs.existsSync(this.#context.builtinsPath)) {
248
- this.#fs.mkdirSync(this.#context.builtinsPath, {
249
- recursive: true
250
- });
251
- }
252
- if (!this.#fs.existsSync(this.#context.entryPath)) {
253
- this.#fs.mkdirSync(this.#context.entryPath, {
254
- recursive: true
255
- });
256
- }
257
- if (!this.#fs.existsSync(this.#context.dtsPath)) {
258
- this.#fs.mkdirSync(this.#context.dtsPath, {
259
- recursive: true
260
- });
261
- }
262
- }
263
- this.#log = extendLog(this.#context.log, "virtual-file-system");
264
- }
265
- [__VFS_INIT__]() {
266
- if (!this.#isPatched && this.#context.config.output.mode !== "fs") {
267
- this.#revert = patchFS(fs, this);
268
- this.#isPatched = true;
269
- }
270
- }
271
- [__VFS_REVERT__]() {
272
- if (this.#isPatched && this.#context.config.output.mode !== "fs") {
273
- if (!this.#revert) {
274
- throw new Error("Attempting to revert File System patch prior to calling `__init__` function");
275
- }
276
- this.#revert?.();
277
- this.#isPatched = false;
278
- }
279
- }
280
- /**
281
- * Returns a Map of all runtime file IDs and their corresponding paths in the virtual file system.
282
- *
283
- * @returns A Map where the keys are runtime file IDs (strings) and the values are their corresponding paths (strings).
284
- */
285
- get builtinIdMap() {
286
- return this.#builtinIdMap;
287
- }
288
- /**
289
- * Lists all runtime IDs in the virtual file system.
290
- *
291
- * @returns An array of formatted runtime IDs.
292
- */
293
- get runtimeIds() {
294
- return Array.from(this.builtinIdMap.keys()).map((id) => this.formatRuntimeId(id));
295
- }
296
- /**
297
- * Checks if a given path or ID corresponds to a runtime file.
298
- *
299
- * @param pathOrId - The path or ID to check.
300
- * @param options - Options for resolving the path, such as paths to check.
301
- * @returns `true` if the path or ID corresponds to a runtime file, otherwise `false`.
302
- */
303
- isBuiltinFile(pathOrId, options) {
304
- return !!this.builtinIdMap.values().find((path2) => path2 === this.resolvePath(pathOrId, {
305
- ...options,
306
- type: "file"
307
- }));
308
- }
309
- /**
310
- * Checks if a provided string is a valid runtime ID (does not need to already be created in the file system).
311
- *
312
- * @param id - The ID to check.
313
- * @returns Whether the ID is a valid runtime ID.
314
- */
315
- isValidBuiltinId(id) {
316
- return id.startsWith(`${this.#context.config.output.builtinPrefix}:`);
317
- }
318
- /**
319
- * Check if a path or ID corresponds to a virtual file.
320
- *
321
- * @param pathOrId - The path or ID to check.
322
- * @param options - Options for resolving the path, such as paths to check.
323
- * @returns Whether the path or ID corresponds to a virtual file.
324
- */
325
- isVirtualFile(pathOrId, options = {}) {
326
- if (!pathOrId) {
327
- return false;
328
- }
329
- const resolvedPath = this.resolvePath(pathOrId, {
330
- ...options,
331
- type: "file"
332
- });
333
- if (!resolvedPath) {
334
- return false;
335
- }
336
- if (this.builtinIdMap.values().find((path2) => path2 === resolvedPath)) {
337
- return true;
338
- }
339
- return this.#virtualFS.existsSync(resolvedPath);
340
- }
341
- /**
342
- * Check if a path exists within one of the directories specified in the tsconfig.json's `path` field.
343
- *
344
- * @see https://www.typescriptlang.org/tsconfig#paths
345
- *
346
- * @param pathOrId - The path or ID to check.
347
- * @returns Whether the path or ID corresponds to a virtual file.
348
- */
349
- isTsconfigPath(pathOrId) {
350
- return !!this.#context.tsconfig.options.paths && Object.keys(this.#context.tsconfig.options.paths).some((path2) => pathOrId.startsWith(path2.replaceAll("*", "")));
351
- }
352
- /**
353
- * Checks if a given ID corresponds to a runtime file path.
354
- *
355
- * @param id - The unique identifier for the runtime file.
356
- * @param pathOrId - The path or ID to check.
357
- * @returns `true` if the ID corresponds to the path or ID of a runtime file, otherwise `false`.
358
- */
359
- isMatchingBuiltinId(id, pathOrId) {
360
- const resolvedPath = this.resolvePath(pathOrId);
361
- const resolvedId = this.resolveId(pathOrId);
362
- return !!(this.isBuiltinFile(pathOrId) && (resolvedPath && (resolvedPath === this.builtinIdMap.get(id) || resolvedPath === this.builtinIdMap.get(this.formatRuntimeId(id))) || resolvedId && (resolvedId === this.builtinIdMap.get(id) || resolvedId === this.builtinIdMap.get(this.formatRuntimeId(id)))));
363
- }
364
- /**
365
- * Lists all runtime files in the virtual file system.
366
- *
367
- * @returns A promise that resolves to an array of runtime files.
368
- */
369
- async listBuiltinFiles() {
370
- const runtimeFiles = [];
371
- for (const [id, path2] of this.builtinIdMap.entries()) {
372
- const contents = await this.readFile(path2);
373
- if (contents) {
374
- runtimeFiles.push({
375
- id: this.formatRuntimeId(id),
376
- path: path2,
377
- contents
378
- });
379
- }
380
- }
381
- return runtimeFiles;
382
- }
383
- /**
384
- * Lists files in a given path.
385
- *
386
- * @param path - The path to list files from.
387
- * @param options - Options for listing files, such as encoding and recursion.
388
- * @returns An array of file names in the specified path.
389
- */
390
- readdirSync(path2, options = "utf8") {
391
- return this.resolveFS(path2).readdirSync(toFilePath(path2), options);
392
- }
393
- /**
394
- * Removes a file in the virtual file system (VFS).
395
- *
396
- * @param path - The path to create the directory at.
397
- */
398
- unlinkSync(path2, options) {
399
- const formattedPath = toFilePath(path2);
400
- if (!this.fileExistsSync(path2)) {
401
- return;
402
- }
403
- this.#log(LogLevelLabel.TRACE, `Synchronously removing file: ${formattedPath}`);
404
- this.resolveFS(path2, options).unlinkSync(formattedPath);
405
- this.#cachedFS.delete(formattedPath);
406
- this.clearResolverCache(formattedPath);
407
- }
408
- /**
409
- * Removes a file in the virtual file system (VFS).
410
- *
411
- * @param path - The path to create the directory at.
412
- */
413
- async unlink(path2, options) {
414
- const formattedPath = toFilePath(path2);
415
- if (!this.fileExistsSync(path2)) {
416
- return;
417
- }
418
- this.#log(LogLevelLabel.TRACE, `Removing file: ${formattedPath}`);
419
- if (isFunction(this.resolveFS(path2, options).promises.unlink)) {
420
- await this.resolveFS(path2, options).promises.unlink(formattedPath);
421
- this.#cachedFS.delete(formattedPath);
422
- this.clearResolverCache(formattedPath);
423
- } else {
424
- this.unlinkSync(formattedPath, options);
425
- }
426
- }
427
- /**
428
- * Removes a directory in the virtual file system (VFS).
429
- *
430
- * @param path - The path to create the directory at.
431
- * @param options - Options for creating the directory.
432
- */
433
- rmdirSync(path2, options = {}) {
434
- const formattedPath = toFilePath(path2);
435
- if (!this.directoryExistsSync(path2)) {
436
- return;
437
- }
438
- this.#log(LogLevelLabel.TRACE, `Synchronously removing directory: ${formattedPath}`);
439
- this.resolveFS(path2, options).rmdirSync(formattedPath, defu5(options, {
440
- recursive: true
441
- }));
442
- this.#cachedFS.delete(formattedPath);
443
- this.clearResolverCache(formattedPath);
444
- }
445
- /**
446
- * Removes a directory in the virtual file system (VFS).
447
- *
448
- * @param path - The path to create the directory at.
449
- * @param options - Options for creating the directory.
450
- * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
451
- */
452
- async rmdir(path2, options = {}) {
453
- const formattedPath = toFilePath(path2);
454
- if (!this.directoryExistsSync(path2)) {
455
- return;
456
- }
457
- this.#log(LogLevelLabel.TRACE, `Removing directory: ${formattedPath}`);
458
- if (isFunction(this.resolveFS(path2, options).promises.rm)) {
459
- await this.resolveFS(path2, options).promises.rm(formattedPath, defu5(options, {
460
- force: true,
461
- recursive: true
462
- }));
463
- this.#cachedFS.delete(formattedPath);
464
- this.clearResolverCache(formattedPath);
465
- } else {
466
- this.rmdirSync(formattedPath, defu5(options ?? {}, {
467
- force: true,
468
- recursive: true
469
- }));
470
- }
471
- }
472
- /**
473
- * Removes a file in the virtual file system (VFS).
474
- *
475
- * @param path - The path to the file to remove.
476
- * @param options - Options for removing the file.
477
- * @returns A promise that resolves when the file is removed.
478
- */
479
- async rm(path2, options = {}) {
480
- this.#log(LogLevelLabel.TRACE, `Removing: ${toFilePath(path2)}`);
481
- if (this.directoryExistsSync(path2)) {
482
- return this.rmdir(path2, options);
483
- }
484
- return this.unlink(path2, options);
485
- }
486
- /**
487
- * Creates a directory in the virtual file system (VFS).
488
- *
489
- * @param path - The path to create the directory at.
490
- * @param options - Options for creating the directory.
491
- * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
492
- */
493
- mkdirSync(path2, options = {}) {
494
- const filePath = toFilePath(path2);
495
- this.clearResolverCache(filePath);
496
- return this.resolveFS(filePath, options).mkdirSync(filePath, defu5(options ?? {}, {
497
- recursive: true
498
- }));
499
- }
500
- /**
501
- * Creates a directory in the virtual file system (VFS).
502
- *
503
- * @param path - The path to create the directory at.
504
- * @param options - Options for creating the directory.
505
- * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
506
- */
507
- async mkdir(path2, options = {}) {
508
- let result;
509
- const filePath = toFilePath(path2);
510
- if (isFunction(this.resolveFS(filePath, options).promises.mkdir)) {
511
- result = await this.resolveFS(filePath, options).promises.mkdir(filePath, defu5(options ?? {}, {
512
- recursive: true
513
- }));
514
- } else {
515
- result = this.resolveFS(filePath, options).mkdirSync(filePath, defu5(options ?? {}, {
516
- recursive: true
517
- }));
518
- }
519
- this.clearResolverCache(filePath);
520
- return result;
521
- }
522
- /**
523
- * Lists files in a given path.
524
- *
525
- * @param path - The path to list files from.
526
- * @param options - Options for listing files, such as encoding and recursion.
527
- * @returns An array of file names in the specified path.
528
- */
529
- async readdir(path2, options = "utf8") {
530
- return this.resolveFS(path2).promises.readdir(toFilePath(path2), options);
531
- }
532
- /**
533
- * Asynchronously reads a file from the virtual file system (VFS).
534
- *
535
- * @param pathOrId - The path or ID of the file to read.
536
- * @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
537
- */
538
- async readFile(pathOrId, options = "utf8") {
539
- if (!pathOrId) {
540
- return void 0;
541
- }
542
- const filePath = this.resolvePath(toFilePath(pathOrId), {
543
- type: "file"
544
- });
545
- if (filePath) {
546
- if (this.#cachedFS.has(filePath)) {
547
- return this.#cachedFS.get(filePath);
548
- }
549
- let result;
550
- if (isFunction(this.resolveFS(filePath).promises.readFile)) {
551
- result = (await this.resolveFS(filePath).promises.readFile(filePath, options))?.toString("utf8");
552
- } else {
553
- result = this.resolveFS(filePath).readFileSync(filePath, options);
554
- }
555
- const content = isBuffer(result) ? bufferToString(result) : result;
556
- this.#cachedFS.set(filePath, content);
557
- return content;
558
- }
559
- return void 0;
560
- }
561
- /**
562
- * Synchronously reads a file from the virtual file system (VFS).
563
- *
564
- * @param pathOrId - The path or ID of the file to read.
565
- * @returns The contents of the file as a string, or undefined if the file does not exist.
566
- */
567
- readFileSync(pathOrId, options = "utf8") {
568
- if (!pathOrId) {
569
- return void 0;
570
- }
571
- const filePath = this.resolvePath(toFilePath(pathOrId), {
572
- type: "file"
573
- });
574
- if (filePath) {
575
- if (this.#cachedFS.has(filePath)) {
576
- return this.#cachedFS.get(filePath);
577
- }
578
- const result = this.resolveFS(filePath).readFileSync(filePath, options);
579
- const content = isBuffer(result) ? bufferToString(result) : result;
580
- this.#cachedFS.set(filePath, content);
581
- return content;
582
- }
583
- return void 0;
584
- }
585
- /**
586
- * Writes a file to the virtual file system (VFS).
587
- *
588
- * @param file - The path to the file.
589
- * @param data - The contents of the file.
590
- * @param options - Optional parameters for writing the file.
591
- * @returns A promise that resolves when the file is written.
592
- */
593
- async writeFile(file, data = "", options = "utf8") {
594
- const absolutePath = this.formatAbsoluteFilePath(toFilePath(file));
595
- if (!this.directoryExistsSync(findFilePath(absolutePath))) {
596
- await this.mkdir(findFilePath(absolutePath), options);
597
- }
598
- this.#log(LogLevelLabel.TRACE, `Writing ${absolutePath} file to the ${this.resolveOutputMode(absolutePath, options) === "fs" ? "" : "virtual "}file system (size: ${prettyBytes(new Blob(toArray(data)).size)})`);
599
- this.#cachedFS.set(absolutePath, data.toString());
600
- this.clearResolverCache(absolutePath);
601
- const ifs = this.resolveFS(absolutePath, options);
602
- if (isFunction(ifs.promises.writeFile)) {
603
- return ifs.promises.writeFile(absolutePath, data, omit(options, [
604
- "mode"
605
- ]));
606
- }
607
- return ifs.writeFileSync(absolutePath, data, omit(options, [
608
- "mode"
609
- ]));
610
- }
611
- /**
612
- * Synchronously writes a file to the virtual file system (VFS).
613
- *
614
- * @param file - The file to write.
615
- * @param data - The contents of the file.
616
- * @param options - Optional parameters for writing the file.
617
- */
618
- writeFileSync(file, data = "", options = "utf8") {
619
- const absolutePath = this.formatAbsoluteFilePath(toFilePath(file));
620
- if (!this.directoryExistsSync(findFilePath(absolutePath))) {
621
- this.mkdirSync(findFilePath(absolutePath));
622
- }
623
- this.#log(LogLevelLabel.TRACE, `Writing ${absolutePath} file to the ${this.resolveOutputMode(absolutePath, options) === "fs" ? "" : "virtual "} (size: ${prettyBytes(new Blob(toArray(data)).size)})`);
624
- this.#cachedFS.set(absolutePath, data.toString());
625
- this.clearResolverCache(absolutePath);
626
- const writeStream = this.resolveFS(absolutePath, omit(options, [
627
- "mode"
628
- ])).createWriteStream(absolutePath);
629
- try {
630
- writeStream.write(data);
631
- } finally {
632
- writeStream.close();
633
- }
634
- }
635
- /**
636
- * Writes a runtime file to the virtual file system (VFS).
637
- *
638
- * @param id - The unique identifier for the runtime file.
639
- * @param path - The path to the runtime file.
640
- * @param contents - The contents of the runtime file.
641
- * @param options - Optional parameters for writing the runtime file.
642
- * @returns A promise that resolves when the file is written.
643
- */
644
- async writeBuiltinFile(id, path2, contents, options = {}) {
645
- const formattedId = this.formatRuntimeId(id);
646
- const absolutePath = this.formatAbsoluteFilePath(toFilePath(path2));
647
- this.builtinIdMap.set(formattedId, absolutePath);
648
- let data = contents;
649
- if (!options.skipFormat) {
650
- data = await format(contents, {
651
- absolutePath,
652
- ...await resolveConfig(absolutePath)
653
- });
654
- }
655
- const _options = defu5(isSetString(options) ? {} : options ?? {}, {
656
- encoding: isSetString(options) ? options : "utf8",
657
- mode: "virtual"
658
- });
659
- this.#log(LogLevelLabel.DEBUG, `Writing runtime file ${absolutePath} (size: ${prettyBytes(new Blob(toArray(data)).size)}) to ${this.resolveOutputMode(absolutePath, _options) === "fs" ? "disk" : "memory"}`);
660
- return this.writeFile(absolutePath, data, _options);
661
- }
662
- /**
663
- * Adds an entry file to the virtual file system.
664
- *
665
- * @param name - The file name or absolute path of the entry module.
666
- * @param contents - The contents of the entry file.
667
- * @param options - Optional parameters for writing the entry file.
668
- */
669
- async writeEntryFile(name, contents, options = {}) {
670
- const absolutePath = this.formatAbsoluteFilePath(isAbsolutePath(toFilePath(name)) ? toFilePath(name) : toFilePath(joinPaths(this.#context.entryPath, name)));
671
- let data = contents;
672
- if (!options.skipFormat) {
673
- data = await format(contents, {
674
- absolutePath,
675
- ...await resolveConfig(absolutePath)
676
- });
677
- }
678
- const _options = defu5(isSetString(options) ? {} : options ?? {}, {
679
- encoding: isSetString(options) ? options : "utf8",
680
- mode: "virtual"
681
- });
682
- this.#log(LogLevelLabel.DEBUG, `Writing entry file ${absolutePath} (size: ${prettyBytes(new Blob(toArray(data)).size)}) to ${this.resolveOutputMode(absolutePath, _options) === "fs" ? "disk" : "virtual memory"}`);
683
- return this.writeFile(absolutePath, data, _options);
684
- }
685
- /**
686
- * Writes a file to disk from the physical file system (on disk).
687
- *
688
- * @param path - The path to the file to write.
689
- * @param contents - The contents of the file to write.
690
- * @param options - Optional parameters for writing the file.
691
- * @returns A promise that resolves when the file is written.
692
- */
693
- async writeFileToDisk(path2, contents, options = {}) {
694
- const absolutePath = this.formatAbsoluteFilePath(toFilePath(path2));
695
- let data = contents;
696
- if (!options.skipFormat) {
697
- const resolvedConfig = await resolveConfig(absolutePath);
698
- if (resolvedConfig) {
699
- data = await format(contents, {
700
- absolutePath,
701
- ...resolvedConfig
702
- });
703
- }
704
- }
705
- return this.writeFile(absolutePath, data, defu5({
706
- mode: "fs"
707
- }, isSetString(options) ? {} : options ?? {}, {
708
- encoding: isSetString(options) ? options : "utf8"
709
- }));
710
- }
711
- /**
712
- * Synchronously checks if a file exists in the virtual file system (VFS).
713
- *
714
- * @param pathOrId - The path or ID of the file to check.
715
- * @returns `true` if the file exists, otherwise `false`.
716
- */
717
- existsSync(pathOrId) {
718
- return this.pathExistsSync(this.resolvePath(toFilePath(pathOrId)) || toFilePath(pathOrId));
719
- }
720
- /**
721
- * Checks if a file exists in the virtual file system (VFS).
722
- *
723
- * @remarks
724
- * This is a base method used by {@link existsSync} - it does not try to resolve the path prior to checking if it exists or not.
725
- *
726
- * @param path - The path of the file to check.
727
- * @returns `true` if the file exists, otherwise `false`.
728
- */
729
- fileExistsSync(path2) {
730
- const formattedPath = this.formatAbsoluteFilePath(toFilePath(path2));
731
- return this.isValidBuiltinId(formattedPath) || this.#virtualFS.existsSync(formattedPath) && this.#virtualFS.lstatSync(formattedPath).isFile() || this.#fs.existsSync(formattedPath) && this.#fs.lstatSync(formattedPath).isFile() || this.resolveFS(path2).existsSync(formattedPath) && this.resolveFS(path2).lstatSync(formattedPath).isFile();
732
- }
733
- /**
734
- * Checks if a directory exists in the virtual file system (VFS).
735
- *
736
- * @param path - The path of the directory to check.
737
- * @returns `true` if the directory exists, otherwise `false`.
738
- */
739
- directoryExistsSync(path2) {
740
- const formattedPath = this.formatAbsoluteFilePath(toFilePath(path2));
741
- return this.#virtualFS.existsSync(formattedPath) && this.#virtualFS.lstatSync(formattedPath).isDirectory() || this.#fs.existsSync(formattedPath) && this.#fs.lstatSync(formattedPath).isDirectory() || this.resolveFS(path2).existsSync(formattedPath) && this.resolveFS(path2).lstatSync(formattedPath).isDirectory();
742
- }
743
- /**
744
- * Checks if a path exists in the virtual file system (VFS).
745
- *
746
- * @param path - The path to check.
747
- * @returns `true` if the path exists, otherwise `false`.
748
- */
749
- pathExistsSync(path2) {
750
- const formattedPath = this.formatAbsoluteFilePath(toFilePath(path2));
751
- return this.isValidBuiltinId(formattedPath) || this.#virtualFS.existsSync(formattedPath) || this.#fs.existsSync(formattedPath) || this.resolveFS(path2).existsSync(formattedPath);
752
- }
753
- /**
754
- * Retrieves the status of a file in the virtual file system (VFS).
755
- *
756
- * @param pathOrId - The path or ID of the file to retrieve status for.
757
- * @returns A promise that resolves to the file's status information, or false if the file does not exist.
758
- */
759
- async stat(pathOrId, options) {
760
- return this.resolveFS(pathOrId).promises.stat(this.resolvePath(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
761
- }
762
- /**
763
- * Synchronously retrieves the status of a file in the virtual file system (VFS).
764
- *
765
- * @param pathOrId - The path or ID of the file to retrieve status for.
766
- * @returns The file's status information, or false if the file does not exist.
767
- */
768
- statSync(pathOrId) {
769
- return this.resolveFS(pathOrId).statSync(this.resolvePath(toFilePath(pathOrId)) || toFilePath(pathOrId));
770
- }
771
- /**
772
- * Retrieves the status of a symbolic link in the virtual file system (VFS).
773
- *
774
- * @param pathOrId - The path or ID of the symbolic link to retrieve status for.
775
- * @returns A promise that resolves to the symbolic link's status information, or false if the link does not exist.
776
- */
777
- async lstat(pathOrId, options) {
778
- return this.resolveFS(pathOrId).promises.lstat(this.resolvePath(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
779
- }
780
- /**
781
- * Synchronously retrieves the status of a symbolic link in the virtual file system (VFS).
782
- *
783
- * @param pathOrId - The path or ID of the symbolic link to retrieve status for.
784
- * @returns The symbolic link's status information, or false if the link does not exist.
785
- */
786
- lstatSync(pathOrId, options) {
787
- return this.resolveFS(pathOrId).lstatSync(this.resolvePath(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
788
- }
789
- /**
790
- * Resolves a path or ID to a runtime file id in the virtual file system.
791
- *
792
- * @param pathOrId - The path or id of the file to resolve.
793
- * @returns The resolved id of the runtime file if it exists, otherwise false.
794
- */
795
- resolveId(pathOrId) {
796
- if (this.builtinIdMap.has(this.formatRuntimeId(toFilePath(pathOrId)))) {
797
- return this.formatRuntimeId(toFilePath(pathOrId));
798
- }
799
- const filePath = this.resolvePath(toFilePath(pathOrId));
800
- if (filePath) {
801
- return this.builtinIdMap.keys().find((id) => this.builtinIdMap.get(id) === filePath) || false;
802
- }
803
- return false;
804
- }
805
- /**
806
- * Resolves a path based on TypeScript's `tsconfig.json` paths.
807
- *
808
- * @see https://www.typescriptlang.org/tsconfig#paths
809
- *
810
- * @param path - The path to check.
811
- * @returns The resolved file path if it exists, otherwise undefined.
812
- */
813
- resolveTsconfigPath(path2) {
814
- if (this.#context.tsconfig.options.paths) {
815
- for (const tsconfigPathKey of Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path2.startsWith(tsconfigPath.replaceAll("*", "")))) {
816
- const resolvedPath = this.#context.tsconfig.options.paths[tsconfigPathKey]?.find((tsconfigPath) => this.resolvePathName(joinPaths(this.#context.workspaceConfig.workspaceRoot, tsconfigPath.replaceAll("*", ""), path2.replace(tsconfigPathKey.replaceAll("*", ""), ""))) || this.formatAbsoluteFilePath(tsconfigPath) === this.formatAbsoluteFilePath(path2));
817
- if (resolvedPath) {
818
- return this.formatAbsoluteFilePath(resolvedPath) === this.formatAbsoluteFilePath(path2) ? this.formatAbsoluteFilePath(resolvedPath) : this.resolvePathName(joinPaths(this.#context.workspaceConfig.workspaceRoot, resolvedPath.replaceAll("*", ""), path2.replace(tsconfigPathKey.replaceAll("*", ""), "")));
819
- }
820
- }
821
- }
822
- return false;
823
- }
824
- /**
825
- * Resolves a path based on TypeScript's `tsconfig.json` paths.
826
- *
827
- * @see https://www.typescriptlang.org/tsconfig#paths
828
- *
829
- * @param path - The path to check.
830
- * @returns The resolved file path if it exists, otherwise undefined.
831
- */
832
- resolveTsconfigPathPackage(path2) {
833
- if (this.#context.tsconfig.options.paths) {
834
- const tsconfigPathKeys = Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path2.startsWith(tsconfigPath.replaceAll("*", "")));
835
- if (tsconfigPathKeys.length > 0 && tsconfigPathKeys[0]) {
836
- return tsconfigPathKeys[0].replace(/\/\*$/, "");
837
- }
838
- }
839
- return false;
840
- }
841
- /**
842
- * Resolves a path or ID to its real path in the virtual file system (VFS).
843
- *
844
- * @param pathOrId - The path or ID to resolve.
845
- * @returns The resolved real path if it exists, otherwise undefined.
846
- */
847
- realpathSync(pathOrId) {
848
- const filePath = this.resolvePath(toFilePath(pathOrId));
849
- if (!filePath) {
850
- throw new Error(`File not found: ${toFilePath(pathOrId)}`);
851
- }
852
- return filePath;
853
- }
854
- /**
855
- * Resolves a path or ID parameter to a corresponding virtual file path in the virtual file system (VFS).
856
- *
857
- * @param pathOrId - The path or ID to resolve.
858
- * @param options - Optional parameters for resolving the path, such as whether to include the file extension.
859
- * @returns The resolved file path if it exists, otherwise undefined.
860
- */
861
- resolvePath(pathOrId, options = {}) {
862
- const formattedPath = toFilePath(pathOrId);
863
- const resolverKey = `${formattedPath}${options.withExtension ? "-ext" : ""}${options.paths ? `-${murmurhash(options.paths)}` : ""}${options.type ? `-${options.type}` : ""}`;
864
- if (this.#cachedResolver.has(resolverKey)) {
865
- return this.#cachedResolver.get(resolverKey);
866
- } else if (this.#cachedFS.has(formattedPath)) {
867
- return formattedPath;
868
- }
869
- let result = false;
870
- if (this.isValidBuiltinId(formattedPath)) {
871
- result = this.builtinIdMap.get(this.formatRuntimeId(formattedPath));
872
- } else {
873
- result = this.resolvePathName(formattedPath, options);
874
- }
875
- if (!result) {
876
- result = false;
877
- } else {
878
- result = toFilePath(result);
879
- }
880
- if (result && options.withExtension === false) {
881
- return result.replace(/\.[m|c]?[t|j]sx?$/, "");
882
- }
883
- this.#cachedResolver.set(resolverKey, result);
884
- return result;
885
- }
886
- /**
887
- * Formats a file path by removing the runtime prefix and leading null character.
888
- *
889
- * @param path - The file path to format.
890
- * @returns The formatted file path.
891
- */
892
- formatFilePath(path2) {
893
- if (!isSetString(path2)) {
894
- throw new Error(`Invalid path provided. Expected a string or a valid file path.`);
895
- }
896
- return path2.replace(new RegExp(`^${this.#context.config.output.builtinPrefix}:`), "").replace(/^\\0/, "");
897
- }
898
- /**
899
- * Converts a relative path to an absolute path based on the workspace and project root.
900
- *
901
- * @param path - The relative path to convert.
902
- * @returns The absolute path.
903
- */
904
- formatAbsoluteFilePath = /* @__PURE__ */ __name((path2) => {
905
- const formattedPath = this.formatFilePath(path2);
906
- if (isAbsolutePath(formattedPath) || formattedPath.startsWith(this.#context.workspaceConfig.workspaceRoot)) {
907
- return formattedPath;
908
- } else if (formattedPath.startsWith(this.#context.config.projectRoot)) {
909
- return joinPaths(this.#context.workspaceConfig.workspaceRoot, formattedPath);
910
- }
911
- return formattedPath;
912
- }, "formatAbsoluteFilePath");
913
- /**
914
- * Formats a runtime ID by removing the file extension and prepending the runtime prefix.
915
- *
916
- * @param id - The runtime ID to format.
917
- * @returns The formatted runtime ID.
918
- */
919
- formatRuntimeId(id) {
920
- return `${this.#context.config.output.builtinPrefix}:${this.formatFilePath(id).replace(/\.[m|c]?[t|j]sx?$/, "")}`;
921
- }
922
- /**
923
- * Resolves a path or ID parameter to a corresponding virtual file path in the virtual file system (VFS).
924
- *
925
- * @param pathOrId - The path or ID to resolve.
926
- * @returns The resolved file path if it exists, otherwise undefined.
927
- */
928
- resolvePathName(pathOrId, options = {}) {
929
- if (pathOrId.startsWith(`${this.#context.config.output.builtinPrefix}:`)) {
930
- return false;
931
- }
932
- if (isAbsolutePath(pathOrId)) {
933
- if (options.type === "file" ? this.fileExistsSync(pathOrId) : this.pathExistsSync(pathOrId)) {
934
- return pathOrId;
935
- }
936
- const result = checkVariants(pathOrId, this);
937
- if (result) {
938
- return result;
939
- }
940
- }
941
- for (const path2 of this.resolveParentPaths(pathOrId, options.paths)) {
942
- const request = joinPaths(path2, pathOrId);
943
- if (options.type === "file" ? this.fileExistsSync(pathOrId) : this.pathExistsSync(pathOrId)) {
944
- return request;
945
- }
946
- const result = checkVariants(request, this);
947
- if (result) {
948
- return result;
949
- }
950
- }
951
- return false;
952
- }
953
- resolveParentPaths(request, current = []) {
954
- let paths = [
955
- this.#context.workspaceConfig.workspaceRoot,
956
- joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot)
957
- ];
958
- if (this.#context.tsconfig.options.paths) {
959
- paths = this.#context.tsconfig.options.paths ? Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => request.startsWith(tsconfigPath.replaceAll("*", ""))).map((tsconfigPath) => this.#context.tsconfig.options.paths?.[tsconfigPath]).flat().reduce((ret, path2) => {
960
- if (path2 && !ret.includes(joinPaths(this.#context.workspaceConfig.workspaceRoot, path2))) {
961
- ret.push(joinPaths(this.#context.workspaceConfig.workspaceRoot, path2));
962
- }
963
- return ret;
964
- }, paths) : paths;
965
- }
966
- return paths.reduce((ret, path2) => {
967
- if (!ret.includes(path2)) {
968
- ret.push(path2);
969
- }
970
- return ret;
971
- }, current.filter(Boolean).map((p) => this.formatAbsoluteFilePath(toFilePath(p))));
972
- }
973
- /**
974
- * Select the file system module to use for the operation based on the path or URL.
975
- *
976
- * @param pathOrUrl - The path to perform the file system operation on.
977
- * @param options - Options for the operation, such as output mode.
978
- * @returns The file system module used for the operation.
979
- */
980
- resolveFS(pathOrUrl, options = {}) {
981
- const mode = this.resolveOutputMode(pathOrUrl, options);
982
- if (mode === "virtual") {
983
- return this.#virtualFS;
984
- } else if (mode === "fs") {
985
- return this.#fs;
986
- }
987
- return this.#unifiedFS;
988
- }
989
- /**
990
- * Select the file system module to use for the operation based on the path or URL.
991
- *
992
- * @param pathOrUrl - The path to perform the file system operation on.
993
- * @param options - Options for the operation, such as output mode.
994
- * @returns The file system module used for the operation.
995
- */
996
- resolveOutputMode(pathOrUrl, options = {}) {
997
- if (options.mode === "virtual" && this.#context.config.output.mode !== "fs" && isParentPath(toFilePath(pathOrUrl), this.#context.artifactsPath)) {
998
- return "virtual";
999
- } else if (options.mode === "fs" || this.#context.config.output.mode === "fs" || isParentPath(toFilePath(pathOrUrl), this.#context.dataPath) || isParentPath(toFilePath(pathOrUrl), this.#context.cachePath) || isParentPath(toFilePath(pathOrUrl), joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
1000
- return "fs";
1001
- }
1002
- return null;
1003
- }
1004
- /**
1005
- * Clears the resolver cache for a given path.
1006
- *
1007
- * @param path - The path to clear the resolver cache for.
1008
- */
1009
- clearResolverCache(path2) {
1010
- this.#cachedResolver.keys().filter((key) => key.startsWith(toFilePath(path2))).forEach((key) => this.#cachedResolver.delete(key));
1011
- }
1012
- });
1013
- var FILE_PREFIX = "file://";
1014
- function toFilePath(pathOrUrl) {
1015
- if (!pathOrUrl) {
1016
- throw new Error("No Path or URL provided to Virtual File System");
1017
- }
1018
- let result = pathOrUrl.toString();
1019
- if (result.startsWith(FILE_PREFIX)) {
1020
- result = result.slice(FILE_PREFIX.length);
1021
- }
1022
- return result;
1023
- }
1024
- __name(toFilePath, "toFilePath");
1025
- var FS_METHODS = [
1026
- "mkdir",
1027
- "mkdirSync",
1028
- "rmdir",
1029
- "rmdirSync",
1030
- "unlink",
1031
- "unlinkSync",
1032
- "existsSync",
1033
- "realpathSync",
1034
- "writeFileSync",
1035
- "readFileSync",
1036
- "readdirSync",
1037
- "createWriteStream",
1038
- "WriteStream",
1039
- "createReadStream",
1040
- "ReadStream"
1041
- ];
1042
- var FS_PROMISE_METHODS = [
1043
- "mkdir",
1044
- "rm",
1045
- "rmdir",
1046
- "unlink",
1047
- "writeFile",
1048
- "readFile",
1049
- "readdir",
1050
- "stat",
1051
- "lstat"
1052
- ];
1053
- function cloneFS(originalFS) {
1054
- const clonedFS = {
1055
- ...originalFS,
1056
- promises: {
1057
- ...originalFS.promises ?? {}
1058
- }
1059
- };
1060
- for (const method of FS_METHODS) {
1061
- if (originalFS[method]) {
1062
- clonedFS[method] = originalFS[method];
1063
- }
1064
- }
1065
- originalFS.promises ??= {};
1066
- for (const method of FS_PROMISE_METHODS) {
1067
- if (originalFS.promises[method]) {
1068
- clonedFS.promises ??= {};
1069
- clonedFS.promises[method] = originalFS.promises[method];
1070
- clonedFS[method] = originalFS.promises[method];
1071
- }
1072
- }
1073
- for (const prop in clonedFS) {
1074
- if (isFunction(clonedFS[prop])) {
1075
- clonedFS[prop] = clonedFS[prop].bind(originalFS);
1076
- if (isFunction(clonedFS.promises[prop])) {
1077
- clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
1078
- }
1079
- }
1080
- }
1081
- for (const prop in clonedFS.promises) {
1082
- if (isFunction(clonedFS.promises[prop])) {
1083
- clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
1084
- }
1085
- }
1086
- return clonedFS;
1087
- }
1088
- __name(cloneFS, "cloneFS");
1089
- function patchFS(originalFS, vfs) {
1090
- const clonedFS = cloneFS(originalFS);
1091
- originalFS.mkdirSync = (file, options) => vfs.mkdirSync(toFilePath(file), options);
1092
- originalFS.mkdir = (file, options, callback) => vfs.mkdir(toFilePath(file), options, callback);
1093
- originalFS.promises.mkdir = async (file, options) => vfs.mkdir(toFilePath(file), options);
1094
- originalFS.unlinkSync = (file) => vfs.unlinkSync(toFilePath(file));
1095
- originalFS.promises.rm = async (file, options) => vfs.rm(toFilePath(file), options);
1096
- originalFS.promises.unlink = async (file) => vfs.unlink(toFilePath(file));
1097
- originalFS.existsSync = (file) => vfs.existsSync(toFilePath(file));
1098
- Object.defineProperty(originalFS, "realpathSync", {
1099
- value: /* @__PURE__ */ __name((file, options) => vfs.realpathSync(toFilePath(file), options), "value")
1100
- });
1101
- originalFS.writeFileSync = (file, data, options) => vfs.writeFileSync(toFilePath(file), data, options);
1102
- originalFS.promises.writeFile = async (file, data, options) => vfs.writeFile(toFilePath(file), data, options);
1103
- originalFS.readFileSync = (file, options) => vfs.readFileSync(toFilePath(file), options);
1104
- originalFS.promises.readFile = (file, options) => vfs.readFile(toFilePath(file), options);
1105
- originalFS.readdirSync = (file, options) => vfs.readdirSync(toFilePath(file), options);
1106
- originalFS.promises.readdir = (file, options) => vfs.readdir(toFilePath(file), options);
1107
- Object.defineProperty(originalFS, "statSync", {
1108
- value: /* @__PURE__ */ __name((file, options) => vfs.statSync(toFilePath(file), options), "value")
1109
- });
1110
- originalFS.stat = (file, options) => vfs.statSync(toFilePath(file), options);
1111
- originalFS.promises.stat = (file, options) => vfs.stat(toFilePath(file), options);
1112
- Object.defineProperty(originalFS, "lstatSync", {
1113
- value: /* @__PURE__ */ __name((file, options) => vfs.lstatSync(toFilePath(file), options), "value")
1114
- });
1115
- originalFS.lstat = (file, options) => vfs.lstatSync(toFilePath(file), options);
1116
- originalFS.promises.lstat = (file, options) => vfs.lstat(toFilePath(file), options);
1117
- return () => {
1118
- originalFS.mkdirSync = clonedFS.mkdirSync;
1119
- originalFS.mkdir = clonedFS.mkdir;
1120
- originalFS.promises.mkdir = clonedFS.promises.mkdir;
1121
- originalFS.unlinkSync = clonedFS.unlinkSync;
1122
- originalFS.promises.rm = clonedFS.promises.rm;
1123
- originalFS.promises.unlink = clonedFS.promises.unlink;
1124
- originalFS.existsSync = clonedFS.existsSync;
1125
- originalFS.realpathSync = clonedFS.realpathSync;
1126
- originalFS.writeFileSync = clonedFS.writeFileSync;
1127
- originalFS.promises.writeFile = clonedFS.promises.writeFile;
1128
- originalFS.readFileSync = clonedFS.readFileSync;
1129
- originalFS.promises.readFile = clonedFS.promises.readFile;
1130
- originalFS.readdirSync = clonedFS.readdirSync;
1131
- originalFS.promises.readdir = clonedFS.promises.readdir;
1132
- Object.defineProperty(originalFS, "statSync", {
1133
- value: clonedFS.statSync
1134
- });
1135
- originalFS.stat = clonedFS.stat;
1136
- originalFS.promises.stat = clonedFS.promises.stat;
1137
- Object.defineProperty(originalFS, "lstatSync", {
1138
- value: clonedFS.lstatSync
1139
- });
1140
- originalFS.lstat = clonedFS.lstat;
1141
- originalFS.promises.lstat = clonedFS.promises.lstat;
1142
- };
1143
- }
1144
- __name(patchFS, "patchFS");
1145
- function checkVariants(request, vfs, parentPath) {
1146
- const path2 = parentPath ? joinPaths(parentPath, request) : request;
1147
- let file = checkExtensions(path2, vfs);
1148
- if (file) {
1149
- return file;
1150
- }
1151
- file = checkIndex(path2, vfs);
1152
- if (file) {
1153
- return file;
1154
- }
1155
- return false;
1156
- }
1157
- __name(checkVariants, "checkVariants");
1158
- function checkIndex(request, vfs) {
1159
- let file = joinPaths(request, "index");
1160
- if (vfs.fileExistsSync(file)) {
1161
- return file;
1162
- }
1163
- file = checkExtensions(file, vfs);
1164
- if (file) {
1165
- return file;
1166
- }
1167
- return false;
1168
- }
1169
- __name(checkIndex, "checkIndex");
1170
- function checkExtensions(request, vfs) {
1171
- let file = `${request}.ts`;
1172
- if (vfs.fileExistsSync(file)) {
1173
- return file;
1174
- }
1175
- file = `${request}.mts`;
1176
- if (vfs.fileExistsSync(file)) {
1177
- return file;
1178
- }
1179
- file = `${request}.cts`;
1180
- if (vfs.fileExistsSync(file)) {
1181
- return file;
1182
- }
1183
- file = `${request}.tsx`;
1184
- if (vfs.fileExistsSync(file)) {
1185
- return file;
1186
- }
1187
- file = `${request}.js`;
1188
- if (vfs.fileExistsSync(file)) {
1189
- return file;
1190
- }
1191
- file = `${request}.mjs`;
1192
- if (vfs.fileExistsSync(file)) {
1193
- return file;
1194
- }
1195
- file = `${request}.cjs`;
1196
- if (vfs.fileExistsSync(file)) {
1197
- return file;
1198
- }
1199
- file = `${request}.jsx`;
1200
- if (vfs.fileExistsSync(file)) {
1201
- return file;
1202
- }
1203
- file = `${request}.json`;
1204
- if (vfs.fileExistsSync(file)) {
1205
- return file;
1206
- }
1207
- file = `${request}.d.ts`;
1208
- if (vfs.fileExistsSync(file)) {
1209
- return file;
1210
- }
1211
- return false;
1212
- }
1213
- __name(checkExtensions, "checkExtensions");
1214
-
1215
- // ../powerlines/src/internal/helpers/eslint.ts
1216
- var MessageSeverity;
1217
- (function(MessageSeverity2) {
1218
- MessageSeverity2[MessageSeverity2["Warning"] = 1] = "Warning";
1219
- MessageSeverity2[MessageSeverity2["Error"] = 2] = "Error";
1220
- })(MessageSeverity || (MessageSeverity = {}));
1221
- function getString(code) {
1222
- if (!code) {
1223
- return "";
1224
- }
1225
- if (isString(code)) {
1226
- return code;
1227
- }
1228
- if (isSetObject(code) && "code" in code) {
1229
- return code.code;
1230
- }
1231
- return code.toString();
1232
- }
1233
- __name(getString, "getString");
1234
- var NON_NODE_MODULE_REGEX = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
1235
- async function handleResolveId(context, args, options = {}) {
1236
- if (args.id) {
1237
- if (context.fs.isVirtualFile(args.id) || args.importer && context.fs.isVirtualFile(args.id, {
1238
- paths: [
1239
- args.importer
1240
- ]
1241
- })) {
1242
- const resolvedPath = args.importer ? context.fs.resolvePath(args.id, {
1243
- paths: [
1244
- args.importer
1245
- ]
1246
- }) : context.fs.resolvePath(args.id);
1247
- if (resolvedPath) {
1248
- return {
1249
- id: resolvedPath,
1250
- external: context.config.projectType !== "application"
1251
- };
1252
- }
1253
- }
1254
- if (context.fs.isTsconfigPath(args.id)) {
1255
- const tsconfigPath = context.fs.resolveTsconfigPath(args.id);
1256
- const tsconfigPathPackage = context.fs.resolveTsconfigPathPackage(args.id);
1257
- if (tsconfigPath && tsconfigPathPackage) {
1258
- return {
1259
- id: tsconfigPath,
1260
- external: Boolean(!options.noExternal?.includes(tsconfigPathPackage) && (options.external?.includes(tsconfigPathPackage) ?? context.config.projectType !== "application"))
1261
- };
1262
- }
1263
- }
1264
- if (options.skipResolve) {
1265
- return void 0;
1266
- }
1267
- if (options.skipNodeModulesBundle) {
1268
- if (match(args.id, options.resolvePatterns) || match(args.id, options.noExternal) || args.id.startsWith("internal:") || args.id.startsWith("virtual:")) {
1269
- return void 0;
1270
- }
1271
- if (match(args.id, options.external) || args.id.startsWith("node:")) {
1272
- return {
1273
- id: args.id,
1274
- external: true
1275
- };
1276
- }
1277
- if (!NON_NODE_MODULE_REGEX.test(args.id)) {
1278
- return {
1279
- id: args.id,
1280
- external: true
1281
- };
1282
- }
1283
- } else {
1284
- if (match(args.id, options.noExternal) || context.fs.isBuiltinFile(args.id) || args.importer && context.fs.isBuiltinFile(args.id, {
1285
- paths: [
1286
- args.importer
1287
- ]
1288
- })) {
1289
- return void 0;
1290
- }
1291
- if (match(args.id, options.external) || args.id.startsWith("node:")) {
1292
- return {
1293
- id: args.id,
1294
- external: true
1295
- };
1296
- }
1297
- }
1298
- }
1299
- return void 0;
1300
- }
1301
- __name(handleResolveId, "handleResolveId");
1302
- function createUnplugin(context, options = {}) {
1303
- const ctx = context;
1304
- return () => {
1305
- const log = extendLog(ctx.log, "unplugin");
1306
- log(LogLevelLabel.DEBUG, "Initializing Unplugin");
1307
- try {
1308
- async function buildStart() {
1309
- log(LogLevelLabel.DEBUG, "Powerlines build plugin starting...");
1310
- await ctx.$$internal.callHook("buildStart", {
1311
- sequential: true
1312
- });
1313
- }
1314
- __name(buildStart, "buildStart");
1315
- async function resolveId(id, importer, opts = {
1316
- isEntry: false
1317
- }) {
1318
- let result = await ctx.$$internal.callHook("resolveId", {
1319
- sequential: true,
1320
- result: "first",
1321
- order: "pre"
1322
- }, id, importer, opts);
1323
- if (result) {
1324
- return result;
1325
- }
1326
- result = await ctx.$$internal.callHook("resolveId", {
1327
- sequential: true,
1328
- result: "first",
1329
- order: "normal"
1330
- }, id, importer, opts);
1331
- if (result) {
1332
- return result;
1333
- }
1334
- result = await handleResolveId(ctx, {
1335
- id,
1336
- importer,
1337
- options: opts
1338
- }, {
1339
- skipResolve: options.skipResolve,
1340
- skipNodeModulesBundle: ctx.config.build.skipNodeModulesBundle,
1341
- external: ctx.config.build.external,
1342
- noExternal: ctx.config.build.noExternal
1343
- });
1344
- if (result) {
1345
- return result;
1346
- }
1347
- return ctx.$$internal.callHook("resolveId", {
1348
- sequential: true,
1349
- result: "first",
1350
- order: "post"
1351
- }, id, importer, opts);
1352
- }
1353
- __name(resolveId, "resolveId");
1354
- async function load(id) {
1355
- let result = await ctx.$$internal.callHook("load", {
1356
- sequential: true,
1357
- result: "first",
1358
- order: "pre"
1359
- }, id);
1360
- if (result) {
1361
- return result;
1362
- }
1363
- result = await ctx.$$internal.callHook("load", {
1364
- sequential: true,
1365
- result: "first",
1366
- order: "normal"
1367
- }, id);
1368
- if (result) {
1369
- return result;
1370
- }
1371
- if (id) {
1372
- const resolvedPath = ctx.fs.resolvePath(id, {
1373
- type: "file"
1374
- });
1375
- if (resolvedPath) {
1376
- return ctx.fs.readFile(resolvedPath);
1377
- }
1378
- }
1379
- return ctx.$$internal.callHook("load", {
1380
- sequential: true,
1381
- result: "first",
1382
- order: "post"
1383
- }, id);
1384
- }
1385
- __name(load, "load");
1386
- async function transform(code, id) {
1387
- let transformed = code;
1388
- for (const handler of ctx.$$internal.environment.selectHooks("transform")) {
1389
- const result = await handler.apply(defu5(ctx, this), [
1390
- getString(transformed),
1391
- id
1392
- ]);
1393
- if (result) {
1394
- transformed = result;
1395
- }
1396
- }
1397
- return transformed;
1398
- }
1399
- __name(transform, "transform");
1400
- async function buildEnd() {
1401
- log(LogLevelLabel.DEBUG, "Powerlines build plugin finishing...");
1402
- return ctx.$$internal.callHook("buildEnd", {
1403
- sequential: true
1404
- });
1405
- }
1406
- __name(buildEnd, "buildEnd");
1407
- async function writeBundle() {
1408
- log(LogLevelLabel.DEBUG, "Finalizing Powerlines project output...");
1409
- return ctx.$$internal.callHook("writeBundle", {
1410
- sequential: true
1411
- });
1412
- }
1413
- __name(writeBundle, "writeBundle");
1414
- return {
1415
- name: "powerlines",
1416
- resolveId: {
1417
- filter: {
1418
- id: {
1419
- include: [
1420
- /.*/
1421
- ]
1422
- }
1423
- },
1424
- handler: resolveId
1425
- },
1426
- load: {
1427
- filter: {
1428
- id: {
1429
- include: [
1430
- /.*/,
1431
- /^storm:/
1432
- ]
1433
- }
1434
- },
1435
- handler: load
1436
- },
1437
- transform,
1438
- buildStart,
1439
- buildFinish: buildEnd,
1440
- writeBundle,
1441
- vite: {
1442
- sharedDuringBuild: true
1443
- }
1444
- };
1445
- } catch (error) {
1446
- log(LogLevelLabel.FATAL, error?.message);
1447
- throw error;
1448
- }
1449
- };
1450
- }
1451
- __name(createUnplugin, "createUnplugin");
1452
- function createESBuildPlugin(context) {
1453
- return createEsbuildPlugin(createUnplugin(context, {
1454
- skipResolve: true
1455
- }))({});
1456
- }
1457
- __name(createESBuildPlugin, "createESBuildPlugin");
1458
-
1459
- export { __name, createESBuildPlugin, resolveEntryInputFile, resolveEntryOutput };
1460
- //# sourceMappingURL=chunk-FGTVQNHX.js.map
1461
- //# sourceMappingURL=chunk-FGTVQNHX.js.map