@powerlines/nx 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/{chunk-HHPODCTP.js → chunk-4UWZOCEA.js} +6 -4
- package/dist/{chunk-5KPKXHZH.mjs → chunk-A6R3IFS4.mjs} +1 -1
- package/dist/{chunk-HSNIRMVR.mjs → chunk-AEUGK5NW.mjs} +1 -1
- package/dist/{chunk-3UUTQUUX.js → chunk-DYBB74M5.js} +2 -2
- package/dist/{chunk-22QO45EK.mjs → chunk-FFBOHADM.mjs} +1 -1
- package/dist/{chunk-XPHWTP5U.js → chunk-GBMB632G.js} +2 -2
- package/dist/{chunk-3LHPBDCN.js → chunk-HGVVLZRZ.js} +2 -2
- package/dist/{chunk-Z4BJ37JY.js → chunk-IFMXBBI7.js} +3 -3
- package/dist/{chunk-XIGAXYDP.mjs → chunk-KXYDHGLW.mjs} +1 -1
- package/dist/{chunk-IU4QT7J4.mjs → chunk-KZPEAPED.mjs} +553 -531
- package/dist/{chunk-KOM7ARUV.js → chunk-MUKKEYV2.js} +2 -2
- package/dist/{chunk-Z2JOX3QC.mjs → chunk-R5YABITA.mjs} +1 -1
- package/dist/{chunk-CYWOTYVX.mjs → chunk-SV7QXBCB.mjs} +6 -4
- package/dist/{chunk-CTSSOUL6.mjs → chunk-VGG6K4L5.mjs} +1 -1
- package/dist/{chunk-CZATM4D6.js → chunk-XTPTXR6Y.js} +571 -549
- package/dist/{chunk-KNKBKT4T.js → chunk-ZJSHMHBZ.js} +2 -2
- package/dist/executors.js +14 -14
- package/dist/executors.mjs +7 -7
- package/dist/index.js +17 -17
- package/dist/index.mjs +8 -8
- package/dist/src/base/base-executor.js +3 -3
- package/dist/src/base/base-executor.mjs +2 -2
- package/dist/src/executors/build/executor.js +5 -5
- package/dist/src/executors/build/executor.mjs +3 -3
- package/dist/src/executors/clean/executor.js +5 -5
- package/dist/src/executors/clean/executor.mjs +3 -3
- package/dist/src/executors/docs/executor.js +5 -5
- package/dist/src/executors/docs/executor.mjs +3 -3
- package/dist/src/executors/lint/executor.js +5 -5
- package/dist/src/executors/lint/executor.mjs +3 -3
- package/dist/src/executors/prepare/executor.js +5 -5
- package/dist/src/executors/prepare/executor.mjs +3 -3
- package/dist/src/plugin/index.js +4 -4
- package/dist/src/plugin/index.mjs +2 -2
- package/package.json +3 -3
- package/dist/src/executors/build/schema.d.ts +0 -85
- package/dist/src/executors/build/schema.json +0 -96
- package/dist/src/executors/clean/schema.d.ts +0 -75
- package/dist/src/executors/clean/schema.json +0 -77
- package/dist/src/executors/docs/schema.d.ts +0 -75
- package/dist/src/executors/docs/schema.json +0 -77
- package/dist/src/executors/lint/schema.d.ts +0 -75
- package/dist/src/executors/lint/schema.json +0 -77
- package/dist/src/executors/prepare/schema.d.ts +0 -75
- package/dist/src/executors/prepare/schema.json +0 -77
- package/dist/src/generators/sync/schema.d.ts +0 -15
- package/dist/src/generators/sync/schema.json +0 -19
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk4UWZOCEA_js = require('./chunk-4UWZOCEA.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');
|
|
@@ -15,8 +15,6 @@ var helpers = require('@stryke/fs/helpers');
|
|
|
15
15
|
var install = require('@stryke/fs/install');
|
|
16
16
|
var listFiles = require('@stryke/fs/list-files');
|
|
17
17
|
var packageFns = require('@stryke/fs/package-fns');
|
|
18
|
-
var filePathFns = require('@stryke/path/file-path-fns');
|
|
19
|
-
var isParentPath = require('@stryke/path/is-parent-path');
|
|
20
18
|
var joinPaths = require('@stryke/path/join-paths');
|
|
21
19
|
var replace = require('@stryke/path/replace');
|
|
22
20
|
var isFunction = require('@stryke/type-checks/is-function');
|
|
@@ -30,16 +28,18 @@ var Handlebars = require('handlebars');
|
|
|
30
28
|
var json = require('@stryke/fs/json');
|
|
31
29
|
var append = require('@stryke/path/append');
|
|
32
30
|
var ts2 = require('typescript');
|
|
33
|
-
var titleCase = require('@stryke/string-format/title-case');
|
|
34
31
|
var isUndefined = require('@stryke/type-checks/is-undefined');
|
|
35
32
|
var writeFile$1 = require('@stryke/fs/write-file');
|
|
36
33
|
var prettier = require('prettier');
|
|
37
34
|
var resolve = require('@stryke/fs/resolve');
|
|
35
|
+
var titleCase = require('@stryke/string-format/title-case');
|
|
38
36
|
var getEnvPaths = require('@stryke/env/get-env-paths');
|
|
39
37
|
var getWorkspaceRoot = require('@stryke/fs/get-workspace-root');
|
|
40
38
|
var murmurhash = require('@stryke/hash/murmurhash');
|
|
41
39
|
var getUnique = require('@stryke/helpers/get-unique');
|
|
42
40
|
var omit = require('@stryke/helpers/omit');
|
|
41
|
+
var filePathFns = require('@stryke/path/file-path-fns');
|
|
42
|
+
var isType = require('@stryke/path/is-type');
|
|
43
43
|
var join = require('@stryke/path/join');
|
|
44
44
|
var isNull = require('@stryke/type-checks/is-null');
|
|
45
45
|
var isString = require('@stryke/type-checks/is-string');
|
|
@@ -50,7 +50,7 @@ var colors = require('@storm-software/config-tools/utilities/colors');
|
|
|
50
50
|
var noop = require('@stryke/helpers/noop');
|
|
51
51
|
var jiti = require('jiti');
|
|
52
52
|
var bufferToString = require('@stryke/convert/buffer-to-string');
|
|
53
|
-
var
|
|
53
|
+
var isParentPath = require('@stryke/path/is-parent-path');
|
|
54
54
|
var prettyBytes = require('@stryke/string-format/pretty-bytes');
|
|
55
55
|
var isBuffer = require('@stryke/type-checks/is-buffer');
|
|
56
56
|
var memfs = require('memfs');
|
|
@@ -183,26 +183,6 @@ ${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && err
|
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
185
|
chunkSHUYVCID_js.__name(getParsedTypeScriptConfig, "getParsedTypeScriptConfig");
|
|
186
|
-
function getBaseFileHeader(context) {
|
|
187
|
-
return `
|
|
188
|
-
// Generated with ${titleCase.titleCase(context.config.framework)}
|
|
189
|
-
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
190
|
-
`;
|
|
191
|
-
}
|
|
192
|
-
chunkSHUYVCID_js.__name(getBaseFileHeader, "getBaseFileHeader");
|
|
193
|
-
function getFileHeader(context, options = {}) {
|
|
194
|
-
const { directive = null, prettierIgnore = false } = options;
|
|
195
|
-
return `/* eslint-disable */
|
|
196
|
-
// biome-ignore lint: disable
|
|
197
|
-
${prettierIgnore ? `// prettier-ignore` : ""}${directive ? `
|
|
198
|
-
|
|
199
|
-
${directive}
|
|
200
|
-
` : "\n"}
|
|
201
|
-
${getBaseFileHeader(context)}
|
|
202
|
-
|
|
203
|
-
`;
|
|
204
|
-
}
|
|
205
|
-
chunkSHUYVCID_js.__name(getFileHeader, "getFileHeader");
|
|
206
186
|
|
|
207
187
|
// ../powerlines/src/types/commands.ts
|
|
208
188
|
var SUPPORTED_COMMANDS = [
|
|
@@ -432,6 +412,154 @@ function createResolver(options) {
|
|
|
432
412
|
return baseResolver;
|
|
433
413
|
}
|
|
434
414
|
chunkSHUYVCID_js.__name(createResolver, "createResolver");
|
|
415
|
+
function isBufferEncoding(options) {
|
|
416
|
+
return isSetString.isSetString(options) || options === null;
|
|
417
|
+
}
|
|
418
|
+
chunkSHUYVCID_js.__name(isBufferEncoding, "isBufferEncoding");
|
|
419
|
+
function isPowerlinesWriteFileOptions(options) {
|
|
420
|
+
return !isBufferEncoding(options) && isSetObject.isSetObject(options) && ("skipFormat" in options || "mode" in options && (options.mode === "fs" || options.mode === "virtual"));
|
|
421
|
+
}
|
|
422
|
+
chunkSHUYVCID_js.__name(isPowerlinesWriteFileOptions, "isPowerlinesWriteFileOptions");
|
|
423
|
+
function isNodeWriteFileOptions(options) {
|
|
424
|
+
return !isUndefined.isUndefined(options) && (isBufferEncoding(options) || !isPowerlinesWriteFileOptions(options));
|
|
425
|
+
}
|
|
426
|
+
chunkSHUYVCID_js.__name(isNodeWriteFileOptions, "isNodeWriteFileOptions");
|
|
427
|
+
function isPowerLinesWriteFileData(data) {
|
|
428
|
+
return !!(isSetObject.isSetObject(data) && "code" in data && data.code);
|
|
429
|
+
}
|
|
430
|
+
chunkSHUYVCID_js.__name(isPowerLinesWriteFileData, "isPowerLinesWriteFileData");
|
|
431
|
+
var FILE_PREFIX = "file://";
|
|
432
|
+
function toFilePath(pathOrUrl) {
|
|
433
|
+
if (!pathOrUrl) {
|
|
434
|
+
throw new Error("No Path or URL provided to Virtual File System");
|
|
435
|
+
}
|
|
436
|
+
let result = pathOrUrl.toString();
|
|
437
|
+
if (result.startsWith(FILE_PREFIX)) {
|
|
438
|
+
result = result.slice(FILE_PREFIX.length);
|
|
439
|
+
}
|
|
440
|
+
return result;
|
|
441
|
+
}
|
|
442
|
+
chunkSHUYVCID_js.__name(toFilePath, "toFilePath");
|
|
443
|
+
var FS_METHODS = [
|
|
444
|
+
"mkdir",
|
|
445
|
+
"mkdirSync",
|
|
446
|
+
"rmdir",
|
|
447
|
+
"rmdirSync",
|
|
448
|
+
"unlink",
|
|
449
|
+
"unlinkSync",
|
|
450
|
+
"existsSync",
|
|
451
|
+
"realpathSync",
|
|
452
|
+
"writeFileSync",
|
|
453
|
+
"readFileSync",
|
|
454
|
+
"readdirSync",
|
|
455
|
+
"createWriteStream",
|
|
456
|
+
"WriteStream",
|
|
457
|
+
"createReadStream",
|
|
458
|
+
"ReadStream"
|
|
459
|
+
];
|
|
460
|
+
var FS_PROMISE_METHODS = [
|
|
461
|
+
"mkdir",
|
|
462
|
+
"rm",
|
|
463
|
+
"rmdir",
|
|
464
|
+
"unlink",
|
|
465
|
+
"writeFile",
|
|
466
|
+
"readFile",
|
|
467
|
+
"readdir",
|
|
468
|
+
"stat",
|
|
469
|
+
"lstat"
|
|
470
|
+
];
|
|
471
|
+
function cloneFS(originalFS) {
|
|
472
|
+
const clonedFS = {
|
|
473
|
+
...originalFS,
|
|
474
|
+
promises: {
|
|
475
|
+
...originalFS.promises ?? {}
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
for (const method of FS_METHODS) {
|
|
479
|
+
if (originalFS[method]) {
|
|
480
|
+
clonedFS[method] = originalFS[method];
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
originalFS.promises ??= {};
|
|
484
|
+
for (const method of FS_PROMISE_METHODS) {
|
|
485
|
+
if (originalFS.promises[method]) {
|
|
486
|
+
clonedFS.promises ??= {};
|
|
487
|
+
clonedFS.promises[method] = originalFS.promises[method];
|
|
488
|
+
clonedFS[method] = originalFS.promises[method];
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
for (const prop in clonedFS) {
|
|
492
|
+
if (isFunction.isFunction(clonedFS[prop])) {
|
|
493
|
+
clonedFS[prop] = clonedFS[prop].bind(originalFS);
|
|
494
|
+
if (isFunction.isFunction(clonedFS.promises[prop])) {
|
|
495
|
+
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
for (const prop in clonedFS.promises) {
|
|
500
|
+
if (isFunction.isFunction(clonedFS.promises[prop])) {
|
|
501
|
+
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return clonedFS;
|
|
505
|
+
}
|
|
506
|
+
chunkSHUYVCID_js.__name(cloneFS, "cloneFS");
|
|
507
|
+
function patchFS(originalFS, vfs) {
|
|
508
|
+
const clonedFS = cloneFS(originalFS);
|
|
509
|
+
originalFS.mkdirSync = (file, options) => vfs.mkdirSync(toFilePath(file), options);
|
|
510
|
+
originalFS.mkdir = (file, options, callback) => vfs.mkdir(toFilePath(file), options, callback);
|
|
511
|
+
originalFS.promises.mkdir = async (file, options) => vfs.mkdir(toFilePath(file), options);
|
|
512
|
+
originalFS.unlinkSync = (file) => vfs.unlinkSync(toFilePath(file));
|
|
513
|
+
originalFS.promises.rm = async (file, options) => vfs.rm(toFilePath(file), options);
|
|
514
|
+
originalFS.promises.unlink = async (file) => vfs.unlink(toFilePath(file));
|
|
515
|
+
originalFS.existsSync = (file) => vfs.existsSync(toFilePath(file));
|
|
516
|
+
Object.defineProperty(originalFS, "realpathSync", {
|
|
517
|
+
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.realpathSync(toFilePath(file), options), "value")
|
|
518
|
+
});
|
|
519
|
+
originalFS.writeFileSync = (file, data, options) => vfs.writeFileSync(toFilePath(file), data, options);
|
|
520
|
+
originalFS.promises.writeFile = async (file, data, options) => vfs.writeFile(toFilePath(file), data, options);
|
|
521
|
+
originalFS.readFileSync = (file, options) => vfs.readFileSync(toFilePath(file), options);
|
|
522
|
+
originalFS.promises.readFile = (file, options) => vfs.readFile(toFilePath(file), options);
|
|
523
|
+
originalFS.readdirSync = (file, options) => vfs.readdirSync(toFilePath(file), options);
|
|
524
|
+
originalFS.promises.readdir = (file, options) => vfs.readdir(toFilePath(file), options);
|
|
525
|
+
Object.defineProperty(originalFS, "statSync", {
|
|
526
|
+
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.statSync(toFilePath(file), options), "value")
|
|
527
|
+
});
|
|
528
|
+
originalFS.stat = (file, options) => vfs.statSync(toFilePath(file), options);
|
|
529
|
+
originalFS.promises.stat = (file, options) => vfs.stat(toFilePath(file), options);
|
|
530
|
+
Object.defineProperty(originalFS, "lstatSync", {
|
|
531
|
+
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.lstatSync(toFilePath(file), options), "value")
|
|
532
|
+
});
|
|
533
|
+
originalFS.lstat = (file, options) => vfs.lstatSync(toFilePath(file), options);
|
|
534
|
+
originalFS.promises.lstat = (file, options) => vfs.lstat(toFilePath(file), options);
|
|
535
|
+
return () => {
|
|
536
|
+
originalFS.mkdirSync = clonedFS.mkdirSync;
|
|
537
|
+
originalFS.mkdir = clonedFS.mkdir;
|
|
538
|
+
originalFS.promises.mkdir = clonedFS.promises.mkdir;
|
|
539
|
+
originalFS.unlinkSync = clonedFS.unlinkSync;
|
|
540
|
+
originalFS.promises.rm = clonedFS.promises.rm;
|
|
541
|
+
originalFS.promises.unlink = clonedFS.promises.unlink;
|
|
542
|
+
originalFS.existsSync = clonedFS.existsSync;
|
|
543
|
+
originalFS.realpathSync = clonedFS.realpathSync;
|
|
544
|
+
originalFS.writeFileSync = clonedFS.writeFileSync;
|
|
545
|
+
originalFS.promises.writeFile = clonedFS.promises.writeFile;
|
|
546
|
+
originalFS.readFileSync = clonedFS.readFileSync;
|
|
547
|
+
originalFS.promises.readFile = clonedFS.promises.readFile;
|
|
548
|
+
originalFS.readdirSync = clonedFS.readdirSync;
|
|
549
|
+
originalFS.promises.readdir = clonedFS.promises.readdir;
|
|
550
|
+
Object.defineProperty(originalFS, "statSync", {
|
|
551
|
+
value: clonedFS.statSync
|
|
552
|
+
});
|
|
553
|
+
originalFS.stat = clonedFS.stat;
|
|
554
|
+
originalFS.promises.stat = clonedFS.promises.stat;
|
|
555
|
+
Object.defineProperty(originalFS, "lstatSync", {
|
|
556
|
+
value: clonedFS.lstatSync
|
|
557
|
+
});
|
|
558
|
+
originalFS.lstat = clonedFS.lstat;
|
|
559
|
+
originalFS.promises.lstat = clonedFS.promises.lstat;
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
chunkSHUYVCID_js.__name(patchFS, "patchFS");
|
|
435
563
|
var VirtualFileSystem = class {
|
|
436
564
|
static {
|
|
437
565
|
chunkSHUYVCID_js.__name(this, "VirtualFileSystem");
|
|
@@ -439,7 +567,11 @@ var VirtualFileSystem = class {
|
|
|
439
567
|
/**
|
|
440
568
|
* The internal map of virtual files.
|
|
441
569
|
*/
|
|
442
|
-
#
|
|
570
|
+
#meta = {};
|
|
571
|
+
/**
|
|
572
|
+
* A map of unique identifiers to their virtual file paths.
|
|
573
|
+
*/
|
|
574
|
+
#ids = {};
|
|
443
575
|
/**
|
|
444
576
|
* A map of virtual file paths to their underlying file content.
|
|
445
577
|
*/
|
|
@@ -480,39 +612,88 @@ var VirtualFileSystem = class {
|
|
|
480
612
|
*/
|
|
481
613
|
#log;
|
|
482
614
|
/**
|
|
615
|
+
* Checks if a path exists in the virtual file system (VFS).
|
|
616
|
+
*
|
|
617
|
+
* @param path - The path to check.
|
|
618
|
+
* @returns `true` if the path exists, otherwise `false`.
|
|
619
|
+
*/
|
|
620
|
+
#existsSync(path) {
|
|
621
|
+
const formattedPath = this.formatPath(path);
|
|
622
|
+
return this.#virtualFS.existsSync(formattedPath) || this.#fs.existsSync(formattedPath) || this.resolveFS(path).existsSync(formattedPath);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
483
625
|
* Exposes the internal VFS map for advanced usage.
|
|
484
626
|
*/
|
|
485
|
-
get [
|
|
627
|
+
get [chunk4UWZOCEA_js.__VFS_CACHE__]() {
|
|
486
628
|
return this.#cachedFS;
|
|
487
629
|
}
|
|
488
630
|
/**
|
|
489
631
|
* Exposes the internal VFS resolver cache for advanced usage.
|
|
490
632
|
*/
|
|
491
|
-
get [
|
|
633
|
+
get [chunk4UWZOCEA_js.__VFS_RESOLVER__]() {
|
|
492
634
|
return this.#cachedResolver;
|
|
493
635
|
}
|
|
494
636
|
/**
|
|
495
637
|
* Exposes the internal VFS map for advanced usage.
|
|
496
638
|
*/
|
|
497
|
-
get [
|
|
639
|
+
get [chunk4UWZOCEA_js.__VFS_VIRTUAL__]() {
|
|
498
640
|
return this.#virtualFS;
|
|
499
641
|
}
|
|
500
642
|
/**
|
|
501
643
|
* Exposes the internal UFS map for advanced usage.
|
|
502
644
|
*/
|
|
503
|
-
get [
|
|
645
|
+
get [chunk4UWZOCEA_js.__VFS_UNIFIED__]() {
|
|
504
646
|
return this.#unifiedFS;
|
|
505
647
|
}
|
|
506
648
|
/**
|
|
649
|
+
* A proxy to access the underlying file metadata.
|
|
650
|
+
*/
|
|
651
|
+
get meta() {
|
|
652
|
+
return new Proxy(this.#meta, {
|
|
653
|
+
get: /* @__PURE__ */ chunkSHUYVCID_js.__name((target, prop) => {
|
|
654
|
+
if (target[prop]) {
|
|
655
|
+
return {
|
|
656
|
+
id: prop,
|
|
657
|
+
mode: this.#virtualFS.existsSync(prop) ? "virtual" : this.#fs.existsSync(prop) ? "fs" : this.#context.config.output.mode,
|
|
658
|
+
details: {},
|
|
659
|
+
variant: "normal",
|
|
660
|
+
...target[prop]
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
return void 0;
|
|
664
|
+
}, "get"),
|
|
665
|
+
set: /* @__PURE__ */ chunkSHUYVCID_js.__name((target, prop, value) => {
|
|
666
|
+
target[prop] = value;
|
|
667
|
+
this.#ids[value.id || prop] = prop;
|
|
668
|
+
return true;
|
|
669
|
+
}, "set"),
|
|
670
|
+
deleteProperty: /* @__PURE__ */ chunkSHUYVCID_js.__name((target, prop) => {
|
|
671
|
+
delete this.#ids[target[prop]?.id || prop];
|
|
672
|
+
delete target[prop];
|
|
673
|
+
return true;
|
|
674
|
+
}, "deleteProperty")
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* A map of module ids to their file paths.
|
|
679
|
+
*/
|
|
680
|
+
get ids() {
|
|
681
|
+
return this.#ids;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
507
684
|
* Creates a new instance of the VirtualFileSystem.
|
|
508
685
|
*
|
|
509
686
|
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
510
687
|
* @param serialized - A map of files/file contents to populate in cache
|
|
511
688
|
*/
|
|
512
|
-
constructor(context, serialized) {
|
|
689
|
+
constructor(context, serialized = {}) {
|
|
513
690
|
this.#context = context;
|
|
514
691
|
this.#cachedFS = /* @__PURE__ */ new Map();
|
|
515
|
-
this.#
|
|
692
|
+
this.#meta = Object.fromEntries(Object.entries(serialized.virtualFilesMeta ?? {}));
|
|
693
|
+
this.#ids = Object.fromEntries(Object.entries(this.#meta).map(([path, data]) => [
|
|
694
|
+
data.id || path,
|
|
695
|
+
path
|
|
696
|
+
]));
|
|
516
697
|
if (!this.#fs.existsSync(this.#context.dataPath)) {
|
|
517
698
|
this.#fs.mkdirSync(this.#context.dataPath, {
|
|
518
699
|
recursive: true
|
|
@@ -578,13 +759,13 @@ var VirtualFileSystem = class {
|
|
|
578
759
|
}
|
|
579
760
|
this.#log = extendLog(this.#context.log, "virtual-file-system");
|
|
580
761
|
}
|
|
581
|
-
[
|
|
762
|
+
[chunk4UWZOCEA_js.__VFS_INIT__]() {
|
|
582
763
|
if (!this.#isPatched && this.#context.config.output.mode !== "fs") {
|
|
583
764
|
this.#revert = patchFS(fs__default.default, this);
|
|
584
765
|
this.#isPatched = true;
|
|
585
766
|
}
|
|
586
767
|
}
|
|
587
|
-
[
|
|
768
|
+
[chunk4UWZOCEA_js.__VFS_REVERT__]() {
|
|
588
769
|
if (this.#isPatched && this.#context.config.output.mode !== "fs") {
|
|
589
770
|
if (!this.#revert) {
|
|
590
771
|
throw new Error("Attempting to revert File System patch prior to calling `__init__` function");
|
|
@@ -594,65 +775,44 @@ var VirtualFileSystem = class {
|
|
|
594
775
|
}
|
|
595
776
|
}
|
|
596
777
|
/**
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
* @returns A Map where the keys are runtime file IDs (strings) and the values are their corresponding paths (strings).
|
|
600
|
-
*/
|
|
601
|
-
get builtinIdMap() {
|
|
602
|
-
return this.#builtinIdMap;
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* Lists all runtime IDs in the virtual file system.
|
|
606
|
-
*
|
|
607
|
-
* @returns An array of formatted runtime IDs.
|
|
608
|
-
*/
|
|
609
|
-
get runtimeIds() {
|
|
610
|
-
return Array.from(this.builtinIdMap.keys()).map((id) => this.formatRuntimeId(id));
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Checks if a given path or ID corresponds to a runtime file.
|
|
778
|
+
* Check if a path or id corresponds to a virtual file **(does not actually exists on disk)**.
|
|
614
779
|
*
|
|
615
|
-
* @param pathOrId - The path or
|
|
616
|
-
* @param options -
|
|
617
|
-
* @returns
|
|
780
|
+
* @param pathOrId - The path or id to check.
|
|
781
|
+
* @param options - Optional parameters for resolving the path.
|
|
782
|
+
* @returns Whether the path or id corresponds to a virtual file **(does not actually exists on disk)**.
|
|
618
783
|
*/
|
|
619
|
-
|
|
620
|
-
|
|
784
|
+
isVirtual(pathOrId, options = {}) {
|
|
785
|
+
if (!pathOrId) {
|
|
786
|
+
return false;
|
|
787
|
+
}
|
|
788
|
+
const resolvedPath = this.resolve(pathOrId, {
|
|
621
789
|
...options,
|
|
622
790
|
type: "file"
|
|
623
|
-
})
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
* @param id - The ID to check.
|
|
629
|
-
* @returns Whether the ID is a valid runtime ID.
|
|
630
|
-
*/
|
|
631
|
-
isValidBuiltinId(id) {
|
|
632
|
-
return id.startsWith(`${this.#context.config.output.builtinPrefix}:`);
|
|
791
|
+
});
|
|
792
|
+
if (!resolvedPath) {
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
return this.meta[resolvedPath]?.mode === "virtual";
|
|
633
796
|
}
|
|
634
797
|
/**
|
|
635
|
-
* Check if a path or
|
|
798
|
+
* Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
|
|
636
799
|
*
|
|
637
|
-
* @param pathOrId - The path or
|
|
638
|
-
* @param options -
|
|
639
|
-
* @returns Whether the path or
|
|
800
|
+
* @param pathOrId - The path or id to check.
|
|
801
|
+
* @param options - Optional parameters for resolving the path.
|
|
802
|
+
* @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
|
|
640
803
|
*/
|
|
641
|
-
|
|
804
|
+
isFs(pathOrId, options = {}) {
|
|
642
805
|
if (!pathOrId) {
|
|
643
806
|
return false;
|
|
644
807
|
}
|
|
645
|
-
const resolvedPath = this.
|
|
808
|
+
const resolvedPath = this.resolve(pathOrId, {
|
|
646
809
|
...options,
|
|
647
810
|
type: "file"
|
|
648
811
|
});
|
|
649
812
|
if (!resolvedPath) {
|
|
650
813
|
return false;
|
|
651
814
|
}
|
|
652
|
-
|
|
653
|
-
return true;
|
|
654
|
-
}
|
|
655
|
-
return this.#virtualFS.existsSync(resolvedPath);
|
|
815
|
+
return this.meta[resolvedPath]?.mode === "fs";
|
|
656
816
|
}
|
|
657
817
|
/**
|
|
658
818
|
* Check if a path exists within one of the directories specified in the tsconfig.json's `path` field.
|
|
@@ -666,37 +826,6 @@ var VirtualFileSystem = class {
|
|
|
666
826
|
return !!this.#context.tsconfig.options.paths && Object.keys(this.#context.tsconfig.options.paths).some((path) => pathOrId.startsWith(path.replaceAll("*", "")));
|
|
667
827
|
}
|
|
668
828
|
/**
|
|
669
|
-
* Checks if a given ID corresponds to a runtime file path.
|
|
670
|
-
*
|
|
671
|
-
* @param id - The unique identifier for the runtime file.
|
|
672
|
-
* @param pathOrId - The path or ID to check.
|
|
673
|
-
* @returns `true` if the ID corresponds to the path or ID of a runtime file, otherwise `false`.
|
|
674
|
-
*/
|
|
675
|
-
isMatchingBuiltinId(id, pathOrId) {
|
|
676
|
-
const resolvedPath = this.resolvePath(pathOrId);
|
|
677
|
-
const resolvedId = this.resolveId(pathOrId);
|
|
678
|
-
return !!(this.isBuiltinFile(pathOrId) && (resolvedPath && (resolvedPath === this.builtinIdMap.get(id) || resolvedPath === this.builtinIdMap.get(this.formatRuntimeId(id))) || resolvedId && (resolvedId === this.builtinIdMap.get(id) || resolvedId === this.builtinIdMap.get(this.formatRuntimeId(id)))));
|
|
679
|
-
}
|
|
680
|
-
/**
|
|
681
|
-
* Lists all runtime files in the virtual file system.
|
|
682
|
-
*
|
|
683
|
-
* @returns A promise that resolves to an array of runtime files.
|
|
684
|
-
*/
|
|
685
|
-
async listBuiltinFiles() {
|
|
686
|
-
const runtimeFiles = [];
|
|
687
|
-
for (const [id, path] of this.builtinIdMap.entries()) {
|
|
688
|
-
const contents = await this.readFile(path);
|
|
689
|
-
if (contents) {
|
|
690
|
-
runtimeFiles.push({
|
|
691
|
-
id: this.formatRuntimeId(id),
|
|
692
|
-
path,
|
|
693
|
-
contents
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
return runtimeFiles;
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
829
|
* Lists files in a given path.
|
|
701
830
|
*
|
|
702
831
|
* @param path - The path to list files from.
|
|
@@ -713,7 +842,7 @@ var VirtualFileSystem = class {
|
|
|
713
842
|
*/
|
|
714
843
|
unlinkSync(path, options) {
|
|
715
844
|
const formattedPath = toFilePath(path);
|
|
716
|
-
if (!this.
|
|
845
|
+
if (!this.isFile(formattedPath)) {
|
|
717
846
|
return;
|
|
718
847
|
}
|
|
719
848
|
this.#log(types.LogLevelLabel.TRACE, `Synchronously removing file: ${formattedPath}`);
|
|
@@ -728,7 +857,7 @@ var VirtualFileSystem = class {
|
|
|
728
857
|
*/
|
|
729
858
|
async unlink(path, options) {
|
|
730
859
|
const formattedPath = toFilePath(path);
|
|
731
|
-
if (!this.
|
|
860
|
+
if (!this.isFile(formattedPath)) {
|
|
732
861
|
return;
|
|
733
862
|
}
|
|
734
863
|
this.#log(types.LogLevelLabel.TRACE, `Removing file: ${formattedPath}`);
|
|
@@ -748,7 +877,7 @@ var VirtualFileSystem = class {
|
|
|
748
877
|
*/
|
|
749
878
|
rmdirSync(path, options = {}) {
|
|
750
879
|
const formattedPath = toFilePath(path);
|
|
751
|
-
if (!this.
|
|
880
|
+
if (!this.isDirectory(formattedPath)) {
|
|
752
881
|
return;
|
|
753
882
|
}
|
|
754
883
|
this.#log(types.LogLevelLabel.TRACE, `Synchronously removing directory: ${formattedPath}`);
|
|
@@ -767,7 +896,7 @@ var VirtualFileSystem = class {
|
|
|
767
896
|
*/
|
|
768
897
|
async rmdir(path, options = {}) {
|
|
769
898
|
const formattedPath = toFilePath(path);
|
|
770
|
-
if (!this.
|
|
899
|
+
if (!this.isDirectory(formattedPath)) {
|
|
771
900
|
return;
|
|
772
901
|
}
|
|
773
902
|
this.#log(types.LogLevelLabel.TRACE, `Removing directory: ${formattedPath}`);
|
|
@@ -794,7 +923,7 @@ var VirtualFileSystem = class {
|
|
|
794
923
|
*/
|
|
795
924
|
async rm(path, options = {}) {
|
|
796
925
|
this.#log(types.LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
|
|
797
|
-
if (this.
|
|
926
|
+
if (this.isDirectory(path)) {
|
|
798
927
|
return this.rmdir(path, options);
|
|
799
928
|
}
|
|
800
929
|
return this.unlink(path, options);
|
|
@@ -838,12 +967,12 @@ var VirtualFileSystem = class {
|
|
|
838
967
|
/**
|
|
839
968
|
* Lists files in a given path.
|
|
840
969
|
*
|
|
841
|
-
* @param
|
|
970
|
+
* @param pathOrId - The path to list files from.
|
|
842
971
|
* @param options - Options for listing files, such as encoding and recursion.
|
|
843
972
|
* @returns An array of file names in the specified path.
|
|
844
973
|
*/
|
|
845
|
-
async readdir(
|
|
846
|
-
return this.resolveFS(
|
|
974
|
+
async readdir(pathOrId, options = "utf8") {
|
|
975
|
+
return this.resolveFS(pathOrId).promises.readdir(toFilePath(pathOrId), options);
|
|
847
976
|
}
|
|
848
977
|
/**
|
|
849
978
|
* Asynchronously reads a file from the virtual file system (VFS).
|
|
@@ -855,7 +984,7 @@ var VirtualFileSystem = class {
|
|
|
855
984
|
if (!pathOrId) {
|
|
856
985
|
return void 0;
|
|
857
986
|
}
|
|
858
|
-
const filePath = this.
|
|
987
|
+
const filePath = this.resolve(toFilePath(pathOrId), {
|
|
859
988
|
type: "file"
|
|
860
989
|
});
|
|
861
990
|
if (filePath) {
|
|
@@ -884,7 +1013,7 @@ var VirtualFileSystem = class {
|
|
|
884
1013
|
if (!pathOrId) {
|
|
885
1014
|
return void 0;
|
|
886
1015
|
}
|
|
887
|
-
const filePath = this.
|
|
1016
|
+
const filePath = this.resolve(toFilePath(pathOrId), {
|
|
888
1017
|
type: "file"
|
|
889
1018
|
});
|
|
890
1019
|
if (filePath) {
|
|
@@ -901,137 +1030,80 @@ var VirtualFileSystem = class {
|
|
|
901
1030
|
/**
|
|
902
1031
|
* Writes a file to the virtual file system (VFS).
|
|
903
1032
|
*
|
|
904
|
-
* @param
|
|
1033
|
+
* @param path - The path to the file.
|
|
905
1034
|
* @param data - The contents of the file.
|
|
906
1035
|
* @param options - Optional parameters for writing the file.
|
|
907
1036
|
* @returns A promise that resolves when the file is written.
|
|
908
1037
|
*/
|
|
909
|
-
async writeFile(
|
|
910
|
-
const
|
|
911
|
-
if (!this.
|
|
912
|
-
await this.mkdir(filePathFns.findFilePath(
|
|
1038
|
+
async writeFile(path, data = "", options = "utf8") {
|
|
1039
|
+
const formattedPath = this.formatPath(path);
|
|
1040
|
+
if (!this.isDirectory(filePathFns.findFilePath(formattedPath))) {
|
|
1041
|
+
await this.mkdir(filePathFns.findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
913
1042
|
}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1043
|
+
let code = isPowerLinesWriteFileData(data) ? data.code : data;
|
|
1044
|
+
if ((!isPowerlinesWriteFileOptions(options) || !options.skipFormat) && isSetString.isSetString(code)) {
|
|
1045
|
+
const resolvedConfig = await prettier.resolveConfig(formattedPath);
|
|
1046
|
+
if (resolvedConfig) {
|
|
1047
|
+
code = await prettier.format(code, {
|
|
1048
|
+
absolutePath: formattedPath,
|
|
1049
|
+
...resolvedConfig
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
const outputMode = this.resolveOutputMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1054
|
+
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)})`);
|
|
1055
|
+
this.meta[formattedPath] = {
|
|
1056
|
+
path: formattedPath,
|
|
1057
|
+
code,
|
|
1058
|
+
mode: outputMode,
|
|
1059
|
+
variant: "normal",
|
|
1060
|
+
...isPowerLinesWriteFileData(data) ? data : {}
|
|
1061
|
+
};
|
|
1062
|
+
this.clearResolverCache(formattedPath);
|
|
1063
|
+
const ifs = this.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
918
1064
|
if (isFunction.isFunction(ifs.promises.writeFile)) {
|
|
919
|
-
return ifs.promises.writeFile(
|
|
920
|
-
"mode"
|
|
921
|
-
]));
|
|
1065
|
+
return ifs.promises.writeFile(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
|
|
922
1066
|
}
|
|
923
|
-
return ifs.writeFileSync(
|
|
924
|
-
"mode"
|
|
925
|
-
]));
|
|
1067
|
+
return ifs.writeFileSync(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
|
|
926
1068
|
}
|
|
927
1069
|
/**
|
|
928
1070
|
* Synchronously writes a file to the virtual file system (VFS).
|
|
929
1071
|
*
|
|
930
|
-
* @param
|
|
1072
|
+
* @param path - The file to write.
|
|
931
1073
|
* @param data - The contents of the file.
|
|
932
1074
|
* @param options - Optional parameters for writing the file.
|
|
933
1075
|
*/
|
|
934
|
-
writeFileSync(
|
|
935
|
-
const
|
|
936
|
-
if (!this.
|
|
937
|
-
this.mkdirSync(filePathFns.findFilePath(
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
this
|
|
941
|
-
this.
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1076
|
+
writeFileSync(path, data = "", options = "utf8") {
|
|
1077
|
+
const formattedPath = this.formatPath(path);
|
|
1078
|
+
if (!this.isDirectory(filePathFns.findFilePath(formattedPath))) {
|
|
1079
|
+
this.mkdirSync(filePathFns.findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1080
|
+
}
|
|
1081
|
+
const code = isPowerLinesWriteFileData(data) ? data.code : data;
|
|
1082
|
+
const outputMode = this.resolveOutputMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1083
|
+
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)})`);
|
|
1084
|
+
this.meta[formattedPath] = {
|
|
1085
|
+
path: formattedPath,
|
|
1086
|
+
code,
|
|
1087
|
+
mode: outputMode,
|
|
1088
|
+
variant: "normal",
|
|
1089
|
+
...isPowerLinesWriteFileData(data) ? data : {}
|
|
1090
|
+
};
|
|
1091
|
+
this.clearResolverCache(formattedPath);
|
|
1092
|
+
const writeStream = this.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0).createWriteStream(formattedPath);
|
|
945
1093
|
try {
|
|
946
|
-
writeStream.write(
|
|
1094
|
+
writeStream.write(code);
|
|
947
1095
|
} finally {
|
|
948
1096
|
writeStream.close();
|
|
949
1097
|
}
|
|
950
1098
|
}
|
|
951
1099
|
/**
|
|
952
|
-
* Writes a runtime file to the virtual file system (VFS).
|
|
953
|
-
*
|
|
954
|
-
* @param id - The unique identifier for the runtime file.
|
|
955
|
-
* @param path - The path to the runtime file.
|
|
956
|
-
* @param contents - The contents of the runtime file.
|
|
957
|
-
* @param options - Optional parameters for writing the runtime file.
|
|
958
|
-
* @returns A promise that resolves when the file is written.
|
|
959
|
-
*/
|
|
960
|
-
async writeBuiltinFile(id, path, contents, options = {}) {
|
|
961
|
-
const formattedId = this.formatRuntimeId(id);
|
|
962
|
-
const absolutePath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
963
|
-
this.builtinIdMap.set(formattedId, absolutePath);
|
|
964
|
-
let data = contents;
|
|
965
|
-
if (!options.skipFormat) {
|
|
966
|
-
data = await prettier.format(contents, {
|
|
967
|
-
absolutePath,
|
|
968
|
-
...await prettier.resolveConfig(absolutePath)
|
|
969
|
-
});
|
|
970
|
-
}
|
|
971
|
-
const _options = defu4__default.default(isSetString.isSetString(options) ? {} : options ?? {}, {
|
|
972
|
-
encoding: isSetString.isSetString(options) ? options : "utf8",
|
|
973
|
-
mode: "virtual"
|
|
974
|
-
});
|
|
975
|
-
this.#log(types.LogLevelLabel.DEBUG, `Writing runtime file ${absolutePath} (size: ${prettyBytes.prettyBytes(new buffer.Blob(toArray.toArray(data)).size)}) to ${this.resolveOutputMode(absolutePath, _options) === "fs" ? "disk" : "memory"}`);
|
|
976
|
-
return this.writeFile(absolutePath, data, _options);
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
* Adds an entry file to the virtual file system.
|
|
980
|
-
*
|
|
981
|
-
* @param name - The file name or absolute path of the entry module.
|
|
982
|
-
* @param contents - The contents of the entry file.
|
|
983
|
-
* @param options - Optional parameters for writing the entry file.
|
|
984
|
-
*/
|
|
985
|
-
async writeEntryFile(name, contents, options = {}) {
|
|
986
|
-
const absolutePath = this.formatAbsoluteFilePath(isType.isAbsolutePath(toFilePath(name)) ? toFilePath(name) : toFilePath(joinPaths.joinPaths(this.#context.entryPath, name)));
|
|
987
|
-
let data = contents;
|
|
988
|
-
if (!options.skipFormat) {
|
|
989
|
-
data = await prettier.format(contents, {
|
|
990
|
-
absolutePath,
|
|
991
|
-
...await prettier.resolveConfig(absolutePath)
|
|
992
|
-
});
|
|
993
|
-
}
|
|
994
|
-
const _options = defu4__default.default(isSetString.isSetString(options) ? {} : options ?? {}, {
|
|
995
|
-
encoding: isSetString.isSetString(options) ? options : "utf8",
|
|
996
|
-
mode: "virtual"
|
|
997
|
-
});
|
|
998
|
-
this.#log(types.LogLevelLabel.DEBUG, `Writing entry file ${absolutePath} (size: ${prettyBytes.prettyBytes(new buffer.Blob(toArray.toArray(data)).size)}) to ${this.resolveOutputMode(absolutePath, _options) === "fs" ? "disk" : "virtual memory"}`);
|
|
999
|
-
return this.writeFile(absolutePath, data, _options);
|
|
1000
|
-
}
|
|
1001
|
-
/**
|
|
1002
|
-
* Writes a file to disk from the physical file system (on disk).
|
|
1003
|
-
*
|
|
1004
|
-
* @param path - The path to the file to write.
|
|
1005
|
-
* @param contents - The contents of the file to write.
|
|
1006
|
-
* @param options - Optional parameters for writing the file.
|
|
1007
|
-
* @returns A promise that resolves when the file is written.
|
|
1008
|
-
*/
|
|
1009
|
-
async writeFileToDisk(path, contents, options = {}) {
|
|
1010
|
-
const absolutePath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
1011
|
-
let data = contents;
|
|
1012
|
-
if (!options.skipFormat) {
|
|
1013
|
-
const resolvedConfig = await prettier.resolveConfig(absolutePath);
|
|
1014
|
-
if (resolvedConfig) {
|
|
1015
|
-
data = await prettier.format(contents, {
|
|
1016
|
-
absolutePath,
|
|
1017
|
-
...resolvedConfig
|
|
1018
|
-
});
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
return this.writeFile(absolutePath, data, defu4__default.default({
|
|
1022
|
-
mode: "fs"
|
|
1023
|
-
}, isSetString.isSetString(options) ? {} : options ?? {}, {
|
|
1024
|
-
encoding: isSetString.isSetString(options) ? options : "utf8"
|
|
1025
|
-
}));
|
|
1026
|
-
}
|
|
1027
|
-
/**
|
|
1028
1100
|
* Synchronously checks if a file exists in the virtual file system (VFS).
|
|
1029
1101
|
*
|
|
1030
1102
|
* @param pathOrId - The path or ID of the file to check.
|
|
1031
1103
|
* @returns `true` if the file exists, otherwise `false`.
|
|
1032
1104
|
*/
|
|
1033
1105
|
existsSync(pathOrId) {
|
|
1034
|
-
return this.
|
|
1106
|
+
return this.resolve(pathOrId) !== false;
|
|
1035
1107
|
}
|
|
1036
1108
|
/**
|
|
1037
1109
|
* Checks if a file exists in the virtual file system (VFS).
|
|
@@ -1039,32 +1111,22 @@ var VirtualFileSystem = class {
|
|
|
1039
1111
|
* @remarks
|
|
1040
1112
|
* 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.
|
|
1041
1113
|
*
|
|
1042
|
-
* @param
|
|
1114
|
+
* @param pathOrId - The path of the file to check.
|
|
1043
1115
|
* @returns `true` if the file exists, otherwise `false`.
|
|
1044
1116
|
*/
|
|
1045
|
-
|
|
1046
|
-
const
|
|
1047
|
-
return
|
|
1117
|
+
isFile(pathOrId) {
|
|
1118
|
+
const resolved = this.resolve(pathOrId);
|
|
1119
|
+
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()));
|
|
1048
1120
|
}
|
|
1049
1121
|
/**
|
|
1050
1122
|
* Checks if a directory exists in the virtual file system (VFS).
|
|
1051
1123
|
*
|
|
1052
|
-
* @param
|
|
1124
|
+
* @param pathOrId - The path of the directory to check.
|
|
1053
1125
|
* @returns `true` if the directory exists, otherwise `false`.
|
|
1054
1126
|
*/
|
|
1055
|
-
|
|
1056
|
-
const
|
|
1057
|
-
return this.#virtualFS.existsSync(
|
|
1058
|
-
}
|
|
1059
|
-
/**
|
|
1060
|
-
* Checks if a path exists in the virtual file system (VFS).
|
|
1061
|
-
*
|
|
1062
|
-
* @param path - The path to check.
|
|
1063
|
-
* @returns `true` if the path exists, otherwise `false`.
|
|
1064
|
-
*/
|
|
1065
|
-
pathExistsSync(path) {
|
|
1066
|
-
const formattedPath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
1067
|
-
return this.isValidBuiltinId(formattedPath) || this.#virtualFS.existsSync(formattedPath) || this.#fs.existsSync(formattedPath) || this.resolveFS(path).existsSync(formattedPath);
|
|
1127
|
+
isDirectory(pathOrId) {
|
|
1128
|
+
const resolved = this.resolve(pathOrId);
|
|
1129
|
+
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()));
|
|
1068
1130
|
}
|
|
1069
1131
|
/**
|
|
1070
1132
|
* Retrieves the status of a file in the virtual file system (VFS).
|
|
@@ -1073,7 +1135,7 @@ var VirtualFileSystem = class {
|
|
|
1073
1135
|
* @returns A promise that resolves to the file's status information, or false if the file does not exist.
|
|
1074
1136
|
*/
|
|
1075
1137
|
async stat(pathOrId, options) {
|
|
1076
|
-
return this.resolveFS(pathOrId).promises.stat(this.
|
|
1138
|
+
return this.resolveFS(pathOrId).promises.stat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
|
|
1077
1139
|
}
|
|
1078
1140
|
/**
|
|
1079
1141
|
* Synchronously retrieves the status of a file in the virtual file system (VFS).
|
|
@@ -1082,7 +1144,7 @@ var VirtualFileSystem = class {
|
|
|
1082
1144
|
* @returns The file's status information, or false if the file does not exist.
|
|
1083
1145
|
*/
|
|
1084
1146
|
statSync(pathOrId) {
|
|
1085
|
-
return this.resolveFS(pathOrId).statSync(this.
|
|
1147
|
+
return this.resolveFS(pathOrId).statSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId));
|
|
1086
1148
|
}
|
|
1087
1149
|
/**
|
|
1088
1150
|
* Retrieves the status of a symbolic link in the virtual file system (VFS).
|
|
@@ -1091,7 +1153,7 @@ var VirtualFileSystem = class {
|
|
|
1091
1153
|
* @returns A promise that resolves to the symbolic link's status information, or false if the link does not exist.
|
|
1092
1154
|
*/
|
|
1093
1155
|
async lstat(pathOrId, options) {
|
|
1094
|
-
return this.resolveFS(pathOrId).promises.lstat(this.
|
|
1156
|
+
return this.resolveFS(pathOrId).promises.lstat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
|
|
1095
1157
|
}
|
|
1096
1158
|
/**
|
|
1097
1159
|
* Synchronously retrieves the status of a symbolic link in the virtual file system (VFS).
|
|
@@ -1100,23 +1162,7 @@ var VirtualFileSystem = class {
|
|
|
1100
1162
|
* @returns The symbolic link's status information, or false if the link does not exist.
|
|
1101
1163
|
*/
|
|
1102
1164
|
lstatSync(pathOrId, options) {
|
|
1103
|
-
return this.resolveFS(pathOrId).lstatSync(this.
|
|
1104
|
-
}
|
|
1105
|
-
/**
|
|
1106
|
-
* Resolves a path or ID to a runtime file id in the virtual file system.
|
|
1107
|
-
*
|
|
1108
|
-
* @param pathOrId - The path or id of the file to resolve.
|
|
1109
|
-
* @returns The resolved id of the runtime file if it exists, otherwise false.
|
|
1110
|
-
*/
|
|
1111
|
-
resolveId(pathOrId) {
|
|
1112
|
-
if (this.builtinIdMap.has(this.formatRuntimeId(toFilePath(pathOrId)))) {
|
|
1113
|
-
return this.formatRuntimeId(toFilePath(pathOrId));
|
|
1114
|
-
}
|
|
1115
|
-
const filePath = this.resolvePath(toFilePath(pathOrId));
|
|
1116
|
-
if (filePath) {
|
|
1117
|
-
return this.builtinIdMap.keys().find((id) => this.builtinIdMap.get(id) === filePath) || false;
|
|
1118
|
-
}
|
|
1119
|
-
return false;
|
|
1165
|
+
return this.resolveFS(pathOrId).lstatSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
|
|
1120
1166
|
}
|
|
1121
1167
|
/**
|
|
1122
1168
|
* Resolves a path based on TypeScript's `tsconfig.json` paths.
|
|
@@ -1129,9 +1175,9 @@ var VirtualFileSystem = class {
|
|
|
1129
1175
|
resolveTsconfigPath(path) {
|
|
1130
1176
|
if (this.#context.tsconfig.options.paths) {
|
|
1131
1177
|
for (const tsconfigPathKey of Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path.startsWith(tsconfigPath.replaceAll("*", "")))) {
|
|
1132
|
-
const resolvedPath = this.#context.tsconfig.options.paths[tsconfigPathKey]?.find((tsconfigPath) => this.
|
|
1178
|
+
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));
|
|
1133
1179
|
if (resolvedPath) {
|
|
1134
|
-
return this.
|
|
1180
|
+
return this.formatPath(resolvedPath) === this.formatPath(path) ? this.formatPath(resolvedPath) : this.resolvePath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, resolvedPath.replaceAll("*", ""), path.replace(tsconfigPathKey.replaceAll("*", ""), "")));
|
|
1135
1181
|
}
|
|
1136
1182
|
}
|
|
1137
1183
|
}
|
|
@@ -1161,7 +1207,7 @@ var VirtualFileSystem = class {
|
|
|
1161
1207
|
* @returns The resolved real path if it exists, otherwise undefined.
|
|
1162
1208
|
*/
|
|
1163
1209
|
realpathSync(pathOrId) {
|
|
1164
|
-
const filePath = this.
|
|
1210
|
+
const filePath = this.resolve(toFilePath(pathOrId));
|
|
1165
1211
|
if (!filePath) {
|
|
1166
1212
|
throw new Error(`File not found: ${toFilePath(pathOrId)}`);
|
|
1167
1213
|
}
|
|
@@ -1174,24 +1220,18 @@ var VirtualFileSystem = class {
|
|
|
1174
1220
|
* @param options - Optional parameters for resolving the path, such as whether to include the file extension.
|
|
1175
1221
|
* @returns The resolved file path if it exists, otherwise undefined.
|
|
1176
1222
|
*/
|
|
1177
|
-
|
|
1178
|
-
const
|
|
1179
|
-
const resolverKey = `${
|
|
1223
|
+
resolve(pathOrId, options = {}) {
|
|
1224
|
+
const formattedPathOrId = toFilePath(pathOrId);
|
|
1225
|
+
const resolverKey = `${formattedPathOrId}${options.withExtension ? "-ext" : ""}${options.paths ? `-${murmurhash.murmurhash(options.paths)}` : ""}${options.type ? `-${options.type}` : ""}`;
|
|
1180
1226
|
if (this.#cachedResolver.has(resolverKey)) {
|
|
1181
1227
|
return this.#cachedResolver.get(resolverKey);
|
|
1182
|
-
} else if (this.#cachedFS.has(formattedPath)) {
|
|
1183
|
-
return formattedPath;
|
|
1184
1228
|
}
|
|
1185
|
-
let result =
|
|
1186
|
-
if (
|
|
1187
|
-
result = this.
|
|
1188
|
-
} else {
|
|
1189
|
-
result = this.resolvePathName(formattedPath, options);
|
|
1229
|
+
let result = this.resolveId(formattedPathOrId);
|
|
1230
|
+
if (!result) {
|
|
1231
|
+
result = this.resolvePath(formattedPathOrId, options);
|
|
1190
1232
|
}
|
|
1191
1233
|
if (!result) {
|
|
1192
1234
|
result = false;
|
|
1193
|
-
} else {
|
|
1194
|
-
result = toFilePath(result);
|
|
1195
1235
|
}
|
|
1196
1236
|
if (result && options.withExtension === false) {
|
|
1197
1237
|
return result.replace(/\.[m|c]?[t|j]sx?$/, "");
|
|
@@ -1200,16 +1240,12 @@ var VirtualFileSystem = class {
|
|
|
1200
1240
|
return result;
|
|
1201
1241
|
}
|
|
1202
1242
|
/**
|
|
1203
|
-
*
|
|
1243
|
+
* Retrieves the partial metadata for all files in the virtual file system (VFS).
|
|
1204
1244
|
*
|
|
1205
|
-
* @
|
|
1206
|
-
* @returns The formatted file path.
|
|
1245
|
+
* @returns A record containing the partial metadata for all files.
|
|
1207
1246
|
*/
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
throw new Error(`Invalid path provided. Expected a string or a valid file path.`);
|
|
1211
|
-
}
|
|
1212
|
-
return path.replace(new RegExp(`^${this.#context.config.output.builtinPrefix}:`), "").replace(/^\\0/, "");
|
|
1247
|
+
getPartialMeta() {
|
|
1248
|
+
return Object.fromEntries(Object.entries(this.#meta).filter(([_, data]) => isSetObject.isSetObject(data)));
|
|
1213
1249
|
}
|
|
1214
1250
|
/**
|
|
1215
1251
|
* Converts a relative path to an absolute path based on the workspace and project root.
|
|
@@ -1217,56 +1253,67 @@ var VirtualFileSystem = class {
|
|
|
1217
1253
|
* @param path - The relative path to convert.
|
|
1218
1254
|
* @returns The absolute path.
|
|
1219
1255
|
*/
|
|
1220
|
-
|
|
1221
|
-
const formattedPath =
|
|
1256
|
+
formatPath(path) {
|
|
1257
|
+
const formattedPath = toFilePath(path);
|
|
1222
1258
|
if (isType.isAbsolutePath(formattedPath) || formattedPath.startsWith(this.#context.workspaceConfig.workspaceRoot)) {
|
|
1223
1259
|
return formattedPath;
|
|
1224
1260
|
} else if (formattedPath.startsWith(this.#context.config.projectRoot)) {
|
|
1225
1261
|
return joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, formattedPath);
|
|
1226
1262
|
}
|
|
1227
1263
|
return formattedPath;
|
|
1228
|
-
}
|
|
1264
|
+
}
|
|
1229
1265
|
/**
|
|
1230
|
-
* Formats a
|
|
1266
|
+
* Formats a file id by removing the file extension and prepending the runtime prefix.
|
|
1231
1267
|
*
|
|
1232
|
-
* @param id - The
|
|
1233
|
-
* @returns The formatted
|
|
1268
|
+
* @param id - The file ID to format.
|
|
1269
|
+
* @returns The formatted file ID.
|
|
1234
1270
|
*/
|
|
1235
|
-
|
|
1236
|
-
|
|
1271
|
+
formatId(id) {
|
|
1272
|
+
const formattedId = toFilePath(id);
|
|
1273
|
+
return `${this.#context.config.output.builtinPrefix}:${formattedId.replace(new RegExp(`^${this.#context.config.output.builtinPrefix}:`), "").replace(/^\\0/, "").replace(filePathFns.findFileExtensionSafe(formattedId), "")}`;
|
|
1237
1274
|
}
|
|
1238
1275
|
/**
|
|
1239
|
-
* Resolves
|
|
1276
|
+
* Resolves an id parameter to a corresponding virtual file path in the virtual file system (VFS).
|
|
1240
1277
|
*
|
|
1241
|
-
* @param
|
|
1242
|
-
* @returns The resolved file
|
|
1278
|
+
* @param id - The id to resolve.
|
|
1279
|
+
* @returns The resolved file id if it exists, otherwise undefined.
|
|
1243
1280
|
*/
|
|
1244
|
-
|
|
1245
|
-
if (
|
|
1246
|
-
return false;
|
|
1281
|
+
resolveId(id) {
|
|
1282
|
+
if (this.#ids[this.formatId(id)]) {
|
|
1283
|
+
return this.#ids[this.formatId(id)] || false;
|
|
1247
1284
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1285
|
+
return false;
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Resolves a path parameter to a corresponding virtual file path in the virtual file system (VFS).
|
|
1289
|
+
*
|
|
1290
|
+
* @param path - The path to resolve.
|
|
1291
|
+
* @param options - Optional parameters for resolving the path.
|
|
1292
|
+
* @returns The resolved file path if it exists, otherwise undefined.
|
|
1293
|
+
*/
|
|
1294
|
+
resolvePath(path, options = {}) {
|
|
1295
|
+
if (isType.isAbsolutePath(path)) {
|
|
1296
|
+
if (this.#existsSync(path)) {
|
|
1297
|
+
return path;
|
|
1251
1298
|
}
|
|
1252
|
-
const result = checkVariants(
|
|
1299
|
+
const result = this.checkVariants(path);
|
|
1253
1300
|
if (result) {
|
|
1254
1301
|
return result;
|
|
1255
1302
|
}
|
|
1256
1303
|
}
|
|
1257
|
-
for (const
|
|
1258
|
-
const request = joinPaths.joinPaths(
|
|
1259
|
-
if (
|
|
1304
|
+
for (const parentPath of this.resolveParentPaths(path, options.paths)) {
|
|
1305
|
+
const request = joinPaths.joinPaths(parentPath, path);
|
|
1306
|
+
if (this.#existsSync(request)) {
|
|
1260
1307
|
return request;
|
|
1261
1308
|
}
|
|
1262
|
-
const result = checkVariants(request
|
|
1309
|
+
const result = this.checkVariants(request);
|
|
1263
1310
|
if (result) {
|
|
1264
1311
|
return result;
|
|
1265
1312
|
}
|
|
1266
1313
|
}
|
|
1267
1314
|
return false;
|
|
1268
1315
|
}
|
|
1269
|
-
resolveParentPaths(request,
|
|
1316
|
+
resolveParentPaths(request, parents = []) {
|
|
1270
1317
|
let paths = [
|
|
1271
1318
|
this.#context.workspaceConfig.workspaceRoot,
|
|
1272
1319
|
joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot)
|
|
@@ -1284,7 +1331,7 @@ var VirtualFileSystem = class {
|
|
|
1284
1331
|
ret.push(path);
|
|
1285
1332
|
}
|
|
1286
1333
|
return ret;
|
|
1287
|
-
},
|
|
1334
|
+
}, parents.filter(Boolean).map((p) => this.formatPath(p)));
|
|
1288
1335
|
}
|
|
1289
1336
|
/**
|
|
1290
1337
|
* Select the file system module to use for the operation based on the path or URL.
|
|
@@ -1315,7 +1362,7 @@ var VirtualFileSystem = class {
|
|
|
1315
1362
|
} 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))) {
|
|
1316
1363
|
return "fs";
|
|
1317
1364
|
}
|
|
1318
|
-
return
|
|
1365
|
+
return void 0;
|
|
1319
1366
|
}
|
|
1320
1367
|
/**
|
|
1321
1368
|
* Clears the resolver cache for a given path.
|
|
@@ -1325,208 +1372,93 @@ var VirtualFileSystem = class {
|
|
|
1325
1372
|
clearResolverCache(path) {
|
|
1326
1373
|
this.#cachedResolver.keys().filter((key) => key.startsWith(toFilePath(path))).forEach((key) => this.#cachedResolver.delete(key));
|
|
1327
1374
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
chunkSHUYVCID_js.__name(toFilePath, "toFilePath");
|
|
1341
|
-
var FS_METHODS = [
|
|
1342
|
-
"mkdir",
|
|
1343
|
-
"mkdirSync",
|
|
1344
|
-
"rmdir",
|
|
1345
|
-
"rmdirSync",
|
|
1346
|
-
"unlink",
|
|
1347
|
-
"unlinkSync",
|
|
1348
|
-
"existsSync",
|
|
1349
|
-
"realpathSync",
|
|
1350
|
-
"writeFileSync",
|
|
1351
|
-
"readFileSync",
|
|
1352
|
-
"readdirSync",
|
|
1353
|
-
"createWriteStream",
|
|
1354
|
-
"WriteStream",
|
|
1355
|
-
"createReadStream",
|
|
1356
|
-
"ReadStream"
|
|
1357
|
-
];
|
|
1358
|
-
var FS_PROMISE_METHODS = [
|
|
1359
|
-
"mkdir",
|
|
1360
|
-
"rm",
|
|
1361
|
-
"rmdir",
|
|
1362
|
-
"unlink",
|
|
1363
|
-
"writeFile",
|
|
1364
|
-
"readFile",
|
|
1365
|
-
"readdir",
|
|
1366
|
-
"stat",
|
|
1367
|
-
"lstat"
|
|
1368
|
-
];
|
|
1369
|
-
function cloneFS(originalFS) {
|
|
1370
|
-
const clonedFS = {
|
|
1371
|
-
...originalFS,
|
|
1372
|
-
promises: {
|
|
1373
|
-
...originalFS.promises ?? {}
|
|
1375
|
+
/**
|
|
1376
|
+
* Check if the file exists with different variants (index, extensions).
|
|
1377
|
+
*
|
|
1378
|
+
* @param request - The request path to check.
|
|
1379
|
+
* @param parentPath - An optional parent path to prepend to the request.
|
|
1380
|
+
* @returns The file path if it exists, otherwise false.
|
|
1381
|
+
*/
|
|
1382
|
+
checkVariants(request, parentPath) {
|
|
1383
|
+
const path = parentPath ? joinPaths.joinPaths(parentPath, request) : request;
|
|
1384
|
+
let file = this.checkExtensions(path);
|
|
1385
|
+
if (file) {
|
|
1386
|
+
return file;
|
|
1374
1387
|
}
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
clonedFS[method] = originalFS[method];
|
|
1388
|
+
file = this.checkIndex(path);
|
|
1389
|
+
if (file) {
|
|
1390
|
+
return file;
|
|
1379
1391
|
}
|
|
1392
|
+
return false;
|
|
1380
1393
|
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1394
|
+
/**
|
|
1395
|
+
* Check if the index file exists in the given request path.
|
|
1396
|
+
*
|
|
1397
|
+
* @param request - The request path to check.
|
|
1398
|
+
* @returns The index file path if it exists, otherwise false.
|
|
1399
|
+
*/
|
|
1400
|
+
checkIndex(request) {
|
|
1401
|
+
let file = joinPaths.joinPaths(request, "index");
|
|
1402
|
+
if (this.#existsSync(file)) {
|
|
1403
|
+
return file;
|
|
1387
1404
|
}
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
clonedFS[prop] = clonedFS[prop].bind(originalFS);
|
|
1392
|
-
if (isFunction.isFunction(clonedFS.promises[prop])) {
|
|
1393
|
-
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
1394
|
-
}
|
|
1405
|
+
file = this.checkExtensions(file);
|
|
1406
|
+
if (file) {
|
|
1407
|
+
return file;
|
|
1395
1408
|
}
|
|
1409
|
+
return false;
|
|
1396
1410
|
}
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1411
|
+
/**
|
|
1412
|
+
* Check if the file exists with different extensions.
|
|
1413
|
+
*
|
|
1414
|
+
* @param request - The request path to check.
|
|
1415
|
+
* @param vfs - The file system module to use for checking file existence.
|
|
1416
|
+
* @returns The file path if it exists with any of the checked extensions, otherwise false.
|
|
1417
|
+
*/
|
|
1418
|
+
checkExtensions(request) {
|
|
1419
|
+
let file = `${request}.ts`;
|
|
1420
|
+
if (this.#existsSync(file)) {
|
|
1421
|
+
return file;
|
|
1400
1422
|
}
|
|
1423
|
+
file = `${request}.mts`;
|
|
1424
|
+
if (this.#existsSync(file)) {
|
|
1425
|
+
return file;
|
|
1426
|
+
}
|
|
1427
|
+
file = `${request}.cts`;
|
|
1428
|
+
if (this.#existsSync(file)) {
|
|
1429
|
+
return file;
|
|
1430
|
+
}
|
|
1431
|
+
file = `${request}.tsx`;
|
|
1432
|
+
if (this.#existsSync(file)) {
|
|
1433
|
+
return file;
|
|
1434
|
+
}
|
|
1435
|
+
file = `${request}.js`;
|
|
1436
|
+
if (this.#existsSync(file)) {
|
|
1437
|
+
return file;
|
|
1438
|
+
}
|
|
1439
|
+
file = `${request}.mjs`;
|
|
1440
|
+
if (this.#existsSync(file)) {
|
|
1441
|
+
return file;
|
|
1442
|
+
}
|
|
1443
|
+
file = `${request}.cjs`;
|
|
1444
|
+
if (this.#existsSync(file)) {
|
|
1445
|
+
return file;
|
|
1446
|
+
}
|
|
1447
|
+
file = `${request}.jsx`;
|
|
1448
|
+
if (this.#existsSync(file)) {
|
|
1449
|
+
return file;
|
|
1450
|
+
}
|
|
1451
|
+
file = `${request}.json`;
|
|
1452
|
+
if (this.#existsSync(file)) {
|
|
1453
|
+
return file;
|
|
1454
|
+
}
|
|
1455
|
+
file = `${request}.d.ts`;
|
|
1456
|
+
if (this.#existsSync(file)) {
|
|
1457
|
+
return file;
|
|
1458
|
+
}
|
|
1459
|
+
return false;
|
|
1401
1460
|
}
|
|
1402
|
-
|
|
1403
|
-
}
|
|
1404
|
-
chunkSHUYVCID_js.__name(cloneFS, "cloneFS");
|
|
1405
|
-
function patchFS(originalFS, vfs) {
|
|
1406
|
-
const clonedFS = cloneFS(originalFS);
|
|
1407
|
-
originalFS.mkdirSync = (file, options) => vfs.mkdirSync(toFilePath(file), options);
|
|
1408
|
-
originalFS.mkdir = (file, options, callback) => vfs.mkdir(toFilePath(file), options, callback);
|
|
1409
|
-
originalFS.promises.mkdir = async (file, options) => vfs.mkdir(toFilePath(file), options);
|
|
1410
|
-
originalFS.unlinkSync = (file) => vfs.unlinkSync(toFilePath(file));
|
|
1411
|
-
originalFS.promises.rm = async (file, options) => vfs.rm(toFilePath(file), options);
|
|
1412
|
-
originalFS.promises.unlink = async (file) => vfs.unlink(toFilePath(file));
|
|
1413
|
-
originalFS.existsSync = (file) => vfs.existsSync(toFilePath(file));
|
|
1414
|
-
Object.defineProperty(originalFS, "realpathSync", {
|
|
1415
|
-
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.realpathSync(toFilePath(file), options), "value")
|
|
1416
|
-
});
|
|
1417
|
-
originalFS.writeFileSync = (file, data, options) => vfs.writeFileSync(toFilePath(file), data, options);
|
|
1418
|
-
originalFS.promises.writeFile = async (file, data, options) => vfs.writeFile(toFilePath(file), data, options);
|
|
1419
|
-
originalFS.readFileSync = (file, options) => vfs.readFileSync(toFilePath(file), options);
|
|
1420
|
-
originalFS.promises.readFile = (file, options) => vfs.readFile(toFilePath(file), options);
|
|
1421
|
-
originalFS.readdirSync = (file, options) => vfs.readdirSync(toFilePath(file), options);
|
|
1422
|
-
originalFS.promises.readdir = (file, options) => vfs.readdir(toFilePath(file), options);
|
|
1423
|
-
Object.defineProperty(originalFS, "statSync", {
|
|
1424
|
-
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.statSync(toFilePath(file), options), "value")
|
|
1425
|
-
});
|
|
1426
|
-
originalFS.stat = (file, options) => vfs.statSync(toFilePath(file), options);
|
|
1427
|
-
originalFS.promises.stat = (file, options) => vfs.stat(toFilePath(file), options);
|
|
1428
|
-
Object.defineProperty(originalFS, "lstatSync", {
|
|
1429
|
-
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.lstatSync(toFilePath(file), options), "value")
|
|
1430
|
-
});
|
|
1431
|
-
originalFS.lstat = (file, options) => vfs.lstatSync(toFilePath(file), options);
|
|
1432
|
-
originalFS.promises.lstat = (file, options) => vfs.lstat(toFilePath(file), options);
|
|
1433
|
-
return () => {
|
|
1434
|
-
originalFS.mkdirSync = clonedFS.mkdirSync;
|
|
1435
|
-
originalFS.mkdir = clonedFS.mkdir;
|
|
1436
|
-
originalFS.promises.mkdir = clonedFS.promises.mkdir;
|
|
1437
|
-
originalFS.unlinkSync = clonedFS.unlinkSync;
|
|
1438
|
-
originalFS.promises.rm = clonedFS.promises.rm;
|
|
1439
|
-
originalFS.promises.unlink = clonedFS.promises.unlink;
|
|
1440
|
-
originalFS.existsSync = clonedFS.existsSync;
|
|
1441
|
-
originalFS.realpathSync = clonedFS.realpathSync;
|
|
1442
|
-
originalFS.writeFileSync = clonedFS.writeFileSync;
|
|
1443
|
-
originalFS.promises.writeFile = clonedFS.promises.writeFile;
|
|
1444
|
-
originalFS.readFileSync = clonedFS.readFileSync;
|
|
1445
|
-
originalFS.promises.readFile = clonedFS.promises.readFile;
|
|
1446
|
-
originalFS.readdirSync = clonedFS.readdirSync;
|
|
1447
|
-
originalFS.promises.readdir = clonedFS.promises.readdir;
|
|
1448
|
-
Object.defineProperty(originalFS, "statSync", {
|
|
1449
|
-
value: clonedFS.statSync
|
|
1450
|
-
});
|
|
1451
|
-
originalFS.stat = clonedFS.stat;
|
|
1452
|
-
originalFS.promises.stat = clonedFS.promises.stat;
|
|
1453
|
-
Object.defineProperty(originalFS, "lstatSync", {
|
|
1454
|
-
value: clonedFS.lstatSync
|
|
1455
|
-
});
|
|
1456
|
-
originalFS.lstat = clonedFS.lstat;
|
|
1457
|
-
originalFS.promises.lstat = clonedFS.promises.lstat;
|
|
1458
|
-
};
|
|
1459
|
-
}
|
|
1460
|
-
chunkSHUYVCID_js.__name(patchFS, "patchFS");
|
|
1461
|
-
function checkVariants(request, vfs, parentPath) {
|
|
1462
|
-
const path = parentPath ? joinPaths.joinPaths(parentPath, request) : request;
|
|
1463
|
-
let file = checkExtensions(path, vfs);
|
|
1464
|
-
if (file) {
|
|
1465
|
-
return file;
|
|
1466
|
-
}
|
|
1467
|
-
file = checkIndex(path, vfs);
|
|
1468
|
-
if (file) {
|
|
1469
|
-
return file;
|
|
1470
|
-
}
|
|
1471
|
-
return false;
|
|
1472
|
-
}
|
|
1473
|
-
chunkSHUYVCID_js.__name(checkVariants, "checkVariants");
|
|
1474
|
-
function checkIndex(request, vfs) {
|
|
1475
|
-
let file = joinPaths.joinPaths(request, "index");
|
|
1476
|
-
if (vfs.fileExistsSync(file)) {
|
|
1477
|
-
return file;
|
|
1478
|
-
}
|
|
1479
|
-
file = checkExtensions(file, vfs);
|
|
1480
|
-
if (file) {
|
|
1481
|
-
return file;
|
|
1482
|
-
}
|
|
1483
|
-
return false;
|
|
1484
|
-
}
|
|
1485
|
-
chunkSHUYVCID_js.__name(checkIndex, "checkIndex");
|
|
1486
|
-
function checkExtensions(request, vfs) {
|
|
1487
|
-
let file = `${request}.ts`;
|
|
1488
|
-
if (vfs.fileExistsSync(file)) {
|
|
1489
|
-
return file;
|
|
1490
|
-
}
|
|
1491
|
-
file = `${request}.mts`;
|
|
1492
|
-
if (vfs.fileExistsSync(file)) {
|
|
1493
|
-
return file;
|
|
1494
|
-
}
|
|
1495
|
-
file = `${request}.cts`;
|
|
1496
|
-
if (vfs.fileExistsSync(file)) {
|
|
1497
|
-
return file;
|
|
1498
|
-
}
|
|
1499
|
-
file = `${request}.tsx`;
|
|
1500
|
-
if (vfs.fileExistsSync(file)) {
|
|
1501
|
-
return file;
|
|
1502
|
-
}
|
|
1503
|
-
file = `${request}.js`;
|
|
1504
|
-
if (vfs.fileExistsSync(file)) {
|
|
1505
|
-
return file;
|
|
1506
|
-
}
|
|
1507
|
-
file = `${request}.mjs`;
|
|
1508
|
-
if (vfs.fileExistsSync(file)) {
|
|
1509
|
-
return file;
|
|
1510
|
-
}
|
|
1511
|
-
file = `${request}.cjs`;
|
|
1512
|
-
if (vfs.fileExistsSync(file)) {
|
|
1513
|
-
return file;
|
|
1514
|
-
}
|
|
1515
|
-
file = `${request}.jsx`;
|
|
1516
|
-
if (vfs.fileExistsSync(file)) {
|
|
1517
|
-
return file;
|
|
1518
|
-
}
|
|
1519
|
-
file = `${request}.json`;
|
|
1520
|
-
if (vfs.fileExistsSync(file)) {
|
|
1521
|
-
return file;
|
|
1522
|
-
}
|
|
1523
|
-
file = `${request}.d.ts`;
|
|
1524
|
-
if (vfs.fileExistsSync(file)) {
|
|
1525
|
-
return file;
|
|
1526
|
-
}
|
|
1527
|
-
return false;
|
|
1528
|
-
}
|
|
1529
|
-
chunkSHUYVCID_js.__name(checkExtensions, "checkExtensions");
|
|
1461
|
+
};
|
|
1530
1462
|
function createVfs(context) {
|
|
1531
1463
|
const vfs = new VirtualFileSystem(context);
|
|
1532
1464
|
return vfs;
|
|
@@ -1534,7 +1466,8 @@ function createVfs(context) {
|
|
|
1534
1466
|
chunkSHUYVCID_js.__name(createVfs, "createVfs");
|
|
1535
1467
|
|
|
1536
1468
|
// ../powerlines/src/internal/contexts/context.ts
|
|
1537
|
-
var
|
|
1469
|
+
var configCache = /* @__PURE__ */ new WeakMap();
|
|
1470
|
+
var parseCache = /* @__PURE__ */ new WeakMap();
|
|
1538
1471
|
var PowerlinesContext = class _PowerlinesContext {
|
|
1539
1472
|
static {
|
|
1540
1473
|
chunkSHUYVCID_js.__name(this, "PowerlinesContext");
|
|
@@ -1583,7 +1516,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1583
1516
|
* @returns A promise that resolves to the new context.
|
|
1584
1517
|
*/
|
|
1585
1518
|
static async from(workspaceRoot, config) {
|
|
1586
|
-
const context = new _PowerlinesContext(await
|
|
1519
|
+
const context = new _PowerlinesContext(await chunk4UWZOCEA_js.loadWorkspaceConfig(workspaceRoot, config.root));
|
|
1587
1520
|
await context.withUserConfig(config);
|
|
1588
1521
|
context.powerlinesPath = await resolve.resolvePackage("powerlines");
|
|
1589
1522
|
if (!context.powerlinesPath) {
|
|
@@ -1670,10 +1603,10 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1670
1603
|
workspaceRoot: this.workspaceConfig?.workspaceRoot,
|
|
1671
1604
|
projectRoot: this.config?.projectRoot
|
|
1672
1605
|
}, {
|
|
1673
|
-
maxLength:
|
|
1606
|
+
maxLength: chunk4UWZOCEA_js.PROJECT_ROOT_HASH_LENGTH
|
|
1674
1607
|
}),
|
|
1675
1608
|
configHash: murmurhash.murmurhash(this.config, {
|
|
1676
|
-
maxLength:
|
|
1609
|
+
maxLength: chunk4UWZOCEA_js.CACHE_HASH_LENGTH
|
|
1677
1610
|
}),
|
|
1678
1611
|
builtinIdMap: {},
|
|
1679
1612
|
virtualFiles: {}
|
|
@@ -1735,7 +1668,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1735
1668
|
* Get the path to the data directory for the project
|
|
1736
1669
|
*/
|
|
1737
1670
|
get dataPath() {
|
|
1738
|
-
return join.joinPaths(this.envPaths.data, "projects",
|
|
1671
|
+
return join.joinPaths(this.envPaths.data, "projects", chunk4UWZOCEA_js.getPrefixedProjectRootHash(this.config.name, this.meta.projectRootHash));
|
|
1739
1672
|
}
|
|
1740
1673
|
/**
|
|
1741
1674
|
* Get the path to the cache directory for the project
|
|
@@ -1745,7 +1678,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1745
1678
|
checksum: this.#checksum,
|
|
1746
1679
|
config: this.meta.configHash
|
|
1747
1680
|
}, {
|
|
1748
|
-
maxLength:
|
|
1681
|
+
maxLength: chunk4UWZOCEA_js.CACHE_HASH_LENGTH
|
|
1749
1682
|
}));
|
|
1750
1683
|
}
|
|
1751
1684
|
/**
|
|
@@ -1761,6 +1694,57 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1761
1694
|
return getWorkspaceRoot.relativeToWorkspaceRoot(this.config.projectRoot);
|
|
1762
1695
|
}
|
|
1763
1696
|
/**
|
|
1697
|
+
* The builtin module id that exist in the Powerlines virtual file system
|
|
1698
|
+
*/
|
|
1699
|
+
get builtins() {
|
|
1700
|
+
return Object.values(this.fs.meta).filter((meta) => meta && meta.variant === "builtin").map((meta) => meta?.id).filter(Boolean);
|
|
1701
|
+
}
|
|
1702
|
+
/**
|
|
1703
|
+
* Get the project root relative to the workspace root
|
|
1704
|
+
*/
|
|
1705
|
+
async getBuiltins() {
|
|
1706
|
+
return Promise.all(Object.entries(this.fs.meta).filter(([, meta]) => meta && meta.variant === "builtin").map(async ([path, meta]) => {
|
|
1707
|
+
const code = await this.fs.readFile(path);
|
|
1708
|
+
return {
|
|
1709
|
+
...meta,
|
|
1710
|
+
path,
|
|
1711
|
+
code
|
|
1712
|
+
};
|
|
1713
|
+
}));
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Resolves a entry virtual file and writes it to the VFS if it does not already exist
|
|
1717
|
+
*
|
|
1718
|
+
* @param code - The source code of the entry file
|
|
1719
|
+
* @param path - A path to write the entry file to
|
|
1720
|
+
* @param options - Optional write file options
|
|
1721
|
+
*/
|
|
1722
|
+
async writeEntry(code, path, options = {}) {
|
|
1723
|
+
return this.fs.writeFile(isType.isAbsolute(path) ? path : append.appendPath(path, this.entryPath), {
|
|
1724
|
+
code,
|
|
1725
|
+
variant: "entry"
|
|
1726
|
+
}, defu4__default.default(options, {
|
|
1727
|
+
mode: this.config.output.mode
|
|
1728
|
+
}));
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Resolves a builtin virtual file and writes it to the VFS if it does not already exist
|
|
1732
|
+
*
|
|
1733
|
+
* @param code - The source code of the builtin file
|
|
1734
|
+
* @param id - The unique identifier of the builtin file
|
|
1735
|
+
* @param path - An optional path to write the builtin file to
|
|
1736
|
+
* @param options - Optional write file options
|
|
1737
|
+
*/
|
|
1738
|
+
async writeBuiltin(code, id, path, options = {}) {
|
|
1739
|
+
return this.fs.writeFile(path ? isType.isAbsolute(path) ? path : join.joinPaths(this.builtinsPath, path) : append.appendPath(id, this.builtinsPath), {
|
|
1740
|
+
id,
|
|
1741
|
+
code,
|
|
1742
|
+
variant: "builtin"
|
|
1743
|
+
}, defu4__default.default(options, {
|
|
1744
|
+
mode: this.config.output.mode
|
|
1745
|
+
}));
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1764
1748
|
* Parses the source code and returns a {@link ParseResult} object.
|
|
1765
1749
|
*
|
|
1766
1750
|
* @param code - The source code to parse.
|
|
@@ -1769,12 +1753,31 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1769
1753
|
* @returns The parsed {@link ParseResult} object.
|
|
1770
1754
|
*/
|
|
1771
1755
|
async parse(code, id, options = {}) {
|
|
1772
|
-
|
|
1756
|
+
if (parseCache.has({
|
|
1757
|
+
code,
|
|
1758
|
+
options
|
|
1759
|
+
})) {
|
|
1760
|
+
return parseCache.get({
|
|
1761
|
+
code,
|
|
1762
|
+
options
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
const result = await oxcParser.parseAsync(id, code, defu4__default.default(options ?? {}, {
|
|
1773
1766
|
lang: filePathFns.hasFileExtension(id) ? void 0 : "ts",
|
|
1774
1767
|
astType: filePathFns.hasFileExtension(id) ? void 0 : "ts",
|
|
1775
1768
|
sourceType: "module",
|
|
1776
1769
|
showSemanticErrors: false
|
|
1777
1770
|
}));
|
|
1771
|
+
if (result.errors && result.errors.length > 0) {
|
|
1772
|
+
throw new Error(`Powerlines parsing errors in file: ${id}
|
|
1773
|
+
${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.codeframe ? ` (${error.codeframe})` : ""}${error.helpMessage ? `
|
|
1774
|
+
Help: ${error.helpMessage}` : ""}`).join("\n")}`);
|
|
1775
|
+
}
|
|
1776
|
+
parseCache.set({
|
|
1777
|
+
code,
|
|
1778
|
+
options
|
|
1779
|
+
}, result);
|
|
1780
|
+
return result;
|
|
1778
1781
|
}
|
|
1779
1782
|
/**
|
|
1780
1783
|
* Update the context using a new user configuration options
|
|
@@ -1863,8 +1866,8 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1863
1866
|
configFile: config.configFile ?? this.config.configFile,
|
|
1864
1867
|
command: this.config.inlineConfig?.command
|
|
1865
1868
|
};
|
|
1866
|
-
if (
|
|
1867
|
-
const result =
|
|
1869
|
+
if (configCache.has(cacheKey)) {
|
|
1870
|
+
const result = configCache.get(cacheKey);
|
|
1868
1871
|
this.projectJson = result.projectJson;
|
|
1869
1872
|
this.packageJson = result.packageJson;
|
|
1870
1873
|
this.#checksum = result.checksum;
|
|
@@ -1879,7 +1882,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1879
1882
|
if (exists.existsSync(packageJsonPath)) {
|
|
1880
1883
|
this.packageJson = await json.readJsonFile(packageJsonPath);
|
|
1881
1884
|
}
|
|
1882
|
-
this.#checksum = await
|
|
1885
|
+
this.#checksum = await chunk4UWZOCEA_js.getChecksum(cacheKey.projectRoot);
|
|
1883
1886
|
this.resolver = createResolver({
|
|
1884
1887
|
workspaceRoot: this.workspaceConfig.workspaceRoot,
|
|
1885
1888
|
projectRoot: cacheKey.projectRoot,
|
|
@@ -1887,9 +1890,9 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1887
1890
|
mode: cacheKey.mode,
|
|
1888
1891
|
skipCache: cacheKey.skipCache
|
|
1889
1892
|
});
|
|
1890
|
-
const userConfig = await
|
|
1893
|
+
const userConfig = await chunk4UWZOCEA_js.loadUserConfigFile(cacheKey.projectRoot, this.resolver, cacheKey.command, cacheKey.mode, cacheKey.configFile);
|
|
1891
1894
|
this.mergeUserConfig(userConfig.config);
|
|
1892
|
-
|
|
1895
|
+
configCache.set(cacheKey, {
|
|
1893
1896
|
projectJson: this.projectJson,
|
|
1894
1897
|
packageJson: this.packageJson,
|
|
1895
1898
|
checksum: this.#checksum,
|
|
@@ -2251,7 +2254,7 @@ var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext
|
|
|
2251
2254
|
* @returns A promise that resolves to the new context.
|
|
2252
2255
|
*/
|
|
2253
2256
|
static async from(workspaceRoot, config) {
|
|
2254
|
-
const context = new _PowerlinesAPIContext(await
|
|
2257
|
+
const context = new _PowerlinesAPIContext(await chunk4UWZOCEA_js.loadWorkspaceConfig(workspaceRoot, config.root));
|
|
2255
2258
|
await context.withUserConfig(config);
|
|
2256
2259
|
context.powerlinesPath = await resolve.resolvePackage("powerlines");
|
|
2257
2260
|
if (!context.powerlinesPath) {
|
|
@@ -2343,6 +2346,26 @@ var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext
|
|
|
2343
2346
|
}
|
|
2344
2347
|
}
|
|
2345
2348
|
};
|
|
2349
|
+
function getBaseFileHeader(context) {
|
|
2350
|
+
return `
|
|
2351
|
+
// Generated with ${titleCase.titleCase(context.config.framework)}
|
|
2352
|
+
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
2353
|
+
`;
|
|
2354
|
+
}
|
|
2355
|
+
chunkSHUYVCID_js.__name(getBaseFileHeader, "getBaseFileHeader");
|
|
2356
|
+
function getFileHeader(context, options = {}) {
|
|
2357
|
+
const { directive = null, prettierIgnore = false } = options;
|
|
2358
|
+
return `/* eslint-disable */
|
|
2359
|
+
// biome-ignore lint: disable
|
|
2360
|
+
${prettierIgnore ? `// prettier-ignore` : ""}${directive ? `
|
|
2361
|
+
|
|
2362
|
+
${directive}
|
|
2363
|
+
` : "\n"}
|
|
2364
|
+
${getBaseFileHeader(context)}
|
|
2365
|
+
|
|
2366
|
+
`;
|
|
2367
|
+
}
|
|
2368
|
+
chunkSHUYVCID_js.__name(getFileHeader, "getFileHeader");
|
|
2346
2369
|
function getString(code) {
|
|
2347
2370
|
if (!code) {
|
|
2348
2371
|
return "";
|
|
@@ -2377,7 +2400,7 @@ function resolveModulePath(nodePath, state) {
|
|
|
2377
2400
|
return;
|
|
2378
2401
|
}
|
|
2379
2402
|
const sourcePath = nodePath.node.value;
|
|
2380
|
-
const resolvedPath = state.context?.fs.
|
|
2403
|
+
const resolvedPath = state.context?.fs.resolve(sourcePath);
|
|
2381
2404
|
if (resolvedPath) {
|
|
2382
2405
|
nodePath.replaceWith(t__namespace.stringLiteral(
|
|
2383
2406
|
// Remove the file extension if it exists
|
|
@@ -2478,8 +2501,9 @@ var moduleResolverBabelPlugin = /* @__PURE__ */ chunkSHUYVCID_js.__name((context
|
|
|
2478
2501
|
async function generateTypes(context) {
|
|
2479
2502
|
context.log(types.LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
|
|
2480
2503
|
context.log(types.LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
|
|
2481
|
-
const builtinFiles = await
|
|
2482
|
-
|
|
2504
|
+
const builtinFiles = await context.getBuiltins();
|
|
2505
|
+
const builtinFilePaths = await Promise.all(builtinFiles.map(async (file) => {
|
|
2506
|
+
const result = await core.transformAsync(file.code.toString(), {
|
|
2483
2507
|
highlightCode: true,
|
|
2484
2508
|
code: true,
|
|
2485
2509
|
ast: false,
|
|
@@ -2507,14 +2531,14 @@ async function generateTypes(context) {
|
|
|
2507
2531
|
throw new Error(`Powerlines - Generate Types failed to compile ${file.id}`);
|
|
2508
2532
|
}
|
|
2509
2533
|
context.log(types.LogLevelLabel.TRACE, `Writing transformed built-in runtime file ${file.id}.`);
|
|
2510
|
-
await context.
|
|
2534
|
+
await context.writeBuiltin(result.code, file.id, file.path);
|
|
2511
2535
|
return file.path;
|
|
2512
2536
|
}));
|
|
2513
2537
|
const typescriptPath = await resolve.resolvePackage("typescript");
|
|
2514
2538
|
if (!typescriptPath) {
|
|
2515
2539
|
throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
|
|
2516
2540
|
}
|
|
2517
|
-
const files =
|
|
2541
|
+
const files = builtinFilePaths.reduce((ret, fileName) => {
|
|
2518
2542
|
const formatted = replace.replacePath(fileName, context.workspaceConfig.workspaceRoot);
|
|
2519
2543
|
if (!ret.includes(formatted)) {
|
|
2520
2544
|
ret.push(formatted);
|
|
@@ -2549,9 +2573,9 @@ async function generateTypes(context) {
|
|
|
2549
2573
|
const emitResult = program.emit(void 0, (fileName, text, _, __, sourceFiles, _data) => {
|
|
2550
2574
|
const sourceFile2 = sourceFiles?.[0];
|
|
2551
2575
|
if (sourceFile2?.fileName && !fileName.endsWith(".map")) {
|
|
2552
|
-
if (
|
|
2576
|
+
if (builtinFiles.some((file) => file.id === sourceFile2.fileName || file.path === sourceFile2.fileName)) {
|
|
2553
2577
|
builtinModules += `
|
|
2554
|
-
declare module "${context.fs.
|
|
2578
|
+
declare module "${context.fs.resolve(sourceFile2.fileName)}" {
|
|
2555
2579
|
${text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
|
|
2556
2580
|
}
|
|
2557
2581
|
`;
|
|
@@ -2590,7 +2614,9 @@ ${builtinModules}`.replace(
|
|
|
2590
2614
|
/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g,
|
|
2591
2615
|
""
|
|
2592
2616
|
).replaceAll("#private;", "").replace(/__Ω/g, ""));
|
|
2593
|
-
await context.fs.
|
|
2617
|
+
await context.fs.writeFile(sourceFile.id, getString(sourceFile.code), {
|
|
2618
|
+
mode: "fs"
|
|
2619
|
+
});
|
|
2594
2620
|
}
|
|
2595
2621
|
chunkSHUYVCID_js.__name(generateTypes, "generateTypes");
|
|
2596
2622
|
async function installPackage(context, packageName, dev = false) {
|
|
@@ -2754,7 +2780,9 @@ async function initializeTsconfig(context) {
|
|
|
2754
2780
|
const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
2755
2781
|
context.tsconfig.originalTsconfigJson = await json.readJsonFile(tsconfigFilePath);
|
|
2756
2782
|
context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
|
|
2757
|
-
await context.fs.
|
|
2783
|
+
await context.fs.writeFile(tsconfigFilePath, stormJson.StormJSON.stringify(context.tsconfig.tsconfigJson), {
|
|
2784
|
+
mode: "fs"
|
|
2785
|
+
});
|
|
2758
2786
|
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
|
|
2759
2787
|
}
|
|
2760
2788
|
chunkSHUYVCID_js.__name(initializeTsconfig, "initializeTsconfig");
|
|
@@ -2878,8 +2906,8 @@ ${context.entry.map((entry) => `- ${entry.input.file || entry.file}${entry.outpu
|
|
|
2878
2906
|
context.log(types.LogLevelLabel.TRACE, `Powerlines configuration has been resolved:
|
|
2879
2907
|
|
|
2880
2908
|
${console.formatLogMessage(context.config)}`);
|
|
2881
|
-
context.fs[
|
|
2882
|
-
await
|
|
2909
|
+
context.fs[chunk4UWZOCEA_js.__VFS_INIT__]();
|
|
2910
|
+
await chunk4UWZOCEA_js.writeMetaFile(context);
|
|
2883
2911
|
context.persistedMeta = context.meta;
|
|
2884
2912
|
if (!exists.existsSync(context.cachePath)) {
|
|
2885
2913
|
await helpers.createDirectory(context.cachePath);
|
|
@@ -2890,11 +2918,6 @@ ${console.formatLogMessage(context.config)}`);
|
|
|
2890
2918
|
await this.callPreHook(context, "prepare");
|
|
2891
2919
|
if (context.config.projectType === "application") {
|
|
2892
2920
|
context.log(types.LogLevelLabel.TRACE, "Generating built-in barrel file");
|
|
2893
|
-
await context.fs.writeBuiltinFile("index", joinPaths.joinPaths(context.builtinsPath, "index.ts"), `
|
|
2894
|
-
${getFileHeader(context)}
|
|
2895
|
-
|
|
2896
|
-
${(await context.fs.listBuiltinFiles()).filter((file) => !isParentPath.isParentPath(file.path, joinPaths.joinPaths(context.builtinsPath, "log")) && !isParentPath.isParentPath(file.path, joinPaths.joinPaths(context.builtinsPath, "storage"))).map((file) => `export * from "./${replace.replacePath(file.path, context.builtinsPath).replace(`.${filePathFns.findFileExtensionSafe(file.path)}`, "")}";`).join("\n")}
|
|
2897
|
-
`);
|
|
2898
2921
|
}
|
|
2899
2922
|
if (context.config.output.dts !== false) {
|
|
2900
2923
|
await generateTypes(context);
|
|
@@ -2905,8 +2928,8 @@ ${console.formatLogMessage(context.config)}`);
|
|
|
2905
2928
|
throw new Error("Failed to parse the TypeScript configuration file.");
|
|
2906
2929
|
}
|
|
2907
2930
|
await this.callPostHook(context, "prepare");
|
|
2908
|
-
await
|
|
2909
|
-
context.fs[
|
|
2931
|
+
await chunk4UWZOCEA_js.writeMetaFile(context);
|
|
2932
|
+
context.fs[chunk4UWZOCEA_js.__VFS_REVERT__]();
|
|
2910
2933
|
});
|
|
2911
2934
|
this.context.log(types.LogLevelLabel.INFO, "Powerlines API has been prepared successfully");
|
|
2912
2935
|
}
|
|
@@ -3065,7 +3088,7 @@ ${console.formatLogMessage(context.config)}`);
|
|
|
3065
3088
|
this.context.log(types.LogLevelLabel.TRACE, "Powerlines finalize execution started");
|
|
3066
3089
|
await this.#executeEnvironments(async (context) => {
|
|
3067
3090
|
await this.callHook(context, "finalize");
|
|
3068
|
-
context.fs[
|
|
3091
|
+
context.fs[chunk4UWZOCEA_js.__VFS_REVERT__]();
|
|
3069
3092
|
});
|
|
3070
3093
|
this.context.log(types.LogLevelLabel.TRACE, "Powerlines finalize execution completed");
|
|
3071
3094
|
}
|
|
@@ -3338,8 +3361,8 @@ var DEFAULT_ESBUILD_CONFIG = {
|
|
|
3338
3361
|
};
|
|
3339
3362
|
function extractESBuildConfig(context) {
|
|
3340
3363
|
return defu4__default.default({
|
|
3341
|
-
alias: context.
|
|
3342
|
-
const path = context.fs.
|
|
3364
|
+
alias: context.builtins.reduce((ret, id) => {
|
|
3365
|
+
const path = context.fs.ids[id];
|
|
3343
3366
|
if (path) {
|
|
3344
3367
|
ret[id] = path;
|
|
3345
3368
|
}
|
|
@@ -3382,8 +3405,8 @@ var DEFAULT_VITE_CONFIG = {
|
|
|
3382
3405
|
function extractViteConfig(context) {
|
|
3383
3406
|
return defu4__default.default({
|
|
3384
3407
|
resolve: {
|
|
3385
|
-
alias: context.
|
|
3386
|
-
const path = context.fs.
|
|
3408
|
+
alias: context.builtins.reduce((ret, id) => {
|
|
3409
|
+
const path = context.fs.ids[id];
|
|
3387
3410
|
if (path) {
|
|
3388
3411
|
ret[id] = path;
|
|
3389
3412
|
}
|
|
@@ -3407,7 +3430,7 @@ function extractViteConfig(context) {
|
|
|
3407
3430
|
esbuild: extractESBuildConfig(context),
|
|
3408
3431
|
logLevel: context.config.logLevel ?? void 0,
|
|
3409
3432
|
envDir: context.config.projectRoot,
|
|
3410
|
-
noExternal:
|
|
3433
|
+
noExternal: context.builtins
|
|
3411
3434
|
}, context.config.build.variant === "vite" ? context.config.build : {}, {
|
|
3412
3435
|
build: {
|
|
3413
3436
|
minify: context.config.mode !== "development",
|
|
@@ -3420,16 +3443,16 @@ chunkSHUYVCID_js.__name(extractViteConfig, "extractViteConfig");
|
|
|
3420
3443
|
var NON_NODE_MODULE_REGEX = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
|
|
3421
3444
|
async function handleResolveId(context, args, options = {}) {
|
|
3422
3445
|
if (args.id) {
|
|
3423
|
-
if (context.fs.
|
|
3446
|
+
if (context.fs.isVirtual(args.id) || args.importer && context.fs.isVirtual(args.id, {
|
|
3424
3447
|
paths: [
|
|
3425
3448
|
args.importer
|
|
3426
3449
|
]
|
|
3427
3450
|
})) {
|
|
3428
|
-
const resolvedPath = args.importer ? context.fs.
|
|
3451
|
+
const resolvedPath = args.importer ? context.fs.resolve(args.id, {
|
|
3429
3452
|
paths: [
|
|
3430
3453
|
args.importer
|
|
3431
3454
|
]
|
|
3432
|
-
}) : context.fs.
|
|
3455
|
+
}) : context.fs.resolve(args.id);
|
|
3433
3456
|
if (resolvedPath) {
|
|
3434
3457
|
return {
|
|
3435
3458
|
id: resolvedPath,
|
|
@@ -3467,11 +3490,12 @@ async function handleResolveId(context, args, options = {}) {
|
|
|
3467
3490
|
};
|
|
3468
3491
|
}
|
|
3469
3492
|
} else {
|
|
3470
|
-
|
|
3471
|
-
paths: [
|
|
3493
|
+
const resolvedPath = context.fs.resolve(args.id, {
|
|
3494
|
+
paths: args.importer ? [
|
|
3472
3495
|
args.importer
|
|
3473
|
-
]
|
|
3474
|
-
})
|
|
3496
|
+
] : []
|
|
3497
|
+
});
|
|
3498
|
+
if (bundleRequire.match(args.id, options.noExternal) || resolvedPath && context.fs.meta[resolvedPath]?.variant === "builtin") {
|
|
3475
3499
|
return void 0;
|
|
3476
3500
|
}
|
|
3477
3501
|
if (bundleRequire.match(args.id, options.external) || args.id.startsWith("node:")) {
|
|
@@ -3530,9 +3554,7 @@ function createUnpluginFactory(variant, decorate) {
|
|
|
3530
3554
|
async function load(id) {
|
|
3531
3555
|
const environment = await api.context.getEnvironment();
|
|
3532
3556
|
if (id) {
|
|
3533
|
-
const resolvedPath = environment.fs.
|
|
3534
|
-
type: "file"
|
|
3535
|
-
});
|
|
3557
|
+
const resolvedPath = environment.fs.resolve(id);
|
|
3536
3558
|
if (resolvedPath) {
|
|
3537
3559
|
return environment.fs.readFile(resolvedPath);
|
|
3538
3560
|
}
|