@powerlines/nx 0.10.37 → 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 +6 -0
- package/dist/{chunk-KTB7KDCP.mjs → chunk-2SK7GXYX.mjs} +1 -1
- package/dist/{chunk-R6CZOQMS.mjs → chunk-37R7Z4YA.mjs} +1 -1
- package/dist/{chunk-5HP24RWY.js → chunk-55HWRJFI.js} +2 -2
- package/dist/{chunk-53FEJYJL.js → chunk-5IM5S57N.js} +2 -2
- package/dist/{chunk-YMEHBI54.mjs → chunk-7Z54WTD3.mjs} +1 -1
- package/dist/{chunk-EKHF27MZ.mjs → chunk-BM5C4GAH.mjs} +1 -1
- package/dist/{chunk-UZF6PHPR.js → chunk-CJE2WIZT.js} +2 -2
- package/dist/{chunk-ZH5WF5UY.js → chunk-DDZYTWHI.js} +2 -2
- package/dist/{chunk-RWFBSRGJ.js → chunk-DNMCZOZX.js} +2 -2
- package/dist/{chunk-2PYUYDPD.js → chunk-DQI2I5KK.js} +1 -3
- package/dist/{chunk-C3K6TKXH.js → chunk-F7EY5OCV.js} +903 -919
- package/dist/{chunk-Q3ODFYEY.mjs → chunk-HJZ2I6NE.mjs} +1 -1
- package/dist/{chunk-D4UEK625.js → chunk-JXYA5T7X.js} +2 -2
- package/dist/{chunk-XZORJRHX.js → chunk-KBRCV5NY.js} +3 -3
- package/dist/{chunk-LLXWCS4O.mjs → chunk-OIL7SLIA.mjs} +1 -1
- package/dist/{chunk-HI5N4XXZ.mjs → chunk-OS2GSBDL.mjs} +899 -914
- package/dist/{chunk-WGIN2BGP.mjs → chunk-OVX2CEXQ.mjs} +1 -3
- package/dist/{chunk-32H4LR4S.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/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');
|
|
@@ -29,6 +30,8 @@ var Handlebars = require('handlebars');
|
|
|
29
30
|
var helperPluginUtils = require('@babel/helper-plugin-utils');
|
|
30
31
|
var t = require('@babel/types');
|
|
31
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');
|
|
@@ -45,7 +48,6 @@ var murmurhash = require('@stryke/hash/murmurhash');
|
|
|
45
48
|
var getUnique = require('@stryke/helpers/get-unique');
|
|
46
49
|
var omit = require('@stryke/helpers/omit');
|
|
47
50
|
var isType = require('@stryke/path/is-type');
|
|
48
|
-
var join = require('@stryke/path/join');
|
|
49
51
|
var isNull = require('@stryke/type-checks/is-null');
|
|
50
52
|
var isString = require('@stryke/type-checks/is-string');
|
|
51
53
|
var uuid = require('@stryke/unique-id/uuid');
|
|
@@ -55,21 +57,19 @@ var isUndefined = require('@stryke/type-checks/is-undefined');
|
|
|
55
57
|
var parseTypeDefinition = require('@stryke/convert/parse-type-definition');
|
|
56
58
|
var isFile = require('@stryke/fs/is-file');
|
|
57
59
|
var $ = require('@stryke/capnp');
|
|
58
|
-
var bufferToString = require('@stryke/convert/buffer-to-string');
|
|
59
60
|
var buffer = require('@stryke/fs/buffer');
|
|
60
61
|
var correctPath = require('@stryke/path/correct-path');
|
|
62
|
+
var isParentPath = require('@stryke/path/is-parent-path');
|
|
61
63
|
var prettyBytes = require('@stryke/string-format/pretty-bytes');
|
|
62
|
-
var isBuffer = require('@stryke/type-checks/is-buffer');
|
|
63
64
|
var flatCache = require('flat-cache');
|
|
64
65
|
var buffer$1 = require('buffer');
|
|
65
|
-
var _fs = require('fs');
|
|
66
66
|
var colors = require('@storm-software/config-tools/utilities/colors');
|
|
67
67
|
var noop = require('@stryke/helpers/noop');
|
|
68
68
|
var slash = require('@stryke/path/slash');
|
|
69
|
-
var
|
|
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
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 = "";
|
|
@@ -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
|
}
|
|
@@ -415,7 +519,7 @@ function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfi
|
|
|
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 = ts__default.default.parseJsonConfigFileContent(
|
|
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,9 +560,6 @@ 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
|
-
if (filePathFns.findFileExtension(context.dtsPath) !== "d.ts" && filePathFns.findFileExtension(context.dtsPath) !== "d.cts" && filePathFns.findFileExtension(context.dtsPath) !== "d.mts") {
|
|
460
|
-
context.config.output.dts = joinPaths.joinPaths(context.dtsPath, "powerlines.d.ts");
|
|
461
|
-
}
|
|
462
563
|
const dtsRelativePath = joinPaths.joinPaths(filePathFns.relativePath(joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot), filePathFns.findFilePath(context.dtsPath)), filePathFns.findFileName(context.dtsPath));
|
|
463
564
|
if (!tsconfigJson.include?.some((filePattern) => isIncludeMatchFound(filePattern, [
|
|
464
565
|
context.dtsPath,
|
|
@@ -501,9 +602,7 @@ async function initializeTsconfig(context) {
|
|
|
501
602
|
context.tsconfig.originalTsconfigJson = await json.readJsonFile(tsconfigFilePath);
|
|
502
603
|
context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
|
|
503
604
|
context.log(types.LogLevelLabel.TRACE, "Writing updated TypeScript configuration (tsconfig.json) file to disk.");
|
|
504
|
-
await context.
|
|
505
|
-
mode: "fs"
|
|
506
|
-
});
|
|
605
|
+
await writeFile(context.log, tsconfigFilePath, stormJson.StormJSON.stringify(context.tsconfig.tsconfigJson));
|
|
507
606
|
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
|
|
508
607
|
}
|
|
509
608
|
chunkSHUYVCID_js.__name(initializeTsconfig, "initializeTsconfig");
|
|
@@ -563,7 +662,7 @@ async function resolveTsconfig(context) {
|
|
|
563
662
|
chunkSHUYVCID_js.__name(resolveTsconfig, "resolveTsconfig");
|
|
564
663
|
var DEFAULT_ENVIRONMENT = "default";
|
|
565
664
|
function createEnvironment(name, userConfig) {
|
|
566
|
-
return
|
|
665
|
+
return defu6__default.default(userConfig.environments?.[name] ?? {}, {
|
|
567
666
|
name,
|
|
568
667
|
title: userConfig.title || titleCase.titleCase(userConfig.name),
|
|
569
668
|
ssr: false,
|
|
@@ -607,8 +706,7 @@ function createDefaultEnvironment(userConfig) {
|
|
|
607
706
|
}
|
|
608
707
|
chunkSHUYVCID_js.__name(createDefaultEnvironment, "createDefaultEnvironment");
|
|
609
708
|
function resolveOptions(options) {
|
|
610
|
-
return
|
|
611
|
-
debug: options.logLevel === "trace",
|
|
709
|
+
return defu6__default.default(options, {
|
|
612
710
|
interopDefault: true,
|
|
613
711
|
fsCache: options.mode !== "development" ? joinPaths.joinPaths(options.cacheDir, "jiti") : false,
|
|
614
712
|
moduleCache: options.mode !== "development"
|
|
@@ -699,7 +797,7 @@ function replacePathTokens(context, path) {
|
|
|
699
797
|
if (!path) {
|
|
700
798
|
return path;
|
|
701
799
|
}
|
|
702
|
-
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));
|
|
703
801
|
}
|
|
704
802
|
chunkSHUYVCID_js.__name(replacePathTokens, "replacePathTokens");
|
|
705
803
|
function resolveEntryInputFile(context, typeDefinition) {
|
|
@@ -783,7 +881,7 @@ var FileMetadata = class _FileMetadata extends $__namespace.Struct {
|
|
|
783
881
|
static _capnp = {
|
|
784
882
|
displayName: "FileMetadata",
|
|
785
883
|
id: "8e2cab5d7e28c7b3",
|
|
786
|
-
size: new $__namespace.ObjectSize(8,
|
|
884
|
+
size: new $__namespace.ObjectSize(8, 3),
|
|
787
885
|
defaultType: "normal"
|
|
788
886
|
};
|
|
789
887
|
static _Properties;
|
|
@@ -798,7 +896,7 @@ var FileMetadata = class _FileMetadata extends $__namespace.Struct {
|
|
|
798
896
|
$__namespace.utils.setText(0, value, this);
|
|
799
897
|
}
|
|
800
898
|
/**
|
|
801
|
-
* The
|
|
899
|
+
* The timestamp representing the file's creation date.
|
|
802
900
|
*
|
|
803
901
|
*/
|
|
804
902
|
get type() {
|
|
@@ -808,16 +906,6 @@ var FileMetadata = class _FileMetadata extends $__namespace.Struct {
|
|
|
808
906
|
$__namespace.utils.setText(1, value, this);
|
|
809
907
|
}
|
|
810
908
|
/**
|
|
811
|
-
* The timestamp representing the file's creation date.
|
|
812
|
-
*
|
|
813
|
-
*/
|
|
814
|
-
get mode() {
|
|
815
|
-
return $__namespace.utils.getText(2, this);
|
|
816
|
-
}
|
|
817
|
-
set mode(value) {
|
|
818
|
-
$__namespace.utils.setText(2, value, this);
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
909
|
* Additional metadata associated with the file.
|
|
822
910
|
*
|
|
823
911
|
*/
|
|
@@ -828,22 +916,22 @@ var FileMetadata = class _FileMetadata extends $__namespace.Struct {
|
|
|
828
916
|
$__namespace.utils.setUint32(0, value, this);
|
|
829
917
|
}
|
|
830
918
|
_adoptProperties(value) {
|
|
831
|
-
$__namespace.utils.adopt(value, $__namespace.utils.getPointer(
|
|
919
|
+
$__namespace.utils.adopt(value, $__namespace.utils.getPointer(2, this));
|
|
832
920
|
}
|
|
833
921
|
_disownProperties() {
|
|
834
922
|
return $__namespace.utils.disown(this.properties);
|
|
835
923
|
}
|
|
836
924
|
get properties() {
|
|
837
|
-
return $__namespace.utils.getList(
|
|
925
|
+
return $__namespace.utils.getList(2, _FileMetadata._Properties, this);
|
|
838
926
|
}
|
|
839
927
|
_hasProperties() {
|
|
840
|
-
return !$__namespace.utils.isNull($__namespace.utils.getPointer(
|
|
928
|
+
return !$__namespace.utils.isNull($__namespace.utils.getPointer(2, this));
|
|
841
929
|
}
|
|
842
930
|
_initProperties(length) {
|
|
843
|
-
return $__namespace.utils.initList(
|
|
931
|
+
return $__namespace.utils.initList(2, _FileMetadata._Properties, length, this);
|
|
844
932
|
}
|
|
845
933
|
set properties(value) {
|
|
846
|
-
$__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(
|
|
934
|
+
$__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(2, this));
|
|
847
935
|
}
|
|
848
936
|
toString() {
|
|
849
937
|
return "FileMetadata_" + super.toString();
|
|
@@ -878,13 +966,13 @@ var FileId = class extends $__namespace.Struct {
|
|
|
878
966
|
return "FileId_" + super.toString();
|
|
879
967
|
}
|
|
880
968
|
};
|
|
881
|
-
var
|
|
969
|
+
var FileStorage = class extends $__namespace.Struct {
|
|
882
970
|
static {
|
|
883
|
-
chunkSHUYVCID_js.__name(this, "
|
|
971
|
+
chunkSHUYVCID_js.__name(this, "FileStorage");
|
|
884
972
|
}
|
|
885
973
|
static _capnp = {
|
|
886
|
-
displayName: "
|
|
887
|
-
id: "
|
|
974
|
+
displayName: "FileStorage",
|
|
975
|
+
id: "9dca66ac858c9ebe",
|
|
888
976
|
size: new $__namespace.ObjectSize(0, 2)
|
|
889
977
|
};
|
|
890
978
|
/**
|
|
@@ -904,7 +992,7 @@ var FileData = class extends $__namespace.Struct {
|
|
|
904
992
|
$__namespace.utils.setText(1, value, this);
|
|
905
993
|
}
|
|
906
994
|
toString() {
|
|
907
|
-
return "
|
|
995
|
+
return "FileStorage_" + super.toString();
|
|
908
996
|
}
|
|
909
997
|
};
|
|
910
998
|
var FileSystem = class _FileSystem extends $__namespace.Struct {
|
|
@@ -917,7 +1005,7 @@ var FileSystem = class _FileSystem extends $__namespace.Struct {
|
|
|
917
1005
|
size: new $__namespace.ObjectSize(0, 3)
|
|
918
1006
|
};
|
|
919
1007
|
static _Ids;
|
|
920
|
-
static
|
|
1008
|
+
static _Storage;
|
|
921
1009
|
static _Metadata;
|
|
922
1010
|
_adoptIds(value) {
|
|
923
1011
|
$__namespace.utils.adopt(value, $__namespace.utils.getPointer(0, this));
|
|
@@ -937,22 +1025,22 @@ var FileSystem = class _FileSystem extends $__namespace.Struct {
|
|
|
937
1025
|
set ids(value) {
|
|
938
1026
|
$__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(0, this));
|
|
939
1027
|
}
|
|
940
|
-
|
|
1028
|
+
_adoptStorage(value) {
|
|
941
1029
|
$__namespace.utils.adopt(value, $__namespace.utils.getPointer(1, this));
|
|
942
1030
|
}
|
|
943
|
-
|
|
944
|
-
return $__namespace.utils.disown(this.
|
|
1031
|
+
_disownStorage() {
|
|
1032
|
+
return $__namespace.utils.disown(this.storage);
|
|
945
1033
|
}
|
|
946
|
-
get
|
|
947
|
-
return $__namespace.utils.getList(1, _FileSystem.
|
|
1034
|
+
get storage() {
|
|
1035
|
+
return $__namespace.utils.getList(1, _FileSystem._Storage, this);
|
|
948
1036
|
}
|
|
949
|
-
|
|
1037
|
+
_hasStorage() {
|
|
950
1038
|
return !$__namespace.utils.isNull($__namespace.utils.getPointer(1, this));
|
|
951
1039
|
}
|
|
952
|
-
|
|
953
|
-
return $__namespace.utils.initList(1, _FileSystem.
|
|
1040
|
+
_initStorage(length) {
|
|
1041
|
+
return $__namespace.utils.initList(1, _FileSystem._Storage, length, this);
|
|
954
1042
|
}
|
|
955
|
-
set
|
|
1043
|
+
set storage(value) {
|
|
956
1044
|
$__namespace.utils.copyFrom(value, $__namespace.utils.getPointer(1, this));
|
|
957
1045
|
}
|
|
958
1046
|
_adoptMetadata(value) {
|
|
@@ -979,12 +1067,15 @@ var FileSystem = class _FileSystem extends $__namespace.Struct {
|
|
|
979
1067
|
};
|
|
980
1068
|
FileMetadata._Properties = $__namespace.CompositeList(FileMetadata_KeyValuePair);
|
|
981
1069
|
FileSystem._Ids = $__namespace.CompositeList(FileId);
|
|
982
|
-
FileSystem.
|
|
1070
|
+
FileSystem._Storage = $__namespace.CompositeList(FileStorage);
|
|
983
1071
|
FileSystem._Metadata = $__namespace.CompositeList(FileMetadata);
|
|
984
1072
|
|
|
985
1073
|
// ../powerlines/src/types/fs.ts
|
|
986
|
-
var
|
|
987
|
-
|
|
1074
|
+
var StoragePreset = /* @__PURE__ */ (function(StoragePreset2) {
|
|
1075
|
+
StoragePreset2["VIRTUAL"] = "virtual";
|
|
1076
|
+
StoragePreset2["FS"] = "fs";
|
|
1077
|
+
return StoragePreset2;
|
|
1078
|
+
})({});
|
|
988
1079
|
var createLog = /* @__PURE__ */ chunkSHUYVCID_js.__name((name, options = {}) => {
|
|
989
1080
|
const logLevel = options.logLevel === null ? types.LogLevelLabel.SILENT : options.logLevel || types.LogLevelLabel.INFO;
|
|
990
1081
|
if (logLevel === types.LogLevelLabel.SILENT) {
|
|
@@ -1023,142 +1114,18 @@ var BADGE_COLORS = [
|
|
|
1023
1114
|
var extendLog = /* @__PURE__ */ chunkSHUYVCID_js.__name((logFn, name) => {
|
|
1024
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(" ")} `);
|
|
1025
1116
|
}, "extendLog");
|
|
1026
|
-
function
|
|
1027
|
-
return
|
|
1028
|
-
}
|
|
1029
|
-
chunkSHUYVCID_js.__name(isBufferEncoding, "isBufferEncoding");
|
|
1030
|
-
function isPowerlinesWriteFileOptions(options) {
|
|
1031
|
-
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;
|
|
1032
1119
|
}
|
|
1033
|
-
chunkSHUYVCID_js.__name(
|
|
1034
|
-
function
|
|
1035
|
-
return
|
|
1120
|
+
chunkSHUYVCID_js.__name(isFileError, "isFileError");
|
|
1121
|
+
function ignoreNotfound(err) {
|
|
1122
|
+
return isFileError(err) && (err.code === "ENOENT" || err.code === "EISDIR" ? null : err);
|
|
1036
1123
|
}
|
|
1037
|
-
chunkSHUYVCID_js.__name(
|
|
1124
|
+
chunkSHUYVCID_js.__name(ignoreNotfound, "ignoreNotfound");
|
|
1038
1125
|
function toFilePath(path) {
|
|
1039
1126
|
return correctPath.correctPath(slash.slash(path?.toString() || ".").replace(/^file:\/\//, ""));
|
|
1040
1127
|
}
|
|
1041
1128
|
chunkSHUYVCID_js.__name(toFilePath, "toFilePath");
|
|
1042
|
-
var FS_METHODS = [
|
|
1043
|
-
"mkdir",
|
|
1044
|
-
"mkdirSync",
|
|
1045
|
-
"rmdir",
|
|
1046
|
-
"rmdirSync",
|
|
1047
|
-
"unlink",
|
|
1048
|
-
"unlinkSync",
|
|
1049
|
-
"existsSync",
|
|
1050
|
-
"realpathSync",
|
|
1051
|
-
"writeFileSync",
|
|
1052
|
-
"readFileSync",
|
|
1053
|
-
"readdirSync",
|
|
1054
|
-
"createWriteStream",
|
|
1055
|
-
"WriteStream",
|
|
1056
|
-
"createReadStream",
|
|
1057
|
-
"ReadStream"
|
|
1058
|
-
];
|
|
1059
|
-
var FS_PROMISE_METHODS = [
|
|
1060
|
-
"mkdir",
|
|
1061
|
-
"rm",
|
|
1062
|
-
"rmdir",
|
|
1063
|
-
"unlink",
|
|
1064
|
-
"writeFile",
|
|
1065
|
-
"readFile",
|
|
1066
|
-
"readdir",
|
|
1067
|
-
"stat",
|
|
1068
|
-
"lstat"
|
|
1069
|
-
];
|
|
1070
|
-
function cloneFS(originalFS) {
|
|
1071
|
-
const clonedFS = {
|
|
1072
|
-
...originalFS,
|
|
1073
|
-
promises: {
|
|
1074
|
-
...originalFS.promises ?? {}
|
|
1075
|
-
}
|
|
1076
|
-
};
|
|
1077
|
-
for (const method of FS_METHODS) {
|
|
1078
|
-
if (originalFS[method]) {
|
|
1079
|
-
clonedFS[method] = originalFS[method];
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
originalFS.promises ??= {};
|
|
1083
|
-
for (const method of FS_PROMISE_METHODS) {
|
|
1084
|
-
if (originalFS.promises[method]) {
|
|
1085
|
-
clonedFS.promises ??= {};
|
|
1086
|
-
clonedFS.promises[method] = originalFS.promises[method];
|
|
1087
|
-
clonedFS[method] = originalFS.promises[method];
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
for (const prop in clonedFS) {
|
|
1091
|
-
if (isFunction.isFunction(clonedFS[prop])) {
|
|
1092
|
-
clonedFS[prop] = clonedFS[prop].bind(originalFS);
|
|
1093
|
-
if (isFunction.isFunction(clonedFS.promises[prop])) {
|
|
1094
|
-
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
for (const prop in clonedFS.promises) {
|
|
1099
|
-
if (isFunction.isFunction(clonedFS.promises[prop])) {
|
|
1100
|
-
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
return clonedFS;
|
|
1104
|
-
}
|
|
1105
|
-
chunkSHUYVCID_js.__name(cloneFS, "cloneFS");
|
|
1106
|
-
function patchFS(originalFS, vfs) {
|
|
1107
|
-
const clonedFS = cloneFS(originalFS);
|
|
1108
|
-
originalFS.mkdirSync = (file, options) => vfs.mkdirSync(toFilePath(file), options);
|
|
1109
|
-
originalFS.mkdir = (file, options, callback) => vfs.mkdir(toFilePath(file), options, callback);
|
|
1110
|
-
originalFS.promises.mkdir = async (file, options) => vfs.mkdir(toFilePath(file), options);
|
|
1111
|
-
originalFS.unlinkSync = (file) => vfs.unlinkSync(toFilePath(file));
|
|
1112
|
-
originalFS.promises.rm = async (file, options) => vfs.rm(toFilePath(file), options);
|
|
1113
|
-
originalFS.promises.unlink = async (file) => vfs.unlink(toFilePath(file));
|
|
1114
|
-
originalFS.existsSync = (file) => vfs.existsSync(toFilePath(file));
|
|
1115
|
-
Object.defineProperty(originalFS, "realpathSync", {
|
|
1116
|
-
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.realpathSync(toFilePath(file), options), "value")
|
|
1117
|
-
});
|
|
1118
|
-
originalFS.writeFileSync = (file, data, options) => vfs.writeFileSync(toFilePath(file), data, options);
|
|
1119
|
-
originalFS.promises.writeFile = async (file, data, options) => vfs.writeFile(toFilePath(file), data, options);
|
|
1120
|
-
originalFS.readFileSync = (file, options) => vfs.readFileSync(toFilePath(file), options);
|
|
1121
|
-
originalFS.promises.readFile = (file, options) => vfs.readFile(toFilePath(file), options);
|
|
1122
|
-
originalFS.readdirSync = (file, options) => vfs.readdirSync(toFilePath(file), options);
|
|
1123
|
-
originalFS.promises.readdir = (file, options) => vfs.readdir(toFilePath(file), options);
|
|
1124
|
-
Object.defineProperty(originalFS, "statSync", {
|
|
1125
|
-
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.statSync(toFilePath(file), options), "value")
|
|
1126
|
-
});
|
|
1127
|
-
originalFS.stat = (file, options) => vfs.statSync(toFilePath(file), options);
|
|
1128
|
-
originalFS.promises.stat = (file, options) => vfs.stat(toFilePath(file), options);
|
|
1129
|
-
Object.defineProperty(originalFS, "lstatSync", {
|
|
1130
|
-
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.lstatSync(toFilePath(file), options), "value")
|
|
1131
|
-
});
|
|
1132
|
-
originalFS.lstat = (file, options) => vfs.lstatSync(toFilePath(file), options);
|
|
1133
|
-
originalFS.promises.lstat = (file, options) => vfs.lstat(toFilePath(file), options);
|
|
1134
|
-
return () => {
|
|
1135
|
-
originalFS.mkdirSync = clonedFS.mkdirSync;
|
|
1136
|
-
originalFS.mkdir = clonedFS.mkdir;
|
|
1137
|
-
originalFS.promises.mkdir = clonedFS.promises.mkdir;
|
|
1138
|
-
originalFS.unlinkSync = clonedFS.unlinkSync;
|
|
1139
|
-
originalFS.promises.rm = clonedFS.promises.rm;
|
|
1140
|
-
originalFS.promises.unlink = clonedFS.promises.unlink;
|
|
1141
|
-
originalFS.existsSync = clonedFS.existsSync;
|
|
1142
|
-
originalFS.realpathSync = clonedFS.realpathSync;
|
|
1143
|
-
originalFS.writeFileSync = clonedFS.writeFileSync;
|
|
1144
|
-
originalFS.promises.writeFile = clonedFS.promises.writeFile;
|
|
1145
|
-
originalFS.readFileSync = clonedFS.readFileSync;
|
|
1146
|
-
originalFS.promises.readFile = clonedFS.promises.readFile;
|
|
1147
|
-
originalFS.readdirSync = clonedFS.readdirSync;
|
|
1148
|
-
originalFS.promises.readdir = clonedFS.promises.readdir;
|
|
1149
|
-
Object.defineProperty(originalFS, "statSync", {
|
|
1150
|
-
value: clonedFS.statSync
|
|
1151
|
-
});
|
|
1152
|
-
originalFS.stat = clonedFS.stat;
|
|
1153
|
-
originalFS.promises.stat = clonedFS.promises.stat;
|
|
1154
|
-
Object.defineProperty(originalFS, "lstatSync", {
|
|
1155
|
-
value: clonedFS.lstatSync
|
|
1156
|
-
});
|
|
1157
|
-
originalFS.lstat = clonedFS.lstat;
|
|
1158
|
-
originalFS.promises.lstat = clonedFS.promises.lstat;
|
|
1159
|
-
};
|
|
1160
|
-
}
|
|
1161
|
-
chunkSHUYVCID_js.__name(patchFS, "patchFS");
|
|
1162
1129
|
function isValidId(id, prefix = "powerlines") {
|
|
1163
1130
|
return id.replace(/^\\0/, "").startsWith(`${prefix.replace(/:$/, "")}`);
|
|
1164
1131
|
}
|
|
@@ -1168,164 +1135,368 @@ function normalizeId(id, prefix = "powerlines") {
|
|
|
1168
1135
|
}
|
|
1169
1136
|
chunkSHUYVCID_js.__name(normalizeId, "normalizeId");
|
|
1170
1137
|
function normalizePath(path, builtinsPath, prefix = "powerlines") {
|
|
1171
|
-
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);
|
|
1172
1139
|
}
|
|
1173
1140
|
chunkSHUYVCID_js.__name(normalizePath, "normalizePath");
|
|
1174
|
-
|
|
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 {
|
|
1175
1156
|
static {
|
|
1176
|
-
chunkSHUYVCID_js.__name(this, "
|
|
1157
|
+
chunkSHUYVCID_js.__name(this, "BaseStorageAdapter");
|
|
1177
1158
|
}
|
|
1178
1159
|
/**
|
|
1179
|
-
*
|
|
1160
|
+
* Indicates whether the storage adapter has been disposed.
|
|
1180
1161
|
*/
|
|
1181
|
-
#
|
|
1162
|
+
#isDisposed = false;
|
|
1182
1163
|
/**
|
|
1183
|
-
*
|
|
1164
|
+
* Configuration options for the storage adapter.
|
|
1184
1165
|
*/
|
|
1185
|
-
|
|
1166
|
+
options;
|
|
1186
1167
|
/**
|
|
1187
|
-
*
|
|
1168
|
+
* Constructor for the BaseStorageAdapter.
|
|
1169
|
+
*
|
|
1170
|
+
* @param options - Configuration options for the storage adapter.
|
|
1188
1171
|
*/
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1196
|
-
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;
|
|
1197
1178
|
}
|
|
1198
1179
|
/**
|
|
1199
|
-
*
|
|
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`.
|
|
1200
1184
|
*/
|
|
1201
|
-
|
|
1202
|
-
return this
|
|
1185
|
+
async exists(key) {
|
|
1186
|
+
return this.existsSync(key);
|
|
1203
1187
|
}
|
|
1204
1188
|
/**
|
|
1205
|
-
*
|
|
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.
|
|
1206
1193
|
*/
|
|
1207
|
-
get
|
|
1208
|
-
return this
|
|
1194
|
+
async get(key) {
|
|
1195
|
+
return this.getSync(key);
|
|
1209
1196
|
}
|
|
1210
1197
|
/**
|
|
1211
|
-
*
|
|
1198
|
+
* Asynchronously sets the value for a given key.
|
|
1212
1199
|
*
|
|
1213
|
-
* @param
|
|
1214
|
-
* @param
|
|
1200
|
+
* @param key - The key to set the value for.
|
|
1201
|
+
* @param value - The value to set.
|
|
1215
1202
|
*/
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
if (!this.#physicalFS.existsSync(this.#context.dataPath)) {
|
|
1220
|
-
this.#physicalFS.mkdirSync(this.#context.dataPath, {
|
|
1221
|
-
recursive: true
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1224
|
-
if (!this.#physicalFS.existsSync(this.#context.cachePath)) {
|
|
1225
|
-
this.#physicalFS.mkdirSync(this.#context.cachePath, {
|
|
1226
|
-
recursive: true
|
|
1227
|
-
});
|
|
1203
|
+
async set(key, value) {
|
|
1204
|
+
if (!this.options.isReadOnly) {
|
|
1205
|
+
this.setSync(key, value);
|
|
1228
1206
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
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);
|
|
1233
1216
|
}
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
this.#virtualFS.mkdirSync(this.#context.builtinsPath, {
|
|
1246
|
-
recursive: true
|
|
1247
|
-
});
|
|
1248
|
-
}
|
|
1249
|
-
if (!this.#virtualFS.existsSync(this.#context.entryPath)) {
|
|
1250
|
-
this.#virtualFS.mkdirSync(this.#context.entryPath, {
|
|
1251
|
-
recursive: true
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
if (!this.#virtualFS.existsSync(this.#context.dtsPath)) {
|
|
1255
|
-
this.#virtualFS.mkdirSync(this.#context.dtsPath, {
|
|
1256
|
-
recursive: true
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
} else if (this.#context.config.projectType === "application") {
|
|
1260
|
-
if (!this.#physicalFS.existsSync(this.#context.artifactsPath)) {
|
|
1261
|
-
this.#physicalFS.mkdirSync(this.#context.artifactsPath, {
|
|
1262
|
-
recursive: true
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
if (!this.#physicalFS.existsSync(this.#context.builtinsPath)) {
|
|
1266
|
-
this.#physicalFS.mkdirSync(this.#context.builtinsPath, {
|
|
1267
|
-
recursive: true
|
|
1268
|
-
});
|
|
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;
|
|
1269
1228
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
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;
|
|
1274
1243
|
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
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);
|
|
1279
1383
|
}
|
|
1280
1384
|
}
|
|
1281
1385
|
}
|
|
1282
1386
|
/**
|
|
1283
|
-
*
|
|
1387
|
+
* Asynchronously removes a key from the storage.
|
|
1284
1388
|
*
|
|
1285
|
-
* @param
|
|
1286
|
-
* @param options - Options for the operation, such as output mode.
|
|
1287
|
-
* @returns The file system module used for the operation.
|
|
1389
|
+
* @param key - The key to remove.
|
|
1288
1390
|
*/
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
return {
|
|
1293
|
-
...this.#virtualFS,
|
|
1294
|
-
mode: "virtual"
|
|
1295
|
-
};
|
|
1296
|
-
} else if (mode === "fs") {
|
|
1297
|
-
return {
|
|
1298
|
-
...this.#physicalFS,
|
|
1299
|
-
mode: "fs"
|
|
1300
|
-
};
|
|
1391
|
+
async remove(key) {
|
|
1392
|
+
if (!this.options.isReadOnly) {
|
|
1393
|
+
return promises.unlink(this.resolve(key)).catch(ignoreNotfound);
|
|
1301
1394
|
}
|
|
1302
|
-
return {
|
|
1303
|
-
...this,
|
|
1304
|
-
mode: this.#context.config.output.mode
|
|
1305
|
-
};
|
|
1306
1395
|
}
|
|
1307
1396
|
/**
|
|
1308
|
-
*
|
|
1397
|
+
* Lists all keys under a given base path synchronously.
|
|
1309
1398
|
*
|
|
1310
|
-
* @param
|
|
1311
|
-
* @
|
|
1312
|
-
* @returns The file system module used for the operation.
|
|
1399
|
+
* @param base - The base path to list keys from.
|
|
1400
|
+
* @returns An array of keys under the specified base path.
|
|
1313
1401
|
*/
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
return
|
|
1317
|
-
|
|
1318
|
-
|
|
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) ?? [];
|
|
1319
1409
|
}
|
|
1320
|
-
return void 0;
|
|
1321
1410
|
}
|
|
1322
1411
|
/**
|
|
1323
|
-
*
|
|
1412
|
+
* Asynchronously lists all keys under a given base path.
|
|
1324
1413
|
*
|
|
1325
|
-
* @
|
|
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.
|
|
1326
1416
|
*/
|
|
1327
|
-
|
|
1328
|
-
return this
|
|
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.
|
|
1445
|
+
*
|
|
1446
|
+
* @param key - The key to check for existence.
|
|
1447
|
+
* @returns Returns `true` if the key exists, otherwise `false`.
|
|
1448
|
+
*/
|
|
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);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Synchronously removes a key from the storage.
|
|
1474
|
+
*
|
|
1475
|
+
* @param key - The key to remove.
|
|
1476
|
+
*/
|
|
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();
|
|
1329
1500
|
}
|
|
1330
1501
|
};
|
|
1331
1502
|
|
|
@@ -1347,29 +1518,23 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1347
1518
|
*/
|
|
1348
1519
|
#paths;
|
|
1349
1520
|
/**
|
|
1350
|
-
* A cache for module resolution results.
|
|
1351
|
-
*/
|
|
1352
|
-
#resolverCache;
|
|
1353
|
-
/**
|
|
1354
1521
|
* The unified volume that combines the virtual file system with the real file system.
|
|
1355
1522
|
*
|
|
1356
1523
|
* @remarks
|
|
1357
1524
|
* This volume allows for seamless access to both virtual and real files.
|
|
1358
1525
|
*/
|
|
1359
|
-
#
|
|
1526
|
+
#storage = {
|
|
1527
|
+
"": new FileSystemStorageAdapter()
|
|
1528
|
+
};
|
|
1360
1529
|
/**
|
|
1361
|
-
*
|
|
1530
|
+
* A cache for module resolution results.
|
|
1362
1531
|
*/
|
|
1363
|
-
#
|
|
1532
|
+
#resolverCache;
|
|
1364
1533
|
/**
|
|
1365
1534
|
* Indicator specifying if the virtual file system (VFS) is disposed
|
|
1366
1535
|
*/
|
|
1367
1536
|
#isDisposed = false;
|
|
1368
1537
|
/**
|
|
1369
|
-
* Function to revert require patch
|
|
1370
|
-
*/
|
|
1371
|
-
#revert;
|
|
1372
|
-
/**
|
|
1373
1538
|
* The context of the virtual file system.
|
|
1374
1539
|
*/
|
|
1375
1540
|
#context;
|
|
@@ -1378,15 +1543,6 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1378
1543
|
*/
|
|
1379
1544
|
#log;
|
|
1380
1545
|
/**
|
|
1381
|
-
* Checks if a path exists in the virtual file system (VFS).
|
|
1382
|
-
*
|
|
1383
|
-
* @param path - The path to check.
|
|
1384
|
-
* @returns `true` if the path exists, otherwise `false`.
|
|
1385
|
-
*/
|
|
1386
|
-
#existsSync(path) {
|
|
1387
|
-
return this.#unifiedFS.virtual.existsSync(this.#normalizePath(path)) || this.#unifiedFS.physical.existsSync(this.#normalizePath(path)) || this.#unifiedFS.resolveFS(path).existsSync(this.#normalizePath(path));
|
|
1388
|
-
}
|
|
1389
|
-
/**
|
|
1390
1546
|
* Normalizes a given module id by resolving it against the built-ins path.
|
|
1391
1547
|
*
|
|
1392
1548
|
* @param id - The module id to normalize.
|
|
@@ -1415,6 +1571,43 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1415
1571
|
return new RegExp(`^${this.#normalizePath(path).replace(/\*\*/g, token).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(new RegExp(token, "g"), ".*")}$`);
|
|
1416
1572
|
}
|
|
1417
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
|
+
/**
|
|
1418
1611
|
* Creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
|
|
1419
1612
|
*
|
|
1420
1613
|
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
@@ -1424,7 +1617,13 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1424
1617
|
if (!context.config.skipCache && exists.existsSync(joinPaths.joinPaths(context.dataPath, "fs.bin"))) {
|
|
1425
1618
|
const buffer$1 = await buffer.readFileBuffer(joinPaths.joinPaths(context.dataPath, "fs.bin"));
|
|
1426
1619
|
const message2 = new $__namespace.Message(buffer$1, false);
|
|
1427
|
-
|
|
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
|
+
}
|
|
1428
1627
|
}
|
|
1429
1628
|
const message = new $__namespace.Message();
|
|
1430
1629
|
return new _VirtualFileSystem(context, message.initRoot(FileSystem));
|
|
@@ -1439,7 +1638,13 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1439
1638
|
if (!context.config.skipCache && exists.existsSync(joinPaths.joinPaths(context.dataPath, "fs.bin"))) {
|
|
1440
1639
|
const buffer$1 = buffer.readFileBufferSync(joinPaths.joinPaths(context.dataPath, "fs.bin"));
|
|
1441
1640
|
const message2 = new $__namespace.Message(buffer$1, false);
|
|
1442
|
-
|
|
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
|
+
}
|
|
1443
1648
|
}
|
|
1444
1649
|
const message = new $__namespace.Message();
|
|
1445
1650
|
return new _VirtualFileSystem(context, message.initRoot(FileSystem));
|
|
@@ -1474,6 +1679,9 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1474
1679
|
}, "get")
|
|
1475
1680
|
});
|
|
1476
1681
|
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Gets the resolver cache.
|
|
1684
|
+
*/
|
|
1477
1685
|
get resolverCache() {
|
|
1478
1686
|
if (!this.#resolverCache) {
|
|
1479
1687
|
this.#resolverCache = flatCache.create({
|
|
@@ -1492,16 +1700,34 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1492
1700
|
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
1493
1701
|
* @param fs - A buffer containing the serialized virtual file system data.
|
|
1494
1702
|
*/
|
|
1495
|
-
constructor(context,
|
|
1703
|
+
constructor(context, fs) {
|
|
1496
1704
|
this.#context = context;
|
|
1497
|
-
|
|
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
|
+
}
|
|
1498
1725
|
this.#metadata = {};
|
|
1499
|
-
if (
|
|
1500
|
-
this.#metadata =
|
|
1726
|
+
if (fs._hasMetadata()) {
|
|
1727
|
+
this.#metadata = fs.metadata.values().reduce((ret, metadata) => {
|
|
1501
1728
|
ret[metadata.id] = {
|
|
1502
1729
|
id: metadata.id,
|
|
1503
1730
|
type: metadata.type,
|
|
1504
|
-
mode: metadata.mode,
|
|
1505
1731
|
timestamp: metadata.timestamp || Date.now(),
|
|
1506
1732
|
properties: metadata._hasProperties() ? metadata.properties.values().reduce((ret2, item) => {
|
|
1507
1733
|
ret2[item.key] = item.value;
|
|
@@ -1513,12 +1739,12 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1513
1739
|
}
|
|
1514
1740
|
this.#ids = {};
|
|
1515
1741
|
this.#paths = {};
|
|
1516
|
-
if (
|
|
1517
|
-
this.#ids =
|
|
1742
|
+
if (fs._hasIds()) {
|
|
1743
|
+
this.#ids = fs.ids.values().reduce((ret, identifier) => {
|
|
1518
1744
|
ret[identifier.path] ??= identifier.id;
|
|
1519
1745
|
return ret;
|
|
1520
1746
|
}, {});
|
|
1521
|
-
this.#paths =
|
|
1747
|
+
this.#paths = fs.ids.values().reduce((ret, identifier) => {
|
|
1522
1748
|
ret[identifier.id] ??= identifier.path;
|
|
1523
1749
|
return ret;
|
|
1524
1750
|
}, {});
|
|
@@ -1526,187 +1752,123 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1526
1752
|
this.#log = extendLog(this.#context.log, "file-system");
|
|
1527
1753
|
}
|
|
1528
1754
|
/**
|
|
1529
|
-
*
|
|
1755
|
+
* Asynchronously checks if a file exists in the virtual file system (VFS).
|
|
1530
1756
|
*
|
|
1531
|
-
* @param
|
|
1532
|
-
* @returns
|
|
1533
|
-
*/
|
|
1534
|
-
isVirtual(pathOrId, importer, options = {}) {
|
|
1535
|
-
if (!pathOrId) {
|
|
1536
|
-
return false;
|
|
1537
|
-
}
|
|
1538
|
-
const resolvedPath = this.resolveSync(pathOrId, importer, options);
|
|
1539
|
-
if (!resolvedPath) {
|
|
1540
|
-
return false;
|
|
1541
|
-
}
|
|
1542
|
-
return this.metadata[resolvedPath]?.mode === "virtual";
|
|
1543
|
-
}
|
|
1544
|
-
/**
|
|
1545
|
-
* Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
|
|
1546
|
-
*
|
|
1547
|
-
* @param pathOrId - The path or id to check.
|
|
1548
|
-
* @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
|
|
1549
|
-
*/
|
|
1550
|
-
isPhysical(pathOrId, importer, options = {}) {
|
|
1551
|
-
if (!pathOrId) {
|
|
1552
|
-
return false;
|
|
1553
|
-
}
|
|
1554
|
-
const resolvedPath = this.resolveSync(pathOrId, importer, options);
|
|
1555
|
-
if (!resolvedPath) {
|
|
1556
|
-
return false;
|
|
1557
|
-
}
|
|
1558
|
-
return this.metadata[resolvedPath]?.mode === "fs";
|
|
1559
|
-
}
|
|
1560
|
-
/**
|
|
1561
|
-
* Lists files in a given path.
|
|
1562
|
-
*
|
|
1563
|
-
* @param path - The path to list files from.
|
|
1564
|
-
* @param options - Options for listing files, such as encoding and recursion.
|
|
1565
|
-
* @returns An array of file names in the specified path.
|
|
1566
|
-
*/
|
|
1567
|
-
readdirSync(path, options = "utf8") {
|
|
1568
|
-
return this.#unifiedFS.resolveFS(path).readdirSync(toFilePath(path), options);
|
|
1569
|
-
}
|
|
1570
|
-
/**
|
|
1571
|
-
* Removes a file in the virtual file system (VFS).
|
|
1572
|
-
*
|
|
1573
|
-
* @param path - The path to create the directory at.
|
|
1574
|
-
*/
|
|
1575
|
-
unlinkSync(path, options) {
|
|
1576
|
-
if (!this.isFile(this.#normalizePath(path))) {
|
|
1577
|
-
return;
|
|
1578
|
-
}
|
|
1579
|
-
this.#log(types.LogLevelLabel.TRACE, `Synchronously removing file: ${this.#normalizePath(path)}`);
|
|
1580
|
-
this.#unifiedFS.resolveFS(path, options).unlinkSync(this.#normalizePath(path));
|
|
1581
|
-
if (this.#ids[this.#normalizePath(path)] && this.#metadata[this.#ids[this.#normalizePath(path)]]) {
|
|
1582
|
-
delete this.#metadata[this.#ids[this.#normalizePath(path)]];
|
|
1583
|
-
delete this.#ids[this.#normalizePath(path)];
|
|
1584
|
-
delete this.#paths[this.#normalizeId(path)];
|
|
1585
|
-
this.#resolverCache.delete(this.#normalizePath(path));
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
/**
|
|
1589
|
-
* Removes a file in the virtual file system (VFS).
|
|
1590
|
-
*
|
|
1591
|
-
* @param path - The path to create the directory at.
|
|
1757
|
+
* @param path - The path to the file.
|
|
1758
|
+
* @returns A promise that resolves to `true` if the file exists, otherwise `false`.
|
|
1592
1759
|
*/
|
|
1593
|
-
async
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
}
|
|
1597
|
-
this.#log(types.LogLevelLabel.TRACE, `Removing file: ${this.#normalizePath(path)}`);
|
|
1598
|
-
if (isFunction.isFunction(this.#unifiedFS.resolveFS(path, options).promises.unlink)) {
|
|
1599
|
-
await this.#unifiedFS.resolveFS(path, options).promises.unlink(this.#normalizePath(path));
|
|
1600
|
-
if (this.#ids[this.#normalizePath(path)] && this.#metadata[this.#ids[this.#normalizePath(path)]]) {
|
|
1601
|
-
delete this.#metadata[this.#ids[this.#normalizePath(path)]];
|
|
1602
|
-
}
|
|
1603
|
-
} else {
|
|
1604
|
-
this.unlinkSync(this.#normalizePath(path), options);
|
|
1605
|
-
}
|
|
1760
|
+
async exists(path) {
|
|
1761
|
+
const { relativeKey, adapter } = this.#getStorage(path);
|
|
1762
|
+
return adapter.exists(relativeKey);
|
|
1606
1763
|
}
|
|
1607
1764
|
/**
|
|
1608
|
-
*
|
|
1765
|
+
* Synchronously checks if a file exists in the virtual file system (VFS).
|
|
1609
1766
|
*
|
|
1610
|
-
* @param path - The path to
|
|
1611
|
-
* @
|
|
1767
|
+
* @param path - The path to the file.
|
|
1768
|
+
* @returns `true` if the file exists, otherwise `false`.
|
|
1612
1769
|
*/
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
}
|
|
1617
|
-
this.#log(types.LogLevelLabel.TRACE, `Synchronously removing directory: ${this.#normalizePath(path)}`);
|
|
1618
|
-
this.#unifiedFS.resolveFS(path, options).rmdirSync(this.#normalizePath(path), defu5__default.default(options, {
|
|
1619
|
-
recursive: true
|
|
1620
|
-
}));
|
|
1770
|
+
existsSync(path) {
|
|
1771
|
+
const { relativeKey, adapter } = this.#getStorage(path);
|
|
1772
|
+
return adapter.existsSync(relativeKey);
|
|
1621
1773
|
}
|
|
1622
1774
|
/**
|
|
1623
|
-
*
|
|
1775
|
+
* Checks if a file is virtual in the virtual file system (VFS).
|
|
1624
1776
|
*
|
|
1625
|
-
* @param path - The path to
|
|
1626
|
-
* @
|
|
1627
|
-
* @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`.
|
|
1628
1779
|
*/
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
this.#log(types.LogLevelLabel.TRACE, `Removing directory: ${this.#normalizePath(path)}`);
|
|
1634
|
-
if (isFunction.isFunction(this.#unifiedFS.resolveFS(path, options).promises.rm)) {
|
|
1635
|
-
await this.#unifiedFS.resolveFS(path, options).promises.rm(this.#normalizePath(path), defu5__default.default(options, {
|
|
1636
|
-
force: true,
|
|
1637
|
-
recursive: true
|
|
1638
|
-
}));
|
|
1639
|
-
} else {
|
|
1640
|
-
this.rmdirSync(this.#normalizePath(path), defu5__default.default(options ?? {}, {
|
|
1641
|
-
force: true,
|
|
1642
|
-
recursive: true
|
|
1643
|
-
}));
|
|
1780
|
+
isVirtual(path) {
|
|
1781
|
+
const resolved = this.resolveSync(path);
|
|
1782
|
+
if (!resolved) {
|
|
1783
|
+
return false;
|
|
1644
1784
|
}
|
|
1785
|
+
return this.#getStorage(resolved)?.adapter?.name === "virtual";
|
|
1645
1786
|
}
|
|
1646
1787
|
/**
|
|
1647
|
-
*
|
|
1788
|
+
* Lists files in a given path.
|
|
1648
1789
|
*
|
|
1649
|
-
* @param path - The path to
|
|
1650
|
-
* @
|
|
1651
|
-
* @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.
|
|
1652
1792
|
*/
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
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
|
+
];
|
|
1657
1806
|
}
|
|
1658
|
-
return
|
|
1807
|
+
return allKeys.filter((key) => filterKeyByBase(key, path));
|
|
1659
1808
|
}
|
|
1660
1809
|
/**
|
|
1661
|
-
*
|
|
1810
|
+
* Lists files in a given path.
|
|
1662
1811
|
*
|
|
1663
|
-
* @param path - The path to
|
|
1664
|
-
* @
|
|
1812
|
+
* @param path - The path to list files from.
|
|
1813
|
+
* @returns An array of file names in the specified path.
|
|
1665
1814
|
*/
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
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
|
+
];
|
|
1670
1828
|
}
|
|
1671
|
-
return
|
|
1829
|
+
return allKeys.filter((key) => filterKeyByBase(key, path));
|
|
1672
1830
|
}
|
|
1673
1831
|
/**
|
|
1674
|
-
*
|
|
1832
|
+
* Removes a file in the virtual file system (VFS).
|
|
1675
1833
|
*
|
|
1676
1834
|
* @param path - The path to create the directory at.
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
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
|
+
}
|
|
1686
1851
|
}
|
|
1687
1852
|
/**
|
|
1688
|
-
*
|
|
1853
|
+
* Removes a file in the virtual file system (VFS).
|
|
1689
1854
|
*
|
|
1690
1855
|
* @param path - The path to create the directory at.
|
|
1691
|
-
* @param options - Options for creating the directory.
|
|
1692
|
-
* @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
|
|
1693
1856
|
*/
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
recursive: true
|
|
1701
|
-
}));
|
|
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);
|
|
1702
1863
|
} else {
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
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];
|
|
1708
1871
|
}
|
|
1709
|
-
return result;
|
|
1710
1872
|
}
|
|
1711
1873
|
/**
|
|
1712
1874
|
* Glob files in the virtual file system (VFS) based on the provided pattern(s).
|
|
@@ -1728,38 +1890,14 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1728
1890
|
const absPattern = isType.isAbsolutePath(normalized) ? normalized : this.#normalizePath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, normalized));
|
|
1729
1891
|
const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
|
|
1730
1892
|
const baseDir = firstGlobIdx === -1 ? filePathFns.findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
let entries = [];
|
|
1737
|
-
try {
|
|
1738
|
-
entries = await this.readdir(dir);
|
|
1739
|
-
} catch {
|
|
1740
|
-
continue;
|
|
1741
|
-
}
|
|
1742
|
-
for (const entry of entries) {
|
|
1743
|
-
const full = this.#normalizePath(joinPaths.joinPaths(dir, entry));
|
|
1744
|
-
let stats;
|
|
1745
|
-
try {
|
|
1746
|
-
stats = this.#unifiedFS.lstatSync(full);
|
|
1747
|
-
} catch {
|
|
1748
|
-
stats = void 0;
|
|
1749
|
-
}
|
|
1750
|
-
if (!stats) continue;
|
|
1751
|
-
if (stats.isDirectory()) {
|
|
1752
|
-
stack.push(full);
|
|
1753
|
-
} else if (stats.isFile()) {
|
|
1754
|
-
if (this.#buildRegex(absPattern).test(full)) {
|
|
1755
|
-
const resolved = this.resolveSync(full);
|
|
1756
|
-
if (resolved && !results.includes(resolved)) {
|
|
1757
|
-
results.push(resolved);
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
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);
|
|
1760
1898
|
}
|
|
1761
1899
|
}
|
|
1762
|
-
}
|
|
1900
|
+
}));
|
|
1763
1901
|
}
|
|
1764
1902
|
return results;
|
|
1765
1903
|
}
|
|
@@ -1783,35 +1921,12 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1783
1921
|
const absPattern = isType.isAbsolutePath(normalized) ? normalized : this.#normalizePath(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, normalized));
|
|
1784
1922
|
const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
|
|
1785
1923
|
const baseDir = firstGlobIdx === -1 ? filePathFns.findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
|
|
1786
|
-
const
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
try {
|
|
1793
|
-
entries = this.readdirSync(dir);
|
|
1794
|
-
} catch {
|
|
1795
|
-
continue;
|
|
1796
|
-
}
|
|
1797
|
-
for (const entry of entries) {
|
|
1798
|
-
const full = this.#normalizePath(joinPaths.joinPaths(dir, entry));
|
|
1799
|
-
let stats;
|
|
1800
|
-
try {
|
|
1801
|
-
stats = this.#unifiedFS.lstatSync(full);
|
|
1802
|
-
} catch {
|
|
1803
|
-
stats = void 0;
|
|
1804
|
-
}
|
|
1805
|
-
if (!stats) continue;
|
|
1806
|
-
if (stats.isDirectory()) {
|
|
1807
|
-
stack.push(full);
|
|
1808
|
-
} else if (stats.isFile()) {
|
|
1809
|
-
if (this.#buildRegex(absPattern).test(full)) {
|
|
1810
|
-
const resolved = this.resolveSync(full);
|
|
1811
|
-
if (resolved && !results.includes(resolved)) {
|
|
1812
|
-
results.push(resolved);
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
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);
|
|
1815
1930
|
}
|
|
1816
1931
|
}
|
|
1817
1932
|
}
|
|
@@ -1819,36 +1934,27 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1819
1934
|
return results;
|
|
1820
1935
|
}
|
|
1821
1936
|
/**
|
|
1822
|
-
* Moves a file from one path to another in the virtual file system (VFS).
|
|
1823
|
-
*
|
|
1824
|
-
* @param srcPath - The source path to move
|
|
1825
|
-
* @param destPath - The destination path to move to
|
|
1826
|
-
*/
|
|
1827
|
-
async move(srcPath, destPath) {
|
|
1828
|
-
const content = await this.readFile(srcPath);
|
|
1829
|
-
await this.writeFile(destPath, content);
|
|
1830
|
-
await this.rm(srcPath);
|
|
1831
|
-
}
|
|
1832
|
-
/**
|
|
1833
|
-
* Synchronously moves a file from one path to another in the virtual file system (VFS).
|
|
1834
|
-
*
|
|
1835
|
-
* @param srcPath - The source path to move
|
|
1836
|
-
* @param destPath - The destination path to move to
|
|
1837
|
-
*/
|
|
1838
|
-
moveSync(srcPath, destPath) {
|
|
1839
|
-
const content = this.readFileSync(srcPath);
|
|
1840
|
-
this.writeFileSync(destPath, content);
|
|
1841
|
-
this.rmSync(srcPath);
|
|
1842
|
-
}
|
|
1843
|
-
/**
|
|
1844
1937
|
* Copies a file from one path to another in the virtual file system (VFS).
|
|
1845
1938
|
*
|
|
1846
1939
|
* @param srcPath - The source path to copy
|
|
1847
1940
|
* @param destPath - The destination path to copy to
|
|
1848
1941
|
*/
|
|
1849
1942
|
async copy(srcPath, destPath) {
|
|
1850
|
-
|
|
1851
|
-
|
|
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
|
+
}
|
|
1852
1958
|
}
|
|
1853
1959
|
/**
|
|
1854
1960
|
* Synchronously copies a file from one path to another in the virtual file system (VFS).
|
|
@@ -1857,51 +1963,85 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1857
1963
|
* @param destPath - The destination path to copy to
|
|
1858
1964
|
*/
|
|
1859
1965
|
copySync(srcPath, destPath) {
|
|
1860
|
-
|
|
1861
|
-
|
|
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
|
+
}
|
|
1862
1981
|
}
|
|
1863
1982
|
/**
|
|
1864
|
-
*
|
|
1983
|
+
* Moves a file (or files) from one path to another in the virtual file system (VFS).
|
|
1865
1984
|
*
|
|
1866
|
-
* @param
|
|
1867
|
-
* @param
|
|
1868
|
-
|
|
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
|
|
1869
2004
|
*/
|
|
1870
|
-
|
|
1871
|
-
|
|
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
|
+
}
|
|
1872
2015
|
}
|
|
1873
2016
|
/**
|
|
1874
2017
|
* Asynchronously reads a file from the virtual file system (VFS).
|
|
1875
2018
|
*
|
|
1876
|
-
* @param
|
|
2019
|
+
* @param path - The path or ID of the file to read.
|
|
1877
2020
|
* @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
|
|
1878
2021
|
*/
|
|
1879
|
-
async
|
|
1880
|
-
const filePath = await this.resolve(
|
|
1881
|
-
if (filePath
|
|
1882
|
-
|
|
1883
|
-
if (isFunction.isFunction(this.#unifiedFS.resolveFS(filePath).promises.readFile)) {
|
|
1884
|
-
result = (await this.#unifiedFS.resolveFS(filePath).promises.readFile(filePath, options))?.toString("utf8");
|
|
1885
|
-
} else {
|
|
1886
|
-
result = this.#unifiedFS.resolveFS(filePath).readFileSync(filePath, options);
|
|
1887
|
-
}
|
|
1888
|
-
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;
|
|
1889
2026
|
}
|
|
1890
|
-
|
|
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;
|
|
1891
2030
|
}
|
|
1892
2031
|
/**
|
|
1893
2032
|
* Synchronously reads a file from the virtual file system (VFS).
|
|
1894
2033
|
*
|
|
1895
|
-
* @param
|
|
2034
|
+
* @param path - The path or ID of the file to read.
|
|
1896
2035
|
* @returns The contents of the file as a string, or undefined if the file does not exist.
|
|
1897
2036
|
*/
|
|
1898
|
-
|
|
1899
|
-
const filePath = this.resolveSync(
|
|
1900
|
-
if (filePath
|
|
1901
|
-
|
|
1902
|
-
return isBuffer.isBuffer(result) ? bufferToString.bufferToString(result) : result;
|
|
2037
|
+
readSync(path) {
|
|
2038
|
+
const filePath = this.resolveSync(path);
|
|
2039
|
+
if (!filePath) {
|
|
2040
|
+
return void 0;
|
|
1903
2041
|
}
|
|
1904
|
-
|
|
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;
|
|
1905
2045
|
}
|
|
1906
2046
|
/**
|
|
1907
2047
|
* Writes a file to the virtual file system (VFS).
|
|
@@ -1911,41 +2051,28 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1911
2051
|
* @param options - Optional parameters for writing the file.
|
|
1912
2052
|
* @returns A promise that resolves when the file is written.
|
|
1913
2053
|
*/
|
|
1914
|
-
async
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
}
|
|
1918
|
-
const metadata = isVirtualFileData(data) ? data : {};
|
|
1919
|
-
metadata.id = this.#normalizeId(path);
|
|
1920
|
-
let code = isVirtualFileData(data) ? metadata.code : data;
|
|
1921
|
-
if ((!isPowerlinesWriteFileOptions(options) || !options.skipFormat) && isSetString.isSetString(code)) {
|
|
2054
|
+
async write(path, data = "", options = {}) {
|
|
2055
|
+
let code = data;
|
|
2056
|
+
if (!options.skipFormat) {
|
|
1922
2057
|
const resolvedConfig = await prettier.resolveConfig(this.#normalizePath(path));
|
|
1923
2058
|
if (resolvedConfig) {
|
|
1924
|
-
code = await prettier.format(
|
|
2059
|
+
code = await prettier.format(data, {
|
|
1925
2060
|
absolutePath: this.#normalizePath(path),
|
|
1926
2061
|
...resolvedConfig
|
|
1927
2062
|
});
|
|
1928
2063
|
}
|
|
1929
2064
|
}
|
|
1930
|
-
const
|
|
1931
|
-
this.#log(types.LogLevelLabel.TRACE, `Writing ${this.#normalizePath(path)}
|
|
1932
|
-
|
|
1933
|
-
|
|
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] = {
|
|
1934
2069
|
variant: "normal",
|
|
1935
2070
|
timestamp: Date.now(),
|
|
1936
|
-
...
|
|
2071
|
+
...options.meta ?? {}
|
|
1937
2072
|
};
|
|
1938
|
-
this.#paths[
|
|
1939
|
-
this.#ids[this.#normalizePath(path)] =
|
|
1940
|
-
|
|
1941
|
-
if (isFunction.isFunction(ifs.promises.writeFile)) {
|
|
1942
|
-
return ifs.promises.writeFile(this.#normalizePath(path), code, isSetObject.isSetObject(options) ? omit.omit(options, [
|
|
1943
|
-
"mode"
|
|
1944
|
-
]) : "utf8");
|
|
1945
|
-
}
|
|
1946
|
-
return ifs.writeFileSync(this.#normalizePath(path), code, isSetObject.isSetObject(options) ? omit.omit(options, [
|
|
1947
|
-
"mode"
|
|
1948
|
-
]) : "utf8");
|
|
2073
|
+
this.#paths[id] = this.#normalizePath(path);
|
|
2074
|
+
this.#ids[this.#normalizePath(path)] = id;
|
|
2075
|
+
return adapter.set(relativeKey, code);
|
|
1949
2076
|
}
|
|
1950
2077
|
/**
|
|
1951
2078
|
* Synchronously writes a file to the virtual file system (VFS).
|
|
@@ -1954,38 +2081,18 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1954
2081
|
* @param data - The contents of the file.
|
|
1955
2082
|
* @param options - Optional parameters for writing the file.
|
|
1956
2083
|
*/
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
metadata.id = this.#normalizeId(path);
|
|
1963
|
-
const code = isVirtualFileData(data) ? metadata.code : data;
|
|
1964
|
-
const outputMode = this.#unifiedFS.resolveMode(this.#normalizePath(path), isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1965
|
-
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)})`);
|
|
1966
|
-
this.#metadata[metadata.id] = {
|
|
1967
|
-
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] = {
|
|
1968
2089
|
variant: "normal",
|
|
1969
2090
|
timestamp: Date.now(),
|
|
1970
|
-
...
|
|
2091
|
+
...options.meta ?? {}
|
|
1971
2092
|
};
|
|
1972
|
-
this.#paths[
|
|
1973
|
-
this.#ids[this.#normalizePath(path)] =
|
|
1974
|
-
|
|
1975
|
-
try {
|
|
1976
|
-
writeStream.write(code);
|
|
1977
|
-
} finally {
|
|
1978
|
-
writeStream.close();
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
/**
|
|
1982
|
-
* Synchronously checks if a file exists in the virtual file system (VFS).
|
|
1983
|
-
*
|
|
1984
|
-
* @param pathOrId - The path or ID of the file to check.
|
|
1985
|
-
* @returns `true` if the file exists, otherwise `false`.
|
|
1986
|
-
*/
|
|
1987
|
-
existsSync(pathOrId) {
|
|
1988
|
-
return !!this.resolveSync(pathOrId);
|
|
2093
|
+
this.#paths[id] = this.#normalizePath(path);
|
|
2094
|
+
this.#ids[this.#normalizePath(path)] = id;
|
|
2095
|
+
return adapter.setSync(relativeKey, data);
|
|
1989
2096
|
}
|
|
1990
2097
|
/**
|
|
1991
2098
|
* Retrieves the metadata of a file in the virtual file system (VFS).
|
|
@@ -2001,78 +2108,6 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2001
2108
|
return void 0;
|
|
2002
2109
|
}
|
|
2003
2110
|
/**
|
|
2004
|
-
* Checks if a file exists in the virtual file system (VFS).
|
|
2005
|
-
*
|
|
2006
|
-
* @remarks
|
|
2007
|
-
* 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.
|
|
2008
|
-
*
|
|
2009
|
-
* @param pathOrId - The path of the file to check.
|
|
2010
|
-
* @returns `true` if the file exists, otherwise `false`.
|
|
2011
|
-
*/
|
|
2012
|
-
isFile(pathOrId) {
|
|
2013
|
-
const resolved = this.resolveSync(pathOrId);
|
|
2014
|
-
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()));
|
|
2015
|
-
}
|
|
2016
|
-
/**
|
|
2017
|
-
* Checks if a directory exists in the virtual file system (VFS).
|
|
2018
|
-
*
|
|
2019
|
-
* @param pathOrId - The path of the directory to check.
|
|
2020
|
-
* @returns `true` if the directory exists, otherwise `false`.
|
|
2021
|
-
*/
|
|
2022
|
-
isDirectory(pathOrId) {
|
|
2023
|
-
const resolved = this.resolveSync(pathOrId);
|
|
2024
|
-
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()));
|
|
2025
|
-
}
|
|
2026
|
-
/**
|
|
2027
|
-
* Retrieves the status of a file in the virtual file system (VFS).
|
|
2028
|
-
*
|
|
2029
|
-
* @param pathOrId - The path or ID of the file to retrieve status for.
|
|
2030
|
-
* @returns A promise that resolves to the file's status information, or false if the file does not exist.
|
|
2031
|
-
*/
|
|
2032
|
-
async stat(pathOrId, options) {
|
|
2033
|
-
return this.#unifiedFS.resolveFS(pathOrId).promises.stat(await this.resolve(pathOrId) || pathOrId, options);
|
|
2034
|
-
}
|
|
2035
|
-
/**
|
|
2036
|
-
* Synchronously retrieves the status of a file in the virtual file system (VFS).
|
|
2037
|
-
*
|
|
2038
|
-
* @param pathOrId - The path or ID of the file to retrieve status for.
|
|
2039
|
-
* @returns The file's status information, or false if the file does not exist.
|
|
2040
|
-
*/
|
|
2041
|
-
statSync(pathOrId) {
|
|
2042
|
-
return this.#unifiedFS.resolveFS(pathOrId).statSync(this.resolveSync(pathOrId) || pathOrId);
|
|
2043
|
-
}
|
|
2044
|
-
/**
|
|
2045
|
-
* Retrieves the status of a symbolic link in the virtual file system (VFS).
|
|
2046
|
-
*
|
|
2047
|
-
* @param pathOrId - The path or ID of the symbolic link to retrieve status for.
|
|
2048
|
-
* @returns A promise that resolves to the symbolic link's status information, or false if the link does not exist.
|
|
2049
|
-
*/
|
|
2050
|
-
async lstat(pathOrId, options) {
|
|
2051
|
-
return this.#unifiedFS.resolveFS(pathOrId).promises.lstat(await this.resolve(pathOrId) || pathOrId, options);
|
|
2052
|
-
}
|
|
2053
|
-
/**
|
|
2054
|
-
* Synchronously retrieves the status of a symbolic link in the virtual file system (VFS).
|
|
2055
|
-
*
|
|
2056
|
-
* @param pathOrId - The path or ID of the symbolic link to retrieve status for.
|
|
2057
|
-
* @returns The symbolic link's status information, or false if the link does not exist.
|
|
2058
|
-
*/
|
|
2059
|
-
lstatSync(pathOrId, options) {
|
|
2060
|
-
return this.#unifiedFS.resolveFS(pathOrId).lstatSync(this.resolveSync(pathOrId) || pathOrId, options);
|
|
2061
|
-
}
|
|
2062
|
-
/**
|
|
2063
|
-
* Resolves a path or ID to its real path in the virtual file system (VFS).
|
|
2064
|
-
*
|
|
2065
|
-
* @param pathOrId - The path or ID to resolve.
|
|
2066
|
-
* @returns The resolved real path if it exists, otherwise undefined.
|
|
2067
|
-
*/
|
|
2068
|
-
realpathSync(pathOrId) {
|
|
2069
|
-
const filePath = this.resolveSync(pathOrId);
|
|
2070
|
-
if (!filePath) {
|
|
2071
|
-
throw new Error(`File not found: ${pathOrId}`);
|
|
2072
|
-
}
|
|
2073
|
-
return filePath;
|
|
2074
|
-
}
|
|
2075
|
-
/**
|
|
2076
2111
|
* A helper function to resolve modules in the virtual file system (VFS).
|
|
2077
2112
|
*
|
|
2078
2113
|
* @remarks
|
|
@@ -2089,9 +2124,15 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2089
2124
|
* @returns A promise that resolves to the resolved module path.
|
|
2090
2125
|
*/
|
|
2091
2126
|
async resolve(id, importer, options = {}) {
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
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
|
+
}
|
|
2095
2136
|
}
|
|
2096
2137
|
result = this.paths[this.#normalizeId(id)];
|
|
2097
2138
|
if (!result) {
|
|
@@ -2106,8 +2147,10 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2106
2147
|
for (const combination of resolve.getResolutionCombinations(id, {
|
|
2107
2148
|
paths
|
|
2108
2149
|
})) {
|
|
2109
|
-
|
|
2150
|
+
const { relativeKey, adapter } = this.#getStorage(combination);
|
|
2151
|
+
if (await adapter.exists(relativeKey)) {
|
|
2110
2152
|
result = combination;
|
|
2153
|
+
break;
|
|
2111
2154
|
}
|
|
2112
2155
|
}
|
|
2113
2156
|
try {
|
|
@@ -2119,7 +2162,9 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2119
2162
|
}
|
|
2120
2163
|
if (result) {
|
|
2121
2164
|
result = correctPath.toAbsolutePath(append.appendPath(result, this.#context.config.projectRoot), this.#context.workspaceConfig.workspaceRoot);
|
|
2122
|
-
this.
|
|
2165
|
+
if (!this.#context.config.skipCache) {
|
|
2166
|
+
this.resolverCache.set(this.#normalizeId(id), result);
|
|
2167
|
+
}
|
|
2123
2168
|
}
|
|
2124
2169
|
return result;
|
|
2125
2170
|
}
|
|
@@ -2140,9 +2185,15 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2140
2185
|
* @returns The resolved module path.
|
|
2141
2186
|
*/
|
|
2142
2187
|
resolveSync(id, importer, options = {}) {
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
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
|
+
}
|
|
2146
2197
|
}
|
|
2147
2198
|
result = this.paths[this.#normalizeId(id)];
|
|
2148
2199
|
if (!result) {
|
|
@@ -2151,14 +2202,16 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2151
2202
|
paths.push(importer);
|
|
2152
2203
|
}
|
|
2153
2204
|
paths.push(this.#context.workspaceConfig.workspaceRoot);
|
|
2154
|
-
paths.push(
|
|
2155
|
-
paths.push(
|
|
2156
|
-
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)));
|
|
2157
2208
|
for (const combination of resolve.getResolutionCombinations(id, {
|
|
2158
2209
|
paths
|
|
2159
2210
|
})) {
|
|
2160
|
-
|
|
2211
|
+
const { relativeKey, adapter } = this.#getStorage(combination);
|
|
2212
|
+
if (adapter.existsSync(relativeKey)) {
|
|
2161
2213
|
result = combination;
|
|
2214
|
+
break;
|
|
2162
2215
|
}
|
|
2163
2216
|
}
|
|
2164
2217
|
try {
|
|
@@ -2170,7 +2223,9 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2170
2223
|
}
|
|
2171
2224
|
if (result) {
|
|
2172
2225
|
result = correctPath.toAbsolutePath(append.appendPath(result, this.#context.config.projectRoot), this.#context.workspaceConfig.workspaceRoot);
|
|
2173
|
-
this.
|
|
2226
|
+
if (!this.#context.config.skipCache) {
|
|
2227
|
+
this.resolverCache.set(this.#normalizeId(id), result);
|
|
2228
|
+
}
|
|
2174
2229
|
}
|
|
2175
2230
|
return result;
|
|
2176
2231
|
}
|
|
@@ -2181,27 +2236,27 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2181
2236
|
if (!this.#isDisposed) {
|
|
2182
2237
|
this.#isDisposed = true;
|
|
2183
2238
|
this.#log(types.LogLevelLabel.DEBUG, "Disposing virtual file system...");
|
|
2184
|
-
await this.
|
|
2239
|
+
await this.remove(joinPaths.joinPaths(this.#context.dataPath, "fs.bin"));
|
|
2185
2240
|
const message = new $__namespace.Message();
|
|
2186
|
-
const
|
|
2187
|
-
const
|
|
2188
|
-
const
|
|
2189
|
-
|
|
2190
|
-
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);
|
|
2191
2247
|
fd.path = path;
|
|
2192
2248
|
fd.code = code || "";
|
|
2193
|
-
});
|
|
2194
|
-
const ids =
|
|
2249
|
+
}));
|
|
2250
|
+
const ids = fs._initIds(Object.keys(this.ids).length);
|
|
2195
2251
|
Object.entries(this.ids).filter(([, path]) => path).forEach(([id, path], index) => {
|
|
2196
2252
|
const fileId = ids.get(index);
|
|
2197
2253
|
fileId.id = id;
|
|
2198
2254
|
fileId.path = path;
|
|
2199
2255
|
});
|
|
2200
|
-
const metadata =
|
|
2256
|
+
const metadata = fs._initMetadata(Object.keys(this.metadata).length);
|
|
2201
2257
|
Object.entries(this.metadata).filter(([, value]) => value).forEach(([id, value], index) => {
|
|
2202
2258
|
const fileMetadata = metadata.get(index);
|
|
2203
2259
|
fileMetadata.id = id;
|
|
2204
|
-
fileMetadata.mode = value.mode;
|
|
2205
2260
|
fileMetadata.type = value.type;
|
|
2206
2261
|
fileMetadata.timestamp = value.timestamp ?? BigInt(Date.now());
|
|
2207
2262
|
if (value.properties) {
|
|
@@ -2214,134 +2269,40 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
2214
2269
|
}
|
|
2215
2270
|
});
|
|
2216
2271
|
await buffer.writeFileBuffer(joinPaths.joinPaths(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
|
|
2217
|
-
this.#
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
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
|
+
// }
|
|
2242
2302
|
async [Symbol.asyncDispose]() {
|
|
2243
2303
|
return this.dispose();
|
|
2244
2304
|
}
|
|
2245
2305
|
};
|
|
2246
|
-
var VirtualFileSystemHost = class VirtualFileSystemHost2 extends tsMorph.InMemoryFileSystemHost {
|
|
2247
|
-
static {
|
|
2248
|
-
chunkSHUYVCID_js.__name(this, "VirtualFileSystemHost");
|
|
2249
|
-
}
|
|
2250
|
-
#fs;
|
|
2251
|
-
constructor(fs2) {
|
|
2252
|
-
super();
|
|
2253
|
-
this.#fs = fs2;
|
|
2254
|
-
}
|
|
2255
|
-
deleteSync(path) {
|
|
2256
|
-
this.#fs.rmSync(path);
|
|
2257
|
-
}
|
|
2258
|
-
readDirSync(dirPath) {
|
|
2259
|
-
return this.#fs.readdirSync(dirPath).reduce((ret, entry) => {
|
|
2260
|
-
const fullPath = this.#fs.resolveSync(join.joinPaths(dirPath, entry));
|
|
2261
|
-
if (fullPath) {
|
|
2262
|
-
ret.push({
|
|
2263
|
-
name: entry,
|
|
2264
|
-
isDirectory: this.#fs.isDirectory(fullPath),
|
|
2265
|
-
isFile: this.#fs.isFile(fullPath),
|
|
2266
|
-
isSymlink: false
|
|
2267
|
-
});
|
|
2268
|
-
}
|
|
2269
|
-
return ret;
|
|
2270
|
-
}, []);
|
|
2271
|
-
}
|
|
2272
|
-
async readFile(filePath) {
|
|
2273
|
-
if (!this.#fs.existsSync(filePath)) {
|
|
2274
|
-
throw new Error(`File not found: '${filePath}'. Please check the path and try again.`);
|
|
2275
|
-
}
|
|
2276
|
-
return await this.#fs.readFile(filePath);
|
|
2277
|
-
}
|
|
2278
|
-
readFileSync(filePath) {
|
|
2279
|
-
if (!this.#fs.existsSync(filePath)) {
|
|
2280
|
-
throw new Error(`File not found: '${filePath}'. Please check the path and try again.`);
|
|
2281
|
-
}
|
|
2282
|
-
return this.#fs.readFileSync(filePath);
|
|
2283
|
-
}
|
|
2284
|
-
async writeFile(filePath, fileText) {
|
|
2285
|
-
return this.#fs.writeFile(filePath, fileText);
|
|
2286
|
-
}
|
|
2287
|
-
writeFileSync(filePath, fileText) {
|
|
2288
|
-
this.#fs.writeFileSync(filePath, fileText);
|
|
2289
|
-
}
|
|
2290
|
-
async mkdir(dirPath) {
|
|
2291
|
-
await this.#fs.mkdir(dirPath);
|
|
2292
|
-
}
|
|
2293
|
-
mkdirSync(dirPath) {
|
|
2294
|
-
this.#fs.mkdirSync(dirPath);
|
|
2295
|
-
}
|
|
2296
|
-
async move(srcPath, destPath) {
|
|
2297
|
-
await this.#fs.move(srcPath, destPath);
|
|
2298
|
-
}
|
|
2299
|
-
moveSync(srcPath, destPath) {
|
|
2300
|
-
this.#fs.moveSync(srcPath, destPath);
|
|
2301
|
-
}
|
|
2302
|
-
async copy(srcPath, destPath) {
|
|
2303
|
-
await this.#fs.copy(srcPath, destPath);
|
|
2304
|
-
}
|
|
2305
|
-
copySync(srcPath, destPath) {
|
|
2306
|
-
this.#fs.copySync(srcPath, destPath);
|
|
2307
|
-
}
|
|
2308
|
-
async fileExists(filePath) {
|
|
2309
|
-
return this.#fs.isFile(filePath);
|
|
2310
|
-
}
|
|
2311
|
-
fileExistsSync(filePath) {
|
|
2312
|
-
return this.#fs.isFile(filePath);
|
|
2313
|
-
}
|
|
2314
|
-
async directoryExists(dirPath) {
|
|
2315
|
-
return this.#fs.isDirectory(dirPath);
|
|
2316
|
-
}
|
|
2317
|
-
directoryExistsSync(dirPath) {
|
|
2318
|
-
return this.#fs.isDirectory(dirPath);
|
|
2319
|
-
}
|
|
2320
|
-
realpathSync(path) {
|
|
2321
|
-
return this.#fs.resolveSync(path) || path;
|
|
2322
|
-
}
|
|
2323
|
-
getCurrentDirectory() {
|
|
2324
|
-
return "/";
|
|
2325
|
-
}
|
|
2326
|
-
async glob(patterns) {
|
|
2327
|
-
return this.#fs.glob(patterns);
|
|
2328
|
-
}
|
|
2329
|
-
globSync(patterns) {
|
|
2330
|
-
return this.#fs.globSync(patterns);
|
|
2331
|
-
}
|
|
2332
|
-
};
|
|
2333
|
-
function createProgram(context, override) {
|
|
2334
|
-
const project = new tsMorph.Project({
|
|
2335
|
-
compilerOptions: {
|
|
2336
|
-
...context.tsconfig.options
|
|
2337
|
-
},
|
|
2338
|
-
tsConfigFilePath: context.tsconfig.tsconfigFilePath,
|
|
2339
|
-
fileSystem: new VirtualFileSystemHost(context.fs),
|
|
2340
|
-
...override
|
|
2341
|
-
});
|
|
2342
|
-
return project;
|
|
2343
|
-
}
|
|
2344
|
-
chunkSHUYVCID_js.__name(createProgram, "createProgram");
|
|
2345
2306
|
|
|
2346
2307
|
// ../powerlines/src/lib/contexts/context.ts
|
|
2347
2308
|
var configCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -2399,7 +2360,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2399
2360
|
* @returns A promise that resolves to the new context.
|
|
2400
2361
|
*/
|
|
2401
2362
|
static async from(workspaceRoot, config) {
|
|
2402
|
-
const context = new _PowerlinesContext(await
|
|
2363
|
+
const context = new _PowerlinesContext(await chunkDQI2I5KK_js.loadWorkspaceConfig(workspaceRoot, config.root));
|
|
2403
2364
|
await context.withUserConfig(config);
|
|
2404
2365
|
context.powerlinesPath = await resolve.resolvePackage("powerlines");
|
|
2405
2366
|
if (!context.powerlinesPath) {
|
|
@@ -2497,10 +2458,10 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2497
2458
|
workspaceRoot: this.workspaceConfig?.workspaceRoot,
|
|
2498
2459
|
projectRoot: this.config?.projectRoot
|
|
2499
2460
|
}, {
|
|
2500
|
-
maxLength:
|
|
2461
|
+
maxLength: chunkDQI2I5KK_js.PROJECT_ROOT_HASH_LENGTH
|
|
2501
2462
|
}),
|
|
2502
2463
|
configHash: murmurhash.murmurhash(this.config, {
|
|
2503
|
-
maxLength:
|
|
2464
|
+
maxLength: chunkDQI2I5KK_js.CACHE_HASH_LENGTH
|
|
2504
2465
|
})
|
|
2505
2466
|
};
|
|
2506
2467
|
}
|
|
@@ -2542,7 +2503,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2542
2503
|
* Get the path to the artifacts directory for the project
|
|
2543
2504
|
*/
|
|
2544
2505
|
get artifactsPath() {
|
|
2545
|
-
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);
|
|
2546
2507
|
}
|
|
2547
2508
|
/**
|
|
2548
2509
|
* Get the path to the builtin modules used by the project
|
|
@@ -2560,7 +2521,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2560
2521
|
* Get the path to the data directory for the project
|
|
2561
2522
|
*/
|
|
2562
2523
|
get dataPath() {
|
|
2563
|
-
return join.joinPaths(this.envPaths.data, "projects",
|
|
2524
|
+
return join.joinPaths(this.envPaths.data, "projects", chunkDQI2I5KK_js.getPrefixedProjectRootHash(this.config.name, this.meta.projectRootHash));
|
|
2564
2525
|
}
|
|
2565
2526
|
/**
|
|
2566
2527
|
* Get the path to the cache directory for the project
|
|
@@ -2570,7 +2531,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2570
2531
|
checksum: this.#checksum,
|
|
2571
2532
|
config: this.meta.configHash
|
|
2572
2533
|
}, {
|
|
2573
|
-
maxLength:
|
|
2534
|
+
maxLength: chunkDQI2I5KK_js.CACHE_HASH_LENGTH
|
|
2574
2535
|
}));
|
|
2575
2536
|
}
|
|
2576
2537
|
/**
|
|
@@ -2682,7 +2643,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2682
2643
|
if (!resolvedId) {
|
|
2683
2644
|
return void 0;
|
|
2684
2645
|
}
|
|
2685
|
-
const code = await this.fs.
|
|
2646
|
+
const code = await this.fs.read(resolvedId);
|
|
2686
2647
|
if (!code) {
|
|
2687
2648
|
return void 0;
|
|
2688
2649
|
}
|
|
@@ -2696,7 +2657,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2696
2657
|
*/
|
|
2697
2658
|
async getBuiltins() {
|
|
2698
2659
|
return Promise.all(Object.entries(this.fs.metadata).filter(([, meta]) => meta && meta.type === "builtin").map(async ([path, meta]) => {
|
|
2699
|
-
const code = await this.fs.
|
|
2660
|
+
const code = await this.fs.read(path);
|
|
2700
2661
|
return {
|
|
2701
2662
|
...meta,
|
|
2702
2663
|
path,
|
|
@@ -2712,11 +2673,8 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2712
2673
|
* @param options - Optional write file options
|
|
2713
2674
|
*/
|
|
2714
2675
|
async emitEntry(code, path, options = {}) {
|
|
2715
|
-
return this.fs.
|
|
2716
|
-
code,
|
|
2676
|
+
return this.fs.write(isType.isAbsolute(path) ? path : append.appendPath(path, this.entryPath), code, defu6__default.default(options, {
|
|
2717
2677
|
type: "entry"
|
|
2718
|
-
}, defu5__default.default(options, {
|
|
2719
|
-
mode: this.config.output.mode
|
|
2720
2678
|
}));
|
|
2721
2679
|
}
|
|
2722
2680
|
/**
|
|
@@ -2728,12 +2686,8 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2728
2686
|
* @param options - Optional write file options
|
|
2729
2687
|
*/
|
|
2730
2688
|
async emitBuiltin(code, id, path, options = {}) {
|
|
2731
|
-
return this.fs.
|
|
2732
|
-
id,
|
|
2733
|
-
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, {
|
|
2734
2690
|
type: "builtin"
|
|
2735
|
-
}, defu5__default.default(options, {
|
|
2736
|
-
mode: this.config.output.mode
|
|
2737
2691
|
}));
|
|
2738
2692
|
}
|
|
2739
2693
|
/**
|
|
@@ -2917,7 +2871,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2917
2871
|
logLevel: config.logLevel || this.config?.logLevel || this.workspaceConfig.logLevel || "info",
|
|
2918
2872
|
skipCache: cacheKey.skipCache
|
|
2919
2873
|
});
|
|
2920
|
-
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);
|
|
2921
2875
|
this.mergeUserConfig(userConfig.config);
|
|
2922
2876
|
configCache.set(cacheKey, {
|
|
2923
2877
|
projectJson: this.projectJson,
|
|
@@ -2927,9 +2881,9 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2927
2881
|
userConfig
|
|
2928
2882
|
});
|
|
2929
2883
|
}
|
|
2930
|
-
|
|
2884
|
+
config.tsconfig ??= getTsconfigFilePath(this.workspaceConfig.workspaceRoot, cacheKey.projectRoot, config.tsconfig);
|
|
2931
2885
|
if (isSetObject.isSetObject(config)) {
|
|
2932
|
-
this.resolvedConfig =
|
|
2886
|
+
this.resolvedConfig = defu6__default.default({
|
|
2933
2887
|
inlineConfig: this.config.inlineConfig,
|
|
2934
2888
|
userConfig: this.config.userConfig
|
|
2935
2889
|
}, options.isHighPriority ? this.#getConfigProps(config) : {}, {
|
|
@@ -2944,12 +2898,11 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2944
2898
|
version: this.packageJson?.version,
|
|
2945
2899
|
description: this.packageJson?.description,
|
|
2946
2900
|
sourceRoot: this.projectJson?.sourceRoot || append.appendPath("src", cacheKey.projectRoot),
|
|
2947
|
-
output: {
|
|
2901
|
+
output: defu6__default.default(config.output ?? {}, {
|
|
2948
2902
|
outputPath: cacheKey.projectRoot ? join.joinPaths(this.workspaceConfig?.directories?.build || "dist", cacheKey.projectRoot) : this.workspaceConfig?.directories?.build || "dist",
|
|
2949
|
-
|
|
2903
|
+
artifactsPath: join.joinPaths(cacheKey.projectRoot, `.${config.framework ?? "powerlines"}`),
|
|
2950
2904
|
dts: join.joinPaths(cacheKey.projectRoot, `${config.framework ?? "powerlines"}.d.ts`),
|
|
2951
2905
|
builtinPrefix: config.framework ?? "powerlines",
|
|
2952
|
-
artifactsFolder: join.joinPaths(cacheKey.projectRoot, `.${config.framework ?? "powerlines"}`),
|
|
2953
2906
|
assets: [
|
|
2954
2907
|
{
|
|
2955
2908
|
glob: "LICENSE"
|
|
@@ -2963,7 +2916,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2963
2916
|
glob: "package.json"
|
|
2964
2917
|
}
|
|
2965
2918
|
]
|
|
2966
|
-
}
|
|
2919
|
+
})
|
|
2967
2920
|
}, options.isHighPriority ? {} : this.#getConfigProps(config), {
|
|
2968
2921
|
inlineConfig: {},
|
|
2969
2922
|
userConfig: {},
|
|
@@ -3008,10 +2961,10 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
3008
2961
|
])));
|
|
3009
2962
|
if (this.config.projectRoot && this.config.projectRoot !== "." && this.config.projectRoot !== "./" && this.config.projectRoot !== this.workspaceConfig.workspaceRoot) {
|
|
3010
2963
|
this.config.output.outputPath ??= join.joinPaths("dist", this.config.projectRoot);
|
|
3011
|
-
this.config.output.
|
|
2964
|
+
this.config.output.buildPath ??= join.joinPaths(this.config.projectRoot, "dist");
|
|
3012
2965
|
} else {
|
|
3013
2966
|
this.config.output.outputPath ??= "dist";
|
|
3014
|
-
this.config.output.
|
|
2967
|
+
this.config.output.buildPath ??= "dist";
|
|
3015
2968
|
}
|
|
3016
2969
|
this.config.output.assets = getUnique.getUnique(this.config.output.assets.map((asset) => {
|
|
3017
2970
|
return {
|
|
@@ -3049,7 +3002,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
3049
3002
|
this.#fs ??= await VirtualFileSystem.create(this);
|
|
3050
3003
|
}
|
|
3051
3004
|
mergeUserConfig(from = {}, into = this.config.userConfig ?? {}) {
|
|
3052
|
-
this.config.userConfig =
|
|
3005
|
+
this.config.userConfig = defu6__default.default({
|
|
3053
3006
|
entry: Array.isArray(from.entry) && from.entry.length > 0 ? from.entry : Array.isArray(into?.entry) && into.entry.length > 0 ? into.entry : []
|
|
3054
3007
|
}, omit.omit(from ?? {}, [
|
|
3055
3008
|
"entry"
|
|
@@ -3294,7 +3247,7 @@ var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext
|
|
|
3294
3247
|
* @returns A promise that resolves to the new context.
|
|
3295
3248
|
*/
|
|
3296
3249
|
static async from(workspaceRoot, config) {
|
|
3297
|
-
const context = new _PowerlinesAPIContext(await
|
|
3250
|
+
const context = new _PowerlinesAPIContext(await chunkDQI2I5KK_js.loadWorkspaceConfig(workspaceRoot, config.root));
|
|
3298
3251
|
await context.withUserConfig(config);
|
|
3299
3252
|
context.powerlinesPath = await resolve.resolvePackage("powerlines");
|
|
3300
3253
|
if (!context.powerlinesPath) {
|
|
@@ -3354,12 +3307,49 @@ var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext
|
|
|
3354
3307
|
}
|
|
3355
3308
|
return context;
|
|
3356
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
|
+
*/
|
|
3357
3341
|
async addPlugin(plugin) {
|
|
3358
3342
|
this.plugins.push(plugin);
|
|
3359
3343
|
await Promise.all(Object.keys(this.environments).map(async (name) => {
|
|
3360
3344
|
await this.environments[name].addPlugin(plugin);
|
|
3361
3345
|
}));
|
|
3362
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
|
+
*/
|
|
3363
3353
|
async getEnvironment(name) {
|
|
3364
3354
|
let environment;
|
|
3365
3355
|
if (name) {
|
|
@@ -3478,24 +3468,20 @@ ${context.entry.map((entry) => `- ${entry.input.file || entry.file}${entry.outpu
|
|
|
3478
3468
|
context.log(types.LogLevelLabel.TRACE, `Powerlines configuration has been resolved:
|
|
3479
3469
|
|
|
3480
3470
|
${console.formatLogMessage(context.config)}`);
|
|
3481
|
-
await
|
|
3471
|
+
await chunkDQI2I5KK_js.writeMetaFile(context);
|
|
3482
3472
|
context.persistedMeta = context.meta;
|
|
3483
3473
|
if (!context.fs.existsSync(context.cachePath)) {
|
|
3484
|
-
await
|
|
3485
|
-
mode: "fs"
|
|
3486
|
-
});
|
|
3474
|
+
await helpers.createDirectory(context.cachePath);
|
|
3487
3475
|
}
|
|
3488
3476
|
if (!context.fs.existsSync(context.dataPath)) {
|
|
3489
|
-
await
|
|
3490
|
-
mode: "fs"
|
|
3491
|
-
});
|
|
3477
|
+
await helpers.createDirectory(context.dataPath);
|
|
3492
3478
|
}
|
|
3493
3479
|
await this.callPreHook(context, "prepare");
|
|
3494
3480
|
await this.callNormalHook(context, "prepare");
|
|
3495
3481
|
if (context.config.output.dts !== false) {
|
|
3496
3482
|
context.log(types.LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
|
|
3497
3483
|
if (context.fs.existsSync(context.dtsPath)) {
|
|
3498
|
-
await context.fs.
|
|
3484
|
+
await context.fs.remove(context.dtsPath);
|
|
3499
3485
|
}
|
|
3500
3486
|
context.log(types.LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
|
|
3501
3487
|
const builtinFilePaths = await Promise.all((await context.getBuiltins()).map(async (file) => {
|
|
@@ -3582,7 +3568,7 @@ ${console.formatLogMessage(context.config)}`);
|
|
|
3582
3568
|
generatedTypes = result;
|
|
3583
3569
|
}
|
|
3584
3570
|
}
|
|
3585
|
-
await context.fs.
|
|
3571
|
+
await context.fs.write(context.dtsPath, `${directives ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
|
|
3586
3572
|
|
|
3587
3573
|
` : ""}${getFileHeader(context, {
|
|
3588
3574
|
directive: null,
|
|
@@ -3590,16 +3576,14 @@ ${console.formatLogMessage(context.config)}`);
|
|
|
3590
3576
|
})}
|
|
3591
3577
|
|
|
3592
3578
|
${formatTypes(generatedTypes)}
|
|
3593
|
-
|
|
3594
|
-
mode: "fs"
|
|
3595
|
-
});
|
|
3579
|
+
`);
|
|
3596
3580
|
}
|
|
3597
3581
|
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
3598
3582
|
if (!context.tsconfig) {
|
|
3599
3583
|
throw new Error("Failed to parse the TypeScript configuration file.");
|
|
3600
3584
|
}
|
|
3601
3585
|
await this.callPostHook(context, "prepare");
|
|
3602
|
-
await
|
|
3586
|
+
await chunkDQI2I5KK_js.writeMetaFile(context);
|
|
3603
3587
|
});
|
|
3604
3588
|
this.context.log(types.LogLevelLabel.INFO, "Powerlines API has been prepared successfully");
|
|
3605
3589
|
}
|
|
@@ -3660,8 +3644,8 @@ ${formatTypes(generatedTypes)}
|
|
|
3660
3644
|
await this.prepare(inlineConfig);
|
|
3661
3645
|
await this.#executeEnvironments(async (context) => {
|
|
3662
3646
|
this.context.log(types.LogLevelLabel.TRACE, "Cleaning the project's dist and artifacts directories.");
|
|
3663
|
-
await context.fs.
|
|
3664
|
-
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));
|
|
3665
3649
|
await callHook(context, "clean", {
|
|
3666
3650
|
sequential: true
|
|
3667
3651
|
});
|
|
@@ -3703,11 +3687,11 @@ ${formatTypes(generatedTypes)}
|
|
|
3703
3687
|
await this.#executeEnvironments(async (context) => {
|
|
3704
3688
|
await this.callPreHook(context, "build");
|
|
3705
3689
|
await this.callNormalHook(context, "build");
|
|
3706
|
-
if (context.config.output.
|
|
3707
|
-
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);
|
|
3708
3692
|
const destinationPath = joinPaths.joinPaths(append.appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot), "dist");
|
|
3709
3693
|
if (sourcePath !== destinationPath) {
|
|
3710
|
-
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}).`);
|
|
3711
3695
|
await copyFile.copyFiles({
|
|
3712
3696
|
input: sourcePath,
|
|
3713
3697
|
glob: "**/*"
|
|
@@ -4050,7 +4034,7 @@ function withExecutor(command, executorFn) {
|
|
|
4050
4034
|
throw new Error("The executor requires `projectsConfigurations` on the context object.");
|
|
4051
4035
|
}
|
|
4052
4036
|
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
4053
|
-
const api = await src_default.from(workspaceConfig.workspaceRoot,
|
|
4037
|
+
const api = await src_default.from(workspaceConfig.workspaceRoot, defu6__default.default({
|
|
4054
4038
|
root: projectConfig.root,
|
|
4055
4039
|
type: projectConfig.projectType,
|
|
4056
4040
|
sourceRoot: projectConfig.sourceRoot,
|
|
@@ -4063,7 +4047,7 @@ function withExecutor(command, executorFn) {
|
|
|
4063
4047
|
}
|
|
4064
4048
|
}, options));
|
|
4065
4049
|
try {
|
|
4066
|
-
return await Promise.resolve(executorFn(
|
|
4050
|
+
return await Promise.resolve(executorFn(defu6__default.default({
|
|
4067
4051
|
projectName: context.projectName,
|
|
4068
4052
|
options,
|
|
4069
4053
|
workspaceConfig,
|