@powerlines/nx 0.10.9 → 0.10.11

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 (44) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/{chunk-WUF54G5K.js → chunk-32RH3DSY.js} +1408 -1228
  3. package/dist/{chunk-QJEIBIEZ.js → chunk-7SWNXVZN.js} +2 -2
  4. package/dist/{chunk-VP7AMTR6.js → chunk-DKRIOFPB.js} +2 -2
  5. package/dist/{chunk-DVGRVHRD.mjs → chunk-FMYWKI25.mjs} +2 -14
  6. package/dist/{chunk-IUHTUUDE.js → chunk-FZWXH2M7.js} +2 -2
  7. package/dist/{chunk-L5RBARDS.js → chunk-HAP4APOA.js} +3 -3
  8. package/dist/{chunk-M647TAWI.mjs → chunk-IWLY4VEK.mjs} +1 -1
  9. package/dist/{chunk-3TWAKTYR.mjs → chunk-K7X3KSVW.mjs} +1 -1
  10. package/dist/{chunk-4S5RU53T.js → chunk-KJAIPQKC.js} +2 -2
  11. package/dist/{chunk-T52ZTHWM.mjs → chunk-KNIZUAS5.mjs} +1 -1
  12. package/dist/{chunk-UOTRU26N.js → chunk-LTCZN4I4.js} +1 -19
  13. package/dist/{chunk-R4LYPNZD.mjs → chunk-NSFCCGL7.mjs} +1 -1
  14. package/dist/{chunk-QWEMU3V4.mjs → chunk-NSLIDWKJ.mjs} +1 -1
  15. package/dist/{chunk-B3UMNKEM.js → chunk-QJLAFC2D.js} +2 -2
  16. package/dist/{chunk-AX3G6RLK.mjs → chunk-RIB65IPA.mjs} +1 -1
  17. package/dist/{chunk-3WPWHDP3.mjs → chunk-WMZ45WVV.mjs} +1411 -1231
  18. package/dist/executors.js +12 -12
  19. package/dist/executors.mjs +7 -7
  20. package/dist/index.js +14 -14
  21. package/dist/index.mjs +8 -8
  22. package/dist/src/base/base-executor.js +3 -3
  23. package/dist/src/base/base-executor.mjs +2 -2
  24. package/dist/src/executors/build/executor.js +5 -5
  25. package/dist/src/executors/build/executor.mjs +3 -3
  26. package/dist/src/executors/build/schema.d.ts +85 -0
  27. package/dist/src/executors/clean/executor.js +5 -5
  28. package/dist/src/executors/clean/executor.mjs +3 -3
  29. package/dist/src/executors/clean/schema.d.ts +75 -0
  30. package/dist/src/executors/docs/executor.js +5 -5
  31. package/dist/src/executors/docs/executor.mjs +3 -3
  32. package/dist/src/executors/docs/schema.d.ts +75 -0
  33. package/dist/src/executors/lint/executor.js +5 -5
  34. package/dist/src/executors/lint/executor.mjs +3 -3
  35. package/dist/src/executors/lint/schema.d.ts +75 -0
  36. package/dist/src/executors/prepare/executor.js +5 -5
  37. package/dist/src/executors/prepare/executor.mjs +3 -3
  38. package/dist/src/executors/prepare/schema.d.ts +75 -0
  39. package/dist/src/executors/prepare/schema.json +77 -0
  40. package/dist/src/generators/sync/schema.d.ts +15 -0
  41. package/dist/src/generators/sync/schema.json +19 -0
  42. package/dist/src/plugin/index.js +3 -3
  43. package/dist/src/plugin/index.mjs +2 -2
  44. package/package.json +7 -7
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkUOTRU26N_js = require('./chunk-UOTRU26N.js');
3
+ var chunkLTCZN4I4_js = require('./chunk-LTCZN4I4.js');
4
4
  var chunkSHUYVCID_js = require('./chunk-SHUYVCID.js');
5
5
  var logger = require('@storm-software/config-tools/logger');
6
6
  var baseExecutor = require('@storm-software/workspace-tools/base/base-executor');
7
7
  var isError = require('@stryke/type-checks/is-error');
8
- var defu3 = require('defu');
8
+ var defu2 = require('defu');
9
9
  var core = require('@babel/core');
10
10
  var console = require('@storm-software/config-tools/logger/console');
11
11
  var types = require('@storm-software/config-tools/types');
@@ -47,19 +47,21 @@ var uuid = require('@stryke/unique-id/uuid');
47
47
  var oxcParser = require('oxc-parser');
48
48
  var parseTypeDefinition = require('@stryke/convert/parse-type-definition');
49
49
  var isFile = require('@stryke/fs/is-file');
50
- var colors = require('@storm-software/config-tools/utilities/colors');
51
- var noop = require('@stryke/helpers/noop');
52
- var isUndefined = require('@stryke/type-checks/is-undefined');
53
- var jiti = require('jiti');
50
+ var $ = require('@stryke/capnp');
54
51
  var bufferToString = require('@stryke/convert/buffer-to-string');
55
- var isParentPath = require('@stryke/path/is-parent-path');
52
+ var buffer = require('@stryke/fs/buffer');
56
53
  var prettyBytes = require('@stryke/string-format/pretty-bytes');
57
54
  var isBuffer = require('@stryke/type-checks/is-buffer');
58
- var memfs = require('memfs');
59
- var buffer = require('buffer');
55
+ var buffer$1 = require('buffer');
60
56
  var fs = require('fs');
61
57
  var prettier = require('prettier');
58
+ var colors = require('@storm-software/config-tools/utilities/colors');
59
+ var noop = require('@stryke/helpers/noop');
60
+ var isUndefined = require('@stryke/type-checks/is-undefined');
61
+ var isParentPath = require('@stryke/path/is-parent-path');
62
+ var volume = require('memfs/lib/node/volume');
62
63
  var unionfs = require('unionfs');
64
+ var jiti = require('jiti');
63
65
  var isObject = require('@stryke/type-checks/is-object');
64
66
  var ts2 = require('typescript');
65
67
  var _package = require('@stryke/string-format/package');
@@ -68,12 +70,12 @@ var tsconfig = require('@stryke/fs/tsconfig');
68
70
  var writeFile$1 = require('@stryke/fs/write-file');
69
71
  var environmentChecks = require('@stryke/env/environment-checks');
70
72
  var unplugin = require('unplugin');
73
+ var camelCase = require('@stryke/string-format/camel-case');
71
74
  var bundleRequire = require('bundle-require');
72
75
  require('@stryke/fs/read-file');
73
76
  require('magic-string');
74
77
  var kit = require('@nuxt/kit');
75
78
  require('@nuxt/schema');
76
- var $ = require('@stryke/capnp');
77
79
 
78
80
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
79
81
 
@@ -95,13 +97,13 @@ function _interopNamespace(e) {
95
97
  return Object.freeze(n);
96
98
  }
97
99
 
98
- var defu3__default = /*#__PURE__*/_interopDefault(defu3);
100
+ var defu2__default = /*#__PURE__*/_interopDefault(defu2);
99
101
  var chalk5__default = /*#__PURE__*/_interopDefault(chalk5);
100
102
  var Handlebars__default = /*#__PURE__*/_interopDefault(Handlebars);
101
103
  var t__namespace = /*#__PURE__*/_interopNamespace(t);
104
+ var $__namespace = /*#__PURE__*/_interopNamespace($);
102
105
  var fs__default = /*#__PURE__*/_interopDefault(fs);
103
106
  var ts2__default = /*#__PURE__*/_interopDefault(ts2);
104
- var $__namespace = /*#__PURE__*/_interopNamespace($);
105
107
 
106
108
  function resolveModulePath(nodePath, state) {
107
109
  if (!t__namespace.isStringLiteral(nodePath.node)) {
@@ -206,7 +208,7 @@ var moduleResolverBabelPlugin = /* @__PURE__ */ chunkSHUYVCID_js.__name((context
206
208
  }, "moduleResolverBabelPlugin");
207
209
  var DEFAULT_ENVIRONMENT = "default";
208
210
  function createEnvironment(name, userConfig) {
209
- return defu3__default.default(userConfig.environments?.[name] ?? {}, {
211
+ return defu2__default.default(userConfig.environments?.[name] ?? {}, {
210
212
  name,
211
213
  title: userConfig.title || titleCase.titleCase(userConfig.name),
212
214
  ssr: false,
@@ -249,6 +251,15 @@ function createDefaultEnvironment(userConfig) {
249
251
  return createEnvironment(DEFAULT_ENVIRONMENT, userConfig);
250
252
  }
251
253
  chunkSHUYVCID_js.__name(createDefaultEnvironment, "createDefaultEnvironment");
254
+ function replacePathTokens(context, path) {
255
+ if (!path) {
256
+ return path;
257
+ }
258
+ return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.projectRoot).replaceAll("{projectRoot}", context.config.projectRoot).replaceAll("{powerlinesPath}", context.powerlinesPath).replaceAll("{cachePath}", context.cachePath).replaceAll("{dataPath}", context.dataPath).replaceAll("{logPath}", context.envPaths.log).replaceAll("{tempPath}", context.envPaths.temp).replaceAll("{configPath}", context.envPaths.config).replaceAll("{artifactsPath}", replace.replacePath(context.artifactsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{builtinPath}", replace.replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{entryPath}", replace.replacePath(context.entryPath, context.workspaceConfig.workspaceRoot));
259
+ }
260
+ chunkSHUYVCID_js.__name(replacePathTokens, "replacePathTokens");
261
+
262
+ // ../powerlines/src/lib/entry.ts
252
263
  function resolveEntryInputFile(context, typeDefinition) {
253
264
  return replace.replacePath(typeDefinition.file, joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot));
254
265
  }
@@ -274,7 +285,7 @@ function resolveEntry(context, typeDefinition) {
274
285
  }
275
286
  chunkSHUYVCID_js.__name(resolveEntry, "resolveEntry");
276
287
  function resolveEntriesSync(context, typeDefinitions) {
277
- return typeDefinitions.map((typeDefinition) => {
288
+ return typeDefinitions.map((entry) => isString.isString(entry) ? replacePathTokens(context, entry) : replacePathTokens(context, entry.file)).map((typeDefinition) => {
278
289
  const parsed = parseTypeDefinition.parseTypeDefinition(typeDefinition);
279
290
  const filePath = append.appendPath(parsed.file, context.config.projectRoot);
280
291
  if (isFile.isFile(filePath)) {
@@ -296,6 +307,232 @@ function getUniqueEntries(entries = []) {
296
307
  }));
297
308
  }
298
309
  chunkSHUYVCID_js.__name(getUniqueEntries, "getUniqueEntries");
310
+ BigInt("0xa56c61324b9d6e49");
311
+ var FileMetadata_KeyValuePair = class extends $__namespace.Struct {
312
+ static {
313
+ chunkSHUYVCID_js.__name(this, "FileMetadata_KeyValuePair");
314
+ }
315
+ static _capnp = {
316
+ displayName: "KeyValuePair",
317
+ id: "eabb26cf58b2a14c",
318
+ size: new $__namespace.ObjectSize(0, 2)
319
+ };
320
+ get key() {
321
+ return $__namespace.utils.getText(0, this);
322
+ }
323
+ set key(value) {
324
+ $__namespace.utils.setText(0, value, this);
325
+ }
326
+ get value() {
327
+ return $__namespace.utils.getText(1, this);
328
+ }
329
+ set value(value) {
330
+ $__namespace.utils.setText(1, value, this);
331
+ }
332
+ toString() {
333
+ return "FileMetadata_KeyValuePair_" + super.toString();
334
+ }
335
+ };
336
+ var FileMetadata = class _FileMetadata extends $__namespace.Struct {
337
+ static {
338
+ chunkSHUYVCID_js.__name(this, "FileMetadata");
339
+ }
340
+ static KeyValuePair = FileMetadata_KeyValuePair;
341
+ static _capnp = {
342
+ displayName: "FileMetadata",
343
+ id: "8e2cab5d7e28c7b3",
344
+ size: new $__namespace.ObjectSize(0, 4),
345
+ defaultVariant: "normal"
346
+ };
347
+ static _Properties;
348
+ /**
349
+ * The variant of the file.
350
+ *
351
+ */
352
+ get id() {
353
+ return $__namespace.utils.getText(0, this);
354
+ }
355
+ set id(value) {
356
+ $__namespace.utils.setText(0, value, this);
357
+ }
358
+ /**
359
+ * The output mode of the file.
360
+ *
361
+ */
362
+ get variant() {
363
+ return $__namespace.utils.getText(1, this, _FileMetadata._capnp.defaultVariant);
364
+ }
365
+ set variant(value) {
366
+ $__namespace.utils.setText(1, value, this);
367
+ }
368
+ /**
369
+ * Additional metadata associated with the file.
370
+ *
371
+ */
372
+ get mode() {
373
+ return $__namespace.utils.getText(2, this);
374
+ }
375
+ set mode(value) {
376
+ $__namespace.utils.setText(2, value, this);
377
+ }
378
+ _adoptProperties(value) {
379
+ $__namespace.utils.adopt(value, $__namespace.utils.getPointer(3, this));
380
+ }
381
+ _disownProperties() {
382
+ return $__namespace.utils.disown(this.properties);
383
+ }
384
+ get properties() {
385
+ return $__namespace.utils.getList(3, _FileMetadata._Properties, this);
386
+ }
387
+ _hasProperties() {
388
+ return !$__namespace.utils.isNull($__namespace.utils.getPointer(3, this));
389
+ }
390
+ _initProperties(length) {
391
+ return $__namespace.utils.initList(3, _FileMetadata._Properties, length, this);
392
+ }
393
+ set properties(value) {
394
+ $__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(3, this));
395
+ }
396
+ toString() {
397
+ return "FileMetadata_" + super.toString();
398
+ }
399
+ };
400
+ var FileIdentifier = class extends $__namespace.Struct {
401
+ static {
402
+ chunkSHUYVCID_js.__name(this, "FileIdentifier");
403
+ }
404
+ static _capnp = {
405
+ displayName: "FileIdentifier",
406
+ id: "e12b8732389d7406",
407
+ size: new $__namespace.ObjectSize(0, 2)
408
+ };
409
+ /**
410
+ * An additional identifier for the file.
411
+ *
412
+ */
413
+ get path() {
414
+ return $__namespace.utils.getText(0, this);
415
+ }
416
+ set path(value) {
417
+ $__namespace.utils.setText(0, value, this);
418
+ }
419
+ get id() {
420
+ return $__namespace.utils.getText(1, this);
421
+ }
422
+ set id(value) {
423
+ $__namespace.utils.setText(1, value, this);
424
+ }
425
+ toString() {
426
+ return "FileIdentifier_" + super.toString();
427
+ }
428
+ };
429
+ var FileData = class extends $__namespace.Struct {
430
+ static {
431
+ chunkSHUYVCID_js.__name(this, "FileData");
432
+ }
433
+ static _capnp = {
434
+ displayName: "FileData",
435
+ id: "fa6725c8a360f9a2",
436
+ size: new $__namespace.ObjectSize(0, 2)
437
+ };
438
+ /**
439
+ * The contents of the file.
440
+ *
441
+ */
442
+ get path() {
443
+ return $__namespace.utils.getText(0, this);
444
+ }
445
+ set path(value) {
446
+ $__namespace.utils.setText(0, value, this);
447
+ }
448
+ get content() {
449
+ return $__namespace.utils.getText(1, this);
450
+ }
451
+ set content(value) {
452
+ $__namespace.utils.setText(1, value, this);
453
+ }
454
+ toString() {
455
+ return "FileData_" + super.toString();
456
+ }
457
+ };
458
+ var FileSystemData = class _FileSystemData extends $__namespace.Struct {
459
+ static {
460
+ chunkSHUYVCID_js.__name(this, "FileSystemData");
461
+ }
462
+ static _capnp = {
463
+ displayName: "FileSystemData",
464
+ id: "aaa72a672ac0732f",
465
+ size: new $__namespace.ObjectSize(0, 3)
466
+ };
467
+ static _Ids;
468
+ static _Metadata;
469
+ static _Files;
470
+ _adoptIds(value) {
471
+ $__namespace.utils.adopt(value, $__namespace.utils.getPointer(0, this));
472
+ }
473
+ _disownIds() {
474
+ return $__namespace.utils.disown(this.ids);
475
+ }
476
+ get ids() {
477
+ return $__namespace.utils.getList(0, _FileSystemData._Ids, this);
478
+ }
479
+ _hasIds() {
480
+ return !$__namespace.utils.isNull($__namespace.utils.getPointer(0, this));
481
+ }
482
+ _initIds(length) {
483
+ return $__namespace.utils.initList(0, _FileSystemData._Ids, length, this);
484
+ }
485
+ set ids(value) {
486
+ $__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(0, this));
487
+ }
488
+ _adoptMetadata(value) {
489
+ $__namespace.utils.adopt(value, $__namespace.utils.getPointer(1, this));
490
+ }
491
+ _disownMetadata() {
492
+ return $__namespace.utils.disown(this.metadata);
493
+ }
494
+ get metadata() {
495
+ return $__namespace.utils.getList(1, _FileSystemData._Metadata, this);
496
+ }
497
+ _hasMetadata() {
498
+ return !$__namespace.utils.isNull($__namespace.utils.getPointer(1, this));
499
+ }
500
+ _initMetadata(length) {
501
+ return $__namespace.utils.initList(1, _FileSystemData._Metadata, length, this);
502
+ }
503
+ set metadata(value) {
504
+ $__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(1, this));
505
+ }
506
+ _adoptFiles(value) {
507
+ $__namespace.utils.adopt(value, $__namespace.utils.getPointer(2, this));
508
+ }
509
+ _disownFiles() {
510
+ return $__namespace.utils.disown(this.files);
511
+ }
512
+ get files() {
513
+ return $__namespace.utils.getList(2, _FileSystemData._Files, this);
514
+ }
515
+ _hasFiles() {
516
+ return !$__namespace.utils.isNull($__namespace.utils.getPointer(2, this));
517
+ }
518
+ _initFiles(length) {
519
+ return $__namespace.utils.initList(2, _FileSystemData._Files, length, this);
520
+ }
521
+ set files(value) {
522
+ $__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(2, this));
523
+ }
524
+ toString() {
525
+ return "FileSystemData_" + super.toString();
526
+ }
527
+ };
528
+ FileMetadata._Properties = $__namespace.CompositeList(FileMetadata_KeyValuePair);
529
+ FileSystemData._Ids = $__namespace.CompositeList(FileIdentifier);
530
+ FileSystemData._Metadata = $__namespace.CompositeList(FileMetadata);
531
+ FileSystemData._Files = $__namespace.CompositeList(FileData);
532
+
533
+ // ../powerlines/src/types/vfs.ts
534
+ var __VFS_PATCH__ = Symbol("__VFS_PATCH__");
535
+ var __VFS_REVERT__ = Symbol("__VFS_REVERT__");
299
536
  var createLog = /* @__PURE__ */ chunkSHUYVCID_js.__name((name, options = {}) => {
300
537
  const logLevel = options.logLevel === null ? types.LogLevelLabel.SILENT : options.logLevel || types.LogLevelLabel.INFO;
301
538
  if (logLevel === types.LogLevelLabel.SILENT) {
@@ -334,94 +571,6 @@ var BADGE_COLORS = [
334
571
  var extendLog = /* @__PURE__ */ chunkSHUYVCID_js.__name((logFn, name) => {
335
572
  return (type, ...args) => logFn(type, ` ${chalk5__default.default.inverse.hex(BADGE_COLORS[name.split("").map((char) => char.charCodeAt(0)).reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length] || BADGE_COLORS[0])(` ${titleCase.titleCase(name)} `)} ${args.join(" ")} `);
336
573
  }, "extendLog");
337
-
338
- // ../powerlines/src/types/commands.ts
339
- var SUPPORTED_COMMANDS = [
340
- "new",
341
- "clean",
342
- "prepare",
343
- "lint",
344
- "test",
345
- "build",
346
- "docs",
347
- "release",
348
- "finalize"
349
- ];
350
-
351
- // ../powerlines/src/plugin-utils/helpers.ts
352
- function isPlugin(value) {
353
- return isSetObject.isSetObject(value) && "name" in value && isSetString.isSetString(value.name) && (isUndefined.isUndefined(value.applyToEnvironment) || "applyToEnvironment" in value && isFunction.isFunction(value.applyToEnvironment)) && (isUndefined.isUndefined(value.dedupe) || "dedupe" in value && isFunction.isFunction(value.dedupe)) && (isUndefined.isUndefined(value.dependsOn) || "dependsOn" in value && Array.isArray(value.dependsOn) && value.dependsOn.every(isPluginConfig)) && SUPPORTED_COMMANDS.every((command) => isUndefined.isUndefined(value[command]) || command in value && (isFunction.isFunction(value[command]) || isSetObject.isSetObject(value[command]) && "handler" in value[command] && isFunction.isFunction(value[command].handler)));
354
- }
355
- chunkSHUYVCID_js.__name(isPlugin, "isPlugin");
356
- function isPluginConfigObject(value) {
357
- return isSetObject.isSetObject(value) && "plugin" in value && ((isSetString.isSetString(value.plugin) || isFunction.isFunction(value.plugin)) && "options" in value && isSetObject.isSetObject(value.options) || isPlugin(value.plugin));
358
- }
359
- chunkSHUYVCID_js.__name(isPluginConfigObject, "isPluginConfigObject");
360
- function isPluginConfigTuple(value) {
361
- return Array.isArray(value) && (value.length === 1 || value.length === 2) && ((isSetString.isSetString(value[0]) || isFunction.isFunction(value[0])) && value.length > 1 && isSetObject.isSetObject(value[1]) || isPlugin(value[0]));
362
- }
363
- chunkSHUYVCID_js.__name(isPluginConfigTuple, "isPluginConfigTuple");
364
- function isPluginConfig(value) {
365
- return isSetString.isSetString(value) || isFunction.isFunction(value) || isPlugin(value) || isPluginConfigObject(value) || isPluginConfigTuple(value);
366
- }
367
- chunkSHUYVCID_js.__name(isPluginConfig, "isPluginConfig");
368
- function isPluginHookFunction(value) {
369
- return isFunction.isFunction(value) || isSetObject.isSetObject(value) && "handler" in value && isFunction.isFunction(value.handler);
370
- }
371
- chunkSHUYVCID_js.__name(isPluginHookFunction, "isPluginHookFunction");
372
- function isPluginHookObject(value) {
373
- return isSetObject.isSetObject(value) && "handler" in value && isFunction.isFunction(value.handler);
374
- }
375
- chunkSHUYVCID_js.__name(isPluginHookObject, "isPluginHookObject");
376
- function isPluginHook(value) {
377
- return isPluginHookFunction(value) || isPluginHookObject(value);
378
- }
379
- chunkSHUYVCID_js.__name(isPluginHook, "isPluginHook");
380
- function getHookHandler(pluginHook) {
381
- return isFunction.isFunction(pluginHook) ? pluginHook : pluginHook.handler;
382
- }
383
- chunkSHUYVCID_js.__name(getHookHandler, "getHookHandler");
384
- function isHookExternal(hook) {
385
- return hook.startsWith("vite:") || hook.startsWith("esbuild:") || hook.startsWith("rolldown:") || hook.startsWith("rollup:") || hook.startsWith("webpack:") || hook.startsWith("rspack:") || hook.startsWith("farm:");
386
- }
387
- chunkSHUYVCID_js.__name(isHookExternal, "isHookExternal");
388
- function checkDedupe(plugin, plugins2) {
389
- return plugin.dedupe === false || plugins2.some((p) => p.dedupe !== false && (isFunction.isFunction(p.dedupe) && p.dedupe(plugin) || p.name === plugin.name));
390
- }
391
- chunkSHUYVCID_js.__name(checkDedupe, "checkDedupe");
392
- function addPluginHook(context, plugin, pluginHook, hooksList) {
393
- if (!checkDedupe(plugin, hooksList.map((hook) => hook.plugin))) {
394
- hooksList.push(isFunction.isFunction(pluginHook) ? {
395
- plugin,
396
- handler: getHookHandler(pluginHook).bind(context)
397
- } : {
398
- plugin,
399
- ...pluginHook,
400
- handler: getHookHandler(pluginHook).bind(context)
401
- });
402
- }
403
- }
404
- chunkSHUYVCID_js.__name(addPluginHook, "addPluginHook");
405
- function resolveOptions(options) {
406
- return defu3__default.default(options, {
407
- interopDefault: true,
408
- fsCache: options.mode !== "development" ? joinPaths.joinPaths(options.cacheDir, "jiti") : false,
409
- moduleCache: options.mode !== "development"
410
- });
411
- }
412
- chunkSHUYVCID_js.__name(resolveOptions, "resolveOptions");
413
- function createPluginResolver(options) {
414
- return jiti.createJiti(joinPaths.joinPaths(options.workspaceRoot, options.projectRoot), resolveOptions({
415
- ...options
416
- }));
417
- }
418
- chunkSHUYVCID_js.__name(createPluginResolver, "createPluginResolver");
419
- function createResolver(options) {
420
- const baseResolver = jiti.createJiti(joinPaths.joinPaths(options.workspaceRoot, options.projectRoot), resolveOptions(options));
421
- baseResolver.plugin = createPluginResolver(options);
422
- return baseResolver;
423
- }
424
- chunkSHUYVCID_js.__name(createResolver, "createResolver");
425
574
  function isBufferEncoding(options) {
426
575
  return isSetString.isSetString(options) || options === null;
427
576
  }
@@ -570,160 +719,71 @@ function patchFS(originalFS, vfs) {
570
719
  };
571
720
  }
572
721
  chunkSHUYVCID_js.__name(patchFS, "patchFS");
573
- var VirtualFileSystem = class {
722
+ var UnifiedFS = class _UnifiedFS extends unionfs.Union {
574
723
  static {
575
- chunkSHUYVCID_js.__name(this, "VirtualFileSystem");
724
+ chunkSHUYVCID_js.__name(this, "UnifiedFS");
576
725
  }
577
726
  /**
578
727
  * The internal map of virtual files.
579
728
  */
580
- #meta = {};
581
- /**
582
- * A map of unique identifiers to their virtual file paths.
583
- */
584
- #ids = {};
585
- /**
586
- * A map of virtual file paths to their underlying file content.
587
- */
588
- #cachedFS = /* @__PURE__ */ new Map();
589
- /**
590
- * A map of virtual file paths to their underlying file content.
591
- */
592
- #cachedResolver = /* @__PURE__ */ new Map();
593
- /**
594
- * The internal map of virtual files.
595
- */
596
- #virtualFS = new memfs.Volume();
729
+ #virtualFS = new volume.Volume();
597
730
  /**
598
731
  * The physical file system.
599
732
  */
600
- #fs = cloneFS(fs__default.default);
601
- /**
602
- * The unified volume that combines the virtual file system with the real file system.
603
- *
604
- * @remarks
605
- * This volume allows for seamless access to both virtual and real files.
606
- */
607
- #unifiedFS = new unionfs.Union();
608
- /**
609
- * Indicator specifying if the file system module is patched
610
- */
611
- #isPatched = false;
612
- /**
613
- * Function to revert require patch
614
- */
615
- #revert;
733
+ #physicalFS = cloneFS(fs__default.default);
616
734
  /**
617
- * The context of the virtual file system.
735
+ * The context of the unified file system.
618
736
  */
619
737
  #context;
620
- /**
621
- * The file system's logging function.
622
- */
623
- #log;
624
- /**
625
- * Checks if a path exists in the virtual file system (VFS).
626
- *
627
- * @param path - The path to check.
628
- * @returns `true` if the path exists, otherwise `false`.
629
- */
630
- #existsSync(path) {
631
- const formattedPath = this.formatPath(path);
632
- return this.#virtualFS.existsSync(formattedPath) || this.#fs.existsSync(formattedPath) || this.resolveFS(path).existsSync(formattedPath);
633
- }
634
- /**
635
- * Exposes the internal VFS map for advanced usage.
636
- */
637
- get [chunkUOTRU26N_js.__VFS_CACHE__]() {
638
- return this.#cachedFS;
639
- }
640
- /**
641
- * Exposes the internal VFS resolver cache for advanced usage.
642
- */
643
- get [chunkUOTRU26N_js.__VFS_RESOLVER__]() {
644
- return this.#cachedResolver;
738
+ static create(context, data) {
739
+ let result = new _UnifiedFS(context, data);
740
+ result = result.use(result.#physicalFS);
741
+ if (result.#context.config.output.mode !== "fs") {
742
+ result = result.use(result.#virtualFS);
743
+ }
744
+ return result;
645
745
  }
646
746
  /**
647
- * Exposes the internal VFS map for advanced usage.
747
+ * Gets the virtual file system (VFS).
648
748
  */
649
- get [chunkUOTRU26N_js.__VFS_VIRTUAL__]() {
749
+ get virtual() {
650
750
  return this.#virtualFS;
651
751
  }
652
752
  /**
653
- * Exposes the internal UFS map for advanced usage.
654
- */
655
- get [chunkUOTRU26N_js.__VFS_UNIFIED__]() {
656
- return this.#unifiedFS;
657
- }
658
- /**
659
- * A proxy to access the underlying file metadata.
660
- */
661
- get meta() {
662
- return new Proxy(this.#meta, {
663
- get: /* @__PURE__ */ chunkSHUYVCID_js.__name((target, prop) => {
664
- if (target[prop]) {
665
- return {
666
- id: prop,
667
- mode: this.#virtualFS.existsSync(prop) ? "virtual" : this.#fs.existsSync(prop) ? "fs" : this.#context.config.output.mode,
668
- details: {},
669
- variant: "normal",
670
- ...target[prop]
671
- };
672
- }
673
- return void 0;
674
- }, "get"),
675
- set: /* @__PURE__ */ chunkSHUYVCID_js.__name((target, prop, value) => {
676
- target[prop] = value;
677
- this.#ids[value.id || prop] = prop;
678
- return true;
679
- }, "set"),
680
- deleteProperty: /* @__PURE__ */ chunkSHUYVCID_js.__name((target, prop) => {
681
- delete this.#ids[target[prop]?.id || prop];
682
- delete target[prop];
683
- return true;
684
- }, "deleteProperty")
685
- });
686
- }
687
- /**
688
- * A map of module ids to their file paths.
753
+ * Gets the physical file system (FS).
689
754
  */
690
- get ids() {
691
- return this.#ids;
755
+ get physical() {
756
+ return this.#physicalFS;
692
757
  }
693
758
  /**
694
759
  * Creates a new instance of the VirtualFileSystem.
695
760
  *
696
761
  * @param context - The context of the virtual file system, typically containing options and logging functions.
697
- * @param serialized - A map of files/file contents to populate in cache
762
+ * @param data - A buffer containing the serialized virtual file system data.
698
763
  */
699
- constructor(context, serialized = {}) {
764
+ constructor(context, data) {
765
+ super();
700
766
  this.#context = context;
701
- this.#cachedFS = /* @__PURE__ */ new Map();
702
- this.#meta = Object.fromEntries(Object.entries(serialized.virtualFilesMeta ?? {}));
703
- this.#ids = Object.fromEntries(Object.entries(this.#meta).map(([path, data]) => [
704
- data.id || path,
705
- path
706
- ]));
707
- if (!this.#fs.existsSync(this.#context.dataPath)) {
708
- this.#fs.mkdirSync(this.#context.dataPath, {
767
+ if (!this.#physicalFS.existsSync(this.#context.dataPath)) {
768
+ this.#physicalFS.mkdirSync(this.#context.dataPath, {
709
769
  recursive: true
710
770
  });
711
771
  }
712
- if (!this.#fs.existsSync(this.#context.cachePath)) {
713
- this.#fs.mkdirSync(this.#context.cachePath, {
772
+ if (!this.#physicalFS.existsSync(this.#context.cachePath)) {
773
+ this.#physicalFS.mkdirSync(this.#context.cachePath, {
714
774
  recursive: true
715
775
  });
716
776
  }
717
- if (!this.#fs.existsSync(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
718
- this.#fs.mkdirSync(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath), {
777
+ if (!this.#physicalFS.existsSync(join.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
778
+ this.#physicalFS.mkdirSync(join.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath), {
719
779
  recursive: true
720
780
  });
721
781
  }
722
- this.#unifiedFS = this.#unifiedFS.use(this.#fs);
723
782
  if (this.#context.config.output.mode !== "fs") {
724
- if (serialized?.virtualFiles && Object.keys(serialized.virtualFiles).length > 0) {
725
- this.#virtualFS = memfs.Volume.fromJSON(serialized.virtualFiles);
726
- }
783
+ this.#virtualFS = volume.Volume.fromJSON(data._hasFiles() && data.files.length > 0 ? data.files.values().reduce((ret, file) => {
784
+ ret[file.path] = file.content;
785
+ return ret;
786
+ }, {}) : {});
727
787
  if (!this.#virtualFS.existsSync(this.#context.artifactsPath)) {
728
788
  this.#virtualFS.mkdirSync(this.#context.artifactsPath, {
729
789
  recursive: true
@@ -744,926 +804,1168 @@ var VirtualFileSystem = class {
744
804
  recursive: true
745
805
  });
746
806
  }
747
- this.#unifiedFS = this.#unifiedFS.use(this.#virtualFS);
748
807
  } else if (this.#context.config.projectType === "application") {
749
- if (!this.#fs.existsSync(this.#context.artifactsPath)) {
750
- this.#fs.mkdirSync(this.#context.artifactsPath, {
808
+ if (!this.#physicalFS.existsSync(this.#context.artifactsPath)) {
809
+ this.#physicalFS.mkdirSync(this.#context.artifactsPath, {
751
810
  recursive: true
752
811
  });
753
812
  }
754
- if (!this.#fs.existsSync(this.#context.builtinsPath)) {
755
- this.#fs.mkdirSync(this.#context.builtinsPath, {
813
+ if (!this.#physicalFS.existsSync(this.#context.builtinsPath)) {
814
+ this.#physicalFS.mkdirSync(this.#context.builtinsPath, {
756
815
  recursive: true
757
816
  });
758
817
  }
759
- if (!this.#fs.existsSync(this.#context.entryPath)) {
760
- this.#fs.mkdirSync(this.#context.entryPath, {
818
+ if (!this.#physicalFS.existsSync(this.#context.entryPath)) {
819
+ this.#physicalFS.mkdirSync(this.#context.entryPath, {
761
820
  recursive: true
762
821
  });
763
822
  }
764
- if (!this.#fs.existsSync(this.#context.dtsPath)) {
765
- this.#fs.mkdirSync(this.#context.dtsPath, {
823
+ if (!this.#physicalFS.existsSync(this.#context.dtsPath)) {
824
+ this.#physicalFS.mkdirSync(this.#context.dtsPath, {
766
825
  recursive: true
767
826
  });
768
827
  }
769
828
  }
770
- this.#log = extendLog(this.#context.log, "virtual-file-system");
771
- }
772
- [chunkUOTRU26N_js.__VFS_INIT__]() {
773
- if (!this.#isPatched && this.#context.config.output.mode !== "fs") {
774
- this.#revert = patchFS(fs__default.default, this);
775
- this.#isPatched = true;
776
- }
777
- }
778
- [chunkUOTRU26N_js.__VFS_REVERT__]() {
779
- if (this.#isPatched && this.#context.config.output.mode !== "fs") {
780
- if (!this.#revert) {
781
- throw new Error("Attempting to revert File System patch prior to calling `__init__` function");
782
- }
783
- this.#revert?.();
784
- this.#isPatched = false;
785
- }
786
829
  }
787
830
  /**
788
- * Check if a path or id corresponds to a virtual file **(does not actually exists on disk)**.
831
+ * Select the file system module to use for the operation based on the path or URL.
789
832
  *
790
- * @param pathOrId - The path or id to check.
791
- * @param options - Optional parameters for resolving the path.
792
- * @returns Whether the path or id corresponds to a virtual file **(does not actually exists on disk)**.
833
+ * @param pathOrUrl - The path to perform the file system operation on.
834
+ * @param options - Options for the operation, such as output mode.
835
+ * @returns The file system module used for the operation.
793
836
  */
794
- isVirtual(pathOrId, options = {}) {
795
- if (!pathOrId) {
796
- return false;
797
- }
798
- const resolvedPath = this.resolve(pathOrId, {
799
- ...options,
800
- type: "file"
801
- });
802
- if (!resolvedPath) {
803
- return false;
837
+ resolveFS(pathOrUrl, options = {}) {
838
+ const mode = this.resolveMode(pathOrUrl, options);
839
+ if (mode === "virtual") {
840
+ return {
841
+ ...this.#virtualFS,
842
+ mode: "virtual"
843
+ };
844
+ } else if (mode === "fs") {
845
+ return {
846
+ ...this.#physicalFS,
847
+ mode: "fs"
848
+ };
804
849
  }
805
- return this.meta[resolvedPath]?.mode === "virtual";
850
+ return {
851
+ ...this,
852
+ mode: this.#context.config.output.mode
853
+ };
806
854
  }
807
855
  /**
808
- * Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
856
+ * Select the file system module to use for the operation based on the path or URL.
809
857
  *
810
- * @param pathOrId - The path or id to check.
811
- * @param options - Optional parameters for resolving the path.
812
- * @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
858
+ * @param pathOrUrl - The path to perform the file system operation on.
859
+ * @param options - Options for the operation, such as output mode.
860
+ * @returns The file system module used for the operation.
813
861
  */
814
- isFs(pathOrId, options = {}) {
815
- if (!pathOrId) {
816
- return false;
817
- }
818
- const resolvedPath = this.resolve(pathOrId, {
819
- ...options,
820
- type: "file"
821
- });
822
- if (!resolvedPath) {
823
- return false;
862
+ resolveMode(pathOrUrl, options = {}) {
863
+ if (options.mode === "virtual" && this.#context.config.output.mode !== "fs" && isParentPath.isParentPath(toFilePath(pathOrUrl), this.#context.artifactsPath)) {
864
+ return "virtual";
865
+ } else if (options.mode === "fs" || this.#context.config.output.mode === "fs" || isParentPath.isParentPath(toFilePath(pathOrUrl), this.#context.dataPath) || isParentPath.isParentPath(toFilePath(pathOrUrl), this.#context.cachePath) || isParentPath.isParentPath(toFilePath(pathOrUrl), join.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
866
+ return "fs";
824
867
  }
825
- return this.meta[resolvedPath]?.mode === "fs";
868
+ return void 0;
826
869
  }
827
870
  /**
828
- * Check if a path exists within one of the directories specified in the tsconfig.json's `path` field.
829
- *
830
- * @see https://www.typescriptlang.org/tsconfig#paths
871
+ * Serializes the virtual file system (VFS) to a JSON object.
831
872
  *
832
- * @param pathOrId - The path or ID to check.
833
- * @returns Whether the path or ID corresponds to a virtual file.
873
+ * @returns A JSON representation of the virtual file system.
834
874
  */
835
- isTsconfigPath(pathOrId) {
836
- return !!this.#context.tsconfig.options.paths && Object.keys(this.#context.tsconfig.options.paths).some((path) => pathOrId.startsWith(path.replaceAll("*", "")));
875
+ toJSON() {
876
+ return this.#virtualFS.toJSON();
877
+ }
878
+ };
879
+
880
+ // ../powerlines/src/lib/fs/vfs.ts
881
+ var VirtualFileSystem = class _VirtualFileSystem {
882
+ static {
883
+ chunkSHUYVCID_js.__name(this, "VirtualFileSystem");
837
884
  }
838
885
  /**
839
- * Lists files in a given path.
840
- *
841
- * @param path - The path to list files from.
842
- * @param options - Options for listing files, such as encoding and recursion.
843
- * @returns An array of file names in the specified path.
886
+ * A map of virtual file IDs to their associated metadata.
844
887
  */
845
- readdirSync(path, options = "utf8") {
846
- return this.resolveFS(path).readdirSync(toFilePath(path), options);
847
- }
888
+ #metadata;
848
889
  /**
849
- * Removes a file in the virtual file system (VFS).
850
- *
851
- * @param path - The path to create the directory at.
890
+ * A map of virtual file IDs to their underlying file paths.
852
891
  */
853
- unlinkSync(path, options) {
854
- const formattedPath = toFilePath(path);
855
- if (!this.isFile(formattedPath)) {
856
- return;
857
- }
858
- this.#log(types.LogLevelLabel.TRACE, `Synchronously removing file: ${formattedPath}`);
859
- this.resolveFS(path, options).unlinkSync(formattedPath);
860
- this.#cachedFS.delete(formattedPath);
861
- this.clearResolverCache(formattedPath);
862
- }
892
+ #ids;
863
893
  /**
864
- * Removes a file in the virtual file system (VFS).
865
- *
866
- * @param path - The path to create the directory at.
894
+ * A map of underlying file paths to their virtual file IDs.
867
895
  */
868
- async unlink(path, options) {
869
- const formattedPath = toFilePath(path);
870
- if (!this.isFile(formattedPath)) {
871
- return;
872
- }
873
- this.#log(types.LogLevelLabel.TRACE, `Removing file: ${formattedPath}`);
874
- if (isFunction.isFunction(this.resolveFS(path, options).promises.unlink)) {
875
- await this.resolveFS(path, options).promises.unlink(formattedPath);
876
- this.#cachedFS.delete(formattedPath);
877
- this.clearResolverCache(formattedPath);
878
- } else {
879
- this.unlinkSync(formattedPath, options);
880
- }
881
- }
896
+ #paths;
882
897
  /**
883
- * Removes a directory in the virtual file system (VFS).
884
- *
885
- * @param path - The path to create the directory at.
886
- * @param options - Options for creating the directory.
898
+ * A map of virtual file paths to their underlying file content.
887
899
  */
888
- rmdirSync(path, options = {}) {
889
- const formattedPath = toFilePath(path);
890
- if (!this.isDirectory(formattedPath)) {
891
- return;
892
- }
893
- this.#log(types.LogLevelLabel.TRACE, `Synchronously removing directory: ${formattedPath}`);
894
- this.resolveFS(path, options).rmdirSync(formattedPath, defu3__default.default(options, {
895
- recursive: true
896
- }));
897
- this.#cachedFS.delete(formattedPath);
898
- this.clearResolverCache(formattedPath);
899
- }
900
+ #cachedResolver = /* @__PURE__ */ new Map();
900
901
  /**
901
- * Removes a directory in the virtual file system (VFS).
902
+ * The unified volume that combines the virtual file system with the real file system.
902
903
  *
903
- * @param path - The path to create the directory at.
904
- * @param options - Options for creating the directory.
905
- * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
904
+ * @remarks
905
+ * This volume allows for seamless access to both virtual and real files.
906
906
  */
907
- async rmdir(path, options = {}) {
908
- const formattedPath = toFilePath(path);
909
- if (!this.isDirectory(formattedPath)) {
910
- return;
911
- }
912
- this.#log(types.LogLevelLabel.TRACE, `Removing directory: ${formattedPath}`);
913
- if (isFunction.isFunction(this.resolveFS(path, options).promises.rm)) {
914
- await this.resolveFS(path, options).promises.rm(formattedPath, defu3__default.default(options, {
915
- force: true,
916
- recursive: true
917
- }));
918
- this.#cachedFS.delete(formattedPath);
919
- this.clearResolverCache(formattedPath);
920
- } else {
921
- this.rmdirSync(formattedPath, defu3__default.default(options ?? {}, {
922
- force: true,
923
- recursive: true
924
- }));
925
- }
926
- }
907
+ #unifiedFS;
927
908
  /**
928
- * Removes a file in the virtual file system (VFS).
909
+ * Indicator specifying if the file system module is patched
910
+ */
911
+ #isPatched = false;
912
+ /**
913
+ * Indicator specifying if the virtual file system (VFS) is disposed
914
+ */
915
+ #isDisposed = false;
916
+ /**
917
+ * Function to revert require patch
918
+ */
919
+ #revert;
920
+ /**
921
+ * The context of the virtual file system.
922
+ */
923
+ #context;
924
+ /**
925
+ * The file system's logging function.
926
+ */
927
+ #log;
928
+ /**
929
+ * Checks if a path exists in the virtual file system (VFS).
929
930
  *
930
- * @param path - The path to the file to remove.
931
- * @param options - Options for removing the file.
932
- * @returns A promise that resolves when the file is removed.
931
+ * @param path - The path to check.
932
+ * @returns `true` if the path exists, otherwise `false`.
933
933
  */
934
- async rm(path, options = {}) {
935
- this.#log(types.LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
936
- if (this.isDirectory(path)) {
937
- return this.rmdir(path, options);
938
- }
939
- return this.unlink(path, options);
934
+ #existsSync(path) {
935
+ const formattedPath = this.formatPath(path);
936
+ return this.#unifiedFS.virtual.existsSync(formattedPath) || this.#unifiedFS.physical.existsSync(formattedPath) || this.#unifiedFS.resolveFS(path).existsSync(formattedPath);
940
937
  }
941
938
  /**
942
- * Synchronously removes a file or directory in the virtual file system (VFS).
939
+ * Builds a regular expression from a string pattern for path matching.
943
940
  *
944
- * @param path - The path to the file or directory to remove.
945
- * @param options - Options for removing the file or directory.
941
+ * @param strPattern - The string pattern to convert.
942
+ * @returns A regular expression for matching paths.
946
943
  */
947
- rmSync(path, options = {}) {
948
- this.#log(types.LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
949
- if (this.isDirectory(path)) {
950
- return this.rmdirSync(path, options);
951
- }
952
- return this.unlinkSync(path, options);
944
+ #buildRegex(strPattern) {
945
+ const token = "::GLOBSTAR::";
946
+ return new RegExp(`^${this.formatPath(strPattern).replace(/\*\*/g, token).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(new RegExp(token, "g"), ".*")}$`);
953
947
  }
954
948
  /**
955
- * Creates a directory in the virtual file system (VFS).
949
+ * Formats a file id by removing the file extension and prepending the runtime prefix.
956
950
  *
957
- * @param path - The path to create the directory at.
958
- * @param options - Options for creating the directory.
959
- * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
951
+ * @param id - The file ID to format.
952
+ * @returns The formatted file ID.
960
953
  */
961
- mkdirSync(path, options = {}) {
962
- const filePath = toFilePath(path);
963
- this.clearResolverCache(filePath);
964
- return this.resolveFS(filePath, options).mkdirSync(filePath, defu3__default.default(options ?? {}, {
965
- recursive: true
966
- }));
954
+ #formatId(id) {
955
+ const formattedId = toFilePath(id);
956
+ return `${this.#context.config.output.builtinPrefix}:${formattedId.replace(new RegExp(`^${this.#context.config.output.builtinPrefix}:`), "").replace(/^\\0/, "").replace(filePathFns.findFileDotExtensionSafe(formattedId), "")}`;
967
957
  }
968
958
  /**
969
- * Creates a directory in the virtual file system (VFS).
959
+ * Resolves an id parameter to a corresponding virtual file path in the virtual file system (VFS).
970
960
  *
971
- * @param path - The path to create the directory at.
972
- * @param options - Options for creating the directory.
973
- * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
961
+ * @param id - The id to resolve.
962
+ * @returns The resolved file id if it exists, otherwise undefined.
974
963
  */
975
- async mkdir(path, options = {}) {
976
- let result;
977
- const filePath = toFilePath(path);
978
- if (isFunction.isFunction(this.resolveFS(filePath, options).promises.mkdir)) {
979
- result = await this.resolveFS(filePath, options).promises.mkdir(filePath, defu3__default.default(options ?? {}, {
980
- recursive: true
981
- }));
982
- } else {
983
- result = this.resolveFS(filePath, options).mkdirSync(filePath, defu3__default.default(options ?? {}, {
984
- recursive: true
985
- }));
964
+ #resolveId(id) {
965
+ if (this.#ids[this.#formatId(id)]) {
966
+ return this.#ids[this.#formatId(id)] || false;
986
967
  }
987
- this.clearResolverCache(filePath);
988
- return result;
968
+ return false;
989
969
  }
990
970
  /**
991
- * Glob files in the virtual file system (VFS) based on the provided pattern(s).
971
+ * Resolves a path parameter to a corresponding virtual file path in the virtual file system (VFS).
992
972
  *
993
- * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
994
- * @returns An array of file paths matching the provided pattern(s)
973
+ * @param path - The path to resolve.
974
+ * @param options - Optional parameters for resolving the path.
975
+ * @returns The resolved file path if it exists, otherwise undefined.
995
976
  */
996
- async glob(patterns) {
997
- const results = [];
998
- for (const pattern of toArray.toArray(patterns)) {
999
- const normalized = this.formatPath(pattern);
1000
- if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
1001
- const resolved = this.resolve(normalized, {
1002
- type: "file"
1003
- });
1004
- if (resolved && !results.includes(resolved)) {
1005
- results.push(resolved);
1006
- }
1007
- continue;
977
+ #resolvePath(path, options = {}) {
978
+ if (isType.isAbsolutePath(path)) {
979
+ if (this.#existsSync(path)) {
980
+ return path;
1008
981
  }
1009
- const absPattern = isType.isAbsolutePath(normalized) ? normalized : this.formatPath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, normalized));
1010
- const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
1011
- const baseDir = firstGlobIdx === -1 ? filePathFns.findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
1012
- const stack = [
1013
- baseDir && isType.isAbsolutePath(baseDir) ? baseDir : this.#context.workspaceConfig.workspaceRoot
1014
- ];
1015
- while (stack.length) {
1016
- const dir = stack.pop();
1017
- let entries = [];
1018
- try {
1019
- entries = await this.readdir(dir);
1020
- } catch {
1021
- continue;
1022
- }
1023
- for (const entry of entries) {
1024
- const full = this.formatPath(joinPaths.joinPaths(dir, entry));
1025
- let stats;
1026
- try {
1027
- stats = this.#unifiedFS.lstatSync(full);
1028
- } catch {
1029
- stats = void 0;
1030
- }
1031
- if (!stats) continue;
1032
- if (stats.isDirectory()) {
1033
- stack.push(full);
1034
- } else if (stats.isFile()) {
1035
- if (this.buildRegex(absPattern).test(full)) {
1036
- const resolved = this.resolve(full, {
1037
- type: "file"
1038
- });
1039
- if (resolved && !results.includes(resolved)) {
1040
- results.push(resolved);
1041
- }
1042
- }
1043
- }
1044
- }
982
+ const result = this.#checkVariants(path);
983
+ if (result) {
984
+ return result;
1045
985
  }
1046
986
  }
1047
- return results;
987
+ for (const parentPath of this.#resolveParentPaths(path, options.paths)) {
988
+ const request = joinPaths.joinPaths(parentPath, path);
989
+ if (this.#existsSync(request)) {
990
+ return request;
991
+ }
992
+ const result = this.#checkVariants(request);
993
+ if (result) {
994
+ return result;
995
+ }
996
+ }
997
+ return false;
1048
998
  }
1049
999
  /**
1050
- * Synchronously glob files in the virtual file system (VFS) based on the provided pattern(s).
1000
+ * Resolves parent paths for a given request.
1051
1001
  *
1052
- * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
1053
- * @returns An array of file paths matching the provided pattern(s)
1002
+ * @param request - The request path to resolve parent paths for.
1003
+ * @param parents - An optional array of parent paths to consider.
1004
+ * @returns An array of resolved parent paths.
1054
1005
  */
1055
- globSync(patterns) {
1056
- const results = [];
1057
- for (const pattern of toArray.toArray(patterns)) {
1058
- const normalized = this.formatPath(pattern);
1059
- if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
1060
- const resolved = this.resolve(normalized, {
1061
- type: "file"
1062
- });
1063
- if (resolved && !results.includes(resolved)) {
1064
- results.push(resolved);
1065
- }
1066
- continue;
1067
- }
1068
- const absPattern = isType.isAbsolutePath(normalized) ? normalized : this.formatPath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, normalized));
1069
- const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
1070
- const baseDir = firstGlobIdx === -1 ? filePathFns.findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
1071
- const stack = [
1072
- baseDir && isType.isAbsolutePath(baseDir) ? baseDir : this.#context.workspaceConfig.workspaceRoot
1073
- ];
1074
- while (stack.length) {
1075
- const dir = stack.pop();
1076
- let entries = [];
1077
- try {
1078
- entries = this.readdirSync(dir);
1079
- } catch {
1080
- continue;
1081
- }
1082
- for (const entry of entries) {
1083
- const full = this.formatPath(joinPaths.joinPaths(dir, entry));
1084
- let stats;
1085
- try {
1086
- stats = this.#unifiedFS.lstatSync(full);
1087
- } catch {
1088
- stats = void 0;
1089
- }
1090
- if (!stats) continue;
1091
- if (stats.isDirectory()) {
1092
- stack.push(full);
1093
- } else if (stats.isFile()) {
1094
- if (this.buildRegex(absPattern).test(full)) {
1095
- const resolved = this.resolve(full, {
1096
- type: "file"
1097
- });
1098
- if (resolved && !results.includes(resolved)) {
1099
- results.push(resolved);
1100
- }
1101
- }
1102
- }
1006
+ #resolveParentPaths(request, parents = []) {
1007
+ let paths = [
1008
+ this.#context.workspaceConfig.workspaceRoot,
1009
+ joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot)
1010
+ ];
1011
+ if (this.#context.tsconfig.options.paths) {
1012
+ 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, path) => {
1013
+ if (path && !ret.includes(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, path))) {
1014
+ ret.push(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, path));
1103
1015
  }
1104
- }
1016
+ return ret;
1017
+ }, paths) : paths;
1105
1018
  }
1106
- return results;
1019
+ return paths.reduce((ret, path) => {
1020
+ if (!ret.includes(path)) {
1021
+ ret.push(path);
1022
+ }
1023
+ return ret;
1024
+ }, parents.filter(Boolean).map((p) => this.formatPath(p)));
1107
1025
  }
1108
1026
  /**
1109
- * Moves a file from one path to another in the virtual file system (VFS).
1027
+ * Clears the resolver cache for a given path.
1110
1028
  *
1111
- * @param srcPath - The source path to move
1112
- * @param destPath - The destination path to move to
1029
+ * @param path - The path to clear the resolver cache for.
1113
1030
  */
1114
- async move(srcPath, destPath) {
1115
- const content = await this.readFile(srcPath);
1116
- await this.writeFile(destPath, content);
1117
- await this.rm(srcPath);
1031
+ #clearResolverCache(path) {
1032
+ this.#cachedResolver.keys().filter((key) => key.startsWith(toFilePath(path))).forEach((key) => this.#cachedResolver.delete(key));
1118
1033
  }
1119
1034
  /**
1120
- * Synchronously moves a file from one path to another in the virtual file system (VFS).
1035
+ * Check if the file exists with different variants (index, extensions).
1121
1036
  *
1122
- * @param srcPath - The source path to move
1123
- * @param destPath - The destination path to move to
1037
+ * @param request - The request path to check.
1038
+ * @param parentPath - An optional parent path to prepend to the request.
1039
+ * @returns The file path if it exists, otherwise false.
1124
1040
  */
1125
- moveSync(srcPath, destPath) {
1126
- const content = this.readFileSync(srcPath);
1127
- this.writeFileSync(destPath, content);
1128
- this.rmSync(srcPath);
1041
+ #checkVariants(request, parentPath) {
1042
+ const path = parentPath ? joinPaths.joinPaths(parentPath, request) : request;
1043
+ let file = this.#checkExtensions(path);
1044
+ if (file) {
1045
+ return file;
1046
+ }
1047
+ file = this.#checkIndex(path);
1048
+ if (file) {
1049
+ return file;
1050
+ }
1051
+ return false;
1129
1052
  }
1130
1053
  /**
1131
- * Copies a file from one path to another in the virtual file system (VFS).
1054
+ * Check if the index file exists in the given request path.
1132
1055
  *
1133
- * @param srcPath - The source path to copy
1134
- * @param destPath - The destination path to copy to
1135
- */
1136
- async copy(srcPath, destPath) {
1137
- const content = await this.readFile(srcPath);
1138
- await this.writeFile(destPath, content);
1139
- }
1140
- /**
1141
- * Synchronously copies a file from one path to another in the virtual file system (VFS).
1142
- *
1143
- * @param srcPath - The source path to copy
1144
- * @param destPath - The destination path to copy to
1145
- */
1146
- copySync(srcPath, destPath) {
1147
- const content = this.readFileSync(srcPath);
1148
- this.writeFileSync(destPath, content);
1149
- }
1150
- /**
1151
- * Lists files in a given path.
1152
- *
1153
- * @param pathOrId - The path to list files from.
1154
- * @param options - Options for listing files, such as encoding and recursion.
1155
- * @returns An array of file names in the specified path.
1156
- */
1157
- async readdir(pathOrId, options = "utf8") {
1158
- return this.resolveFS(pathOrId).promises.readdir(toFilePath(pathOrId), options);
1159
- }
1160
- /**
1161
- * Asynchronously reads a file from the virtual file system (VFS).
1162
- *
1163
- * @param pathOrId - The path or ID of the file to read.
1164
- * @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
1056
+ * @param request - The request path to check.
1057
+ * @returns The index file path if it exists, otherwise false.
1165
1058
  */
1166
- async readFile(pathOrId, options = "utf8") {
1167
- if (!pathOrId) {
1168
- return void 0;
1059
+ #checkIndex(request) {
1060
+ let file = joinPaths.joinPaths(request, "index");
1061
+ if (this.#existsSync(file)) {
1062
+ return file;
1169
1063
  }
1170
- const filePath = this.resolve(toFilePath(pathOrId), {
1171
- type: "file"
1172
- });
1173
- if (filePath) {
1174
- if (this.#cachedFS.has(filePath)) {
1175
- return this.#cachedFS.get(filePath);
1176
- }
1177
- let result;
1178
- if (isFunction.isFunction(this.resolveFS(filePath).promises.readFile)) {
1179
- result = (await this.resolveFS(filePath).promises.readFile(filePath, options))?.toString("utf8");
1180
- } else {
1181
- result = this.resolveFS(filePath).readFileSync(filePath, options);
1182
- }
1183
- const content = isBuffer.isBuffer(result) ? bufferToString.bufferToString(result) : result;
1184
- this.#cachedFS.set(filePath, content);
1185
- return content;
1064
+ file = this.#checkExtensions(file);
1065
+ if (file) {
1066
+ return file;
1186
1067
  }
1187
- return void 0;
1068
+ return false;
1188
1069
  }
1189
1070
  /**
1190
- * Synchronously reads a file from the virtual file system (VFS).
1071
+ * Check if the file exists with different extensions.
1191
1072
  *
1192
- * @param pathOrId - The path or ID of the file to read.
1193
- * @returns The contents of the file as a string, or undefined if the file does not exist.
1073
+ * @param request - The request path to check.
1074
+ * @returns The file path if it exists with any of the checked extensions, otherwise false.
1194
1075
  */
1195
- readFileSync(pathOrId, options = "utf8") {
1196
- if (!pathOrId) {
1197
- return void 0;
1076
+ #checkExtensions(request) {
1077
+ let file = `${request}.ts`;
1078
+ if (this.#existsSync(file)) {
1079
+ return file;
1198
1080
  }
1199
- const filePath = this.resolve(toFilePath(pathOrId), {
1200
- type: "file"
1201
- });
1202
- if (filePath) {
1203
- if (this.#cachedFS.has(filePath)) {
1204
- return this.#cachedFS.get(filePath);
1205
- }
1206
- const result = this.resolveFS(filePath).readFileSync(filePath, options);
1207
- const content = isBuffer.isBuffer(result) ? bufferToString.bufferToString(result) : result;
1208
- this.#cachedFS.set(filePath, content);
1209
- return content;
1081
+ file = `${request}.mts`;
1082
+ if (this.#existsSync(file)) {
1083
+ return file;
1210
1084
  }
1211
- return void 0;
1212
- }
1213
- /**
1214
- * Writes a file to the virtual file system (VFS).
1215
- *
1216
- * @param path - The path to the file.
1217
- * @param data - The contents of the file.
1218
- * @param options - Optional parameters for writing the file.
1219
- * @returns A promise that resolves when the file is written.
1220
- */
1221
- async writeFile(path, data = "", options = "utf8") {
1222
- const formattedPath = this.formatPath(path);
1223
- if (!this.isDirectory(filePathFns.findFilePath(formattedPath))) {
1224
- await this.mkdir(filePathFns.findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
1085
+ file = `${request}.cts`;
1086
+ if (this.#existsSync(file)) {
1087
+ return file;
1225
1088
  }
1226
- let code = isPowerLinesWriteFileData(data) ? data.code : data;
1227
- if ((!isPowerlinesWriteFileOptions(options) || !options.skipFormat) && isSetString.isSetString(code)) {
1228
- const resolvedConfig = await prettier.resolveConfig(formattedPath);
1229
- if (resolvedConfig) {
1230
- code = await prettier.format(code, {
1231
- absolutePath: formattedPath,
1232
- ...resolvedConfig
1233
- });
1234
- }
1089
+ file = `${request}.tsx`;
1090
+ if (this.#existsSync(file)) {
1091
+ return file;
1235
1092
  }
1236
- const outputMode = this.resolveOutputMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
1237
- this.#log(types.LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes.prettyBytes(new buffer.Blob(toArray.toArray(code)).size)})`);
1238
- this.meta[formattedPath] = {
1239
- path: formattedPath,
1240
- code,
1241
- mode: outputMode,
1242
- variant: "normal",
1243
- ...isPowerLinesWriteFileData(data) ? data : {}
1244
- };
1245
- this.clearResolverCache(formattedPath);
1246
- const ifs = this.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
1247
- if (isFunction.isFunction(ifs.promises.writeFile)) {
1248
- return ifs.promises.writeFile(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
1093
+ file = `${request}.js`;
1094
+ if (this.#existsSync(file)) {
1095
+ return file;
1249
1096
  }
1250
- return ifs.writeFileSync(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
1251
- }
1252
- /**
1253
- * Synchronously writes a file to the virtual file system (VFS).
1254
- *
1255
- * @param path - The file to write.
1256
- * @param data - The contents of the file.
1257
- * @param options - Optional parameters for writing the file.
1258
- */
1259
- writeFileSync(path, data = "", options = "utf8") {
1260
- const formattedPath = this.formatPath(path);
1261
- if (!this.isDirectory(filePathFns.findFilePath(formattedPath))) {
1262
- this.mkdirSync(filePathFns.findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
1097
+ file = `${request}.mjs`;
1098
+ if (this.#existsSync(file)) {
1099
+ return file;
1263
1100
  }
1264
- const code = isPowerLinesWriteFileData(data) ? data.code : data;
1265
- const outputMode = this.resolveOutputMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
1266
- this.#log(types.LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes.prettyBytes(new buffer.Blob(toArray.toArray(code)).size)})`);
1267
- this.meta[formattedPath] = {
1268
- path: formattedPath,
1269
- code,
1270
- mode: outputMode,
1271
- variant: "normal",
1272
- ...isPowerLinesWriteFileData(data) ? data : {}
1273
- };
1274
- this.clearResolverCache(formattedPath);
1275
- const writeStream = this.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0).createWriteStream(formattedPath);
1276
- try {
1277
- writeStream.write(code);
1278
- } finally {
1279
- writeStream.close();
1101
+ file = `${request}.cjs`;
1102
+ if (this.#existsSync(file)) {
1103
+ return file;
1104
+ }
1105
+ file = `${request}.jsx`;
1106
+ if (this.#existsSync(file)) {
1107
+ return file;
1108
+ }
1109
+ file = `${request}.json`;
1110
+ if (this.#existsSync(file)) {
1111
+ return file;
1112
+ }
1113
+ file = `${request}.d.ts`;
1114
+ if (this.#existsSync(file)) {
1115
+ return file;
1280
1116
  }
1117
+ return false;
1281
1118
  }
1282
1119
  /**
1283
- * Synchronously checks if a file exists in the virtual file system (VFS).
1120
+ * Creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
1284
1121
  *
1285
- * @param pathOrId - The path or ID of the file to check.
1286
- * @returns `true` if the file exists, otherwise `false`.
1122
+ * @param context - The context of the virtual file system, typically containing options and logging functions.
1123
+ * @returns A promise that resolves to a new virtual file system instance.
1287
1124
  */
1288
- existsSync(pathOrId) {
1289
- return this.resolve(pathOrId) !== false;
1125
+ static async create(context) {
1126
+ if (!context.config.skipCache && exists.existsSync(joinPaths.joinPaths(context.cachePath, "fs.bin"))) {
1127
+ const buffer$1 = await buffer.readFileBuffer(joinPaths.joinPaths(context.cachePath, "fs.bin"));
1128
+ const message2 = new $__namespace.Message(buffer$1, false);
1129
+ return new _VirtualFileSystem(context, message2.getRoot(FileSystemData));
1130
+ }
1131
+ const message = new $__namespace.Message();
1132
+ return new _VirtualFileSystem(context, message.initRoot(FileSystemData));
1290
1133
  }
1291
1134
  /**
1292
- * Retrieves the metadata of a file in the virtual file system (VFS).
1135
+ * Synchronously creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
1293
1136
  *
1294
- * @param pathOrId - The path or ID of the file to retrieve metadata for.
1295
- * @returns The metadata of the file, or undefined if the file does not exist.
1137
+ * @param context - The context of the virtual file system, typically containing options and logging functions.
1138
+ * @returns A new virtual file system instance.
1296
1139
  */
1297
- getMetadata(pathOrId) {
1298
- const resolved = this.resolve(pathOrId);
1299
- if (resolved && this.meta[resolved]) {
1300
- return this.meta[resolved];
1140
+ static createSync(context) {
1141
+ if (!context.config.skipCache && exists.existsSync(joinPaths.joinPaths(context.cachePath, "fs.bin"))) {
1142
+ const buffer$1 = buffer.readFileBufferSync(joinPaths.joinPaths(context.cachePath, "fs.bin"));
1143
+ const message2 = new $__namespace.Message(buffer$1, false);
1144
+ return new _VirtualFileSystem(context, message2.getRoot(FileSystemData));
1301
1145
  }
1302
- return void 0;
1146
+ const message = new $__namespace.Message();
1147
+ return new _VirtualFileSystem(context, message.initRoot(FileSystemData));
1303
1148
  }
1304
1149
  /**
1305
- * Checks if a file exists in the virtual file system (VFS).
1306
- *
1307
- * @remarks
1308
- * 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.
1309
- *
1310
- * @param pathOrId - The path of the file to check.
1311
- * @returns `true` if the file exists, otherwise `false`.
1150
+ * A map of file ids to their metadata.
1312
1151
  */
1313
- isFile(pathOrId) {
1314
- const resolved = this.resolve(pathOrId);
1315
- return !!(resolved && (this.#virtualFS.existsSync(resolved) && this.#virtualFS.lstatSync(resolved).isFile() || this.#fs.existsSync(resolved) && this.#fs.lstatSync(resolved).isFile() || this.resolveFS(resolved).existsSync(resolved) && this.resolveFS(resolved).lstatSync(resolved).isFile()));
1152
+ get metadata() {
1153
+ return this.#metadata;
1316
1154
  }
1317
1155
  /**
1318
- * Checks if a directory exists in the virtual file system (VFS).
1319
- *
1320
- * @param pathOrId - The path of the directory to check.
1321
- * @returns `true` if the directory exists, otherwise `false`.
1156
+ * A map of module ids to their file paths.
1322
1157
  */
1323
- isDirectory(pathOrId) {
1324
- const resolved = this.resolve(pathOrId);
1325
- return !!(resolved && (this.#virtualFS.existsSync(resolved) && this.#virtualFS.lstatSync(resolved).isDirectory() || this.#fs.existsSync(resolved) && this.#fs.lstatSync(resolved).isDirectory() || this.resolveFS(resolved).existsSync(resolved) && this.resolveFS(resolved).lstatSync(resolved).isDirectory()));
1158
+ get ids() {
1159
+ return this.#ids;
1326
1160
  }
1327
1161
  /**
1328
- * Retrieves the status of a file in the virtual file system (VFS).
1329
- *
1330
- * @param pathOrId - The path or ID of the file to retrieve status for.
1331
- * @returns A promise that resolves to the file's status information, or false if the file does not exist.
1162
+ * A map of virtual file paths to their IDs.
1332
1163
  */
1333
- async stat(pathOrId, options) {
1334
- return this.resolveFS(pathOrId).promises.stat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
1164
+ get paths() {
1165
+ return this.#paths;
1335
1166
  }
1336
1167
  /**
1337
- * Synchronously retrieves the status of a file in the virtual file system (VFS).
1168
+ * Creates a new instance of the {@link VirtualFileSystem}.
1338
1169
  *
1339
- * @param pathOrId - The path or ID of the file to retrieve status for.
1340
- * @returns The file's status information, or false if the file does not exist.
1170
+ * @param context - The context of the virtual file system, typically containing options and logging functions.
1171
+ * @param data - A buffer containing the serialized virtual file system data.
1341
1172
  */
1342
- statSync(pathOrId) {
1343
- return this.resolveFS(pathOrId).statSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId));
1173
+ constructor(context, data) {
1174
+ this.#context = context;
1175
+ this.#unifiedFS = UnifiedFS.create(context, data);
1176
+ this.#metadata = {};
1177
+ if (data._hasMetadata()) {
1178
+ this.#metadata = data.metadata.values().reduce((ret, data2) => {
1179
+ ret[data2.id] = {
1180
+ id: data2.id,
1181
+ variant: data2.variant,
1182
+ mode: data2.mode,
1183
+ properties: data2._hasProperties() ? data2.properties.values().reduce((ret2, item) => {
1184
+ ret2[item.key] = item.value;
1185
+ return ret2;
1186
+ }, {}) : {}
1187
+ };
1188
+ return ret;
1189
+ }, {});
1190
+ }
1191
+ this.#ids = {};
1192
+ this.#paths = {};
1193
+ if (data._hasIds()) {
1194
+ this.#ids = data.ids.values().reduce((ret, data2) => {
1195
+ ret[data2.id] ??= data2.path;
1196
+ ret[data2.path] ??= data2.path;
1197
+ return ret;
1198
+ }, {});
1199
+ this.#paths = data.ids.values().reduce((ret, data2) => {
1200
+ ret[data2.path] ??= data2.id;
1201
+ return ret;
1202
+ }, {});
1203
+ }
1204
+ this.#log = extendLog(this.#context.log, "file-system");
1344
1205
  }
1345
1206
  /**
1346
- * Retrieves the status of a symbolic link in the virtual file system (VFS).
1207
+ * Check if a path or id corresponds to a virtual file **(does not actually exists on disk)**.
1347
1208
  *
1348
- * @param pathOrId - The path or ID of the symbolic link to retrieve status for.
1349
- * @returns A promise that resolves to the symbolic link's status information, or false if the link does not exist.
1209
+ * @param pathOrId - The path or id to check.
1210
+ * @param options - Optional parameters for resolving the path.
1211
+ * @returns Whether the path or id corresponds to a virtual file **(does not actually exists on disk)**.
1350
1212
  */
1351
- async lstat(pathOrId, options) {
1352
- return this.resolveFS(pathOrId).promises.lstat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
1213
+ isVirtual(pathOrId, options = {}) {
1214
+ if (!pathOrId) {
1215
+ return false;
1216
+ }
1217
+ const resolvedPath = this.resolve(pathOrId, {
1218
+ ...options,
1219
+ type: "file"
1220
+ });
1221
+ if (!resolvedPath) {
1222
+ return false;
1223
+ }
1224
+ return this.metadata[resolvedPath]?.mode === "virtual";
1353
1225
  }
1354
1226
  /**
1355
- * Synchronously retrieves the status of a symbolic link in the virtual file system (VFS).
1227
+ * Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
1356
1228
  *
1357
- * @param pathOrId - The path or ID of the symbolic link to retrieve status for.
1358
- * @returns The symbolic link's status information, or false if the link does not exist.
1229
+ * @param pathOrId - The path or id to check.
1230
+ * @param options - Optional parameters for resolving the path.
1231
+ * @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
1359
1232
  */
1360
- lstatSync(pathOrId, options) {
1361
- return this.resolveFS(pathOrId).lstatSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
1233
+ isPhysical(pathOrId, options = {}) {
1234
+ if (!pathOrId) {
1235
+ return false;
1236
+ }
1237
+ const resolvedPath = this.resolve(pathOrId, {
1238
+ ...options,
1239
+ type: "file"
1240
+ });
1241
+ if (!resolvedPath) {
1242
+ return false;
1243
+ }
1244
+ return this.metadata[resolvedPath]?.mode === "fs";
1362
1245
  }
1363
1246
  /**
1364
- * Resolves a path based on TypeScript's `tsconfig.json` paths.
1365
- *
1366
- * @see https://www.typescriptlang.org/tsconfig#paths
1247
+ * Lists files in a given path.
1367
1248
  *
1368
- * @param path - The path to check.
1369
- * @returns The resolved file path if it exists, otherwise undefined.
1249
+ * @param path - The path to list files from.
1250
+ * @param options - Options for listing files, such as encoding and recursion.
1251
+ * @returns An array of file names in the specified path.
1370
1252
  */
1371
- resolveTsconfigPath(path) {
1372
- if (this.#context.tsconfig.options.paths) {
1373
- for (const tsconfigPathKey of Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path.startsWith(tsconfigPath.replaceAll("*", "")))) {
1374
- const resolvedPath = this.#context.tsconfig.options.paths[tsconfigPathKey]?.find((tsconfigPath) => this.resolvePath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, tsconfigPath.replaceAll("*", ""), path.replace(tsconfigPathKey.replaceAll("*", ""), ""))) || this.formatPath(tsconfigPath) === this.formatPath(path));
1375
- if (resolvedPath) {
1376
- return this.formatPath(resolvedPath) === this.formatPath(path) ? this.formatPath(resolvedPath) : this.resolvePath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, resolvedPath.replaceAll("*", ""), path.replace(tsconfigPathKey.replaceAll("*", ""), "")));
1377
- }
1378
- }
1379
- }
1380
- return false;
1253
+ readdirSync(path, options = "utf8") {
1254
+ return this.#unifiedFS.resolveFS(path).readdirSync(toFilePath(path), options);
1381
1255
  }
1382
1256
  /**
1383
- * Resolves a path based on TypeScript's `tsconfig.json` paths.
1384
- *
1385
- * @see https://www.typescriptlang.org/tsconfig#paths
1257
+ * Removes a file in the virtual file system (VFS).
1386
1258
  *
1387
- * @param path - The path to check.
1388
- * @returns The resolved file path if it exists, otherwise undefined.
1259
+ * @param path - The path to create the directory at.
1389
1260
  */
1390
- resolveTsconfigPathPackage(path) {
1391
- if (this.#context.tsconfig.options.paths) {
1392
- const tsconfigPathKeys = Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path.startsWith(tsconfigPath.replaceAll("*", "")));
1393
- if (tsconfigPathKeys.length > 0 && tsconfigPathKeys[0]) {
1394
- return tsconfigPathKeys[0].replace(/\/\*$/, "");
1395
- }
1261
+ unlinkSync(path, options) {
1262
+ const formattedPath = toFilePath(path);
1263
+ if (!this.isFile(formattedPath)) {
1264
+ return;
1396
1265
  }
1397
- return false;
1398
- }
1399
- /**
1400
- * Resolves a path or ID to its real path in the virtual file system (VFS).
1401
- *
1402
- * @param pathOrId - The path or ID to resolve.
1403
- * @returns The resolved real path if it exists, otherwise undefined.
1404
- */
1405
- realpathSync(pathOrId) {
1406
- const filePath = this.resolve(toFilePath(pathOrId));
1407
- if (!filePath) {
1408
- throw new Error(`File not found: ${toFilePath(pathOrId)}`);
1266
+ this.#log(types.LogLevelLabel.TRACE, `Synchronously removing file: ${formattedPath}`);
1267
+ this.#unifiedFS.resolveFS(path, options).unlinkSync(formattedPath);
1268
+ if (this.paths[formattedPath] && this.metadata[this.paths[formattedPath]]) {
1269
+ delete this.metadata[this.paths[formattedPath]];
1409
1270
  }
1410
- return filePath;
1271
+ this.#clearResolverCache(formattedPath);
1411
1272
  }
1412
1273
  /**
1413
- * Resolves a path or ID parameter to a corresponding virtual file path in the virtual file system (VFS).
1274
+ * Removes a file in the virtual file system (VFS).
1414
1275
  *
1415
- * @param pathOrId - The path or ID to resolve.
1416
- * @param options - Optional parameters for resolving the path, such as whether to include the file extension.
1417
- * @returns The resolved file path if it exists, otherwise undefined.
1276
+ * @param path - The path to create the directory at.
1418
1277
  */
1419
- resolve(pathOrId, options = {}) {
1420
- const formattedPathOrId = toFilePath(pathOrId);
1421
- const resolverKey = `${formattedPathOrId}${options.withExtension ? "-ext" : ""}${options.paths ? `-${murmurhash.murmurhash(options.paths)}` : ""}${options.type ? `-${options.type}` : ""}`;
1422
- if (this.#cachedResolver.has(resolverKey)) {
1423
- return this.#cachedResolver.get(resolverKey);
1424
- }
1425
- let result = this.resolveId(formattedPathOrId);
1426
- if (!result) {
1427
- result = this.resolvePath(formattedPathOrId, options);
1428
- }
1429
- if (!result) {
1430
- result = false;
1278
+ async unlink(path, options) {
1279
+ const formattedPath = toFilePath(path);
1280
+ if (!this.isFile(formattedPath)) {
1281
+ return;
1431
1282
  }
1432
- if (result && options.withExtension === false) {
1433
- return result.replace(/\.[m|c]?[t|j]sx?$/, "");
1283
+ this.#log(types.LogLevelLabel.TRACE, `Removing file: ${formattedPath}`);
1284
+ if (isFunction.isFunction(this.#unifiedFS.resolveFS(path, options).promises.unlink)) {
1285
+ await this.#unifiedFS.resolveFS(path, options).promises.unlink(formattedPath);
1286
+ if (this.paths[formattedPath] && this.metadata[this.paths[formattedPath]]) {
1287
+ delete this.metadata[this.paths[formattedPath]];
1288
+ }
1289
+ this.#clearResolverCache(formattedPath);
1290
+ } else {
1291
+ this.unlinkSync(formattedPath, options);
1434
1292
  }
1435
- this.#cachedResolver.set(resolverKey, result);
1436
- return result;
1437
1293
  }
1438
1294
  /**
1439
- * Retrieves the partial metadata for all files in the virtual file system (VFS).
1295
+ * Removes a directory in the virtual file system (VFS).
1440
1296
  *
1441
- * @returns A record containing the partial metadata for all files.
1297
+ * @param path - The path to create the directory at.
1298
+ * @param options - Options for creating the directory.
1442
1299
  */
1443
- getPartialMeta() {
1444
- return Object.fromEntries(Object.entries(this.#meta).filter(([_, data]) => isSetObject.isSetObject(data)));
1445
- }
1446
- buildRegex(strPattern) {
1447
- const token = "::GLOBSTAR::";
1448
- return new RegExp(`^${this.formatPath(strPattern).replace(/\*\*/g, token).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(new RegExp(token, "g"), ".*")}$`);
1300
+ rmdirSync(path, options = {}) {
1301
+ const formattedPath = toFilePath(path);
1302
+ if (!this.isDirectory(formattedPath)) {
1303
+ return;
1304
+ }
1305
+ this.#log(types.LogLevelLabel.TRACE, `Synchronously removing directory: ${formattedPath}`);
1306
+ this.#unifiedFS.resolveFS(path, options).rmdirSync(formattedPath, defu2__default.default(options, {
1307
+ recursive: true
1308
+ }));
1309
+ this.#clearResolverCache(formattedPath);
1449
1310
  }
1450
1311
  /**
1451
- * Converts a relative path to an absolute path based on the workspace and project root.
1312
+ * Removes a directory in the virtual file system (VFS).
1452
1313
  *
1453
- * @param path - The relative path to convert.
1454
- * @returns The absolute path.
1314
+ * @param path - The path to create the directory at.
1315
+ * @param options - Options for creating the directory.
1316
+ * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
1455
1317
  */
1456
- formatPath(path) {
1318
+ async rmdir(path, options = {}) {
1457
1319
  const formattedPath = toFilePath(path);
1458
- if (isType.isAbsolutePath(formattedPath) || formattedPath.startsWith(this.#context.workspaceConfig.workspaceRoot)) {
1459
- return formattedPath;
1460
- } else if (formattedPath.startsWith(this.#context.config.projectRoot)) {
1461
- return joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, formattedPath);
1320
+ if (!this.isDirectory(formattedPath)) {
1321
+ return;
1322
+ }
1323
+ this.#log(types.LogLevelLabel.TRACE, `Removing directory: ${formattedPath}`);
1324
+ if (isFunction.isFunction(this.#unifiedFS.resolveFS(path, options).promises.rm)) {
1325
+ await this.#unifiedFS.resolveFS(path, options).promises.rm(formattedPath, defu2__default.default(options, {
1326
+ force: true,
1327
+ recursive: true
1328
+ }));
1329
+ this.#clearResolverCache(formattedPath);
1330
+ } else {
1331
+ this.rmdirSync(formattedPath, defu2__default.default(options ?? {}, {
1332
+ force: true,
1333
+ recursive: true
1334
+ }));
1462
1335
  }
1463
- return formattedPath;
1464
1336
  }
1465
1337
  /**
1466
- * Formats a file id by removing the file extension and prepending the runtime prefix.
1338
+ * Removes a file in the virtual file system (VFS).
1467
1339
  *
1468
- * @param id - The file ID to format.
1469
- * @returns The formatted file ID.
1340
+ * @param path - The path to the file to remove.
1341
+ * @param options - Options for removing the file.
1342
+ * @returns A promise that resolves when the file is removed.
1470
1343
  */
1471
- formatId(id) {
1472
- const formattedId = toFilePath(id);
1473
- return `${this.#context.config.output.builtinPrefix}:${formattedId.replace(new RegExp(`^${this.#context.config.output.builtinPrefix}:`), "").replace(/^\\0/, "").replace(filePathFns.findFileDotExtensionSafe(formattedId), "")}`;
1344
+ async rm(path, options = {}) {
1345
+ this.#log(types.LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
1346
+ if (this.isDirectory(path)) {
1347
+ return this.rmdir(path, options);
1348
+ }
1349
+ return this.unlink(path, options);
1474
1350
  }
1475
1351
  /**
1476
- * Resolves an id parameter to a corresponding virtual file path in the virtual file system (VFS).
1352
+ * Synchronously removes a file or directory in the virtual file system (VFS).
1477
1353
  *
1478
- * @param id - The id to resolve.
1479
- * @returns The resolved file id if it exists, otherwise undefined.
1354
+ * @param path - The path to the file or directory to remove.
1355
+ * @param options - Options for removing the file or directory.
1480
1356
  */
1481
- resolveId(id) {
1482
- if (this.#ids[this.formatId(id)]) {
1483
- return this.#ids[this.formatId(id)] || false;
1357
+ rmSync(path, options = {}) {
1358
+ this.#log(types.LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
1359
+ if (this.isDirectory(path)) {
1360
+ return this.rmdirSync(path, options);
1484
1361
  }
1485
- return false;
1362
+ return this.unlinkSync(path, options);
1486
1363
  }
1487
1364
  /**
1488
- * Resolves a path parameter to a corresponding virtual file path in the virtual file system (VFS).
1365
+ * Creates a directory in the virtual file system (VFS).
1489
1366
  *
1490
- * @param path - The path to resolve.
1491
- * @param options - Optional parameters for resolving the path.
1492
- * @returns The resolved file path if it exists, otherwise undefined.
1367
+ * @param path - The path to create the directory at.
1368
+ * @param options - Options for creating the directory.
1369
+ * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
1493
1370
  */
1494
- resolvePath(path, options = {}) {
1495
- if (isType.isAbsolutePath(path)) {
1496
- if (this.#existsSync(path)) {
1497
- return path;
1498
- }
1499
- const result = this.checkVariants(path);
1500
- if (result) {
1501
- return result;
1502
- }
1503
- }
1504
- for (const parentPath of this.resolveParentPaths(path, options.paths)) {
1505
- const request = joinPaths.joinPaths(parentPath, path);
1506
- if (this.#existsSync(request)) {
1507
- return request;
1508
- }
1509
- const result = this.checkVariants(request);
1510
- if (result) {
1511
- return result;
1512
- }
1513
- }
1514
- return false;
1515
- }
1516
- resolveParentPaths(request, parents = []) {
1517
- let paths = [
1518
- this.#context.workspaceConfig.workspaceRoot,
1519
- joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot)
1520
- ];
1521
- if (this.#context.tsconfig.options.paths) {
1522
- 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, path) => {
1523
- if (path && !ret.includes(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, path))) {
1524
- ret.push(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, path));
1525
- }
1526
- return ret;
1527
- }, paths) : paths;
1528
- }
1529
- return paths.reduce((ret, path) => {
1530
- if (!ret.includes(path)) {
1531
- ret.push(path);
1532
- }
1533
- return ret;
1534
- }, parents.filter(Boolean).map((p) => this.formatPath(p)));
1371
+ mkdirSync(path, options = {}) {
1372
+ const filePath = toFilePath(path);
1373
+ this.#clearResolverCache(filePath);
1374
+ return this.#unifiedFS.resolveFS(filePath, options).mkdirSync(filePath, defu2__default.default(options ?? {}, {
1375
+ recursive: true
1376
+ }));
1535
1377
  }
1536
1378
  /**
1537
- * Select the file system module to use for the operation based on the path or URL.
1379
+ * Creates a directory in the virtual file system (VFS).
1538
1380
  *
1539
- * @param pathOrUrl - The path to perform the file system operation on.
1540
- * @param options - Options for the operation, such as output mode.
1541
- * @returns The file system module used for the operation.
1381
+ * @param path - The path to create the directory at.
1382
+ * @param options - Options for creating the directory.
1383
+ * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
1542
1384
  */
1543
- resolveFS(pathOrUrl, options = {}) {
1544
- const mode = this.resolveOutputMode(pathOrUrl, options);
1545
- if (mode === "virtual") {
1546
- return this.#virtualFS;
1547
- } else if (mode === "fs") {
1548
- return this.#fs;
1385
+ async mkdir(path, options = {}) {
1386
+ let result;
1387
+ const filePath = toFilePath(path);
1388
+ if (isFunction.isFunction(this.#unifiedFS.resolveFS(filePath, options).promises.mkdir)) {
1389
+ result = await this.#unifiedFS.resolveFS(filePath, options).promises.mkdir(filePath, defu2__default.default(options ?? {}, {
1390
+ recursive: true
1391
+ }));
1392
+ } else {
1393
+ result = this.#unifiedFS.resolveFS(filePath, options).mkdirSync(filePath, defu2__default.default(options ?? {}, {
1394
+ recursive: true
1395
+ }));
1549
1396
  }
1550
- return this.#unifiedFS;
1397
+ this.#clearResolverCache(filePath);
1398
+ return result;
1551
1399
  }
1552
1400
  /**
1553
- * Select the file system module to use for the operation based on the path or URL.
1401
+ * Glob files in the virtual file system (VFS) based on the provided pattern(s).
1554
1402
  *
1555
- * @param pathOrUrl - The path to perform the file system operation on.
1556
- * @param options - Options for the operation, such as output mode.
1557
- * @returns The file system module used for the operation.
1403
+ * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
1404
+ * @returns An array of file paths matching the provided pattern(s)
1558
1405
  */
1559
- resolveOutputMode(pathOrUrl, options = {}) {
1560
- if (options.mode === "virtual" && this.#context.config.output.mode !== "fs" && isParentPath.isParentPath(toFilePath(pathOrUrl), this.#context.artifactsPath)) {
1561
- return "virtual";
1562
- } else if (options.mode === "fs" || this.#context.config.output.mode === "fs" || isParentPath.isParentPath(toFilePath(pathOrUrl), this.#context.dataPath) || isParentPath.isParentPath(toFilePath(pathOrUrl), this.#context.cachePath) || isParentPath.isParentPath(toFilePath(pathOrUrl), joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
1563
- return "fs";
1406
+ async glob(patterns) {
1407
+ const results = [];
1408
+ for (const pattern of toArray.toArray(patterns)) {
1409
+ const normalized = this.formatPath(pattern);
1410
+ if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
1411
+ const resolved = this.resolve(normalized, {
1412
+ type: "file"
1413
+ });
1414
+ if (resolved && !results.includes(resolved)) {
1415
+ results.push(resolved);
1416
+ }
1417
+ continue;
1418
+ }
1419
+ const absPattern = isType.isAbsolutePath(normalized) ? normalized : this.formatPath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, normalized));
1420
+ const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
1421
+ const baseDir = firstGlobIdx === -1 ? filePathFns.findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
1422
+ const stack = [
1423
+ baseDir && isType.isAbsolutePath(baseDir) ? baseDir : this.#context.workspaceConfig.workspaceRoot
1424
+ ];
1425
+ while (stack.length) {
1426
+ const dir = stack.pop();
1427
+ let entries = [];
1428
+ try {
1429
+ entries = await this.readdir(dir);
1430
+ } catch {
1431
+ continue;
1432
+ }
1433
+ for (const entry of entries) {
1434
+ const full = this.formatPath(joinPaths.joinPaths(dir, entry));
1435
+ let stats;
1436
+ try {
1437
+ stats = this.#unifiedFS.lstatSync(full);
1438
+ } catch {
1439
+ stats = void 0;
1440
+ }
1441
+ if (!stats) continue;
1442
+ if (stats.isDirectory()) {
1443
+ stack.push(full);
1444
+ } else if (stats.isFile()) {
1445
+ if (this.#buildRegex(absPattern).test(full)) {
1446
+ const resolved = this.resolve(full, {
1447
+ type: "file"
1448
+ });
1449
+ if (resolved && !results.includes(resolved)) {
1450
+ results.push(resolved);
1451
+ }
1452
+ }
1453
+ }
1454
+ }
1455
+ }
1564
1456
  }
1565
- return void 0;
1457
+ return results;
1566
1458
  }
1567
1459
  /**
1568
- * Clears the resolver cache for a given path.
1460
+ * Synchronously glob files in the virtual file system (VFS) based on the provided pattern(s).
1569
1461
  *
1570
- * @param path - The path to clear the resolver cache for.
1462
+ * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
1463
+ * @returns An array of file paths matching the provided pattern(s)
1571
1464
  */
1572
- clearResolverCache(path) {
1573
- this.#cachedResolver.keys().filter((key) => key.startsWith(toFilePath(path))).forEach((key) => this.#cachedResolver.delete(key));
1574
- }
1575
- /**
1576
- * Check if the file exists with different variants (index, extensions).
1577
- *
1578
- * @param request - The request path to check.
1579
- * @param parentPath - An optional parent path to prepend to the request.
1580
- * @returns The file path if it exists, otherwise false.
1465
+ globSync(patterns) {
1466
+ const results = [];
1467
+ for (const pattern of toArray.toArray(patterns)) {
1468
+ const normalized = this.formatPath(pattern);
1469
+ if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
1470
+ const resolved = this.resolve(normalized, {
1471
+ type: "file"
1472
+ });
1473
+ if (resolved && !results.includes(resolved)) {
1474
+ results.push(resolved);
1475
+ }
1476
+ continue;
1477
+ }
1478
+ const absPattern = isType.isAbsolutePath(normalized) ? normalized : this.formatPath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, normalized));
1479
+ const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
1480
+ const baseDir = firstGlobIdx === -1 ? filePathFns.findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
1481
+ const stack = [
1482
+ baseDir && isType.isAbsolutePath(baseDir) ? baseDir : this.#context.workspaceConfig.workspaceRoot
1483
+ ];
1484
+ while (stack.length) {
1485
+ const dir = stack.pop();
1486
+ let entries = [];
1487
+ try {
1488
+ entries = this.readdirSync(dir);
1489
+ } catch {
1490
+ continue;
1491
+ }
1492
+ for (const entry of entries) {
1493
+ const full = this.formatPath(joinPaths.joinPaths(dir, entry));
1494
+ let stats;
1495
+ try {
1496
+ stats = this.#unifiedFS.lstatSync(full);
1497
+ } catch {
1498
+ stats = void 0;
1499
+ }
1500
+ if (!stats) continue;
1501
+ if (stats.isDirectory()) {
1502
+ stack.push(full);
1503
+ } else if (stats.isFile()) {
1504
+ if (this.#buildRegex(absPattern).test(full)) {
1505
+ const resolved = this.resolve(full, {
1506
+ type: "file"
1507
+ });
1508
+ if (resolved && !results.includes(resolved)) {
1509
+ results.push(resolved);
1510
+ }
1511
+ }
1512
+ }
1513
+ }
1514
+ }
1515
+ }
1516
+ return results;
1517
+ }
1518
+ /**
1519
+ * Moves a file from one path to another in the virtual file system (VFS).
1520
+ *
1521
+ * @param srcPath - The source path to move
1522
+ * @param destPath - The destination path to move to
1581
1523
  */
1582
- checkVariants(request, parentPath) {
1583
- const path = parentPath ? joinPaths.joinPaths(parentPath, request) : request;
1584
- let file = this.checkExtensions(path);
1585
- if (file) {
1586
- return file;
1524
+ async move(srcPath, destPath) {
1525
+ const content = await this.readFile(srcPath);
1526
+ await this.writeFile(destPath, content);
1527
+ await this.rm(srcPath);
1528
+ }
1529
+ /**
1530
+ * Synchronously moves a file from one path to another in the virtual file system (VFS).
1531
+ *
1532
+ * @param srcPath - The source path to move
1533
+ * @param destPath - The destination path to move to
1534
+ */
1535
+ moveSync(srcPath, destPath) {
1536
+ const content = this.readFileSync(srcPath);
1537
+ this.writeFileSync(destPath, content);
1538
+ this.rmSync(srcPath);
1539
+ }
1540
+ /**
1541
+ * Copies a file from one path to another in the virtual file system (VFS).
1542
+ *
1543
+ * @param srcPath - The source path to copy
1544
+ * @param destPath - The destination path to copy to
1545
+ */
1546
+ async copy(srcPath, destPath) {
1547
+ const content = await this.readFile(srcPath);
1548
+ await this.writeFile(destPath, content);
1549
+ }
1550
+ /**
1551
+ * Synchronously copies a file from one path to another in the virtual file system (VFS).
1552
+ *
1553
+ * @param srcPath - The source path to copy
1554
+ * @param destPath - The destination path to copy to
1555
+ */
1556
+ copySync(srcPath, destPath) {
1557
+ const content = this.readFileSync(srcPath);
1558
+ this.writeFileSync(destPath, content);
1559
+ }
1560
+ /**
1561
+ * Lists files in a given path.
1562
+ *
1563
+ * @param pathOrId - The path to list files from.
1564
+ * @param options - Options for listing files, such as encoding and recursion.
1565
+ * @returns An array of file names in the specified path.
1566
+ */
1567
+ async readdir(pathOrId, options = "utf8") {
1568
+ return this.#unifiedFS.resolveFS(pathOrId).promises.readdir(toFilePath(pathOrId), options);
1569
+ }
1570
+ /**
1571
+ * Asynchronously reads a file from the virtual file system (VFS).
1572
+ *
1573
+ * @param pathOrId - The path or ID of the file to read.
1574
+ * @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
1575
+ */
1576
+ async readFile(pathOrId, options = "utf8") {
1577
+ if (!pathOrId) {
1578
+ return void 0;
1587
1579
  }
1588
- file = this.checkIndex(path);
1589
- if (file) {
1590
- return file;
1580
+ const filePath = this.resolve(toFilePath(pathOrId), {
1581
+ type: "file"
1582
+ });
1583
+ if (filePath) {
1584
+ let result;
1585
+ if (isFunction.isFunction(this.#unifiedFS.resolveFS(filePath).promises.readFile)) {
1586
+ result = (await this.#unifiedFS.resolveFS(filePath).promises.readFile(filePath, options))?.toString("utf8");
1587
+ } else {
1588
+ result = this.#unifiedFS.resolveFS(filePath).readFileSync(filePath, options);
1589
+ }
1590
+ const content = isBuffer.isBuffer(result) ? bufferToString.bufferToString(result) : result;
1591
+ return content;
1591
1592
  }
1592
- return false;
1593
+ return void 0;
1593
1594
  }
1594
1595
  /**
1595
- * Check if the index file exists in the given request path.
1596
+ * Synchronously reads a file from the virtual file system (VFS).
1596
1597
  *
1597
- * @param request - The request path to check.
1598
- * @returns The index file path if it exists, otherwise false.
1598
+ * @param pathOrId - The path or ID of the file to read.
1599
+ * @returns The contents of the file as a string, or undefined if the file does not exist.
1599
1600
  */
1600
- checkIndex(request) {
1601
- let file = joinPaths.joinPaths(request, "index");
1602
- if (this.#existsSync(file)) {
1603
- return file;
1601
+ readFileSync(pathOrId, options = "utf8") {
1602
+ if (!pathOrId) {
1603
+ return void 0;
1604
1604
  }
1605
- file = this.checkExtensions(file);
1606
- if (file) {
1607
- return file;
1605
+ const filePath = this.resolve(toFilePath(pathOrId), {
1606
+ type: "file"
1607
+ });
1608
+ if (filePath) {
1609
+ const result = this.#unifiedFS.resolveFS(filePath).readFileSync(filePath, options);
1610
+ const content = isBuffer.isBuffer(result) ? bufferToString.bufferToString(result) : result;
1611
+ return content;
1608
1612
  }
1609
- return false;
1613
+ return void 0;
1610
1614
  }
1611
1615
  /**
1612
- * Check if the file exists with different extensions.
1616
+ * Writes a file to the virtual file system (VFS).
1613
1617
  *
1614
- * @param request - The request path to check.
1615
- * @param vfs - The file system module to use for checking file existence.
1616
- * @returns The file path if it exists with any of the checked extensions, otherwise false.
1618
+ * @param path - The path to the file.
1619
+ * @param data - The contents of the file.
1620
+ * @param options - Optional parameters for writing the file.
1621
+ * @returns A promise that resolves when the file is written.
1617
1622
  */
1618
- checkExtensions(request) {
1619
- let file = `${request}.ts`;
1620
- if (this.#existsSync(file)) {
1621
- return file;
1623
+ async writeFile(path, data = "", options = "utf8") {
1624
+ const formattedPath = this.formatPath(path);
1625
+ if (!this.isDirectory(filePathFns.findFilePath(formattedPath))) {
1626
+ await this.mkdir(filePathFns.findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
1622
1627
  }
1623
- file = `${request}.mts`;
1624
- if (this.#existsSync(file)) {
1625
- return file;
1628
+ let code = isPowerLinesWriteFileData(data) ? data.code : data;
1629
+ if ((!isPowerlinesWriteFileOptions(options) || !options.skipFormat) && isSetString.isSetString(code)) {
1630
+ const resolvedConfig = await prettier.resolveConfig(formattedPath);
1631
+ if (resolvedConfig) {
1632
+ code = await prettier.format(code, {
1633
+ absolutePath: formattedPath,
1634
+ ...resolvedConfig
1635
+ });
1636
+ }
1626
1637
  }
1627
- file = `${request}.cts`;
1628
- if (this.#existsSync(file)) {
1629
- return file;
1638
+ const outputMode = this.#unifiedFS.resolveMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
1639
+ this.#log(types.LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes.prettyBytes(new buffer$1.Blob(toArray.toArray(code)).size)})`);
1640
+ this.metadata[formattedPath] = {
1641
+ mode: outputMode,
1642
+ variant: "normal",
1643
+ ...isPowerLinesWriteFileData(data) ? data : {}
1644
+ };
1645
+ this.#clearResolverCache(formattedPath);
1646
+ const ifs = this.#unifiedFS.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
1647
+ if (isFunction.isFunction(ifs.promises.writeFile)) {
1648
+ return ifs.promises.writeFile(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
1630
1649
  }
1631
- file = `${request}.tsx`;
1632
- if (this.#existsSync(file)) {
1633
- return file;
1650
+ return ifs.writeFileSync(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
1651
+ }
1652
+ /**
1653
+ * Synchronously writes a file to the virtual file system (VFS).
1654
+ *
1655
+ * @param path - The file to write.
1656
+ * @param data - The contents of the file.
1657
+ * @param options - Optional parameters for writing the file.
1658
+ */
1659
+ writeFileSync(path, data = "", options = "utf8") {
1660
+ const formattedPath = this.formatPath(path);
1661
+ if (!this.isDirectory(filePathFns.findFilePath(formattedPath))) {
1662
+ this.mkdirSync(filePathFns.findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
1634
1663
  }
1635
- file = `${request}.js`;
1636
- if (this.#existsSync(file)) {
1637
- return file;
1664
+ const code = isPowerLinesWriteFileData(data) ? data.code : data;
1665
+ const outputMode = this.#unifiedFS.resolveMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
1666
+ this.#log(types.LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes.prettyBytes(new buffer$1.Blob(toArray.toArray(code)).size)})`);
1667
+ this.metadata[formattedPath] = {
1668
+ mode: outputMode,
1669
+ variant: "normal",
1670
+ ...isPowerLinesWriteFileData(data) ? data : {}
1671
+ };
1672
+ this.#clearResolverCache(formattedPath);
1673
+ const writeStream = this.#unifiedFS.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0).createWriteStream(formattedPath);
1674
+ try {
1675
+ writeStream.write(code);
1676
+ } finally {
1677
+ writeStream.close();
1638
1678
  }
1639
- file = `${request}.mjs`;
1640
- if (this.#existsSync(file)) {
1641
- return file;
1679
+ }
1680
+ /**
1681
+ * Synchronously checks if a file exists in the virtual file system (VFS).
1682
+ *
1683
+ * @param pathOrId - The path or ID of the file to check.
1684
+ * @returns `true` if the file exists, otherwise `false`.
1685
+ */
1686
+ existsSync(pathOrId) {
1687
+ return this.resolve(pathOrId) !== false;
1688
+ }
1689
+ /**
1690
+ * Retrieves the metadata of a file in the virtual file system (VFS).
1691
+ *
1692
+ * @param pathOrId - The path or ID of the file to retrieve metadata for.
1693
+ * @returns The metadata of the file, or undefined if the file does not exist.
1694
+ */
1695
+ getMetadata(pathOrId) {
1696
+ const resolved = this.resolve(pathOrId);
1697
+ if (resolved && this.metadata[resolved]) {
1698
+ return this.metadata[resolved];
1642
1699
  }
1643
- file = `${request}.cjs`;
1644
- if (this.#existsSync(file)) {
1645
- return file;
1700
+ return void 0;
1701
+ }
1702
+ /**
1703
+ * Checks if a file exists in the virtual file system (VFS).
1704
+ *
1705
+ * @remarks
1706
+ * 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.
1707
+ *
1708
+ * @param pathOrId - The path of the file to check.
1709
+ * @returns `true` if the file exists, otherwise `false`.
1710
+ */
1711
+ isFile(pathOrId) {
1712
+ const resolved = this.resolve(pathOrId);
1713
+ return !!(resolved && (this.#unifiedFS.virtual.existsSync(resolved) && this.#unifiedFS.virtual.lstatSync(resolved).isFile() || this.#unifiedFS.physical.existsSync(resolved) && this.#unifiedFS.physical.lstatSync(resolved).isFile() || this.#unifiedFS.resolveFS(resolved).existsSync(resolved) && this.#unifiedFS.resolveFS(resolved).lstatSync(resolved).isFile()));
1714
+ }
1715
+ /**
1716
+ * Checks if a directory exists in the virtual file system (VFS).
1717
+ *
1718
+ * @param pathOrId - The path of the directory to check.
1719
+ * @returns `true` if the directory exists, otherwise `false`.
1720
+ */
1721
+ isDirectory(pathOrId) {
1722
+ const resolved = this.resolve(pathOrId);
1723
+ return !!(resolved && (this.#unifiedFS.virtual.existsSync(resolved) && this.#unifiedFS.virtual.lstatSync(resolved).isDirectory() || this.#unifiedFS.physical.existsSync(resolved) && this.#unifiedFS.physical.lstatSync(resolved).isDirectory() || this.#unifiedFS.resolveFS(resolved).existsSync(resolved) && this.#unifiedFS.resolveFS(resolved).lstatSync(resolved).isDirectory()));
1724
+ }
1725
+ /**
1726
+ * Retrieves the status of a file in the virtual file system (VFS).
1727
+ *
1728
+ * @param pathOrId - The path or ID of the file to retrieve status for.
1729
+ * @returns A promise that resolves to the file's status information, or false if the file does not exist.
1730
+ */
1731
+ async stat(pathOrId, options) {
1732
+ return this.#unifiedFS.resolveFS(pathOrId).promises.stat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
1733
+ }
1734
+ /**
1735
+ * Synchronously retrieves the status of a file in the virtual file system (VFS).
1736
+ *
1737
+ * @param pathOrId - The path or ID of the file to retrieve status for.
1738
+ * @returns The file's status information, or false if the file does not exist.
1739
+ */
1740
+ statSync(pathOrId) {
1741
+ return this.#unifiedFS.resolveFS(pathOrId).statSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId));
1742
+ }
1743
+ /**
1744
+ * Retrieves the status of a symbolic link in the virtual file system (VFS).
1745
+ *
1746
+ * @param pathOrId - The path or ID of the symbolic link to retrieve status for.
1747
+ * @returns A promise that resolves to the symbolic link's status information, or false if the link does not exist.
1748
+ */
1749
+ async lstat(pathOrId, options) {
1750
+ return this.#unifiedFS.resolveFS(pathOrId).promises.lstat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
1751
+ }
1752
+ /**
1753
+ * Synchronously retrieves the status of a symbolic link in the virtual file system (VFS).
1754
+ *
1755
+ * @param pathOrId - The path or ID of the symbolic link to retrieve status for.
1756
+ * @returns The symbolic link's status information, or false if the link does not exist.
1757
+ */
1758
+ lstatSync(pathOrId, options) {
1759
+ return this.#unifiedFS.resolveFS(pathOrId).lstatSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
1760
+ }
1761
+ /**
1762
+ * Resolves a path or ID to its real path in the virtual file system (VFS).
1763
+ *
1764
+ * @param pathOrId - The path or ID to resolve.
1765
+ * @returns The resolved real path if it exists, otherwise undefined.
1766
+ */
1767
+ realpathSync(pathOrId) {
1768
+ const filePath = this.resolve(toFilePath(pathOrId));
1769
+ if (!filePath) {
1770
+ throw new Error(`File not found: ${toFilePath(pathOrId)}`);
1646
1771
  }
1647
- file = `${request}.jsx`;
1648
- if (this.#existsSync(file)) {
1649
- return file;
1772
+ return filePath;
1773
+ }
1774
+ /**
1775
+ * Resolves a path or ID parameter to a corresponding virtual file path in the virtual file system (VFS).
1776
+ *
1777
+ * @param pathOrId - The path or ID to resolve.
1778
+ * @param options - Optional parameters for resolving the path, such as whether to include the file extension.
1779
+ * @returns The resolved file path if it exists, otherwise undefined.
1780
+ */
1781
+ resolve(pathOrId, options = {}) {
1782
+ const formattedPathOrId = toFilePath(pathOrId);
1783
+ const resolverKey = `${formattedPathOrId}${options.withExtension ? "-ext" : ""}${options.paths ? `-${murmurhash.murmurhash(options.paths)}` : ""}${options.type ? `-${options.type}` : ""}`;
1784
+ if (this.#cachedResolver.has(resolverKey)) {
1785
+ return this.#cachedResolver.get(resolverKey);
1650
1786
  }
1651
- file = `${request}.json`;
1652
- if (this.#existsSync(file)) {
1653
- return file;
1787
+ let result = this.#resolveId(formattedPathOrId);
1788
+ if (!result) {
1789
+ result = this.#resolvePath(formattedPathOrId, options);
1654
1790
  }
1655
- file = `${request}.d.ts`;
1656
- if (this.#existsSync(file)) {
1657
- return file;
1791
+ if (!result) {
1792
+ result = false;
1658
1793
  }
1659
- return false;
1794
+ if (result && options.withExtension === false) {
1795
+ return result.replace(/\.[m|c]?[t|j]sx?$/, "");
1796
+ }
1797
+ this.#cachedResolver.set(resolverKey, result);
1798
+ return result;
1799
+ }
1800
+ /**
1801
+ * Converts a relative path to an absolute path based on the workspace and project root.
1802
+ *
1803
+ * @param path - The relative path to convert.
1804
+ * @returns The absolute path.
1805
+ */
1806
+ formatPath(path) {
1807
+ const formattedPath = toFilePath(path);
1808
+ if (isType.isAbsolutePath(formattedPath) || formattedPath.startsWith(this.#context.workspaceConfig.workspaceRoot)) {
1809
+ return formattedPath;
1810
+ } else if (formattedPath.startsWith(this.#context.config.projectRoot)) {
1811
+ return joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, formattedPath);
1812
+ }
1813
+ return formattedPath;
1814
+ }
1815
+ /**
1816
+ * Disposes of the virtual file system (VFS) by saving its state to disk.
1817
+ */
1818
+ async dispose() {
1819
+ if (!this.#isDisposed) {
1820
+ this.#isDisposed = true;
1821
+ this.#log(types.LogLevelLabel.DEBUG, "Disposing virtual file system...");
1822
+ await this.unlink(joinPaths.joinPaths(this.#context.cachePath, "fs.bin"));
1823
+ const message = new $__namespace.Message();
1824
+ const data = message.initRoot(FileSystemData);
1825
+ const virtualFS = this.#unifiedFS.toJSON();
1826
+ const files = data._initFiles(Object.keys(virtualFS).length);
1827
+ Object.entries(virtualFS).filter(([_, content]) => content).forEach(([path, content], index) => {
1828
+ const fileData = files.get(index);
1829
+ fileData.path = path;
1830
+ fileData.content = content;
1831
+ });
1832
+ const ids = data._initIds(Object.keys(this.ids).length);
1833
+ Object.entries(this.ids).forEach(([id, path], index) => {
1834
+ const fileId = ids.get(index);
1835
+ fileId.id = id;
1836
+ fileId.path = path;
1837
+ });
1838
+ const metadata = data._initMetadata(Object.keys(this.metadata).length);
1839
+ Object.entries(this.metadata).forEach(([id, value], index) => {
1840
+ const fileMetadata = metadata.get(index);
1841
+ fileMetadata.id = id;
1842
+ fileMetadata.mode = value.mode;
1843
+ fileMetadata.variant = value.variant;
1844
+ if (value.properties) {
1845
+ const props = fileMetadata._initProperties(Object.keys(value.properties).length);
1846
+ Object.entries(value.properties).forEach(([key, val], propIndex) => {
1847
+ const propData = props.get(propIndex);
1848
+ propData.key = key;
1849
+ propData.value = val;
1850
+ });
1851
+ }
1852
+ });
1853
+ await buffer.writeFileBuffer(joinPaths.joinPaths(this.#context.cachePath, "fs.bin"), message.toArrayBuffer());
1854
+ }
1855
+ }
1856
+ /**
1857
+ * Initializes the virtual file system (VFS) by patching the file system module if necessary.
1858
+ */
1859
+ [__VFS_PATCH__]() {
1860
+ if (!this.#isPatched && this.#context.config.output.mode !== "fs") {
1861
+ this.#revert = patchFS(fs__default.default, this);
1862
+ this.#isPatched = true;
1863
+ }
1864
+ }
1865
+ /**
1866
+ * Reverts the file system module to its original state if it was previously patched.
1867
+ */
1868
+ [__VFS_REVERT__]() {
1869
+ if (this.#isPatched && this.#context.config.output.mode !== "fs") {
1870
+ if (!this.#revert) {
1871
+ throw new Error("Attempting to revert File System patch prior to calling `__init__` function");
1872
+ }
1873
+ this.#revert?.();
1874
+ this.#isPatched = false;
1875
+ }
1876
+ }
1877
+ async [Symbol.asyncDispose]() {
1878
+ return this.dispose();
1660
1879
  }
1661
1880
  };
1662
- function createVfs(context) {
1663
- const vfs = new VirtualFileSystem(context);
1664
- return vfs;
1881
+
1882
+ // ../powerlines/src/types/commands.ts
1883
+ var SUPPORTED_COMMANDS = [
1884
+ "new",
1885
+ "clean",
1886
+ "prepare",
1887
+ "lint",
1888
+ "test",
1889
+ "build",
1890
+ "docs",
1891
+ "deploy",
1892
+ "finalize"
1893
+ ];
1894
+
1895
+ // ../powerlines/src/plugin-utils/helpers.ts
1896
+ function isPlugin(value) {
1897
+ return isSetObject.isSetObject(value) && "name" in value && isSetString.isSetString(value.name) && (isUndefined.isUndefined(value.applyToEnvironment) || "applyToEnvironment" in value && isFunction.isFunction(value.applyToEnvironment)) && (isUndefined.isUndefined(value.dedupe) || "dedupe" in value && isFunction.isFunction(value.dedupe)) && (isUndefined.isUndefined(value.dependsOn) || "dependsOn" in value && Array.isArray(value.dependsOn) && value.dependsOn.every(isPluginConfig)) && SUPPORTED_COMMANDS.every((command) => isUndefined.isUndefined(value[command]) || command in value && (isFunction.isFunction(value[command]) || isSetObject.isSetObject(value[command]) && "handler" in value[command] && isFunction.isFunction(value[command].handler)));
1898
+ }
1899
+ chunkSHUYVCID_js.__name(isPlugin, "isPlugin");
1900
+ function isPluginConfigObject(value) {
1901
+ return isSetObject.isSetObject(value) && "plugin" in value && ((isSetString.isSetString(value.plugin) || isFunction.isFunction(value.plugin)) && "options" in value && isSetObject.isSetObject(value.options) || isPlugin(value.plugin));
1902
+ }
1903
+ chunkSHUYVCID_js.__name(isPluginConfigObject, "isPluginConfigObject");
1904
+ function isPluginConfigTuple(value) {
1905
+ return Array.isArray(value) && (value.length === 1 || value.length === 2) && ((isSetString.isSetString(value[0]) || isFunction.isFunction(value[0])) && value.length > 1 && isSetObject.isSetObject(value[1]) || isPlugin(value[0]));
1906
+ }
1907
+ chunkSHUYVCID_js.__name(isPluginConfigTuple, "isPluginConfigTuple");
1908
+ function isPluginConfig(value) {
1909
+ return isSetString.isSetString(value) || isFunction.isFunction(value) || isPlugin(value) || isPluginConfigObject(value) || isPluginConfigTuple(value);
1910
+ }
1911
+ chunkSHUYVCID_js.__name(isPluginConfig, "isPluginConfig");
1912
+ function isPluginHookFunction(value) {
1913
+ return isFunction.isFunction(value) || isSetObject.isSetObject(value) && "handler" in value && isFunction.isFunction(value.handler);
1914
+ }
1915
+ chunkSHUYVCID_js.__name(isPluginHookFunction, "isPluginHookFunction");
1916
+ function isPluginHookObject(value) {
1917
+ return isSetObject.isSetObject(value) && "handler" in value && isFunction.isFunction(value.handler);
1918
+ }
1919
+ chunkSHUYVCID_js.__name(isPluginHookObject, "isPluginHookObject");
1920
+ function isPluginHook(value) {
1921
+ return isPluginHookFunction(value) || isPluginHookObject(value);
1922
+ }
1923
+ chunkSHUYVCID_js.__name(isPluginHook, "isPluginHook");
1924
+ function getHookHandler(pluginHook) {
1925
+ return isFunction.isFunction(pluginHook) ? pluginHook : pluginHook.handler;
1926
+ }
1927
+ chunkSHUYVCID_js.__name(getHookHandler, "getHookHandler");
1928
+ function isHookExternal(hook) {
1929
+ return hook.startsWith("vite:") || hook.startsWith("esbuild:") || hook.startsWith("rolldown:") || hook.startsWith("rollup:") || hook.startsWith("webpack:") || hook.startsWith("rspack:") || hook.startsWith("farm:");
1930
+ }
1931
+ chunkSHUYVCID_js.__name(isHookExternal, "isHookExternal");
1932
+ function checkDedupe(plugin, plugins2) {
1933
+ return plugin.dedupe === false || plugins2.some((p) => p.dedupe !== false && (isFunction.isFunction(p.dedupe) && p.dedupe(plugin) || p.name === plugin.name));
1934
+ }
1935
+ chunkSHUYVCID_js.__name(checkDedupe, "checkDedupe");
1936
+ function addPluginHook(context, plugin, pluginHook, hooksList) {
1937
+ if (!checkDedupe(plugin, hooksList.map((hook) => hook.plugin))) {
1938
+ hooksList.push(isFunction.isFunction(pluginHook) ? {
1939
+ plugin,
1940
+ handler: getHookHandler(pluginHook).bind(context)
1941
+ } : {
1942
+ plugin,
1943
+ ...pluginHook,
1944
+ handler: getHookHandler(pluginHook).bind(context)
1945
+ });
1946
+ }
1947
+ }
1948
+ chunkSHUYVCID_js.__name(addPluginHook, "addPluginHook");
1949
+ function resolveOptions(options) {
1950
+ return defu2__default.default(options, {
1951
+ interopDefault: true,
1952
+ fsCache: options.mode !== "development" ? joinPaths.joinPaths(options.cacheDir, "jiti") : false,
1953
+ moduleCache: options.mode !== "development"
1954
+ });
1955
+ }
1956
+ chunkSHUYVCID_js.__name(resolveOptions, "resolveOptions");
1957
+ function createPluginResolver(options) {
1958
+ return jiti.createJiti(joinPaths.joinPaths(options.workspaceRoot, options.projectRoot), resolveOptions({
1959
+ ...options
1960
+ }));
1961
+ }
1962
+ chunkSHUYVCID_js.__name(createPluginResolver, "createPluginResolver");
1963
+ function createResolver(options) {
1964
+ const baseResolver = jiti.createJiti(joinPaths.joinPaths(options.workspaceRoot, options.projectRoot), resolveOptions(options));
1965
+ baseResolver.plugin = createPluginResolver(options);
1966
+ return baseResolver;
1665
1967
  }
1666
- chunkSHUYVCID_js.__name(createVfs, "createVfs");
1968
+ chunkSHUYVCID_js.__name(createResolver, "createResolver");
1667
1969
 
1668
1970
  // ../powerlines/src/internal/contexts/context.ts
1669
1971
  var configCache = /* @__PURE__ */ new WeakMap();
@@ -1703,7 +2005,6 @@ var PowerlinesContext = class _PowerlinesContext {
1703
2005
  lint: config.lint,
1704
2006
  transform: config.transform,
1705
2007
  build: config.build,
1706
- override: config.override,
1707
2008
  framework: config.framework
1708
2009
  };
1709
2010
  }
@@ -1715,7 +2016,7 @@ var PowerlinesContext = class _PowerlinesContext {
1715
2016
  * @returns A promise that resolves to the new context.
1716
2017
  */
1717
2018
  static async from(workspaceRoot, config) {
1718
- const context = new _PowerlinesContext(await chunkUOTRU26N_js.loadWorkspaceConfig(workspaceRoot, config.root));
2019
+ const context = new _PowerlinesContext(await chunkLTCZN4I4_js.loadWorkspaceConfig(workspaceRoot, config.root));
1719
2020
  await context.withUserConfig(config);
1720
2021
  context.powerlinesPath = await resolve.resolvePackage("powerlines");
1721
2022
  if (!context.powerlinesPath) {
@@ -1779,7 +2080,7 @@ var PowerlinesContext = class _PowerlinesContext {
1779
2080
  */
1780
2081
  get fs() {
1781
2082
  if (!this.#fs) {
1782
- this.#fs = createVfs(this);
2083
+ this.#fs = VirtualFileSystem.createSync(this);
1783
2084
  }
1784
2085
  return this.#fs;
1785
2086
  }
@@ -1802,13 +2103,11 @@ var PowerlinesContext = class _PowerlinesContext {
1802
2103
  workspaceRoot: this.workspaceConfig?.workspaceRoot,
1803
2104
  projectRoot: this.config?.projectRoot
1804
2105
  }, {
1805
- maxLength: chunkUOTRU26N_js.PROJECT_ROOT_HASH_LENGTH
2106
+ maxLength: chunkLTCZN4I4_js.PROJECT_ROOT_HASH_LENGTH
1806
2107
  }),
1807
2108
  configHash: murmurhash.murmurhash(this.config, {
1808
- maxLength: chunkUOTRU26N_js.CACHE_HASH_LENGTH
1809
- }),
1810
- builtinIdMap: {},
1811
- virtualFiles: {}
2109
+ maxLength: chunkLTCZN4I4_js.CACHE_HASH_LENGTH
2110
+ })
1812
2111
  };
1813
2112
  }
1814
2113
  /**
@@ -1867,7 +2166,7 @@ var PowerlinesContext = class _PowerlinesContext {
1867
2166
  * Get the path to the data directory for the project
1868
2167
  */
1869
2168
  get dataPath() {
1870
- return join.joinPaths(this.envPaths.data, "projects", chunkUOTRU26N_js.getPrefixedProjectRootHash(this.config.name, this.meta.projectRootHash));
2169
+ return join.joinPaths(this.envPaths.data, "projects", chunkLTCZN4I4_js.getPrefixedProjectRootHash(this.config.name, this.meta.projectRootHash));
1871
2170
  }
1872
2171
  /**
1873
2172
  * Get the path to the cache directory for the project
@@ -1877,7 +2176,7 @@ var PowerlinesContext = class _PowerlinesContext {
1877
2176
  checksum: this.#checksum,
1878
2177
  config: this.meta.configHash
1879
2178
  }, {
1880
- maxLength: chunkUOTRU26N_js.CACHE_HASH_LENGTH
2179
+ maxLength: chunkLTCZN4I4_js.CACHE_HASH_LENGTH
1881
2180
  }));
1882
2181
  }
1883
2182
  /**
@@ -1896,13 +2195,13 @@ var PowerlinesContext = class _PowerlinesContext {
1896
2195
  * The builtin module id that exist in the Powerlines virtual file system
1897
2196
  */
1898
2197
  get builtins() {
1899
- return Object.values(this.fs.meta).filter((meta) => meta && meta.variant === "builtin").map((meta) => meta?.id).filter(Boolean);
2198
+ return Object.values(this.fs.metadata).filter((meta) => meta && meta.variant === "builtin").map((meta) => meta?.id).filter(Boolean);
1900
2199
  }
1901
2200
  /**
1902
- * Get the project root relative to the workspace root
2201
+ * Get the builtin virtual files that exist in the Powerlines virtual file system
1903
2202
  */
1904
2203
  async getBuiltins() {
1905
- return Promise.all(Object.entries(this.fs.meta).filter(([, meta]) => meta && meta.variant === "builtin").map(async ([path, meta]) => {
2204
+ return Promise.all(Object.entries(this.fs.metadata).filter(([, meta]) => meta && meta.variant === "builtin").map(async ([path, meta]) => {
1906
2205
  const code = await this.fs.readFile(path);
1907
2206
  return {
1908
2207
  ...meta,
@@ -1922,7 +2221,7 @@ var PowerlinesContext = class _PowerlinesContext {
1922
2221
  return this.fs.writeFile(isType.isAbsolute(path) ? path : append.appendPath(path, this.entryPath), {
1923
2222
  code,
1924
2223
  variant: "entry"
1925
- }, defu3__default.default(options, {
2224
+ }, defu2__default.default(options, {
1926
2225
  mode: this.config.output.mode
1927
2226
  }));
1928
2227
  }
@@ -1939,7 +2238,7 @@ var PowerlinesContext = class _PowerlinesContext {
1939
2238
  id,
1940
2239
  code,
1941
2240
  variant: "builtin"
1942
- }, defu3__default.default(options, {
2241
+ }, defu2__default.default(options, {
1943
2242
  mode: this.config.output.mode
1944
2243
  }));
1945
2244
  }
@@ -1961,7 +2260,7 @@ var PowerlinesContext = class _PowerlinesContext {
1961
2260
  options
1962
2261
  });
1963
2262
  }
1964
- const result = await oxcParser.parseAsync(id, code, defu3__default.default(options ?? {}, {
2263
+ const result = await oxcParser.parseAsync(id, code, defu2__default.default(options ?? {}, {
1965
2264
  lang: filePathFns.hasFileExtension(id) ? void 0 : "ts",
1966
2265
  astType: filePathFns.hasFileExtension(id) ? void 0 : "ts",
1967
2266
  sourceType: "module",
@@ -2130,7 +2429,7 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
2130
2429
  if (exists.existsSync(packageJsonPath)) {
2131
2430
  this.packageJson = await json.readJsonFile(packageJsonPath);
2132
2431
  }
2133
- this.#checksum = await chunkUOTRU26N_js.getChecksum(cacheKey.projectRoot);
2432
+ this.#checksum = await chunkLTCZN4I4_js.getChecksum(cacheKey.projectRoot);
2134
2433
  this.resolver = createResolver({
2135
2434
  workspaceRoot: this.workspaceConfig.workspaceRoot,
2136
2435
  projectRoot: cacheKey.projectRoot,
@@ -2138,7 +2437,7 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
2138
2437
  mode: cacheKey.mode,
2139
2438
  skipCache: cacheKey.skipCache
2140
2439
  });
2141
- const userConfig = await chunkUOTRU26N_js.loadUserConfigFile(cacheKey.projectRoot, this.resolver, cacheKey.command, cacheKey.mode, cacheKey.configFile, cacheKey.framework);
2440
+ const userConfig = await chunkLTCZN4I4_js.loadUserConfigFile(cacheKey.projectRoot, this.resolver, cacheKey.command, cacheKey.mode, cacheKey.configFile, cacheKey.framework);
2142
2441
  this.mergeUserConfig(userConfig.config);
2143
2442
  configCache.set(cacheKey, {
2144
2443
  projectJson: this.projectJson,
@@ -2149,7 +2448,7 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
2149
2448
  });
2150
2449
  }
2151
2450
  if (isSetObject.isSetObject(config)) {
2152
- this.resolvedConfig = defu3__default.default({
2451
+ this.resolvedConfig = defu2__default.default({
2153
2452
  inlineConfig: this.config.inlineConfig,
2154
2453
  userConfig: this.config.userConfig
2155
2454
  }, options.isHighPriority ? this.#getConfigProps(config) : {}, {
@@ -2205,9 +2504,9 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
2205
2504
  eslint: {}
2206
2505
  },
2207
2506
  build: {
2208
- target: "esnext"
2209
- },
2210
- override: {}
2507
+ target: "esnext",
2508
+ override: {}
2509
+ }
2211
2510
  });
2212
2511
  }
2213
2512
  this.config.entry = getUniqueEntries(this.config.entry);
@@ -2243,9 +2542,10 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
2243
2542
  ret.push(plugin);
2244
2543
  return ret;
2245
2544
  }, []);
2545
+ this.#fs ??= await VirtualFileSystem.create(this);
2246
2546
  }
2247
2547
  mergeUserConfig(from = {}, into = this.config.userConfig ?? {}) {
2248
- this.config.userConfig = defu3__default.default({
2548
+ this.config.userConfig = defu2__default.default({
2249
2549
  entry: Array.isArray(from.entry) && from.entry.length > 0 ? from.entry : Array.isArray(into?.entry) && into.entry.length > 0 ? into.entry : []
2250
2550
  }, omit.omit(from ?? {}, [
2251
2551
  "entry"
@@ -2300,7 +2600,7 @@ async function callHook(context, hook, options, ...args) {
2300
2600
  if (definedResults.length > 0) {
2301
2601
  let mergedResult = void 0;
2302
2602
  for (const result of definedResults) {
2303
- mergedResult = defu3.defu(result, mergedResult ?? {});
2603
+ mergedResult = defu2.defu(result, mergedResult ?? {});
2304
2604
  }
2305
2605
  return mergedResult;
2306
2606
  }
@@ -2502,7 +2802,7 @@ var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext
2502
2802
  * @returns A promise that resolves to the new context.
2503
2803
  */
2504
2804
  static async from(workspaceRoot, config) {
2505
- const context = new _PowerlinesAPIContext(await chunkUOTRU26N_js.loadWorkspaceConfig(workspaceRoot, config.root));
2805
+ const context = new _PowerlinesAPIContext(await chunkLTCZN4I4_js.loadWorkspaceConfig(workspaceRoot, config.root));
2506
2806
  await context.withUserConfig(config);
2507
2807
  context.powerlinesPath = await resolve.resolvePackage("powerlines");
2508
2808
  if (!context.powerlinesPath) {
@@ -2610,7 +2910,7 @@ async function emitTypes(context, tsconfig, files) {
2610
2910
  const emitResult = program.emit(void 0, (fileName, text, _, __, sourceFiles, _data) => {
2611
2911
  const sourceFile = sourceFiles?.[0];
2612
2912
  if (sourceFile?.fileName && !fileName.endsWith(".map")) {
2613
- if (context.builtins.some((file) => file === sourceFile.fileName || context.fs.meta[file]?.id && context.fs.meta[file]?.id === sourceFile.fileName)) {
2913
+ if (context.builtins.some((file) => file === sourceFile.fileName || context.fs.metadata[file]?.id && context.fs.metadata[file]?.id === sourceFile.fileName)) {
2614
2914
  builtinModules += `
2615
2915
  declare module "${context.fs.resolve(sourceFile.fileName)}" {
2616
2916
  ${text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
@@ -2759,7 +3059,7 @@ function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfi
2759
3059
  if (!tsconfigJson) {
2760
3060
  throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${joinPaths.joinPaths(projectRoot, tsconfig ?? "tsconfig.json")}`);
2761
3061
  }
2762
- const parsedCommandLine = ts2__default.default.parseJsonConfigFileContent(defu3__default.default(tsconfigRaw ?? {}, tsconfigJson), host, append.appendPath(projectRoot, workspaceRoot));
3062
+ const parsedCommandLine = ts2__default.default.parseJsonConfigFileContent(defu2__default.default(tsconfigRaw ?? {}, tsconfigJson), host, append.appendPath(projectRoot, workspaceRoot));
2763
3063
  if (parsedCommandLine.errors.length > 0) {
2764
3064
  const errorMessage = `Cannot parse the TypeScript compiler options. Please investigate the following issues:
2765
3065
  ${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && error.code ? `[${error.category}-${error.code}]: ` : "") + error.messageText.toString()}`).join("\n")}
@@ -3051,11 +3351,14 @@ ${context.entry.map((entry) => `- ${entry.input.file || entry.file}${entry.outpu
3051
3351
  await resolveTsconfig(context);
3052
3352
  await installDependencies(context);
3053
3353
  await this.callPostHook(context, "configResolved");
3354
+ if (context.config.build.polyfill) {
3355
+ context.config.build.polyfill = context.config.build.polyfill.map((polyfill) => replacePathTokens(context, polyfill));
3356
+ }
3054
3357
  context.log(types.LogLevelLabel.TRACE, `Powerlines configuration has been resolved:
3055
3358
 
3056
3359
  ${console.formatLogMessage(context.config)}`);
3057
- context.fs[chunkUOTRU26N_js.__VFS_INIT__]();
3058
- await chunkUOTRU26N_js.writeMetaFile(context);
3360
+ context.fs[__VFS_PATCH__]();
3361
+ await chunkLTCZN4I4_js.writeMetaFile(context);
3059
3362
  context.persistedMeta = context.meta;
3060
3363
  if (!exists.existsSync(context.cachePath)) {
3061
3364
  await helpers.createDirectory(context.cachePath);
@@ -3114,7 +3417,7 @@ ${console.formatLogMessage(context.config)}`);
3114
3417
  joinPaths.joinPaths(typescriptPath, "lib", "lib.esnext.full.d.ts")
3115
3418
  ]);
3116
3419
  context.log(types.LogLevelLabel.TRACE, "Parsing TypeScript configuration for the Powerlines project.");
3117
- const resolvedTsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.tsconfig.tsconfigFilePath, defu3__default.default({
3420
+ const resolvedTsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.tsconfig.tsconfigFilePath, defu2__default.default({
3118
3421
  compilerOptions: {
3119
3422
  strict: false,
3120
3423
  noEmit: false,
@@ -3185,8 +3488,8 @@ ${formatTypes(generatedTypes)}
3185
3488
  throw new Error("Failed to parse the TypeScript configuration file.");
3186
3489
  }
3187
3490
  await this.callPostHook(context, "prepare");
3188
- await chunkUOTRU26N_js.writeMetaFile(context);
3189
- context.fs[chunkUOTRU26N_js.__VFS_REVERT__]();
3491
+ await chunkLTCZN4I4_js.writeMetaFile(context);
3492
+ context.fs[__VFS_REVERT__]();
3190
3493
  });
3191
3494
  this.context.log(types.LogLevelLabel.INFO, "Powerlines API has been prepared successfully");
3192
3495
  }
@@ -3316,22 +3619,22 @@ ${formatTypes(generatedTypes)}
3316
3619
  this.#context.log(types.LogLevelLabel.TRACE, "Powerlines documentation generation completed");
3317
3620
  }
3318
3621
  /**
3319
- * Release the project
3622
+ * Deploy the project source code
3320
3623
  *
3321
3624
  * @remarks
3322
- * This method will prepare and build the Powerlines project, generating the necessary artifacts for release.
3625
+ * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
3323
3626
  *
3324
- * @param inlineConfig - The inline configuration for the release command
3627
+ * @param inlineConfig - The inline configuration for the deploy command
3325
3628
  */
3326
- async release(inlineConfig = {
3327
- command: "release"
3629
+ async deploy(inlineConfig = {
3630
+ command: "deploy"
3328
3631
  }) {
3329
- this.context.log(types.LogLevelLabel.INFO, "\u{1F4E6} Releasing the Powerlines project");
3632
+ this.context.log(types.LogLevelLabel.INFO, "\u{1F4E6} Deploying the Powerlines project");
3330
3633
  await this.prepare(inlineConfig);
3331
3634
  await this.#executeEnvironments(async (context) => {
3332
- await this.callHook(context, "release");
3635
+ await this.callHook(context, "deploy");
3333
3636
  });
3334
- this.context.log(types.LogLevelLabel.TRACE, "Powerlines release completed");
3637
+ this.context.log(types.LogLevelLabel.TRACE, "Powerlines deploy completed");
3335
3638
  }
3336
3639
  /**
3337
3640
  * Finalization process
@@ -3345,7 +3648,8 @@ ${formatTypes(generatedTypes)}
3345
3648
  this.context.log(types.LogLevelLabel.TRACE, "Powerlines finalize execution started");
3346
3649
  await this.#executeEnvironments(async (context) => {
3347
3650
  await this.callHook(context, "finalize");
3348
- context.fs[chunkUOTRU26N_js.__VFS_REVERT__]();
3651
+ context.fs[__VFS_REVERT__]();
3652
+ await context.fs.dispose();
3349
3653
  });
3350
3654
  this.context.log(types.LogLevelLabel.TRACE, "Powerlines finalize execution completed");
3351
3655
  }
@@ -3617,22 +3921,88 @@ var DEFAULT_ESBUILD_CONFIG = {
3617
3921
  logLevel: "silent"
3618
3922
  };
3619
3923
  function extractESBuildConfig(context) {
3620
- return defu3__default.default({
3924
+ const inject = context.config.build.override.inject ?? context.config.build.inject;
3925
+ if (inject && Object.keys(inject).length > 0) {
3926
+ context.fs.writeFileSync(joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.artifactsPath, "inject-shim.js"), Object.entries(inject).map(([key, value]) => {
3927
+ if (value) {
3928
+ if (Array.isArray(value)) {
3929
+ if (camelCase.camelCase(key) !== key) {
3930
+ if (value.length === 1) {
3931
+ return `
3932
+ import ${camelCase.camelCase(key)} from "${value[0]}";
3933
+ export { ${camelCase.camelCase(key)} as "${key}" }`;
3934
+ } else if (value.length > 1) {
3935
+ return `
3936
+ import ${value[1] === "*" ? `* as ${camelCase.camelCase(key)}` : `{ ${value[1]} as ${camelCase.camelCase(key)} }`} from "${value[0]}";
3937
+ export { ${camelCase.camelCase(key)} as "${key}" }`;
3938
+ }
3939
+ } else if (value.length === 1) {
3940
+ return `
3941
+ import ${key} from "${value[0]}";
3942
+ export { ${key} };`;
3943
+ } else if (value.length > 1) {
3944
+ return `
3945
+ import ${value[1] === "*" ? `* as ${key}` : `{ ${value[1]} as ${key} }`} from "${value[0]}";
3946
+ export { ${key} };`;
3947
+ }
3948
+ } else if (camelCase.camelCase(key) !== key) {
3949
+ return `
3950
+ import ${camelCase.camelCase(key)} from "${value[0]}";
3951
+ export { ${camelCase.camelCase(key)} as "${key}" }`;
3952
+ } else {
3953
+ return `
3954
+ import ${key} from "${value}";
3955
+ export { ${key} };`;
3956
+ }
3957
+ }
3958
+ return "";
3959
+ }).join("\n"));
3960
+ }
3961
+ return defu2__default.default({
3621
3962
  alias: context.builtins.reduce((ret, id) => {
3622
- const path = context.fs.ids[id];
3623
- if (path) {
3624
- ret[id] = path;
3963
+ if (!ret[id]) {
3964
+ const path = context.fs.ids[id];
3965
+ if (path) {
3966
+ ret[id] = path;
3967
+ }
3625
3968
  }
3626
3969
  return ret;
3627
- }, {})
3628
- }, context.config.build.variant === "esbuild" ? context.config.override : {}, {
3970
+ }, context.config.build.alias ? Array.isArray(context.config.build.alias) ? context.config.build.alias.reduce((ret, alias) => {
3971
+ if (!ret[alias.find.toString()]) {
3972
+ ret[alias.find.toString()] = alias.replacement;
3973
+ }
3974
+ return ret;
3975
+ }, {}) : context.config.build.alias : {}),
3976
+ inject: inject && Object.keys(inject).length > 0 ? [
3977
+ joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.artifactsPath, "inject-shim.js")
3978
+ ] : void 0
3979
+ }, context.config.build.variant === "esbuild" ? omit.omit(context.config.build.override, [
3980
+ "alias",
3981
+ "inject",
3982
+ "external",
3983
+ "noExternal",
3984
+ "skipNodeModulesBundle",
3985
+ "extensions"
3986
+ ]) : {}, {
3987
+ mainFields: context.config.build.mainFields,
3988
+ conditions: context.config.build.conditions,
3989
+ define: context.config.build.define,
3990
+ resolveExtensions: context.config.build.extensions,
3991
+ packages: context.config.build.skipNodeModulesBundle ? "external" : context.config.build.variant === "esbuild" ? context.config.build.packages : void 0,
3629
3992
  format: Array.isArray(context.config.output.format) ? context.config.output.format[0] : context.config.output.format,
3630
3993
  platform: context.config.build.platform,
3631
3994
  treeShaking: Boolean(context.config.build?.treeshake) || context.config.build?.treeShaking,
3632
3995
  outdir: context.config.output.outputPath,
3633
3996
  tsconfig: context.tsconfig.tsconfigFilePath,
3634
3997
  tsconfigRaw: context.tsconfig.tsconfigJson
3635
- }, context.config.build.variant === "esbuild" ? context.config.build : {}, {
3998
+ }, context.config.build.variant === "esbuild" ? omit.omit(context.config.build, [
3999
+ "alias",
4000
+ "inject",
4001
+ "external",
4002
+ "noExternal",
4003
+ "skipNodeModulesBundle",
4004
+ "extensions"
4005
+ ]) : {}, {
3636
4006
  minify: context.config.mode !== "development",
3637
4007
  metafile: context.config.mode === "development",
3638
4008
  sourcemap: context.config.mode === "development"
@@ -3660,21 +4030,35 @@ var DEFAULT_VITE_CONFIG = {
3660
4030
  clearScreen: true
3661
4031
  };
3662
4032
  function extractViteConfig(context) {
3663
- return defu3__default.default({
4033
+ return defu2__default.default({
3664
4034
  resolve: {
3665
4035
  alias: context.builtins.reduce((ret, id) => {
3666
- const path = context.fs.ids[id];
3667
- if (path) {
3668
- ret[id] = path;
4036
+ if (!ret.find((e) => e.find === id)) {
4037
+ const path = context.fs.ids[id];
4038
+ if (path) {
4039
+ ret.push({
4040
+ find: id,
4041
+ replacement: path
4042
+ });
4043
+ }
3669
4044
  }
3670
4045
  return ret;
3671
- }, {})
3672
- }
3673
- }, context.config.build.variant === "vite" ? context.config.override : {}, {
3674
- external: context.config.build.external,
3675
- noExternal: context.config.build.noExternal,
3676
- skipNodeModulesBundle: context.config.build.skipNodeModulesBundle
3677
- }, {
4046
+ }, context.config.build.alias ? Array.isArray(context.config.build.alias) ? context.config.build.alias : Object.entries(context.config.build.alias).reduce((ret, [id, path]) => {
4047
+ if (!ret.find((e) => e.find === id)) {
4048
+ ret.push({
4049
+ find: id,
4050
+ replacement: path
4051
+ });
4052
+ }
4053
+ return ret;
4054
+ }, []) : []),
4055
+ dedupe: context.config.build.dedupe,
4056
+ mainFields: context.config.build.mainFields,
4057
+ conditions: context.config.build.conditions,
4058
+ extensions: context.config.build.extensions
4059
+ }
4060
+ }, context.config.build.variant === "vite" ? context.config.build.override : {}, {
4061
+ define: context.config.build.define,
3678
4062
  rootDir: context.config.sourceRoot,
3679
4063
  platform: context.config.build.platform,
3680
4064
  mode: context.config.mode === "development" ? "development" : "production",
@@ -3686,8 +4070,7 @@ function extractViteConfig(context) {
3686
4070
  },
3687
4071
  esbuild: extractESBuildConfig(context),
3688
4072
  logLevel: context.config.logLevel ?? void 0,
3689
- envDir: context.config.projectRoot,
3690
- noExternal: context.builtins
4073
+ envDir: context.config.projectRoot
3691
4074
  }, context.config.build.variant === "vite" ? context.config.build : {}, {
3692
4075
  build: {
3693
4076
  minify: context.config.mode !== "development",
@@ -3730,9 +4113,23 @@ async function handleResolveId(context, args, options = {}) {
3730
4113
  };
3731
4114
  }
3732
4115
  }
3733
- if (context.fs.isTsconfigPath(args.id)) {
3734
- const tsconfigPath = context.fs.resolveTsconfigPath(args.id);
3735
- const tsconfigPathPackage = context.fs.resolveTsconfigPathPackage(args.id);
4116
+ if (!!context.tsconfig.options.paths && Object.keys(context.tsconfig.options.paths).some((path) => args.id.startsWith(path.replaceAll("*", "")))) {
4117
+ let tsconfigPath = false;
4118
+ if (context.tsconfig.options.paths) {
4119
+ for (const tsconfigPathKey of Object.keys(context.tsconfig.options.paths).filter((tsconfigPath2) => args.id.startsWith(tsconfigPath2.replaceAll("*", "")))) {
4120
+ const resolvedPath = context.tsconfig.options.paths[tsconfigPathKey]?.find((tsconfigPath2) => context.fs.resolve(join.joinPaths(context.workspaceConfig.workspaceRoot, tsconfigPath2.replaceAll("*", ""), args.id.replace(tsconfigPathKey.replaceAll("*", ""), ""))) || context.fs.formatPath(tsconfigPath2) === context.fs.formatPath(args.id));
4121
+ if (resolvedPath) {
4122
+ tsconfigPath = context.fs.formatPath(resolvedPath) === context.fs.formatPath(args.id) ? context.fs.formatPath(resolvedPath) : context.fs.resolve(join.joinPaths(context.workspaceConfig.workspaceRoot, resolvedPath.replaceAll("*", ""), args.id.replace(tsconfigPathKey.replaceAll("*", ""), "")));
4123
+ }
4124
+ }
4125
+ }
4126
+ let tsconfigPathPackage = false;
4127
+ if (context.tsconfig.options.paths) {
4128
+ const tsconfigPathKeys = Object.keys(context.tsconfig.options.paths).filter((tsconfigPath2) => args.id.startsWith(tsconfigPath2.replaceAll("*", "")));
4129
+ if (tsconfigPathKeys.length > 0 && tsconfigPathKeys[0]) {
4130
+ tsconfigPathPackage = tsconfigPathKeys[0].replace(/\/\*$/, "");
4131
+ }
4132
+ }
3736
4133
  if (tsconfigPath && tsconfigPathPackage) {
3737
4134
  return {
3738
4135
  id: tsconfigPath,
@@ -3765,7 +4162,7 @@ async function handleResolveId(context, args, options = {}) {
3765
4162
  args.importer
3766
4163
  ] : []
3767
4164
  });
3768
- if (bundleRequire.match(args.id, options.noExternal) || resolvedPath && context.fs.meta[resolvedPath]?.variant === "builtin") {
4165
+ if (bundleRequire.match(args.id, options.noExternal) || resolvedPath && context.fs.metadata[resolvedPath]?.variant === "builtin") {
3769
4166
  return void 0;
3770
4167
  }
3771
4168
  if (bundleRequire.match(args.id, options.external) || args.id.startsWith("node:")) {
@@ -3914,7 +4311,12 @@ var vite = unplugin.createVitePlugin(createUnpluginFactory("vite", (api, plugin)
3914
4311
  api.context.config.mode = environmentChecks.isDevelopmentMode(env.mode) ? "development" : environmentChecks.isTestMode(env.mode) ? "test" : "production";
3915
4312
  const environment = await api.context.getEnvironment();
3916
4313
  const result = await api.callHook(environment, "config");
3917
- return defu3__default.default(extractViteConfig(api.context), result?.build ?? {}, config);
4314
+ return defu2__default.default(
4315
+ extractViteConfig(api.context),
4316
+ // Need to use `any` here to avoid excessive type complexity
4317
+ result?.build ?? {},
4318
+ config
4319
+ );
3918
4320
  },
3919
4321
  async configResolved(_config) {
3920
4322
  const environment = await api.context.getEnvironment();
@@ -3977,228 +4379,6 @@ unplugin.createRolldownPlugin(createUnpluginFactory("rolldown"));
3977
4379
  unplugin.createRollupPlugin(createUnpluginFactory("rollup"));
3978
4380
  unplugin.createRspackPlugin(createUnpluginFactory("rspack"));
3979
4381
  unplugin.createUnloaderPlugin(createUnpluginFactory("unloader"));
3980
- BigInt("0xa56c61324b9d6e49");
3981
- var FileMetadata_KeyValuePair = class extends $__namespace.Struct {
3982
- static {
3983
- chunkSHUYVCID_js.__name(this, "FileMetadata_KeyValuePair");
3984
- }
3985
- static _capnp = {
3986
- displayName: "KeyValuePair",
3987
- id: "eabb26cf58b2a14c",
3988
- size: new $__namespace.ObjectSize(0, 2)
3989
- };
3990
- get key() {
3991
- return $__namespace.utils.getText(0, this);
3992
- }
3993
- set key(value) {
3994
- $__namespace.utils.setText(0, value, this);
3995
- }
3996
- get value() {
3997
- return $__namespace.utils.getText(1, this);
3998
- }
3999
- set value(value) {
4000
- $__namespace.utils.setText(1, value, this);
4001
- }
4002
- toString() {
4003
- return "FileMetadata_KeyValuePair_" + super.toString();
4004
- }
4005
- };
4006
- var FileMetadata = class _FileMetadata extends $__namespace.Struct {
4007
- static {
4008
- chunkSHUYVCID_js.__name(this, "FileMetadata");
4009
- }
4010
- static KeyValuePair = FileMetadata_KeyValuePair;
4011
- static _capnp = {
4012
- displayName: "FileMetadata",
4013
- id: "8e2cab5d7e28c7b3",
4014
- size: new $__namespace.ObjectSize(0, 4),
4015
- defaultVariant: "normal"
4016
- };
4017
- static _Properties;
4018
- /**
4019
- * The variant of the file.
4020
- *
4021
- */
4022
- get id() {
4023
- return $__namespace.utils.getText(0, this);
4024
- }
4025
- set id(value) {
4026
- $__namespace.utils.setText(0, value, this);
4027
- }
4028
- /**
4029
- * The output mode of the file.
4030
- *
4031
- */
4032
- get variant() {
4033
- return $__namespace.utils.getText(1, this, _FileMetadata._capnp.defaultVariant);
4034
- }
4035
- set variant(value) {
4036
- $__namespace.utils.setText(1, value, this);
4037
- }
4038
- /**
4039
- * Additional metadata associated with the file.
4040
- *
4041
- */
4042
- get mode() {
4043
- return $__namespace.utils.getText(2, this);
4044
- }
4045
- set mode(value) {
4046
- $__namespace.utils.setText(2, value, this);
4047
- }
4048
- _adoptProperties(value) {
4049
- $__namespace.utils.adopt(value, $__namespace.utils.getPointer(3, this));
4050
- }
4051
- _disownProperties() {
4052
- return $__namespace.utils.disown(this.properties);
4053
- }
4054
- get properties() {
4055
- return $__namespace.utils.getList(3, _FileMetadata._Properties, this);
4056
- }
4057
- _hasProperties() {
4058
- return !$__namespace.utils.isNull($__namespace.utils.getPointer(3, this));
4059
- }
4060
- _initProperties(length) {
4061
- return $__namespace.utils.initList(3, _FileMetadata._Properties, length, this);
4062
- }
4063
- set properties(value) {
4064
- $__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(3, this));
4065
- }
4066
- toString() {
4067
- return "FileMetadata_" + super.toString();
4068
- }
4069
- };
4070
- var FileIdentifier = class extends $__namespace.Struct {
4071
- static {
4072
- chunkSHUYVCID_js.__name(this, "FileIdentifier");
4073
- }
4074
- static _capnp = {
4075
- displayName: "FileIdentifier",
4076
- id: "e12b8732389d7406",
4077
- size: new $__namespace.ObjectSize(0, 2)
4078
- };
4079
- /**
4080
- * An additional identifier for the file.
4081
- *
4082
- */
4083
- get path() {
4084
- return $__namespace.utils.getText(0, this);
4085
- }
4086
- set path(value) {
4087
- $__namespace.utils.setText(0, value, this);
4088
- }
4089
- get id() {
4090
- return $__namespace.utils.getText(1, this);
4091
- }
4092
- set id(value) {
4093
- $__namespace.utils.setText(1, value, this);
4094
- }
4095
- toString() {
4096
- return "FileIdentifier_" + super.toString();
4097
- }
4098
- };
4099
- var FileData = class extends $__namespace.Struct {
4100
- static {
4101
- chunkSHUYVCID_js.__name(this, "FileData");
4102
- }
4103
- static _capnp = {
4104
- displayName: "FileData",
4105
- id: "fa6725c8a360f9a2",
4106
- size: new $__namespace.ObjectSize(0, 2)
4107
- };
4108
- /**
4109
- * The contents of the file.
4110
- *
4111
- */
4112
- get path() {
4113
- return $__namespace.utils.getText(0, this);
4114
- }
4115
- set path(value) {
4116
- $__namespace.utils.setText(0, value, this);
4117
- }
4118
- get content() {
4119
- return $__namespace.utils.getText(1, this);
4120
- }
4121
- set content(value) {
4122
- $__namespace.utils.setText(1, value, this);
4123
- }
4124
- toString() {
4125
- return "FileData_" + super.toString();
4126
- }
4127
- };
4128
- var FileSystemData = class _FileSystemData extends $__namespace.Struct {
4129
- static {
4130
- chunkSHUYVCID_js.__name(this, "FileSystemData");
4131
- }
4132
- static _capnp = {
4133
- displayName: "FileSystemData",
4134
- id: "aaa72a672ac0732f",
4135
- size: new $__namespace.ObjectSize(0, 3)
4136
- };
4137
- static _Ids;
4138
- static _Metadata;
4139
- static _Files;
4140
- _adoptIds(value) {
4141
- $__namespace.utils.adopt(value, $__namespace.utils.getPointer(0, this));
4142
- }
4143
- _disownIds() {
4144
- return $__namespace.utils.disown(this.ids);
4145
- }
4146
- get ids() {
4147
- return $__namespace.utils.getList(0, _FileSystemData._Ids, this);
4148
- }
4149
- _hasIds() {
4150
- return !$__namespace.utils.isNull($__namespace.utils.getPointer(0, this));
4151
- }
4152
- _initIds(length) {
4153
- return $__namespace.utils.initList(0, _FileSystemData._Ids, length, this);
4154
- }
4155
- set ids(value) {
4156
- $__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(0, this));
4157
- }
4158
- _adoptMetadata(value) {
4159
- $__namespace.utils.adopt(value, $__namespace.utils.getPointer(1, this));
4160
- }
4161
- _disownMetadata() {
4162
- return $__namespace.utils.disown(this.metadata);
4163
- }
4164
- get metadata() {
4165
- return $__namespace.utils.getList(1, _FileSystemData._Metadata, this);
4166
- }
4167
- _hasMetadata() {
4168
- return !$__namespace.utils.isNull($__namespace.utils.getPointer(1, this));
4169
- }
4170
- _initMetadata(length) {
4171
- return $__namespace.utils.initList(1, _FileSystemData._Metadata, length, this);
4172
- }
4173
- set metadata(value) {
4174
- $__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(1, this));
4175
- }
4176
- _adoptFiles(value) {
4177
- $__namespace.utils.adopt(value, $__namespace.utils.getPointer(2, this));
4178
- }
4179
- _disownFiles() {
4180
- return $__namespace.utils.disown(this.files);
4181
- }
4182
- get files() {
4183
- return $__namespace.utils.getList(2, _FileSystemData._Files, this);
4184
- }
4185
- _hasFiles() {
4186
- return !$__namespace.utils.isNull($__namespace.utils.getPointer(2, this));
4187
- }
4188
- _initFiles(length) {
4189
- return $__namespace.utils.initList(2, _FileSystemData._Files, length, this);
4190
- }
4191
- set files(value) {
4192
- $__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(2, this));
4193
- }
4194
- toString() {
4195
- return "FileSystemData_" + super.toString();
4196
- }
4197
- };
4198
- FileMetadata._Properties = $__namespace.CompositeList(FileMetadata_KeyValuePair);
4199
- FileSystemData._Ids = $__namespace.CompositeList(FileIdentifier);
4200
- FileSystemData._Metadata = $__namespace.CompositeList(FileMetadata);
4201
- FileSystemData._Files = $__namespace.CompositeList(FileData);
4202
4382
 
4203
4383
  // ../powerlines/src/index.ts
4204
4384
  var src_default = PowerlinesAPI;
@@ -4213,7 +4393,7 @@ function withExecutor(command, executorFn) {
4213
4393
  throw new Error("The executor requires `projectsConfigurations` on the context object.");
4214
4394
  }
4215
4395
  const projectConfig = context.projectsConfigurations.projects[context.projectName];
4216
- const api = await src_default.from(workspaceConfig.workspaceRoot, defu3__default.default({
4396
+ const api = await src_default.from(workspaceConfig.workspaceRoot, defu2__default.default({
4217
4397
  root: projectConfig.root,
4218
4398
  type: projectConfig.projectType,
4219
4399
  sourceRoot: projectConfig.sourceRoot,
@@ -4226,7 +4406,7 @@ function withExecutor(command, executorFn) {
4226
4406
  }
4227
4407
  }, options));
4228
4408
  try {
4229
- return await Promise.resolve(executorFn(defu3__default.default({
4409
+ return await Promise.resolve(executorFn(defu2__default.default({
4230
4410
  projectName: context.projectName,
4231
4411
  options,
4232
4412
  workspaceConfig,