@powerlines/nx 0.10.36 → 0.10.38
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 +17 -0
- package/dist/{chunk-HOCK3PN2.mjs → chunk-2SK7GXYX.mjs} +1 -1
- package/dist/{chunk-ZGEXR2Z6.mjs → chunk-37R7Z4YA.mjs} +1 -1
- package/dist/{chunk-62JK5CR2.js → chunk-55HWRJFI.js} +2 -2
- package/dist/{chunk-D5MAY4B6.js → chunk-5IM5S57N.js} +2 -2
- package/dist/{chunk-6M466CL6.mjs → chunk-7Z54WTD3.mjs} +1 -1
- package/dist/{chunk-OBVSDJNP.mjs → chunk-BM5C4GAH.mjs} +1 -1
- package/dist/{chunk-76PYI2PW.js → chunk-CJE2WIZT.js} +2 -2
- package/dist/{chunk-V3APU4CI.js → chunk-DDZYTWHI.js} +2 -2
- package/dist/{chunk-FXB722G2.js → chunk-DNMCZOZX.js} +2 -2
- package/dist/{chunk-2PYUYDPD.js → chunk-DQI2I5KK.js} +1 -3
- package/dist/{chunk-LNSZHZQF.js → chunk-F7EY5OCV.js} +911 -947
- package/dist/{chunk-A36IQB2U.mjs → chunk-HJZ2I6NE.mjs} +11 -19
- package/dist/{chunk-YAQUTH2M.js → chunk-JXYA5T7X.js} +2 -2
- package/dist/{chunk-Q6DRZWW7.js → chunk-KBRCV5NY.js} +13 -21
- package/dist/{chunk-3QGFYJKW.mjs → chunk-OIL7SLIA.mjs} +1 -1
- package/dist/{chunk-XQ44F4OL.mjs → chunk-OS2GSBDL.mjs} +904 -939
- package/dist/{chunk-WGIN2BGP.mjs → chunk-OVX2CEXQ.mjs} +1 -3
- package/dist/{chunk-AGWVUBME.mjs → chunk-PWZ3J3N6.mjs} +1 -1
- package/dist/executors.js +15 -15
- package/dist/executors.mjs +7 -7
- package/dist/index.js +18 -18
- package/dist/index.mjs +9 -9
- 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/helpers/plugin-utilities.js +5 -5
- package/dist/src/helpers/plugin-utilities.mjs +2 -2
- package/dist/src/plugin/index.js +4 -4
- package/dist/src/plugin/index.mjs +3 -3
- package/dist/src/types/plugin.d.mts +1 -1
- package/dist/src/types/plugin.d.ts +1 -1
- package/package.json +8 -8
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkDQI2I5KK_js = require('./chunk-DQI2I5KK.js');
|
|
4
4
|
var chunkSHUYVCID_js = require('./chunk-SHUYVCID.js');
|
|
5
5
|
var logger = require('@storm-software/config-tools/logger');
|
|
6
6
|
var baseExecutor = require('@storm-software/workspace-tools/base/base-executor');
|
|
7
7
|
var isError = require('@stryke/type-checks/is-error');
|
|
8
|
-
var
|
|
8
|
+
var defu6 = require('defu');
|
|
9
9
|
var core = require('@babel/core');
|
|
10
10
|
var console = require('@storm-software/config-tools/logger/console');
|
|
11
11
|
var types = require('@storm-software/config-tools/types');
|
|
12
12
|
var toArray = require('@stryke/convert/to-array');
|
|
13
13
|
var copyFile = require('@stryke/fs/copy-file');
|
|
14
|
+
var helpers = require('@stryke/fs/helpers');
|
|
14
15
|
var install = require('@stryke/fs/install');
|
|
15
16
|
var listFiles = require('@stryke/fs/list-files');
|
|
16
17
|
var packageFns = require('@stryke/fs/package-fns');
|
|
@@ -28,13 +29,14 @@ var chalk5 = require('chalk');
|
|
|
28
29
|
var Handlebars = require('handlebars');
|
|
29
30
|
var helperPluginUtils = require('@babel/helper-plugin-utils');
|
|
30
31
|
var t = require('@babel/types');
|
|
31
|
-
var
|
|
32
|
+
var ts = require('typescript');
|
|
33
|
+
var join = require('@stryke/path/join');
|
|
34
|
+
var tsMorph = require('ts-morph');
|
|
32
35
|
var _package = require('@stryke/string-format/package');
|
|
33
36
|
var superdiff = require('@donedeal0/superdiff');
|
|
34
37
|
var json = require('@stryke/fs/json');
|
|
35
38
|
var stormJson = require('@stryke/json/storm-json');
|
|
36
39
|
var filePathFns = require('@stryke/path/file-path-fns');
|
|
37
|
-
var isParentPath = require('@stryke/path/is-parent-path');
|
|
38
40
|
var titleCase = require('@stryke/string-format/title-case');
|
|
39
41
|
var exists = require('@stryke/fs/exists');
|
|
40
42
|
var writeFile$1 = require('@stryke/fs/write-file');
|
|
@@ -46,7 +48,6 @@ var murmurhash = require('@stryke/hash/murmurhash');
|
|
|
46
48
|
var getUnique = require('@stryke/helpers/get-unique');
|
|
47
49
|
var omit = require('@stryke/helpers/omit');
|
|
48
50
|
var isType = require('@stryke/path/is-type');
|
|
49
|
-
var join = require('@stryke/path/join');
|
|
50
51
|
var isNull = require('@stryke/type-checks/is-null');
|
|
51
52
|
var isString = require('@stryke/type-checks/is-string');
|
|
52
53
|
var uuid = require('@stryke/unique-id/uuid');
|
|
@@ -56,20 +57,19 @@ var isUndefined = require('@stryke/type-checks/is-undefined');
|
|
|
56
57
|
var parseTypeDefinition = require('@stryke/convert/parse-type-definition');
|
|
57
58
|
var isFile = require('@stryke/fs/is-file');
|
|
58
59
|
var $ = require('@stryke/capnp');
|
|
59
|
-
var bufferToString = require('@stryke/convert/buffer-to-string');
|
|
60
60
|
var buffer = require('@stryke/fs/buffer');
|
|
61
61
|
var correctPath = require('@stryke/path/correct-path');
|
|
62
|
+
var isParentPath = require('@stryke/path/is-parent-path');
|
|
62
63
|
var prettyBytes = require('@stryke/string-format/pretty-bytes');
|
|
63
|
-
var isBuffer = require('@stryke/type-checks/is-buffer');
|
|
64
64
|
var flatCache = require('flat-cache');
|
|
65
65
|
var buffer$1 = require('buffer');
|
|
66
|
-
var _fs = require('fs');
|
|
67
66
|
var colors = require('@storm-software/config-tools/utilities/colors');
|
|
68
67
|
var noop = require('@stryke/helpers/noop');
|
|
69
68
|
var slash = require('@stryke/path/slash');
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
var
|
|
69
|
+
var readFile = require('@stryke/fs/read-file');
|
|
70
|
+
var fs = require('fs');
|
|
71
|
+
var promises = require('fs/promises');
|
|
72
|
+
var path = require('path');
|
|
73
73
|
var isObject = require('@stryke/type-checks/is-object');
|
|
74
74
|
|
|
75
75
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -92,13 +92,12 @@ function _interopNamespace(e) {
|
|
|
92
92
|
return Object.freeze(n);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
var
|
|
95
|
+
var defu6__default = /*#__PURE__*/_interopDefault(defu6);
|
|
96
96
|
var chalk5__default = /*#__PURE__*/_interopDefault(chalk5);
|
|
97
97
|
var Handlebars__default = /*#__PURE__*/_interopDefault(Handlebars);
|
|
98
98
|
var t__namespace = /*#__PURE__*/_interopNamespace(t);
|
|
99
|
-
var
|
|
99
|
+
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
100
100
|
var $__namespace = /*#__PURE__*/_interopNamespace($);
|
|
101
|
-
var _fs__default = /*#__PURE__*/_interopDefault(_fs);
|
|
102
101
|
|
|
103
102
|
function resolveModulePath(nodePath, state) {
|
|
104
103
|
if (!t__namespace.isStringLiteral(nodePath.node)) {
|
|
@@ -201,6 +200,108 @@ var moduleResolverBabelPlugin = /* @__PURE__ */ chunkSHUYVCID_js.__name((context
|
|
|
201
200
|
};
|
|
202
201
|
}, "builder"));
|
|
203
202
|
}, "moduleResolverBabelPlugin");
|
|
203
|
+
var VirtualFileSystemHost = class extends tsMorph.InMemoryFileSystemHost {
|
|
204
|
+
static {
|
|
205
|
+
chunkSHUYVCID_js.__name(this, "VirtualFileSystemHost");
|
|
206
|
+
}
|
|
207
|
+
#context;
|
|
208
|
+
constructor(context) {
|
|
209
|
+
super();
|
|
210
|
+
this.#context = context;
|
|
211
|
+
}
|
|
212
|
+
deleteSync(path) {
|
|
213
|
+
this.#context.fs.removeSync(path);
|
|
214
|
+
}
|
|
215
|
+
readDirSync(dirPath) {
|
|
216
|
+
return this.#context.fs.listSync(dirPath).reduce((ret, entry) => {
|
|
217
|
+
const fullPath = this.#context.fs.resolveSync(join.joinPaths(dirPath, entry));
|
|
218
|
+
if (fullPath) {
|
|
219
|
+
ret.push({
|
|
220
|
+
name: entry,
|
|
221
|
+
isDirectory: this.#context.fs.existsSync(fullPath),
|
|
222
|
+
isFile: this.#context.fs.existsSync(fullPath),
|
|
223
|
+
isSymlink: false
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return ret;
|
|
227
|
+
}, []);
|
|
228
|
+
}
|
|
229
|
+
async readFile(filePath) {
|
|
230
|
+
if (!this.#context.fs.existsSync(filePath)) {
|
|
231
|
+
throw new Error(`File not found: '${filePath}'. Please check the path and try again.`);
|
|
232
|
+
}
|
|
233
|
+
return await this.#context.fs.read(filePath);
|
|
234
|
+
}
|
|
235
|
+
readFileSync(filePath) {
|
|
236
|
+
if (!this.#context.fs.existsSync(filePath)) {
|
|
237
|
+
throw new Error(`File not found: '${filePath}'. Please check the path and try again.`);
|
|
238
|
+
}
|
|
239
|
+
return this.#context.fs.readSync(filePath);
|
|
240
|
+
}
|
|
241
|
+
async writeFile(filePath, fileText) {
|
|
242
|
+
return this.#context.fs.write(filePath, fileText);
|
|
243
|
+
}
|
|
244
|
+
writeFileSync(filePath, fileText) {
|
|
245
|
+
this.#context.fs.writeSync(filePath, fileText);
|
|
246
|
+
}
|
|
247
|
+
async mkdir(_dirPath) {
|
|
248
|
+
}
|
|
249
|
+
mkdirSync(_dirPath) {
|
|
250
|
+
}
|
|
251
|
+
async move(srcPath, destPath) {
|
|
252
|
+
await this.#context.fs.move(srcPath, destPath);
|
|
253
|
+
}
|
|
254
|
+
moveSync(srcPath, destPath) {
|
|
255
|
+
this.#context.fs.moveSync(srcPath, destPath);
|
|
256
|
+
}
|
|
257
|
+
async copy(srcPath, destPath) {
|
|
258
|
+
await this.#context.fs.copy(srcPath, destPath);
|
|
259
|
+
}
|
|
260
|
+
copySync(srcPath, destPath) {
|
|
261
|
+
this.#context.fs.copySync(srcPath, destPath);
|
|
262
|
+
}
|
|
263
|
+
async fileExists(filePath) {
|
|
264
|
+
return this.#context.fs.exists(filePath);
|
|
265
|
+
}
|
|
266
|
+
fileExistsSync(filePath) {
|
|
267
|
+
return this.#context.fs.existsSync(filePath);
|
|
268
|
+
}
|
|
269
|
+
async directoryExists(dirPath) {
|
|
270
|
+
return this.#context.fs.exists(dirPath);
|
|
271
|
+
}
|
|
272
|
+
directoryExistsSync(dirPath) {
|
|
273
|
+
return this.#context.fs.existsSync(dirPath);
|
|
274
|
+
}
|
|
275
|
+
realpathSync(path) {
|
|
276
|
+
return this.#context.fs.resolveSync(path) || path;
|
|
277
|
+
}
|
|
278
|
+
getCurrentDirectory() {
|
|
279
|
+
return this.#context.workspaceConfig.workspaceRoot;
|
|
280
|
+
}
|
|
281
|
+
async glob(patterns) {
|
|
282
|
+
return this.#context.fs.glob(patterns);
|
|
283
|
+
}
|
|
284
|
+
globSync(patterns) {
|
|
285
|
+
return this.#context.fs.globSync(patterns);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
function createProgram(context, override) {
|
|
289
|
+
context.log(types.LogLevelLabel.TRACE, `Creating ts-morph Project instance with configuration from: ${context.tsconfig.tsconfigFilePath}.`);
|
|
290
|
+
const project = new tsMorph.Project(defu6__default.default(override ?? {}, {
|
|
291
|
+
skipAddingFilesFromTsConfig: false,
|
|
292
|
+
tsConfigFilePath: context.tsconfig.tsconfigFilePath,
|
|
293
|
+
fileSystem: new VirtualFileSystemHost(context),
|
|
294
|
+
compilerOptions: defu6__default.default(context.tsconfig.options ?? {}, {
|
|
295
|
+
lib: [
|
|
296
|
+
"lib.esnext.full.d.ts"
|
|
297
|
+
]
|
|
298
|
+
})
|
|
299
|
+
}));
|
|
300
|
+
return project;
|
|
301
|
+
}
|
|
302
|
+
chunkSHUYVCID_js.__name(createProgram, "createProgram");
|
|
303
|
+
|
|
304
|
+
// ../powerlines/src/internal/helpers/generate-types.ts
|
|
204
305
|
function formatTypes(code) {
|
|
205
306
|
return code.replace(
|
|
206
307
|
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
|
@@ -211,8 +312,11 @@ function formatTypes(code) {
|
|
|
211
312
|
chunkSHUYVCID_js.__name(formatTypes, "formatTypes");
|
|
212
313
|
async function emitTypes(context, files) {
|
|
213
314
|
context.log(types.LogLevelLabel.TRACE, `Running the TypeScript compiler for ${files.length} generated runtime files.`);
|
|
214
|
-
|
|
215
|
-
|
|
315
|
+
const program = createProgram(context, {
|
|
316
|
+
skipAddingFilesFromTsConfig: true
|
|
317
|
+
});
|
|
318
|
+
program.addSourceFilesAtPaths(files);
|
|
319
|
+
const result = program.emitToMemory({
|
|
216
320
|
emitOnlyDtsFiles: true
|
|
217
321
|
});
|
|
218
322
|
let builtinModules = "";
|
|
@@ -231,9 +335,9 @@ async function emitTypes(context, files) {
|
|
|
231
335
|
const diagnosticMessages = [];
|
|
232
336
|
result.getDiagnostics().forEach((diagnostic) => {
|
|
233
337
|
if (diagnostic.getSourceFile()?.getBaseName()) {
|
|
234
|
-
diagnosticMessages.push(`${diagnostic.getSourceFile()?.getBaseName()} (${(diagnostic.getLineNumber() ?? 0) + 1}): ${
|
|
338
|
+
diagnosticMessages.push(`${diagnostic.getSourceFile()?.getBaseName()} (${(diagnostic.getLineNumber() ?? 0) + 1}): ${ts.flattenDiagnosticMessageText(diagnostic.getMessageText().toString(), "\n")}`);
|
|
235
339
|
} else {
|
|
236
|
-
diagnosticMessages.push(
|
|
340
|
+
diagnosticMessages.push(ts.flattenDiagnosticMessageText(diagnostic.getMessageText().toString(), "\n"));
|
|
237
341
|
}
|
|
238
342
|
});
|
|
239
343
|
const diagnosticMessage = diagnosticMessages.join("\n");
|
|
@@ -272,7 +376,7 @@ async function callHook(context, hook, options, ...args) {
|
|
|
272
376
|
if (definedResults.length > 0) {
|
|
273
377
|
let mergedResult = void 0;
|
|
274
378
|
for (const result of definedResults) {
|
|
275
|
-
mergedResult =
|
|
379
|
+
mergedResult = defu6.defu(result, mergedResult ?? {});
|
|
276
380
|
}
|
|
277
381
|
return mergedResult;
|
|
278
382
|
}
|
|
@@ -409,13 +513,13 @@ function isIncludeMatchFound(tsconfigType, types) {
|
|
|
409
513
|
return findIncludeMatch(tsconfigType, types) !== void 0;
|
|
410
514
|
}
|
|
411
515
|
chunkSHUYVCID_js.__name(isIncludeMatchFound, "isIncludeMatchFound");
|
|
412
|
-
function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfigRaw = {}, originalTsconfigJson, host =
|
|
516
|
+
function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfigRaw = {}, originalTsconfigJson, host = ts__default.default.sys) {
|
|
413
517
|
const tsconfigFilePath = getTsconfigFilePath(workspaceRoot, projectRoot, tsconfig);
|
|
414
518
|
const tsconfigJson = json.readJsonFileSync(tsconfigFilePath);
|
|
415
519
|
if (!tsconfigJson) {
|
|
416
520
|
throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${joinPaths.joinPaths(projectRoot, tsconfig ?? "tsconfig.json")}`);
|
|
417
521
|
}
|
|
418
|
-
const parsedCommandLine =
|
|
522
|
+
const parsedCommandLine = ts__default.default.parseJsonConfigFileContent(defu6__default.default(tsconfigRaw ?? {}, tsconfigJson), host, append.appendPath(projectRoot, workspaceRoot));
|
|
419
523
|
if (parsedCommandLine.errors.length > 0) {
|
|
420
524
|
const errorMessage = `Cannot parse the TypeScript compiler options. Please investigate the following issues:
|
|
421
525
|
${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && error.code ? `[${error.category}-${error.code}]: ` : "") + error.messageText.toString()}`).join("\n")}
|
|
@@ -456,15 +560,10 @@ async function resolveTsconfigChanges(context) {
|
|
|
456
560
|
const tsconfigJson = await json.readJsonFile(tsconfigFilePath);
|
|
457
561
|
tsconfigJson.compilerOptions ??= {};
|
|
458
562
|
if (context.config.output.dts !== false) {
|
|
459
|
-
|
|
460
|
-
if (filePathFns.findFileExtension(context.config.output.dts) !== "d.ts" && filePathFns.findFileExtension(context.config.output.dts) !== "d.cts" && filePathFns.findFileExtension(context.config.output.dts) !== "d.mts") {
|
|
461
|
-
context.config.output.dts = joinPaths.joinPaths(context.config.output.dts, "powerlines.d.ts");
|
|
462
|
-
}
|
|
463
|
-
const dtsRelativePath = joinPaths.joinPaths(filePathFns.relativePath(joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot), filePathFns.findFilePath(context.config.output.dts)), filePathFns.findFileName(context.config.output.dts));
|
|
563
|
+
const dtsRelativePath = joinPaths.joinPaths(filePathFns.relativePath(joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot), filePathFns.findFilePath(context.dtsPath)), filePathFns.findFileName(context.dtsPath));
|
|
464
564
|
if (!tsconfigJson.include?.some((filePattern) => isIncludeMatchFound(filePattern, [
|
|
465
|
-
|
|
466
|
-
dtsRelativePath
|
|
467
|
-
"storm.d.ts"
|
|
565
|
+
context.dtsPath,
|
|
566
|
+
dtsRelativePath
|
|
468
567
|
]))) {
|
|
469
568
|
tsconfigJson.include ??= [];
|
|
470
569
|
tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
|
|
@@ -479,24 +578,6 @@ async function resolveTsconfigChanges(context) {
|
|
|
479
578
|
tsconfigJson.compilerOptions.lib ??= [];
|
|
480
579
|
tsconfigJson.compilerOptions.lib.push("esnext");
|
|
481
580
|
}
|
|
482
|
-
if (tsconfig.options.module !== ts2__default.default.ModuleKind.ESNext) {
|
|
483
|
-
tsconfigJson.compilerOptions.module = "ESNext";
|
|
484
|
-
}
|
|
485
|
-
if (!tsconfig.options.target || ![
|
|
486
|
-
ts2__default.default.ScriptTarget.ESNext,
|
|
487
|
-
ts2__default.default.ScriptTarget.ES2024,
|
|
488
|
-
ts2__default.default.ScriptTarget.ES2023,
|
|
489
|
-
ts2__default.default.ScriptTarget.ES2022,
|
|
490
|
-
ts2__default.default.ScriptTarget.ES2021
|
|
491
|
-
].includes(tsconfig.options.target)) {
|
|
492
|
-
tsconfigJson.compilerOptions.target = "ESNext";
|
|
493
|
-
}
|
|
494
|
-
if (tsconfig.options.moduleResolution !== ts2__default.default.ModuleResolutionKind.Bundler) {
|
|
495
|
-
tsconfigJson.compilerOptions.moduleResolution = "Bundler";
|
|
496
|
-
}
|
|
497
|
-
if (tsconfig.options.moduleDetection !== ts2__default.default.ModuleDetectionKind.Force) {
|
|
498
|
-
tsconfigJson.compilerOptions.moduleDetection = "force";
|
|
499
|
-
}
|
|
500
581
|
if (tsconfig.options.esModuleInterop !== true) {
|
|
501
582
|
tsconfigJson.compilerOptions.esModuleInterop = true;
|
|
502
583
|
}
|
|
@@ -521,9 +602,7 @@ async function initializeTsconfig(context) {
|
|
|
521
602
|
context.tsconfig.originalTsconfigJson = await json.readJsonFile(tsconfigFilePath);
|
|
522
603
|
context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
|
|
523
604
|
context.log(types.LogLevelLabel.TRACE, "Writing updated TypeScript configuration (tsconfig.json) file to disk.");
|
|
524
|
-
await context.
|
|
525
|
-
mode: "fs"
|
|
526
|
-
});
|
|
605
|
+
await writeFile(context.log, tsconfigFilePath, stormJson.StormJSON.stringify(context.tsconfig.tsconfigJson));
|
|
527
606
|
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
|
|
528
607
|
}
|
|
529
608
|
chunkSHUYVCID_js.__name(initializeTsconfig, "initializeTsconfig");
|
|
@@ -583,7 +662,7 @@ async function resolveTsconfig(context) {
|
|
|
583
662
|
chunkSHUYVCID_js.__name(resolveTsconfig, "resolveTsconfig");
|
|
584
663
|
var DEFAULT_ENVIRONMENT = "default";
|
|
585
664
|
function createEnvironment(name, userConfig) {
|
|
586
|
-
return
|
|
665
|
+
return defu6__default.default(userConfig.environments?.[name] ?? {}, {
|
|
587
666
|
name,
|
|
588
667
|
title: userConfig.title || titleCase.titleCase(userConfig.name),
|
|
589
668
|
ssr: false,
|
|
@@ -627,8 +706,7 @@ function createDefaultEnvironment(userConfig) {
|
|
|
627
706
|
}
|
|
628
707
|
chunkSHUYVCID_js.__name(createDefaultEnvironment, "createDefaultEnvironment");
|
|
629
708
|
function resolveOptions(options) {
|
|
630
|
-
return
|
|
631
|
-
debug: options.logLevel === "trace",
|
|
709
|
+
return defu6__default.default(options, {
|
|
632
710
|
interopDefault: true,
|
|
633
711
|
fsCache: options.mode !== "development" ? joinPaths.joinPaths(options.cacheDir, "jiti") : false,
|
|
634
712
|
moduleCache: options.mode !== "development"
|
|
@@ -719,7 +797,7 @@ function replacePathTokens(context, path) {
|
|
|
719
797
|
if (!path) {
|
|
720
798
|
return path;
|
|
721
799
|
}
|
|
722
|
-
return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.projectRoot).replaceAll("{projectRoot}", context.config.projectRoot).replaceAll("{powerlinesPath}", context.powerlinesPath).replaceAll("{cachePath}", context.cachePath).replaceAll("{dataPath}", context.dataPath).replaceAll("{logPath}", context.envPaths.log).replaceAll("{tempPath}", context.envPaths.temp).replaceAll("{configPath}", context.envPaths.config).replaceAll("{outputPath}", context.config.output.outputPath).replaceAll("{
|
|
800
|
+
return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.projectRoot).replaceAll("{projectRoot}", context.config.projectRoot).replaceAll("{powerlinesPath}", context.powerlinesPath).replaceAll("{cachePath}", context.cachePath).replaceAll("{dataPath}", context.dataPath).replaceAll("{logPath}", context.envPaths.log).replaceAll("{tempPath}", context.envPaths.temp).replaceAll("{configPath}", context.envPaths.config).replaceAll("{outputPath}", context.config.output.outputPath).replaceAll("{buildPath}", context.config.output.buildPath).replaceAll("{artifactsPath}", replace.replacePath(context.artifactsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{builtinPath}", replace.replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{entryPath}", replace.replacePath(context.entryPath, context.workspaceConfig.workspaceRoot));
|
|
723
801
|
}
|
|
724
802
|
chunkSHUYVCID_js.__name(replacePathTokens, "replacePathTokens");
|
|
725
803
|
function resolveEntryInputFile(context, typeDefinition) {
|
|
@@ -803,7 +881,7 @@ var FileMetadata = class _FileMetadata extends $__namespace.Struct {
|
|
|
803
881
|
static _capnp = {
|
|
804
882
|
displayName: "FileMetadata",
|
|
805
883
|
id: "8e2cab5d7e28c7b3",
|
|
806
|
-
size: new $__namespace.ObjectSize(8,
|
|
884
|
+
size: new $__namespace.ObjectSize(8, 3),
|
|
807
885
|
defaultType: "normal"
|
|
808
886
|
};
|
|
809
887
|
static _Properties;
|
|
@@ -818,7 +896,7 @@ var FileMetadata = class _FileMetadata extends $__namespace.Struct {
|
|
|
818
896
|
$__namespace.utils.setText(0, value, this);
|
|
819
897
|
}
|
|
820
898
|
/**
|
|
821
|
-
* The
|
|
899
|
+
* The timestamp representing the file's creation date.
|
|
822
900
|
*
|
|
823
901
|
*/
|
|
824
902
|
get type() {
|
|
@@ -828,16 +906,6 @@ var FileMetadata = class _FileMetadata extends $__namespace.Struct {
|
|
|
828
906
|
$__namespace.utils.setText(1, value, this);
|
|
829
907
|
}
|
|
830
908
|
/**
|
|
831
|
-
* The timestamp representing the file's creation date.
|
|
832
|
-
*
|
|
833
|
-
*/
|
|
834
|
-
get mode() {
|
|
835
|
-
return $__namespace.utils.getText(2, this);
|
|
836
|
-
}
|
|
837
|
-
set mode(value) {
|
|
838
|
-
$__namespace.utils.setText(2, value, this);
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
909
|
* Additional metadata associated with the file.
|
|
842
910
|
*
|
|
843
911
|
*/
|
|
@@ -848,22 +916,22 @@ var FileMetadata = class _FileMetadata extends $__namespace.Struct {
|
|
|
848
916
|
$__namespace.utils.setUint32(0, value, this);
|
|
849
917
|
}
|
|
850
918
|
_adoptProperties(value) {
|
|
851
|
-
$__namespace.utils.adopt(value, $__namespace.utils.getPointer(
|
|
919
|
+
$__namespace.utils.adopt(value, $__namespace.utils.getPointer(2, this));
|
|
852
920
|
}
|
|
853
921
|
_disownProperties() {
|
|
854
922
|
return $__namespace.utils.disown(this.properties);
|
|
855
923
|
}
|
|
856
924
|
get properties() {
|
|
857
|
-
return $__namespace.utils.getList(
|
|
925
|
+
return $__namespace.utils.getList(2, _FileMetadata._Properties, this);
|
|
858
926
|
}
|
|
859
927
|
_hasProperties() {
|
|
860
|
-
return !$__namespace.utils.isNull($__namespace.utils.getPointer(
|
|
928
|
+
return !$__namespace.utils.isNull($__namespace.utils.getPointer(2, this));
|
|
861
929
|
}
|
|
862
930
|
_initProperties(length) {
|
|
863
|
-
return $__namespace.utils.initList(
|
|
931
|
+
return $__namespace.utils.initList(2, _FileMetadata._Properties, length, this);
|
|
864
932
|
}
|
|
865
933
|
set properties(value) {
|
|
866
|
-
$__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(
|
|
934
|
+
$__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(2, this));
|
|
867
935
|
}
|
|
868
936
|
toString() {
|
|
869
937
|
return "FileMetadata_" + super.toString();
|
|
@@ -898,13 +966,13 @@ var FileId = class extends $__namespace.Struct {
|
|
|
898
966
|
return "FileId_" + super.toString();
|
|
899
967
|
}
|
|
900
968
|
};
|
|
901
|
-
var
|
|
969
|
+
var FileStorage = class extends $__namespace.Struct {
|
|
902
970
|
static {
|
|
903
|
-
chunkSHUYVCID_js.__name(this, "
|
|
971
|
+
chunkSHUYVCID_js.__name(this, "FileStorage");
|
|
904
972
|
}
|
|
905
973
|
static _capnp = {
|
|
906
|
-
displayName: "
|
|
907
|
-
id: "
|
|
974
|
+
displayName: "FileStorage",
|
|
975
|
+
id: "9dca66ac858c9ebe",
|
|
908
976
|
size: new $__namespace.ObjectSize(0, 2)
|
|
909
977
|
};
|
|
910
978
|
/**
|
|
@@ -924,7 +992,7 @@ var FileData = class extends $__namespace.Struct {
|
|
|
924
992
|
$__namespace.utils.setText(1, value, this);
|
|
925
993
|
}
|
|
926
994
|
toString() {
|
|
927
|
-
return "
|
|
995
|
+
return "FileStorage_" + super.toString();
|
|
928
996
|
}
|
|
929
997
|
};
|
|
930
998
|
var FileSystem = class _FileSystem extends $__namespace.Struct {
|
|
@@ -937,7 +1005,7 @@ var FileSystem = class _FileSystem extends $__namespace.Struct {
|
|
|
937
1005
|
size: new $__namespace.ObjectSize(0, 3)
|
|
938
1006
|
};
|
|
939
1007
|
static _Ids;
|
|
940
|
-
static
|
|
1008
|
+
static _Storage;
|
|
941
1009
|
static _Metadata;
|
|
942
1010
|
_adoptIds(value) {
|
|
943
1011
|
$__namespace.utils.adopt(value, $__namespace.utils.getPointer(0, this));
|
|
@@ -957,22 +1025,22 @@ var FileSystem = class _FileSystem extends $__namespace.Struct {
|
|
|
957
1025
|
set ids(value) {
|
|
958
1026
|
$__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(0, this));
|
|
959
1027
|
}
|
|
960
|
-
|
|
1028
|
+
_adoptStorage(value) {
|
|
961
1029
|
$__namespace.utils.adopt(value, $__namespace.utils.getPointer(1, this));
|
|
962
1030
|
}
|
|
963
|
-
|
|
964
|
-
return $__namespace.utils.disown(this.
|
|
1031
|
+
_disownStorage() {
|
|
1032
|
+
return $__namespace.utils.disown(this.storage);
|
|
965
1033
|
}
|
|
966
|
-
get
|
|
967
|
-
return $__namespace.utils.getList(1, _FileSystem.
|
|
1034
|
+
get storage() {
|
|
1035
|
+
return $__namespace.utils.getList(1, _FileSystem._Storage, this);
|
|
968
1036
|
}
|
|
969
|
-
|
|
1037
|
+
_hasStorage() {
|
|
970
1038
|
return !$__namespace.utils.isNull($__namespace.utils.getPointer(1, this));
|
|
971
1039
|
}
|
|
972
|
-
|
|
973
|
-
return $__namespace.utils.initList(1, _FileSystem.
|
|
1040
|
+
_initStorage(length) {
|
|
1041
|
+
return $__namespace.utils.initList(1, _FileSystem._Storage, length, this);
|
|
974
1042
|
}
|
|
975
|
-
set
|
|
1043
|
+
set storage(value) {
|
|
976
1044
|
$__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(1, this));
|
|
977
1045
|
}
|
|
978
1046
|
_adoptMetadata(value) {
|
|
@@ -999,12 +1067,15 @@ var FileSystem = class _FileSystem extends $__namespace.Struct {
|
|
|
999
1067
|
};
|
|
1000
1068
|
FileMetadata._Properties = $__namespace.CompositeList(FileMetadata_KeyValuePair);
|
|
1001
1069
|
FileSystem._Ids = $__namespace.CompositeList(FileId);
|
|
1002
|
-
FileSystem.
|
|
1070
|
+
FileSystem._Storage = $__namespace.CompositeList(FileStorage);
|
|
1003
1071
|
FileSystem._Metadata = $__namespace.CompositeList(FileMetadata);
|
|
1004
1072
|
|
|
1005
1073
|
// ../powerlines/src/types/fs.ts
|
|
1006
|
-
var
|
|
1007
|
-
|
|
1074
|
+
var StoragePreset = /* @__PURE__ */ (function(StoragePreset2) {
|
|
1075
|
+
StoragePreset2["VIRTUAL"] = "virtual";
|
|
1076
|
+
StoragePreset2["FS"] = "fs";
|
|
1077
|
+
return StoragePreset2;
|
|
1078
|
+
})({});
|
|
1008
1079
|
var createLog = /* @__PURE__ */ chunkSHUYVCID_js.__name((name, options = {}) => {
|
|
1009
1080
|
const logLevel = options.logLevel === null ? types.LogLevelLabel.SILENT : options.logLevel || types.LogLevelLabel.INFO;
|
|
1010
1081
|
if (logLevel === types.LogLevelLabel.SILENT) {
|
|
@@ -1043,142 +1114,18 @@ var BADGE_COLORS = [
|
|
|
1043
1114
|
var extendLog = /* @__PURE__ */ chunkSHUYVCID_js.__name((logFn, name) => {
|
|
1044
1115
|
return (type, ...args) => logFn(type, ` ${chalk5__default.default.inverse.hex(BADGE_COLORS[name.split("").map((char) => char.charCodeAt(0)).reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length] || BADGE_COLORS[0])(` ${titleCase.titleCase(name)} `)} ${args.join(" ")} `);
|
|
1045
1116
|
}, "extendLog");
|
|
1046
|
-
function
|
|
1047
|
-
return
|
|
1048
|
-
}
|
|
1049
|
-
chunkSHUYVCID_js.__name(isBufferEncoding, "isBufferEncoding");
|
|
1050
|
-
function isPowerlinesWriteFileOptions(options) {
|
|
1051
|
-
return !isBufferEncoding(options) && isSetObject.isSetObject(options) && "mode" in options && (options.mode === "fs" || options.mode === "virtual");
|
|
1117
|
+
function isFileError(err) {
|
|
1118
|
+
return isError.isError(err) && "code" in err && err.code;
|
|
1052
1119
|
}
|
|
1053
|
-
chunkSHUYVCID_js.__name(
|
|
1054
|
-
function
|
|
1055
|
-
return
|
|
1120
|
+
chunkSHUYVCID_js.__name(isFileError, "isFileError");
|
|
1121
|
+
function ignoreNotfound(err) {
|
|
1122
|
+
return isFileError(err) && (err.code === "ENOENT" || err.code === "EISDIR" ? null : err);
|
|
1056
1123
|
}
|
|
1057
|
-
chunkSHUYVCID_js.__name(
|
|
1124
|
+
chunkSHUYVCID_js.__name(ignoreNotfound, "ignoreNotfound");
|
|
1058
1125
|
function toFilePath(path) {
|
|
1059
1126
|
return correctPath.correctPath(slash.slash(path?.toString() || ".").replace(/^file:\/\//, ""));
|
|
1060
1127
|
}
|
|
1061
1128
|
chunkSHUYVCID_js.__name(toFilePath, "toFilePath");
|
|
1062
|
-
var FS_METHODS = [
|
|
1063
|
-
"mkdir",
|
|
1064
|
-
"mkdirSync",
|
|
1065
|
-
"rmdir",
|
|
1066
|
-
"rmdirSync",
|
|
1067
|
-
"unlink",
|
|
1068
|
-
"unlinkSync",
|
|
1069
|
-
"existsSync",
|
|
1070
|
-
"realpathSync",
|
|
1071
|
-
"writeFileSync",
|
|
1072
|
-
"readFileSync",
|
|
1073
|
-
"readdirSync",
|
|
1074
|
-
"createWriteStream",
|
|
1075
|
-
"WriteStream",
|
|
1076
|
-
"createReadStream",
|
|
1077
|
-
"ReadStream"
|
|
1078
|
-
];
|
|
1079
|
-
var FS_PROMISE_METHODS = [
|
|
1080
|
-
"mkdir",
|
|
1081
|
-
"rm",
|
|
1082
|
-
"rmdir",
|
|
1083
|
-
"unlink",
|
|
1084
|
-
"writeFile",
|
|
1085
|
-
"readFile",
|
|
1086
|
-
"readdir",
|
|
1087
|
-
"stat",
|
|
1088
|
-
"lstat"
|
|
1089
|
-
];
|
|
1090
|
-
function cloneFS(originalFS) {
|
|
1091
|
-
const clonedFS = {
|
|
1092
|
-
...originalFS,
|
|
1093
|
-
promises: {
|
|
1094
|
-
...originalFS.promises ?? {}
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
for (const method of FS_METHODS) {
|
|
1098
|
-
if (originalFS[method]) {
|
|
1099
|
-
clonedFS[method] = originalFS[method];
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
originalFS.promises ??= {};
|
|
1103
|
-
for (const method of FS_PROMISE_METHODS) {
|
|
1104
|
-
if (originalFS.promises[method]) {
|
|
1105
|
-
clonedFS.promises ??= {};
|
|
1106
|
-
clonedFS.promises[method] = originalFS.promises[method];
|
|
1107
|
-
clonedFS[method] = originalFS.promises[method];
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
for (const prop in clonedFS) {
|
|
1111
|
-
if (isFunction.isFunction(clonedFS[prop])) {
|
|
1112
|
-
clonedFS[prop] = clonedFS[prop].bind(originalFS);
|
|
1113
|
-
if (isFunction.isFunction(clonedFS.promises[prop])) {
|
|
1114
|
-
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
for (const prop in clonedFS.promises) {
|
|
1119
|
-
if (isFunction.isFunction(clonedFS.promises[prop])) {
|
|
1120
|
-
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
return clonedFS;
|
|
1124
|
-
}
|
|
1125
|
-
chunkSHUYVCID_js.__name(cloneFS, "cloneFS");
|
|
1126
|
-
function patchFS(originalFS, vfs) {
|
|
1127
|
-
const clonedFS = cloneFS(originalFS);
|
|
1128
|
-
originalFS.mkdirSync = (file, options) => vfs.mkdirSync(toFilePath(file), options);
|
|
1129
|
-
originalFS.mkdir = (file, options, callback) => vfs.mkdir(toFilePath(file), options, callback);
|
|
1130
|
-
originalFS.promises.mkdir = async (file, options) => vfs.mkdir(toFilePath(file), options);
|
|
1131
|
-
originalFS.unlinkSync = (file) => vfs.unlinkSync(toFilePath(file));
|
|
1132
|
-
originalFS.promises.rm = async (file, options) => vfs.rm(toFilePath(file), options);
|
|
1133
|
-
originalFS.promises.unlink = async (file) => vfs.unlink(toFilePath(file));
|
|
1134
|
-
originalFS.existsSync = (file) => vfs.existsSync(toFilePath(file));
|
|
1135
|
-
Object.defineProperty(originalFS, "realpathSync", {
|
|
1136
|
-
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.realpathSync(toFilePath(file), options), "value")
|
|
1137
|
-
});
|
|
1138
|
-
originalFS.writeFileSync = (file, data, options) => vfs.writeFileSync(toFilePath(file), data, options);
|
|
1139
|
-
originalFS.promises.writeFile = async (file, data, options) => vfs.writeFile(toFilePath(file), data, options);
|
|
1140
|
-
originalFS.readFileSync = (file, options) => vfs.readFileSync(toFilePath(file), options);
|
|
1141
|
-
originalFS.promises.readFile = (file, options) => vfs.readFile(toFilePath(file), options);
|
|
1142
|
-
originalFS.readdirSync = (file, options) => vfs.readdirSync(toFilePath(file), options);
|
|
1143
|
-
originalFS.promises.readdir = (file, options) => vfs.readdir(toFilePath(file), options);
|
|
1144
|
-
Object.defineProperty(originalFS, "statSync", {
|
|
1145
|
-
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.statSync(toFilePath(file), options), "value")
|
|
1146
|
-
});
|
|
1147
|
-
originalFS.stat = (file, options) => vfs.statSync(toFilePath(file), options);
|
|
1148
|
-
originalFS.promises.stat = (file, options) => vfs.stat(toFilePath(file), options);
|
|
1149
|
-
Object.defineProperty(originalFS, "lstatSync", {
|
|
1150
|
-
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.lstatSync(toFilePath(file), options), "value")
|
|
1151
|
-
});
|
|
1152
|
-
originalFS.lstat = (file, options) => vfs.lstatSync(toFilePath(file), options);
|
|
1153
|
-
originalFS.promises.lstat = (file, options) => vfs.lstat(toFilePath(file), options);
|
|
1154
|
-
return () => {
|
|
1155
|
-
originalFS.mkdirSync = clonedFS.mkdirSync;
|
|
1156
|
-
originalFS.mkdir = clonedFS.mkdir;
|
|
1157
|
-
originalFS.promises.mkdir = clonedFS.promises.mkdir;
|
|
1158
|
-
originalFS.unlinkSync = clonedFS.unlinkSync;
|
|
1159
|
-
originalFS.promises.rm = clonedFS.promises.rm;
|
|
1160
|
-
originalFS.promises.unlink = clonedFS.promises.unlink;
|
|
1161
|
-
originalFS.existsSync = clonedFS.existsSync;
|
|
1162
|
-
originalFS.realpathSync = clonedFS.realpathSync;
|
|
1163
|
-
originalFS.writeFileSync = clonedFS.writeFileSync;
|
|
1164
|
-
originalFS.promises.writeFile = clonedFS.promises.writeFile;
|
|
1165
|
-
originalFS.readFileSync = clonedFS.readFileSync;
|
|
1166
|
-
originalFS.promises.readFile = clonedFS.promises.readFile;
|
|
1167
|
-
originalFS.readdirSync = clonedFS.readdirSync;
|
|
1168
|
-
originalFS.promises.readdir = clonedFS.promises.readdir;
|
|
1169
|
-
Object.defineProperty(originalFS, "statSync", {
|
|
1170
|
-
value: clonedFS.statSync
|
|
1171
|
-
});
|
|
1172
|
-
originalFS.stat = clonedFS.stat;
|
|
1173
|
-
originalFS.promises.stat = clonedFS.promises.stat;
|
|
1174
|
-
Object.defineProperty(originalFS, "lstatSync", {
|
|
1175
|
-
value: clonedFS.lstatSync
|
|
1176
|
-
});
|
|
1177
|
-
originalFS.lstat = clonedFS.lstat;
|
|
1178
|
-
originalFS.promises.lstat = clonedFS.promises.lstat;
|
|
1179
|
-
};
|
|
1180
|
-
}
|
|
1181
|
-
chunkSHUYVCID_js.__name(patchFS, "patchFS");
|
|
1182
1129
|
function isValidId(id, prefix = "powerlines") {
|
|
1183
1130
|
return id.replace(/^\\0/, "").startsWith(`${prefix.replace(/:$/, "")}`);
|
|
1184
1131
|
}
|
|
@@ -1188,164 +1135,368 @@ function normalizeId(id, prefix = "powerlines") {
|
|
|
1188
1135
|
}
|
|
1189
1136
|
chunkSHUYVCID_js.__name(normalizeId, "normalizeId");
|
|
1190
1137
|
function normalizePath(path, builtinsPath, prefix = "powerlines") {
|
|
1191
|
-
return isValidId(toFilePath(path), prefix) ? normalizeId(toFilePath(path), prefix).replace(new RegExp(`^${prefix.replace(/:$/, "")}:`), builtinsPath) : toFilePath(path);
|
|
1138
|
+
return isType.isAbsolutePath(path) ? path : isValidId(toFilePath(path), prefix) ? normalizeId(toFilePath(path), prefix).replace(new RegExp(`^${prefix.replace(/:$/, "")}:`), builtinsPath) : toFilePath(path);
|
|
1192
1139
|
}
|
|
1193
1140
|
chunkSHUYVCID_js.__name(normalizePath, "normalizePath");
|
|
1194
|
-
|
|
1141
|
+
function normalizeKey(key, sep = ":") {
|
|
1142
|
+
if (!key) {
|
|
1143
|
+
return "";
|
|
1144
|
+
}
|
|
1145
|
+
return key.replace(/[:/\\]/g, sep).replace(/^[:/\\]|[:/\\]$/g, "");
|
|
1146
|
+
}
|
|
1147
|
+
chunkSHUYVCID_js.__name(normalizeKey, "normalizeKey");
|
|
1148
|
+
function filterKeyByBase(key, base) {
|
|
1149
|
+
if (base) {
|
|
1150
|
+
return key.startsWith(base) && key[key.length - 1] !== "$";
|
|
1151
|
+
}
|
|
1152
|
+
return key[key.length - 1] !== "$";
|
|
1153
|
+
}
|
|
1154
|
+
chunkSHUYVCID_js.__name(filterKeyByBase, "filterKeyByBase");
|
|
1155
|
+
var BaseStorageAdapter = class {
|
|
1195
1156
|
static {
|
|
1196
|
-
chunkSHUYVCID_js.__name(this, "
|
|
1157
|
+
chunkSHUYVCID_js.__name(this, "BaseStorageAdapter");
|
|
1197
1158
|
}
|
|
1198
1159
|
/**
|
|
1199
|
-
*
|
|
1160
|
+
* Indicates whether the storage adapter has been disposed.
|
|
1200
1161
|
*/
|
|
1201
|
-
#
|
|
1162
|
+
#isDisposed = false;
|
|
1202
1163
|
/**
|
|
1203
|
-
*
|
|
1164
|
+
* Configuration options for the storage adapter.
|
|
1204
1165
|
*/
|
|
1205
|
-
|
|
1166
|
+
options;
|
|
1206
1167
|
/**
|
|
1207
|
-
*
|
|
1168
|
+
* Constructor for the BaseStorageAdapter.
|
|
1169
|
+
*
|
|
1170
|
+
* @param options - Configuration options for the storage adapter.
|
|
1208
1171
|
*/
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
return result;
|
|
1172
|
+
constructor(options = {
|
|
1173
|
+
base: "/"
|
|
1174
|
+
}) {
|
|
1175
|
+
this.options = options;
|
|
1176
|
+
this.options.base = path.resolve(options.base);
|
|
1177
|
+
this.options.isReadOnly = !!options.isReadOnly;
|
|
1217
1178
|
}
|
|
1218
1179
|
/**
|
|
1219
|
-
*
|
|
1180
|
+
* Asynchronously checks if a key exists in the storage.
|
|
1181
|
+
*
|
|
1182
|
+
* @param key - The key to check for existence.
|
|
1183
|
+
* @returns A promise that resolves to `true` if the key exists, otherwise `false`.
|
|
1220
1184
|
*/
|
|
1221
|
-
|
|
1222
|
-
return this
|
|
1185
|
+
async exists(key) {
|
|
1186
|
+
return this.existsSync(key);
|
|
1223
1187
|
}
|
|
1224
1188
|
/**
|
|
1225
|
-
*
|
|
1189
|
+
* Asynchronously retrieves the value associated with a given key.
|
|
1190
|
+
*
|
|
1191
|
+
* @param key - The key whose value is to be retrieved.
|
|
1192
|
+
* @returns A promise that resolves to the value associated with the key, or `null` if the key does not exist.
|
|
1226
1193
|
*/
|
|
1227
|
-
get
|
|
1228
|
-
return this
|
|
1194
|
+
async get(key) {
|
|
1195
|
+
return this.getSync(key);
|
|
1229
1196
|
}
|
|
1230
1197
|
/**
|
|
1231
|
-
*
|
|
1198
|
+
* Asynchronously sets the value for a given key.
|
|
1232
1199
|
*
|
|
1233
|
-
* @param
|
|
1234
|
-
* @param
|
|
1200
|
+
* @param key - The key to set the value for.
|
|
1201
|
+
* @param value - The value to set.
|
|
1235
1202
|
*/
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
if (!this.#physicalFS.existsSync(this.#context.dataPath)) {
|
|
1240
|
-
this.#physicalFS.mkdirSync(this.#context.dataPath, {
|
|
1241
|
-
recursive: true
|
|
1242
|
-
});
|
|
1203
|
+
async set(key, value) {
|
|
1204
|
+
if (!this.options.isReadOnly) {
|
|
1205
|
+
this.setSync(key, value);
|
|
1243
1206
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Asynchronously removes a key from the storage.
|
|
1210
|
+
*
|
|
1211
|
+
* @param key - The key to remove.
|
|
1212
|
+
*/
|
|
1213
|
+
async remove(key) {
|
|
1214
|
+
if (!this.options.isReadOnly) {
|
|
1215
|
+
this.removeSync(key);
|
|
1253
1216
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
this.#virtualFS.mkdirSync(this.#context.builtinsPath, {
|
|
1266
|
-
recursive: true
|
|
1267
|
-
});
|
|
1268
|
-
}
|
|
1269
|
-
if (!this.#virtualFS.existsSync(this.#context.entryPath)) {
|
|
1270
|
-
this.#virtualFS.mkdirSync(this.#context.entryPath, {
|
|
1271
|
-
recursive: true
|
|
1272
|
-
});
|
|
1273
|
-
}
|
|
1274
|
-
if (!this.#virtualFS.existsSync(this.#context.dtsPath)) {
|
|
1275
|
-
this.#virtualFS.mkdirSync(this.#context.dtsPath, {
|
|
1276
|
-
recursive: true
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
} else if (this.#context.config.projectType === "application") {
|
|
1280
|
-
if (!this.#physicalFS.existsSync(this.#context.artifactsPath)) {
|
|
1281
|
-
this.#physicalFS.mkdirSync(this.#context.artifactsPath, {
|
|
1282
|
-
recursive: true
|
|
1283
|
-
});
|
|
1284
|
-
}
|
|
1285
|
-
if (!this.#physicalFS.existsSync(this.#context.builtinsPath)) {
|
|
1286
|
-
this.#physicalFS.mkdirSync(this.#context.builtinsPath, {
|
|
1287
|
-
recursive: true
|
|
1288
|
-
});
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Synchronously removes all entries from the storage that match the provided base path.
|
|
1220
|
+
*
|
|
1221
|
+
* @param base - The base path to clear keys from.
|
|
1222
|
+
*/
|
|
1223
|
+
clearSync(base) {
|
|
1224
|
+
if (!this.options.isReadOnly) {
|
|
1225
|
+
const keys = this.listSync(base || this.options.base);
|
|
1226
|
+
if (!keys.length) {
|
|
1227
|
+
return;
|
|
1289
1228
|
}
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1229
|
+
keys.map((key) => this.removeSync(base && !key.startsWith(base) ? join.joinPaths(base, key) : key));
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* Asynchronously removes all entries from the storage that match the provided base path.
|
|
1234
|
+
*
|
|
1235
|
+
* @param base - The base path to clear keys from.
|
|
1236
|
+
* @returns A promise that resolves when the operation is complete.
|
|
1237
|
+
*/
|
|
1238
|
+
async clear(base) {
|
|
1239
|
+
if (!this.options.isReadOnly) {
|
|
1240
|
+
const keys = await this.list(base || this.options.base);
|
|
1241
|
+
if (!keys.length) {
|
|
1242
|
+
return;
|
|
1294
1243
|
}
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1244
|
+
await Promise.all(keys.map(async (key) => this.remove(base && !key.startsWith(base) ? join.joinPaths(base, key) : key)));
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Asynchronously lists all keys under a given base path.
|
|
1249
|
+
*
|
|
1250
|
+
* @param base - The base path to list keys from.
|
|
1251
|
+
* @returns A promise that resolves to an array of keys under the specified base path.
|
|
1252
|
+
*/
|
|
1253
|
+
async list(base) {
|
|
1254
|
+
return this.listSync(base);
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Disposes of the storage adapter, releasing any held resources.
|
|
1258
|
+
*
|
|
1259
|
+
* @returns A promise that resolves when the disposal is complete.
|
|
1260
|
+
*/
|
|
1261
|
+
dispose() {
|
|
1262
|
+
return Promise.resolve();
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Async dispose method to clean up resources.
|
|
1266
|
+
*
|
|
1267
|
+
* @returns A promise that resolves when disposal is complete.
|
|
1268
|
+
*/
|
|
1269
|
+
async [Symbol.asyncDispose]() {
|
|
1270
|
+
return this._dispose();
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Resolves a given key to its full path within the storage adapter.
|
|
1274
|
+
*
|
|
1275
|
+
* @param key - The key to resolve.
|
|
1276
|
+
* @returns The resolved full path for the key.
|
|
1277
|
+
*/
|
|
1278
|
+
resolve(key = this.options.base) {
|
|
1279
|
+
if (/\.\.:|\.\.$/.test(key)) {
|
|
1280
|
+
throw new Error(`[${this.name}]: Invalid key: ${JSON.stringify(key)} provided to storage adapter.`);
|
|
1281
|
+
}
|
|
1282
|
+
return append.appendPath(correctPath.correctPath(key).replace(/:/g, "/"), this.options.base);
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Disposes of the storage adapter, releasing any held resources.
|
|
1286
|
+
*
|
|
1287
|
+
* @returns A promise that resolves when the disposal is complete.
|
|
1288
|
+
*/
|
|
1289
|
+
async _dispose() {
|
|
1290
|
+
if (!this.#isDisposed) {
|
|
1291
|
+
await Promise.resolve(this.dispose());
|
|
1292
|
+
this.#isDisposed = true;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
// ../powerlines/src/lib/fs/storage/file-system.ts
|
|
1298
|
+
var FileSystemStorageAdapter = class extends BaseStorageAdapter {
|
|
1299
|
+
static {
|
|
1300
|
+
chunkSHUYVCID_js.__name(this, "FileSystemStorageAdapter");
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* A name identifying the storage adapter type.
|
|
1304
|
+
*/
|
|
1305
|
+
name = "file-system";
|
|
1306
|
+
/**
|
|
1307
|
+
* Constructor for the FileSystemStorageAdapter.
|
|
1308
|
+
*
|
|
1309
|
+
* @param options - Configuration options for the storage adapter.
|
|
1310
|
+
*/
|
|
1311
|
+
constructor(options) {
|
|
1312
|
+
super(options);
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Synchronously checks if a key exists in the storage.
|
|
1316
|
+
*
|
|
1317
|
+
* @param key - The key to check for existence.
|
|
1318
|
+
* @returns Returns `true` if the key exists, otherwise `false`.
|
|
1319
|
+
*/
|
|
1320
|
+
existsSync(key) {
|
|
1321
|
+
return exists.existsSync(this.resolve(key));
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Asynchronously checks if a key exists in the storage.
|
|
1325
|
+
*
|
|
1326
|
+
* @param key - The key to check for existence.
|
|
1327
|
+
* @returns A promise that resolves to `true` if the key exists, otherwise `false`.
|
|
1328
|
+
*/
|
|
1329
|
+
async exists(key) {
|
|
1330
|
+
return exists.exists(this.resolve(key));
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Synchronously retrieves the value associated with a given key.
|
|
1334
|
+
*
|
|
1335
|
+
* @param key - The key whose value is to be retrieved.
|
|
1336
|
+
* @returns The value associated with the key, or `null` if the key does not exist.
|
|
1337
|
+
*/
|
|
1338
|
+
getSync(key) {
|
|
1339
|
+
return readFile.readFileSync(this.resolve(key));
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Asynchronously retrieves the value associated with a given key.
|
|
1343
|
+
*
|
|
1344
|
+
* @param key - The key whose value is to be retrieved.
|
|
1345
|
+
* @returns A promise that resolves to the value associated with the key, or `null` if the key does not exist.
|
|
1346
|
+
*/
|
|
1347
|
+
async get(key) {
|
|
1348
|
+
return readFile.readFile(this.resolve(key));
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Synchronously sets the value for a given key.
|
|
1352
|
+
*
|
|
1353
|
+
* @param key - The key to set the value for.
|
|
1354
|
+
* @param value - The value to set.
|
|
1355
|
+
*/
|
|
1356
|
+
setSync(key, value) {
|
|
1357
|
+
if (!this.options.isReadOnly) {
|
|
1358
|
+
return writeFile$1.writeFileSync(this.resolve(key), value);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
/**
|
|
1362
|
+
* Asynchronously sets the value for a given key.
|
|
1363
|
+
*
|
|
1364
|
+
* @param key - The key to set the value for.
|
|
1365
|
+
* @param value - The value to set.
|
|
1366
|
+
*/
|
|
1367
|
+
async set(key, value) {
|
|
1368
|
+
if (!this.options.isReadOnly) {
|
|
1369
|
+
return writeFile$1.writeFile(this.resolve(key), value);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* Synchronously removes a key from the storage.
|
|
1374
|
+
*
|
|
1375
|
+
* @param key - The key to remove.
|
|
1376
|
+
*/
|
|
1377
|
+
removeSync(key) {
|
|
1378
|
+
if (!this.options.isReadOnly) {
|
|
1379
|
+
try {
|
|
1380
|
+
return fs.unlinkSync(this.resolve(key));
|
|
1381
|
+
} catch (err) {
|
|
1382
|
+
return ignoreNotfound(err);
|
|
1299
1383
|
}
|
|
1300
1384
|
}
|
|
1301
1385
|
}
|
|
1302
1386
|
/**
|
|
1303
|
-
*
|
|
1387
|
+
* Asynchronously removes a key from the storage.
|
|
1304
1388
|
*
|
|
1305
|
-
* @param
|
|
1306
|
-
* @param options - Options for the operation, such as output mode.
|
|
1307
|
-
* @returns The file system module used for the operation.
|
|
1389
|
+
* @param key - The key to remove.
|
|
1308
1390
|
*/
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
return {
|
|
1313
|
-
...this.#virtualFS,
|
|
1314
|
-
mode: "virtual"
|
|
1315
|
-
};
|
|
1316
|
-
} else if (mode === "fs") {
|
|
1317
|
-
return {
|
|
1318
|
-
...this.#physicalFS,
|
|
1319
|
-
mode: "fs"
|
|
1320
|
-
};
|
|
1391
|
+
async remove(key) {
|
|
1392
|
+
if (!this.options.isReadOnly) {
|
|
1393
|
+
return promises.unlink(this.resolve(key)).catch(ignoreNotfound);
|
|
1321
1394
|
}
|
|
1322
|
-
return {
|
|
1323
|
-
...this,
|
|
1324
|
-
mode: this.#context.config.output.mode
|
|
1325
|
-
};
|
|
1326
1395
|
}
|
|
1327
1396
|
/**
|
|
1328
|
-
*
|
|
1397
|
+
* Lists all keys under a given base path synchronously.
|
|
1398
|
+
*
|
|
1399
|
+
* @param base - The base path to list keys from.
|
|
1400
|
+
* @returns An array of keys under the specified base path.
|
|
1401
|
+
*/
|
|
1402
|
+
listSync(base) {
|
|
1403
|
+
try {
|
|
1404
|
+
return listFiles.listFilesSync(this.resolve(base), {
|
|
1405
|
+
ignore: this.options.ignore
|
|
1406
|
+
});
|
|
1407
|
+
} catch (err) {
|
|
1408
|
+
return ignoreNotfound(err) ?? [];
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Asynchronously lists all keys under a given base path.
|
|
1413
|
+
*
|
|
1414
|
+
* @param base - The base path to list keys from.
|
|
1415
|
+
* @returns A promise that resolves to an array of keys under the specified base path.
|
|
1416
|
+
*/
|
|
1417
|
+
async list(base) {
|
|
1418
|
+
return listFiles.listFiles(this.resolve(base), {
|
|
1419
|
+
ignore: this.options.ignore
|
|
1420
|
+
}).catch(ignoreNotfound).then((r) => r || []);
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
var VirtualStorageAdapter = class extends BaseStorageAdapter {
|
|
1424
|
+
static {
|
|
1425
|
+
chunkSHUYVCID_js.__name(this, "VirtualStorageAdapter");
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* A name identifying the storage adapter type.
|
|
1429
|
+
*/
|
|
1430
|
+
name = "virtual";
|
|
1431
|
+
/**
|
|
1432
|
+
* In-memory data storage.
|
|
1433
|
+
*/
|
|
1434
|
+
data = /* @__PURE__ */ new Map();
|
|
1435
|
+
/**
|
|
1436
|
+
* Constructor for the VirtualStorageAdapter.
|
|
1437
|
+
*
|
|
1438
|
+
* @param options - Configuration options for the storage adapter.
|
|
1439
|
+
*/
|
|
1440
|
+
constructor(options) {
|
|
1441
|
+
super(options);
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Synchronously checks if a key exists in the storage.
|
|
1329
1445
|
*
|
|
1330
|
-
* @param
|
|
1331
|
-
* @
|
|
1332
|
-
* @returns The file system module used for the operation.
|
|
1446
|
+
* @param key - The key to check for existence.
|
|
1447
|
+
* @returns Returns `true` if the key exists, otherwise `false`.
|
|
1333
1448
|
*/
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1449
|
+
existsSync(key) {
|
|
1450
|
+
return this.data.has(this.resolve(key));
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Synchronously retrieves the value associated with a given key.
|
|
1454
|
+
*
|
|
1455
|
+
* @param key - The key whose value is to be retrieved.
|
|
1456
|
+
* @returns The value associated with the key, or `null` if the key does not exist.
|
|
1457
|
+
*/
|
|
1458
|
+
getSync(key) {
|
|
1459
|
+
return this.data.get(this.resolve(key)) ?? null;
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Synchronously sets the value for a given key.
|
|
1463
|
+
*
|
|
1464
|
+
* @param key - The key to set the value for.
|
|
1465
|
+
* @param value - The value to set.
|
|
1466
|
+
*/
|
|
1467
|
+
setSync(key, value) {
|
|
1468
|
+
if (!this.options.isReadOnly) {
|
|
1469
|
+
this.data.set(this.resolve(key), value);
|
|
1339
1470
|
}
|
|
1340
|
-
return void 0;
|
|
1341
1471
|
}
|
|
1342
1472
|
/**
|
|
1343
|
-
*
|
|
1473
|
+
* Synchronously removes a key from the storage.
|
|
1344
1474
|
*
|
|
1345
|
-
* @
|
|
1475
|
+
* @param key - The key to remove.
|
|
1346
1476
|
*/
|
|
1347
|
-
|
|
1348
|
-
|
|
1477
|
+
removeSync(key) {
|
|
1478
|
+
if (!this.options.isReadOnly) {
|
|
1479
|
+
this.data.delete(this.resolve(key));
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Lists all keys under a given base path synchronously.
|
|
1484
|
+
*
|
|
1485
|
+
* @param base - The base path to list keys from.
|
|
1486
|
+
* @returns An array of keys under the specified base path.
|
|
1487
|
+
*/
|
|
1488
|
+
listSync(base) {
|
|
1489
|
+
return [
|
|
1490
|
+
...this.data.keys().filter((key) => !base ? true : isParentPath.isParentPath(key, this.resolve(base)))
|
|
1491
|
+
];
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Disposes of the storage adapter, releasing any held resources.
|
|
1495
|
+
*
|
|
1496
|
+
* @returns A promise that resolves when the disposal is complete.
|
|
1497
|
+
*/
|
|
1498
|
+
async dispose() {
|
|
1499
|
+
return this.clear();
|
|
1349
1500
|
}
|
|
1350
1501
|
};
|
|
1351
1502
|
|
|
@@ -1367,29 +1518,23 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1367
1518
|
*/
|
|
1368
1519
|
#paths;
|
|
1369
1520
|
/**
|
|
1370
|
-
* A cache for module resolution results.
|
|
1371
|
-
*/
|
|
1372
|
-
#resolverCache;
|
|
1373
|
-
/**
|
|
1374
1521
|
* The unified volume that combines the virtual file system with the real file system.
|
|
1375
1522
|
*
|
|
1376
1523
|
* @remarks
|
|
1377
1524
|
* This volume allows for seamless access to both virtual and real files.
|
|
1378
1525
|
*/
|
|
1379
|
-
#
|
|
1526
|
+
#storage = {
|
|
1527
|
+
"": new FileSystemStorageAdapter()
|
|
1528
|
+
};
|
|
1380
1529
|
/**
|
|
1381
|
-
*
|
|
1530
|
+
* A cache for module resolution results.
|
|
1382
1531
|
*/
|
|
1383
|
-
#
|
|
1532
|
+
#resolverCache;
|
|
1384
1533
|
/**
|
|
1385
1534
|
* Indicator specifying if the virtual file system (VFS) is disposed
|
|
1386
1535
|
*/
|
|
1387
1536
|
#isDisposed = false;
|
|
1388
1537
|
/**
|
|
1389
|
-
* Function to revert require patch
|
|
1390
|
-
*/
|
|
1391
|
-
#revert;
|
|
1392
|
-
/**
|
|
1393
1538
|
* The context of the virtual file system.
|
|
1394
1539
|
*/
|
|
1395
1540
|
#context;
|
|
@@ -1398,15 +1543,6 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1398
1543
|
*/
|
|
1399
1544
|
#log;
|
|
1400
1545
|
/**
|
|
1401
|
-
* Checks if a path exists in the virtual file system (VFS).
|
|
1402
|
-
*
|
|
1403
|
-
* @param path - The path to check.
|
|
1404
|
-
* @returns `true` if the path exists, otherwise `false`.
|
|
1405
|
-
*/
|
|
1406
|
-
#existsSync(path) {
|
|
1407
|
-
return this.#unifiedFS.virtual.existsSync(this.#normalizePath(path)) || this.#unifiedFS.physical.existsSync(this.#normalizePath(path)) || this.#unifiedFS.resolveFS(path).existsSync(this.#normalizePath(path));
|
|
1408
|
-
}
|
|
1409
|
-
/**
|
|
1410
1546
|
* Normalizes a given module id by resolving it against the built-ins path.
|
|
1411
1547
|
*
|
|
1412
1548
|
* @param id - The module id to normalize.
|
|
@@ -1435,6 +1571,43 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1435
1571
|
return new RegExp(`^${this.#normalizePath(path).replace(/\*\*/g, token).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(new RegExp(token, "g"), ".*")}$`);
|
|
1436
1572
|
}
|
|
1437
1573
|
/**
|
|
1574
|
+
* Gets the storage adapter and relative key for a given key.
|
|
1575
|
+
*
|
|
1576
|
+
* @param key - The key to get the storage adapter for.
|
|
1577
|
+
* @returns The storage adapter and relative key for the given key.
|
|
1578
|
+
*/
|
|
1579
|
+
#getStorage(key) {
|
|
1580
|
+
const path = this.resolveSync(this.#normalizePath(key)) || key;
|
|
1581
|
+
for (const base of Object.keys(this.#storage).filter(Boolean).sort().reverse()) {
|
|
1582
|
+
if (isParentPath.isParentPath(path, base)) {
|
|
1583
|
+
return {
|
|
1584
|
+
base,
|
|
1585
|
+
relativeKey: replace.replacePath(path, base),
|
|
1586
|
+
adapter: this.#storage[base]
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
return {
|
|
1591
|
+
base: "",
|
|
1592
|
+
relativeKey: path,
|
|
1593
|
+
adapter: this.#storage[""]
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Gets all storage adapters that match a given base key.
|
|
1598
|
+
*
|
|
1599
|
+
* @param base - The base key to match storage adapters against.
|
|
1600
|
+
* @param includeParent - Whether to include parent storage adapters.
|
|
1601
|
+
* @returns An array of storage adapters that match the given base key.
|
|
1602
|
+
*/
|
|
1603
|
+
#getStorages(base = "", includeParent = false) {
|
|
1604
|
+
return Object.keys(this.#storage).sort().reverse().filter((key) => isParentPath.isParentPath(key, base) || includeParent && isParentPath.isParentPath(base, key)).map((key) => ({
|
|
1605
|
+
relativeBase: base.length > key.length ? base.slice(key.length) : void 0,
|
|
1606
|
+
base: key,
|
|
1607
|
+
adapter: this.#storage[key]
|
|
1608
|
+
}));
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1438
1611
|
* Creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
|
|
1439
1612
|
*
|
|
1440
1613
|
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
@@ -1444,7 +1617,13 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1444
1617
|
if (!context.config.skipCache && exists.existsSync(joinPaths.joinPaths(context.dataPath, "fs.bin"))) {
|
|
1445
1618
|
const buffer$1 = await buffer.readFileBuffer(joinPaths.joinPaths(context.dataPath, "fs.bin"));
|
|
1446
1619
|
const message2 = new $__namespace.Message(buffer$1, false);
|
|
1447
|
-
|
|
1620
|
+
const fs = message2.getRoot(FileSystem);
|
|
1621
|
+
const result = new _VirtualFileSystem(context, fs);
|
|
1622
|
+
if (fs._hasStorage() && fs.storage.length > 0) {
|
|
1623
|
+
await Promise.all(fs.storage.values().map(async (file) => {
|
|
1624
|
+
await result.write(file.path, file.code);
|
|
1625
|
+
}));
|
|
1626
|
+
}
|
|
1448
1627
|
}
|
|
1449
1628
|
const message = new $__namespace.Message();
|
|
1450
1629
|
return new _VirtualFileSystem(context, message.initRoot(FileSystem));
|
|
@@ -1459,7 +1638,13 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1459
1638
|
if (!context.config.skipCache && exists.existsSync(joinPaths.joinPaths(context.dataPath, "fs.bin"))) {
|
|
1460
1639
|
const buffer$1 = buffer.readFileBufferSync(joinPaths.joinPaths(context.dataPath, "fs.bin"));
|
|
1461
1640
|
const message2 = new $__namespace.Message(buffer$1, false);
|
|
1462
|
-
|
|
1641
|
+
const fs = message2.getRoot(FileSystem);
|
|
1642
|
+
const result = new _VirtualFileSystem(context, fs);
|
|
1643
|
+
if (fs._hasStorage() && fs.storage.length > 0) {
|
|
1644
|
+
fs.storage.values().map((file) => {
|
|
1645
|
+
result.writeSync(file.path, file.code);
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1463
1648
|
}
|
|
1464
1649
|
const message = new $__namespace.Message();
|
|
1465
1650
|
return new _VirtualFileSystem(context, message.initRoot(FileSystem));
|
|
@@ -1494,6 +1679,9 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1494
1679
|
}, "get")
|
|
1495
1680
|
});
|
|
1496
1681
|
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Gets the resolver cache.
|
|
1684
|
+
*/
|
|
1497
1685
|
get resolverCache() {
|
|
1498
1686
|
if (!this.#resolverCache) {
|
|
1499
1687
|
this.#resolverCache = flatCache.create({
|
|
@@ -1512,16 +1700,34 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1512
1700
|
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
1513
1701
|
* @param fs - A buffer containing the serialized virtual file system data.
|
|
1514
1702
|
*/
|
|
1515
|
-
constructor(context,
|
|
1703
|
+
constructor(context, fs) {
|
|
1516
1704
|
this.#context = context;
|
|
1517
|
-
|
|
1705
|
+
if (isSetObject.isSetObject(this.#context.config.output.storage)) {
|
|
1706
|
+
this.#storage = {
|
|
1707
|
+
...this.#storage,
|
|
1708
|
+
...this.#context.config.output.storage
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1711
|
+
this.#storage.virtual ??= new VirtualStorageAdapter({
|
|
1712
|
+
base: "/_virtual"
|
|
1713
|
+
});
|
|
1714
|
+
if (this.#context.config.output.storage !== StoragePreset.FS) {
|
|
1715
|
+
this.#storage[this.#context.artifactsPath] ??= new VirtualStorageAdapter({
|
|
1716
|
+
base: this.#context.artifactsPath
|
|
1717
|
+
});
|
|
1718
|
+
this.#storage[this.#context.builtinsPath] ??= new VirtualStorageAdapter({
|
|
1719
|
+
base: this.#context.builtinsPath
|
|
1720
|
+
});
|
|
1721
|
+
this.#storage[this.#context.entryPath] ??= new VirtualStorageAdapter({
|
|
1722
|
+
base: this.#context.entryPath
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1518
1725
|
this.#metadata = {};
|
|
1519
|
-
if (
|
|
1520
|
-
this.#metadata =
|
|
1726
|
+
if (fs._hasMetadata()) {
|
|
1727
|
+
this.#metadata = fs.metadata.values().reduce((ret, metadata) => {
|
|
1521
1728
|
ret[metadata.id] = {
|
|
1522
1729
|
id: metadata.id,
|
|
1523
1730
|
type: metadata.type,
|
|
1524
|
-
mode: metadata.mode,
|
|
1525
1731
|
timestamp: metadata.timestamp || Date.now(),
|
|
1526
1732
|
properties: metadata._hasProperties() ? metadata.properties.values().reduce((ret2, item) => {
|
|
1527
1733
|
ret2[item.key] = item.value;
|
|
@@ -1533,12 +1739,12 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1533
1739
|
}
|
|
1534
1740
|
this.#ids = {};
|
|
1535
1741
|
this.#paths = {};
|
|
1536
|
-
if (
|
|
1537
|
-
this.#ids =
|
|
1742
|
+
if (fs._hasIds()) {
|
|
1743
|
+
this.#ids = fs.ids.values().reduce((ret, identifier) => {
|
|
1538
1744
|
ret[identifier.path] ??= identifier.id;
|
|
1539
1745
|
return ret;
|
|
1540
1746
|
}, {});
|
|
1541
|
-
this.#paths =
|
|
1747
|
+
this.#paths = fs.ids.values().reduce((ret, identifier) => {
|
|
1542
1748
|
ret[identifier.id] ??= identifier.path;
|
|
1543
1749
|
return ret;
|
|
1544
1750
|
}, {});
|
|
@@ -1546,187 +1752,123 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1546
1752
|
this.#log = extendLog(this.#context.log, "file-system");
|
|
1547
1753
|
}
|
|
1548
1754
|
/**
|
|
1549
|
-
*
|
|
1550
|
-
*
|
|
1551
|
-
* @param pathOrId - The path or id to check.
|
|
1552
|
-
* @returns Whether the path or id corresponds to a virtual file **(does not actually exists on disk)**.
|
|
1553
|
-
*/
|
|
1554
|
-
isVirtual(pathOrId, importer, options = {}) {
|
|
1555
|
-
if (!pathOrId) {
|
|
1556
|
-
return false;
|
|
1557
|
-
}
|
|
1558
|
-
const resolvedPath = this.resolveSync(pathOrId, importer, options);
|
|
1559
|
-
if (!resolvedPath) {
|
|
1560
|
-
return false;
|
|
1561
|
-
}
|
|
1562
|
-
return this.metadata[resolvedPath]?.mode === "virtual";
|
|
1563
|
-
}
|
|
1564
|
-
/**
|
|
1565
|
-
* Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
|
|
1566
|
-
*
|
|
1567
|
-
* @param pathOrId - The path or id to check.
|
|
1568
|
-
* @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
|
|
1569
|
-
*/
|
|
1570
|
-
isPhysical(pathOrId, importer, options = {}) {
|
|
1571
|
-
if (!pathOrId) {
|
|
1572
|
-
return false;
|
|
1573
|
-
}
|
|
1574
|
-
const resolvedPath = this.resolveSync(pathOrId, importer, options);
|
|
1575
|
-
if (!resolvedPath) {
|
|
1576
|
-
return false;
|
|
1577
|
-
}
|
|
1578
|
-
return this.metadata[resolvedPath]?.mode === "fs";
|
|
1579
|
-
}
|
|
1580
|
-
/**
|
|
1581
|
-
* Lists files in a given path.
|
|
1582
|
-
*
|
|
1583
|
-
* @param path - The path to list files from.
|
|
1584
|
-
* @param options - Options for listing files, such as encoding and recursion.
|
|
1585
|
-
* @returns An array of file names in the specified path.
|
|
1586
|
-
*/
|
|
1587
|
-
readdirSync(path, options = "utf8") {
|
|
1588
|
-
return this.#unifiedFS.resolveFS(path).readdirSync(toFilePath(path), options);
|
|
1589
|
-
}
|
|
1590
|
-
/**
|
|
1591
|
-
* Removes a file in the virtual file system (VFS).
|
|
1755
|
+
* Asynchronously checks if a file exists in the virtual file system (VFS).
|
|
1592
1756
|
*
|
|
1593
|
-
* @param path - The path to
|
|
1757
|
+
* @param path - The path to the file.
|
|
1758
|
+
* @returns A promise that resolves to `true` if the file exists, otherwise `false`.
|
|
1594
1759
|
*/
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
}
|
|
1599
|
-
this.#log(types.LogLevelLabel.TRACE, `Synchronously removing file: ${this.#normalizePath(path)}`);
|
|
1600
|
-
this.#unifiedFS.resolveFS(path, options).unlinkSync(this.#normalizePath(path));
|
|
1601
|
-
if (this.#ids[this.#normalizePath(path)] && this.#metadata[this.#ids[this.#normalizePath(path)]]) {
|
|
1602
|
-
delete this.#metadata[this.#ids[this.#normalizePath(path)]];
|
|
1603
|
-
delete this.#ids[this.#normalizePath(path)];
|
|
1604
|
-
delete this.#paths[this.#normalizeId(path)];
|
|
1605
|
-
this.#resolverCache.delete(this.#normalizePath(path));
|
|
1606
|
-
}
|
|
1760
|
+
async exists(path) {
|
|
1761
|
+
const { relativeKey, adapter } = this.#getStorage(path);
|
|
1762
|
+
return adapter.exists(relativeKey);
|
|
1607
1763
|
}
|
|
1608
1764
|
/**
|
|
1609
|
-
*
|
|
1610
|
-
*
|
|
1611
|
-
* @param path - The path to create the directory at.
|
|
1612
|
-
*/
|
|
1613
|
-
async unlink(path, options) {
|
|
1614
|
-
if (!this.isFile(this.#normalizePath(path))) {
|
|
1615
|
-
return;
|
|
1616
|
-
}
|
|
1617
|
-
this.#log(types.LogLevelLabel.TRACE, `Removing file: ${this.#normalizePath(path)}`);
|
|
1618
|
-
if (isFunction.isFunction(this.#unifiedFS.resolveFS(path, options).promises.unlink)) {
|
|
1619
|
-
await this.#unifiedFS.resolveFS(path, options).promises.unlink(this.#normalizePath(path));
|
|
1620
|
-
if (this.#ids[this.#normalizePath(path)] && this.#metadata[this.#ids[this.#normalizePath(path)]]) {
|
|
1621
|
-
delete this.#metadata[this.#ids[this.#normalizePath(path)]];
|
|
1622
|
-
}
|
|
1623
|
-
} else {
|
|
1624
|
-
this.unlinkSync(this.#normalizePath(path), options);
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
/**
|
|
1628
|
-
* Removes a directory in the virtual file system (VFS).
|
|
1765
|
+
* Synchronously checks if a file exists in the virtual file system (VFS).
|
|
1629
1766
|
*
|
|
1630
|
-
* @param path - The path to
|
|
1631
|
-
* @
|
|
1767
|
+
* @param path - The path to the file.
|
|
1768
|
+
* @returns `true` if the file exists, otherwise `false`.
|
|
1632
1769
|
*/
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
}
|
|
1637
|
-
this.#log(types.LogLevelLabel.TRACE, `Synchronously removing directory: ${this.#normalizePath(path)}`);
|
|
1638
|
-
this.#unifiedFS.resolveFS(path, options).rmdirSync(this.#normalizePath(path), defu5__default.default(options, {
|
|
1639
|
-
recursive: true
|
|
1640
|
-
}));
|
|
1770
|
+
existsSync(path) {
|
|
1771
|
+
const { relativeKey, adapter } = this.#getStorage(path);
|
|
1772
|
+
return adapter.existsSync(relativeKey);
|
|
1641
1773
|
}
|
|
1642
1774
|
/**
|
|
1643
|
-
*
|
|
1775
|
+
* Checks if a file is virtual in the virtual file system (VFS).
|
|
1644
1776
|
*
|
|
1645
|
-
* @param path - The path to
|
|
1646
|
-
* @
|
|
1647
|
-
* @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
|
|
1777
|
+
* @param path - The path to the file.
|
|
1778
|
+
* @returns `true` if the file is virtual, otherwise `false`.
|
|
1648
1779
|
*/
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
this.#log(types.LogLevelLabel.TRACE, `Removing directory: ${this.#normalizePath(path)}`);
|
|
1654
|
-
if (isFunction.isFunction(this.#unifiedFS.resolveFS(path, options).promises.rm)) {
|
|
1655
|
-
await this.#unifiedFS.resolveFS(path, options).promises.rm(this.#normalizePath(path), defu5__default.default(options, {
|
|
1656
|
-
force: true,
|
|
1657
|
-
recursive: true
|
|
1658
|
-
}));
|
|
1659
|
-
} else {
|
|
1660
|
-
this.rmdirSync(this.#normalizePath(path), defu5__default.default(options ?? {}, {
|
|
1661
|
-
force: true,
|
|
1662
|
-
recursive: true
|
|
1663
|
-
}));
|
|
1780
|
+
isVirtual(path) {
|
|
1781
|
+
const resolved = this.resolveSync(path);
|
|
1782
|
+
if (!resolved) {
|
|
1783
|
+
return false;
|
|
1664
1784
|
}
|
|
1785
|
+
return this.#getStorage(resolved)?.adapter?.name === "virtual";
|
|
1665
1786
|
}
|
|
1666
1787
|
/**
|
|
1667
|
-
*
|
|
1788
|
+
* Lists files in a given path.
|
|
1668
1789
|
*
|
|
1669
|
-
* @param path - The path to
|
|
1670
|
-
* @
|
|
1671
|
-
* @returns A promise that resolves when the file is removed.
|
|
1790
|
+
* @param path - The path to list files from.
|
|
1791
|
+
* @returns An array of file names in the specified path.
|
|
1672
1792
|
*/
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1793
|
+
listSync(path) {
|
|
1794
|
+
let maskedMounts = [];
|
|
1795
|
+
const allKeys = [];
|
|
1796
|
+
for (const storage of this.#getStorages(path, true)) {
|
|
1797
|
+
for (const key of storage.adapter.listSync(storage.relativeBase)) {
|
|
1798
|
+
if (!maskedMounts.some((p) => `${storage.base}${normalizeKey(key)}`.startsWith(p))) {
|
|
1799
|
+
allKeys.push(`${storage.base}${normalizeKey(key)}`);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
maskedMounts = [
|
|
1803
|
+
storage.base,
|
|
1804
|
+
...maskedMounts.filter((p) => !p.startsWith(storage.base))
|
|
1805
|
+
];
|
|
1677
1806
|
}
|
|
1678
|
-
return
|
|
1807
|
+
return allKeys.filter((key) => filterKeyByBase(key, path));
|
|
1679
1808
|
}
|
|
1680
1809
|
/**
|
|
1681
|
-
*
|
|
1810
|
+
* Lists files in a given path.
|
|
1682
1811
|
*
|
|
1683
|
-
* @param path - The path to
|
|
1684
|
-
* @
|
|
1812
|
+
* @param path - The path to list files from.
|
|
1813
|
+
* @returns An array of file names in the specified path.
|
|
1685
1814
|
*/
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1815
|
+
async list(path) {
|
|
1816
|
+
let maskedMounts = [];
|
|
1817
|
+
const allKeys = [];
|
|
1818
|
+
for (const storage of this.#getStorages(path, true)) {
|
|
1819
|
+
for (const key of await storage.adapter.list(storage.relativeBase)) {
|
|
1820
|
+
if (!maskedMounts.some((p) => `${storage.base}${normalizeKey(key)}`.startsWith(p))) {
|
|
1821
|
+
allKeys.push(`${storage.base}${normalizeKey(key)}`);
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
maskedMounts = [
|
|
1825
|
+
storage.base,
|
|
1826
|
+
...maskedMounts.filter((p) => !p.startsWith(storage.base))
|
|
1827
|
+
];
|
|
1690
1828
|
}
|
|
1691
|
-
return
|
|
1829
|
+
return allKeys.filter((key) => filterKeyByBase(key, path));
|
|
1692
1830
|
}
|
|
1693
1831
|
/**
|
|
1694
|
-
*
|
|
1832
|
+
* Removes a file in the virtual file system (VFS).
|
|
1695
1833
|
*
|
|
1696
1834
|
* @param path - The path to create the directory at.
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1835
|
+
*/
|
|
1836
|
+
async remove(path) {
|
|
1837
|
+
const normalizedPath = this.#normalizePath(path);
|
|
1838
|
+
this.#log(types.LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
|
|
1839
|
+
const { relativeKey, adapter } = this.#getStorage(normalizedPath);
|
|
1840
|
+
if (filePathFns.hasFileExtension(normalizedPath)) {
|
|
1841
|
+
await adapter.remove(relativeKey);
|
|
1842
|
+
} else {
|
|
1843
|
+
await adapter.clear(relativeKey);
|
|
1844
|
+
}
|
|
1845
|
+
const id = this.#ids[normalizedPath];
|
|
1846
|
+
if (id && this.#metadata[id]) {
|
|
1847
|
+
delete this.#metadata[id];
|
|
1848
|
+
delete this.#ids[normalizedPath];
|
|
1849
|
+
delete this.#paths[id];
|
|
1850
|
+
}
|
|
1706
1851
|
}
|
|
1707
1852
|
/**
|
|
1708
|
-
*
|
|
1853
|
+
* Removes a file in the virtual file system (VFS).
|
|
1709
1854
|
*
|
|
1710
1855
|
* @param path - The path to create the directory at.
|
|
1711
|
-
* @param options - Options for creating the directory.
|
|
1712
|
-
* @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
|
|
1713
1856
|
*/
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
recursive: true
|
|
1721
|
-
}));
|
|
1857
|
+
removeSync(path) {
|
|
1858
|
+
const normalizedPath = this.#normalizePath(path);
|
|
1859
|
+
this.#log(types.LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
|
|
1860
|
+
const { relativeKey, adapter } = this.#getStorage(normalizedPath);
|
|
1861
|
+
if (filePathFns.hasFileExtension(normalizedPath)) {
|
|
1862
|
+
adapter.removeSync(relativeKey);
|
|
1722
1863
|
} else {
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1864
|
+
adapter.clearSync(relativeKey);
|
|
1865
|
+
}
|
|
1866
|
+
const id = this.#ids[normalizedPath];
|
|
1867
|
+
if (id && this.#metadata[id]) {
|
|
1868
|
+
delete this.#metadata[id];
|
|
1869
|
+
delete this.#ids[normalizedPath];
|
|
1870
|
+
delete this.#paths[id];
|
|
1728
1871
|
}
|
|
1729
|
-
return result;
|
|
1730
1872
|
}
|
|
1731
1873
|
/**
|
|
1732
1874
|
* Glob files in the virtual file system (VFS) based on the provided pattern(s).
|
|
@@ -1748,38 +1890,14 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1748
1890
|
const absPattern = isType.isAbsolutePath(normalized) ? normalized : this.#normalizePath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, normalized));
|
|
1749
1891
|
const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
|
|
1750
1892
|
const baseDir = firstGlobIdx === -1 ? filePathFns.findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
let entries = [];
|
|
1757
|
-
try {
|
|
1758
|
-
entries = await this.readdir(dir);
|
|
1759
|
-
} catch {
|
|
1760
|
-
continue;
|
|
1761
|
-
}
|
|
1762
|
-
for (const entry of entries) {
|
|
1763
|
-
const full = this.#normalizePath(joinPaths.joinPaths(dir, entry));
|
|
1764
|
-
let stats;
|
|
1765
|
-
try {
|
|
1766
|
-
stats = this.#unifiedFS.lstatSync(full);
|
|
1767
|
-
} catch {
|
|
1768
|
-
stats = void 0;
|
|
1769
|
-
}
|
|
1770
|
-
if (!stats) continue;
|
|
1771
|
-
if (stats.isDirectory()) {
|
|
1772
|
-
stack.push(full);
|
|
1773
|
-
} else if (stats.isFile()) {
|
|
1774
|
-
if (this.#buildRegex(absPattern).test(full)) {
|
|
1775
|
-
const resolved = this.resolveSync(full);
|
|
1776
|
-
if (resolved && !results.includes(resolved)) {
|
|
1777
|
-
results.push(resolved);
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1893
|
+
await Promise.all((await this.list(baseDir && isType.isAbsolutePath(baseDir) ? baseDir : this.#context.workspaceConfig.workspaceRoot)).map(async (file) => {
|
|
1894
|
+
if (this.#buildRegex(absPattern).test(file)) {
|
|
1895
|
+
const resolved = this.resolveSync(file);
|
|
1896
|
+
if (resolved && !results.includes(resolved)) {
|
|
1897
|
+
results.push(resolved);
|
|
1780
1898
|
}
|
|
1781
1899
|
}
|
|
1782
|
-
}
|
|
1900
|
+
}));
|
|
1783
1901
|
}
|
|
1784
1902
|
return results;
|
|
1785
1903
|
}
|
|
@@ -1803,35 +1921,12 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1803
1921
|
const absPattern = isType.isAbsolutePath(normalized) ? normalized : this.#normalizePath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, normalized));
|
|
1804
1922
|
const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
|
|
1805
1923
|
const baseDir = firstGlobIdx === -1 ? filePathFns.findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
|
|
1806
|
-
const
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
try {
|
|
1813
|
-
entries = this.readdirSync(dir);
|
|
1814
|
-
} catch {
|
|
1815
|
-
continue;
|
|
1816
|
-
}
|
|
1817
|
-
for (const entry of entries) {
|
|
1818
|
-
const full = this.#normalizePath(joinPaths.joinPaths(dir, entry));
|
|
1819
|
-
let stats;
|
|
1820
|
-
try {
|
|
1821
|
-
stats = this.#unifiedFS.lstatSync(full);
|
|
1822
|
-
} catch {
|
|
1823
|
-
stats = void 0;
|
|
1824
|
-
}
|
|
1825
|
-
if (!stats) continue;
|
|
1826
|
-
if (stats.isDirectory()) {
|
|
1827
|
-
stack.push(full);
|
|
1828
|
-
} else if (stats.isFile()) {
|
|
1829
|
-
if (this.#buildRegex(absPattern).test(full)) {
|
|
1830
|
-
const resolved = this.resolveSync(full);
|
|
1831
|
-
if (resolved && !results.includes(resolved)) {
|
|
1832
|
-
results.push(resolved);
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1924
|
+
const files = this.listSync(baseDir && isType.isAbsolutePath(baseDir) ? baseDir : this.#context.workspaceConfig.workspaceRoot);
|
|
1925
|
+
for (const file of files) {
|
|
1926
|
+
if (this.#buildRegex(absPattern).test(file)) {
|
|
1927
|
+
const resolved = this.resolveSync(file);
|
|
1928
|
+
if (resolved && !results.includes(resolved)) {
|
|
1929
|
+
results.push(resolved);
|
|
1835
1930
|
}
|
|
1836
1931
|
}
|
|
1837
1932
|
}
|
|
@@ -1839,36 +1934,27 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1839
1934
|
return results;
|
|
1840
1935
|
}
|
|
1841
1936
|
/**
|
|
1842
|
-
* Moves a file from one path to another in the virtual file system (VFS).
|
|
1843
|
-
*
|
|
1844
|
-
* @param srcPath - The source path to move
|
|
1845
|
-
* @param destPath - The destination path to move to
|
|
1846
|
-
*/
|
|
1847
|
-
async move(srcPath, destPath) {
|
|
1848
|
-
const content = await this.readFile(srcPath);
|
|
1849
|
-
await this.writeFile(destPath, content);
|
|
1850
|
-
await this.rm(srcPath);
|
|
1851
|
-
}
|
|
1852
|
-
/**
|
|
1853
|
-
* Synchronously moves a file from one path to another in the virtual file system (VFS).
|
|
1854
|
-
*
|
|
1855
|
-
* @param srcPath - The source path to move
|
|
1856
|
-
* @param destPath - The destination path to move to
|
|
1857
|
-
*/
|
|
1858
|
-
moveSync(srcPath, destPath) {
|
|
1859
|
-
const content = this.readFileSync(srcPath);
|
|
1860
|
-
this.writeFileSync(destPath, content);
|
|
1861
|
-
this.rmSync(srcPath);
|
|
1862
|
-
}
|
|
1863
|
-
/**
|
|
1864
1937
|
* Copies a file from one path to another in the virtual file system (VFS).
|
|
1865
1938
|
*
|
|
1866
1939
|
* @param srcPath - The source path to copy
|
|
1867
1940
|
* @param destPath - The destination path to copy to
|
|
1868
1941
|
*/
|
|
1869
1942
|
async copy(srcPath, destPath) {
|
|
1870
|
-
|
|
1871
|
-
|
|
1943
|
+
if (filePathFns.hasFileExtension(srcPath)) {
|
|
1944
|
+
const content = await this.read(srcPath);
|
|
1945
|
+
if (content !== void 0) {
|
|
1946
|
+
await this.write(filePathFns.hasFileExtension(destPath) ? destPath : joinPaths.joinPaths(destPath, filePathFns.findFileName(srcPath)), content);
|
|
1947
|
+
}
|
|
1948
|
+
} else {
|
|
1949
|
+
await Promise.all((await this.list(srcPath)).map(async (file) => {
|
|
1950
|
+
const relativePath2 = file.replace(this.#normalizePath(srcPath), "");
|
|
1951
|
+
const destinationPath = this.#normalizePath(append.appendPath(destPath, relativePath2));
|
|
1952
|
+
const content = await this.read(file);
|
|
1953
|
+
if (content !== void 0) {
|
|
1954
|
+
await this.write(destinationPath, content);
|
|
1955
|
+
}
|
|
1956
|
+
}));
|
|
1957
|
+
}
|
|
1872
1958
|
}
|
|
1873
1959
|
/**
|
|
1874
1960
|
* Synchronously copies a file from one path to another in the virtual file system (VFS).
|
|
@@ -1877,51 +1963,85 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1877
1963
|
* @param destPath - The destination path to copy to
|
|
1878
1964
|
*/
|
|
1879
1965
|
copySync(srcPath, destPath) {
|
|
1880
|
-
|
|
1881
|
-
|
|
1966
|
+
if (filePathFns.hasFileExtension(srcPath)) {
|
|
1967
|
+
const content = this.readSync(srcPath);
|
|
1968
|
+
if (content !== void 0) {
|
|
1969
|
+
this.writeSync(filePathFns.hasFileExtension(destPath) ? destPath : joinPaths.joinPaths(destPath, filePathFns.findFileName(srcPath)), content);
|
|
1970
|
+
}
|
|
1971
|
+
} else {
|
|
1972
|
+
this.listSync(srcPath).forEach((file) => {
|
|
1973
|
+
const relativePath2 = file.replace(this.#normalizePath(srcPath), "");
|
|
1974
|
+
const destinationPath = this.#normalizePath(append.appendPath(destPath, relativePath2));
|
|
1975
|
+
const content = this.readSync(file);
|
|
1976
|
+
if (content !== void 0) {
|
|
1977
|
+
this.writeSync(destinationPath, content);
|
|
1978
|
+
}
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1882
1981
|
}
|
|
1883
1982
|
/**
|
|
1884
|
-
*
|
|
1983
|
+
* Moves a file (or files) from one path to another in the virtual file system (VFS).
|
|
1885
1984
|
*
|
|
1886
|
-
* @param
|
|
1887
|
-
* @param
|
|
1888
|
-
|
|
1985
|
+
* @param srcPath - The source path to move
|
|
1986
|
+
* @param destPath - The destination path to move to
|
|
1987
|
+
*/
|
|
1988
|
+
async move(srcPath, destPath) {
|
|
1989
|
+
if (filePathFns.hasFileExtension(srcPath)) {
|
|
1990
|
+
await this.copy(srcPath, destPath);
|
|
1991
|
+
await this.remove(srcPath);
|
|
1992
|
+
} else {
|
|
1993
|
+
await Promise.all((await this.list(srcPath)).map(async (file) => {
|
|
1994
|
+
await this.copy(file, destPath);
|
|
1995
|
+
await this.remove(file);
|
|
1996
|
+
}));
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Synchronously moves a file (or files) from one path to another in the virtual file system (VFS).
|
|
2001
|
+
*
|
|
2002
|
+
* @param srcPath - The source path to move
|
|
2003
|
+
* @param destPath - The destination path to move to
|
|
1889
2004
|
*/
|
|
1890
|
-
|
|
1891
|
-
|
|
2005
|
+
moveSync(srcPath, destPath) {
|
|
2006
|
+
if (filePathFns.hasFileExtension(srcPath)) {
|
|
2007
|
+
this.copySync(srcPath, destPath);
|
|
2008
|
+
this.removeSync(srcPath);
|
|
2009
|
+
} else {
|
|
2010
|
+
this.listSync(srcPath).forEach((file) => {
|
|
2011
|
+
this.copySync(file, destPath);
|
|
2012
|
+
this.removeSync(file);
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
1892
2015
|
}
|
|
1893
2016
|
/**
|
|
1894
2017
|
* Asynchronously reads a file from the virtual file system (VFS).
|
|
1895
2018
|
*
|
|
1896
|
-
* @param
|
|
2019
|
+
* @param path - The path or ID of the file to read.
|
|
1897
2020
|
* @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
|
|
1898
2021
|
*/
|
|
1899
|
-
async
|
|
1900
|
-
const filePath = await this.resolve(
|
|
1901
|
-
if (filePath
|
|
1902
|
-
|
|
1903
|
-
if (isFunction.isFunction(this.#unifiedFS.resolveFS(filePath).promises.readFile)) {
|
|
1904
|
-
result = (await this.#unifiedFS.resolveFS(filePath).promises.readFile(filePath, options))?.toString("utf8");
|
|
1905
|
-
} else {
|
|
1906
|
-
result = this.#unifiedFS.resolveFS(filePath).readFileSync(filePath, options);
|
|
1907
|
-
}
|
|
1908
|
-
return isBuffer.isBuffer(result) ? bufferToString.bufferToString(result) : result;
|
|
2022
|
+
async read(path) {
|
|
2023
|
+
const filePath = await this.resolve(path);
|
|
2024
|
+
if (!filePath) {
|
|
2025
|
+
return void 0;
|
|
1909
2026
|
}
|
|
1910
|
-
|
|
2027
|
+
const { relativeKey, adapter } = this.#getStorage(filePath);
|
|
2028
|
+
this.#log(types.LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
|
|
2029
|
+
return await adapter.get(relativeKey) ?? void 0;
|
|
1911
2030
|
}
|
|
1912
2031
|
/**
|
|
1913
2032
|
* Synchronously reads a file from the virtual file system (VFS).
|
|
1914
2033
|
*
|
|
1915
|
-
* @param
|
|
2034
|
+
* @param path - The path or ID of the file to read.
|
|
1916
2035
|
* @returns The contents of the file as a string, or undefined if the file does not exist.
|
|
1917
2036
|
*/
|
|
1918
|
-
|
|
1919
|
-
const filePath = this.resolveSync(
|
|
1920
|
-
if (filePath
|
|
1921
|
-
|
|
1922
|
-
return isBuffer.isBuffer(result) ? bufferToString.bufferToString(result) : result;
|
|
2037
|
+
readSync(path) {
|
|
2038
|
+
const filePath = this.resolveSync(path);
|
|
2039
|
+
if (!filePath) {
|
|
2040
|
+
return void 0;
|
|
1923
2041
|
}
|
|
1924
|
-
|
|
2042
|
+
const { relativeKey, adapter } = this.#getStorage(filePath);
|
|
2043
|
+
this.#log(types.LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
|
|
2044
|
+
return adapter.getSync(relativeKey) ?? void 0;
|
|
1925
2045
|
}
|
|
1926
2046
|
/**
|
|
1927
2047
|
* Writes a file to the virtual file system (VFS).
|
|
@@ -1931,41 +2051,28 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1931
2051
|
* @param options - Optional parameters for writing the file.
|
|
1932
2052
|
* @returns A promise that resolves when the file is written.
|
|
1933
2053
|
*/
|
|
1934
|
-
async
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
}
|
|
1938
|
-
const metadata = isVirtualFileData(data) ? data : {};
|
|
1939
|
-
metadata.id = this.#normalizeId(path);
|
|
1940
|
-
let code = isVirtualFileData(data) ? metadata.code : data;
|
|
1941
|
-
if ((!isPowerlinesWriteFileOptions(options) || !options.skipFormat) && isSetString.isSetString(code)) {
|
|
2054
|
+
async write(path, data = "", options = {}) {
|
|
2055
|
+
let code = data;
|
|
2056
|
+
if (!options.skipFormat) {
|
|
1942
2057
|
const resolvedConfig = await prettier.resolveConfig(this.#normalizePath(path));
|
|
1943
2058
|
if (resolvedConfig) {
|
|
1944
|
-
code = await prettier.format(
|
|
2059
|
+
code = await prettier.format(data, {
|
|
1945
2060
|
absolutePath: this.#normalizePath(path),
|
|
1946
2061
|
...resolvedConfig
|
|
1947
2062
|
});
|
|
1948
2063
|
}
|
|
1949
2064
|
}
|
|
1950
|
-
const
|
|
1951
|
-
this.#log(types.LogLevelLabel.TRACE, `Writing ${this.#normalizePath(path)}
|
|
1952
|
-
|
|
1953
|
-
|
|
2065
|
+
const { relativeKey, adapter } = this.#getStorage(path);
|
|
2066
|
+
this.#log(types.LogLevelLabel.TRACE, `Writing ${this.#normalizePath(path)} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes.prettyBytes(new buffer$1.Blob(toArray.toArray(code)).size)})`);
|
|
2067
|
+
const id = options?.meta?.id || this.#normalizeId(path);
|
|
2068
|
+
this.#metadata[id] = {
|
|
1954
2069
|
variant: "normal",
|
|
1955
2070
|
timestamp: Date.now(),
|
|
1956
|
-
...
|
|
2071
|
+
...options.meta ?? {}
|
|
1957
2072
|
};
|
|
1958
|
-
this.#paths[
|
|
1959
|
-
this.#ids[this.#normalizePath(path)] =
|
|
1960
|
-
|
|
1961
|
-
if (isFunction.isFunction(ifs.promises.writeFile)) {
|
|
1962
|
-
return ifs.promises.writeFile(this.#normalizePath(path), code, isSetObject.isSetObject(options) ? omit.omit(options, [
|
|
1963
|
-
"mode"
|
|
1964
|
-
]) : "utf8");
|
|
1965
|
-
}
|
|
1966
|
-
return ifs.writeFileSync(this.#normalizePath(path), code, isSetObject.isSetObject(options) ? omit.omit(options, [
|
|
1967
|
-
"mode"
|
|
1968
|
-
]) : "utf8");
|
|
2073
|
+
this.#paths[id] = this.#normalizePath(path);
|
|
2074
|
+
this.#ids[this.#normalizePath(path)] = id;
|
|
2075
|
+
return adapter.set(relativeKey, code);
|
|
1969
2076
|
}
|
|
1970
2077
|
/**
|
|
1971
2078
|
* Synchronously writes a file to the virtual file system (VFS).
|
|
@@ -1974,38 +2081,18 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1974
2081
|
* @param data - The contents of the file.
|
|
1975
2082
|
* @param options - Optional parameters for writing the file.
|
|
1976
2083
|
*/
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
metadata.id = this.#normalizeId(path);
|
|
1983
|
-
const code = isVirtualFileData(data) ? metadata.code : data;
|
|
1984
|
-
const outputMode = this.#unifiedFS.resolveMode(this.#normalizePath(path), isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1985
|
-
this.#log(types.LogLevelLabel.TRACE, `Writing ${this.#normalizePath(path)} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes.prettyBytes(new buffer$1.Blob(toArray.toArray(code)).size)})`);
|
|
1986
|
-
this.#metadata[metadata.id] = {
|
|
1987
|
-
mode: outputMode,
|
|
2084
|
+
writeSync(path, data = "", options = {}) {
|
|
2085
|
+
const { relativeKey, adapter } = this.#getStorage(path);
|
|
2086
|
+
this.#log(types.LogLevelLabel.TRACE, `Writing ${this.#normalizePath(path)} file to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes.prettyBytes(new buffer$1.Blob(toArray.toArray(data)).size)})`);
|
|
2087
|
+
const id = options?.meta?.id || this.#normalizeId(path);
|
|
2088
|
+
this.#metadata[id] = {
|
|
1988
2089
|
variant: "normal",
|
|
1989
2090
|
timestamp: Date.now(),
|
|
1990
|
-
...
|
|
2091
|
+
...options.meta ?? {}
|
|
1991
2092
|
};
|
|
1992
|
-
this.#paths[
|
|
1993
|
-
this.#ids[this.#normalizePath(path)] =
|
|
1994
|
-
|
|
1995
|
-
try {
|
|
1996
|
-
writeStream.write(code);
|
|
1997
|
-
} finally {
|
|
1998
|
-
writeStream.close();
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
|
-
/**
|
|
2002
|
-
* Synchronously checks if a file exists in the virtual file system (VFS).
|
|
2003
|
-
*
|
|
2004
|
-
* @param pathOrId - The path or ID of the file to check.
|
|
2005
|
-
* @returns `true` if the file exists, otherwise `false`.
|
|
2006
|
-
*/
|
|
2007
|
-
existsSync(pathOrId) {
|
|
2008
|
-
return !!this.resolveSync(pathOrId);
|
|
2093
|
+
this.#paths[id] = this.#normalizePath(path);
|
|
2094
|
+
this.#ids[this.#normalizePath(path)] = id;
|
|
2095
|
+
return adapter.setSync(relativeKey, data);
|
|
2009
2096
|
}
|
|
2010
2097
|
/**
|
|
2011
2098
|
* Retrieves the metadata of a file in the virtual file system (VFS).
|
|
@@ -2021,78 +2108,6 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2021
2108
|
return void 0;
|
|
2022
2109
|
}
|
|
2023
2110
|
/**
|
|
2024
|
-
* Checks if a file exists in the virtual file system (VFS).
|
|
2025
|
-
*
|
|
2026
|
-
* @remarks
|
|
2027
|
-
* 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.
|
|
2028
|
-
*
|
|
2029
|
-
* @param pathOrId - The path of the file to check.
|
|
2030
|
-
* @returns `true` if the file exists, otherwise `false`.
|
|
2031
|
-
*/
|
|
2032
|
-
isFile(pathOrId) {
|
|
2033
|
-
const resolved = this.resolveSync(pathOrId);
|
|
2034
|
-
return !!(resolved && (this.#unifiedFS.virtual.existsSync(resolved) && this.#unifiedFS.virtual.lstatSync(resolved).isFile() || this.#unifiedFS.physical.existsSync(resolved) && this.#unifiedFS.physical.lstatSync(resolved).isFile() || this.#unifiedFS.resolveFS(resolved).existsSync(resolved) && this.#unifiedFS.resolveFS(resolved).lstatSync(resolved).isFile()));
|
|
2035
|
-
}
|
|
2036
|
-
/**
|
|
2037
|
-
* Checks if a directory exists in the virtual file system (VFS).
|
|
2038
|
-
*
|
|
2039
|
-
* @param pathOrId - The path of the directory to check.
|
|
2040
|
-
* @returns `true` if the directory exists, otherwise `false`.
|
|
2041
|
-
*/
|
|
2042
|
-
isDirectory(pathOrId) {
|
|
2043
|
-
const resolved = this.resolveSync(pathOrId);
|
|
2044
|
-
return !!(resolved && (this.#unifiedFS.virtual.existsSync(resolved) && this.#unifiedFS.virtual.lstatSync(resolved).isDirectory() || this.#unifiedFS.physical.existsSync(resolved) && this.#unifiedFS.physical.lstatSync(resolved).isDirectory() || this.#unifiedFS.resolveFS(resolved).existsSync(resolved) && this.#unifiedFS.resolveFS(resolved).lstatSync(resolved).isDirectory()));
|
|
2045
|
-
}
|
|
2046
|
-
/**
|
|
2047
|
-
* Retrieves the status of a file in the virtual file system (VFS).
|
|
2048
|
-
*
|
|
2049
|
-
* @param pathOrId - The path or ID of the file to retrieve status for.
|
|
2050
|
-
* @returns A promise that resolves to the file's status information, or false if the file does not exist.
|
|
2051
|
-
*/
|
|
2052
|
-
async stat(pathOrId, options) {
|
|
2053
|
-
return this.#unifiedFS.resolveFS(pathOrId).promises.stat(await this.resolve(pathOrId) || pathOrId, options);
|
|
2054
|
-
}
|
|
2055
|
-
/**
|
|
2056
|
-
* Synchronously retrieves the status of a file in the virtual file system (VFS).
|
|
2057
|
-
*
|
|
2058
|
-
* @param pathOrId - The path or ID of the file to retrieve status for.
|
|
2059
|
-
* @returns The file's status information, or false if the file does not exist.
|
|
2060
|
-
*/
|
|
2061
|
-
statSync(pathOrId) {
|
|
2062
|
-
return this.#unifiedFS.resolveFS(pathOrId).statSync(this.resolveSync(pathOrId) || pathOrId);
|
|
2063
|
-
}
|
|
2064
|
-
/**
|
|
2065
|
-
* Retrieves the status of a symbolic link in the virtual file system (VFS).
|
|
2066
|
-
*
|
|
2067
|
-
* @param pathOrId - The path or ID of the symbolic link to retrieve status for.
|
|
2068
|
-
* @returns A promise that resolves to the symbolic link's status information, or false if the link does not exist.
|
|
2069
|
-
*/
|
|
2070
|
-
async lstat(pathOrId, options) {
|
|
2071
|
-
return this.#unifiedFS.resolveFS(pathOrId).promises.lstat(await this.resolve(pathOrId) || pathOrId, options);
|
|
2072
|
-
}
|
|
2073
|
-
/**
|
|
2074
|
-
* Synchronously retrieves the status of a symbolic link in the virtual file system (VFS).
|
|
2075
|
-
*
|
|
2076
|
-
* @param pathOrId - The path or ID of the symbolic link to retrieve status for.
|
|
2077
|
-
* @returns The symbolic link's status information, or false if the link does not exist.
|
|
2078
|
-
*/
|
|
2079
|
-
lstatSync(pathOrId, options) {
|
|
2080
|
-
return this.#unifiedFS.resolveFS(pathOrId).lstatSync(this.resolveSync(pathOrId) || pathOrId, options);
|
|
2081
|
-
}
|
|
2082
|
-
/**
|
|
2083
|
-
* Resolves a path or ID to its real path in the virtual file system (VFS).
|
|
2084
|
-
*
|
|
2085
|
-
* @param pathOrId - The path or ID to resolve.
|
|
2086
|
-
* @returns The resolved real path if it exists, otherwise undefined.
|
|
2087
|
-
*/
|
|
2088
|
-
realpathSync(pathOrId) {
|
|
2089
|
-
const filePath = this.resolveSync(pathOrId);
|
|
2090
|
-
if (!filePath) {
|
|
2091
|
-
throw new Error(`File not found: ${pathOrId}`);
|
|
2092
|
-
}
|
|
2093
|
-
return filePath;
|
|
2094
|
-
}
|
|
2095
|
-
/**
|
|
2096
2111
|
* A helper function to resolve modules in the virtual file system (VFS).
|
|
2097
2112
|
*
|
|
2098
2113
|
* @remarks
|
|
@@ -2109,9 +2124,15 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2109
2124
|
* @returns A promise that resolves to the resolved module path.
|
|
2110
2125
|
*/
|
|
2111
2126
|
async resolve(id, importer, options = {}) {
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2127
|
+
if (isType.isAbsolutePath(id)) {
|
|
2128
|
+
return id;
|
|
2129
|
+
}
|
|
2130
|
+
let result;
|
|
2131
|
+
if (!this.#context.config.skipCache) {
|
|
2132
|
+
result = this.resolverCache.get(this.#normalizeId(id));
|
|
2133
|
+
if (result) {
|
|
2134
|
+
return result;
|
|
2135
|
+
}
|
|
2115
2136
|
}
|
|
2116
2137
|
result = this.paths[this.#normalizeId(id)];
|
|
2117
2138
|
if (!result) {
|
|
@@ -2126,8 +2147,10 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2126
2147
|
for (const combination of resolve.getResolutionCombinations(id, {
|
|
2127
2148
|
paths
|
|
2128
2149
|
})) {
|
|
2129
|
-
|
|
2150
|
+
const { relativeKey, adapter } = this.#getStorage(combination);
|
|
2151
|
+
if (await adapter.exists(relativeKey)) {
|
|
2130
2152
|
result = combination;
|
|
2153
|
+
break;
|
|
2131
2154
|
}
|
|
2132
2155
|
}
|
|
2133
2156
|
try {
|
|
@@ -2139,7 +2162,9 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2139
2162
|
}
|
|
2140
2163
|
if (result) {
|
|
2141
2164
|
result = correctPath.toAbsolutePath(append.appendPath(result, this.#context.config.projectRoot), this.#context.workspaceConfig.workspaceRoot);
|
|
2142
|
-
this.
|
|
2165
|
+
if (!this.#context.config.skipCache) {
|
|
2166
|
+
this.resolverCache.set(this.#normalizeId(id), result);
|
|
2167
|
+
}
|
|
2143
2168
|
}
|
|
2144
2169
|
return result;
|
|
2145
2170
|
}
|
|
@@ -2160,9 +2185,15 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2160
2185
|
* @returns The resolved module path.
|
|
2161
2186
|
*/
|
|
2162
2187
|
resolveSync(id, importer, options = {}) {
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2188
|
+
if (isType.isAbsolutePath(id)) {
|
|
2189
|
+
return id;
|
|
2190
|
+
}
|
|
2191
|
+
let result;
|
|
2192
|
+
if (!this.#context.config.skipCache) {
|
|
2193
|
+
result = this.resolverCache.get(this.#normalizeId(id));
|
|
2194
|
+
if (result) {
|
|
2195
|
+
return result;
|
|
2196
|
+
}
|
|
2166
2197
|
}
|
|
2167
2198
|
result = this.paths[this.#normalizeId(id)];
|
|
2168
2199
|
if (!result) {
|
|
@@ -2171,14 +2202,16 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2171
2202
|
paths.push(importer);
|
|
2172
2203
|
}
|
|
2173
2204
|
paths.push(this.#context.workspaceConfig.workspaceRoot);
|
|
2174
|
-
paths.push(
|
|
2175
|
-
paths.push(
|
|
2176
|
-
paths.push(...Object.keys(this.#context.tsconfig
|
|
2205
|
+
paths.push(append.appendPath(this.#context.config.projectRoot, this.#context.workspaceConfig.workspaceRoot));
|
|
2206
|
+
paths.push(append.appendPath(this.#context.config.sourceRoot, this.#context.workspaceConfig.workspaceRoot));
|
|
2207
|
+
paths.push(...Object.keys(this.#context.tsconfig.options.paths ?? {}).filter((tsconfigPath) => id.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig.options.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => append.appendPath(tsconfigPath, this.#context.workspaceConfig.workspaceRoot)));
|
|
2177
2208
|
for (const combination of resolve.getResolutionCombinations(id, {
|
|
2178
2209
|
paths
|
|
2179
2210
|
})) {
|
|
2180
|
-
|
|
2211
|
+
const { relativeKey, adapter } = this.#getStorage(combination);
|
|
2212
|
+
if (adapter.existsSync(relativeKey)) {
|
|
2181
2213
|
result = combination;
|
|
2214
|
+
break;
|
|
2182
2215
|
}
|
|
2183
2216
|
}
|
|
2184
2217
|
try {
|
|
@@ -2190,7 +2223,9 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2190
2223
|
}
|
|
2191
2224
|
if (result) {
|
|
2192
2225
|
result = correctPath.toAbsolutePath(append.appendPath(result, this.#context.config.projectRoot), this.#context.workspaceConfig.workspaceRoot);
|
|
2193
|
-
this.
|
|
2226
|
+
if (!this.#context.config.skipCache) {
|
|
2227
|
+
this.resolverCache.set(this.#normalizeId(id), result);
|
|
2228
|
+
}
|
|
2194
2229
|
}
|
|
2195
2230
|
return result;
|
|
2196
2231
|
}
|
|
@@ -2201,27 +2236,27 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2201
2236
|
if (!this.#isDisposed) {
|
|
2202
2237
|
this.#isDisposed = true;
|
|
2203
2238
|
this.#log(types.LogLevelLabel.DEBUG, "Disposing virtual file system...");
|
|
2204
|
-
await this.
|
|
2239
|
+
await this.remove(joinPaths.joinPaths(this.#context.dataPath, "fs.bin"));
|
|
2205
2240
|
const message = new $__namespace.Message();
|
|
2206
|
-
const
|
|
2207
|
-
const
|
|
2208
|
-
const
|
|
2209
|
-
|
|
2210
|
-
const
|
|
2241
|
+
const fs = message.initRoot(FileSystem);
|
|
2242
|
+
const paths = await this.list();
|
|
2243
|
+
const storage = fs._initStorage(paths.length);
|
|
2244
|
+
await Promise.all(paths.map(async (path, index) => {
|
|
2245
|
+
const code = await this.read(path);
|
|
2246
|
+
const fd = storage.get(index);
|
|
2211
2247
|
fd.path = path;
|
|
2212
2248
|
fd.code = code || "";
|
|
2213
|
-
});
|
|
2214
|
-
const ids =
|
|
2249
|
+
}));
|
|
2250
|
+
const ids = fs._initIds(Object.keys(this.ids).length);
|
|
2215
2251
|
Object.entries(this.ids).filter(([, path]) => path).forEach(([id, path], index) => {
|
|
2216
2252
|
const fileId = ids.get(index);
|
|
2217
2253
|
fileId.id = id;
|
|
2218
2254
|
fileId.path = path;
|
|
2219
2255
|
});
|
|
2220
|
-
const metadata =
|
|
2256
|
+
const metadata = fs._initMetadata(Object.keys(this.metadata).length);
|
|
2221
2257
|
Object.entries(this.metadata).filter(([, value]) => value).forEach(([id, value], index) => {
|
|
2222
2258
|
const fileMetadata = metadata.get(index);
|
|
2223
2259
|
fileMetadata.id = id;
|
|
2224
|
-
fileMetadata.mode = value.mode;
|
|
2225
2260
|
fileMetadata.type = value.type;
|
|
2226
2261
|
fileMetadata.timestamp = value.timestamp ?? BigInt(Date.now());
|
|
2227
2262
|
if (value.properties) {
|
|
@@ -2234,134 +2269,40 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2234
2269
|
}
|
|
2235
2270
|
});
|
|
2236
2271
|
await buffer.writeFileBuffer(joinPaths.joinPaths(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
|
|
2237
|
-
this.#
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2272
|
+
if (!this.#context.config.skipCache) {
|
|
2273
|
+
this.#resolverCache.save(true);
|
|
2274
|
+
}
|
|
2275
|
+
await Promise.all(this.#getStorages().map(async (storage2) => storage2.adapter.dispose()));
|
|
2276
|
+
this.#log(types.LogLevelLabel.TRACE, "Virtual file system has been disposed.");
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
// /**
|
|
2280
|
+
// * Initializes the virtual file system (VFS) by patching the file system module if necessary.
|
|
2281
|
+
// */
|
|
2282
|
+
// public [__VFS_PATCH__]() {
|
|
2283
|
+
// if (!this.#isPatched && this.#context.config.output.mode !== "fs") {
|
|
2284
|
+
// this.#revert = patchFS(fs, this);
|
|
2285
|
+
// this.#isPatched = true;
|
|
2286
|
+
// }
|
|
2287
|
+
// }
|
|
2288
|
+
// /**
|
|
2289
|
+
// * Reverts the file system module to its original state if it was previously patched.
|
|
2290
|
+
// */
|
|
2291
|
+
// public [__VFS_REVERT__]() {
|
|
2292
|
+
// if (this.#isPatched && this.#context.config.output.mode !== "fs") {
|
|
2293
|
+
// if (!this.#revert) {
|
|
2294
|
+
// throw new Error(
|
|
2295
|
+
// "Attempting to revert File System patch prior to calling `__init__` function"
|
|
2296
|
+
// );
|
|
2297
|
+
// }
|
|
2298
|
+
// this.#revert?.();
|
|
2299
|
+
// this.#isPatched = false;
|
|
2300
|
+
// }
|
|
2301
|
+
// }
|
|
2262
2302
|
async [Symbol.asyncDispose]() {
|
|
2263
2303
|
return this.dispose();
|
|
2264
2304
|
}
|
|
2265
2305
|
};
|
|
2266
|
-
var VirtualFileSystemHost = class VirtualFileSystemHost2 extends tsMorph.InMemoryFileSystemHost {
|
|
2267
|
-
static {
|
|
2268
|
-
chunkSHUYVCID_js.__name(this, "VirtualFileSystemHost");
|
|
2269
|
-
}
|
|
2270
|
-
#fs;
|
|
2271
|
-
constructor(fs2) {
|
|
2272
|
-
super();
|
|
2273
|
-
this.#fs = fs2;
|
|
2274
|
-
}
|
|
2275
|
-
deleteSync(path) {
|
|
2276
|
-
this.#fs.rmSync(path);
|
|
2277
|
-
}
|
|
2278
|
-
readDirSync(dirPath) {
|
|
2279
|
-
return this.#fs.readdirSync(dirPath).reduce((ret, entry) => {
|
|
2280
|
-
const fullPath = this.#fs.resolveSync(join.joinPaths(dirPath, entry));
|
|
2281
|
-
if (fullPath) {
|
|
2282
|
-
ret.push({
|
|
2283
|
-
name: entry,
|
|
2284
|
-
isDirectory: this.#fs.isDirectory(fullPath),
|
|
2285
|
-
isFile: this.#fs.isFile(fullPath),
|
|
2286
|
-
isSymlink: false
|
|
2287
|
-
});
|
|
2288
|
-
}
|
|
2289
|
-
return ret;
|
|
2290
|
-
}, []);
|
|
2291
|
-
}
|
|
2292
|
-
async readFile(filePath) {
|
|
2293
|
-
if (!this.#fs.existsSync(filePath)) {
|
|
2294
|
-
throw new Error(`File not found: '${filePath}'. Please check the path and try again.`);
|
|
2295
|
-
}
|
|
2296
|
-
return await this.#fs.readFile(filePath);
|
|
2297
|
-
}
|
|
2298
|
-
readFileSync(filePath) {
|
|
2299
|
-
if (!this.#fs.existsSync(filePath)) {
|
|
2300
|
-
throw new Error(`File not found: '${filePath}'. Please check the path and try again.`);
|
|
2301
|
-
}
|
|
2302
|
-
return this.#fs.readFileSync(filePath);
|
|
2303
|
-
}
|
|
2304
|
-
async writeFile(filePath, fileText) {
|
|
2305
|
-
return this.#fs.writeFile(filePath, fileText);
|
|
2306
|
-
}
|
|
2307
|
-
writeFileSync(filePath, fileText) {
|
|
2308
|
-
this.#fs.writeFileSync(filePath, fileText);
|
|
2309
|
-
}
|
|
2310
|
-
async mkdir(dirPath) {
|
|
2311
|
-
await this.#fs.mkdir(dirPath);
|
|
2312
|
-
}
|
|
2313
|
-
mkdirSync(dirPath) {
|
|
2314
|
-
this.#fs.mkdirSync(dirPath);
|
|
2315
|
-
}
|
|
2316
|
-
async move(srcPath, destPath) {
|
|
2317
|
-
await this.#fs.move(srcPath, destPath);
|
|
2318
|
-
}
|
|
2319
|
-
moveSync(srcPath, destPath) {
|
|
2320
|
-
this.#fs.moveSync(srcPath, destPath);
|
|
2321
|
-
}
|
|
2322
|
-
async copy(srcPath, destPath) {
|
|
2323
|
-
await this.#fs.copy(srcPath, destPath);
|
|
2324
|
-
}
|
|
2325
|
-
copySync(srcPath, destPath) {
|
|
2326
|
-
this.#fs.copySync(srcPath, destPath);
|
|
2327
|
-
}
|
|
2328
|
-
async fileExists(filePath) {
|
|
2329
|
-
return this.#fs.isFile(filePath);
|
|
2330
|
-
}
|
|
2331
|
-
fileExistsSync(filePath) {
|
|
2332
|
-
return this.#fs.isFile(filePath);
|
|
2333
|
-
}
|
|
2334
|
-
async directoryExists(dirPath) {
|
|
2335
|
-
return this.#fs.isDirectory(dirPath);
|
|
2336
|
-
}
|
|
2337
|
-
directoryExistsSync(dirPath) {
|
|
2338
|
-
return this.#fs.isDirectory(dirPath);
|
|
2339
|
-
}
|
|
2340
|
-
realpathSync(path) {
|
|
2341
|
-
return this.#fs.resolveSync(path) || path;
|
|
2342
|
-
}
|
|
2343
|
-
getCurrentDirectory() {
|
|
2344
|
-
return "/";
|
|
2345
|
-
}
|
|
2346
|
-
async glob(patterns) {
|
|
2347
|
-
return this.#fs.glob(patterns);
|
|
2348
|
-
}
|
|
2349
|
-
globSync(patterns) {
|
|
2350
|
-
return this.#fs.globSync(patterns);
|
|
2351
|
-
}
|
|
2352
|
-
};
|
|
2353
|
-
function createProgram(context, override) {
|
|
2354
|
-
const project = new tsMorph.Project({
|
|
2355
|
-
compilerOptions: {
|
|
2356
|
-
...context.tsconfig.options
|
|
2357
|
-
},
|
|
2358
|
-
tsConfigFilePath: context.tsconfig.tsconfigFilePath,
|
|
2359
|
-
fileSystem: new VirtualFileSystemHost(context.fs),
|
|
2360
|
-
...override
|
|
2361
|
-
});
|
|
2362
|
-
return project;
|
|
2363
|
-
}
|
|
2364
|
-
chunkSHUYVCID_js.__name(createProgram, "createProgram");
|
|
2365
2306
|
|
|
2366
2307
|
// ../powerlines/src/lib/contexts/context.ts
|
|
2367
2308
|
var configCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -2419,7 +2360,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2419
2360
|
* @returns A promise that resolves to the new context.
|
|
2420
2361
|
*/
|
|
2421
2362
|
static async from(workspaceRoot, config) {
|
|
2422
|
-
const context = new _PowerlinesContext(await
|
|
2363
|
+
const context = new _PowerlinesContext(await chunkDQI2I5KK_js.loadWorkspaceConfig(workspaceRoot, config.root));
|
|
2423
2364
|
await context.withUserConfig(config);
|
|
2424
2365
|
context.powerlinesPath = await resolve.resolvePackage("powerlines");
|
|
2425
2366
|
if (!context.powerlinesPath) {
|
|
@@ -2517,10 +2458,10 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2517
2458
|
workspaceRoot: this.workspaceConfig?.workspaceRoot,
|
|
2518
2459
|
projectRoot: this.config?.projectRoot
|
|
2519
2460
|
}, {
|
|
2520
|
-
maxLength:
|
|
2461
|
+
maxLength: chunkDQI2I5KK_js.PROJECT_ROOT_HASH_LENGTH
|
|
2521
2462
|
}),
|
|
2522
2463
|
configHash: murmurhash.murmurhash(this.config, {
|
|
2523
|
-
maxLength:
|
|
2464
|
+
maxLength: chunkDQI2I5KK_js.CACHE_HASH_LENGTH
|
|
2524
2465
|
})
|
|
2525
2466
|
};
|
|
2526
2467
|
}
|
|
@@ -2562,7 +2503,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2562
2503
|
* Get the path to the artifacts directory for the project
|
|
2563
2504
|
*/
|
|
2564
2505
|
get artifactsPath() {
|
|
2565
|
-
return join.joinPaths(this.workspaceConfig.workspaceRoot, this.config.projectRoot, this.config.output.
|
|
2506
|
+
return join.joinPaths(this.workspaceConfig.workspaceRoot, this.config.projectRoot, this.config.output.artifactsPath);
|
|
2566
2507
|
}
|
|
2567
2508
|
/**
|
|
2568
2509
|
* Get the path to the builtin modules used by the project
|
|
@@ -2580,7 +2521,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2580
2521
|
* Get the path to the data directory for the project
|
|
2581
2522
|
*/
|
|
2582
2523
|
get dataPath() {
|
|
2583
|
-
return join.joinPaths(this.envPaths.data, "projects",
|
|
2524
|
+
return join.joinPaths(this.envPaths.data, "projects", chunkDQI2I5KK_js.getPrefixedProjectRootHash(this.config.name, this.meta.projectRootHash));
|
|
2584
2525
|
}
|
|
2585
2526
|
/**
|
|
2586
2527
|
* Get the path to the cache directory for the project
|
|
@@ -2590,7 +2531,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2590
2531
|
checksum: this.#checksum,
|
|
2591
2532
|
config: this.meta.configHash
|
|
2592
2533
|
}, {
|
|
2593
|
-
maxLength:
|
|
2534
|
+
maxLength: chunkDQI2I5KK_js.CACHE_HASH_LENGTH
|
|
2594
2535
|
}));
|
|
2595
2536
|
}
|
|
2596
2537
|
/**
|
|
@@ -2702,7 +2643,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2702
2643
|
if (!resolvedId) {
|
|
2703
2644
|
return void 0;
|
|
2704
2645
|
}
|
|
2705
|
-
const code = await this.fs.
|
|
2646
|
+
const code = await this.fs.read(resolvedId);
|
|
2706
2647
|
if (!code) {
|
|
2707
2648
|
return void 0;
|
|
2708
2649
|
}
|
|
@@ -2716,7 +2657,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2716
2657
|
*/
|
|
2717
2658
|
async getBuiltins() {
|
|
2718
2659
|
return Promise.all(Object.entries(this.fs.metadata).filter(([, meta]) => meta && meta.type === "builtin").map(async ([path, meta]) => {
|
|
2719
|
-
const code = await this.fs.
|
|
2660
|
+
const code = await this.fs.read(path);
|
|
2720
2661
|
return {
|
|
2721
2662
|
...meta,
|
|
2722
2663
|
path,
|
|
@@ -2732,11 +2673,8 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2732
2673
|
* @param options - Optional write file options
|
|
2733
2674
|
*/
|
|
2734
2675
|
async emitEntry(code, path, options = {}) {
|
|
2735
|
-
return this.fs.
|
|
2736
|
-
code,
|
|
2676
|
+
return this.fs.write(isType.isAbsolute(path) ? path : append.appendPath(path, this.entryPath), code, defu6__default.default(options, {
|
|
2737
2677
|
type: "entry"
|
|
2738
|
-
}, defu5__default.default(options, {
|
|
2739
|
-
mode: this.config.output.mode
|
|
2740
2678
|
}));
|
|
2741
2679
|
}
|
|
2742
2680
|
/**
|
|
@@ -2748,12 +2686,8 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2748
2686
|
* @param options - Optional write file options
|
|
2749
2687
|
*/
|
|
2750
2688
|
async emitBuiltin(code, id, path, options = {}) {
|
|
2751
|
-
return this.fs.
|
|
2752
|
-
id,
|
|
2753
|
-
code,
|
|
2689
|
+
return this.fs.write(path ? isType.isAbsolute(path) ? path : join.joinPaths(this.builtinsPath, path) : append.appendPath(id, this.builtinsPath), code, defu6__default.default(options, {
|
|
2754
2690
|
type: "builtin"
|
|
2755
|
-
}, defu5__default.default(options, {
|
|
2756
|
-
mode: this.config.output.mode
|
|
2757
2691
|
}));
|
|
2758
2692
|
}
|
|
2759
2693
|
/**
|
|
@@ -2937,7 +2871,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2937
2871
|
logLevel: config.logLevel || this.config?.logLevel || this.workspaceConfig.logLevel || "info",
|
|
2938
2872
|
skipCache: cacheKey.skipCache
|
|
2939
2873
|
});
|
|
2940
|
-
const userConfig = await
|
|
2874
|
+
const userConfig = await chunkDQI2I5KK_js.loadUserConfigFile(cacheKey.projectRoot, this.workspaceConfig.workspaceRoot, this.resolver, cacheKey.command, cacheKey.mode, cacheKey.configFile, cacheKey.framework);
|
|
2941
2875
|
this.mergeUserConfig(userConfig.config);
|
|
2942
2876
|
configCache.set(cacheKey, {
|
|
2943
2877
|
projectJson: this.projectJson,
|
|
@@ -2947,9 +2881,9 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2947
2881
|
userConfig
|
|
2948
2882
|
});
|
|
2949
2883
|
}
|
|
2950
|
-
|
|
2884
|
+
config.tsconfig ??= getTsconfigFilePath(this.workspaceConfig.workspaceRoot, cacheKey.projectRoot, config.tsconfig);
|
|
2951
2885
|
if (isSetObject.isSetObject(config)) {
|
|
2952
|
-
this.resolvedConfig =
|
|
2886
|
+
this.resolvedConfig = defu6__default.default({
|
|
2953
2887
|
inlineConfig: this.config.inlineConfig,
|
|
2954
2888
|
userConfig: this.config.userConfig
|
|
2955
2889
|
}, options.isHighPriority ? this.#getConfigProps(config) : {}, {
|
|
@@ -2964,12 +2898,11 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2964
2898
|
version: this.packageJson?.version,
|
|
2965
2899
|
description: this.packageJson?.description,
|
|
2966
2900
|
sourceRoot: this.projectJson?.sourceRoot || append.appendPath("src", cacheKey.projectRoot),
|
|
2967
|
-
output: {
|
|
2901
|
+
output: defu6__default.default(config.output ?? {}, {
|
|
2968
2902
|
outputPath: cacheKey.projectRoot ? join.joinPaths(this.workspaceConfig?.directories?.build || "dist", cacheKey.projectRoot) : this.workspaceConfig?.directories?.build || "dist",
|
|
2969
|
-
|
|
2903
|
+
artifactsPath: join.joinPaths(cacheKey.projectRoot, `.${config.framework ?? "powerlines"}`),
|
|
2970
2904
|
dts: join.joinPaths(cacheKey.projectRoot, `${config.framework ?? "powerlines"}.d.ts`),
|
|
2971
2905
|
builtinPrefix: config.framework ?? "powerlines",
|
|
2972
|
-
artifactsFolder: join.joinPaths(cacheKey.projectRoot, `.${config.framework ?? "powerlines"}`),
|
|
2973
2906
|
assets: [
|
|
2974
2907
|
{
|
|
2975
2908
|
glob: "LICENSE"
|
|
@@ -2983,7 +2916,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2983
2916
|
glob: "package.json"
|
|
2984
2917
|
}
|
|
2985
2918
|
]
|
|
2986
|
-
}
|
|
2919
|
+
})
|
|
2987
2920
|
}, options.isHighPriority ? {} : this.#getConfigProps(config), {
|
|
2988
2921
|
inlineConfig: {},
|
|
2989
2922
|
userConfig: {},
|
|
@@ -3028,10 +2961,10 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
3028
2961
|
])));
|
|
3029
2962
|
if (this.config.projectRoot && this.config.projectRoot !== "." && this.config.projectRoot !== "./" && this.config.projectRoot !== this.workspaceConfig.workspaceRoot) {
|
|
3030
2963
|
this.config.output.outputPath ??= join.joinPaths("dist", this.config.projectRoot);
|
|
3031
|
-
this.config.output.
|
|
2964
|
+
this.config.output.buildPath ??= join.joinPaths(this.config.projectRoot, "dist");
|
|
3032
2965
|
} else {
|
|
3033
2966
|
this.config.output.outputPath ??= "dist";
|
|
3034
|
-
this.config.output.
|
|
2967
|
+
this.config.output.buildPath ??= "dist";
|
|
3035
2968
|
}
|
|
3036
2969
|
this.config.output.assets = getUnique.getUnique(this.config.output.assets.map((asset) => {
|
|
3037
2970
|
return {
|
|
@@ -3069,7 +3002,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
3069
3002
|
this.#fs ??= await VirtualFileSystem.create(this);
|
|
3070
3003
|
}
|
|
3071
3004
|
mergeUserConfig(from = {}, into = this.config.userConfig ?? {}) {
|
|
3072
|
-
this.config.userConfig =
|
|
3005
|
+
this.config.userConfig = defu6__default.default({
|
|
3073
3006
|
entry: Array.isArray(from.entry) && from.entry.length > 0 ? from.entry : Array.isArray(into?.entry) && into.entry.length > 0 ? into.entry : []
|
|
3074
3007
|
}, omit.omit(from ?? {}, [
|
|
3075
3008
|
"entry"
|
|
@@ -3314,7 +3247,7 @@ var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext
|
|
|
3314
3247
|
* @returns A promise that resolves to the new context.
|
|
3315
3248
|
*/
|
|
3316
3249
|
static async from(workspaceRoot, config) {
|
|
3317
|
-
const context = new _PowerlinesAPIContext(await
|
|
3250
|
+
const context = new _PowerlinesAPIContext(await chunkDQI2I5KK_js.loadWorkspaceConfig(workspaceRoot, config.root));
|
|
3318
3251
|
await context.withUserConfig(config);
|
|
3319
3252
|
context.powerlinesPath = await resolve.resolvePackage("powerlines");
|
|
3320
3253
|
if (!context.powerlinesPath) {
|
|
@@ -3374,12 +3307,49 @@ var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext
|
|
|
3374
3307
|
}
|
|
3375
3308
|
return context;
|
|
3376
3309
|
}
|
|
3310
|
+
/**
|
|
3311
|
+
* Update the context using a new user configuration options
|
|
3312
|
+
*
|
|
3313
|
+
* @param userConfig - The new user configuration options.
|
|
3314
|
+
*/
|
|
3315
|
+
async withUserConfig(userConfig, options = {
|
|
3316
|
+
isHighPriority: true
|
|
3317
|
+
}) {
|
|
3318
|
+
await super.withUserConfig(userConfig, options);
|
|
3319
|
+
await Promise.all(Object.keys(this.#environments).map(async (name) => {
|
|
3320
|
+
await this.#environments[name].withUserConfig(userConfig, options);
|
|
3321
|
+
}));
|
|
3322
|
+
}
|
|
3323
|
+
/**
|
|
3324
|
+
* Update the context using a new inline configuration options
|
|
3325
|
+
*
|
|
3326
|
+
* @param inlineConfig - The new inline configuration options.
|
|
3327
|
+
*/
|
|
3328
|
+
async withInlineConfig(inlineConfig, options = {
|
|
3329
|
+
isHighPriority: true
|
|
3330
|
+
}) {
|
|
3331
|
+
await super.withInlineConfig(inlineConfig, options);
|
|
3332
|
+
await Promise.all(Object.keys(this.#environments).map(async (name) => {
|
|
3333
|
+
await this.#environments[name].withInlineConfig(inlineConfig, options);
|
|
3334
|
+
}));
|
|
3335
|
+
}
|
|
3336
|
+
/**
|
|
3337
|
+
* Add a plugin to the API context and all environments
|
|
3338
|
+
*
|
|
3339
|
+
* @param plugin - The plugin to add.
|
|
3340
|
+
*/
|
|
3377
3341
|
async addPlugin(plugin) {
|
|
3378
3342
|
this.plugins.push(plugin);
|
|
3379
3343
|
await Promise.all(Object.keys(this.environments).map(async (name) => {
|
|
3380
3344
|
await this.environments[name].addPlugin(plugin);
|
|
3381
3345
|
}));
|
|
3382
3346
|
}
|
|
3347
|
+
/**
|
|
3348
|
+
* Get an environment by name, or the default environment if no name is provided
|
|
3349
|
+
*
|
|
3350
|
+
* @param name - The name of the environment to retrieve.
|
|
3351
|
+
* @returns The requested environment context.
|
|
3352
|
+
*/
|
|
3383
3353
|
async getEnvironment(name) {
|
|
3384
3354
|
let environment;
|
|
3385
3355
|
if (name) {
|
|
@@ -3498,24 +3468,20 @@ ${context.entry.map((entry) => `- ${entry.input.file || entry.file}${entry.outpu
|
|
|
3498
3468
|
context.log(types.LogLevelLabel.TRACE, `Powerlines configuration has been resolved:
|
|
3499
3469
|
|
|
3500
3470
|
${console.formatLogMessage(context.config)}`);
|
|
3501
|
-
await
|
|
3471
|
+
await chunkDQI2I5KK_js.writeMetaFile(context);
|
|
3502
3472
|
context.persistedMeta = context.meta;
|
|
3503
3473
|
if (!context.fs.existsSync(context.cachePath)) {
|
|
3504
|
-
await
|
|
3505
|
-
mode: "fs"
|
|
3506
|
-
});
|
|
3474
|
+
await helpers.createDirectory(context.cachePath);
|
|
3507
3475
|
}
|
|
3508
3476
|
if (!context.fs.existsSync(context.dataPath)) {
|
|
3509
|
-
await
|
|
3510
|
-
mode: "fs"
|
|
3511
|
-
});
|
|
3477
|
+
await helpers.createDirectory(context.dataPath);
|
|
3512
3478
|
}
|
|
3513
3479
|
await this.callPreHook(context, "prepare");
|
|
3514
3480
|
await this.callNormalHook(context, "prepare");
|
|
3515
3481
|
if (context.config.output.dts !== false) {
|
|
3516
3482
|
context.log(types.LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
|
|
3517
3483
|
if (context.fs.existsSync(context.dtsPath)) {
|
|
3518
|
-
await context.fs.
|
|
3484
|
+
await context.fs.remove(context.dtsPath);
|
|
3519
3485
|
}
|
|
3520
3486
|
context.log(types.LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
|
|
3521
3487
|
const builtinFilePaths = await Promise.all((await context.getBuiltins()).map(async (file) => {
|
|
@@ -3602,7 +3568,7 @@ ${console.formatLogMessage(context.config)}`);
|
|
|
3602
3568
|
generatedTypes = result;
|
|
3603
3569
|
}
|
|
3604
3570
|
}
|
|
3605
|
-
await context.fs.
|
|
3571
|
+
await context.fs.write(context.dtsPath, `${directives ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
|
|
3606
3572
|
|
|
3607
3573
|
` : ""}${getFileHeader(context, {
|
|
3608
3574
|
directive: null,
|
|
@@ -3610,16 +3576,14 @@ ${console.formatLogMessage(context.config)}`);
|
|
|
3610
3576
|
})}
|
|
3611
3577
|
|
|
3612
3578
|
${formatTypes(generatedTypes)}
|
|
3613
|
-
|
|
3614
|
-
mode: "fs"
|
|
3615
|
-
});
|
|
3579
|
+
`);
|
|
3616
3580
|
}
|
|
3617
3581
|
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
3618
3582
|
if (!context.tsconfig) {
|
|
3619
3583
|
throw new Error("Failed to parse the TypeScript configuration file.");
|
|
3620
3584
|
}
|
|
3621
3585
|
await this.callPostHook(context, "prepare");
|
|
3622
|
-
await
|
|
3586
|
+
await chunkDQI2I5KK_js.writeMetaFile(context);
|
|
3623
3587
|
});
|
|
3624
3588
|
this.context.log(types.LogLevelLabel.INFO, "Powerlines API has been prepared successfully");
|
|
3625
3589
|
}
|
|
@@ -3680,8 +3644,8 @@ ${formatTypes(generatedTypes)}
|
|
|
3680
3644
|
await this.prepare(inlineConfig);
|
|
3681
3645
|
await this.#executeEnvironments(async (context) => {
|
|
3682
3646
|
this.context.log(types.LogLevelLabel.TRACE, "Cleaning the project's dist and artifacts directories.");
|
|
3683
|
-
await context.fs.
|
|
3684
|
-
await context.fs.
|
|
3647
|
+
await context.fs.remove(joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.buildPath));
|
|
3648
|
+
await context.fs.remove(joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.artifactsPath));
|
|
3685
3649
|
await callHook(context, "clean", {
|
|
3686
3650
|
sequential: true
|
|
3687
3651
|
});
|
|
@@ -3723,11 +3687,11 @@ ${formatTypes(generatedTypes)}
|
|
|
3723
3687
|
await this.#executeEnvironments(async (context) => {
|
|
3724
3688
|
await this.callPreHook(context, "build");
|
|
3725
3689
|
await this.callNormalHook(context, "build");
|
|
3726
|
-
if (context.config.output.
|
|
3727
|
-
const sourcePath = append.appendPath(context.config.output.
|
|
3690
|
+
if (context.config.output.buildPath !== context.config.output.outputPath) {
|
|
3691
|
+
const sourcePath = append.appendPath(context.config.output.buildPath, context.workspaceConfig.workspaceRoot);
|
|
3728
3692
|
const destinationPath = joinPaths.joinPaths(append.appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot), "dist");
|
|
3729
3693
|
if (sourcePath !== destinationPath) {
|
|
3730
|
-
context.log(types.LogLevelLabel.INFO, `Copying build output files from project's build directory (${context.config.output.
|
|
3694
|
+
context.log(types.LogLevelLabel.INFO, `Copying build output files from project's build directory (${context.config.output.buildPath}) to the workspace's output directory (${context.config.output.outputPath}).`);
|
|
3731
3695
|
await copyFile.copyFiles({
|
|
3732
3696
|
input: sourcePath,
|
|
3733
3697
|
glob: "**/*"
|
|
@@ -4070,7 +4034,7 @@ function withExecutor(command, executorFn) {
|
|
|
4070
4034
|
throw new Error("The executor requires `projectsConfigurations` on the context object.");
|
|
4071
4035
|
}
|
|
4072
4036
|
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
4073
|
-
const api = await src_default.from(workspaceConfig.workspaceRoot,
|
|
4037
|
+
const api = await src_default.from(workspaceConfig.workspaceRoot, defu6__default.default({
|
|
4074
4038
|
root: projectConfig.root,
|
|
4075
4039
|
type: projectConfig.projectType,
|
|
4076
4040
|
sourceRoot: projectConfig.sourceRoot,
|
|
@@ -4083,7 +4047,7 @@ function withExecutor(command, executorFn) {
|
|
|
4083
4047
|
}
|
|
4084
4048
|
}, options));
|
|
4085
4049
|
try {
|
|
4086
|
-
return await Promise.resolve(executorFn(
|
|
4050
|
+
return await Promise.resolve(executorFn(defu6__default.default({
|
|
4087
4051
|
projectName: context.projectName,
|
|
4088
4052
|
options,
|
|
4089
4053
|
workspaceConfig,
|