@powerlines/nx 0.8.1 → 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 +11 -0
- package/dist/{chunk-HHPODCTP.js → chunk-4UWZOCEA.js} +6 -4
- package/dist/{chunk-SEKRZM2M.mjs → chunk-A6R3IFS4.mjs} +1 -1
- package/dist/{chunk-ZN4SPOFK.mjs → chunk-AEUGK5NW.mjs} +1 -1
- package/dist/{chunk-LB2WKEBP.js → chunk-DYBB74M5.js} +2 -2
- package/dist/{chunk-22QO45EK.mjs → chunk-FFBOHADM.mjs} +1 -1
- package/dist/{chunk-SMAXXYNQ.js → chunk-GBMB632G.js} +2 -2
- package/dist/{chunk-6ZIN2CAX.js → chunk-HGVVLZRZ.js} +2 -2
- package/dist/{chunk-Z4BJ37JY.js → chunk-IFMXBBI7.js} +3 -3
- package/dist/{chunk-5XZZZSXP.mjs → chunk-KXYDHGLW.mjs} +1 -1
- package/dist/{chunk-VDJPCGIO.mjs → chunk-KZPEAPED.mjs} +528 -526
- package/dist/{chunk-RDBAXMH3.js → chunk-MUKKEYV2.js} +2 -2
- package/dist/{chunk-5BGY6YWV.mjs → chunk-R5YABITA.mjs} +1 -1
- package/dist/{chunk-CYWOTYVX.mjs → chunk-SV7QXBCB.mjs} +6 -4
- package/dist/{chunk-DBX2Y6G3.mjs → chunk-VGG6K4L5.mjs} +1 -1
- package/dist/{chunk-OYUWBYK7.js → chunk-XTPTXR6Y.js} +546 -544
- package/dist/{chunk-DGAY3PM7.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,4 +1,4 @@
|
|
|
1
|
-
import { __VFS_CACHE__, __VFS_RESOLVER__, __VFS_VIRTUAL__, __VFS_UNIFIED__, __VFS_INIT__, __VFS_REVERT__, loadWorkspaceConfig, CACHE_HASH_LENGTH, PROJECT_ROOT_HASH_LENGTH, getPrefixedProjectRootHash, getChecksum, loadUserConfigFile, writeMetaFile } from './chunk-
|
|
1
|
+
import { __VFS_CACHE__, __VFS_RESOLVER__, __VFS_VIRTUAL__, __VFS_UNIFIED__, __VFS_INIT__, __VFS_REVERT__, loadWorkspaceConfig, CACHE_HASH_LENGTH, PROJECT_ROOT_HASH_LENGTH, getPrefixedProjectRootHash, getChecksum, loadUserConfigFile, writeMetaFile } from './chunk-SV7QXBCB.mjs';
|
|
2
2
|
import { __name } from './chunk-O6YSETKJ.mjs';
|
|
3
3
|
import { getLogFn, getLogLevel, writeError } from '@storm-software/config-tools/logger';
|
|
4
4
|
import { withRunExecutor } from '@storm-software/workspace-tools/base/base-executor';
|
|
@@ -13,8 +13,6 @@ import { createDirectory } from '@stryke/fs/helpers';
|
|
|
13
13
|
import { install } from '@stryke/fs/install';
|
|
14
14
|
import { listFiles, listFilesSync } from '@stryke/fs/list-files';
|
|
15
15
|
import { isPackageExists, isPackageListed, doesPackageMatch, getPackageListing } from '@stryke/fs/package-fns';
|
|
16
|
-
import { findFilePath, hasFileExtension, findFileExtensionSafe, relativePath, findFileName } from '@stryke/path/file-path-fns';
|
|
17
|
-
import { isParentPath } from '@stryke/path/is-parent-path';
|
|
18
16
|
import { joinPaths } from '@stryke/path/join-paths';
|
|
19
17
|
import { replacePath } from '@stryke/path/replace';
|
|
20
18
|
import { isFunction } from '@stryke/type-checks/is-function';
|
|
@@ -28,16 +26,18 @@ import Handlebars from 'handlebars';
|
|
|
28
26
|
import { readJsonFile, readJsonFileSync } from '@stryke/fs/json';
|
|
29
27
|
import { appendPath } from '@stryke/path/append';
|
|
30
28
|
import ts2, { createProgram, createCompilerHost, getPreEmitDiagnostics, getLineAndCharacterOfPosition, flattenDiagnosticMessageText } from 'typescript';
|
|
31
|
-
import { titleCase } from '@stryke/string-format/title-case';
|
|
32
29
|
import { isUndefined } from '@stryke/type-checks/is-undefined';
|
|
33
30
|
import { writeFile as writeFile$1 } from '@stryke/fs/write-file';
|
|
34
|
-
import {
|
|
31
|
+
import { resolveConfig, format } from 'prettier';
|
|
35
32
|
import { resolvePackage } from '@stryke/fs/resolve';
|
|
33
|
+
import { titleCase } from '@stryke/string-format/title-case';
|
|
36
34
|
import { getEnvPaths } from '@stryke/env/get-env-paths';
|
|
37
35
|
import { relativeToWorkspaceRoot, getWorkspaceRoot } from '@stryke/fs/get-workspace-root';
|
|
38
36
|
import { murmurhash } from '@stryke/hash/murmurhash';
|
|
39
37
|
import { getUnique, getUniqueBy } from '@stryke/helpers/get-unique';
|
|
40
38
|
import { omit } from '@stryke/helpers/omit';
|
|
39
|
+
import { findFilePath, findFileExtensionSafe, hasFileExtension, relativePath, findFileName } from '@stryke/path/file-path-fns';
|
|
40
|
+
import { isAbsolutePath, isAbsolute } from '@stryke/path/is-type';
|
|
41
41
|
import { joinPaths as joinPaths$1 } from '@stryke/path/join';
|
|
42
42
|
import { isNull } from '@stryke/type-checks/is-null';
|
|
43
43
|
import { isString } from '@stryke/type-checks/is-string';
|
|
@@ -48,7 +48,7 @@ import { getColor } from '@storm-software/config-tools/utilities/colors';
|
|
|
48
48
|
import { noop } from '@stryke/helpers/noop';
|
|
49
49
|
import { createJiti } from 'jiti';
|
|
50
50
|
import { bufferToString } from '@stryke/convert/buffer-to-string';
|
|
51
|
-
import {
|
|
51
|
+
import { isParentPath } from '@stryke/path/is-parent-path';
|
|
52
52
|
import { prettyBytes } from '@stryke/string-format/pretty-bytes';
|
|
53
53
|
import { isBuffer } from '@stryke/type-checks/is-buffer';
|
|
54
54
|
import { Volume } from 'memfs';
|
|
@@ -153,26 +153,6 @@ ${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && err
|
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
__name(getParsedTypeScriptConfig, "getParsedTypeScriptConfig");
|
|
156
|
-
function getBaseFileHeader(context) {
|
|
157
|
-
return `
|
|
158
|
-
// Generated with ${titleCase(context.config.framework)}
|
|
159
|
-
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
160
|
-
`;
|
|
161
|
-
}
|
|
162
|
-
__name(getBaseFileHeader, "getBaseFileHeader");
|
|
163
|
-
function getFileHeader(context, options = {}) {
|
|
164
|
-
const { directive = null, prettierIgnore = false } = options;
|
|
165
|
-
return `/* eslint-disable */
|
|
166
|
-
// biome-ignore lint: disable
|
|
167
|
-
${prettierIgnore ? `// prettier-ignore` : ""}${directive ? `
|
|
168
|
-
|
|
169
|
-
${directive}
|
|
170
|
-
` : "\n"}
|
|
171
|
-
${getBaseFileHeader(context)}
|
|
172
|
-
|
|
173
|
-
`;
|
|
174
|
-
}
|
|
175
|
-
__name(getFileHeader, "getFileHeader");
|
|
176
156
|
|
|
177
157
|
// ../powerlines/src/types/commands.ts
|
|
178
158
|
var SUPPORTED_COMMANDS = [
|
|
@@ -402,6 +382,154 @@ function createResolver(options) {
|
|
|
402
382
|
return baseResolver;
|
|
403
383
|
}
|
|
404
384
|
__name(createResolver, "createResolver");
|
|
385
|
+
function isBufferEncoding(options) {
|
|
386
|
+
return isSetString(options) || options === null;
|
|
387
|
+
}
|
|
388
|
+
__name(isBufferEncoding, "isBufferEncoding");
|
|
389
|
+
function isPowerlinesWriteFileOptions(options) {
|
|
390
|
+
return !isBufferEncoding(options) && isSetObject(options) && ("skipFormat" in options || "mode" in options && (options.mode === "fs" || options.mode === "virtual"));
|
|
391
|
+
}
|
|
392
|
+
__name(isPowerlinesWriteFileOptions, "isPowerlinesWriteFileOptions");
|
|
393
|
+
function isNodeWriteFileOptions(options) {
|
|
394
|
+
return !isUndefined(options) && (isBufferEncoding(options) || !isPowerlinesWriteFileOptions(options));
|
|
395
|
+
}
|
|
396
|
+
__name(isNodeWriteFileOptions, "isNodeWriteFileOptions");
|
|
397
|
+
function isPowerLinesWriteFileData(data) {
|
|
398
|
+
return !!(isSetObject(data) && "code" in data && data.code);
|
|
399
|
+
}
|
|
400
|
+
__name(isPowerLinesWriteFileData, "isPowerLinesWriteFileData");
|
|
401
|
+
var FILE_PREFIX = "file://";
|
|
402
|
+
function toFilePath(pathOrUrl) {
|
|
403
|
+
if (!pathOrUrl) {
|
|
404
|
+
throw new Error("No Path or URL provided to Virtual File System");
|
|
405
|
+
}
|
|
406
|
+
let result = pathOrUrl.toString();
|
|
407
|
+
if (result.startsWith(FILE_PREFIX)) {
|
|
408
|
+
result = result.slice(FILE_PREFIX.length);
|
|
409
|
+
}
|
|
410
|
+
return result;
|
|
411
|
+
}
|
|
412
|
+
__name(toFilePath, "toFilePath");
|
|
413
|
+
var FS_METHODS = [
|
|
414
|
+
"mkdir",
|
|
415
|
+
"mkdirSync",
|
|
416
|
+
"rmdir",
|
|
417
|
+
"rmdirSync",
|
|
418
|
+
"unlink",
|
|
419
|
+
"unlinkSync",
|
|
420
|
+
"existsSync",
|
|
421
|
+
"realpathSync",
|
|
422
|
+
"writeFileSync",
|
|
423
|
+
"readFileSync",
|
|
424
|
+
"readdirSync",
|
|
425
|
+
"createWriteStream",
|
|
426
|
+
"WriteStream",
|
|
427
|
+
"createReadStream",
|
|
428
|
+
"ReadStream"
|
|
429
|
+
];
|
|
430
|
+
var FS_PROMISE_METHODS = [
|
|
431
|
+
"mkdir",
|
|
432
|
+
"rm",
|
|
433
|
+
"rmdir",
|
|
434
|
+
"unlink",
|
|
435
|
+
"writeFile",
|
|
436
|
+
"readFile",
|
|
437
|
+
"readdir",
|
|
438
|
+
"stat",
|
|
439
|
+
"lstat"
|
|
440
|
+
];
|
|
441
|
+
function cloneFS(originalFS) {
|
|
442
|
+
const clonedFS = {
|
|
443
|
+
...originalFS,
|
|
444
|
+
promises: {
|
|
445
|
+
...originalFS.promises ?? {}
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
for (const method of FS_METHODS) {
|
|
449
|
+
if (originalFS[method]) {
|
|
450
|
+
clonedFS[method] = originalFS[method];
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
originalFS.promises ??= {};
|
|
454
|
+
for (const method of FS_PROMISE_METHODS) {
|
|
455
|
+
if (originalFS.promises[method]) {
|
|
456
|
+
clonedFS.promises ??= {};
|
|
457
|
+
clonedFS.promises[method] = originalFS.promises[method];
|
|
458
|
+
clonedFS[method] = originalFS.promises[method];
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
for (const prop in clonedFS) {
|
|
462
|
+
if (isFunction(clonedFS[prop])) {
|
|
463
|
+
clonedFS[prop] = clonedFS[prop].bind(originalFS);
|
|
464
|
+
if (isFunction(clonedFS.promises[prop])) {
|
|
465
|
+
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
for (const prop in clonedFS.promises) {
|
|
470
|
+
if (isFunction(clonedFS.promises[prop])) {
|
|
471
|
+
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return clonedFS;
|
|
475
|
+
}
|
|
476
|
+
__name(cloneFS, "cloneFS");
|
|
477
|
+
function patchFS(originalFS, vfs) {
|
|
478
|
+
const clonedFS = cloneFS(originalFS);
|
|
479
|
+
originalFS.mkdirSync = (file, options) => vfs.mkdirSync(toFilePath(file), options);
|
|
480
|
+
originalFS.mkdir = (file, options, callback) => vfs.mkdir(toFilePath(file), options, callback);
|
|
481
|
+
originalFS.promises.mkdir = async (file, options) => vfs.mkdir(toFilePath(file), options);
|
|
482
|
+
originalFS.unlinkSync = (file) => vfs.unlinkSync(toFilePath(file));
|
|
483
|
+
originalFS.promises.rm = async (file, options) => vfs.rm(toFilePath(file), options);
|
|
484
|
+
originalFS.promises.unlink = async (file) => vfs.unlink(toFilePath(file));
|
|
485
|
+
originalFS.existsSync = (file) => vfs.existsSync(toFilePath(file));
|
|
486
|
+
Object.defineProperty(originalFS, "realpathSync", {
|
|
487
|
+
value: /* @__PURE__ */ __name((file, options) => vfs.realpathSync(toFilePath(file), options), "value")
|
|
488
|
+
});
|
|
489
|
+
originalFS.writeFileSync = (file, data, options) => vfs.writeFileSync(toFilePath(file), data, options);
|
|
490
|
+
originalFS.promises.writeFile = async (file, data, options) => vfs.writeFile(toFilePath(file), data, options);
|
|
491
|
+
originalFS.readFileSync = (file, options) => vfs.readFileSync(toFilePath(file), options);
|
|
492
|
+
originalFS.promises.readFile = (file, options) => vfs.readFile(toFilePath(file), options);
|
|
493
|
+
originalFS.readdirSync = (file, options) => vfs.readdirSync(toFilePath(file), options);
|
|
494
|
+
originalFS.promises.readdir = (file, options) => vfs.readdir(toFilePath(file), options);
|
|
495
|
+
Object.defineProperty(originalFS, "statSync", {
|
|
496
|
+
value: /* @__PURE__ */ __name((file, options) => vfs.statSync(toFilePath(file), options), "value")
|
|
497
|
+
});
|
|
498
|
+
originalFS.stat = (file, options) => vfs.statSync(toFilePath(file), options);
|
|
499
|
+
originalFS.promises.stat = (file, options) => vfs.stat(toFilePath(file), options);
|
|
500
|
+
Object.defineProperty(originalFS, "lstatSync", {
|
|
501
|
+
value: /* @__PURE__ */ __name((file, options) => vfs.lstatSync(toFilePath(file), options), "value")
|
|
502
|
+
});
|
|
503
|
+
originalFS.lstat = (file, options) => vfs.lstatSync(toFilePath(file), options);
|
|
504
|
+
originalFS.promises.lstat = (file, options) => vfs.lstat(toFilePath(file), options);
|
|
505
|
+
return () => {
|
|
506
|
+
originalFS.mkdirSync = clonedFS.mkdirSync;
|
|
507
|
+
originalFS.mkdir = clonedFS.mkdir;
|
|
508
|
+
originalFS.promises.mkdir = clonedFS.promises.mkdir;
|
|
509
|
+
originalFS.unlinkSync = clonedFS.unlinkSync;
|
|
510
|
+
originalFS.promises.rm = clonedFS.promises.rm;
|
|
511
|
+
originalFS.promises.unlink = clonedFS.promises.unlink;
|
|
512
|
+
originalFS.existsSync = clonedFS.existsSync;
|
|
513
|
+
originalFS.realpathSync = clonedFS.realpathSync;
|
|
514
|
+
originalFS.writeFileSync = clonedFS.writeFileSync;
|
|
515
|
+
originalFS.promises.writeFile = clonedFS.promises.writeFile;
|
|
516
|
+
originalFS.readFileSync = clonedFS.readFileSync;
|
|
517
|
+
originalFS.promises.readFile = clonedFS.promises.readFile;
|
|
518
|
+
originalFS.readdirSync = clonedFS.readdirSync;
|
|
519
|
+
originalFS.promises.readdir = clonedFS.promises.readdir;
|
|
520
|
+
Object.defineProperty(originalFS, "statSync", {
|
|
521
|
+
value: clonedFS.statSync
|
|
522
|
+
});
|
|
523
|
+
originalFS.stat = clonedFS.stat;
|
|
524
|
+
originalFS.promises.stat = clonedFS.promises.stat;
|
|
525
|
+
Object.defineProperty(originalFS, "lstatSync", {
|
|
526
|
+
value: clonedFS.lstatSync
|
|
527
|
+
});
|
|
528
|
+
originalFS.lstat = clonedFS.lstat;
|
|
529
|
+
originalFS.promises.lstat = clonedFS.promises.lstat;
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
__name(patchFS, "patchFS");
|
|
405
533
|
var VirtualFileSystem = class {
|
|
406
534
|
static {
|
|
407
535
|
__name(this, "VirtualFileSystem");
|
|
@@ -409,7 +537,11 @@ var VirtualFileSystem = class {
|
|
|
409
537
|
/**
|
|
410
538
|
* The internal map of virtual files.
|
|
411
539
|
*/
|
|
412
|
-
#
|
|
540
|
+
#meta = {};
|
|
541
|
+
/**
|
|
542
|
+
* A map of unique identifiers to their virtual file paths.
|
|
543
|
+
*/
|
|
544
|
+
#ids = {};
|
|
413
545
|
/**
|
|
414
546
|
* A map of virtual file paths to their underlying file content.
|
|
415
547
|
*/
|
|
@@ -450,6 +582,16 @@ var VirtualFileSystem = class {
|
|
|
450
582
|
*/
|
|
451
583
|
#log;
|
|
452
584
|
/**
|
|
585
|
+
* Checks if a path exists in the virtual file system (VFS).
|
|
586
|
+
*
|
|
587
|
+
* @param path - The path to check.
|
|
588
|
+
* @returns `true` if the path exists, otherwise `false`.
|
|
589
|
+
*/
|
|
590
|
+
#existsSync(path) {
|
|
591
|
+
const formattedPath = this.formatPath(path);
|
|
592
|
+
return this.#virtualFS.existsSync(formattedPath) || this.#fs.existsSync(formattedPath) || this.resolveFS(path).existsSync(formattedPath);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
453
595
|
* Exposes the internal VFS map for advanced usage.
|
|
454
596
|
*/
|
|
455
597
|
get [__VFS_CACHE__]() {
|
|
@@ -474,15 +616,54 @@ var VirtualFileSystem = class {
|
|
|
474
616
|
return this.#unifiedFS;
|
|
475
617
|
}
|
|
476
618
|
/**
|
|
619
|
+
* A proxy to access the underlying file metadata.
|
|
620
|
+
*/
|
|
621
|
+
get meta() {
|
|
622
|
+
return new Proxy(this.#meta, {
|
|
623
|
+
get: /* @__PURE__ */ __name((target, prop) => {
|
|
624
|
+
if (target[prop]) {
|
|
625
|
+
return {
|
|
626
|
+
id: prop,
|
|
627
|
+
mode: this.#virtualFS.existsSync(prop) ? "virtual" : this.#fs.existsSync(prop) ? "fs" : this.#context.config.output.mode,
|
|
628
|
+
details: {},
|
|
629
|
+
variant: "normal",
|
|
630
|
+
...target[prop]
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
return void 0;
|
|
634
|
+
}, "get"),
|
|
635
|
+
set: /* @__PURE__ */ __name((target, prop, value) => {
|
|
636
|
+
target[prop] = value;
|
|
637
|
+
this.#ids[value.id || prop] = prop;
|
|
638
|
+
return true;
|
|
639
|
+
}, "set"),
|
|
640
|
+
deleteProperty: /* @__PURE__ */ __name((target, prop) => {
|
|
641
|
+
delete this.#ids[target[prop]?.id || prop];
|
|
642
|
+
delete target[prop];
|
|
643
|
+
return true;
|
|
644
|
+
}, "deleteProperty")
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* A map of module ids to their file paths.
|
|
649
|
+
*/
|
|
650
|
+
get ids() {
|
|
651
|
+
return this.#ids;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
477
654
|
* Creates a new instance of the VirtualFileSystem.
|
|
478
655
|
*
|
|
479
656
|
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
480
657
|
* @param serialized - A map of files/file contents to populate in cache
|
|
481
658
|
*/
|
|
482
|
-
constructor(context, serialized) {
|
|
659
|
+
constructor(context, serialized = {}) {
|
|
483
660
|
this.#context = context;
|
|
484
661
|
this.#cachedFS = /* @__PURE__ */ new Map();
|
|
485
|
-
this.#
|
|
662
|
+
this.#meta = Object.fromEntries(Object.entries(serialized.virtualFilesMeta ?? {}));
|
|
663
|
+
this.#ids = Object.fromEntries(Object.entries(this.#meta).map(([path, data]) => [
|
|
664
|
+
data.id || path,
|
|
665
|
+
path
|
|
666
|
+
]));
|
|
486
667
|
if (!this.#fs.existsSync(this.#context.dataPath)) {
|
|
487
668
|
this.#fs.mkdirSync(this.#context.dataPath, {
|
|
488
669
|
recursive: true
|
|
@@ -564,65 +745,44 @@ var VirtualFileSystem = class {
|
|
|
564
745
|
}
|
|
565
746
|
}
|
|
566
747
|
/**
|
|
567
|
-
*
|
|
748
|
+
* Check if a path or id corresponds to a virtual file **(does not actually exists on disk)**.
|
|
568
749
|
*
|
|
569
|
-
* @
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
return this.#builtinIdMap;
|
|
573
|
-
}
|
|
574
|
-
/**
|
|
575
|
-
* Lists all runtime IDs in the virtual file system.
|
|
576
|
-
*
|
|
577
|
-
* @returns An array of formatted runtime IDs.
|
|
578
|
-
*/
|
|
579
|
-
get runtimeIds() {
|
|
580
|
-
return Array.from(this.builtinIdMap.keys()).map((id) => this.formatRuntimeId(id));
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Checks if a given path or ID corresponds to a runtime file.
|
|
584
|
-
*
|
|
585
|
-
* @param pathOrId - The path or ID to check.
|
|
586
|
-
* @param options - Options for resolving the path, such as paths to check.
|
|
587
|
-
* @returns `true` if the path or ID corresponds to a runtime file, otherwise `false`.
|
|
750
|
+
* @param pathOrId - The path or id to check.
|
|
751
|
+
* @param options - Optional parameters for resolving the path.
|
|
752
|
+
* @returns Whether the path or id corresponds to a virtual file **(does not actually exists on disk)**.
|
|
588
753
|
*/
|
|
589
|
-
|
|
590
|
-
|
|
754
|
+
isVirtual(pathOrId, options = {}) {
|
|
755
|
+
if (!pathOrId) {
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
const resolvedPath = this.resolve(pathOrId, {
|
|
591
759
|
...options,
|
|
592
760
|
type: "file"
|
|
593
|
-
})
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
* @param id - The ID to check.
|
|
599
|
-
* @returns Whether the ID is a valid runtime ID.
|
|
600
|
-
*/
|
|
601
|
-
isValidBuiltinId(id) {
|
|
602
|
-
return id.startsWith(`${this.#context.config.output.builtinPrefix}:`);
|
|
761
|
+
});
|
|
762
|
+
if (!resolvedPath) {
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
return this.meta[resolvedPath]?.mode === "virtual";
|
|
603
766
|
}
|
|
604
767
|
/**
|
|
605
|
-
* Check if a path or
|
|
768
|
+
* Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
|
|
606
769
|
*
|
|
607
|
-
* @param pathOrId - The path or
|
|
608
|
-
* @param options -
|
|
609
|
-
* @returns Whether the path or
|
|
770
|
+
* @param pathOrId - The path or id to check.
|
|
771
|
+
* @param options - Optional parameters for resolving the path.
|
|
772
|
+
* @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
|
|
610
773
|
*/
|
|
611
|
-
|
|
774
|
+
isFs(pathOrId, options = {}) {
|
|
612
775
|
if (!pathOrId) {
|
|
613
776
|
return false;
|
|
614
777
|
}
|
|
615
|
-
const resolvedPath = this.
|
|
778
|
+
const resolvedPath = this.resolve(pathOrId, {
|
|
616
779
|
...options,
|
|
617
780
|
type: "file"
|
|
618
781
|
});
|
|
619
782
|
if (!resolvedPath) {
|
|
620
783
|
return false;
|
|
621
784
|
}
|
|
622
|
-
|
|
623
|
-
return true;
|
|
624
|
-
}
|
|
625
|
-
return this.#virtualFS.existsSync(resolvedPath);
|
|
785
|
+
return this.meta[resolvedPath]?.mode === "fs";
|
|
626
786
|
}
|
|
627
787
|
/**
|
|
628
788
|
* Check if a path exists within one of the directories specified in the tsconfig.json's `path` field.
|
|
@@ -636,37 +796,6 @@ var VirtualFileSystem = class {
|
|
|
636
796
|
return !!this.#context.tsconfig.options.paths && Object.keys(this.#context.tsconfig.options.paths).some((path) => pathOrId.startsWith(path.replaceAll("*", "")));
|
|
637
797
|
}
|
|
638
798
|
/**
|
|
639
|
-
* Checks if a given ID corresponds to a runtime file path.
|
|
640
|
-
*
|
|
641
|
-
* @param id - The unique identifier for the runtime file.
|
|
642
|
-
* @param pathOrId - The path or ID to check.
|
|
643
|
-
* @returns `true` if the ID corresponds to the path or ID of a runtime file, otherwise `false`.
|
|
644
|
-
*/
|
|
645
|
-
isMatchingBuiltinId(id, pathOrId) {
|
|
646
|
-
const resolvedPath = this.resolvePath(pathOrId);
|
|
647
|
-
const resolvedId = this.resolveId(pathOrId);
|
|
648
|
-
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)))));
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* Lists all runtime files in the virtual file system.
|
|
652
|
-
*
|
|
653
|
-
* @returns A promise that resolves to an array of runtime files.
|
|
654
|
-
*/
|
|
655
|
-
async listBuiltinFiles() {
|
|
656
|
-
const runtimeFiles = [];
|
|
657
|
-
for (const [id, path] of this.builtinIdMap.entries()) {
|
|
658
|
-
const contents = await this.readFile(path);
|
|
659
|
-
if (contents) {
|
|
660
|
-
runtimeFiles.push({
|
|
661
|
-
id: this.formatRuntimeId(id),
|
|
662
|
-
path,
|
|
663
|
-
contents
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
return runtimeFiles;
|
|
668
|
-
}
|
|
669
|
-
/**
|
|
670
799
|
* Lists files in a given path.
|
|
671
800
|
*
|
|
672
801
|
* @param path - The path to list files from.
|
|
@@ -683,7 +812,7 @@ var VirtualFileSystem = class {
|
|
|
683
812
|
*/
|
|
684
813
|
unlinkSync(path, options) {
|
|
685
814
|
const formattedPath = toFilePath(path);
|
|
686
|
-
if (!this.
|
|
815
|
+
if (!this.isFile(formattedPath)) {
|
|
687
816
|
return;
|
|
688
817
|
}
|
|
689
818
|
this.#log(LogLevelLabel.TRACE, `Synchronously removing file: ${formattedPath}`);
|
|
@@ -698,7 +827,7 @@ var VirtualFileSystem = class {
|
|
|
698
827
|
*/
|
|
699
828
|
async unlink(path, options) {
|
|
700
829
|
const formattedPath = toFilePath(path);
|
|
701
|
-
if (!this.
|
|
830
|
+
if (!this.isFile(formattedPath)) {
|
|
702
831
|
return;
|
|
703
832
|
}
|
|
704
833
|
this.#log(LogLevelLabel.TRACE, `Removing file: ${formattedPath}`);
|
|
@@ -718,7 +847,7 @@ var VirtualFileSystem = class {
|
|
|
718
847
|
*/
|
|
719
848
|
rmdirSync(path, options = {}) {
|
|
720
849
|
const formattedPath = toFilePath(path);
|
|
721
|
-
if (!this.
|
|
850
|
+
if (!this.isDirectory(formattedPath)) {
|
|
722
851
|
return;
|
|
723
852
|
}
|
|
724
853
|
this.#log(LogLevelLabel.TRACE, `Synchronously removing directory: ${formattedPath}`);
|
|
@@ -737,7 +866,7 @@ var VirtualFileSystem = class {
|
|
|
737
866
|
*/
|
|
738
867
|
async rmdir(path, options = {}) {
|
|
739
868
|
const formattedPath = toFilePath(path);
|
|
740
|
-
if (!this.
|
|
869
|
+
if (!this.isDirectory(formattedPath)) {
|
|
741
870
|
return;
|
|
742
871
|
}
|
|
743
872
|
this.#log(LogLevelLabel.TRACE, `Removing directory: ${formattedPath}`);
|
|
@@ -764,7 +893,7 @@ var VirtualFileSystem = class {
|
|
|
764
893
|
*/
|
|
765
894
|
async rm(path, options = {}) {
|
|
766
895
|
this.#log(LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
|
|
767
|
-
if (this.
|
|
896
|
+
if (this.isDirectory(path)) {
|
|
768
897
|
return this.rmdir(path, options);
|
|
769
898
|
}
|
|
770
899
|
return this.unlink(path, options);
|
|
@@ -808,12 +937,12 @@ var VirtualFileSystem = class {
|
|
|
808
937
|
/**
|
|
809
938
|
* Lists files in a given path.
|
|
810
939
|
*
|
|
811
|
-
* @param
|
|
940
|
+
* @param pathOrId - The path to list files from.
|
|
812
941
|
* @param options - Options for listing files, such as encoding and recursion.
|
|
813
942
|
* @returns An array of file names in the specified path.
|
|
814
943
|
*/
|
|
815
|
-
async readdir(
|
|
816
|
-
return this.resolveFS(
|
|
944
|
+
async readdir(pathOrId, options = "utf8") {
|
|
945
|
+
return this.resolveFS(pathOrId).promises.readdir(toFilePath(pathOrId), options);
|
|
817
946
|
}
|
|
818
947
|
/**
|
|
819
948
|
* Asynchronously reads a file from the virtual file system (VFS).
|
|
@@ -825,7 +954,7 @@ var VirtualFileSystem = class {
|
|
|
825
954
|
if (!pathOrId) {
|
|
826
955
|
return void 0;
|
|
827
956
|
}
|
|
828
|
-
const filePath = this.
|
|
957
|
+
const filePath = this.resolve(toFilePath(pathOrId), {
|
|
829
958
|
type: "file"
|
|
830
959
|
});
|
|
831
960
|
if (filePath) {
|
|
@@ -854,7 +983,7 @@ var VirtualFileSystem = class {
|
|
|
854
983
|
if (!pathOrId) {
|
|
855
984
|
return void 0;
|
|
856
985
|
}
|
|
857
|
-
const filePath = this.
|
|
986
|
+
const filePath = this.resolve(toFilePath(pathOrId), {
|
|
858
987
|
type: "file"
|
|
859
988
|
});
|
|
860
989
|
if (filePath) {
|
|
@@ -871,137 +1000,80 @@ var VirtualFileSystem = class {
|
|
|
871
1000
|
/**
|
|
872
1001
|
* Writes a file to the virtual file system (VFS).
|
|
873
1002
|
*
|
|
874
|
-
* @param
|
|
1003
|
+
* @param path - The path to the file.
|
|
875
1004
|
* @param data - The contents of the file.
|
|
876
1005
|
* @param options - Optional parameters for writing the file.
|
|
877
1006
|
* @returns A promise that resolves when the file is written.
|
|
878
1007
|
*/
|
|
879
|
-
async writeFile(
|
|
880
|
-
const
|
|
881
|
-
if (!this.
|
|
882
|
-
await this.mkdir(findFilePath(
|
|
1008
|
+
async writeFile(path, data = "", options = "utf8") {
|
|
1009
|
+
const formattedPath = this.formatPath(path);
|
|
1010
|
+
if (!this.isDirectory(findFilePath(formattedPath))) {
|
|
1011
|
+
await this.mkdir(findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
883
1012
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
1013
|
+
let code = isPowerLinesWriteFileData(data) ? data.code : data;
|
|
1014
|
+
if ((!isPowerlinesWriteFileOptions(options) || !options.skipFormat) && isSetString(code)) {
|
|
1015
|
+
const resolvedConfig = await resolveConfig(formattedPath);
|
|
1016
|
+
if (resolvedConfig) {
|
|
1017
|
+
code = await format(code, {
|
|
1018
|
+
absolutePath: formattedPath,
|
|
1019
|
+
...resolvedConfig
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
const outputMode = this.resolveOutputMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1024
|
+
this.#log(LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
|
|
1025
|
+
this.meta[formattedPath] = {
|
|
1026
|
+
path: formattedPath,
|
|
1027
|
+
code,
|
|
1028
|
+
mode: outputMode,
|
|
1029
|
+
variant: "normal",
|
|
1030
|
+
...isPowerLinesWriteFileData(data) ? data : {}
|
|
1031
|
+
};
|
|
1032
|
+
this.clearResolverCache(formattedPath);
|
|
1033
|
+
const ifs = this.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
888
1034
|
if (isFunction(ifs.promises.writeFile)) {
|
|
889
|
-
return ifs.promises.writeFile(
|
|
890
|
-
"mode"
|
|
891
|
-
]));
|
|
1035
|
+
return ifs.promises.writeFile(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
|
|
892
1036
|
}
|
|
893
|
-
return ifs.writeFileSync(
|
|
894
|
-
"mode"
|
|
895
|
-
]));
|
|
1037
|
+
return ifs.writeFileSync(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
|
|
896
1038
|
}
|
|
897
1039
|
/**
|
|
898
1040
|
* Synchronously writes a file to the virtual file system (VFS).
|
|
899
1041
|
*
|
|
900
|
-
* @param
|
|
1042
|
+
* @param path - The file to write.
|
|
901
1043
|
* @param data - The contents of the file.
|
|
902
1044
|
* @param options - Optional parameters for writing the file.
|
|
903
1045
|
*/
|
|
904
|
-
writeFileSync(
|
|
905
|
-
const
|
|
906
|
-
if (!this.
|
|
907
|
-
this.mkdirSync(findFilePath(
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
this
|
|
911
|
-
this.
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
1046
|
+
writeFileSync(path, data = "", options = "utf8") {
|
|
1047
|
+
const formattedPath = this.formatPath(path);
|
|
1048
|
+
if (!this.isDirectory(findFilePath(formattedPath))) {
|
|
1049
|
+
this.mkdirSync(findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1050
|
+
}
|
|
1051
|
+
const code = isPowerLinesWriteFileData(data) ? data.code : data;
|
|
1052
|
+
const outputMode = this.resolveOutputMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1053
|
+
this.#log(LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
|
|
1054
|
+
this.meta[formattedPath] = {
|
|
1055
|
+
path: formattedPath,
|
|
1056
|
+
code,
|
|
1057
|
+
mode: outputMode,
|
|
1058
|
+
variant: "normal",
|
|
1059
|
+
...isPowerLinesWriteFileData(data) ? data : {}
|
|
1060
|
+
};
|
|
1061
|
+
this.clearResolverCache(formattedPath);
|
|
1062
|
+
const writeStream = this.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0).createWriteStream(formattedPath);
|
|
915
1063
|
try {
|
|
916
|
-
writeStream.write(
|
|
1064
|
+
writeStream.write(code);
|
|
917
1065
|
} finally {
|
|
918
1066
|
writeStream.close();
|
|
919
1067
|
}
|
|
920
1068
|
}
|
|
921
1069
|
/**
|
|
922
|
-
* Writes a runtime file to the virtual file system (VFS).
|
|
923
|
-
*
|
|
924
|
-
* @param id - The unique identifier for the runtime file.
|
|
925
|
-
* @param path - The path to the runtime file.
|
|
926
|
-
* @param contents - The contents of the runtime file.
|
|
927
|
-
* @param options - Optional parameters for writing the runtime file.
|
|
928
|
-
* @returns A promise that resolves when the file is written.
|
|
929
|
-
*/
|
|
930
|
-
async writeBuiltinFile(id, path, contents, options = {}) {
|
|
931
|
-
const formattedId = this.formatRuntimeId(id);
|
|
932
|
-
const absolutePath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
933
|
-
this.builtinIdMap.set(formattedId, absolutePath);
|
|
934
|
-
let data = contents;
|
|
935
|
-
if (!options.skipFormat) {
|
|
936
|
-
data = await format(contents, {
|
|
937
|
-
absolutePath,
|
|
938
|
-
...await resolveConfig(absolutePath)
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
const _options = defu4(isSetString(options) ? {} : options ?? {}, {
|
|
942
|
-
encoding: isSetString(options) ? options : "utf8",
|
|
943
|
-
mode: "virtual"
|
|
944
|
-
});
|
|
945
|
-
this.#log(LogLevelLabel.DEBUG, `Writing runtime file ${absolutePath} (size: ${prettyBytes(new Blob(toArray(data)).size)}) to ${this.resolveOutputMode(absolutePath, _options) === "fs" ? "disk" : "memory"}`);
|
|
946
|
-
return this.writeFile(absolutePath, data, _options);
|
|
947
|
-
}
|
|
948
|
-
/**
|
|
949
|
-
* Adds an entry file to the virtual file system.
|
|
950
|
-
*
|
|
951
|
-
* @param name - The file name or absolute path of the entry module.
|
|
952
|
-
* @param contents - The contents of the entry file.
|
|
953
|
-
* @param options - Optional parameters for writing the entry file.
|
|
954
|
-
*/
|
|
955
|
-
async writeEntryFile(name, contents, options = {}) {
|
|
956
|
-
const absolutePath = this.formatAbsoluteFilePath(isAbsolutePath(toFilePath(name)) ? toFilePath(name) : toFilePath(joinPaths(this.#context.entryPath, name)));
|
|
957
|
-
let data = contents;
|
|
958
|
-
if (!options.skipFormat) {
|
|
959
|
-
data = await format(contents, {
|
|
960
|
-
absolutePath,
|
|
961
|
-
...await resolveConfig(absolutePath)
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
const _options = defu4(isSetString(options) ? {} : options ?? {}, {
|
|
965
|
-
encoding: isSetString(options) ? options : "utf8",
|
|
966
|
-
mode: "virtual"
|
|
967
|
-
});
|
|
968
|
-
this.#log(LogLevelLabel.DEBUG, `Writing entry file ${absolutePath} (size: ${prettyBytes(new Blob(toArray(data)).size)}) to ${this.resolveOutputMode(absolutePath, _options) === "fs" ? "disk" : "virtual memory"}`);
|
|
969
|
-
return this.writeFile(absolutePath, data, _options);
|
|
970
|
-
}
|
|
971
|
-
/**
|
|
972
|
-
* Writes a file to disk from the physical file system (on disk).
|
|
973
|
-
*
|
|
974
|
-
* @param path - The path to the file to write.
|
|
975
|
-
* @param contents - The contents of the file to write.
|
|
976
|
-
* @param options - Optional parameters for writing the file.
|
|
977
|
-
* @returns A promise that resolves when the file is written.
|
|
978
|
-
*/
|
|
979
|
-
async writeFileToDisk(path, contents, options = {}) {
|
|
980
|
-
const absolutePath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
981
|
-
let data = contents;
|
|
982
|
-
if (!options.skipFormat) {
|
|
983
|
-
const resolvedConfig = await resolveConfig(absolutePath);
|
|
984
|
-
if (resolvedConfig) {
|
|
985
|
-
data = await format(contents, {
|
|
986
|
-
absolutePath,
|
|
987
|
-
...resolvedConfig
|
|
988
|
-
});
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
return this.writeFile(absolutePath, data, defu4({
|
|
992
|
-
mode: "fs"
|
|
993
|
-
}, isSetString(options) ? {} : options ?? {}, {
|
|
994
|
-
encoding: isSetString(options) ? options : "utf8"
|
|
995
|
-
}));
|
|
996
|
-
}
|
|
997
|
-
/**
|
|
998
1070
|
* Synchronously checks if a file exists in the virtual file system (VFS).
|
|
999
1071
|
*
|
|
1000
1072
|
* @param pathOrId - The path or ID of the file to check.
|
|
1001
1073
|
* @returns `true` if the file exists, otherwise `false`.
|
|
1002
1074
|
*/
|
|
1003
1075
|
existsSync(pathOrId) {
|
|
1004
|
-
return this.
|
|
1076
|
+
return this.resolve(pathOrId) !== false;
|
|
1005
1077
|
}
|
|
1006
1078
|
/**
|
|
1007
1079
|
* Checks if a file exists in the virtual file system (VFS).
|
|
@@ -1009,32 +1081,22 @@ var VirtualFileSystem = class {
|
|
|
1009
1081
|
* @remarks
|
|
1010
1082
|
* 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.
|
|
1011
1083
|
*
|
|
1012
|
-
* @param
|
|
1084
|
+
* @param pathOrId - The path of the file to check.
|
|
1013
1085
|
* @returns `true` if the file exists, otherwise `false`.
|
|
1014
1086
|
*/
|
|
1015
|
-
|
|
1016
|
-
const
|
|
1017
|
-
return
|
|
1087
|
+
isFile(pathOrId) {
|
|
1088
|
+
const resolved = this.resolve(pathOrId);
|
|
1089
|
+
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()));
|
|
1018
1090
|
}
|
|
1019
1091
|
/**
|
|
1020
1092
|
* Checks if a directory exists in the virtual file system (VFS).
|
|
1021
1093
|
*
|
|
1022
|
-
* @param
|
|
1094
|
+
* @param pathOrId - The path of the directory to check.
|
|
1023
1095
|
* @returns `true` if the directory exists, otherwise `false`.
|
|
1024
1096
|
*/
|
|
1025
|
-
|
|
1026
|
-
const
|
|
1027
|
-
return this.#virtualFS.existsSync(
|
|
1028
|
-
}
|
|
1029
|
-
/**
|
|
1030
|
-
* Checks if a path exists in the virtual file system (VFS).
|
|
1031
|
-
*
|
|
1032
|
-
* @param path - The path to check.
|
|
1033
|
-
* @returns `true` if the path exists, otherwise `false`.
|
|
1034
|
-
*/
|
|
1035
|
-
pathExistsSync(path) {
|
|
1036
|
-
const formattedPath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
1037
|
-
return this.isValidBuiltinId(formattedPath) || this.#virtualFS.existsSync(formattedPath) || this.#fs.existsSync(formattedPath) || this.resolveFS(path).existsSync(formattedPath);
|
|
1097
|
+
isDirectory(pathOrId) {
|
|
1098
|
+
const resolved = this.resolve(pathOrId);
|
|
1099
|
+
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()));
|
|
1038
1100
|
}
|
|
1039
1101
|
/**
|
|
1040
1102
|
* Retrieves the status of a file in the virtual file system (VFS).
|
|
@@ -1043,7 +1105,7 @@ var VirtualFileSystem = class {
|
|
|
1043
1105
|
* @returns A promise that resolves to the file's status information, or false if the file does not exist.
|
|
1044
1106
|
*/
|
|
1045
1107
|
async stat(pathOrId, options) {
|
|
1046
|
-
return this.resolveFS(pathOrId).promises.stat(this.
|
|
1108
|
+
return this.resolveFS(pathOrId).promises.stat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
|
|
1047
1109
|
}
|
|
1048
1110
|
/**
|
|
1049
1111
|
* Synchronously retrieves the status of a file in the virtual file system (VFS).
|
|
@@ -1052,7 +1114,7 @@ var VirtualFileSystem = class {
|
|
|
1052
1114
|
* @returns The file's status information, or false if the file does not exist.
|
|
1053
1115
|
*/
|
|
1054
1116
|
statSync(pathOrId) {
|
|
1055
|
-
return this.resolveFS(pathOrId).statSync(this.
|
|
1117
|
+
return this.resolveFS(pathOrId).statSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId));
|
|
1056
1118
|
}
|
|
1057
1119
|
/**
|
|
1058
1120
|
* Retrieves the status of a symbolic link in the virtual file system (VFS).
|
|
@@ -1061,7 +1123,7 @@ var VirtualFileSystem = class {
|
|
|
1061
1123
|
* @returns A promise that resolves to the symbolic link's status information, or false if the link does not exist.
|
|
1062
1124
|
*/
|
|
1063
1125
|
async lstat(pathOrId, options) {
|
|
1064
|
-
return this.resolveFS(pathOrId).promises.lstat(this.
|
|
1126
|
+
return this.resolveFS(pathOrId).promises.lstat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
|
|
1065
1127
|
}
|
|
1066
1128
|
/**
|
|
1067
1129
|
* Synchronously retrieves the status of a symbolic link in the virtual file system (VFS).
|
|
@@ -1070,23 +1132,7 @@ var VirtualFileSystem = class {
|
|
|
1070
1132
|
* @returns The symbolic link's status information, or false if the link does not exist.
|
|
1071
1133
|
*/
|
|
1072
1134
|
lstatSync(pathOrId, options) {
|
|
1073
|
-
return this.resolveFS(pathOrId).lstatSync(this.
|
|
1074
|
-
}
|
|
1075
|
-
/**
|
|
1076
|
-
* Resolves a path or ID to a runtime file id in the virtual file system.
|
|
1077
|
-
*
|
|
1078
|
-
* @param pathOrId - The path or id of the file to resolve.
|
|
1079
|
-
* @returns The resolved id of the runtime file if it exists, otherwise false.
|
|
1080
|
-
*/
|
|
1081
|
-
resolveId(pathOrId) {
|
|
1082
|
-
if (this.builtinIdMap.has(this.formatRuntimeId(toFilePath(pathOrId)))) {
|
|
1083
|
-
return this.formatRuntimeId(toFilePath(pathOrId));
|
|
1084
|
-
}
|
|
1085
|
-
const filePath = this.resolvePath(toFilePath(pathOrId));
|
|
1086
|
-
if (filePath) {
|
|
1087
|
-
return this.builtinIdMap.keys().find((id) => this.builtinIdMap.get(id) === filePath) || false;
|
|
1088
|
-
}
|
|
1089
|
-
return false;
|
|
1135
|
+
return this.resolveFS(pathOrId).lstatSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
|
|
1090
1136
|
}
|
|
1091
1137
|
/**
|
|
1092
1138
|
* Resolves a path based on TypeScript's `tsconfig.json` paths.
|
|
@@ -1099,9 +1145,9 @@ var VirtualFileSystem = class {
|
|
|
1099
1145
|
resolveTsconfigPath(path) {
|
|
1100
1146
|
if (this.#context.tsconfig.options.paths) {
|
|
1101
1147
|
for (const tsconfigPathKey of Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path.startsWith(tsconfigPath.replaceAll("*", "")))) {
|
|
1102
|
-
const resolvedPath = this.#context.tsconfig.options.paths[tsconfigPathKey]?.find((tsconfigPath) => this.
|
|
1148
|
+
const resolvedPath = this.#context.tsconfig.options.paths[tsconfigPathKey]?.find((tsconfigPath) => this.resolvePath(joinPaths(this.#context.workspaceConfig.workspaceRoot, tsconfigPath.replaceAll("*", ""), path.replace(tsconfigPathKey.replaceAll("*", ""), ""))) || this.formatPath(tsconfigPath) === this.formatPath(path));
|
|
1103
1149
|
if (resolvedPath) {
|
|
1104
|
-
return this.
|
|
1150
|
+
return this.formatPath(resolvedPath) === this.formatPath(path) ? this.formatPath(resolvedPath) : this.resolvePath(joinPaths(this.#context.workspaceConfig.workspaceRoot, resolvedPath.replaceAll("*", ""), path.replace(tsconfigPathKey.replaceAll("*", ""), "")));
|
|
1105
1151
|
}
|
|
1106
1152
|
}
|
|
1107
1153
|
}
|
|
@@ -1131,7 +1177,7 @@ var VirtualFileSystem = class {
|
|
|
1131
1177
|
* @returns The resolved real path if it exists, otherwise undefined.
|
|
1132
1178
|
*/
|
|
1133
1179
|
realpathSync(pathOrId) {
|
|
1134
|
-
const filePath = this.
|
|
1180
|
+
const filePath = this.resolve(toFilePath(pathOrId));
|
|
1135
1181
|
if (!filePath) {
|
|
1136
1182
|
throw new Error(`File not found: ${toFilePath(pathOrId)}`);
|
|
1137
1183
|
}
|
|
@@ -1144,24 +1190,18 @@ var VirtualFileSystem = class {
|
|
|
1144
1190
|
* @param options - Optional parameters for resolving the path, such as whether to include the file extension.
|
|
1145
1191
|
* @returns The resolved file path if it exists, otherwise undefined.
|
|
1146
1192
|
*/
|
|
1147
|
-
|
|
1148
|
-
const
|
|
1149
|
-
const resolverKey = `${
|
|
1193
|
+
resolve(pathOrId, options = {}) {
|
|
1194
|
+
const formattedPathOrId = toFilePath(pathOrId);
|
|
1195
|
+
const resolverKey = `${formattedPathOrId}${options.withExtension ? "-ext" : ""}${options.paths ? `-${murmurhash(options.paths)}` : ""}${options.type ? `-${options.type}` : ""}`;
|
|
1150
1196
|
if (this.#cachedResolver.has(resolverKey)) {
|
|
1151
1197
|
return this.#cachedResolver.get(resolverKey);
|
|
1152
|
-
} else if (this.#cachedFS.has(formattedPath)) {
|
|
1153
|
-
return formattedPath;
|
|
1154
1198
|
}
|
|
1155
|
-
let result =
|
|
1156
|
-
if (
|
|
1157
|
-
result = this.
|
|
1158
|
-
} else {
|
|
1159
|
-
result = this.resolvePathName(formattedPath, options);
|
|
1199
|
+
let result = this.resolveId(formattedPathOrId);
|
|
1200
|
+
if (!result) {
|
|
1201
|
+
result = this.resolvePath(formattedPathOrId, options);
|
|
1160
1202
|
}
|
|
1161
1203
|
if (!result) {
|
|
1162
1204
|
result = false;
|
|
1163
|
-
} else {
|
|
1164
|
-
result = toFilePath(result);
|
|
1165
1205
|
}
|
|
1166
1206
|
if (result && options.withExtension === false) {
|
|
1167
1207
|
return result.replace(/\.[m|c]?[t|j]sx?$/, "");
|
|
@@ -1170,16 +1210,12 @@ var VirtualFileSystem = class {
|
|
|
1170
1210
|
return result;
|
|
1171
1211
|
}
|
|
1172
1212
|
/**
|
|
1173
|
-
*
|
|
1213
|
+
* Retrieves the partial metadata for all files in the virtual file system (VFS).
|
|
1174
1214
|
*
|
|
1175
|
-
* @
|
|
1176
|
-
* @returns The formatted file path.
|
|
1215
|
+
* @returns A record containing the partial metadata for all files.
|
|
1177
1216
|
*/
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
throw new Error(`Invalid path provided. Expected a string or a valid file path.`);
|
|
1181
|
-
}
|
|
1182
|
-
return path.replace(new RegExp(`^${this.#context.config.output.builtinPrefix}:`), "").replace(/^\\0/, "");
|
|
1217
|
+
getPartialMeta() {
|
|
1218
|
+
return Object.fromEntries(Object.entries(this.#meta).filter(([_, data]) => isSetObject(data)));
|
|
1183
1219
|
}
|
|
1184
1220
|
/**
|
|
1185
1221
|
* Converts a relative path to an absolute path based on the workspace and project root.
|
|
@@ -1187,56 +1223,67 @@ var VirtualFileSystem = class {
|
|
|
1187
1223
|
* @param path - The relative path to convert.
|
|
1188
1224
|
* @returns The absolute path.
|
|
1189
1225
|
*/
|
|
1190
|
-
|
|
1191
|
-
const formattedPath =
|
|
1226
|
+
formatPath(path) {
|
|
1227
|
+
const formattedPath = toFilePath(path);
|
|
1192
1228
|
if (isAbsolutePath(formattedPath) || formattedPath.startsWith(this.#context.workspaceConfig.workspaceRoot)) {
|
|
1193
1229
|
return formattedPath;
|
|
1194
1230
|
} else if (formattedPath.startsWith(this.#context.config.projectRoot)) {
|
|
1195
1231
|
return joinPaths(this.#context.workspaceConfig.workspaceRoot, formattedPath);
|
|
1196
1232
|
}
|
|
1197
1233
|
return formattedPath;
|
|
1198
|
-
}
|
|
1234
|
+
}
|
|
1199
1235
|
/**
|
|
1200
|
-
* Formats a
|
|
1236
|
+
* Formats a file id by removing the file extension and prepending the runtime prefix.
|
|
1201
1237
|
*
|
|
1202
|
-
* @param id - The
|
|
1203
|
-
* @returns The formatted
|
|
1238
|
+
* @param id - The file ID to format.
|
|
1239
|
+
* @returns The formatted file ID.
|
|
1204
1240
|
*/
|
|
1205
|
-
|
|
1206
|
-
|
|
1241
|
+
formatId(id) {
|
|
1242
|
+
const formattedId = toFilePath(id);
|
|
1243
|
+
return `${this.#context.config.output.builtinPrefix}:${formattedId.replace(new RegExp(`^${this.#context.config.output.builtinPrefix}:`), "").replace(/^\\0/, "").replace(findFileExtensionSafe(formattedId), "")}`;
|
|
1207
1244
|
}
|
|
1208
1245
|
/**
|
|
1209
|
-
* Resolves
|
|
1246
|
+
* Resolves an id parameter to a corresponding virtual file path in the virtual file system (VFS).
|
|
1210
1247
|
*
|
|
1211
|
-
* @param
|
|
1212
|
-
* @returns The resolved file
|
|
1248
|
+
* @param id - The id to resolve.
|
|
1249
|
+
* @returns The resolved file id if it exists, otherwise undefined.
|
|
1213
1250
|
*/
|
|
1214
|
-
|
|
1215
|
-
if (
|
|
1216
|
-
return false;
|
|
1251
|
+
resolveId(id) {
|
|
1252
|
+
if (this.#ids[this.formatId(id)]) {
|
|
1253
|
+
return this.#ids[this.formatId(id)] || false;
|
|
1217
1254
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1255
|
+
return false;
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* Resolves a path parameter to a corresponding virtual file path in the virtual file system (VFS).
|
|
1259
|
+
*
|
|
1260
|
+
* @param path - The path to resolve.
|
|
1261
|
+
* @param options - Optional parameters for resolving the path.
|
|
1262
|
+
* @returns The resolved file path if it exists, otherwise undefined.
|
|
1263
|
+
*/
|
|
1264
|
+
resolvePath(path, options = {}) {
|
|
1265
|
+
if (isAbsolutePath(path)) {
|
|
1266
|
+
if (this.#existsSync(path)) {
|
|
1267
|
+
return path;
|
|
1221
1268
|
}
|
|
1222
|
-
const result = checkVariants(
|
|
1269
|
+
const result = this.checkVariants(path);
|
|
1223
1270
|
if (result) {
|
|
1224
1271
|
return result;
|
|
1225
1272
|
}
|
|
1226
1273
|
}
|
|
1227
|
-
for (const
|
|
1228
|
-
const request = joinPaths(
|
|
1229
|
-
if (
|
|
1274
|
+
for (const parentPath of this.resolveParentPaths(path, options.paths)) {
|
|
1275
|
+
const request = joinPaths(parentPath, path);
|
|
1276
|
+
if (this.#existsSync(request)) {
|
|
1230
1277
|
return request;
|
|
1231
1278
|
}
|
|
1232
|
-
const result = checkVariants(request
|
|
1279
|
+
const result = this.checkVariants(request);
|
|
1233
1280
|
if (result) {
|
|
1234
1281
|
return result;
|
|
1235
1282
|
}
|
|
1236
1283
|
}
|
|
1237
1284
|
return false;
|
|
1238
1285
|
}
|
|
1239
|
-
resolveParentPaths(request,
|
|
1286
|
+
resolveParentPaths(request, parents = []) {
|
|
1240
1287
|
let paths = [
|
|
1241
1288
|
this.#context.workspaceConfig.workspaceRoot,
|
|
1242
1289
|
joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot)
|
|
@@ -1254,7 +1301,7 @@ var VirtualFileSystem = class {
|
|
|
1254
1301
|
ret.push(path);
|
|
1255
1302
|
}
|
|
1256
1303
|
return ret;
|
|
1257
|
-
},
|
|
1304
|
+
}, parents.filter(Boolean).map((p) => this.formatPath(p)));
|
|
1258
1305
|
}
|
|
1259
1306
|
/**
|
|
1260
1307
|
* Select the file system module to use for the operation based on the path or URL.
|
|
@@ -1285,7 +1332,7 @@ var VirtualFileSystem = class {
|
|
|
1285
1332
|
} else if (options.mode === "fs" || this.#context.config.output.mode === "fs" || isParentPath(toFilePath(pathOrUrl), this.#context.dataPath) || isParentPath(toFilePath(pathOrUrl), this.#context.cachePath) || isParentPath(toFilePath(pathOrUrl), joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
|
|
1286
1333
|
return "fs";
|
|
1287
1334
|
}
|
|
1288
|
-
return
|
|
1335
|
+
return void 0;
|
|
1289
1336
|
}
|
|
1290
1337
|
/**
|
|
1291
1338
|
* Clears the resolver cache for a given path.
|
|
@@ -1295,208 +1342,93 @@ var VirtualFileSystem = class {
|
|
|
1295
1342
|
clearResolverCache(path) {
|
|
1296
1343
|
this.#cachedResolver.keys().filter((key) => key.startsWith(toFilePath(path))).forEach((key) => this.#cachedResolver.delete(key));
|
|
1297
1344
|
}
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
__name(toFilePath, "toFilePath");
|
|
1311
|
-
var FS_METHODS = [
|
|
1312
|
-
"mkdir",
|
|
1313
|
-
"mkdirSync",
|
|
1314
|
-
"rmdir",
|
|
1315
|
-
"rmdirSync",
|
|
1316
|
-
"unlink",
|
|
1317
|
-
"unlinkSync",
|
|
1318
|
-
"existsSync",
|
|
1319
|
-
"realpathSync",
|
|
1320
|
-
"writeFileSync",
|
|
1321
|
-
"readFileSync",
|
|
1322
|
-
"readdirSync",
|
|
1323
|
-
"createWriteStream",
|
|
1324
|
-
"WriteStream",
|
|
1325
|
-
"createReadStream",
|
|
1326
|
-
"ReadStream"
|
|
1327
|
-
];
|
|
1328
|
-
var FS_PROMISE_METHODS = [
|
|
1329
|
-
"mkdir",
|
|
1330
|
-
"rm",
|
|
1331
|
-
"rmdir",
|
|
1332
|
-
"unlink",
|
|
1333
|
-
"writeFile",
|
|
1334
|
-
"readFile",
|
|
1335
|
-
"readdir",
|
|
1336
|
-
"stat",
|
|
1337
|
-
"lstat"
|
|
1338
|
-
];
|
|
1339
|
-
function cloneFS(originalFS) {
|
|
1340
|
-
const clonedFS = {
|
|
1341
|
-
...originalFS,
|
|
1342
|
-
promises: {
|
|
1343
|
-
...originalFS.promises ?? {}
|
|
1345
|
+
/**
|
|
1346
|
+
* Check if the file exists with different variants (index, extensions).
|
|
1347
|
+
*
|
|
1348
|
+
* @param request - The request path to check.
|
|
1349
|
+
* @param parentPath - An optional parent path to prepend to the request.
|
|
1350
|
+
* @returns The file path if it exists, otherwise false.
|
|
1351
|
+
*/
|
|
1352
|
+
checkVariants(request, parentPath) {
|
|
1353
|
+
const path = parentPath ? joinPaths(parentPath, request) : request;
|
|
1354
|
+
let file = this.checkExtensions(path);
|
|
1355
|
+
if (file) {
|
|
1356
|
+
return file;
|
|
1344
1357
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
clonedFS[method] = originalFS[method];
|
|
1358
|
+
file = this.checkIndex(path);
|
|
1359
|
+
if (file) {
|
|
1360
|
+
return file;
|
|
1349
1361
|
}
|
|
1362
|
+
return false;
|
|
1350
1363
|
}
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1364
|
+
/**
|
|
1365
|
+
* Check if the index file exists in the given request path.
|
|
1366
|
+
*
|
|
1367
|
+
* @param request - The request path to check.
|
|
1368
|
+
* @returns The index file path if it exists, otherwise false.
|
|
1369
|
+
*/
|
|
1370
|
+
checkIndex(request) {
|
|
1371
|
+
let file = joinPaths(request, "index");
|
|
1372
|
+
if (this.#existsSync(file)) {
|
|
1373
|
+
return file;
|
|
1357
1374
|
}
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
clonedFS[prop] = clonedFS[prop].bind(originalFS);
|
|
1362
|
-
if (isFunction(clonedFS.promises[prop])) {
|
|
1363
|
-
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
1364
|
-
}
|
|
1375
|
+
file = this.checkExtensions(file);
|
|
1376
|
+
if (file) {
|
|
1377
|
+
return file;
|
|
1365
1378
|
}
|
|
1379
|
+
return false;
|
|
1366
1380
|
}
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1381
|
+
/**
|
|
1382
|
+
* Check if the file exists with different extensions.
|
|
1383
|
+
*
|
|
1384
|
+
* @param request - The request path to check.
|
|
1385
|
+
* @param vfs - The file system module to use for checking file existence.
|
|
1386
|
+
* @returns The file path if it exists with any of the checked extensions, otherwise false.
|
|
1387
|
+
*/
|
|
1388
|
+
checkExtensions(request) {
|
|
1389
|
+
let file = `${request}.ts`;
|
|
1390
|
+
if (this.#existsSync(file)) {
|
|
1391
|
+
return file;
|
|
1370
1392
|
}
|
|
1393
|
+
file = `${request}.mts`;
|
|
1394
|
+
if (this.#existsSync(file)) {
|
|
1395
|
+
return file;
|
|
1396
|
+
}
|
|
1397
|
+
file = `${request}.cts`;
|
|
1398
|
+
if (this.#existsSync(file)) {
|
|
1399
|
+
return file;
|
|
1400
|
+
}
|
|
1401
|
+
file = `${request}.tsx`;
|
|
1402
|
+
if (this.#existsSync(file)) {
|
|
1403
|
+
return file;
|
|
1404
|
+
}
|
|
1405
|
+
file = `${request}.js`;
|
|
1406
|
+
if (this.#existsSync(file)) {
|
|
1407
|
+
return file;
|
|
1408
|
+
}
|
|
1409
|
+
file = `${request}.mjs`;
|
|
1410
|
+
if (this.#existsSync(file)) {
|
|
1411
|
+
return file;
|
|
1412
|
+
}
|
|
1413
|
+
file = `${request}.cjs`;
|
|
1414
|
+
if (this.#existsSync(file)) {
|
|
1415
|
+
return file;
|
|
1416
|
+
}
|
|
1417
|
+
file = `${request}.jsx`;
|
|
1418
|
+
if (this.#existsSync(file)) {
|
|
1419
|
+
return file;
|
|
1420
|
+
}
|
|
1421
|
+
file = `${request}.json`;
|
|
1422
|
+
if (this.#existsSync(file)) {
|
|
1423
|
+
return file;
|
|
1424
|
+
}
|
|
1425
|
+
file = `${request}.d.ts`;
|
|
1426
|
+
if (this.#existsSync(file)) {
|
|
1427
|
+
return file;
|
|
1428
|
+
}
|
|
1429
|
+
return false;
|
|
1371
1430
|
}
|
|
1372
|
-
|
|
1373
|
-
}
|
|
1374
|
-
__name(cloneFS, "cloneFS");
|
|
1375
|
-
function patchFS(originalFS, vfs) {
|
|
1376
|
-
const clonedFS = cloneFS(originalFS);
|
|
1377
|
-
originalFS.mkdirSync = (file, options) => vfs.mkdirSync(toFilePath(file), options);
|
|
1378
|
-
originalFS.mkdir = (file, options, callback) => vfs.mkdir(toFilePath(file), options, callback);
|
|
1379
|
-
originalFS.promises.mkdir = async (file, options) => vfs.mkdir(toFilePath(file), options);
|
|
1380
|
-
originalFS.unlinkSync = (file) => vfs.unlinkSync(toFilePath(file));
|
|
1381
|
-
originalFS.promises.rm = async (file, options) => vfs.rm(toFilePath(file), options);
|
|
1382
|
-
originalFS.promises.unlink = async (file) => vfs.unlink(toFilePath(file));
|
|
1383
|
-
originalFS.existsSync = (file) => vfs.existsSync(toFilePath(file));
|
|
1384
|
-
Object.defineProperty(originalFS, "realpathSync", {
|
|
1385
|
-
value: /* @__PURE__ */ __name((file, options) => vfs.realpathSync(toFilePath(file), options), "value")
|
|
1386
|
-
});
|
|
1387
|
-
originalFS.writeFileSync = (file, data, options) => vfs.writeFileSync(toFilePath(file), data, options);
|
|
1388
|
-
originalFS.promises.writeFile = async (file, data, options) => vfs.writeFile(toFilePath(file), data, options);
|
|
1389
|
-
originalFS.readFileSync = (file, options) => vfs.readFileSync(toFilePath(file), options);
|
|
1390
|
-
originalFS.promises.readFile = (file, options) => vfs.readFile(toFilePath(file), options);
|
|
1391
|
-
originalFS.readdirSync = (file, options) => vfs.readdirSync(toFilePath(file), options);
|
|
1392
|
-
originalFS.promises.readdir = (file, options) => vfs.readdir(toFilePath(file), options);
|
|
1393
|
-
Object.defineProperty(originalFS, "statSync", {
|
|
1394
|
-
value: /* @__PURE__ */ __name((file, options) => vfs.statSync(toFilePath(file), options), "value")
|
|
1395
|
-
});
|
|
1396
|
-
originalFS.stat = (file, options) => vfs.statSync(toFilePath(file), options);
|
|
1397
|
-
originalFS.promises.stat = (file, options) => vfs.stat(toFilePath(file), options);
|
|
1398
|
-
Object.defineProperty(originalFS, "lstatSync", {
|
|
1399
|
-
value: /* @__PURE__ */ __name((file, options) => vfs.lstatSync(toFilePath(file), options), "value")
|
|
1400
|
-
});
|
|
1401
|
-
originalFS.lstat = (file, options) => vfs.lstatSync(toFilePath(file), options);
|
|
1402
|
-
originalFS.promises.lstat = (file, options) => vfs.lstat(toFilePath(file), options);
|
|
1403
|
-
return () => {
|
|
1404
|
-
originalFS.mkdirSync = clonedFS.mkdirSync;
|
|
1405
|
-
originalFS.mkdir = clonedFS.mkdir;
|
|
1406
|
-
originalFS.promises.mkdir = clonedFS.promises.mkdir;
|
|
1407
|
-
originalFS.unlinkSync = clonedFS.unlinkSync;
|
|
1408
|
-
originalFS.promises.rm = clonedFS.promises.rm;
|
|
1409
|
-
originalFS.promises.unlink = clonedFS.promises.unlink;
|
|
1410
|
-
originalFS.existsSync = clonedFS.existsSync;
|
|
1411
|
-
originalFS.realpathSync = clonedFS.realpathSync;
|
|
1412
|
-
originalFS.writeFileSync = clonedFS.writeFileSync;
|
|
1413
|
-
originalFS.promises.writeFile = clonedFS.promises.writeFile;
|
|
1414
|
-
originalFS.readFileSync = clonedFS.readFileSync;
|
|
1415
|
-
originalFS.promises.readFile = clonedFS.promises.readFile;
|
|
1416
|
-
originalFS.readdirSync = clonedFS.readdirSync;
|
|
1417
|
-
originalFS.promises.readdir = clonedFS.promises.readdir;
|
|
1418
|
-
Object.defineProperty(originalFS, "statSync", {
|
|
1419
|
-
value: clonedFS.statSync
|
|
1420
|
-
});
|
|
1421
|
-
originalFS.stat = clonedFS.stat;
|
|
1422
|
-
originalFS.promises.stat = clonedFS.promises.stat;
|
|
1423
|
-
Object.defineProperty(originalFS, "lstatSync", {
|
|
1424
|
-
value: clonedFS.lstatSync
|
|
1425
|
-
});
|
|
1426
|
-
originalFS.lstat = clonedFS.lstat;
|
|
1427
|
-
originalFS.promises.lstat = clonedFS.promises.lstat;
|
|
1428
|
-
};
|
|
1429
|
-
}
|
|
1430
|
-
__name(patchFS, "patchFS");
|
|
1431
|
-
function checkVariants(request, vfs, parentPath) {
|
|
1432
|
-
const path = parentPath ? joinPaths(parentPath, request) : request;
|
|
1433
|
-
let file = checkExtensions(path, vfs);
|
|
1434
|
-
if (file) {
|
|
1435
|
-
return file;
|
|
1436
|
-
}
|
|
1437
|
-
file = checkIndex(path, vfs);
|
|
1438
|
-
if (file) {
|
|
1439
|
-
return file;
|
|
1440
|
-
}
|
|
1441
|
-
return false;
|
|
1442
|
-
}
|
|
1443
|
-
__name(checkVariants, "checkVariants");
|
|
1444
|
-
function checkIndex(request, vfs) {
|
|
1445
|
-
let file = joinPaths(request, "index");
|
|
1446
|
-
if (vfs.fileExistsSync(file)) {
|
|
1447
|
-
return file;
|
|
1448
|
-
}
|
|
1449
|
-
file = checkExtensions(file, vfs);
|
|
1450
|
-
if (file) {
|
|
1451
|
-
return file;
|
|
1452
|
-
}
|
|
1453
|
-
return false;
|
|
1454
|
-
}
|
|
1455
|
-
__name(checkIndex, "checkIndex");
|
|
1456
|
-
function checkExtensions(request, vfs) {
|
|
1457
|
-
let file = `${request}.ts`;
|
|
1458
|
-
if (vfs.fileExistsSync(file)) {
|
|
1459
|
-
return file;
|
|
1460
|
-
}
|
|
1461
|
-
file = `${request}.mts`;
|
|
1462
|
-
if (vfs.fileExistsSync(file)) {
|
|
1463
|
-
return file;
|
|
1464
|
-
}
|
|
1465
|
-
file = `${request}.cts`;
|
|
1466
|
-
if (vfs.fileExistsSync(file)) {
|
|
1467
|
-
return file;
|
|
1468
|
-
}
|
|
1469
|
-
file = `${request}.tsx`;
|
|
1470
|
-
if (vfs.fileExistsSync(file)) {
|
|
1471
|
-
return file;
|
|
1472
|
-
}
|
|
1473
|
-
file = `${request}.js`;
|
|
1474
|
-
if (vfs.fileExistsSync(file)) {
|
|
1475
|
-
return file;
|
|
1476
|
-
}
|
|
1477
|
-
file = `${request}.mjs`;
|
|
1478
|
-
if (vfs.fileExistsSync(file)) {
|
|
1479
|
-
return file;
|
|
1480
|
-
}
|
|
1481
|
-
file = `${request}.cjs`;
|
|
1482
|
-
if (vfs.fileExistsSync(file)) {
|
|
1483
|
-
return file;
|
|
1484
|
-
}
|
|
1485
|
-
file = `${request}.jsx`;
|
|
1486
|
-
if (vfs.fileExistsSync(file)) {
|
|
1487
|
-
return file;
|
|
1488
|
-
}
|
|
1489
|
-
file = `${request}.json`;
|
|
1490
|
-
if (vfs.fileExistsSync(file)) {
|
|
1491
|
-
return file;
|
|
1492
|
-
}
|
|
1493
|
-
file = `${request}.d.ts`;
|
|
1494
|
-
if (vfs.fileExistsSync(file)) {
|
|
1495
|
-
return file;
|
|
1496
|
-
}
|
|
1497
|
-
return false;
|
|
1498
|
-
}
|
|
1499
|
-
__name(checkExtensions, "checkExtensions");
|
|
1431
|
+
};
|
|
1500
1432
|
function createVfs(context) {
|
|
1501
1433
|
const vfs = new VirtualFileSystem(context);
|
|
1502
1434
|
return vfs;
|
|
@@ -1732,6 +1664,57 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1732
1664
|
return relativeToWorkspaceRoot(this.config.projectRoot);
|
|
1733
1665
|
}
|
|
1734
1666
|
/**
|
|
1667
|
+
* The builtin module id that exist in the Powerlines virtual file system
|
|
1668
|
+
*/
|
|
1669
|
+
get builtins() {
|
|
1670
|
+
return Object.values(this.fs.meta).filter((meta) => meta && meta.variant === "builtin").map((meta) => meta?.id).filter(Boolean);
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
* Get the project root relative to the workspace root
|
|
1674
|
+
*/
|
|
1675
|
+
async getBuiltins() {
|
|
1676
|
+
return Promise.all(Object.entries(this.fs.meta).filter(([, meta]) => meta && meta.variant === "builtin").map(async ([path, meta]) => {
|
|
1677
|
+
const code = await this.fs.readFile(path);
|
|
1678
|
+
return {
|
|
1679
|
+
...meta,
|
|
1680
|
+
path,
|
|
1681
|
+
code
|
|
1682
|
+
};
|
|
1683
|
+
}));
|
|
1684
|
+
}
|
|
1685
|
+
/**
|
|
1686
|
+
* Resolves a entry virtual file and writes it to the VFS if it does not already exist
|
|
1687
|
+
*
|
|
1688
|
+
* @param code - The source code of the entry file
|
|
1689
|
+
* @param path - A path to write the entry file to
|
|
1690
|
+
* @param options - Optional write file options
|
|
1691
|
+
*/
|
|
1692
|
+
async writeEntry(code, path, options = {}) {
|
|
1693
|
+
return this.fs.writeFile(isAbsolute(path) ? path : appendPath(path, this.entryPath), {
|
|
1694
|
+
code,
|
|
1695
|
+
variant: "entry"
|
|
1696
|
+
}, defu4(options, {
|
|
1697
|
+
mode: this.config.output.mode
|
|
1698
|
+
}));
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* Resolves a builtin virtual file and writes it to the VFS if it does not already exist
|
|
1702
|
+
*
|
|
1703
|
+
* @param code - The source code of the builtin file
|
|
1704
|
+
* @param id - The unique identifier of the builtin file
|
|
1705
|
+
* @param path - An optional path to write the builtin file to
|
|
1706
|
+
* @param options - Optional write file options
|
|
1707
|
+
*/
|
|
1708
|
+
async writeBuiltin(code, id, path, options = {}) {
|
|
1709
|
+
return this.fs.writeFile(path ? isAbsolute(path) ? path : joinPaths$1(this.builtinsPath, path) : appendPath(id, this.builtinsPath), {
|
|
1710
|
+
id,
|
|
1711
|
+
code,
|
|
1712
|
+
variant: "builtin"
|
|
1713
|
+
}, defu4(options, {
|
|
1714
|
+
mode: this.config.output.mode
|
|
1715
|
+
}));
|
|
1716
|
+
}
|
|
1717
|
+
/**
|
|
1735
1718
|
* Parses the source code and returns a {@link ParseResult} object.
|
|
1736
1719
|
*
|
|
1737
1720
|
* @param code - The source code to parse.
|
|
@@ -2333,6 +2316,26 @@ var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext
|
|
|
2333
2316
|
}
|
|
2334
2317
|
}
|
|
2335
2318
|
};
|
|
2319
|
+
function getBaseFileHeader(context) {
|
|
2320
|
+
return `
|
|
2321
|
+
// Generated with ${titleCase(context.config.framework)}
|
|
2322
|
+
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
2323
|
+
`;
|
|
2324
|
+
}
|
|
2325
|
+
__name(getBaseFileHeader, "getBaseFileHeader");
|
|
2326
|
+
function getFileHeader(context, options = {}) {
|
|
2327
|
+
const { directive = null, prettierIgnore = false } = options;
|
|
2328
|
+
return `/* eslint-disable */
|
|
2329
|
+
// biome-ignore lint: disable
|
|
2330
|
+
${prettierIgnore ? `// prettier-ignore` : ""}${directive ? `
|
|
2331
|
+
|
|
2332
|
+
${directive}
|
|
2333
|
+
` : "\n"}
|
|
2334
|
+
${getBaseFileHeader(context)}
|
|
2335
|
+
|
|
2336
|
+
`;
|
|
2337
|
+
}
|
|
2338
|
+
__name(getFileHeader, "getFileHeader");
|
|
2336
2339
|
function getString(code) {
|
|
2337
2340
|
if (!code) {
|
|
2338
2341
|
return "";
|
|
@@ -2367,7 +2370,7 @@ function resolveModulePath(nodePath, state) {
|
|
|
2367
2370
|
return;
|
|
2368
2371
|
}
|
|
2369
2372
|
const sourcePath = nodePath.node.value;
|
|
2370
|
-
const resolvedPath = state.context?.fs.
|
|
2373
|
+
const resolvedPath = state.context?.fs.resolve(sourcePath);
|
|
2371
2374
|
if (resolvedPath) {
|
|
2372
2375
|
nodePath.replaceWith(t.stringLiteral(
|
|
2373
2376
|
// Remove the file extension if it exists
|
|
@@ -2468,8 +2471,9 @@ var moduleResolverBabelPlugin = /* @__PURE__ */ __name((context) => {
|
|
|
2468
2471
|
async function generateTypes(context) {
|
|
2469
2472
|
context.log(LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
|
|
2470
2473
|
context.log(LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
|
|
2471
|
-
const builtinFiles = await
|
|
2472
|
-
|
|
2474
|
+
const builtinFiles = await context.getBuiltins();
|
|
2475
|
+
const builtinFilePaths = await Promise.all(builtinFiles.map(async (file) => {
|
|
2476
|
+
const result = await transformAsync(file.code.toString(), {
|
|
2473
2477
|
highlightCode: true,
|
|
2474
2478
|
code: true,
|
|
2475
2479
|
ast: false,
|
|
@@ -2497,14 +2501,14 @@ async function generateTypes(context) {
|
|
|
2497
2501
|
throw new Error(`Powerlines - Generate Types failed to compile ${file.id}`);
|
|
2498
2502
|
}
|
|
2499
2503
|
context.log(LogLevelLabel.TRACE, `Writing transformed built-in runtime file ${file.id}.`);
|
|
2500
|
-
await context.
|
|
2504
|
+
await context.writeBuiltin(result.code, file.id, file.path);
|
|
2501
2505
|
return file.path;
|
|
2502
2506
|
}));
|
|
2503
2507
|
const typescriptPath = await resolvePackage("typescript");
|
|
2504
2508
|
if (!typescriptPath) {
|
|
2505
2509
|
throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
|
|
2506
2510
|
}
|
|
2507
|
-
const files =
|
|
2511
|
+
const files = builtinFilePaths.reduce((ret, fileName) => {
|
|
2508
2512
|
const formatted = replacePath(fileName, context.workspaceConfig.workspaceRoot);
|
|
2509
2513
|
if (!ret.includes(formatted)) {
|
|
2510
2514
|
ret.push(formatted);
|
|
@@ -2539,9 +2543,9 @@ async function generateTypes(context) {
|
|
|
2539
2543
|
const emitResult = program.emit(void 0, (fileName, text, _, __, sourceFiles, _data) => {
|
|
2540
2544
|
const sourceFile2 = sourceFiles?.[0];
|
|
2541
2545
|
if (sourceFile2?.fileName && !fileName.endsWith(".map")) {
|
|
2542
|
-
if (
|
|
2546
|
+
if (builtinFiles.some((file) => file.id === sourceFile2.fileName || file.path === sourceFile2.fileName)) {
|
|
2543
2547
|
builtinModules += `
|
|
2544
|
-
declare module "${context.fs.
|
|
2548
|
+
declare module "${context.fs.resolve(sourceFile2.fileName)}" {
|
|
2545
2549
|
${text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
|
|
2546
2550
|
}
|
|
2547
2551
|
`;
|
|
@@ -2580,7 +2584,9 @@ ${builtinModules}`.replace(
|
|
|
2580
2584
|
/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g,
|
|
2581
2585
|
""
|
|
2582
2586
|
).replaceAll("#private;", "").replace(/__Ω/g, ""));
|
|
2583
|
-
await context.fs.
|
|
2587
|
+
await context.fs.writeFile(sourceFile.id, getString(sourceFile.code), {
|
|
2588
|
+
mode: "fs"
|
|
2589
|
+
});
|
|
2584
2590
|
}
|
|
2585
2591
|
__name(generateTypes, "generateTypes");
|
|
2586
2592
|
async function installPackage(context, packageName, dev = false) {
|
|
@@ -2744,7 +2750,9 @@ async function initializeTsconfig(context) {
|
|
|
2744
2750
|
const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
2745
2751
|
context.tsconfig.originalTsconfigJson = await readJsonFile(tsconfigFilePath);
|
|
2746
2752
|
context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
|
|
2747
|
-
await context.fs.
|
|
2753
|
+
await context.fs.writeFile(tsconfigFilePath, StormJSON.stringify(context.tsconfig.tsconfigJson), {
|
|
2754
|
+
mode: "fs"
|
|
2755
|
+
});
|
|
2748
2756
|
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
|
|
2749
2757
|
}
|
|
2750
2758
|
__name(initializeTsconfig, "initializeTsconfig");
|
|
@@ -2880,11 +2888,6 @@ ${formatLogMessage(context.config)}`);
|
|
|
2880
2888
|
await this.callPreHook(context, "prepare");
|
|
2881
2889
|
if (context.config.projectType === "application") {
|
|
2882
2890
|
context.log(LogLevelLabel.TRACE, "Generating built-in barrel file");
|
|
2883
|
-
await context.fs.writeBuiltinFile("index", joinPaths(context.builtinsPath, "index.ts"), `
|
|
2884
|
-
${getFileHeader(context)}
|
|
2885
|
-
|
|
2886
|
-
${(await context.fs.listBuiltinFiles()).filter((file) => !isParentPath(file.path, joinPaths(context.builtinsPath, "log")) && !isParentPath(file.path, joinPaths(context.builtinsPath, "storage"))).map((file) => `export * from "./${replacePath(file.path, context.builtinsPath).replace(`.${findFileExtensionSafe(file.path)}`, "")}";`).join("\n")}
|
|
2887
|
-
`);
|
|
2888
2891
|
}
|
|
2889
2892
|
if (context.config.output.dts !== false) {
|
|
2890
2893
|
await generateTypes(context);
|
|
@@ -3328,8 +3331,8 @@ var DEFAULT_ESBUILD_CONFIG = {
|
|
|
3328
3331
|
};
|
|
3329
3332
|
function extractESBuildConfig(context) {
|
|
3330
3333
|
return defu4({
|
|
3331
|
-
alias: context.
|
|
3332
|
-
const path = context.fs.
|
|
3334
|
+
alias: context.builtins.reduce((ret, id) => {
|
|
3335
|
+
const path = context.fs.ids[id];
|
|
3333
3336
|
if (path) {
|
|
3334
3337
|
ret[id] = path;
|
|
3335
3338
|
}
|
|
@@ -3372,8 +3375,8 @@ var DEFAULT_VITE_CONFIG = {
|
|
|
3372
3375
|
function extractViteConfig(context) {
|
|
3373
3376
|
return defu4({
|
|
3374
3377
|
resolve: {
|
|
3375
|
-
alias: context.
|
|
3376
|
-
const path = context.fs.
|
|
3378
|
+
alias: context.builtins.reduce((ret, id) => {
|
|
3379
|
+
const path = context.fs.ids[id];
|
|
3377
3380
|
if (path) {
|
|
3378
3381
|
ret[id] = path;
|
|
3379
3382
|
}
|
|
@@ -3397,7 +3400,7 @@ function extractViteConfig(context) {
|
|
|
3397
3400
|
esbuild: extractESBuildConfig(context),
|
|
3398
3401
|
logLevel: context.config.logLevel ?? void 0,
|
|
3399
3402
|
envDir: context.config.projectRoot,
|
|
3400
|
-
noExternal:
|
|
3403
|
+
noExternal: context.builtins
|
|
3401
3404
|
}, context.config.build.variant === "vite" ? context.config.build : {}, {
|
|
3402
3405
|
build: {
|
|
3403
3406
|
minify: context.config.mode !== "development",
|
|
@@ -3410,16 +3413,16 @@ __name(extractViteConfig, "extractViteConfig");
|
|
|
3410
3413
|
var NON_NODE_MODULE_REGEX = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
|
|
3411
3414
|
async function handleResolveId(context, args, options = {}) {
|
|
3412
3415
|
if (args.id) {
|
|
3413
|
-
if (context.fs.
|
|
3416
|
+
if (context.fs.isVirtual(args.id) || args.importer && context.fs.isVirtual(args.id, {
|
|
3414
3417
|
paths: [
|
|
3415
3418
|
args.importer
|
|
3416
3419
|
]
|
|
3417
3420
|
})) {
|
|
3418
|
-
const resolvedPath = args.importer ? context.fs.
|
|
3421
|
+
const resolvedPath = args.importer ? context.fs.resolve(args.id, {
|
|
3419
3422
|
paths: [
|
|
3420
3423
|
args.importer
|
|
3421
3424
|
]
|
|
3422
|
-
}) : context.fs.
|
|
3425
|
+
}) : context.fs.resolve(args.id);
|
|
3423
3426
|
if (resolvedPath) {
|
|
3424
3427
|
return {
|
|
3425
3428
|
id: resolvedPath,
|
|
@@ -3457,11 +3460,12 @@ async function handleResolveId(context, args, options = {}) {
|
|
|
3457
3460
|
};
|
|
3458
3461
|
}
|
|
3459
3462
|
} else {
|
|
3460
|
-
|
|
3461
|
-
paths: [
|
|
3463
|
+
const resolvedPath = context.fs.resolve(args.id, {
|
|
3464
|
+
paths: args.importer ? [
|
|
3462
3465
|
args.importer
|
|
3463
|
-
]
|
|
3464
|
-
})
|
|
3466
|
+
] : []
|
|
3467
|
+
});
|
|
3468
|
+
if (match(args.id, options.noExternal) || resolvedPath && context.fs.meta[resolvedPath]?.variant === "builtin") {
|
|
3465
3469
|
return void 0;
|
|
3466
3470
|
}
|
|
3467
3471
|
if (match(args.id, options.external) || args.id.startsWith("node:")) {
|
|
@@ -3520,9 +3524,7 @@ function createUnpluginFactory(variant, decorate) {
|
|
|
3520
3524
|
async function load(id) {
|
|
3521
3525
|
const environment = await api.context.getEnvironment();
|
|
3522
3526
|
if (id) {
|
|
3523
|
-
const resolvedPath = environment.fs.
|
|
3524
|
-
type: "file"
|
|
3525
|
-
});
|
|
3527
|
+
const resolvedPath = environment.fs.resolve(id);
|
|
3526
3528
|
if (resolvedPath) {
|
|
3527
3529
|
return environment.fs.readFile(resolvedPath);
|
|
3528
3530
|
}
|