@powerlines/nx 0.1.0
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/LICENSE +201 -0
- package/README.md +490 -0
- package/dist/chunk-23KFTIT2.mjs +1 -0
- package/dist/chunk-2IKNOV7W.mjs +305 -0
- package/dist/chunk-326QB2VK.mjs +14 -0
- package/dist/chunk-3QPPK4K2.js +18 -0
- package/dist/chunk-5K7DMFAV.mjs +15 -0
- package/dist/chunk-6UG6SXHV.js +4307 -0
- package/dist/chunk-6ZABD5GY.js +18 -0
- package/dist/chunk-AKX3TTDA.js +18 -0
- package/dist/chunk-CQP2LCFV.mjs +19 -0
- package/dist/chunk-CYWOTYVX.mjs +108 -0
- package/dist/chunk-E6VIOC6R.mjs +19 -0
- package/dist/chunk-ED7GH5H4.js +30 -0
- package/dist/chunk-ESI25Y6Y.mjs +15 -0
- package/dist/chunk-FK3VJFET.mjs +28 -0
- package/dist/chunk-FXCIWWXO.mjs +15 -0
- package/dist/chunk-HHPODCTP.js +126 -0
- package/dist/chunk-N2YKXZ5R.js +2 -0
- package/dist/chunk-O6BSKBJP.js +26 -0
- package/dist/chunk-O6YSETKJ.mjs +4 -0
- package/dist/chunk-OOERKIVS.js +312 -0
- package/dist/chunk-OZMYXUES.mjs +4276 -0
- package/dist/chunk-SHUYVCID.js +6 -0
- package/dist/chunk-TCSCYVA7.mjs +76 -0
- package/dist/chunk-UV4HQO3Y.mjs +1 -0
- package/dist/chunk-WKH7IEJU.js +26 -0
- package/dist/chunk-WUJKJGEW.js +17 -0
- package/dist/chunk-XO62WWX4.js +2 -0
- package/dist/chunk-XPEFTYN7.js +82 -0
- package/dist/executor-B2Y0F4JC.d.ts +83 -0
- package/dist/executor-BAcpDLQu.d.ts +83 -0
- package/dist/executor-BHIUeaip.d.ts +93 -0
- package/dist/executor-BYGMOBlU.d.mts +83 -0
- package/dist/executor-Ba95I3EK.d.mts +93 -0
- package/dist/executor-CIEyQL42.d.mts +83 -0
- package/dist/executor-CkqLFUNx.d.ts +83 -0
- package/dist/executor-D055lNr2.d.ts +83 -0
- package/dist/executor-D0PJOQkn.d.mts +83 -0
- package/dist/executor-DsRaA9mk.d.mts +83 -0
- package/dist/executors.d.mts +12 -0
- package/dist/executors.d.ts +12 -0
- package/dist/executors.js +34 -0
- package/dist/executors.mjs +9 -0
- package/dist/generators.d.mts +19 -0
- package/dist/generators.d.ts +19 -0
- package/dist/generators.js +16 -0
- package/dist/generators.mjs +3 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +53 -0
- package/dist/index.mjs +12 -0
- package/dist/src/base/base-executor.d.mts +27 -0
- package/dist/src/base/base-executor.d.ts +27 -0
- package/dist/src/base/base-executor.js +12 -0
- package/dist/src/base/base-executor.mjs +3 -0
- package/dist/src/base/base-executor.schema.d.d.mts +75 -0
- package/dist/src/base/base-executor.schema.d.d.ts +75 -0
- package/dist/src/base/base-executor.schema.d.js +2 -0
- package/dist/src/base/base-executor.schema.d.mjs +1 -0
- package/dist/src/base/base-executor.schema.d.ts +75 -0
- package/dist/src/base/base-executor.schema.json +77 -0
- package/dist/src/base/base-executor.untyped.d.mts +5 -0
- package/dist/src/base/base-executor.untyped.d.ts +5 -0
- package/dist/src/base/base-executor.untyped.js +10 -0
- package/dist/src/base/base-executor.untyped.mjs +2 -0
- package/dist/src/executors/build/executor.d.mts +8 -0
- package/dist/src/executors/build/executor.d.ts +8 -0
- package/dist/src/executors/build/executor.js +19 -0
- package/dist/src/executors/build/executor.mjs +4 -0
- package/dist/src/executors/build/untyped.d.mts +5 -0
- package/dist/src/executors/build/untyped.d.ts +5 -0
- package/dist/src/executors/build/untyped.js +37 -0
- package/dist/src/executors/build/untyped.mjs +33 -0
- package/dist/src/executors/clean/executor.d.mts +8 -0
- package/dist/src/executors/clean/executor.d.ts +8 -0
- package/dist/src/executors/clean/executor.js +19 -0
- package/dist/src/executors/clean/executor.mjs +4 -0
- package/dist/src/executors/clean/untyped.d.mts +5 -0
- package/dist/src/executors/clean/untyped.d.ts +5 -0
- package/dist/src/executors/clean/untyped.js +19 -0
- package/dist/src/executors/clean/untyped.mjs +15 -0
- package/dist/src/executors/docs/executor.d.mts +8 -0
- package/dist/src/executors/docs/executor.d.ts +8 -0
- package/dist/src/executors/docs/executor.js +19 -0
- package/dist/src/executors/docs/executor.mjs +4 -0
- package/dist/src/executors/docs/untyped.d.mts +5 -0
- package/dist/src/executors/docs/untyped.d.ts +5 -0
- package/dist/src/executors/docs/untyped.js +20 -0
- package/dist/src/executors/docs/untyped.mjs +16 -0
- package/dist/src/executors/lint/executor.d.mts +8 -0
- package/dist/src/executors/lint/executor.d.ts +8 -0
- package/dist/src/executors/lint/executor.js +19 -0
- package/dist/src/executors/lint/executor.mjs +4 -0
- package/dist/src/executors/lint/untyped.d.mts +5 -0
- package/dist/src/executors/lint/untyped.d.ts +5 -0
- package/dist/src/executors/lint/untyped.js +20 -0
- package/dist/src/executors/lint/untyped.mjs +16 -0
- package/dist/src/executors/prepare/executor.d.mts +8 -0
- package/dist/src/executors/prepare/executor.d.ts +8 -0
- package/dist/src/executors/prepare/executor.js +19 -0
- package/dist/src/executors/prepare/executor.mjs +4 -0
- package/dist/src/executors/prepare/untyped.d.mts +5 -0
- package/dist/src/executors/prepare/untyped.d.ts +5 -0
- package/dist/src/executors/prepare/untyped.js +11 -0
- package/dist/src/executors/prepare/untyped.mjs +3 -0
- package/dist/src/generators/sync/generator.d.mts +6 -0
- package/dist/src/generators/sync/generator.d.ts +6 -0
- package/dist/src/generators/sync/generator.js +17 -0
- package/dist/src/generators/sync/generator.mjs +2 -0
- package/dist/src/generators/sync/untyped.d.mts +5 -0
- package/dist/src/generators/sync/untyped.d.ts +5 -0
- package/dist/src/generators/sync/untyped.js +25 -0
- package/dist/src/generators/sync/untyped.mjs +21 -0
- package/dist/src/plugin/index.d.mts +8 -0
- package/dist/src/plugin/index.d.ts +8 -0
- package/dist/src/plugin/index.js +16 -0
- package/dist/src/plugin/index.mjs +3 -0
- package/docs/api/base-executor.schema.md +72 -0
- package/docs/api/build/schema.md +82 -0
- package/docs/api/clean/schema.md +72 -0
- package/docs/api/docs/schema.md +72 -0
- package/docs/api/lint/schema.md +72 -0
- package/docs/api/prepare/schema.md +72 -0
- package/docs/api/sync/schema.md +16 -0
- package/executors.json +30 -0
- package/generators.json +14 -0
- package/package.json +172 -0
|
@@ -0,0 +1,4307 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkHHPODCTP_js = require('./chunk-HHPODCTP.js');
|
|
4
|
+
var chunkSHUYVCID_js = require('./chunk-SHUYVCID.js');
|
|
5
|
+
var logger = require('@storm-software/config-tools/logger');
|
|
6
|
+
var baseExecutor = require('@storm-software/workspace-tools/base/base-executor');
|
|
7
|
+
var isError = require('@stryke/type-checks/is-error');
|
|
8
|
+
var defu4 = require('defu');
|
|
9
|
+
var console$1 = require('@storm-software/config-tools/logger/console');
|
|
10
|
+
var types = require('@storm-software/config-tools/types');
|
|
11
|
+
var toArray = require('@stryke/convert/to-array');
|
|
12
|
+
var copyFile = require('@stryke/fs/copy-file');
|
|
13
|
+
var exists = require('@stryke/fs/exists');
|
|
14
|
+
var helpers = require('@stryke/fs/helpers');
|
|
15
|
+
var install = require('@stryke/fs/install');
|
|
16
|
+
var listFiles = require('@stryke/fs/list-files');
|
|
17
|
+
var packageFns = require('@stryke/fs/package-fns');
|
|
18
|
+
var filePathFns = require('@stryke/path/file-path-fns');
|
|
19
|
+
var isParentPath = require('@stryke/path/is-parent-path');
|
|
20
|
+
var joinPaths = require('@stryke/path/join-paths');
|
|
21
|
+
var replace = require('@stryke/path/replace');
|
|
22
|
+
var isFunction = require('@stryke/type-checks/is-function');
|
|
23
|
+
var isNumber = require('@stryke/type-checks/is-number');
|
|
24
|
+
var isSet = require('@stryke/type-checks/is-set');
|
|
25
|
+
var isSetObject = require('@stryke/type-checks/is-set-object');
|
|
26
|
+
var isSetString = require('@stryke/type-checks/is-set-string');
|
|
27
|
+
var chalk5 = require('chalk');
|
|
28
|
+
var Handlebars = require('handlebars');
|
|
29
|
+
var promises = require('fs/promises');
|
|
30
|
+
var path = require('path');
|
|
31
|
+
var typedoc = require('typedoc');
|
|
32
|
+
var json = require('@stryke/fs/json');
|
|
33
|
+
var append = require('@stryke/path/append');
|
|
34
|
+
var ts3 = require('typescript');
|
|
35
|
+
var isUndefined = require('@stryke/type-checks/is-undefined');
|
|
36
|
+
var writeFile = require('@stryke/fs/write-file');
|
|
37
|
+
var prettier = require('prettier');
|
|
38
|
+
var resolve = require('@stryke/fs/resolve');
|
|
39
|
+
var titleCase = require('@stryke/string-format/title-case');
|
|
40
|
+
var getEnvPaths = require('@stryke/env/get-env-paths');
|
|
41
|
+
var getWorkspaceRoot = require('@stryke/fs/get-workspace-root');
|
|
42
|
+
var murmurhash = require('@stryke/hash/murmurhash');
|
|
43
|
+
var getUnique = require('@stryke/helpers/get-unique');
|
|
44
|
+
var omit = require('@stryke/helpers/omit');
|
|
45
|
+
var join = require('@stryke/path/join');
|
|
46
|
+
var isNull = require('@stryke/type-checks/is-null');
|
|
47
|
+
var isString = require('@stryke/type-checks/is-string');
|
|
48
|
+
var uuid = require('@stryke/unique-id/uuid');
|
|
49
|
+
var parseTypeDefinition = require('@stryke/convert/parse-type-definition');
|
|
50
|
+
var colors = require('@storm-software/config-tools/utilities/colors');
|
|
51
|
+
var noop = require('@stryke/helpers/noop');
|
|
52
|
+
var jiti = require('jiti');
|
|
53
|
+
var bufferToString = require('@stryke/convert/buffer-to-string');
|
|
54
|
+
var isType = require('@stryke/path/is-type');
|
|
55
|
+
var prettyBytes = require('@stryke/string-format/pretty-bytes');
|
|
56
|
+
var isBuffer = require('@stryke/type-checks/is-buffer');
|
|
57
|
+
var memfs = require('memfs');
|
|
58
|
+
var buffer = require('buffer');
|
|
59
|
+
var fs = require('fs');
|
|
60
|
+
var unionfs = require('unionfs');
|
|
61
|
+
var isObject = require('@stryke/type-checks/is-object');
|
|
62
|
+
var isFile = require('@stryke/fs/is-file');
|
|
63
|
+
var readFile = require('@stryke/fs/read-file');
|
|
64
|
+
var semverFns = require('@stryke/fs/semver-fns');
|
|
65
|
+
var getParentPath = require('@stryke/path/get-parent-path');
|
|
66
|
+
var _package = require('@stryke/string-format/package');
|
|
67
|
+
var core = require('@babel/core');
|
|
68
|
+
var MagicString = require('magic-string');
|
|
69
|
+
var helperPluginUtils = require('@babel/helper-plugin-utils');
|
|
70
|
+
var t = require('@babel/types');
|
|
71
|
+
var superdiff = require('@donedeal0/superdiff');
|
|
72
|
+
var tsconfig = require('@stryke/fs/tsconfig');
|
|
73
|
+
var stormJson = require('@stryke/json/storm-json');
|
|
74
|
+
var minimatch = require('minimatch');
|
|
75
|
+
var environmentChecks = require('@stryke/env/environment-checks');
|
|
76
|
+
var unplugin = require('unplugin');
|
|
77
|
+
var bundleRequire = require('bundle-require');
|
|
78
|
+
var kit = require('@nuxt/kit');
|
|
79
|
+
require('@nuxt/schema');
|
|
80
|
+
|
|
81
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
82
|
+
|
|
83
|
+
function _interopNamespace(e) {
|
|
84
|
+
if (e && e.__esModule) return e;
|
|
85
|
+
var n = Object.create(null);
|
|
86
|
+
if (e) {
|
|
87
|
+
Object.keys(e).forEach(function (k) {
|
|
88
|
+
if (k !== 'default') {
|
|
89
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
90
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () { return e[k]; }
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
n.default = e;
|
|
98
|
+
return Object.freeze(n);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var defu4__default = /*#__PURE__*/_interopDefault(defu4);
|
|
102
|
+
var chalk5__default = /*#__PURE__*/_interopDefault(chalk5);
|
|
103
|
+
var Handlebars__default = /*#__PURE__*/_interopDefault(Handlebars);
|
|
104
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
105
|
+
var ts3__default = /*#__PURE__*/_interopDefault(ts3);
|
|
106
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
107
|
+
var MagicString__default = /*#__PURE__*/_interopDefault(MagicString);
|
|
108
|
+
var t__namespace = /*#__PURE__*/_interopNamespace(t);
|
|
109
|
+
|
|
110
|
+
var objectToFrontmatter = /* @__PURE__ */ chunkSHUYVCID_js.__name((object = {}) => Object.entries(object).filter(([, value]) => {
|
|
111
|
+
return value !== void 0 && value !== null && value !== "" && typeof value === "string" || Array.isArray(value) && value.length > 0;
|
|
112
|
+
}).map(([key, value]) => `${key}: ${value}`).join("\n"), "objectToFrontmatter");
|
|
113
|
+
var onRendererPageEnd = /* @__PURE__ */ chunkSHUYVCID_js.__name((frontmatterObject) => (event) => {
|
|
114
|
+
if (!event.contents) {
|
|
115
|
+
return;
|
|
116
|
+
} else if (/README\.md$/.test(event.url)) {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const frontmatter = `---
|
|
121
|
+
title: '${event.model.name}'
|
|
122
|
+
${objectToFrontmatter(frontmatterObject)}
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
`;
|
|
126
|
+
event.contents = frontmatter + event.contents;
|
|
127
|
+
}, "onRendererPageEnd");
|
|
128
|
+
var buildNavigationFromProjectReflection = /* @__PURE__ */ chunkSHUYVCID_js.__name((baseUrl = "", project) => {
|
|
129
|
+
const baseUrlWithoutTrailingSlash = baseUrl.replace(/\/$/gm, "");
|
|
130
|
+
const result = {
|
|
131
|
+
type: "flat"
|
|
132
|
+
};
|
|
133
|
+
const isGroupOfModules = /* @__PURE__ */ chunkSHUYVCID_js.__name((group) => group.title === "Modules", "isGroupOfModules");
|
|
134
|
+
const reflectionToNavItem = /* @__PURE__ */ chunkSHUYVCID_js.__name((reflection) => {
|
|
135
|
+
return {
|
|
136
|
+
title: reflection.name,
|
|
137
|
+
url: `${baseUrlWithoutTrailingSlash}/${reflection.url}`.replace(/\.md$/, "")
|
|
138
|
+
};
|
|
139
|
+
}, "reflectionToNavItem");
|
|
140
|
+
const modulesGroupToNavigationGroup = /* @__PURE__ */ chunkSHUYVCID_js.__name((module) => ({
|
|
141
|
+
items: (module.groups ?? []).flatMap((group) => group.children.map(reflectionToNavItem)),
|
|
142
|
+
name: module.name
|
|
143
|
+
}), "modulesGroupToNavigationGroup");
|
|
144
|
+
const navFromReflectionGroups = /* @__PURE__ */ chunkSHUYVCID_js.__name((groups, nav = {
|
|
145
|
+
type: "flat"
|
|
146
|
+
}) => {
|
|
147
|
+
groups.forEach((group) => {
|
|
148
|
+
if (isGroupOfModules(group)) {
|
|
149
|
+
nav.type = "modular";
|
|
150
|
+
nav.modules = group.children.map(modulesGroupToNavigationGroup);
|
|
151
|
+
} else {
|
|
152
|
+
nav.items = nav?.items?.length ? nav.items : [];
|
|
153
|
+
nav.items = nav.items.concat(group.children.flatMap(reflectionToNavItem));
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return nav;
|
|
157
|
+
}, "navFromReflectionGroups");
|
|
158
|
+
return navFromReflectionGroups(project.groups, result);
|
|
159
|
+
}, "buildNavigationFromProjectReflection");
|
|
160
|
+
var onDeclaration = /* @__PURE__ */ chunkSHUYVCID_js.__name((entryPoints = []) => (context, reflection) => {
|
|
161
|
+
if (reflection.kind === typedoc.ReflectionKind.Module) {
|
|
162
|
+
const matchingEntryPoint = entryPoints.find((entryPoint) => entryPoint.path === reflection.sources[0].fullFileName);
|
|
163
|
+
reflection.name = matchingEntryPoint?.name ?? reflection.name;
|
|
164
|
+
}
|
|
165
|
+
}, "onDeclaration");
|
|
166
|
+
var typedocConfig = {
|
|
167
|
+
excludeExternals: true,
|
|
168
|
+
excludeInternal: true,
|
|
169
|
+
excludePrivate: true,
|
|
170
|
+
excludeProtected: true,
|
|
171
|
+
githubPages: false
|
|
172
|
+
};
|
|
173
|
+
var markdownPluginConfig = {
|
|
174
|
+
hideBreadcrumbs: true,
|
|
175
|
+
hideInPageTOC: true,
|
|
176
|
+
hidePageHeader: true,
|
|
177
|
+
hidePageTitle: true
|
|
178
|
+
};
|
|
179
|
+
var removeTrailingSlash = /* @__PURE__ */ chunkSHUYVCID_js.__name((pathString = "") => pathString.endsWith(path.sep) ? pathString.slice(0, pathString.length - 1) : pathString, "removeTrailingSlash");
|
|
180
|
+
var initTypedoc = /* @__PURE__ */ chunkSHUYVCID_js.__name(async (context, options) => {
|
|
181
|
+
const { baseUrl = "/docs/", outputPath } = options;
|
|
182
|
+
const entryPoints = options.entryPoints ?? context.entry.map((entry) => ({
|
|
183
|
+
name: entry.name || entry.output || filePathFns.findFileName(entry.file, {
|
|
184
|
+
withExtension: false
|
|
185
|
+
}),
|
|
186
|
+
path: joinPaths.joinPaths(context.config.projectRoot, entry.file)
|
|
187
|
+
}));
|
|
188
|
+
const app = await typedoc.Application.bootstrapWithPlugins({
|
|
189
|
+
...typedocConfig,
|
|
190
|
+
...markdownPluginConfig,
|
|
191
|
+
gitRevision: context.workspaceConfig.branch || "main",
|
|
192
|
+
tsconfig: context.tsconfig.tsconfigFilePath,
|
|
193
|
+
exclude: context.tsconfig.tsconfigJson.exclude?.filter(Boolean),
|
|
194
|
+
out: outputPath,
|
|
195
|
+
basePath: baseUrl,
|
|
196
|
+
entryPoints: entryPoints?.map((e) => e.path),
|
|
197
|
+
plugin: [
|
|
198
|
+
"typedoc-plugin-markdown",
|
|
199
|
+
"powerlines/lib/typedoc/plugin"
|
|
200
|
+
],
|
|
201
|
+
theme: "powerlines",
|
|
202
|
+
readme: "none",
|
|
203
|
+
excludePrivate: true,
|
|
204
|
+
hideGenerator: true
|
|
205
|
+
}, [
|
|
206
|
+
new typedoc.TypeDocReader(),
|
|
207
|
+
new typedoc.PackageJsonReader(),
|
|
208
|
+
new typedoc.TSConfigReader()
|
|
209
|
+
]);
|
|
210
|
+
app.options.addReader(new typedoc.TSConfigReader());
|
|
211
|
+
app.converter.on(typedoc.Converter.EVENT_CREATE_DECLARATION, onDeclaration(entryPoints));
|
|
212
|
+
const getReflections = /* @__PURE__ */ chunkSHUYVCID_js.__name(async () => app.convert(), "getReflections");
|
|
213
|
+
const generateDocs = /* @__PURE__ */ chunkSHUYVCID_js.__name(async (opts) => {
|
|
214
|
+
const { outputPath: outputFolder, project, frontmatter } = opts;
|
|
215
|
+
app.renderer.on(typedoc.PageEvent.END, onRendererPageEnd(frontmatter));
|
|
216
|
+
await app.generateDocs(project, outputFolder || outputPath);
|
|
217
|
+
}, "generateDocs");
|
|
218
|
+
const generateNavigationJSON = /* @__PURE__ */ chunkSHUYVCID_js.__name(async (project, outputFolder = outputPath) => {
|
|
219
|
+
const navigation = buildNavigationFromProjectReflection(baseUrl, project);
|
|
220
|
+
await promises.writeFile(`${removeTrailingSlash(outputFolder)}/nav.json`, JSON.stringify(navigation));
|
|
221
|
+
}, "generateNavigationJSON");
|
|
222
|
+
return {
|
|
223
|
+
app,
|
|
224
|
+
generateDocs,
|
|
225
|
+
generateNavigationJSON,
|
|
226
|
+
getReflections
|
|
227
|
+
};
|
|
228
|
+
}, "initTypedoc");
|
|
229
|
+
function getTsconfigFilePath(workspaceRoot, projectRoot, tsconfig = "tsconfig.json") {
|
|
230
|
+
let tsconfigFilePath = tsconfig;
|
|
231
|
+
if (!exists.existsSync(tsconfigFilePath)) {
|
|
232
|
+
tsconfigFilePath = append.appendPath(tsconfig, projectRoot);
|
|
233
|
+
if (!exists.existsSync(tsconfigFilePath)) {
|
|
234
|
+
tsconfigFilePath = append.appendPath(tsconfig, workspaceRoot);
|
|
235
|
+
if (!exists.existsSync(tsconfigFilePath)) {
|
|
236
|
+
tsconfigFilePath = append.appendPath(tsconfig, joinPaths.joinPaths(workspaceRoot, projectRoot));
|
|
237
|
+
if (!exists.existsSync(tsconfigFilePath)) {
|
|
238
|
+
throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${tsconfig}, ${append.appendPath(tsconfig, projectRoot)}, ${append.appendPath(tsconfig, workspaceRoot)}, or ${tsconfigFilePath}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return tsconfigFilePath;
|
|
244
|
+
}
|
|
245
|
+
chunkSHUYVCID_js.__name(getTsconfigFilePath, "getTsconfigFilePath");
|
|
246
|
+
function findMatch(tsconfigType, types, extensions = [
|
|
247
|
+
".ts",
|
|
248
|
+
".tsx",
|
|
249
|
+
".d.ts"
|
|
250
|
+
]) {
|
|
251
|
+
return types.find((type) => tsconfigType?.toString().toLowerCase() === type?.toString().toLowerCase() || tsconfigType?.toString().toLowerCase() === `./${type?.toString().toLowerCase()}` || `./${tsconfigType?.toString().toLowerCase()}` === type?.toString().toLowerCase() || extensions.some((ext) => `${tsconfigType?.toString().toLowerCase()}${ext}` === type?.toString().toLowerCase() || `${tsconfigType?.toString().toLowerCase()}${ext}` === `./${type?.toString().toLowerCase()}` || `${type?.toString().toLowerCase()}${ext}` === `./${tsconfigType?.toString().toLowerCase()}` || tsconfigType?.toString().toLowerCase() === `${type?.toString().toLowerCase()}${ext}` || tsconfigType?.toString().toLowerCase() === `./${type?.toString().toLowerCase()}${ext}` || type?.toString().toLowerCase() === `./${tsconfigType?.toString().toLowerCase()}${ext}`));
|
|
252
|
+
}
|
|
253
|
+
chunkSHUYVCID_js.__name(findMatch, "findMatch");
|
|
254
|
+
function findIncludeMatch(tsconfigType, types) {
|
|
255
|
+
return findMatch(tsconfigType, types, [
|
|
256
|
+
".ts",
|
|
257
|
+
".tsx",
|
|
258
|
+
".d.ts",
|
|
259
|
+
".js",
|
|
260
|
+
".jsx",
|
|
261
|
+
".mjs",
|
|
262
|
+
".cjs",
|
|
263
|
+
".mts",
|
|
264
|
+
".cts",
|
|
265
|
+
"/*.ts",
|
|
266
|
+
"/*.tsx",
|
|
267
|
+
"/*.d.ts",
|
|
268
|
+
"/*.js",
|
|
269
|
+
"/*.jsx",
|
|
270
|
+
"/*.mjs",
|
|
271
|
+
"/*.cjs",
|
|
272
|
+
"/*.mts",
|
|
273
|
+
"/*.cts",
|
|
274
|
+
"/**/*.ts",
|
|
275
|
+
"/**/*.tsx",
|
|
276
|
+
"/**/*.d.ts",
|
|
277
|
+
"/**/*.js",
|
|
278
|
+
"/**/*.jsx",
|
|
279
|
+
"/**/*.mjs",
|
|
280
|
+
"/**/*.cjs",
|
|
281
|
+
"/**/*.mts",
|
|
282
|
+
"/**/*.cts"
|
|
283
|
+
]);
|
|
284
|
+
}
|
|
285
|
+
chunkSHUYVCID_js.__name(findIncludeMatch, "findIncludeMatch");
|
|
286
|
+
function isIncludeMatchFound(tsconfigType, types) {
|
|
287
|
+
return findIncludeMatch(tsconfigType, types) !== void 0;
|
|
288
|
+
}
|
|
289
|
+
chunkSHUYVCID_js.__name(isIncludeMatchFound, "isIncludeMatchFound");
|
|
290
|
+
function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfigRaw = {}, originalTsconfigJson, host = ts3__default.default.sys) {
|
|
291
|
+
const tsconfigFilePath = getTsconfigFilePath(workspaceRoot, projectRoot, tsconfig);
|
|
292
|
+
const tsconfigJson = json.readJsonFileSync(tsconfigFilePath);
|
|
293
|
+
if (!tsconfigJson) {
|
|
294
|
+
throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${joinPaths.joinPaths(projectRoot, tsconfig ?? "tsconfig.json")}`);
|
|
295
|
+
}
|
|
296
|
+
const parsedCommandLine = ts3__default.default.parseJsonConfigFileContent(defu4__default.default(tsconfigRaw ?? {}, tsconfigJson), host, append.appendPath(projectRoot, workspaceRoot));
|
|
297
|
+
if (parsedCommandLine.errors.length > 0) {
|
|
298
|
+
const errorMessage = `Cannot parse the TypeScript compiler options. Please investigate the following issues:
|
|
299
|
+
${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && error.code ? `[${error.category}-${error.code}]: ` : "") + error.messageText.toString()}`).join("\n")}
|
|
300
|
+
`;
|
|
301
|
+
throw new Error(errorMessage);
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
...parsedCommandLine,
|
|
305
|
+
originalTsconfigJson: originalTsconfigJson ?? tsconfigJson,
|
|
306
|
+
tsconfigJson,
|
|
307
|
+
tsconfigFilePath
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
chunkSHUYVCID_js.__name(getParsedTypeScriptConfig, "getParsedTypeScriptConfig");
|
|
311
|
+
|
|
312
|
+
// ../powerlines/src/lib/utilities/file-header.ts
|
|
313
|
+
function getBaseFileHeader() {
|
|
314
|
+
return `
|
|
315
|
+
// Generated with Powerlines
|
|
316
|
+
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
317
|
+
`;
|
|
318
|
+
}
|
|
319
|
+
chunkSHUYVCID_js.__name(getBaseFileHeader, "getBaseFileHeader");
|
|
320
|
+
function getFileHeader(directive = "", prettierIgnore = false) {
|
|
321
|
+
if (directive && process.env.POWERLINES_LOCAL) {
|
|
322
|
+
directive = directive.replaceAll("powerlines/runtime-types", "../../dist/packages/types");
|
|
323
|
+
}
|
|
324
|
+
return `/* eslint-disable */
|
|
325
|
+
// biome-ignore lint: disable
|
|
326
|
+
${prettierIgnore ? `// prettier-ignore` : ""}${directive ? `
|
|
327
|
+
|
|
328
|
+
${directive}
|
|
329
|
+
` : "\n"}
|
|
330
|
+
${getBaseFileHeader()}
|
|
331
|
+
|
|
332
|
+
`;
|
|
333
|
+
}
|
|
334
|
+
chunkSHUYVCID_js.__name(getFileHeader, "getFileHeader");
|
|
335
|
+
|
|
336
|
+
// ../powerlines/src/types/commands.ts
|
|
337
|
+
var SUPPORTED_COMMANDS = [
|
|
338
|
+
"new",
|
|
339
|
+
"clean",
|
|
340
|
+
"prepare",
|
|
341
|
+
"lint",
|
|
342
|
+
"test",
|
|
343
|
+
"build",
|
|
344
|
+
"docs",
|
|
345
|
+
"release",
|
|
346
|
+
"finalize"
|
|
347
|
+
];
|
|
348
|
+
|
|
349
|
+
// ../powerlines/src/lib/utilities/plugin-helpers.ts
|
|
350
|
+
function isPlugin(value) {
|
|
351
|
+
return isSetObject.isSetObject(value) && "name" in value && isSetString.isSetString(value.name) && (isUndefined.isUndefined(value.applyToEnvironment) || "applyToEnvironment" in value && isFunction.isFunction(value.applyToEnvironment)) && (isUndefined.isUndefined(value.dedupe) || "dedupe" in value && isFunction.isFunction(value.dedupe)) && (isUndefined.isUndefined(value.dependsOn) || "dependsOn" in value && Array.isArray(value.dependsOn) && value.dependsOn.every(isPluginConfig)) && SUPPORTED_COMMANDS.every((command) => isUndefined.isUndefined(value[command]) || command in value && (isFunction.isFunction(value[command]) || isSetObject.isSetObject(value[command]) && "handler" in value[command] && isFunction.isFunction(value[command].handler)));
|
|
352
|
+
}
|
|
353
|
+
chunkSHUYVCID_js.__name(isPlugin, "isPlugin");
|
|
354
|
+
function isPluginConfigObject(value) {
|
|
355
|
+
return isSetObject.isSetObject(value) && "plugin" in value && ((isSetString.isSetString(value.plugin) || isFunction.isFunction(value.plugin)) && "options" in value && isSetObject.isSetObject(value.options) || isPlugin(value.plugin));
|
|
356
|
+
}
|
|
357
|
+
chunkSHUYVCID_js.__name(isPluginConfigObject, "isPluginConfigObject");
|
|
358
|
+
function isPluginConfigTuple(value) {
|
|
359
|
+
return Array.isArray(value) && (value.length === 1 || value.length === 2) && ((isSetString.isSetString(value[0]) || isFunction.isFunction(value[0])) && value.length > 1 && isSetObject.isSetObject(value[1]) || isPlugin(value[0]));
|
|
360
|
+
}
|
|
361
|
+
chunkSHUYVCID_js.__name(isPluginConfigTuple, "isPluginConfigTuple");
|
|
362
|
+
function isPluginConfig(value) {
|
|
363
|
+
return isSetString.isSetString(value) || isFunction.isFunction(value) || isPlugin(value) || isPluginConfigObject(value) || isPluginConfigTuple(value);
|
|
364
|
+
}
|
|
365
|
+
chunkSHUYVCID_js.__name(isPluginConfig, "isPluginConfig");
|
|
366
|
+
function isPluginHookFunction(value) {
|
|
367
|
+
return isFunction.isFunction(value) || isSetObject.isSetObject(value) && "handler" in value && isFunction.isFunction(value.handler);
|
|
368
|
+
}
|
|
369
|
+
chunkSHUYVCID_js.__name(isPluginHookFunction, "isPluginHookFunction");
|
|
370
|
+
function isPluginHookObject(value) {
|
|
371
|
+
return isSetObject.isSetObject(value) && "handler" in value && isFunction.isFunction(value.handler);
|
|
372
|
+
}
|
|
373
|
+
chunkSHUYVCID_js.__name(isPluginHookObject, "isPluginHookObject");
|
|
374
|
+
function isPluginHook(value) {
|
|
375
|
+
return isPluginHookFunction(value) || isPluginHookObject(value);
|
|
376
|
+
}
|
|
377
|
+
chunkSHUYVCID_js.__name(isPluginHook, "isPluginHook");
|
|
378
|
+
function getHookHandler(pluginHook) {
|
|
379
|
+
return isFunction.isFunction(pluginHook) ? pluginHook : pluginHook.handler;
|
|
380
|
+
}
|
|
381
|
+
chunkSHUYVCID_js.__name(getHookHandler, "getHookHandler");
|
|
382
|
+
function isHookExternal(hook) {
|
|
383
|
+
return hook.startsWith("vite:") || hook.startsWith("esbuild:") || hook.startsWith("rolldown:") || hook.startsWith("rollup:") || hook.startsWith("webpack:") || hook.startsWith("rspack:") || hook.startsWith("farm:");
|
|
384
|
+
}
|
|
385
|
+
chunkSHUYVCID_js.__name(isHookExternal, "isHookExternal");
|
|
386
|
+
function checkDedupe(plugin, plugins2) {
|
|
387
|
+
return plugins2.some((p) => p.dedupe !== false && (isFunction.isFunction(p.dedupe) && p.dedupe(plugin) || p.name === plugin.name));
|
|
388
|
+
}
|
|
389
|
+
chunkSHUYVCID_js.__name(checkDedupe, "checkDedupe");
|
|
390
|
+
function addPluginHook(context, plugin, pluginHook, hooksList) {
|
|
391
|
+
if (!checkDedupe(plugin, hooksList.map((hook) => hook.plugin))) {
|
|
392
|
+
hooksList.push(isFunction.isFunction(pluginHook) ? {
|
|
393
|
+
plugin,
|
|
394
|
+
handler: getHookHandler(pluginHook).bind(context)
|
|
395
|
+
} : {
|
|
396
|
+
plugin,
|
|
397
|
+
...pluginHook,
|
|
398
|
+
handler: getHookHandler(pluginHook).bind(context)
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
chunkSHUYVCID_js.__name(addPluginHook, "addPluginHook");
|
|
403
|
+
async function writeFile2(log, filepath, content, skipFormat = false) {
|
|
404
|
+
try {
|
|
405
|
+
if (skipFormat) {
|
|
406
|
+
await writeFile.writeFile(filepath, content);
|
|
407
|
+
} else {
|
|
408
|
+
const config = await prettier.resolveConfig(filepath);
|
|
409
|
+
const formatted = await prettier.format(content, {
|
|
410
|
+
...config ?? {},
|
|
411
|
+
filepath
|
|
412
|
+
});
|
|
413
|
+
await writeFile.writeFile(filepath, formatted || "");
|
|
414
|
+
}
|
|
415
|
+
} catch (error) {
|
|
416
|
+
log(types.LogLevelLabel.ERROR, `Failed to write file ${filepath} to disk
|
|
417
|
+
${error?.message ? error.message : ""}`);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
chunkSHUYVCID_js.__name(writeFile2, "writeFile");
|
|
421
|
+
var DEFAULT_ENVIRONMENT = "default";
|
|
422
|
+
function createEnvironment(name, userConfig) {
|
|
423
|
+
return defu4__default.default(userConfig.environments?.[name] ?? {}, {
|
|
424
|
+
name,
|
|
425
|
+
title: userConfig.title || titleCase.titleCase(userConfig.name),
|
|
426
|
+
ssr: false,
|
|
427
|
+
mainFields: userConfig.build?.platform === "browser" ? [
|
|
428
|
+
"browser",
|
|
429
|
+
"module",
|
|
430
|
+
"jsnext:main",
|
|
431
|
+
"jsnext"
|
|
432
|
+
] : [
|
|
433
|
+
"module",
|
|
434
|
+
"jsnext:main",
|
|
435
|
+
"jsnext"
|
|
436
|
+
],
|
|
437
|
+
extensions: [
|
|
438
|
+
".mjs",
|
|
439
|
+
".js",
|
|
440
|
+
".mts",
|
|
441
|
+
".ts",
|
|
442
|
+
".jsx",
|
|
443
|
+
".tsx",
|
|
444
|
+
".json"
|
|
445
|
+
],
|
|
446
|
+
consumer: userConfig.build?.platform === "browser" ? "client" : "server",
|
|
447
|
+
preview: userConfig.build?.platform === "browser" ? {
|
|
448
|
+
port: 5173,
|
|
449
|
+
open: true,
|
|
450
|
+
strictPort: false,
|
|
451
|
+
// https: false,
|
|
452
|
+
host: "localhost",
|
|
453
|
+
allowedHosts: [
|
|
454
|
+
"."
|
|
455
|
+
],
|
|
456
|
+
cors: true,
|
|
457
|
+
headers: {}
|
|
458
|
+
} : void 0
|
|
459
|
+
}, userConfig);
|
|
460
|
+
}
|
|
461
|
+
chunkSHUYVCID_js.__name(createEnvironment, "createEnvironment");
|
|
462
|
+
function createDefaultEnvironment(userConfig) {
|
|
463
|
+
return createEnvironment(DEFAULT_ENVIRONMENT, userConfig);
|
|
464
|
+
}
|
|
465
|
+
chunkSHUYVCID_js.__name(createDefaultEnvironment, "createDefaultEnvironment");
|
|
466
|
+
function resolveEntryInputFile(context, typeDefinition) {
|
|
467
|
+
return replace.replacePath(typeDefinition.file, joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot));
|
|
468
|
+
}
|
|
469
|
+
chunkSHUYVCID_js.__name(resolveEntryInputFile, "resolveEntryInputFile");
|
|
470
|
+
function resolveEntryInput(context, typeDefinition) {
|
|
471
|
+
return {
|
|
472
|
+
file: resolveEntryInputFile(context, typeDefinition),
|
|
473
|
+
name: typeDefinition.name
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
chunkSHUYVCID_js.__name(resolveEntryInput, "resolveEntryInput");
|
|
477
|
+
function resolveEntryOutput(context, typeDefinition) {
|
|
478
|
+
return joinPaths.joinPaths(replace.replacePath(replace.replacePath(replace.replacePath(replace.replacePath(typeDefinition.file, joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.sourceRoot)), joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot)), context.config.sourceRoot), context.config.projectRoot)).replace(`.${filePathFns.findFileExtensionSafe(typeDefinition.file)}`, "");
|
|
479
|
+
}
|
|
480
|
+
chunkSHUYVCID_js.__name(resolveEntryOutput, "resolveEntryOutput");
|
|
481
|
+
function resolveEntry(context, typeDefinition) {
|
|
482
|
+
const input = resolveEntryInput(context, typeDefinition);
|
|
483
|
+
return {
|
|
484
|
+
...input,
|
|
485
|
+
input,
|
|
486
|
+
output: resolveEntryOutput(context, typeDefinition)
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
chunkSHUYVCID_js.__name(resolveEntry, "resolveEntry");
|
|
490
|
+
function resolveEntriesSync(context, typeDefinitions) {
|
|
491
|
+
return typeDefinitions.map((typeDefinition) => {
|
|
492
|
+
const parsed = parseTypeDefinition.parseTypeDefinition(typeDefinition);
|
|
493
|
+
return listFiles.listFilesSync(append.appendPath(parsed.file, context.config.projectRoot)).map((file) => resolveEntry(context, {
|
|
494
|
+
file,
|
|
495
|
+
name: parsed.name
|
|
496
|
+
}));
|
|
497
|
+
}).flat().filter(Boolean);
|
|
498
|
+
}
|
|
499
|
+
chunkSHUYVCID_js.__name(resolveEntriesSync, "resolveEntriesSync");
|
|
500
|
+
function getUniqueEntries(entries = []) {
|
|
501
|
+
return getUnique.getUniqueBy(toArray.toArray(entries), (item) => isSetString.isSetString(item) ? item : murmurhash.murmurhash(item ?? {}, {
|
|
502
|
+
maxLength: 24
|
|
503
|
+
}));
|
|
504
|
+
}
|
|
505
|
+
chunkSHUYVCID_js.__name(getUniqueEntries, "getUniqueEntries");
|
|
506
|
+
var createLog = /* @__PURE__ */ chunkSHUYVCID_js.__name((name, options = {}) => {
|
|
507
|
+
const logLevel = options.logLevel === null ? types.LogLevelLabel.SILENT : options.logLevel || types.LogLevelLabel.INFO;
|
|
508
|
+
if (logLevel === types.LogLevelLabel.SILENT) {
|
|
509
|
+
return noop.noop;
|
|
510
|
+
}
|
|
511
|
+
if (options.customLogger) {
|
|
512
|
+
return options.customLogger;
|
|
513
|
+
}
|
|
514
|
+
return (type, ...args) => logger.getLogFn(logger.getLogLevel(type), {
|
|
515
|
+
...options,
|
|
516
|
+
logLevel
|
|
517
|
+
})(`${chalk5__default.default.bold.hex(colors.getColor("brand", options))(`powerlines${name ? `:${name}` : ""}${options.name ? ` ${chalk5__default.default.gray("> ")}${options.name}` : ""} ${chalk5__default.default.gray("> ")}`)}${args.join(" ")} `.trim());
|
|
518
|
+
}, "createLog");
|
|
519
|
+
var BADGE_COLORS = [
|
|
520
|
+
"#00A0DD",
|
|
521
|
+
"#6FCE4E",
|
|
522
|
+
"#FBBF24",
|
|
523
|
+
"#F43F5E",
|
|
524
|
+
"#3B82F6",
|
|
525
|
+
"#A855F7",
|
|
526
|
+
"#469592",
|
|
527
|
+
"#288EDF",
|
|
528
|
+
"#10B981",
|
|
529
|
+
"#EF4444",
|
|
530
|
+
"#F0EC56",
|
|
531
|
+
"#F472B6",
|
|
532
|
+
"#22D3EE",
|
|
533
|
+
"#EAB308",
|
|
534
|
+
"#84CC16",
|
|
535
|
+
"#F87171",
|
|
536
|
+
"#0EA5E9",
|
|
537
|
+
"#D946EF",
|
|
538
|
+
"#FACC15",
|
|
539
|
+
"#34D399"
|
|
540
|
+
];
|
|
541
|
+
var extendLog = /* @__PURE__ */ chunkSHUYVCID_js.__name((logFn, name) => {
|
|
542
|
+
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(" ")} `);
|
|
543
|
+
}, "extendLog");
|
|
544
|
+
function resolveOptions(options) {
|
|
545
|
+
return defu4__default.default(options, {
|
|
546
|
+
interopDefault: true,
|
|
547
|
+
fsCache: options.mode !== "development" ? joinPaths.joinPaths(options.cacheDir, "jiti") : false,
|
|
548
|
+
moduleCache: options.mode !== "development"
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
chunkSHUYVCID_js.__name(resolveOptions, "resolveOptions");
|
|
552
|
+
function createPluginResolver(options) {
|
|
553
|
+
return jiti.createJiti(joinPaths.joinPaths(options.workspaceRoot, options.projectRoot), resolveOptions({
|
|
554
|
+
...options
|
|
555
|
+
}));
|
|
556
|
+
}
|
|
557
|
+
chunkSHUYVCID_js.__name(createPluginResolver, "createPluginResolver");
|
|
558
|
+
function createResolver(options) {
|
|
559
|
+
const baseResolver = jiti.createJiti(joinPaths.joinPaths(options.workspaceRoot, options.projectRoot), resolveOptions(options));
|
|
560
|
+
baseResolver.plugin = createPluginResolver(options);
|
|
561
|
+
return baseResolver;
|
|
562
|
+
}
|
|
563
|
+
chunkSHUYVCID_js.__name(createResolver, "createResolver");
|
|
564
|
+
var VirtualFileSystem = class {
|
|
565
|
+
static {
|
|
566
|
+
chunkSHUYVCID_js.__name(this, "VirtualFileSystem");
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* The internal map of virtual files.
|
|
570
|
+
*/
|
|
571
|
+
#builtinIdMap = /* @__PURE__ */ new Map();
|
|
572
|
+
/**
|
|
573
|
+
* A map of virtual file paths to their underlying file content.
|
|
574
|
+
*/
|
|
575
|
+
#cachedFS = /* @__PURE__ */ new Map();
|
|
576
|
+
/**
|
|
577
|
+
* A map of virtual file paths to their underlying file content.
|
|
578
|
+
*/
|
|
579
|
+
#cachedResolver = /* @__PURE__ */ new Map();
|
|
580
|
+
/**
|
|
581
|
+
* The internal map of virtual files.
|
|
582
|
+
*/
|
|
583
|
+
#virtualFS = new memfs.Volume();
|
|
584
|
+
/**
|
|
585
|
+
* The physical file system.
|
|
586
|
+
*/
|
|
587
|
+
#fs = cloneFS(fs__default.default);
|
|
588
|
+
/**
|
|
589
|
+
* The unified volume that combines the virtual file system with the real file system.
|
|
590
|
+
*
|
|
591
|
+
* @remarks
|
|
592
|
+
* This volume allows for seamless access to both virtual and real files.
|
|
593
|
+
*/
|
|
594
|
+
#unifiedFS = new unionfs.Union();
|
|
595
|
+
/**
|
|
596
|
+
* Indicator specifying if the file system module is patched
|
|
597
|
+
*/
|
|
598
|
+
#isPatched = false;
|
|
599
|
+
/**
|
|
600
|
+
* Function to revert require patch
|
|
601
|
+
*/
|
|
602
|
+
#revert;
|
|
603
|
+
/**
|
|
604
|
+
* The context of the virtual file system.
|
|
605
|
+
*/
|
|
606
|
+
#context;
|
|
607
|
+
/**
|
|
608
|
+
* The file system's logging function.
|
|
609
|
+
*/
|
|
610
|
+
#log;
|
|
611
|
+
/**
|
|
612
|
+
* Exposes the internal VFS map for advanced usage.
|
|
613
|
+
*/
|
|
614
|
+
get [chunkHHPODCTP_js.__VFS_CACHE__]() {
|
|
615
|
+
return this.#cachedFS;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Exposes the internal VFS resolver cache for advanced usage.
|
|
619
|
+
*/
|
|
620
|
+
get [chunkHHPODCTP_js.__VFS_RESOLVER__]() {
|
|
621
|
+
return this.#cachedResolver;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Exposes the internal VFS map for advanced usage.
|
|
625
|
+
*/
|
|
626
|
+
get [chunkHHPODCTP_js.__VFS_VIRTUAL__]() {
|
|
627
|
+
return this.#virtualFS;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Exposes the internal UFS map for advanced usage.
|
|
631
|
+
*/
|
|
632
|
+
get [chunkHHPODCTP_js.__VFS_UNIFIED__]() {
|
|
633
|
+
return this.#unifiedFS;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Creates a new instance of the VirtualFileSystem.
|
|
637
|
+
*
|
|
638
|
+
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
639
|
+
* @param serialized - A map of files/file contents to populate in cache
|
|
640
|
+
*/
|
|
641
|
+
constructor(context, serialized) {
|
|
642
|
+
this.#context = context;
|
|
643
|
+
this.#cachedFS = /* @__PURE__ */ new Map();
|
|
644
|
+
this.#builtinIdMap = new Map(Object.entries(serialized?.builtinIdMap ?? {}));
|
|
645
|
+
if (!this.#fs.existsSync(this.#context.dataPath)) {
|
|
646
|
+
this.#fs.mkdirSync(this.#context.dataPath, {
|
|
647
|
+
recursive: true
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
if (!this.#fs.existsSync(this.#context.cachePath)) {
|
|
651
|
+
this.#fs.mkdirSync(this.#context.cachePath, {
|
|
652
|
+
recursive: true
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
if (!this.#fs.existsSync(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
|
|
656
|
+
this.#fs.mkdirSync(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath), {
|
|
657
|
+
recursive: true
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
this.#unifiedFS = this.#unifiedFS.use(this.#fs);
|
|
661
|
+
if (this.#context.config.output.mode !== "fs") {
|
|
662
|
+
if (serialized?.virtualFiles && Object.keys(serialized.virtualFiles).length > 0) {
|
|
663
|
+
this.#virtualFS = memfs.Volume.fromJSON(serialized.virtualFiles);
|
|
664
|
+
}
|
|
665
|
+
if (!this.#virtualFS.existsSync(this.#context.artifactsPath)) {
|
|
666
|
+
this.#virtualFS.mkdirSync(this.#context.artifactsPath, {
|
|
667
|
+
recursive: true
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
if (!this.#virtualFS.existsSync(this.#context.builtinsPath)) {
|
|
671
|
+
this.#virtualFS.mkdirSync(this.#context.builtinsPath, {
|
|
672
|
+
recursive: true
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
if (!this.#virtualFS.existsSync(this.#context.entryPath)) {
|
|
676
|
+
this.#virtualFS.mkdirSync(this.#context.entryPath, {
|
|
677
|
+
recursive: true
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
if (!this.#virtualFS.existsSync(this.#context.dtsPath)) {
|
|
681
|
+
this.#virtualFS.mkdirSync(this.#context.dtsPath, {
|
|
682
|
+
recursive: true
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
this.#unifiedFS = this.#unifiedFS.use(this.#virtualFS);
|
|
686
|
+
} else if (this.#context.config.projectType === "application") {
|
|
687
|
+
if (!this.#fs.existsSync(this.#context.artifactsPath)) {
|
|
688
|
+
this.#fs.mkdirSync(this.#context.artifactsPath, {
|
|
689
|
+
recursive: true
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
if (!this.#fs.existsSync(this.#context.builtinsPath)) {
|
|
693
|
+
this.#fs.mkdirSync(this.#context.builtinsPath, {
|
|
694
|
+
recursive: true
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
if (!this.#fs.existsSync(this.#context.entryPath)) {
|
|
698
|
+
this.#fs.mkdirSync(this.#context.entryPath, {
|
|
699
|
+
recursive: true
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
if (!this.#fs.existsSync(this.#context.dtsPath)) {
|
|
703
|
+
this.#fs.mkdirSync(this.#context.dtsPath, {
|
|
704
|
+
recursive: true
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
this.#log = extendLog(this.#context.log, "virtual-file-system");
|
|
709
|
+
}
|
|
710
|
+
[chunkHHPODCTP_js.__VFS_INIT__]() {
|
|
711
|
+
if (!this.#isPatched && this.#context.config.output.mode !== "fs") {
|
|
712
|
+
this.#revert = patchFS(fs__default.default, this);
|
|
713
|
+
this.#isPatched = true;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
[chunkHHPODCTP_js.__VFS_REVERT__]() {
|
|
717
|
+
if (this.#isPatched && this.#context.config.output.mode !== "fs") {
|
|
718
|
+
if (!this.#revert) {
|
|
719
|
+
throw new Error("Attempting to revert File System patch prior to calling `__init__` function");
|
|
720
|
+
}
|
|
721
|
+
this.#revert?.();
|
|
722
|
+
this.#isPatched = false;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Returns a Map of all runtime file IDs and their corresponding paths in the virtual file system.
|
|
727
|
+
*
|
|
728
|
+
* @returns A Map where the keys are runtime file IDs (strings) and the values are their corresponding paths (strings).
|
|
729
|
+
*/
|
|
730
|
+
get builtinIdMap() {
|
|
731
|
+
return this.#builtinIdMap;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Lists all runtime IDs in the virtual file system.
|
|
735
|
+
*
|
|
736
|
+
* @returns An array of formatted runtime IDs.
|
|
737
|
+
*/
|
|
738
|
+
get runtimeIds() {
|
|
739
|
+
return Array.from(this.builtinIdMap.keys()).map((id) => this.formatRuntimeId(id));
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Checks if a given path or ID corresponds to a runtime file.
|
|
743
|
+
*
|
|
744
|
+
* @param pathOrId - The path or ID to check.
|
|
745
|
+
* @param options - Options for resolving the path, such as paths to check.
|
|
746
|
+
* @returns `true` if the path or ID corresponds to a runtime file, otherwise `false`.
|
|
747
|
+
*/
|
|
748
|
+
isBuiltinFile(pathOrId, options) {
|
|
749
|
+
return !!this.builtinIdMap.values().find((path2) => path2 === this.resolvePath(pathOrId, {
|
|
750
|
+
...options,
|
|
751
|
+
type: "file"
|
|
752
|
+
}));
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Checks if a provided string is a valid runtime ID (does not need to already be created in the file system).
|
|
756
|
+
*
|
|
757
|
+
* @param id - The ID to check.
|
|
758
|
+
* @returns Whether the ID is a valid runtime ID.
|
|
759
|
+
*/
|
|
760
|
+
isValidBuiltinId(id) {
|
|
761
|
+
return id.startsWith(`${this.#context.config.builtinPrefix}:`);
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Check if a path or ID corresponds to a virtual file.
|
|
765
|
+
*
|
|
766
|
+
* @param pathOrId - The path or ID to check.
|
|
767
|
+
* @param options - Options for resolving the path, such as paths to check.
|
|
768
|
+
* @returns Whether the path or ID corresponds to a virtual file.
|
|
769
|
+
*/
|
|
770
|
+
isVirtualFile(pathOrId, options = {}) {
|
|
771
|
+
if (!pathOrId) {
|
|
772
|
+
return false;
|
|
773
|
+
}
|
|
774
|
+
const resolvedPath = this.resolvePath(pathOrId, {
|
|
775
|
+
...options,
|
|
776
|
+
type: "file"
|
|
777
|
+
});
|
|
778
|
+
if (!resolvedPath) {
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
if (this.builtinIdMap.values().find((path2) => path2 === resolvedPath)) {
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
return this.#virtualFS.existsSync(resolvedPath);
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Check if a path exists within one of the directories specified in the tsconfig.json's `path` field.
|
|
788
|
+
*
|
|
789
|
+
* @see https://www.typescriptlang.org/tsconfig#paths
|
|
790
|
+
*
|
|
791
|
+
* @param pathOrId - The path or ID to check.
|
|
792
|
+
* @returns Whether the path or ID corresponds to a virtual file.
|
|
793
|
+
*/
|
|
794
|
+
isTsconfigPath(pathOrId) {
|
|
795
|
+
return !!this.#context.tsconfig.options.paths && Object.keys(this.#context.tsconfig.options.paths).some((path2) => pathOrId.startsWith(path2.replaceAll("*", "")));
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Checks if a given ID corresponds to a runtime file path.
|
|
799
|
+
*
|
|
800
|
+
* @param id - The unique identifier for the runtime file.
|
|
801
|
+
* @param pathOrId - The path or ID to check.
|
|
802
|
+
* @returns `true` if the ID corresponds to the path or ID of a runtime file, otherwise `false`.
|
|
803
|
+
*/
|
|
804
|
+
isMatchingBuiltinId(id, pathOrId) {
|
|
805
|
+
const resolvedPath = this.resolvePath(pathOrId);
|
|
806
|
+
const resolvedId = this.resolveId(pathOrId);
|
|
807
|
+
return !!(this.isBuiltinFile(pathOrId) && (resolvedPath && (resolvedPath === this.builtinIdMap.get(id) || resolvedPath === this.builtinIdMap.get(this.formatRuntimeId(id))) || resolvedId && (resolvedId === this.builtinIdMap.get(id) || resolvedId === this.builtinIdMap.get(this.formatRuntimeId(id)))));
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Lists all runtime files in the virtual file system.
|
|
811
|
+
*
|
|
812
|
+
* @returns A promise that resolves to an array of runtime files.
|
|
813
|
+
*/
|
|
814
|
+
async listBuiltinFiles() {
|
|
815
|
+
const runtimeFiles = [];
|
|
816
|
+
for (const [id, path2] of this.builtinIdMap.entries()) {
|
|
817
|
+
const contents = await this.readFile(path2);
|
|
818
|
+
if (contents) {
|
|
819
|
+
runtimeFiles.push({
|
|
820
|
+
id: this.formatRuntimeId(id),
|
|
821
|
+
path: path2,
|
|
822
|
+
contents
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return runtimeFiles;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Lists files in a given path.
|
|
830
|
+
*
|
|
831
|
+
* @param path - The path to list files from.
|
|
832
|
+
* @param options - Options for listing files, such as encoding and recursion.
|
|
833
|
+
* @returns An array of file names in the specified path.
|
|
834
|
+
*/
|
|
835
|
+
readdirSync(path2, options = "utf8") {
|
|
836
|
+
return this.resolveFS(path2).readdirSync(toFilePath(path2), options);
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Removes a file in the virtual file system (VFS).
|
|
840
|
+
*
|
|
841
|
+
* @param path - The path to create the directory at.
|
|
842
|
+
*/
|
|
843
|
+
unlinkSync(path2, options) {
|
|
844
|
+
const formattedPath = toFilePath(path2);
|
|
845
|
+
if (!this.fileExistsSync(path2)) {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
this.#log(types.LogLevelLabel.TRACE, `Synchronously removing file: ${formattedPath}`);
|
|
849
|
+
this.resolveFS(path2, options).unlinkSync(formattedPath);
|
|
850
|
+
this.#cachedFS.delete(formattedPath);
|
|
851
|
+
this.clearResolverCache(formattedPath);
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Removes a file in the virtual file system (VFS).
|
|
855
|
+
*
|
|
856
|
+
* @param path - The path to create the directory at.
|
|
857
|
+
*/
|
|
858
|
+
async unlink(path2, options) {
|
|
859
|
+
const formattedPath = toFilePath(path2);
|
|
860
|
+
if (!this.fileExistsSync(path2)) {
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
this.#log(types.LogLevelLabel.TRACE, `Removing file: ${formattedPath}`);
|
|
864
|
+
if (isFunction.isFunction(this.resolveFS(path2, options).promises.unlink)) {
|
|
865
|
+
await this.resolveFS(path2, options).promises.unlink(formattedPath);
|
|
866
|
+
this.#cachedFS.delete(formattedPath);
|
|
867
|
+
this.clearResolverCache(formattedPath);
|
|
868
|
+
} else {
|
|
869
|
+
this.unlinkSync(formattedPath, options);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Removes a directory in the virtual file system (VFS).
|
|
874
|
+
*
|
|
875
|
+
* @param path - The path to create the directory at.
|
|
876
|
+
* @param options - Options for creating the directory.
|
|
877
|
+
*/
|
|
878
|
+
rmdirSync(path2, options = {}) {
|
|
879
|
+
const formattedPath = toFilePath(path2);
|
|
880
|
+
if (!this.directoryExistsSync(path2)) {
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
this.#log(types.LogLevelLabel.TRACE, `Synchronously removing directory: ${formattedPath}`);
|
|
884
|
+
this.resolveFS(path2, options).rmdirSync(formattedPath, defu4__default.default(options, {
|
|
885
|
+
recursive: true
|
|
886
|
+
}));
|
|
887
|
+
this.#cachedFS.delete(formattedPath);
|
|
888
|
+
this.clearResolverCache(formattedPath);
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Removes a directory in the virtual file system (VFS).
|
|
892
|
+
*
|
|
893
|
+
* @param path - The path to create the directory at.
|
|
894
|
+
* @param options - Options for creating the directory.
|
|
895
|
+
* @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
|
|
896
|
+
*/
|
|
897
|
+
async rmdir(path2, options = {}) {
|
|
898
|
+
const formattedPath = toFilePath(path2);
|
|
899
|
+
if (!this.directoryExistsSync(path2)) {
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
this.#log(types.LogLevelLabel.TRACE, `Removing directory: ${formattedPath}`);
|
|
903
|
+
if (isFunction.isFunction(this.resolveFS(path2, options).promises.rm)) {
|
|
904
|
+
await this.resolveFS(path2, options).promises.rm(formattedPath, defu4__default.default(options, {
|
|
905
|
+
force: true,
|
|
906
|
+
recursive: true
|
|
907
|
+
}));
|
|
908
|
+
this.#cachedFS.delete(formattedPath);
|
|
909
|
+
this.clearResolverCache(formattedPath);
|
|
910
|
+
} else {
|
|
911
|
+
this.rmdirSync(formattedPath, defu4__default.default(options ?? {}, {
|
|
912
|
+
force: true,
|
|
913
|
+
recursive: true
|
|
914
|
+
}));
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Removes a file in the virtual file system (VFS).
|
|
919
|
+
*
|
|
920
|
+
* @param path - The path to the file to remove.
|
|
921
|
+
* @param options - Options for removing the file.
|
|
922
|
+
* @returns A promise that resolves when the file is removed.
|
|
923
|
+
*/
|
|
924
|
+
async rm(path2, options = {}) {
|
|
925
|
+
this.#log(types.LogLevelLabel.TRACE, `Removing: ${toFilePath(path2)}`);
|
|
926
|
+
if (this.directoryExistsSync(path2)) {
|
|
927
|
+
return this.rmdir(path2, options);
|
|
928
|
+
}
|
|
929
|
+
return this.unlink(path2, options);
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Creates a directory in the virtual file system (VFS).
|
|
933
|
+
*
|
|
934
|
+
* @param path - The path to create the directory at.
|
|
935
|
+
* @param options - Options for creating the directory.
|
|
936
|
+
* @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
|
|
937
|
+
*/
|
|
938
|
+
mkdirSync(path2, options = {}) {
|
|
939
|
+
const filePath = toFilePath(path2);
|
|
940
|
+
this.clearResolverCache(filePath);
|
|
941
|
+
return this.resolveFS(filePath, options).mkdirSync(filePath, defu4__default.default(options ?? {}, {
|
|
942
|
+
recursive: true
|
|
943
|
+
}));
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Creates a directory in the virtual file system (VFS).
|
|
947
|
+
*
|
|
948
|
+
* @param path - The path to create the directory at.
|
|
949
|
+
* @param options - Options for creating the directory.
|
|
950
|
+
* @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
|
|
951
|
+
*/
|
|
952
|
+
async mkdir(path2, options = {}) {
|
|
953
|
+
let result;
|
|
954
|
+
const filePath = toFilePath(path2);
|
|
955
|
+
if (isFunction.isFunction(this.resolveFS(filePath, options).promises.mkdir)) {
|
|
956
|
+
result = await this.resolveFS(filePath, options).promises.mkdir(filePath, defu4__default.default(options ?? {}, {
|
|
957
|
+
recursive: true
|
|
958
|
+
}));
|
|
959
|
+
} else {
|
|
960
|
+
result = this.resolveFS(filePath, options).mkdirSync(filePath, defu4__default.default(options ?? {}, {
|
|
961
|
+
recursive: true
|
|
962
|
+
}));
|
|
963
|
+
}
|
|
964
|
+
this.clearResolverCache(filePath);
|
|
965
|
+
return result;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Lists files in a given path.
|
|
969
|
+
*
|
|
970
|
+
* @param path - The path to list files from.
|
|
971
|
+
* @param options - Options for listing files, such as encoding and recursion.
|
|
972
|
+
* @returns An array of file names in the specified path.
|
|
973
|
+
*/
|
|
974
|
+
async readdir(path2, options = "utf8") {
|
|
975
|
+
return this.resolveFS(path2).promises.readdir(toFilePath(path2), options);
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Asynchronously reads a file from the virtual file system (VFS).
|
|
979
|
+
*
|
|
980
|
+
* @param pathOrId - The path or ID of the file to read.
|
|
981
|
+
* @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
|
|
982
|
+
*/
|
|
983
|
+
async readFile(pathOrId, options = "utf8") {
|
|
984
|
+
if (!pathOrId) {
|
|
985
|
+
return void 0;
|
|
986
|
+
}
|
|
987
|
+
const filePath = this.resolvePath(toFilePath(pathOrId), {
|
|
988
|
+
type: "file"
|
|
989
|
+
});
|
|
990
|
+
if (filePath) {
|
|
991
|
+
if (this.#cachedFS.has(filePath)) {
|
|
992
|
+
return this.#cachedFS.get(filePath);
|
|
993
|
+
}
|
|
994
|
+
let result;
|
|
995
|
+
if (isFunction.isFunction(this.resolveFS(filePath).promises.readFile)) {
|
|
996
|
+
result = (await this.resolveFS(filePath).promises.readFile(filePath, options))?.toString("utf8");
|
|
997
|
+
} else {
|
|
998
|
+
result = this.resolveFS(filePath).readFileSync(filePath, options);
|
|
999
|
+
}
|
|
1000
|
+
const content = isBuffer.isBuffer(result) ? bufferToString.bufferToString(result) : result;
|
|
1001
|
+
this.#cachedFS.set(filePath, content);
|
|
1002
|
+
return content;
|
|
1003
|
+
}
|
|
1004
|
+
return void 0;
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Synchronously reads a file from the virtual file system (VFS).
|
|
1008
|
+
*
|
|
1009
|
+
* @param pathOrId - The path or ID of the file to read.
|
|
1010
|
+
* @returns The contents of the file as a string, or undefined if the file does not exist.
|
|
1011
|
+
*/
|
|
1012
|
+
readFileSync(pathOrId, options = "utf8") {
|
|
1013
|
+
if (!pathOrId) {
|
|
1014
|
+
return void 0;
|
|
1015
|
+
}
|
|
1016
|
+
const filePath = this.resolvePath(toFilePath(pathOrId), {
|
|
1017
|
+
type: "file"
|
|
1018
|
+
});
|
|
1019
|
+
if (filePath) {
|
|
1020
|
+
if (this.#cachedFS.has(filePath)) {
|
|
1021
|
+
return this.#cachedFS.get(filePath);
|
|
1022
|
+
}
|
|
1023
|
+
const result = this.resolveFS(filePath).readFileSync(filePath, options);
|
|
1024
|
+
const content = isBuffer.isBuffer(result) ? bufferToString.bufferToString(result) : result;
|
|
1025
|
+
this.#cachedFS.set(filePath, content);
|
|
1026
|
+
return content;
|
|
1027
|
+
}
|
|
1028
|
+
return void 0;
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Writes a file to the virtual file system (VFS).
|
|
1032
|
+
*
|
|
1033
|
+
* @param file - The path to the file.
|
|
1034
|
+
* @param data - The contents of the file.
|
|
1035
|
+
* @param options - Optional parameters for writing the file.
|
|
1036
|
+
* @returns A promise that resolves when the file is written.
|
|
1037
|
+
*/
|
|
1038
|
+
async writeFile(file, data = "", options = "utf8") {
|
|
1039
|
+
const absolutePath = this.formatAbsoluteFilePath(toFilePath(file));
|
|
1040
|
+
if (!this.directoryExistsSync(filePathFns.findFilePath(absolutePath))) {
|
|
1041
|
+
await this.mkdir(filePathFns.findFilePath(absolutePath), options);
|
|
1042
|
+
}
|
|
1043
|
+
this.#log(types.LogLevelLabel.TRACE, `Writing ${absolutePath} file to the ${this.resolveOutputMode(absolutePath, options) === "fs" ? "" : "virtual "}file system (size: ${prettyBytes.prettyBytes(new buffer.Blob(toArray.toArray(data)).size)})`);
|
|
1044
|
+
this.#cachedFS.set(absolutePath, data.toString());
|
|
1045
|
+
this.clearResolverCache(absolutePath);
|
|
1046
|
+
const ifs = this.resolveFS(absolutePath, options);
|
|
1047
|
+
if (isFunction.isFunction(ifs.promises.writeFile)) {
|
|
1048
|
+
return ifs.promises.writeFile(absolutePath, data, omit.omit(options, [
|
|
1049
|
+
"mode"
|
|
1050
|
+
]));
|
|
1051
|
+
}
|
|
1052
|
+
return ifs.writeFileSync(absolutePath, data, omit.omit(options, [
|
|
1053
|
+
"mode"
|
|
1054
|
+
]));
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Synchronously writes a file to the virtual file system (VFS).
|
|
1058
|
+
*
|
|
1059
|
+
* @param file - The file to write.
|
|
1060
|
+
* @param data - The contents of the file.
|
|
1061
|
+
* @param options - Optional parameters for writing the file.
|
|
1062
|
+
*/
|
|
1063
|
+
writeFileSync(file, data = "", options = "utf8") {
|
|
1064
|
+
const absolutePath = this.formatAbsoluteFilePath(toFilePath(file));
|
|
1065
|
+
if (!this.directoryExistsSync(filePathFns.findFilePath(absolutePath))) {
|
|
1066
|
+
this.mkdirSync(filePathFns.findFilePath(absolutePath));
|
|
1067
|
+
}
|
|
1068
|
+
this.#log(types.LogLevelLabel.TRACE, `Writing ${absolutePath} file to the ${this.resolveOutputMode(absolutePath, options) === "fs" ? "" : "virtual "} (size: ${prettyBytes.prettyBytes(new buffer.Blob(toArray.toArray(data)).size)})`);
|
|
1069
|
+
this.#cachedFS.set(absolutePath, data.toString());
|
|
1070
|
+
this.clearResolverCache(absolutePath);
|
|
1071
|
+
const writeStream = this.resolveFS(absolutePath, omit.omit(options, [
|
|
1072
|
+
"mode"
|
|
1073
|
+
])).createWriteStream(absolutePath);
|
|
1074
|
+
try {
|
|
1075
|
+
writeStream.write(data);
|
|
1076
|
+
} finally {
|
|
1077
|
+
writeStream.close();
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Writes a runtime file to the virtual file system (VFS).
|
|
1082
|
+
*
|
|
1083
|
+
* @param id - The unique identifier for the runtime file.
|
|
1084
|
+
* @param path - The path to the runtime file.
|
|
1085
|
+
* @param contents - The contents of the runtime file.
|
|
1086
|
+
* @param options - Optional parameters for writing the runtime file.
|
|
1087
|
+
* @returns A promise that resolves when the file is written.
|
|
1088
|
+
*/
|
|
1089
|
+
async writeBuiltinFile(id, path2, contents, options = {}) {
|
|
1090
|
+
const formattedId = this.formatRuntimeId(id);
|
|
1091
|
+
const absolutePath = this.formatAbsoluteFilePath(toFilePath(path2));
|
|
1092
|
+
this.builtinIdMap.set(formattedId, absolutePath);
|
|
1093
|
+
let data = contents;
|
|
1094
|
+
if (!options.skipFormat) {
|
|
1095
|
+
data = await prettier.format(contents, {
|
|
1096
|
+
absolutePath,
|
|
1097
|
+
...await prettier.resolveConfig(absolutePath)
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
const _options = defu4__default.default(isSetString.isSetString(options) ? {} : options ?? {}, {
|
|
1101
|
+
encoding: isSetString.isSetString(options) ? options : "utf8",
|
|
1102
|
+
mode: "virtual"
|
|
1103
|
+
});
|
|
1104
|
+
this.#log(types.LogLevelLabel.DEBUG, `Writing runtime file ${absolutePath} (size: ${prettyBytes.prettyBytes(new buffer.Blob(toArray.toArray(data)).size)}) to ${this.resolveOutputMode(absolutePath, _options) === "fs" ? "disk" : "memory"}`);
|
|
1105
|
+
return this.writeFile(absolutePath, data, _options);
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Adds an entry file to the virtual file system.
|
|
1109
|
+
*
|
|
1110
|
+
* @param name - The file name or absolute path of the entry module.
|
|
1111
|
+
* @param contents - The contents of the entry file.
|
|
1112
|
+
* @param options - Optional parameters for writing the entry file.
|
|
1113
|
+
*/
|
|
1114
|
+
async writeEntryFile(name, contents, options = {}) {
|
|
1115
|
+
const absolutePath = this.formatAbsoluteFilePath(isType.isAbsolutePath(toFilePath(name)) ? toFilePath(name) : toFilePath(joinPaths.joinPaths(this.#context.entryPath, name)));
|
|
1116
|
+
let data = contents;
|
|
1117
|
+
if (!options.skipFormat) {
|
|
1118
|
+
data = await prettier.format(contents, {
|
|
1119
|
+
absolutePath,
|
|
1120
|
+
...await prettier.resolveConfig(absolutePath)
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
const _options = defu4__default.default(isSetString.isSetString(options) ? {} : options ?? {}, {
|
|
1124
|
+
encoding: isSetString.isSetString(options) ? options : "utf8",
|
|
1125
|
+
mode: "virtual"
|
|
1126
|
+
});
|
|
1127
|
+
this.#log(types.LogLevelLabel.DEBUG, `Writing entry file ${absolutePath} (size: ${prettyBytes.prettyBytes(new buffer.Blob(toArray.toArray(data)).size)}) to ${this.resolveOutputMode(absolutePath, _options) === "fs" ? "disk" : "virtual memory"}`);
|
|
1128
|
+
return this.writeFile(absolutePath, data, _options);
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* Writes a file to disk from the physical file system (on disk).
|
|
1132
|
+
*
|
|
1133
|
+
* @param path - The path to the file to write.
|
|
1134
|
+
* @param contents - The contents of the file to write.
|
|
1135
|
+
* @param options - Optional parameters for writing the file.
|
|
1136
|
+
* @returns A promise that resolves when the file is written.
|
|
1137
|
+
*/
|
|
1138
|
+
async writeFileToDisk(path2, contents, options = {}) {
|
|
1139
|
+
const absolutePath = this.formatAbsoluteFilePath(toFilePath(path2));
|
|
1140
|
+
let data = contents;
|
|
1141
|
+
if (!options.skipFormat) {
|
|
1142
|
+
const resolvedConfig = await prettier.resolveConfig(absolutePath);
|
|
1143
|
+
if (resolvedConfig) {
|
|
1144
|
+
data = await prettier.format(contents, {
|
|
1145
|
+
absolutePath,
|
|
1146
|
+
...resolvedConfig
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
return this.writeFile(absolutePath, data, defu4__default.default({
|
|
1151
|
+
mode: "fs"
|
|
1152
|
+
}, isSetString.isSetString(options) ? {} : options ?? {}, {
|
|
1153
|
+
encoding: isSetString.isSetString(options) ? options : "utf8"
|
|
1154
|
+
}));
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Synchronously checks if a file exists in the virtual file system (VFS).
|
|
1158
|
+
*
|
|
1159
|
+
* @param pathOrId - The path or ID of the file to check.
|
|
1160
|
+
* @returns `true` if the file exists, otherwise `false`.
|
|
1161
|
+
*/
|
|
1162
|
+
existsSync(pathOrId) {
|
|
1163
|
+
return this.pathExistsSync(this.resolvePath(toFilePath(pathOrId)) || toFilePath(pathOrId));
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Checks if a file exists in the virtual file system (VFS).
|
|
1167
|
+
*
|
|
1168
|
+
* @remarks
|
|
1169
|
+
* 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.
|
|
1170
|
+
*
|
|
1171
|
+
* @param path - The path of the file to check.
|
|
1172
|
+
* @returns `true` if the file exists, otherwise `false`.
|
|
1173
|
+
*/
|
|
1174
|
+
fileExistsSync(path2) {
|
|
1175
|
+
const formattedPath = this.formatAbsoluteFilePath(toFilePath(path2));
|
|
1176
|
+
return this.isValidBuiltinId(formattedPath) || this.#virtualFS.existsSync(formattedPath) && this.#virtualFS.lstatSync(formattedPath).isFile() || this.#fs.existsSync(formattedPath) && this.#fs.lstatSync(formattedPath).isFile() || this.resolveFS(path2).existsSync(formattedPath) && this.resolveFS(path2).lstatSync(formattedPath).isFile();
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Checks if a directory exists in the virtual file system (VFS).
|
|
1180
|
+
*
|
|
1181
|
+
* @param path - The path of the directory to check.
|
|
1182
|
+
* @returns `true` if the directory exists, otherwise `false`.
|
|
1183
|
+
*/
|
|
1184
|
+
directoryExistsSync(path2) {
|
|
1185
|
+
const formattedPath = this.formatAbsoluteFilePath(toFilePath(path2));
|
|
1186
|
+
return this.#virtualFS.existsSync(formattedPath) && this.#virtualFS.lstatSync(formattedPath).isDirectory() || this.#fs.existsSync(formattedPath) && this.#fs.lstatSync(formattedPath).isDirectory() || this.resolveFS(path2).existsSync(formattedPath) && this.resolveFS(path2).lstatSync(formattedPath).isDirectory();
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Checks if a path exists in the virtual file system (VFS).
|
|
1190
|
+
*
|
|
1191
|
+
* @param path - The path to check.
|
|
1192
|
+
* @returns `true` if the path exists, otherwise `false`.
|
|
1193
|
+
*/
|
|
1194
|
+
pathExistsSync(path2) {
|
|
1195
|
+
const formattedPath = this.formatAbsoluteFilePath(toFilePath(path2));
|
|
1196
|
+
return this.isValidBuiltinId(formattedPath) || this.#virtualFS.existsSync(formattedPath) || this.#fs.existsSync(formattedPath) || this.resolveFS(path2).existsSync(formattedPath);
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Retrieves the status of a file in the virtual file system (VFS).
|
|
1200
|
+
*
|
|
1201
|
+
* @param pathOrId - The path or ID of the file to retrieve status for.
|
|
1202
|
+
* @returns A promise that resolves to the file's status information, or false if the file does not exist.
|
|
1203
|
+
*/
|
|
1204
|
+
async stat(pathOrId, options) {
|
|
1205
|
+
return this.resolveFS(pathOrId).promises.stat(this.resolvePath(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Synchronously retrieves the status of a file in the virtual file system (VFS).
|
|
1209
|
+
*
|
|
1210
|
+
* @param pathOrId - The path or ID of the file to retrieve status for.
|
|
1211
|
+
* @returns The file's status information, or false if the file does not exist.
|
|
1212
|
+
*/
|
|
1213
|
+
statSync(pathOrId) {
|
|
1214
|
+
return this.resolveFS(pathOrId).statSync(this.resolvePath(toFilePath(pathOrId)) || toFilePath(pathOrId));
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Retrieves the status of a symbolic link in the virtual file system (VFS).
|
|
1218
|
+
*
|
|
1219
|
+
* @param pathOrId - The path or ID of the symbolic link to retrieve status for.
|
|
1220
|
+
* @returns A promise that resolves to the symbolic link's status information, or false if the link does not exist.
|
|
1221
|
+
*/
|
|
1222
|
+
async lstat(pathOrId, options) {
|
|
1223
|
+
return this.resolveFS(pathOrId).promises.lstat(this.resolvePath(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Synchronously retrieves the status of a symbolic link in the virtual file system (VFS).
|
|
1227
|
+
*
|
|
1228
|
+
* @param pathOrId - The path or ID of the symbolic link to retrieve status for.
|
|
1229
|
+
* @returns The symbolic link's status information, or false if the link does not exist.
|
|
1230
|
+
*/
|
|
1231
|
+
lstatSync(pathOrId, options) {
|
|
1232
|
+
return this.resolveFS(pathOrId).lstatSync(this.resolvePath(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Resolves a path or ID to a runtime file id in the virtual file system.
|
|
1236
|
+
*
|
|
1237
|
+
* @param pathOrId - The path or id of the file to resolve.
|
|
1238
|
+
* @returns The resolved id of the runtime file if it exists, otherwise false.
|
|
1239
|
+
*/
|
|
1240
|
+
resolveId(pathOrId) {
|
|
1241
|
+
if (this.builtinIdMap.has(this.formatRuntimeId(toFilePath(pathOrId)))) {
|
|
1242
|
+
return this.formatRuntimeId(toFilePath(pathOrId));
|
|
1243
|
+
}
|
|
1244
|
+
const filePath = this.resolvePath(toFilePath(pathOrId));
|
|
1245
|
+
if (filePath) {
|
|
1246
|
+
return this.builtinIdMap.keys().find((id) => this.builtinIdMap.get(id) === filePath) || false;
|
|
1247
|
+
}
|
|
1248
|
+
return false;
|
|
1249
|
+
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Resolves a path based on TypeScript's `tsconfig.json` paths.
|
|
1252
|
+
*
|
|
1253
|
+
* @see https://www.typescriptlang.org/tsconfig#paths
|
|
1254
|
+
*
|
|
1255
|
+
* @param path - The path to check.
|
|
1256
|
+
* @returns The resolved file path if it exists, otherwise undefined.
|
|
1257
|
+
*/
|
|
1258
|
+
resolveTsconfigPath(path2) {
|
|
1259
|
+
if (this.#context.tsconfig.options.paths) {
|
|
1260
|
+
for (const tsconfigPathKey of Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path2.startsWith(tsconfigPath.replaceAll("*", "")))) {
|
|
1261
|
+
const resolvedPath = this.#context.tsconfig.options.paths[tsconfigPathKey]?.find((tsconfigPath) => this.resolvePathName(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, tsconfigPath.replaceAll("*", ""), path2.replace(tsconfigPathKey.replaceAll("*", ""), ""))) || this.formatAbsoluteFilePath(tsconfigPath) === this.formatAbsoluteFilePath(path2));
|
|
1262
|
+
if (resolvedPath) {
|
|
1263
|
+
return this.formatAbsoluteFilePath(resolvedPath) === this.formatAbsoluteFilePath(path2) ? this.formatAbsoluteFilePath(resolvedPath) : this.resolvePathName(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, resolvedPath.replaceAll("*", ""), path2.replace(tsconfigPathKey.replaceAll("*", ""), "")));
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
return false;
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Resolves a path based on TypeScript's `tsconfig.json` paths.
|
|
1271
|
+
*
|
|
1272
|
+
* @see https://www.typescriptlang.org/tsconfig#paths
|
|
1273
|
+
*
|
|
1274
|
+
* @param path - The path to check.
|
|
1275
|
+
* @returns The resolved file path if it exists, otherwise undefined.
|
|
1276
|
+
*/
|
|
1277
|
+
resolveTsconfigPathPackage(path2) {
|
|
1278
|
+
if (this.#context.tsconfig.options.paths) {
|
|
1279
|
+
const tsconfigPathKeys = Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path2.startsWith(tsconfigPath.replaceAll("*", "")));
|
|
1280
|
+
if (tsconfigPathKeys.length > 0 && tsconfigPathKeys[0]) {
|
|
1281
|
+
return tsconfigPathKeys[0].replace(/\/\*$/, "");
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
return false;
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Resolves a path or ID to its real path in the virtual file system (VFS).
|
|
1288
|
+
*
|
|
1289
|
+
* @param pathOrId - The path or ID to resolve.
|
|
1290
|
+
* @returns The resolved real path if it exists, otherwise undefined.
|
|
1291
|
+
*/
|
|
1292
|
+
realpathSync(pathOrId) {
|
|
1293
|
+
const filePath = this.resolvePath(toFilePath(pathOrId));
|
|
1294
|
+
if (!filePath) {
|
|
1295
|
+
throw new Error(`File not found: ${toFilePath(pathOrId)}`);
|
|
1296
|
+
}
|
|
1297
|
+
return filePath;
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Resolves a path or ID parameter to a corresponding virtual file path in the virtual file system (VFS).
|
|
1301
|
+
*
|
|
1302
|
+
* @param pathOrId - The path or ID to resolve.
|
|
1303
|
+
* @param options - Optional parameters for resolving the path, such as whether to include the file extension.
|
|
1304
|
+
* @returns The resolved file path if it exists, otherwise undefined.
|
|
1305
|
+
*/
|
|
1306
|
+
resolvePath(pathOrId, options = {}) {
|
|
1307
|
+
const formattedPath = toFilePath(pathOrId);
|
|
1308
|
+
const resolverKey = `${formattedPath}${options.withExtension ? "-ext" : ""}${options.paths ? `-${murmurhash.murmurhash(options.paths)}` : ""}${options.type ? `-${options.type}` : ""}`;
|
|
1309
|
+
if (this.#cachedResolver.has(resolverKey)) {
|
|
1310
|
+
return this.#cachedResolver.get(resolverKey);
|
|
1311
|
+
} else if (this.#cachedFS.has(formattedPath)) {
|
|
1312
|
+
return formattedPath;
|
|
1313
|
+
}
|
|
1314
|
+
let result = false;
|
|
1315
|
+
if (this.isValidBuiltinId(formattedPath)) {
|
|
1316
|
+
result = this.builtinIdMap.get(this.formatRuntimeId(formattedPath));
|
|
1317
|
+
} else {
|
|
1318
|
+
result = this.resolvePathName(formattedPath, options);
|
|
1319
|
+
}
|
|
1320
|
+
if (!result) {
|
|
1321
|
+
result = false;
|
|
1322
|
+
} else {
|
|
1323
|
+
result = toFilePath(result);
|
|
1324
|
+
}
|
|
1325
|
+
if (result && options.withExtension === false) {
|
|
1326
|
+
return result.replace(/\.[m|c]?[t|j]sx?$/, "");
|
|
1327
|
+
}
|
|
1328
|
+
this.#cachedResolver.set(resolverKey, result);
|
|
1329
|
+
return result;
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Formats a file path by removing the runtime prefix and leading null character.
|
|
1333
|
+
*
|
|
1334
|
+
* @param path - The file path to format.
|
|
1335
|
+
* @returns The formatted file path.
|
|
1336
|
+
*/
|
|
1337
|
+
formatFilePath(path2) {
|
|
1338
|
+
if (!isSetString.isSetString(path2)) {
|
|
1339
|
+
throw new Error(`Invalid path provided. Expected a string or a valid file path.`);
|
|
1340
|
+
}
|
|
1341
|
+
return path2.replace(new RegExp(`^${this.#context.config.builtinPrefix}:`), "").replace(/^\\0/, "");
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Converts a relative path to an absolute path based on the workspace and project root.
|
|
1345
|
+
*
|
|
1346
|
+
* @param path - The relative path to convert.
|
|
1347
|
+
* @returns The absolute path.
|
|
1348
|
+
*/
|
|
1349
|
+
formatAbsoluteFilePath = /* @__PURE__ */ chunkSHUYVCID_js.__name((path2) => {
|
|
1350
|
+
const formattedPath = this.formatFilePath(path2);
|
|
1351
|
+
if (isType.isAbsolutePath(formattedPath) || formattedPath.startsWith(this.#context.workspaceConfig.workspaceRoot)) {
|
|
1352
|
+
return formattedPath;
|
|
1353
|
+
} else if (formattedPath.startsWith(this.#context.config.projectRoot)) {
|
|
1354
|
+
return joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, formattedPath);
|
|
1355
|
+
}
|
|
1356
|
+
return formattedPath;
|
|
1357
|
+
}, "formatAbsoluteFilePath");
|
|
1358
|
+
/**
|
|
1359
|
+
* Formats a runtime ID by removing the file extension and prepending the runtime prefix.
|
|
1360
|
+
*
|
|
1361
|
+
* @param id - The runtime ID to format.
|
|
1362
|
+
* @returns The formatted runtime ID.
|
|
1363
|
+
*/
|
|
1364
|
+
formatRuntimeId(id) {
|
|
1365
|
+
return `${this.#context.config.builtinPrefix}:${this.formatFilePath(id).replace(/\.[m|c]?[t|j]sx?$/, "")}`;
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Resolves a path or ID parameter to a corresponding virtual file path in the virtual file system (VFS).
|
|
1369
|
+
*
|
|
1370
|
+
* @param pathOrId - The path or ID to resolve.
|
|
1371
|
+
* @returns The resolved file path if it exists, otherwise undefined.
|
|
1372
|
+
*/
|
|
1373
|
+
resolvePathName(pathOrId, options = {}) {
|
|
1374
|
+
if (pathOrId.startsWith(`${this.#context.config.builtinPrefix}:`)) {
|
|
1375
|
+
return false;
|
|
1376
|
+
}
|
|
1377
|
+
if (isType.isAbsolutePath(pathOrId)) {
|
|
1378
|
+
if (options.type === "file" ? this.fileExistsSync(pathOrId) : this.pathExistsSync(pathOrId)) {
|
|
1379
|
+
return pathOrId;
|
|
1380
|
+
}
|
|
1381
|
+
const result = checkVariants(pathOrId, this);
|
|
1382
|
+
if (result) {
|
|
1383
|
+
return result;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
for (const path2 of this.resolveParentPaths(pathOrId, options.paths)) {
|
|
1387
|
+
const request = joinPaths.joinPaths(path2, pathOrId);
|
|
1388
|
+
if (options.type === "file" ? this.fileExistsSync(pathOrId) : this.pathExistsSync(pathOrId)) {
|
|
1389
|
+
return request;
|
|
1390
|
+
}
|
|
1391
|
+
const result = checkVariants(request, this);
|
|
1392
|
+
if (result) {
|
|
1393
|
+
return result;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
return false;
|
|
1397
|
+
}
|
|
1398
|
+
resolveParentPaths(request, current = []) {
|
|
1399
|
+
let paths = [
|
|
1400
|
+
this.#context.workspaceConfig.workspaceRoot,
|
|
1401
|
+
joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot)
|
|
1402
|
+
];
|
|
1403
|
+
if (this.#context.tsconfig.options.paths) {
|
|
1404
|
+
paths = this.#context.tsconfig.options.paths ? Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => request.startsWith(tsconfigPath.replaceAll("*", ""))).map((tsconfigPath) => this.#context.tsconfig.options.paths?.[tsconfigPath]).flat().reduce((ret, path2) => {
|
|
1405
|
+
if (path2 && !ret.includes(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, path2))) {
|
|
1406
|
+
ret.push(joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, path2));
|
|
1407
|
+
}
|
|
1408
|
+
return ret;
|
|
1409
|
+
}, paths) : paths;
|
|
1410
|
+
}
|
|
1411
|
+
return paths.reduce((ret, path2) => {
|
|
1412
|
+
if (!ret.includes(path2)) {
|
|
1413
|
+
ret.push(path2);
|
|
1414
|
+
}
|
|
1415
|
+
return ret;
|
|
1416
|
+
}, current.filter(Boolean).map((p) => this.formatAbsoluteFilePath(toFilePath(p))));
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Select the file system module to use for the operation based on the path or URL.
|
|
1420
|
+
*
|
|
1421
|
+
* @param pathOrUrl - The path to perform the file system operation on.
|
|
1422
|
+
* @param options - Options for the operation, such as output mode.
|
|
1423
|
+
* @returns The file system module used for the operation.
|
|
1424
|
+
*/
|
|
1425
|
+
resolveFS(pathOrUrl, options = {}) {
|
|
1426
|
+
const mode = this.resolveOutputMode(pathOrUrl, options);
|
|
1427
|
+
if (mode === "virtual") {
|
|
1428
|
+
return this.#virtualFS;
|
|
1429
|
+
} else if (mode === "fs") {
|
|
1430
|
+
return this.#fs;
|
|
1431
|
+
}
|
|
1432
|
+
return this.#unifiedFS;
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Select the file system module to use for the operation based on the path or URL.
|
|
1436
|
+
*
|
|
1437
|
+
* @param pathOrUrl - The path to perform the file system operation on.
|
|
1438
|
+
* @param options - Options for the operation, such as output mode.
|
|
1439
|
+
* @returns The file system module used for the operation.
|
|
1440
|
+
*/
|
|
1441
|
+
resolveOutputMode(pathOrUrl, options = {}) {
|
|
1442
|
+
if (options.mode === "virtual" && this.#context.config.output.mode !== "fs" && isParentPath.isParentPath(toFilePath(pathOrUrl), this.#context.artifactsPath)) {
|
|
1443
|
+
return "virtual";
|
|
1444
|
+
} else if (options.mode === "fs" || this.#context.config.output.mode === "fs" || isParentPath.isParentPath(toFilePath(pathOrUrl), this.#context.dataPath) || isParentPath.isParentPath(toFilePath(pathOrUrl), this.#context.cachePath) || isParentPath.isParentPath(toFilePath(pathOrUrl), joinPaths.joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
|
|
1445
|
+
return "fs";
|
|
1446
|
+
}
|
|
1447
|
+
return null;
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Clears the resolver cache for a given path.
|
|
1451
|
+
*
|
|
1452
|
+
* @param path - The path to clear the resolver cache for.
|
|
1453
|
+
*/
|
|
1454
|
+
clearResolverCache(path2) {
|
|
1455
|
+
this.#cachedResolver.keys().filter((key) => key.startsWith(toFilePath(path2))).forEach((key) => this.#cachedResolver.delete(key));
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
var FILE_PREFIX = "file://";
|
|
1459
|
+
function toFilePath(pathOrUrl) {
|
|
1460
|
+
if (!pathOrUrl) {
|
|
1461
|
+
throw new Error("No Path or URL provided to Virtual File System");
|
|
1462
|
+
}
|
|
1463
|
+
let result = pathOrUrl.toString();
|
|
1464
|
+
if (result.startsWith(FILE_PREFIX)) {
|
|
1465
|
+
result = result.slice(FILE_PREFIX.length);
|
|
1466
|
+
}
|
|
1467
|
+
return result;
|
|
1468
|
+
}
|
|
1469
|
+
chunkSHUYVCID_js.__name(toFilePath, "toFilePath");
|
|
1470
|
+
var FS_METHODS = [
|
|
1471
|
+
"mkdir",
|
|
1472
|
+
"mkdirSync",
|
|
1473
|
+
"rmdir",
|
|
1474
|
+
"rmdirSync",
|
|
1475
|
+
"unlink",
|
|
1476
|
+
"unlinkSync",
|
|
1477
|
+
"existsSync",
|
|
1478
|
+
"realpathSync",
|
|
1479
|
+
"writeFileSync",
|
|
1480
|
+
"readFileSync",
|
|
1481
|
+
"readdirSync",
|
|
1482
|
+
"createWriteStream",
|
|
1483
|
+
"WriteStream",
|
|
1484
|
+
"createReadStream",
|
|
1485
|
+
"ReadStream"
|
|
1486
|
+
];
|
|
1487
|
+
var FS_PROMISE_METHODS = [
|
|
1488
|
+
"mkdir",
|
|
1489
|
+
"rm",
|
|
1490
|
+
"rmdir",
|
|
1491
|
+
"unlink",
|
|
1492
|
+
"writeFile",
|
|
1493
|
+
"readFile",
|
|
1494
|
+
"readdir",
|
|
1495
|
+
"stat",
|
|
1496
|
+
"lstat"
|
|
1497
|
+
];
|
|
1498
|
+
function cloneFS(originalFS) {
|
|
1499
|
+
const clonedFS = {
|
|
1500
|
+
...originalFS,
|
|
1501
|
+
promises: {
|
|
1502
|
+
...originalFS.promises ?? {}
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
for (const method of FS_METHODS) {
|
|
1506
|
+
if (originalFS[method]) {
|
|
1507
|
+
clonedFS[method] = originalFS[method];
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
originalFS.promises ??= {};
|
|
1511
|
+
for (const method of FS_PROMISE_METHODS) {
|
|
1512
|
+
if (originalFS.promises[method]) {
|
|
1513
|
+
clonedFS.promises ??= {};
|
|
1514
|
+
clonedFS.promises[method] = originalFS.promises[method];
|
|
1515
|
+
clonedFS[method] = originalFS.promises[method];
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
for (const prop in clonedFS) {
|
|
1519
|
+
if (isFunction.isFunction(clonedFS[prop])) {
|
|
1520
|
+
clonedFS[prop] = clonedFS[prop].bind(originalFS);
|
|
1521
|
+
if (isFunction.isFunction(clonedFS.promises[prop])) {
|
|
1522
|
+
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
for (const prop in clonedFS.promises) {
|
|
1527
|
+
if (isFunction.isFunction(clonedFS.promises[prop])) {
|
|
1528
|
+
clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
return clonedFS;
|
|
1532
|
+
}
|
|
1533
|
+
chunkSHUYVCID_js.__name(cloneFS, "cloneFS");
|
|
1534
|
+
function patchFS(originalFS, vfs) {
|
|
1535
|
+
const clonedFS = cloneFS(originalFS);
|
|
1536
|
+
originalFS.mkdirSync = (file, options) => vfs.mkdirSync(toFilePath(file), options);
|
|
1537
|
+
originalFS.mkdir = (file, options, callback) => vfs.mkdir(toFilePath(file), options, callback);
|
|
1538
|
+
originalFS.promises.mkdir = async (file, options) => vfs.mkdir(toFilePath(file), options);
|
|
1539
|
+
originalFS.unlinkSync = (file) => vfs.unlinkSync(toFilePath(file));
|
|
1540
|
+
originalFS.promises.rm = async (file, options) => vfs.rm(toFilePath(file), options);
|
|
1541
|
+
originalFS.promises.unlink = async (file) => vfs.unlink(toFilePath(file));
|
|
1542
|
+
originalFS.existsSync = (file) => vfs.existsSync(toFilePath(file));
|
|
1543
|
+
Object.defineProperty(originalFS, "realpathSync", {
|
|
1544
|
+
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.realpathSync(toFilePath(file), options), "value")
|
|
1545
|
+
});
|
|
1546
|
+
originalFS.writeFileSync = (file, data, options) => vfs.writeFileSync(toFilePath(file), data, options);
|
|
1547
|
+
originalFS.promises.writeFile = async (file, data, options) => vfs.writeFile(toFilePath(file), data, options);
|
|
1548
|
+
originalFS.readFileSync = (file, options) => vfs.readFileSync(toFilePath(file), options);
|
|
1549
|
+
originalFS.promises.readFile = (file, options) => vfs.readFile(toFilePath(file), options);
|
|
1550
|
+
originalFS.readdirSync = (file, options) => vfs.readdirSync(toFilePath(file), options);
|
|
1551
|
+
originalFS.promises.readdir = (file, options) => vfs.readdir(toFilePath(file), options);
|
|
1552
|
+
Object.defineProperty(originalFS, "statSync", {
|
|
1553
|
+
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.statSync(toFilePath(file), options), "value")
|
|
1554
|
+
});
|
|
1555
|
+
originalFS.stat = (file, options) => vfs.statSync(toFilePath(file), options);
|
|
1556
|
+
originalFS.promises.stat = (file, options) => vfs.stat(toFilePath(file), options);
|
|
1557
|
+
Object.defineProperty(originalFS, "lstatSync", {
|
|
1558
|
+
value: /* @__PURE__ */ chunkSHUYVCID_js.__name((file, options) => vfs.lstatSync(toFilePath(file), options), "value")
|
|
1559
|
+
});
|
|
1560
|
+
originalFS.lstat = (file, options) => vfs.lstatSync(toFilePath(file), options);
|
|
1561
|
+
originalFS.promises.lstat = (file, options) => vfs.lstat(toFilePath(file), options);
|
|
1562
|
+
return () => {
|
|
1563
|
+
originalFS.mkdirSync = clonedFS.mkdirSync;
|
|
1564
|
+
originalFS.mkdir = clonedFS.mkdir;
|
|
1565
|
+
originalFS.promises.mkdir = clonedFS.promises.mkdir;
|
|
1566
|
+
originalFS.unlinkSync = clonedFS.unlinkSync;
|
|
1567
|
+
originalFS.promises.rm = clonedFS.promises.rm;
|
|
1568
|
+
originalFS.promises.unlink = clonedFS.promises.unlink;
|
|
1569
|
+
originalFS.existsSync = clonedFS.existsSync;
|
|
1570
|
+
originalFS.realpathSync = clonedFS.realpathSync;
|
|
1571
|
+
originalFS.writeFileSync = clonedFS.writeFileSync;
|
|
1572
|
+
originalFS.promises.writeFile = clonedFS.promises.writeFile;
|
|
1573
|
+
originalFS.readFileSync = clonedFS.readFileSync;
|
|
1574
|
+
originalFS.promises.readFile = clonedFS.promises.readFile;
|
|
1575
|
+
originalFS.readdirSync = clonedFS.readdirSync;
|
|
1576
|
+
originalFS.promises.readdir = clonedFS.promises.readdir;
|
|
1577
|
+
Object.defineProperty(originalFS, "statSync", {
|
|
1578
|
+
value: clonedFS.statSync
|
|
1579
|
+
});
|
|
1580
|
+
originalFS.stat = clonedFS.stat;
|
|
1581
|
+
originalFS.promises.stat = clonedFS.promises.stat;
|
|
1582
|
+
Object.defineProperty(originalFS, "lstatSync", {
|
|
1583
|
+
value: clonedFS.lstatSync
|
|
1584
|
+
});
|
|
1585
|
+
originalFS.lstat = clonedFS.lstat;
|
|
1586
|
+
originalFS.promises.lstat = clonedFS.promises.lstat;
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
chunkSHUYVCID_js.__name(patchFS, "patchFS");
|
|
1590
|
+
function checkVariants(request, vfs, parentPath) {
|
|
1591
|
+
const path2 = parentPath ? joinPaths.joinPaths(parentPath, request) : request;
|
|
1592
|
+
let file = checkExtensions(path2, vfs);
|
|
1593
|
+
if (file) {
|
|
1594
|
+
return file;
|
|
1595
|
+
}
|
|
1596
|
+
file = checkIndex(path2, vfs);
|
|
1597
|
+
if (file) {
|
|
1598
|
+
return file;
|
|
1599
|
+
}
|
|
1600
|
+
return false;
|
|
1601
|
+
}
|
|
1602
|
+
chunkSHUYVCID_js.__name(checkVariants, "checkVariants");
|
|
1603
|
+
function checkIndex(request, vfs) {
|
|
1604
|
+
let file = joinPaths.joinPaths(request, "index");
|
|
1605
|
+
if (vfs.fileExistsSync(file)) {
|
|
1606
|
+
return file;
|
|
1607
|
+
}
|
|
1608
|
+
file = checkExtensions(file, vfs);
|
|
1609
|
+
if (file) {
|
|
1610
|
+
return file;
|
|
1611
|
+
}
|
|
1612
|
+
return false;
|
|
1613
|
+
}
|
|
1614
|
+
chunkSHUYVCID_js.__name(checkIndex, "checkIndex");
|
|
1615
|
+
function checkExtensions(request, vfs) {
|
|
1616
|
+
let file = `${request}.ts`;
|
|
1617
|
+
if (vfs.fileExistsSync(file)) {
|
|
1618
|
+
return file;
|
|
1619
|
+
}
|
|
1620
|
+
file = `${request}.mts`;
|
|
1621
|
+
if (vfs.fileExistsSync(file)) {
|
|
1622
|
+
return file;
|
|
1623
|
+
}
|
|
1624
|
+
file = `${request}.cts`;
|
|
1625
|
+
if (vfs.fileExistsSync(file)) {
|
|
1626
|
+
return file;
|
|
1627
|
+
}
|
|
1628
|
+
file = `${request}.tsx`;
|
|
1629
|
+
if (vfs.fileExistsSync(file)) {
|
|
1630
|
+
return file;
|
|
1631
|
+
}
|
|
1632
|
+
file = `${request}.js`;
|
|
1633
|
+
if (vfs.fileExistsSync(file)) {
|
|
1634
|
+
return file;
|
|
1635
|
+
}
|
|
1636
|
+
file = `${request}.mjs`;
|
|
1637
|
+
if (vfs.fileExistsSync(file)) {
|
|
1638
|
+
return file;
|
|
1639
|
+
}
|
|
1640
|
+
file = `${request}.cjs`;
|
|
1641
|
+
if (vfs.fileExistsSync(file)) {
|
|
1642
|
+
return file;
|
|
1643
|
+
}
|
|
1644
|
+
file = `${request}.jsx`;
|
|
1645
|
+
if (vfs.fileExistsSync(file)) {
|
|
1646
|
+
return file;
|
|
1647
|
+
}
|
|
1648
|
+
file = `${request}.json`;
|
|
1649
|
+
if (vfs.fileExistsSync(file)) {
|
|
1650
|
+
return file;
|
|
1651
|
+
}
|
|
1652
|
+
file = `${request}.d.ts`;
|
|
1653
|
+
if (vfs.fileExistsSync(file)) {
|
|
1654
|
+
return file;
|
|
1655
|
+
}
|
|
1656
|
+
return false;
|
|
1657
|
+
}
|
|
1658
|
+
chunkSHUYVCID_js.__name(checkExtensions, "checkExtensions");
|
|
1659
|
+
function createVfs(context) {
|
|
1660
|
+
const vfs = new VirtualFileSystem(context);
|
|
1661
|
+
return vfs;
|
|
1662
|
+
}
|
|
1663
|
+
chunkSHUYVCID_js.__name(createVfs, "createVfs");
|
|
1664
|
+
|
|
1665
|
+
// ../powerlines/src/internal/contexts/context.ts
|
|
1666
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
1667
|
+
var PowerlinesContext = class _PowerlinesContext {
|
|
1668
|
+
static {
|
|
1669
|
+
chunkSHUYVCID_js.__name(this, "PowerlinesContext");
|
|
1670
|
+
}
|
|
1671
|
+
#workspaceConfig;
|
|
1672
|
+
#checksum = null;
|
|
1673
|
+
#buildId = uuid.uuid();
|
|
1674
|
+
#releaseId = uuid.uuid();
|
|
1675
|
+
#timestamp = Date.now();
|
|
1676
|
+
#envPaths;
|
|
1677
|
+
#fs;
|
|
1678
|
+
#tsconfig;
|
|
1679
|
+
// #entry: ResolvedEntryTypeDefinition[] = [] as ResolvedEntryTypeDefinition[];
|
|
1680
|
+
#getConfigProps(config = {}) {
|
|
1681
|
+
return {
|
|
1682
|
+
variant: config.build?.variant,
|
|
1683
|
+
projectType: config.type,
|
|
1684
|
+
projectRoot: config.root,
|
|
1685
|
+
name: config.name,
|
|
1686
|
+
title: config.title,
|
|
1687
|
+
description: config.description,
|
|
1688
|
+
sourceRoot: config.sourceRoot,
|
|
1689
|
+
configFile: config.configFile,
|
|
1690
|
+
customLogger: config.customLogger,
|
|
1691
|
+
logLevel: config.logLevel,
|
|
1692
|
+
builtinPrefix: config.builtinPrefix,
|
|
1693
|
+
tsconfig: config.tsconfig,
|
|
1694
|
+
tsconfigRaw: config.tsconfigRaw,
|
|
1695
|
+
skipCache: config.skipCache,
|
|
1696
|
+
skipInstalls: config.skipInstalls,
|
|
1697
|
+
entry: config.entry,
|
|
1698
|
+
output: config.output,
|
|
1699
|
+
plugins: config.plugins,
|
|
1700
|
+
mode: config.mode,
|
|
1701
|
+
lint: config.lint,
|
|
1702
|
+
transform: config.transform,
|
|
1703
|
+
build: config.build,
|
|
1704
|
+
override: config.override
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Create a new Storm context from the workspace root and user config.
|
|
1709
|
+
*
|
|
1710
|
+
* @param workspaceRoot - The root directory of the workspace.
|
|
1711
|
+
* @param config - The user configuration options.
|
|
1712
|
+
* @returns A promise that resolves to the new context.
|
|
1713
|
+
*/
|
|
1714
|
+
static async from(workspaceRoot, config) {
|
|
1715
|
+
const context = new _PowerlinesContext(await chunkHHPODCTP_js.loadWorkspaceConfig(workspaceRoot, config.root));
|
|
1716
|
+
await context.withUserConfig(config);
|
|
1717
|
+
context.corePackagePath = process.env.POWERLINES_LOCAL ? join.joinPaths(context.workspaceConfig.workspaceRoot, "packages/core") : await resolve.resolvePackage("powerlines");
|
|
1718
|
+
if (!context.corePackagePath) {
|
|
1719
|
+
throw new Error("Could not resolve powerlines package location.");
|
|
1720
|
+
}
|
|
1721
|
+
return context;
|
|
1722
|
+
}
|
|
1723
|
+
dependencies = {};
|
|
1724
|
+
reflections = {};
|
|
1725
|
+
persistedMeta = void 0;
|
|
1726
|
+
corePackagePath;
|
|
1727
|
+
packageJson;
|
|
1728
|
+
projectJson = void 0;
|
|
1729
|
+
resolver;
|
|
1730
|
+
get entry() {
|
|
1731
|
+
return resolveEntriesSync(this, toArray.toArray(this.config.entry));
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* The TypeScript configuration parsed from the tsconfig file
|
|
1735
|
+
*/
|
|
1736
|
+
get tsconfig() {
|
|
1737
|
+
if (!this.#tsconfig) {
|
|
1738
|
+
this.#tsconfig = {
|
|
1739
|
+
tsconfigFilePath: this.config.tsconfig
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
return this.#tsconfig;
|
|
1743
|
+
}
|
|
1744
|
+
set tsconfig(value) {
|
|
1745
|
+
this.#tsconfig = value;
|
|
1746
|
+
}
|
|
1747
|
+
get fs() {
|
|
1748
|
+
if (!this.#fs) {
|
|
1749
|
+
this.#fs = createVfs(this);
|
|
1750
|
+
}
|
|
1751
|
+
return this.#fs;
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Get the checksum of the project's current state
|
|
1755
|
+
*/
|
|
1756
|
+
get checksum() {
|
|
1757
|
+
return this.#checksum;
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* The meta information about the current build
|
|
1761
|
+
*/
|
|
1762
|
+
get meta() {
|
|
1763
|
+
return {
|
|
1764
|
+
buildId: this.#buildId,
|
|
1765
|
+
releaseId: this.#releaseId,
|
|
1766
|
+
checksum: this.#checksum,
|
|
1767
|
+
timestamp: this.#timestamp,
|
|
1768
|
+
projectRootHash: murmurhash.murmurhash({
|
|
1769
|
+
workspaceRoot: this.workspaceConfig?.workspaceRoot,
|
|
1770
|
+
projectRoot: this.config?.projectRoot
|
|
1771
|
+
}, {
|
|
1772
|
+
maxLength: chunkHHPODCTP_js.PROJECT_ROOT_HASH_LENGTH
|
|
1773
|
+
}),
|
|
1774
|
+
configHash: murmurhash.murmurhash(this.config, {
|
|
1775
|
+
maxLength: chunkHHPODCTP_js.CACHE_HASH_LENGTH
|
|
1776
|
+
}),
|
|
1777
|
+
builtinIdMap: {},
|
|
1778
|
+
virtualFiles: {}
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
/**
|
|
1782
|
+
* The resolved configuration options
|
|
1783
|
+
*/
|
|
1784
|
+
get config() {
|
|
1785
|
+
return this.resolvedConfig ?? {};
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* The logger function
|
|
1789
|
+
*/
|
|
1790
|
+
get log() {
|
|
1791
|
+
if (!this.logFn) {
|
|
1792
|
+
this.logFn = this.createLog();
|
|
1793
|
+
}
|
|
1794
|
+
return this.logFn;
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* The workspace configuration
|
|
1798
|
+
*/
|
|
1799
|
+
get workspaceConfig() {
|
|
1800
|
+
return this.#workspaceConfig;
|
|
1801
|
+
}
|
|
1802
|
+
get envPaths() {
|
|
1803
|
+
if (!this.#envPaths) {
|
|
1804
|
+
this.#envPaths = getEnvPaths.getEnvPaths({
|
|
1805
|
+
orgId: "storm-software",
|
|
1806
|
+
appId: "powerlines",
|
|
1807
|
+
workspaceRoot: this.workspaceConfig.workspaceRoot
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
return this.#envPaths;
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* Get the path to the artifacts directory for the project
|
|
1814
|
+
*/
|
|
1815
|
+
get artifactsPath() {
|
|
1816
|
+
return join.joinPaths(this.workspaceConfig.workspaceRoot, this.config.projectRoot, ".storm");
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* Get the path to the builtin modules used by the project
|
|
1820
|
+
*/
|
|
1821
|
+
get builtinsPath() {
|
|
1822
|
+
return join.joinPaths(this.artifactsPath, "builtins");
|
|
1823
|
+
}
|
|
1824
|
+
/**
|
|
1825
|
+
* Get the path to the entry directory for the project
|
|
1826
|
+
*/
|
|
1827
|
+
get entryPath() {
|
|
1828
|
+
return join.joinPaths(this.artifactsPath, "entry");
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Get the path to the data directory for the project
|
|
1832
|
+
*/
|
|
1833
|
+
get dataPath() {
|
|
1834
|
+
return join.joinPaths(this.envPaths.data, "projects", chunkHHPODCTP_js.getPrefixedProjectRootHash(this.config.name, this.meta.projectRootHash));
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Get the path to the cache directory for the project
|
|
1838
|
+
*/
|
|
1839
|
+
get cachePath() {
|
|
1840
|
+
return join.joinPaths(this.envPaths.cache, "projects", murmurhash.murmurhash({
|
|
1841
|
+
checksum: this.#checksum,
|
|
1842
|
+
config: this.meta.configHash
|
|
1843
|
+
}, {
|
|
1844
|
+
maxLength: chunkHHPODCTP_js.CACHE_HASH_LENGTH
|
|
1845
|
+
}));
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Get the path to the generated declaration file for the project
|
|
1849
|
+
*/
|
|
1850
|
+
get dtsPath() {
|
|
1851
|
+
return this.config.output.dts ? append.appendPath(this.config.output.dts, this.workspaceConfig.workspaceRoot) : join.joinPaths(this.workspaceConfig.workspaceRoot, this.config.projectRoot, "storm.d.ts");
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* Get the project root relative to the workspace root
|
|
1855
|
+
*/
|
|
1856
|
+
get relativeToWorkspaceRoot() {
|
|
1857
|
+
return getWorkspaceRoot.relativeToWorkspaceRoot(this.config.projectRoot);
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Update the context using a new user configuration options
|
|
1861
|
+
*
|
|
1862
|
+
* @param userConfig - The new user configuration options.
|
|
1863
|
+
*/
|
|
1864
|
+
async withUserConfig(userConfig, options = {
|
|
1865
|
+
isHighPriority: true
|
|
1866
|
+
}) {
|
|
1867
|
+
this.mergeUserConfig(userConfig);
|
|
1868
|
+
await this.init(this.config.userConfig, options);
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Update the context using a new inline configuration options
|
|
1872
|
+
*
|
|
1873
|
+
* @param inlineConfig - The new inline configuration options.
|
|
1874
|
+
*/
|
|
1875
|
+
async withInlineConfig(inlineConfig, options = {
|
|
1876
|
+
isHighPriority: true
|
|
1877
|
+
}) {
|
|
1878
|
+
this.config.inlineConfig = inlineConfig;
|
|
1879
|
+
if (inlineConfig.command === "new") {
|
|
1880
|
+
const workspacePackageJsonPath = join.joinPaths(this.workspaceConfig.workspaceRoot, "package.json");
|
|
1881
|
+
if (!exists.existsSync(workspacePackageJsonPath)) {
|
|
1882
|
+
throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
|
|
1883
|
+
}
|
|
1884
|
+
this.packageJson = await json.readJsonFile(workspacePackageJsonPath);
|
|
1885
|
+
this.workspaceConfig.repository ??= isSetString.isSetString(this.packageJson?.repository) ? this.packageJson.repository : this.packageJson?.repository?.url;
|
|
1886
|
+
}
|
|
1887
|
+
await this.init(this.config.inlineConfig, options);
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Create a new logger instance
|
|
1891
|
+
*
|
|
1892
|
+
* @param name - The name to use for the logger instance
|
|
1893
|
+
* @returns A logger function
|
|
1894
|
+
*/
|
|
1895
|
+
createLog(name = null) {
|
|
1896
|
+
return createLog(name, {
|
|
1897
|
+
...this.config,
|
|
1898
|
+
logLevel: isNull.isNull(this.config.logLevel) ? "silent" : this.config.logLevel
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* Extend the current logger instance with a new name
|
|
1903
|
+
*
|
|
1904
|
+
* @param name - The name to use for the extended logger instance
|
|
1905
|
+
* @returns A logger function
|
|
1906
|
+
*/
|
|
1907
|
+
extendLog(name) {
|
|
1908
|
+
return extendLog(this.log, name);
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Creates a new StormContext instance.
|
|
1912
|
+
*
|
|
1913
|
+
* @param workspaceConfig - The workspace configuration.
|
|
1914
|
+
*/
|
|
1915
|
+
constructor(workspaceConfig) {
|
|
1916
|
+
this.#workspaceConfig = workspaceConfig;
|
|
1917
|
+
this.#envPaths = getEnvPaths.getEnvPaths({
|
|
1918
|
+
orgId: "storm-software",
|
|
1919
|
+
appId: "powerlines",
|
|
1920
|
+
workspaceRoot: workspaceConfig.workspaceRoot
|
|
1921
|
+
});
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* The resolved configuration for this context
|
|
1925
|
+
*/
|
|
1926
|
+
resolvedConfig = {};
|
|
1927
|
+
/**
|
|
1928
|
+
* A logger function specific to this context
|
|
1929
|
+
*/
|
|
1930
|
+
logFn;
|
|
1931
|
+
/**
|
|
1932
|
+
* Initialize the context with the provided configuration options
|
|
1933
|
+
*
|
|
1934
|
+
* @param config - The partial user configuration to use for initialization.
|
|
1935
|
+
*/
|
|
1936
|
+
async init(config = {}, options = {
|
|
1937
|
+
isHighPriority: true
|
|
1938
|
+
}) {
|
|
1939
|
+
const cacheKey = {
|
|
1940
|
+
projectRoot: config.root ?? this.config.projectRoot ?? this.config.userConfig?.root ?? this.config.inlineConfig?.root,
|
|
1941
|
+
mode: (config.mode ?? this.config.mode) || this.workspaceConfig.mode,
|
|
1942
|
+
skipCache: config.skipCache ?? this.config.skipCache ?? false,
|
|
1943
|
+
configFile: config.configFile ?? this.config.configFile,
|
|
1944
|
+
command: this.config.inlineConfig?.command
|
|
1945
|
+
};
|
|
1946
|
+
if (cache.has(cacheKey)) {
|
|
1947
|
+
const result = cache.get(cacheKey);
|
|
1948
|
+
this.projectJson = result.projectJson;
|
|
1949
|
+
this.packageJson = result.packageJson;
|
|
1950
|
+
this.#checksum = result.checksum;
|
|
1951
|
+
this.resolver = result.resolver;
|
|
1952
|
+
this.mergeUserConfig(result.userConfig.config, this.config.userConfig);
|
|
1953
|
+
} else {
|
|
1954
|
+
const projectJsonPath = join.joinPaths(cacheKey.projectRoot, "project.json");
|
|
1955
|
+
if (exists.existsSync(projectJsonPath)) {
|
|
1956
|
+
this.projectJson = await json.readJsonFile(projectJsonPath);
|
|
1957
|
+
}
|
|
1958
|
+
const packageJsonPath = join.joinPaths(cacheKey.projectRoot, "package.json");
|
|
1959
|
+
if (exists.existsSync(packageJsonPath)) {
|
|
1960
|
+
this.packageJson = await json.readJsonFile(packageJsonPath);
|
|
1961
|
+
}
|
|
1962
|
+
this.#checksum = await chunkHHPODCTP_js.getChecksum(cacheKey.projectRoot);
|
|
1963
|
+
this.resolver = createResolver({
|
|
1964
|
+
workspaceRoot: this.workspaceConfig.workspaceRoot,
|
|
1965
|
+
projectRoot: cacheKey.projectRoot,
|
|
1966
|
+
cacheDir: this.cachePath,
|
|
1967
|
+
mode: cacheKey.mode,
|
|
1968
|
+
skipCache: cacheKey.skipCache
|
|
1969
|
+
});
|
|
1970
|
+
const userConfig = await chunkHHPODCTP_js.loadUserConfigFile(cacheKey.projectRoot, this.resolver, cacheKey.command, cacheKey.mode, cacheKey.configFile);
|
|
1971
|
+
this.mergeUserConfig(userConfig.config);
|
|
1972
|
+
cache.set(cacheKey, {
|
|
1973
|
+
projectJson: this.projectJson,
|
|
1974
|
+
packageJson: this.packageJson,
|
|
1975
|
+
checksum: this.#checksum,
|
|
1976
|
+
resolver: this.resolver,
|
|
1977
|
+
userConfig
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
if (isSetObject.isSetObject(config)) {
|
|
1981
|
+
this.resolvedConfig = defu4__default.default({
|
|
1982
|
+
inlineConfig: this.config.inlineConfig,
|
|
1983
|
+
userConfig: this.config.userConfig
|
|
1984
|
+
}, options.isHighPriority ? this.#getConfigProps(config) : {}, {
|
|
1985
|
+
command: this.config.inlineConfig?.command,
|
|
1986
|
+
...this.#getConfigProps(this.config.inlineConfig)
|
|
1987
|
+
}, this.#getConfigProps(this.config.userConfig), {
|
|
1988
|
+
mode: this.workspaceConfig?.mode,
|
|
1989
|
+
logLevel: this.workspaceConfig?.logLevel,
|
|
1990
|
+
skipCache: this.workspaceConfig?.skipCache
|
|
1991
|
+
}, {
|
|
1992
|
+
name: this.projectJson?.name || this.packageJson?.name,
|
|
1993
|
+
version: this.packageJson?.version,
|
|
1994
|
+
description: this.packageJson?.description,
|
|
1995
|
+
tsconfig: append.appendPath("tsconfig.json", cacheKey.projectRoot),
|
|
1996
|
+
sourceRoot: this.projectJson?.sourceRoot || append.appendPath("src", cacheKey.projectRoot),
|
|
1997
|
+
output: {
|
|
1998
|
+
outputPath: join.joinPaths("dist", cacheKey.projectRoot),
|
|
1999
|
+
mode: "virtual",
|
|
2000
|
+
dts: join.joinPaths(cacheKey.projectRoot, "storm.d.ts"),
|
|
2001
|
+
assets: [
|
|
2002
|
+
{
|
|
2003
|
+
glob: "LICENSE"
|
|
2004
|
+
},
|
|
2005
|
+
{
|
|
2006
|
+
input: cacheKey.projectRoot,
|
|
2007
|
+
glob: "*.md"
|
|
2008
|
+
},
|
|
2009
|
+
{
|
|
2010
|
+
input: cacheKey.projectRoot,
|
|
2011
|
+
glob: "package.json"
|
|
2012
|
+
}
|
|
2013
|
+
]
|
|
2014
|
+
}
|
|
2015
|
+
}, options.isHighPriority ? {} : this.#getConfigProps(config), {
|
|
2016
|
+
inlineConfig: {},
|
|
2017
|
+
userConfig: {},
|
|
2018
|
+
platform: "neutral",
|
|
2019
|
+
mode: "production",
|
|
2020
|
+
projectType: "application",
|
|
2021
|
+
logLevel: "info",
|
|
2022
|
+
builtinPrefix: "storm",
|
|
2023
|
+
preview: false,
|
|
2024
|
+
environments: {},
|
|
2025
|
+
transform: {
|
|
2026
|
+
babel: {
|
|
2027
|
+
plugins: [],
|
|
2028
|
+
presets: []
|
|
2029
|
+
}
|
|
2030
|
+
},
|
|
2031
|
+
lint: {
|
|
2032
|
+
eslint: {}
|
|
2033
|
+
},
|
|
2034
|
+
build: {
|
|
2035
|
+
target: "esnext"
|
|
2036
|
+
},
|
|
2037
|
+
override: {}
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
this.config.entry = getUniqueEntries(this.config.entry);
|
|
2041
|
+
if (this.config.name?.startsWith("@") && this.config.name.split("/").filter(Boolean).length > 1) {
|
|
2042
|
+
this.config.name = this.config.name.split("/").filter(Boolean)[1];
|
|
2043
|
+
}
|
|
2044
|
+
this.config.title ??= titleCase.titleCase(this.config.name);
|
|
2045
|
+
if (this.config.build.external) {
|
|
2046
|
+
this.config.build.external = getUnique.getUnique(this.config.build.external);
|
|
2047
|
+
}
|
|
2048
|
+
if (this.config.build.noExternal) {
|
|
2049
|
+
this.config.build.noExternal = getUnique.getUnique(this.config.build.noExternal);
|
|
2050
|
+
}
|
|
2051
|
+
this.config.output.format = getUnique.getUnique(toArray.toArray(this.config.output?.format ?? (this.config.projectType === "library" ? [
|
|
2052
|
+
"cjs",
|
|
2053
|
+
"esm"
|
|
2054
|
+
] : [
|
|
2055
|
+
"esm"
|
|
2056
|
+
])));
|
|
2057
|
+
this.config.output.outputPath ??= join.joinPaths("dist", this.config.projectRoot || ".");
|
|
2058
|
+
this.config.output.assets = getUnique.getUnique(this.config.output.assets.map((asset) => {
|
|
2059
|
+
return {
|
|
2060
|
+
glob: isSetObject.isSetObject(asset) ? asset.glob : asset,
|
|
2061
|
+
input: isString.isString(asset) || !asset.input || asset.input === "." || asset.input === "/" || asset.input === "./" ? this.workspaceConfig.workspaceRoot : append.appendPath(asset.input, this.workspaceConfig.workspaceRoot),
|
|
2062
|
+
output: append.appendPath(isSetObject.isSetObject(asset) && asset.output ? join.joinPaths(this.config.output.outputPath, replace.replacePath(asset.output, this.config.output.outputPath)) : this.config.output.outputPath, this.workspaceConfig.workspaceRoot),
|
|
2063
|
+
ignore: isSetObject.isSetObject(asset) && asset.ignore ? toArray.toArray(asset.ignore) : void 0
|
|
2064
|
+
};
|
|
2065
|
+
}));
|
|
2066
|
+
this.config.plugins = (this.config.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
|
|
2067
|
+
if (isPlugin(plugin) && checkDedupe(plugin, ret.filter((p) => isPlugin(p)))) {
|
|
2068
|
+
return ret;
|
|
2069
|
+
}
|
|
2070
|
+
ret.push(plugin);
|
|
2071
|
+
return ret;
|
|
2072
|
+
}, []);
|
|
2073
|
+
}
|
|
2074
|
+
mergeUserConfig(from = {}, into = this.config.userConfig ?? {}) {
|
|
2075
|
+
this.config.userConfig = defu4__default.default({
|
|
2076
|
+
entry: Array.isArray(from.entry) && from.entry.length > 0 ? from.entry : Array.isArray(into?.entry) && into.entry.length > 0 ? into.entry : []
|
|
2077
|
+
}, omit.omit(from ?? {}, [
|
|
2078
|
+
"entry"
|
|
2079
|
+
]), omit.omit(into ?? {}, [
|
|
2080
|
+
"entry"
|
|
2081
|
+
]));
|
|
2082
|
+
if (this.config.userConfig.output?.format) {
|
|
2083
|
+
this.config.userConfig.output.format = getUnique.getUnique(toArray.toArray(this.config.userConfig.output?.format));
|
|
2084
|
+
}
|
|
2085
|
+
this.config.userConfig.plugins = (this.config.userConfig.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
|
|
2086
|
+
if (isPlugin(plugin) && checkDedupe(plugin, ret.filter((p) => isPlugin(p)))) {
|
|
2087
|
+
return ret;
|
|
2088
|
+
}
|
|
2089
|
+
ret.push(plugin);
|
|
2090
|
+
return ret;
|
|
2091
|
+
}, []);
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
2094
|
+
|
|
2095
|
+
// ../powerlines/src/types/plugin.ts
|
|
2096
|
+
var PLUGIN_NON_HOOK_FIELDS = [
|
|
2097
|
+
"name",
|
|
2098
|
+
"enforce",
|
|
2099
|
+
"dedupe",
|
|
2100
|
+
"dependsOn",
|
|
2101
|
+
"applyToEnvironment"
|
|
2102
|
+
];
|
|
2103
|
+
async function callHook(context, hook, options, ...args) {
|
|
2104
|
+
const handlers = context.selectHooks(hook, options);
|
|
2105
|
+
if (handlers.length > 0) {
|
|
2106
|
+
context.log(types.LogLevelLabel.DEBUG, ` \u{1F9E9} Calling plugin hook: ${chalk5__default.default.bold.cyanBright(`${hook}${options?.order ? ` (${options.order})` : ""}`)}`);
|
|
2107
|
+
let results = [];
|
|
2108
|
+
if (options?.sequential === false) {
|
|
2109
|
+
results = await Promise.all(handlers.map(async (handler) => {
|
|
2110
|
+
if (!isFunction.isFunction(handler)) {
|
|
2111
|
+
throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
|
|
2112
|
+
}
|
|
2113
|
+
return Promise.resolve(handler.apply(null, ...args));
|
|
2114
|
+
}));
|
|
2115
|
+
} else {
|
|
2116
|
+
for (const handler of handlers) {
|
|
2117
|
+
if (!isFunction.isFunction(handler)) {
|
|
2118
|
+
throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
|
|
2119
|
+
}
|
|
2120
|
+
results.push(await Promise.resolve(handler.apply(null, ...args)));
|
|
2121
|
+
if (options?.result === "first" && isSet.isSet(results[results.length - 1])) {
|
|
2122
|
+
break;
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
const definedResults = results.filter((result) => isSet.isSet(result));
|
|
2127
|
+
if (definedResults.length > 0) {
|
|
2128
|
+
let mergedResult = void 0;
|
|
2129
|
+
for (const result of definedResults) {
|
|
2130
|
+
mergedResult = defu4.defu(result, mergedResult ?? {});
|
|
2131
|
+
}
|
|
2132
|
+
return mergedResult;
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
return void 0;
|
|
2136
|
+
}
|
|
2137
|
+
chunkSHUYVCID_js.__name(callHook, "callHook");
|
|
2138
|
+
|
|
2139
|
+
// ../powerlines/src/internal/contexts/plugin-context.ts
|
|
2140
|
+
function createPluginContext(plugin, environment) {
|
|
2141
|
+
const normalizeMessage = /* @__PURE__ */ chunkSHUYVCID_js.__name((message) => {
|
|
2142
|
+
return isString.isString(message) ? message : message.message;
|
|
2143
|
+
}, "normalizeMessage");
|
|
2144
|
+
const log = environment.extendLog(plugin.name);
|
|
2145
|
+
const callHookFn = /* @__PURE__ */ chunkSHUYVCID_js.__name(async (hook, options, ...args) => {
|
|
2146
|
+
return callHook(environment, hook, {
|
|
2147
|
+
sequential: true,
|
|
2148
|
+
...options
|
|
2149
|
+
}, ...args);
|
|
2150
|
+
}, "callHookFn");
|
|
2151
|
+
return new Proxy({}, {
|
|
2152
|
+
get(_, prop) {
|
|
2153
|
+
if (prop === "$$internal") {
|
|
2154
|
+
return {
|
|
2155
|
+
environment,
|
|
2156
|
+
callHook: callHookFn
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2159
|
+
if (prop === "log" || prop === "logger") {
|
|
2160
|
+
return log;
|
|
2161
|
+
}
|
|
2162
|
+
if (prop === "error") {
|
|
2163
|
+
return (message) => {
|
|
2164
|
+
log(types.LogLevelLabel.ERROR, normalizeMessage(message));
|
|
2165
|
+
};
|
|
2166
|
+
}
|
|
2167
|
+
if (prop === "warn") {
|
|
2168
|
+
return (message) => {
|
|
2169
|
+
log(types.LogLevelLabel.WARN, normalizeMessage(message));
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
return environment[prop];
|
|
2173
|
+
},
|
|
2174
|
+
set(_, prop, value) {
|
|
2175
|
+
if ([
|
|
2176
|
+
"$$internal",
|
|
2177
|
+
"environment",
|
|
2178
|
+
"config",
|
|
2179
|
+
"log",
|
|
2180
|
+
"logger",
|
|
2181
|
+
"error",
|
|
2182
|
+
"warn",
|
|
2183
|
+
"plugins",
|
|
2184
|
+
"hooks",
|
|
2185
|
+
"addPlugin",
|
|
2186
|
+
"selectHooks"
|
|
2187
|
+
].includes(prop)) {
|
|
2188
|
+
log(types.LogLevelLabel.WARN, `Cannot set read-only property "${String(prop)}"`);
|
|
2189
|
+
return false;
|
|
2190
|
+
}
|
|
2191
|
+
environment[prop] = value;
|
|
2192
|
+
return true;
|
|
2193
|
+
}
|
|
2194
|
+
});
|
|
2195
|
+
}
|
|
2196
|
+
chunkSHUYVCID_js.__name(createPluginContext, "createPluginContext");
|
|
2197
|
+
|
|
2198
|
+
// ../powerlines/src/internal/contexts/environment-context.ts
|
|
2199
|
+
var PowerlinesEnvironmentContext = class _PowerlinesEnvironmentContext extends PowerlinesContext {
|
|
2200
|
+
static {
|
|
2201
|
+
chunkSHUYVCID_js.__name(this, "PowerlinesEnvironmentContext");
|
|
2202
|
+
}
|
|
2203
|
+
#hooks = {};
|
|
2204
|
+
/**
|
|
2205
|
+
* Create a new Storm context from the workspace root and user config.
|
|
2206
|
+
*
|
|
2207
|
+
* @param workspaceConfig - The root directory of the workspace.
|
|
2208
|
+
* @param config - The user configuration options.
|
|
2209
|
+
* @returns A promise that resolves to the new context.
|
|
2210
|
+
*/
|
|
2211
|
+
static async fromConfig(workspaceConfig, config) {
|
|
2212
|
+
const context = new _PowerlinesEnvironmentContext(config, workspaceConfig);
|
|
2213
|
+
await context.init();
|
|
2214
|
+
context.corePackagePath = process.env.POWERLINES_LOCAL ? joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, "packages/core") : await resolve.resolvePackage("powerlines");
|
|
2215
|
+
if (!context.corePackagePath) {
|
|
2216
|
+
throw new Error("Could not resolve powerlines package location.");
|
|
2217
|
+
}
|
|
2218
|
+
return context;
|
|
2219
|
+
}
|
|
2220
|
+
environment;
|
|
2221
|
+
plugins = [];
|
|
2222
|
+
/**
|
|
2223
|
+
* The resolved configuration options
|
|
2224
|
+
*/
|
|
2225
|
+
get config() {
|
|
2226
|
+
return super.config;
|
|
2227
|
+
}
|
|
2228
|
+
get hooks() {
|
|
2229
|
+
return this.#hooks;
|
|
2230
|
+
}
|
|
2231
|
+
async addPlugin(plugin) {
|
|
2232
|
+
let resolvedPlugin = plugin;
|
|
2233
|
+
if (plugin.applyToEnvironment) {
|
|
2234
|
+
const result = await Promise.resolve(plugin.applyToEnvironment(this.environment));
|
|
2235
|
+
if (!result || isObject.isObject(result) && Object.keys(result).length === 0) {
|
|
2236
|
+
return;
|
|
2237
|
+
}
|
|
2238
|
+
resolvedPlugin = isPlugin(result) ? result : plugin;
|
|
2239
|
+
}
|
|
2240
|
+
const context = createPluginContext(resolvedPlugin, this);
|
|
2241
|
+
this.plugins.push({
|
|
2242
|
+
plugin: resolvedPlugin,
|
|
2243
|
+
context
|
|
2244
|
+
});
|
|
2245
|
+
this.#hooks = Object.keys(resolvedPlugin).filter((key) => !PLUGIN_NON_HOOK_FIELDS.includes(key)).reduce((ret, key) => {
|
|
2246
|
+
const hook = key;
|
|
2247
|
+
const pluginHook = resolvedPlugin[hook];
|
|
2248
|
+
if (!isPluginHook(pluginHook)) {
|
|
2249
|
+
return ret;
|
|
2250
|
+
}
|
|
2251
|
+
if (!isHookExternal(hook)) {
|
|
2252
|
+
ret[hook] ??= {};
|
|
2253
|
+
if (resolvedPlugin.enforce) {
|
|
2254
|
+
ret[hook][`${resolvedPlugin.enforce}Enforced`] ??= [];
|
|
2255
|
+
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${resolvedPlugin.enforce}Enforced`]);
|
|
2256
|
+
return ret;
|
|
2257
|
+
}
|
|
2258
|
+
if (isFunction.isFunction(pluginHook) || !pluginHook.order) {
|
|
2259
|
+
ret[hook].normal ??= [];
|
|
2260
|
+
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook].normal);
|
|
2261
|
+
return ret;
|
|
2262
|
+
}
|
|
2263
|
+
ret[hook][`${pluginHook.order}Ordered`] ??= [];
|
|
2264
|
+
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${pluginHook.order}Ordered`]);
|
|
2265
|
+
} else {
|
|
2266
|
+
ret[hook] ??= [];
|
|
2267
|
+
ret[hook].push({
|
|
2268
|
+
plugin: resolvedPlugin,
|
|
2269
|
+
hook: getHookHandler(pluginHook).bind(context)
|
|
2270
|
+
});
|
|
2271
|
+
}
|
|
2272
|
+
return ret;
|
|
2273
|
+
}, this.hooks);
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* Retrieves the hook handlers for a specific hook name
|
|
2277
|
+
*/
|
|
2278
|
+
selectHooks(hook, options) {
|
|
2279
|
+
const handlers = [];
|
|
2280
|
+
if (this.hooks[hook]) {
|
|
2281
|
+
if (!isHookExternal(hook)) {
|
|
2282
|
+
const hooks = this.hooks[hook];
|
|
2283
|
+
if (options?.order) {
|
|
2284
|
+
if (options?.order === "pre") {
|
|
2285
|
+
handlers.push(...(hooks.preOrdered ?? []).map((h) => h.handler));
|
|
2286
|
+
handlers.push(...(hooks.preEnforced ?? []).map((h) => h.handler));
|
|
2287
|
+
} else if (options?.order === "post") {
|
|
2288
|
+
handlers.push(...(hooks.postOrdered ?? []).map((h) => h.handler));
|
|
2289
|
+
handlers.push(...(hooks.postEnforced ?? []).map((h) => h.handler));
|
|
2290
|
+
} else {
|
|
2291
|
+
handlers.push(...(hooks.normal ?? []).map((h) => h.handler));
|
|
2292
|
+
}
|
|
2293
|
+
} else {
|
|
2294
|
+
handlers.push(...this.selectHooks(hook, {
|
|
2295
|
+
order: "pre"
|
|
2296
|
+
}));
|
|
2297
|
+
handlers.push(...this.selectHooks(hook, {
|
|
2298
|
+
order: "normal"
|
|
2299
|
+
}));
|
|
2300
|
+
handlers.push(...this.selectHooks(hook, {
|
|
2301
|
+
order: "post"
|
|
2302
|
+
}));
|
|
2303
|
+
}
|
|
2304
|
+
} else {
|
|
2305
|
+
handlers.push(...this.hooks[hook].map((h) => h.handler));
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
return handlers;
|
|
2309
|
+
}
|
|
2310
|
+
constructor(config, workspaceConfig) {
|
|
2311
|
+
super(workspaceConfig);
|
|
2312
|
+
this.resolvedConfig = config;
|
|
2313
|
+
}
|
|
2314
|
+
};
|
|
2315
|
+
|
|
2316
|
+
// ../powerlines/src/internal/contexts/api-context.ts
|
|
2317
|
+
var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext {
|
|
2318
|
+
static {
|
|
2319
|
+
chunkSHUYVCID_js.__name(this, "PowerlinesAPIContext");
|
|
2320
|
+
}
|
|
2321
|
+
#environments = {};
|
|
2322
|
+
#plugins = [];
|
|
2323
|
+
#log;
|
|
2324
|
+
/**
|
|
2325
|
+
* Create a new Storm context from the workspace root and user config.
|
|
2326
|
+
*
|
|
2327
|
+
* @param workspaceRoot - The root directory of the workspace.
|
|
2328
|
+
* @param config - The user configuration options.
|
|
2329
|
+
* @returns A promise that resolves to the new context.
|
|
2330
|
+
*/
|
|
2331
|
+
static async from(workspaceRoot, config) {
|
|
2332
|
+
const context = new _PowerlinesAPIContext(await chunkHHPODCTP_js.loadWorkspaceConfig(workspaceRoot, config.root));
|
|
2333
|
+
await context.withUserConfig(config);
|
|
2334
|
+
context.corePackagePath = process.env.POWERLINES_LOCAL ? joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, "packages/core") : await resolve.resolvePackage("powerlines");
|
|
2335
|
+
if (!context.corePackagePath) {
|
|
2336
|
+
throw new Error("Could not resolve powerlines package location.");
|
|
2337
|
+
}
|
|
2338
|
+
return context;
|
|
2339
|
+
}
|
|
2340
|
+
/**
|
|
2341
|
+
* A record of all environments by name
|
|
2342
|
+
*/
|
|
2343
|
+
get environments() {
|
|
2344
|
+
return this.#environments;
|
|
2345
|
+
}
|
|
2346
|
+
get log() {
|
|
2347
|
+
if (!this.#log) {
|
|
2348
|
+
this.#log = this.createLog("engine");
|
|
2349
|
+
}
|
|
2350
|
+
return this.#log;
|
|
2351
|
+
}
|
|
2352
|
+
get plugins() {
|
|
2353
|
+
return this.#plugins;
|
|
2354
|
+
}
|
|
2355
|
+
constructor(workspaceConfig) {
|
|
2356
|
+
super(workspaceConfig);
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Initialize the context with the provided configuration options
|
|
2360
|
+
*
|
|
2361
|
+
* @param config - The partial user configuration to use for initialization.
|
|
2362
|
+
*/
|
|
2363
|
+
async init(config = {}) {
|
|
2364
|
+
await super.init(config);
|
|
2365
|
+
await Promise.all(toArray.toArray(this.config.userConfig.environments && Object.keys(this.config.userConfig.environments).length > 0 ? Object.keys(this.config.userConfig.environments).map((name) => createEnvironment(name, this.config.userConfig)) : createDefaultEnvironment(this.config.userConfig)).map(async (env) => {
|
|
2366
|
+
this.#environments[env.name] = await this.in(env);
|
|
2367
|
+
}));
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* A function to copy the context and update the fields for a specific environment
|
|
2371
|
+
*
|
|
2372
|
+
* @param environment - The environment configuration to use.
|
|
2373
|
+
* @returns A new context instance with the updated environment.
|
|
2374
|
+
*/
|
|
2375
|
+
async in(environment) {
|
|
2376
|
+
let context;
|
|
2377
|
+
if (this.environments[environment.name]) {
|
|
2378
|
+
context = this.environments[environment.name];
|
|
2379
|
+
} else {
|
|
2380
|
+
context = await PowerlinesEnvironmentContext.fromConfig(this.workspaceConfig, this.config);
|
|
2381
|
+
}
|
|
2382
|
+
if (isSetObject.isSetObject(this.config.inlineConfig)) {
|
|
2383
|
+
await context.withInlineConfig(this.config.inlineConfig);
|
|
2384
|
+
}
|
|
2385
|
+
context.environment = environment;
|
|
2386
|
+
context.plugins = [];
|
|
2387
|
+
for (const plugin of this.plugins) {
|
|
2388
|
+
await context.addPlugin(plugin);
|
|
2389
|
+
}
|
|
2390
|
+
return context;
|
|
2391
|
+
}
|
|
2392
|
+
async addPlugin(plugin) {
|
|
2393
|
+
this.plugins.push(plugin);
|
|
2394
|
+
await Promise.all(Object.keys(this.environments).map(async (name) => {
|
|
2395
|
+
await this.environments[name].addPlugin(plugin);
|
|
2396
|
+
}));
|
|
2397
|
+
}
|
|
2398
|
+
async getEnvironment(name) {
|
|
2399
|
+
let environment;
|
|
2400
|
+
if (name) {
|
|
2401
|
+
environment = this.environments[name];
|
|
2402
|
+
}
|
|
2403
|
+
if (Object.keys(this.environments).length === 1) {
|
|
2404
|
+
environment = this.environments[Object.keys(this.environments)[0]];
|
|
2405
|
+
this.log(types.LogLevelLabel.DEBUG, `Applying the only configured environment: ${chalk5__default.default.bold.cyanBright(environment?.environment.name)}`);
|
|
2406
|
+
}
|
|
2407
|
+
if (!environment) {
|
|
2408
|
+
if (name) {
|
|
2409
|
+
throw new Error(`Environment "${name}" not found.`);
|
|
2410
|
+
}
|
|
2411
|
+
environment = await this.in(createDefaultEnvironment(this.config.userConfig));
|
|
2412
|
+
this.log(types.LogLevelLabel.WARN, `No environment specified, and no default environment found. Using a temporary default environment: ${chalk5__default.default.bold.cyanBright(environment?.environment.name)}`);
|
|
2413
|
+
}
|
|
2414
|
+
return environment;
|
|
2415
|
+
}
|
|
2416
|
+
async getEnvironmentSafe(name) {
|
|
2417
|
+
try {
|
|
2418
|
+
return await this.getEnvironment(name);
|
|
2419
|
+
} catch {
|
|
2420
|
+
return void 0;
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
};
|
|
2424
|
+
async function installPackage(context, packageName, dev = false) {
|
|
2425
|
+
const isListed = await packageFns.isPackageListed(packageName, {
|
|
2426
|
+
cwd: context.config.projectRoot
|
|
2427
|
+
});
|
|
2428
|
+
if (!isListed) {
|
|
2429
|
+
if (context.config.skipInstalls !== true && !process.env.POWERLINES_LOCAL) {
|
|
2430
|
+
context.log(types.LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`);
|
|
2431
|
+
const result = await install.install(packageName, {
|
|
2432
|
+
cwd: context.config.projectRoot,
|
|
2433
|
+
dev
|
|
2434
|
+
});
|
|
2435
|
+
if (isNumber.isNumber(result.exitCode) && result.exitCode > 0) {
|
|
2436
|
+
context.log(types.LogLevelLabel.ERROR, result.stderr);
|
|
2437
|
+
throw new Error(`An error occurred while installing the package "${packageName}"`);
|
|
2438
|
+
}
|
|
2439
|
+
} else {
|
|
2440
|
+
context.log(types.LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`);
|
|
2441
|
+
}
|
|
2442
|
+
} else if (_package.hasPackageVersion(packageName) && !process.env.STORM_STACK_SKIP_VERSION_CHECK) {
|
|
2443
|
+
const isMatching = await packageFns.doesPackageMatch(_package.getPackageName(packageName), _package.getPackageVersion(packageName), context.config.projectRoot);
|
|
2444
|
+
if (!isMatching) {
|
|
2445
|
+
const packageListing = await packageFns.getPackageListing(_package.getPackageName(packageName), {
|
|
2446
|
+
cwd: context.config.projectRoot
|
|
2447
|
+
});
|
|
2448
|
+
if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) {
|
|
2449
|
+
context.log(types.LogLevelLabel.WARN, `The package "${_package.getPackageName(packageName)}" is installed but does not match the expected version ${_package.getPackageVersion(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`);
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
chunkSHUYVCID_js.__name(installPackage, "installPackage");
|
|
2455
|
+
async function installPackages(context, packages) {
|
|
2456
|
+
return Promise.all(packages.map(async (pkg) => installPackage(context, pkg.name, pkg.dev)));
|
|
2457
|
+
}
|
|
2458
|
+
chunkSHUYVCID_js.__name(installPackages, "installPackages");
|
|
2459
|
+
|
|
2460
|
+
// ../powerlines/src/internal/helpers/eslint.ts
|
|
2461
|
+
var MessageSeverity;
|
|
2462
|
+
(function(MessageSeverity2) {
|
|
2463
|
+
MessageSeverity2[MessageSeverity2["Warning"] = 1] = "Warning";
|
|
2464
|
+
MessageSeverity2[MessageSeverity2["Error"] = 2] = "Error";
|
|
2465
|
+
})(MessageSeverity || (MessageSeverity = {}));
|
|
2466
|
+
function pluginCount(messages) {
|
|
2467
|
+
let nextPluginWarningCount = 0;
|
|
2468
|
+
let nextPluginErrorCount = 0;
|
|
2469
|
+
for (let i = 0; i < messages.length; i++) {
|
|
2470
|
+
const { severity, ruleId } = messages[i];
|
|
2471
|
+
if (ruleId?.includes("powerlines")) {
|
|
2472
|
+
if (severity === 1) {
|
|
2473
|
+
nextPluginWarningCount += 1;
|
|
2474
|
+
} else {
|
|
2475
|
+
nextPluginErrorCount += 1;
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
return {
|
|
2480
|
+
nextPluginErrorCount,
|
|
2481
|
+
nextPluginWarningCount
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
chunkSHUYVCID_js.__name(pluginCount, "pluginCount");
|
|
2485
|
+
function formatMessage(dir, messages, filePath) {
|
|
2486
|
+
let fileName = path__default.default.posix.normalize(path__default.default.relative(dir, filePath).replace(/\\/g, "/"));
|
|
2487
|
+
if (!fileName.startsWith(".")) {
|
|
2488
|
+
fileName = `./${fileName}`;
|
|
2489
|
+
}
|
|
2490
|
+
let output = `
|
|
2491
|
+
${fileName}`;
|
|
2492
|
+
for (let i = 0; i < messages.length; i++) {
|
|
2493
|
+
const { message, severity, line, column, ruleId } = messages[i];
|
|
2494
|
+
output += "\n";
|
|
2495
|
+
if (line && column) {
|
|
2496
|
+
output = `${output + line.toString()}:${column.toString()} `;
|
|
2497
|
+
}
|
|
2498
|
+
if (severity === 1) {
|
|
2499
|
+
output += `Warning: `;
|
|
2500
|
+
} else {
|
|
2501
|
+
output += `Error: `;
|
|
2502
|
+
}
|
|
2503
|
+
output += message;
|
|
2504
|
+
if (ruleId) {
|
|
2505
|
+
output += ` ${ruleId}`;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
return output;
|
|
2509
|
+
}
|
|
2510
|
+
chunkSHUYVCID_js.__name(formatMessage, "formatMessage");
|
|
2511
|
+
async function formatResults(baseDir, results, format3) {
|
|
2512
|
+
let totalPluginErrorCount = 0;
|
|
2513
|
+
let totalPluginWarningCount = 0;
|
|
2514
|
+
const resultsWithMessages = results.filter(({ messages }) => messages?.length);
|
|
2515
|
+
resultsWithMessages.forEach(({ messages }) => {
|
|
2516
|
+
const res = pluginCount(messages);
|
|
2517
|
+
totalPluginErrorCount += res.nextPluginErrorCount;
|
|
2518
|
+
totalPluginWarningCount += res.nextPluginWarningCount;
|
|
2519
|
+
});
|
|
2520
|
+
const output = format3 ? await format3(resultsWithMessages) : resultsWithMessages.map(({ messages, filePath }) => formatMessage(baseDir, messages, filePath)).join("\n");
|
|
2521
|
+
return {
|
|
2522
|
+
output,
|
|
2523
|
+
outputWithMessages: resultsWithMessages.length > 0 ? `${output}
|
|
2524
|
+
|
|
2525
|
+
Info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/app/api-reference/config/eslint#disabling-rules` : "",
|
|
2526
|
+
totalPluginErrorCount,
|
|
2527
|
+
totalPluginWarningCount
|
|
2528
|
+
};
|
|
2529
|
+
}
|
|
2530
|
+
chunkSHUYVCID_js.__name(formatResults, "formatResults");
|
|
2531
|
+
async function writeDefaultEslintConfig(log, context, type = "recommended") {
|
|
2532
|
+
const eslintConfigFile = joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, "eslint.config.js");
|
|
2533
|
+
const eslintConfig = `
|
|
2534
|
+
import { getConfig } from "eslint-config-powerlines";
|
|
2535
|
+
|
|
2536
|
+
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
|
|
2537
|
+
|
|
2538
|
+
export default getConfig({
|
|
2539
|
+
repositoryName: "${context.workspaceConfig.name || context.config.name || "powerlines"}",
|
|
2540
|
+
"powerlines": "${type}",
|
|
2541
|
+
});
|
|
2542
|
+
`;
|
|
2543
|
+
log(types.LogLevelLabel.INFO, `Writing a default ESLint config file to ${eslintConfigFile}`);
|
|
2544
|
+
return writeFile2(log, eslintConfigFile, eslintConfig);
|
|
2545
|
+
}
|
|
2546
|
+
chunkSHUYVCID_js.__name(writeDefaultEslintConfig, "writeDefaultEslintConfig");
|
|
2547
|
+
var VALID_SEVERITY = [
|
|
2548
|
+
"off",
|
|
2549
|
+
"warn",
|
|
2550
|
+
"error"
|
|
2551
|
+
];
|
|
2552
|
+
function isValidSeverity(severity) {
|
|
2553
|
+
return VALID_SEVERITY.includes(severity);
|
|
2554
|
+
}
|
|
2555
|
+
chunkSHUYVCID_js.__name(isValidSeverity, "isValidSeverity");
|
|
2556
|
+
async function writeOutputFile(log, outputFile, outputData) {
|
|
2557
|
+
const filePath = path__default.default.resolve(process.cwd(), outputFile);
|
|
2558
|
+
if (isFile.isDirectory(filePath)) {
|
|
2559
|
+
log(types.LogLevelLabel.ERROR, `Cannot write to output file path, it is a directory: ${filePath}`);
|
|
2560
|
+
} else {
|
|
2561
|
+
try {
|
|
2562
|
+
await writeFile2(log, filePath, outputData);
|
|
2563
|
+
log(types.LogLevelLabel.INFO, `The output file has been created: ${filePath}`);
|
|
2564
|
+
} catch (err) {
|
|
2565
|
+
log(types.LogLevelLabel.ERROR, `There was a problem writing the output file: ${filePath}`);
|
|
2566
|
+
console.error(err);
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
chunkSHUYVCID_js.__name(writeOutputFile, "writeOutputFile");
|
|
2571
|
+
async function hasEslintConfiguration(eslintFile, packageJsonConfig) {
|
|
2572
|
+
const configObject = {
|
|
2573
|
+
exists: false,
|
|
2574
|
+
emptyEslint: false,
|
|
2575
|
+
emptyPkgJsonConfig: false
|
|
2576
|
+
};
|
|
2577
|
+
if (eslintFile) {
|
|
2578
|
+
const content = await readFile.readFile(eslintFile).then((txt) => txt.trim().replace(/\n/g, ""), () => null);
|
|
2579
|
+
if (content === "" || content === "{}" || content === "---" || content === "module.exports = {}") {
|
|
2580
|
+
configObject.emptyEslint = true;
|
|
2581
|
+
} else {
|
|
2582
|
+
configObject.exists = true;
|
|
2583
|
+
}
|
|
2584
|
+
} else if (packageJsonConfig?.eslintConfig) {
|
|
2585
|
+
if (Object.keys(packageJsonConfig.eslintConfig).length) {
|
|
2586
|
+
configObject.exists = true;
|
|
2587
|
+
} else {
|
|
2588
|
+
configObject.emptyPkgJsonConfig = true;
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
return configObject;
|
|
2592
|
+
}
|
|
2593
|
+
chunkSHUYVCID_js.__name(hasEslintConfiguration, "hasEslintConfiguration");
|
|
2594
|
+
var lint = /* @__PURE__ */ chunkSHUYVCID_js.__name(async (log, context, eslintConfigPath, { lintDuringBuild = false, eslintOptions = null, reportErrorsOnly = false, maxWarnings = -1, formatter = null, outputFile = null }) => {
|
|
2595
|
+
try {
|
|
2596
|
+
await installPackages(context, [
|
|
2597
|
+
{
|
|
2598
|
+
name: "eslint",
|
|
2599
|
+
dev: true
|
|
2600
|
+
},
|
|
2601
|
+
{
|
|
2602
|
+
name: "eslint-config-powerlines",
|
|
2603
|
+
dev: true
|
|
2604
|
+
}
|
|
2605
|
+
]);
|
|
2606
|
+
const isInstalled = packageFns.isPackageExists("eslint", {
|
|
2607
|
+
paths: [
|
|
2608
|
+
context.workspaceConfig.workspaceRoot,
|
|
2609
|
+
context.config.projectRoot
|
|
2610
|
+
]
|
|
2611
|
+
});
|
|
2612
|
+
if (!isInstalled) {
|
|
2613
|
+
log(types.LogLevelLabel.ERROR, `ESLint must be installed${lintDuringBuild ? " in order to run during builds:" : ":"} npm install --save-dev eslint`);
|
|
2614
|
+
return null;
|
|
2615
|
+
}
|
|
2616
|
+
const module = await context.resolver.import(context.resolver.esmResolve("eslint"));
|
|
2617
|
+
const useFlatConfig = eslintConfigPath ? filePathFns.findFileName(eslintConfigPath).startsWith("eslint.config.") : false;
|
|
2618
|
+
let ESLint;
|
|
2619
|
+
if ("loadESLint" in module) {
|
|
2620
|
+
ESLint = await module.loadESLint({
|
|
2621
|
+
useFlatConfig
|
|
2622
|
+
});
|
|
2623
|
+
}
|
|
2624
|
+
const eslintVersion = semverFns.parseVersion(ESLint?.version);
|
|
2625
|
+
if (!eslintVersion || eslintVersion.compare("8.57.0") < 0) {
|
|
2626
|
+
return `Error - Your project has an older version of ESLint installed${eslintVersion ? ` (${eslintVersion.major}.${eslintVersion.minor}.${eslintVersion.patch})` : ""}. Please upgrade to ESLint version 8.57.0 or above`;
|
|
2627
|
+
}
|
|
2628
|
+
const options = {
|
|
2629
|
+
useEslintrc: true,
|
|
2630
|
+
baseConfig: {},
|
|
2631
|
+
errorOnUnmatchedPattern: false,
|
|
2632
|
+
extensions: [
|
|
2633
|
+
".js",
|
|
2634
|
+
".jsx",
|
|
2635
|
+
".ts",
|
|
2636
|
+
".tsx"
|
|
2637
|
+
],
|
|
2638
|
+
cache: true,
|
|
2639
|
+
...eslintOptions
|
|
2640
|
+
};
|
|
2641
|
+
if (eslintVersion?.compare("9.0.0") && useFlatConfig) {
|
|
2642
|
+
for (const option of [
|
|
2643
|
+
"useEslintrc",
|
|
2644
|
+
"extensions",
|
|
2645
|
+
"ignorePath",
|
|
2646
|
+
"reportUnusedDisableDirectives",
|
|
2647
|
+
"resolvePluginsRelativeTo",
|
|
2648
|
+
"rulePaths",
|
|
2649
|
+
"inlineConfig",
|
|
2650
|
+
"maxWarnings"
|
|
2651
|
+
]) {
|
|
2652
|
+
if (option in options) {
|
|
2653
|
+
delete options[option];
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
let eslint2 = new ESLint(options);
|
|
2658
|
+
let stormStackEslintPluginIsEnabled = false;
|
|
2659
|
+
const stormStackRulesEnabled = /* @__PURE__ */ new Map();
|
|
2660
|
+
for (const configFile of [
|
|
2661
|
+
eslintConfigPath,
|
|
2662
|
+
joinPaths.joinPaths(context.config.projectRoot, "package.json")
|
|
2663
|
+
]) {
|
|
2664
|
+
if (!configFile) continue;
|
|
2665
|
+
const completeConfig = await eslint2.calculateConfigForFile(configFile);
|
|
2666
|
+
if (!completeConfig) continue;
|
|
2667
|
+
const plugins2 = completeConfig.plugins;
|
|
2668
|
+
const hasStormStackPlugin = (
|
|
2669
|
+
// in ESLint < 9, `plugins` value is string[]
|
|
2670
|
+
Array.isArray(plugins2) ? plugins2.includes("powerlines") : "powerlines" in plugins2
|
|
2671
|
+
);
|
|
2672
|
+
if (hasStormStackPlugin) {
|
|
2673
|
+
stormStackEslintPluginIsEnabled = true;
|
|
2674
|
+
for (const [name, [severity]] of Object.entries(completeConfig.rules)) {
|
|
2675
|
+
if (!name.startsWith("powerlines/")) {
|
|
2676
|
+
continue;
|
|
2677
|
+
}
|
|
2678
|
+
if (typeof severity === "number" && severity >= 0 && severity < VALID_SEVERITY.length) {
|
|
2679
|
+
stormStackRulesEnabled.set(name, VALID_SEVERITY[severity]);
|
|
2680
|
+
} else if (typeof severity === "string" && isValidSeverity(severity)) {
|
|
2681
|
+
stormStackRulesEnabled.set(name, severity);
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
break;
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
if (stormStackEslintPluginIsEnabled) {
|
|
2688
|
+
eslint2 = new ESLint(options);
|
|
2689
|
+
} else {
|
|
2690
|
+
log(types.LogLevelLabel.WARN, "The Powerlines plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/app/api-reference/config/eslint#migrating-existing-config");
|
|
2691
|
+
}
|
|
2692
|
+
const lintStart = process.hrtime();
|
|
2693
|
+
let results = await eslint2.lintFiles(context.tsconfig.fileNames.filter((fileName) => !fileName.includes(context.artifactsPath) && !fileName.includes("node_modules")));
|
|
2694
|
+
let selectedFormatter = null;
|
|
2695
|
+
if (options.fix) {
|
|
2696
|
+
await ESLint.outputFixes(results);
|
|
2697
|
+
}
|
|
2698
|
+
if (reportErrorsOnly) {
|
|
2699
|
+
results = ESLint.getErrorResults(results);
|
|
2700
|
+
}
|
|
2701
|
+
if (formatter) {
|
|
2702
|
+
selectedFormatter = await eslint2.loadFormatter(formatter);
|
|
2703
|
+
}
|
|
2704
|
+
const formattedResult = await formatResults(context.config.projectRoot, results, selectedFormatter?.format?.bind(selectedFormatter));
|
|
2705
|
+
const lintEnd = process.hrtime(lintStart);
|
|
2706
|
+
const totalWarnings = results.reduce((sum, file) => sum + file.warningCount, 0);
|
|
2707
|
+
if (outputFile) {
|
|
2708
|
+
await writeOutputFile(log, outputFile, formattedResult.output);
|
|
2709
|
+
}
|
|
2710
|
+
return {
|
|
2711
|
+
output: formattedResult.outputWithMessages,
|
|
2712
|
+
isError: ESLint.getErrorResults(results)?.length > 0 || maxWarnings >= 0 && totalWarnings > maxWarnings,
|
|
2713
|
+
eventInfo: {
|
|
2714
|
+
durationInSeconds: lintEnd[0],
|
|
2715
|
+
eslintVersion: eslintVersion.version,
|
|
2716
|
+
lintedFilesCount: results.length,
|
|
2717
|
+
lintFix: !!options.fix,
|
|
2718
|
+
eslintPluginErrorsCount: formattedResult.totalPluginErrorCount,
|
|
2719
|
+
eslintPluginWarningsCount: formattedResult.totalPluginWarningCount,
|
|
2720
|
+
stormStackRulesEnabled: Object.fromEntries(stormStackRulesEnabled)
|
|
2721
|
+
}
|
|
2722
|
+
};
|
|
2723
|
+
} catch (err) {
|
|
2724
|
+
if (lintDuringBuild) {
|
|
2725
|
+
log(types.LogLevelLabel.ERROR, `ESLint: ${isError.isError(err) && err.message ? err.message.replace(/\n/g, " ") : String(err)}`);
|
|
2726
|
+
return null;
|
|
2727
|
+
} else {
|
|
2728
|
+
throw err;
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
}, "lint");
|
|
2732
|
+
async function eslint(context, lintDuringBuild = false, opts = {}) {
|
|
2733
|
+
const { eslintOptions = null, reportErrorsOnly = false, maxWarnings = -1, formatter = null, outputFile = null, type = "recommended" } = opts;
|
|
2734
|
+
const eslintFile = getParentPath.getParentPath([
|
|
2735
|
+
// eslint v9
|
|
2736
|
+
"eslint.config.js",
|
|
2737
|
+
"eslint.config.mjs",
|
|
2738
|
+
"eslint.config.cjs",
|
|
2739
|
+
// TS extensions require to install a separate package `jiti`.
|
|
2740
|
+
// https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files
|
|
2741
|
+
"eslint.config.ts",
|
|
2742
|
+
"eslint.config.mts",
|
|
2743
|
+
"eslint.config.cts",
|
|
2744
|
+
// eslint <= v8
|
|
2745
|
+
".eslintrc.js",
|
|
2746
|
+
".eslintrc.cjs",
|
|
2747
|
+
".eslintrc.yaml",
|
|
2748
|
+
".eslintrc.yml",
|
|
2749
|
+
".eslintrc.json",
|
|
2750
|
+
".eslintrc"
|
|
2751
|
+
], context.config.projectRoot) ?? null;
|
|
2752
|
+
const config = await hasEslintConfiguration(eslintFile, context.packageJson);
|
|
2753
|
+
if (config.exists) {
|
|
2754
|
+
return lint(context.log, context, eslintFile, {
|
|
2755
|
+
lintDuringBuild,
|
|
2756
|
+
eslintOptions,
|
|
2757
|
+
reportErrorsOnly,
|
|
2758
|
+
maxWarnings,
|
|
2759
|
+
formatter,
|
|
2760
|
+
outputFile
|
|
2761
|
+
});
|
|
2762
|
+
}
|
|
2763
|
+
if (lintDuringBuild) {
|
|
2764
|
+
if (config.emptyPkgJsonConfig || config.emptyEslint) {
|
|
2765
|
+
context.log(types.LogLevelLabel.WARN, `No ESLint configuration detected. Run "storm lint" to begin setup`);
|
|
2766
|
+
}
|
|
2767
|
+
return null;
|
|
2768
|
+
} else {
|
|
2769
|
+
const isEslintInstalled = packageFns.isPackageExists("eslint", {
|
|
2770
|
+
paths: [
|
|
2771
|
+
context.workspaceConfig.workspaceRoot,
|
|
2772
|
+
context.config.projectRoot
|
|
2773
|
+
]
|
|
2774
|
+
});
|
|
2775
|
+
const isEslintPluginInstalled = packageFns.isPackageExists("eslint-config-powerlines", {
|
|
2776
|
+
paths: [
|
|
2777
|
+
context.workspaceConfig.workspaceRoot,
|
|
2778
|
+
context.config.projectRoot
|
|
2779
|
+
]
|
|
2780
|
+
});
|
|
2781
|
+
if (!isEslintInstalled || !isEslintPluginInstalled) {
|
|
2782
|
+
await installPackages(context, [
|
|
2783
|
+
{
|
|
2784
|
+
name: "eslint",
|
|
2785
|
+
dev: true
|
|
2786
|
+
},
|
|
2787
|
+
{
|
|
2788
|
+
name: "eslint-config-powerlines",
|
|
2789
|
+
dev: true
|
|
2790
|
+
}
|
|
2791
|
+
]);
|
|
2792
|
+
}
|
|
2793
|
+
await writeDefaultEslintConfig(context.log, context, type);
|
|
2794
|
+
}
|
|
2795
|
+
context.log(types.LogLevelLabel.SUCCESS, `ESLint has successfully been configured. Run "storm lint" again to view warnings and errors.`);
|
|
2796
|
+
return null;
|
|
2797
|
+
}
|
|
2798
|
+
chunkSHUYVCID_js.__name(eslint, "eslint");
|
|
2799
|
+
function getString(code) {
|
|
2800
|
+
if (!code) {
|
|
2801
|
+
return "";
|
|
2802
|
+
}
|
|
2803
|
+
if (isString.isString(code)) {
|
|
2804
|
+
return code;
|
|
2805
|
+
}
|
|
2806
|
+
if (isSetObject.isSetObject(code) && "code" in code) {
|
|
2807
|
+
return code.code;
|
|
2808
|
+
}
|
|
2809
|
+
return code.toString();
|
|
2810
|
+
}
|
|
2811
|
+
chunkSHUYVCID_js.__name(getString, "getString");
|
|
2812
|
+
function getMagicString(code) {
|
|
2813
|
+
if (isString.isString(code)) {
|
|
2814
|
+
return new MagicString__default.default(code);
|
|
2815
|
+
}
|
|
2816
|
+
return code;
|
|
2817
|
+
}
|
|
2818
|
+
chunkSHUYVCID_js.__name(getMagicString, "getMagicString");
|
|
2819
|
+
function getSourceFile(code, id) {
|
|
2820
|
+
const content = code ?? readFile.readFileIfExistingSync(id);
|
|
2821
|
+
return {
|
|
2822
|
+
id,
|
|
2823
|
+
code: getMagicString(content),
|
|
2824
|
+
env: []
|
|
2825
|
+
};
|
|
2826
|
+
}
|
|
2827
|
+
chunkSHUYVCID_js.__name(getSourceFile, "getSourceFile");
|
|
2828
|
+
function resolveModulePath(nodePath, state) {
|
|
2829
|
+
if (!t__namespace.isStringLiteral(nodePath.node)) {
|
|
2830
|
+
return;
|
|
2831
|
+
}
|
|
2832
|
+
const sourcePath = nodePath.node.value;
|
|
2833
|
+
const resolvedPath = state.context?.fs.resolvePath(sourcePath);
|
|
2834
|
+
if (resolvedPath) {
|
|
2835
|
+
nodePath.replaceWith(t__namespace.stringLiteral(
|
|
2836
|
+
// Remove the file extension if it exists
|
|
2837
|
+
resolvedPath.replace(/\.(?:ts|mts|cts)x?$/, "")
|
|
2838
|
+
));
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
chunkSHUYVCID_js.__name(resolveModulePath, "resolveModulePath");
|
|
2842
|
+
var TRANSFORM_FUNCTIONS = [
|
|
2843
|
+
"require",
|
|
2844
|
+
"require.resolve",
|
|
2845
|
+
"System.import",
|
|
2846
|
+
// Jest methods
|
|
2847
|
+
"jest.genMockFromModule",
|
|
2848
|
+
"jest.mock",
|
|
2849
|
+
"jest.unmock",
|
|
2850
|
+
"jest.doMock",
|
|
2851
|
+
// eslint-disable-next-line @cspell/spellchecker
|
|
2852
|
+
"jest.dontMock",
|
|
2853
|
+
"jest.setMock",
|
|
2854
|
+
"jest.requireActual",
|
|
2855
|
+
"jest.requireMock",
|
|
2856
|
+
// Older Jest methods
|
|
2857
|
+
"require.requireActual",
|
|
2858
|
+
"require.requireMock"
|
|
2859
|
+
];
|
|
2860
|
+
function matchesPattern(state, calleePath, pattern) {
|
|
2861
|
+
const { node } = calleePath;
|
|
2862
|
+
if (t__namespace.isMemberExpression(node)) {
|
|
2863
|
+
return calleePath.matchesPattern(pattern);
|
|
2864
|
+
}
|
|
2865
|
+
if (!t__namespace.isIdentifier(node) || pattern.includes(".")) {
|
|
2866
|
+
return false;
|
|
2867
|
+
}
|
|
2868
|
+
const name = pattern.split(".")[0];
|
|
2869
|
+
return node.name === name;
|
|
2870
|
+
}
|
|
2871
|
+
chunkSHUYVCID_js.__name(matchesPattern, "matchesPattern");
|
|
2872
|
+
var importVisitors = {
|
|
2873
|
+
CallExpression: /* @__PURE__ */ chunkSHUYVCID_js.__name((nodePath, state) => {
|
|
2874
|
+
if (state.moduleResolverVisited.has(nodePath)) {
|
|
2875
|
+
return;
|
|
2876
|
+
}
|
|
2877
|
+
const calleePath = nodePath.get("callee");
|
|
2878
|
+
if (calleePath && TRANSFORM_FUNCTIONS.some((pattern) => matchesPattern(state, calleePath, pattern)) || t__namespace.isImport(nodePath.node.callee)) {
|
|
2879
|
+
state.moduleResolverVisited.add(nodePath);
|
|
2880
|
+
resolveModulePath(nodePath.get("arguments.0"), state);
|
|
2881
|
+
}
|
|
2882
|
+
}, "CallExpression"),
|
|
2883
|
+
// eslint-disable-next-line ts/naming-convention
|
|
2884
|
+
"ImportDeclaration|ExportDeclaration|ExportAllDeclaration": /* @__PURE__ */ chunkSHUYVCID_js.__name((nodePath, state) => {
|
|
2885
|
+
if (!nodePath || !nodePath.get("source") || state.moduleResolverVisited.has(nodePath)) {
|
|
2886
|
+
return;
|
|
2887
|
+
}
|
|
2888
|
+
state.moduleResolverVisited.add(nodePath);
|
|
2889
|
+
resolveModulePath(nodePath.get("source"), state);
|
|
2890
|
+
}, "ImportDeclaration|ExportDeclaration|ExportAllDeclaration")
|
|
2891
|
+
};
|
|
2892
|
+
var moduleResolverBabelPlugin = /* @__PURE__ */ chunkSHUYVCID_js.__name((context) => {
|
|
2893
|
+
return helperPluginUtils.declare(/* @__PURE__ */ chunkSHUYVCID_js.__name(function builder(api) {
|
|
2894
|
+
let moduleResolverVisited = /* @__PURE__ */ new Set();
|
|
2895
|
+
return {
|
|
2896
|
+
name: "powerlines:module-resolver",
|
|
2897
|
+
manipulateOptions(opts) {
|
|
2898
|
+
opts.filename ??= "unknown";
|
|
2899
|
+
},
|
|
2900
|
+
pre() {
|
|
2901
|
+
moduleResolverVisited = /* @__PURE__ */ new Set();
|
|
2902
|
+
},
|
|
2903
|
+
visitor: {
|
|
2904
|
+
Program: {
|
|
2905
|
+
enter(programPath, state) {
|
|
2906
|
+
programPath.traverse(importVisitors, {
|
|
2907
|
+
...state,
|
|
2908
|
+
context,
|
|
2909
|
+
moduleResolverVisited,
|
|
2910
|
+
api
|
|
2911
|
+
});
|
|
2912
|
+
},
|
|
2913
|
+
exit(programPath, state) {
|
|
2914
|
+
programPath.traverse(importVisitors, {
|
|
2915
|
+
...state,
|
|
2916
|
+
context,
|
|
2917
|
+
moduleResolverVisited,
|
|
2918
|
+
api
|
|
2919
|
+
});
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
},
|
|
2923
|
+
post() {
|
|
2924
|
+
moduleResolverVisited.clear();
|
|
2925
|
+
}
|
|
2926
|
+
};
|
|
2927
|
+
}, "builder"));
|
|
2928
|
+
}, "moduleResolverBabelPlugin");
|
|
2929
|
+
|
|
2930
|
+
// ../powerlines/src/internal/helpers/generate-types.ts
|
|
2931
|
+
async function generateTypes(context) {
|
|
2932
|
+
context.log(types.LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
|
|
2933
|
+
context.log(types.LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
|
|
2934
|
+
const builtinFiles = await Promise.all((await context.fs.listBuiltinFiles()).filter((file) => !context.fs.isMatchingBuiltinId("index", file.id)).map(async (file) => {
|
|
2935
|
+
const result = await core.transformAsync(file.contents, {
|
|
2936
|
+
highlightCode: true,
|
|
2937
|
+
code: true,
|
|
2938
|
+
ast: false,
|
|
2939
|
+
cloneInputAst: false,
|
|
2940
|
+
comments: true,
|
|
2941
|
+
sourceType: "module",
|
|
2942
|
+
configFile: false,
|
|
2943
|
+
babelrc: false,
|
|
2944
|
+
envName: context.config.mode,
|
|
2945
|
+
caller: {
|
|
2946
|
+
name: "powerlines"
|
|
2947
|
+
},
|
|
2948
|
+
...context.config.transform.babel,
|
|
2949
|
+
filename: file.path,
|
|
2950
|
+
plugins: [
|
|
2951
|
+
[
|
|
2952
|
+
"@babel/plugin-syntax-typescript"
|
|
2953
|
+
],
|
|
2954
|
+
[
|
|
2955
|
+
moduleResolverBabelPlugin(context)
|
|
2956
|
+
]
|
|
2957
|
+
]
|
|
2958
|
+
});
|
|
2959
|
+
if (!result?.code) {
|
|
2960
|
+
throw new Error(`Powerlines - Generate Types failed to compile ${file.id}`);
|
|
2961
|
+
}
|
|
2962
|
+
context.log(types.LogLevelLabel.TRACE, `Writing transformed built-in runtime file ${file.id}.`);
|
|
2963
|
+
await context.fs.writeBuiltinFile(file.id, file.path, result.code);
|
|
2964
|
+
return file.path;
|
|
2965
|
+
}));
|
|
2966
|
+
const typescriptPath = await resolve.resolvePackage("typescript");
|
|
2967
|
+
if (!typescriptPath) {
|
|
2968
|
+
throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
|
|
2969
|
+
}
|
|
2970
|
+
const files = builtinFiles.reduce((ret, fileName) => {
|
|
2971
|
+
const formatted = replace.replacePath(fileName, context.workspaceConfig.workspaceRoot);
|
|
2972
|
+
if (!ret.includes(formatted)) {
|
|
2973
|
+
ret.push(formatted);
|
|
2974
|
+
}
|
|
2975
|
+
return ret;
|
|
2976
|
+
}, [
|
|
2977
|
+
joinPaths.joinPaths(typescriptPath, "lib", "lib.esnext.full.d.ts")
|
|
2978
|
+
]);
|
|
2979
|
+
context.log(types.LogLevelLabel.TRACE, "Parsing TypeScript configuration for the Powerlines project.");
|
|
2980
|
+
const resolvedTsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.tsconfig.tsconfigFilePath, defu4__default.default({
|
|
2981
|
+
compilerOptions: {
|
|
2982
|
+
strict: false,
|
|
2983
|
+
noEmit: false,
|
|
2984
|
+
declaration: true,
|
|
2985
|
+
declarationMap: false,
|
|
2986
|
+
emitDeclarationOnly: true,
|
|
2987
|
+
skipLibCheck: true
|
|
2988
|
+
},
|
|
2989
|
+
exclude: [
|
|
2990
|
+
"node_modules",
|
|
2991
|
+
"dist"
|
|
2992
|
+
],
|
|
2993
|
+
include: files
|
|
2994
|
+
}, context.config.tsconfigRaw ?? {}));
|
|
2995
|
+
resolvedTsconfig.options.configFilePath = joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.tsconfig.tsconfigFilePath);
|
|
2996
|
+
resolvedTsconfig.options.pathsBasePath = context.workspaceConfig.workspaceRoot;
|
|
2997
|
+
resolvedTsconfig.options.suppressOutputPathCheck = true;
|
|
2998
|
+
context.log(types.LogLevelLabel.TRACE, "Creating the TypeScript compiler host");
|
|
2999
|
+
const program = ts3.createProgram(files, resolvedTsconfig.options, ts3.createCompilerHost(resolvedTsconfig.options));
|
|
3000
|
+
context.log(types.LogLevelLabel.TRACE, `Running TypeScript compiler on ${builtinFiles.length} built-in runtime files.`);
|
|
3001
|
+
let builtinModules = "";
|
|
3002
|
+
const emitResult = program.emit(void 0, (fileName, text, _, __, sourceFiles, _data) => {
|
|
3003
|
+
const sourceFile2 = sourceFiles?.[0];
|
|
3004
|
+
if (sourceFile2?.fileName && !fileName.endsWith(".map")) {
|
|
3005
|
+
if (context.fs.isBuiltinFile(sourceFile2.fileName)) {
|
|
3006
|
+
builtinModules += `
|
|
3007
|
+
declare module "${context.fs.resolveId(sourceFile2.fileName)}" {
|
|
3008
|
+
${text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
|
|
3009
|
+
}
|
|
3010
|
+
`;
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
}, void 0, true);
|
|
3014
|
+
const diagnostics = ts3.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
3015
|
+
const diagnosticMessages = [];
|
|
3016
|
+
diagnostics.forEach((diagnostic) => {
|
|
3017
|
+
if (diagnostic.file) {
|
|
3018
|
+
const { line, character } = ts3.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
3019
|
+
const message = ts3.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
3020
|
+
diagnosticMessages.push(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
|
3021
|
+
} else {
|
|
3022
|
+
const message = ts3.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
3023
|
+
diagnosticMessages.push(message);
|
|
3024
|
+
}
|
|
3025
|
+
});
|
|
3026
|
+
const diagnosticMessage = diagnosticMessages.join("\n");
|
|
3027
|
+
if (diagnosticMessage) {
|
|
3028
|
+
throw new Error(`TypeScript compilation failed:
|
|
3029
|
+
|
|
3030
|
+
${diagnosticMessage.length > 5e3 ? `${diagnosticMessage.slice(0, 5e3)}...` : diagnosticMessage}`);
|
|
3031
|
+
}
|
|
3032
|
+
context.log(types.LogLevelLabel.TRACE, `Generating TypeScript declaration file in ${context.config.output.dts}.`);
|
|
3033
|
+
const sourceFile = getSourceFile(String(context.config.output.dts), `/// <reference types="powerlines/shared" />${context.config.build.platform !== "neutral" ? `
|
|
3034
|
+
/// <reference types="powerlines/${context.config.build.platform}" />` : ""}
|
|
3035
|
+
|
|
3036
|
+
${getFileHeader(null, false)}
|
|
3037
|
+
|
|
3038
|
+
${builtinModules}`.replace(
|
|
3039
|
+
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
|
3040
|
+
/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g,
|
|
3041
|
+
""
|
|
3042
|
+
).replaceAll("#private;", "").replace(/__Ω/g, ""));
|
|
3043
|
+
await context.fs.writeFileToDisk(sourceFile.id, getString(sourceFile.code));
|
|
3044
|
+
}
|
|
3045
|
+
chunkSHUYVCID_js.__name(generateTypes, "generateTypes");
|
|
3046
|
+
async function installDependencies(context) {
|
|
3047
|
+
context.log(types.LogLevelLabel.TRACE, `Checking and installing missing project dependencies.`);
|
|
3048
|
+
context.dependencies ??= {};
|
|
3049
|
+
context.dependencies["powerlines"] = {
|
|
3050
|
+
type: "dependency"
|
|
3051
|
+
};
|
|
3052
|
+
if (context.config.projectType === "application") {
|
|
3053
|
+
context.dependencies.unstorage = {
|
|
3054
|
+
type: "dependency"
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
context.log(types.LogLevelLabel.TRACE, `The following packages must be installed as dependencies:
|
|
3058
|
+
${Object.keys(context.dependencies).map((key) => ` - ${_package.getPackageName(key)}${_package.hasPackageVersion(key) || isSetObject.isSetObject(context.dependencies[key]) && isSetString.isSetString(context.dependencies[key].version) ? ` v${isSetObject.isSetObject(context.dependencies[key]) && isSetString.isSetString(context.dependencies[key].version) ? context.dependencies[key].version : _package.getPackageVersion(key)}` : ""} (${(isString.isString(context.dependencies[key]) ? context.dependencies[key] : context.dependencies[key]?.type) || "dependency"})`).join("\n")}`);
|
|
3059
|
+
for (const [key, value] of Object.entries(context.dependencies)) {
|
|
3060
|
+
const version = isSetObject.isSetObject(value) && semverFns.isValidRange(value.version) && value.version || _package.getPackageVersion(key);
|
|
3061
|
+
await installPackage(context, version ? `${_package.getPackageName(key)}@${String(version)}` : _package.getPackageName(key), (isSetString.isSetString(value) ? value : value.type) === "devDependency");
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
chunkSHUYVCID_js.__name(installDependencies, "installDependencies");
|
|
3065
|
+
async function resolveTsconfigChanges(context) {
|
|
3066
|
+
const tsconfig$1 = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw);
|
|
3067
|
+
const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
3068
|
+
const tsconfigJson = await json.readJsonFile(tsconfigFilePath);
|
|
3069
|
+
tsconfigJson.compilerOptions ??= {};
|
|
3070
|
+
const extendedTsconfig = await tsconfig.loadTsConfig(tsconfigFilePath);
|
|
3071
|
+
extendedTsconfig.compilerOptions ??= {};
|
|
3072
|
+
if (tsconfigJson.reflection !== true) {
|
|
3073
|
+
tsconfigJson.reflection = true;
|
|
3074
|
+
}
|
|
3075
|
+
if (tsconfig$1.options.experimentalDecorators !== true) {
|
|
3076
|
+
tsconfigJson.compilerOptions.experimentalDecorators = true;
|
|
3077
|
+
}
|
|
3078
|
+
if (tsconfig$1.options.emitDecoratorMetadata !== true) {
|
|
3079
|
+
tsconfigJson.compilerOptions.emitDecoratorMetadata = true;
|
|
3080
|
+
}
|
|
3081
|
+
if (context.config.output.dts) {
|
|
3082
|
+
const dtsFilePath = context.config.output.dts ? context.config.output.dts.startsWith(context.workspaceConfig.workspaceRoot) ? context.config.output.dts : joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.dts) : joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot, "storm.d.ts");
|
|
3083
|
+
const dtsRelativePath = joinPaths.joinPaths(filePathFns.relativePath(joinPaths.joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot), filePathFns.findFilePath(dtsFilePath)), filePathFns.findFileName(dtsFilePath));
|
|
3084
|
+
if (!tsconfigJson.include?.some((filePattern) => isIncludeMatchFound(filePattern, [
|
|
3085
|
+
dtsFilePath,
|
|
3086
|
+
dtsRelativePath,
|
|
3087
|
+
"storm.d.ts"
|
|
3088
|
+
]))) {
|
|
3089
|
+
tsconfigJson.include ??= [];
|
|
3090
|
+
tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
if (!tsconfig$1.options.lib?.some((lib) => [
|
|
3094
|
+
"lib.esnext.d.ts",
|
|
3095
|
+
"lib.es2021.d.ts",
|
|
3096
|
+
"lib.es2022.d.ts",
|
|
3097
|
+
"lib.es2023.d.ts"
|
|
3098
|
+
].includes(lib.toLowerCase()))) {
|
|
3099
|
+
tsconfigJson.compilerOptions.lib ??= [];
|
|
3100
|
+
tsconfigJson.compilerOptions.lib.push("esnext");
|
|
3101
|
+
}
|
|
3102
|
+
if (tsconfig$1.options.module !== ts3__default.default.ModuleKind.ESNext) {
|
|
3103
|
+
tsconfigJson.compilerOptions.module = "ESNext";
|
|
3104
|
+
}
|
|
3105
|
+
if (!tsconfig$1.options.target || ![
|
|
3106
|
+
ts3__default.default.ScriptTarget.ESNext,
|
|
3107
|
+
ts3__default.default.ScriptTarget.ES2024,
|
|
3108
|
+
ts3__default.default.ScriptTarget.ES2023,
|
|
3109
|
+
ts3__default.default.ScriptTarget.ES2022,
|
|
3110
|
+
ts3__default.default.ScriptTarget.ES2021
|
|
3111
|
+
].includes(tsconfig$1.options.target)) {
|
|
3112
|
+
tsconfigJson.compilerOptions.target = "ESNext";
|
|
3113
|
+
}
|
|
3114
|
+
if (tsconfig$1.options.moduleResolution !== ts3__default.default.ModuleResolutionKind.Bundler) {
|
|
3115
|
+
tsconfigJson.compilerOptions.moduleResolution = "Bundler";
|
|
3116
|
+
}
|
|
3117
|
+
if (tsconfig$1.options.moduleDetection !== ts3__default.default.ModuleDetectionKind.Force) {
|
|
3118
|
+
tsconfigJson.compilerOptions.moduleDetection = "force";
|
|
3119
|
+
}
|
|
3120
|
+
if (tsconfig$1.options.allowSyntheticDefaultImports !== true) {
|
|
3121
|
+
tsconfigJson.compilerOptions.allowSyntheticDefaultImports = true;
|
|
3122
|
+
}
|
|
3123
|
+
if (tsconfig$1.options.noImplicitOverride !== true) {
|
|
3124
|
+
tsconfigJson.compilerOptions.noImplicitOverride = true;
|
|
3125
|
+
}
|
|
3126
|
+
if (tsconfig$1.options.noUncheckedIndexedAccess !== true) {
|
|
3127
|
+
tsconfigJson.compilerOptions.noUncheckedIndexedAccess = true;
|
|
3128
|
+
}
|
|
3129
|
+
if (tsconfig$1.options.skipLibCheck !== true) {
|
|
3130
|
+
tsconfigJson.compilerOptions.skipLibCheck = true;
|
|
3131
|
+
}
|
|
3132
|
+
if (tsconfig$1.options.resolveJsonModule !== true) {
|
|
3133
|
+
tsconfigJson.compilerOptions.resolveJsonModule = true;
|
|
3134
|
+
}
|
|
3135
|
+
if (tsconfig$1.options.isolatedModules !== true) {
|
|
3136
|
+
tsconfigJson.compilerOptions.isolatedModules = true;
|
|
3137
|
+
}
|
|
3138
|
+
if (tsconfig$1.options.verbatimModuleSyntax !== false) {
|
|
3139
|
+
tsconfigJson.compilerOptions.verbatimModuleSyntax = false;
|
|
3140
|
+
}
|
|
3141
|
+
if (tsconfig$1.options.allowJs !== true) {
|
|
3142
|
+
tsconfigJson.compilerOptions.allowJs = true;
|
|
3143
|
+
}
|
|
3144
|
+
if (tsconfig$1.options.esModuleInterop !== true) {
|
|
3145
|
+
tsconfigJson.compilerOptions.esModuleInterop = true;
|
|
3146
|
+
}
|
|
3147
|
+
if (tsconfig$1.options.declaration !== true) {
|
|
3148
|
+
tsconfigJson.compilerOptions.declaration = true;
|
|
3149
|
+
}
|
|
3150
|
+
if (context.environment.consumer === "client") {
|
|
3151
|
+
if (tsconfig$1.options.jsx !== ts3__default.default.JsxEmit.ReactJSX) {
|
|
3152
|
+
tsconfigJson.compilerOptions.jsx = "react-jsx";
|
|
3153
|
+
}
|
|
3154
|
+
if (!tsconfig$1.options.lib?.some((lib) => lib.toLowerCase() !== "dom")) {
|
|
3155
|
+
tsconfigJson.compilerOptions.lib ??= [];
|
|
3156
|
+
tsconfigJson.compilerOptions.lib.push("dom");
|
|
3157
|
+
}
|
|
3158
|
+
if (!tsconfig$1.options.lib?.some((lib) => lib.toLowerCase() !== "dom.iterable")) {
|
|
3159
|
+
tsconfigJson.compilerOptions.lib ??= [];
|
|
3160
|
+
tsconfigJson.compilerOptions.lib.push("dom.iterable");
|
|
3161
|
+
}
|
|
3162
|
+
} else if (context.config.build.platform === "node") {
|
|
3163
|
+
if (!tsconfig$1.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
|
|
3164
|
+
tsconfigJson.compilerOptions.types ??= [];
|
|
3165
|
+
tsconfigJson.compilerOptions.types.push("node");
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
return tsconfigJson;
|
|
3169
|
+
}
|
|
3170
|
+
chunkSHUYVCID_js.__name(resolveTsconfigChanges, "resolveTsconfigChanges");
|
|
3171
|
+
async function initializeTsconfig(context) {
|
|
3172
|
+
context.log(types.LogLevelLabel.TRACE, "Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
|
|
3173
|
+
if (!packageFns.isPackageExists("typescript")) {
|
|
3174
|
+
throw new Error('The TypeScript package is not installed. Please install the package using the command: "npm install typescript --save-dev"');
|
|
3175
|
+
}
|
|
3176
|
+
const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
3177
|
+
context.tsconfig.originalTsconfigJson = await json.readJsonFile(tsconfigFilePath);
|
|
3178
|
+
context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
|
|
3179
|
+
await context.fs.writeFileToDisk(tsconfigFilePath, stormJson.StormJSON.stringify(context.tsconfig.tsconfigJson));
|
|
3180
|
+
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
|
|
3181
|
+
}
|
|
3182
|
+
chunkSHUYVCID_js.__name(initializeTsconfig, "initializeTsconfig");
|
|
3183
|
+
async function resolveTsconfig(context) {
|
|
3184
|
+
const updateTsconfigJson = await json.readJsonFile(context.tsconfig.tsconfigFilePath);
|
|
3185
|
+
if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) {
|
|
3186
|
+
delete updateTsconfigJson.compilerOptions.types;
|
|
3187
|
+
}
|
|
3188
|
+
const result = superdiff.getObjectDiff(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
|
|
3189
|
+
ignoreArrayOrder: true,
|
|
3190
|
+
showOnly: {
|
|
3191
|
+
statuses: [
|
|
3192
|
+
"added",
|
|
3193
|
+
"deleted",
|
|
3194
|
+
"updated"
|
|
3195
|
+
],
|
|
3196
|
+
granularity: "deep"
|
|
3197
|
+
}
|
|
3198
|
+
});
|
|
3199
|
+
const changes = [];
|
|
3200
|
+
const getChanges = /* @__PURE__ */ chunkSHUYVCID_js.__name((difference, property) => {
|
|
3201
|
+
if (difference.status === "added" || difference.status === "deleted" || difference.status === "updated") {
|
|
3202
|
+
if (difference.diff) {
|
|
3203
|
+
for (const diff of difference.diff) {
|
|
3204
|
+
getChanges(diff, property ? `${property}.${difference.property}` : difference.property);
|
|
3205
|
+
}
|
|
3206
|
+
} else {
|
|
3207
|
+
changes.push({
|
|
3208
|
+
field: property ? `${property}.${difference.property}` : difference.property,
|
|
3209
|
+
status: difference.status,
|
|
3210
|
+
previous: difference.status === "added" ? "---" : stormJson.StormJSON.stringify(difference.previousValue),
|
|
3211
|
+
current: difference.status === "deleted" ? "---" : stormJson.StormJSON.stringify(difference.currentValue)
|
|
3212
|
+
});
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
}, "getChanges");
|
|
3216
|
+
for (const diff of result.diff) {
|
|
3217
|
+
getChanges(diff);
|
|
3218
|
+
}
|
|
3219
|
+
if (changes.length > 0) {
|
|
3220
|
+
context.log(types.LogLevelLabel.WARN, `Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
|
|
3221
|
+
|
|
3222
|
+
${changes.map((change, i) => `${chalk5__default.default.bold.whiteBright(`${i + 1}. ${titleCase.titleCase(change.status)} the ${change.field} field: `)}
|
|
3223
|
+
${chalk5__default.default.red(` - Previous: ${change.previous} `)}
|
|
3224
|
+
${chalk5__default.default.green(` - Updated: ${change.current} `)}
|
|
3225
|
+
`).join("\n")}
|
|
3226
|
+
`);
|
|
3227
|
+
}
|
|
3228
|
+
await writeFile2(context.log, context.tsconfig.tsconfigFilePath, stormJson.StormJSON.stringify(updateTsconfigJson));
|
|
3229
|
+
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
3230
|
+
if (!context.tsconfig) {
|
|
3231
|
+
throw new Error("Failed to parse the TypeScript configuration file.");
|
|
3232
|
+
}
|
|
3233
|
+
context.tsconfig.tsconfigJson.compilerOptions ??= {};
|
|
3234
|
+
context.tsconfig.tsconfigJson.compilerOptions.strict = false;
|
|
3235
|
+
}
|
|
3236
|
+
chunkSHUYVCID_js.__name(resolveTsconfig, "resolveTsconfig");
|
|
3237
|
+
function getDefaultCompilerOptions() {
|
|
3238
|
+
return {
|
|
3239
|
+
...ts3__default.default.getDefaultCompilerOptions(),
|
|
3240
|
+
jsx: ts3__default.default.JsxEmit.React,
|
|
3241
|
+
strict: true,
|
|
3242
|
+
esModuleInterop: true,
|
|
3243
|
+
module: ts3__default.default.ModuleKind.ESNext,
|
|
3244
|
+
suppressOutputPathCheck: true,
|
|
3245
|
+
skipLibCheck: true,
|
|
3246
|
+
skipDefaultLibCheck: true,
|
|
3247
|
+
moduleResolution: ts3__default.default.ModuleResolutionKind.Node10
|
|
3248
|
+
};
|
|
3249
|
+
}
|
|
3250
|
+
chunkSHUYVCID_js.__name(getDefaultCompilerOptions, "getDefaultCompilerOptions");
|
|
3251
|
+
async function createVirtualProgram(rootNames, context, compilerOptions = {}) {
|
|
3252
|
+
const options = defu4__default.default(compilerOptions, getDefaultCompilerOptions());
|
|
3253
|
+
const host = {
|
|
3254
|
+
name: "storm-vfs",
|
|
3255
|
+
root: context.workspaceConfig.workspaceRoot,
|
|
3256
|
+
...ts3__default.default.sys,
|
|
3257
|
+
realpath: /* @__PURE__ */ chunkSHUYVCID_js.__name((path2) => {
|
|
3258
|
+
if (context.fs.existsSync(path2)) {
|
|
3259
|
+
return context.fs.resolvePath(path2);
|
|
3260
|
+
}
|
|
3261
|
+
return ts3__default.default.sys.realpath?.(path2) ?? path2;
|
|
3262
|
+
}, "realpath"),
|
|
3263
|
+
getCurrentDirectory() {
|
|
3264
|
+
return context.workspaceConfig.workspaceRoot;
|
|
3265
|
+
},
|
|
3266
|
+
getCanonicalFileName(fileName) {
|
|
3267
|
+
return fileName;
|
|
3268
|
+
},
|
|
3269
|
+
getDefaultLibFileName(_options) {
|
|
3270
|
+
return ts3__default.default.getDefaultLibFileName(options);
|
|
3271
|
+
},
|
|
3272
|
+
getDefaultLibLocation() {
|
|
3273
|
+
return "/";
|
|
3274
|
+
},
|
|
3275
|
+
getNewLine() {
|
|
3276
|
+
return "\n";
|
|
3277
|
+
},
|
|
3278
|
+
useCaseSensitiveFileNames() {
|
|
3279
|
+
return true;
|
|
3280
|
+
},
|
|
3281
|
+
fileExists(fileName) {
|
|
3282
|
+
return context.fs.existsSync(fileName);
|
|
3283
|
+
},
|
|
3284
|
+
readFile(fileName) {
|
|
3285
|
+
if (context.fs.existsSync(fileName)) {
|
|
3286
|
+
return context.fs.readFileSync(fileName);
|
|
3287
|
+
}
|
|
3288
|
+
return void 0;
|
|
3289
|
+
},
|
|
3290
|
+
readDirectory: /* @__PURE__ */ chunkSHUYVCID_js.__name((path2, extensions = [], exclude = [], include = []) => {
|
|
3291
|
+
let results = [];
|
|
3292
|
+
if (context.fs.existsSync(path2)) {
|
|
3293
|
+
results = context.fs.readdirSync(path2, {
|
|
3294
|
+
encoding: "utf8",
|
|
3295
|
+
recursive: true
|
|
3296
|
+
});
|
|
3297
|
+
if (extensions.length > 0) {
|
|
3298
|
+
results = results.filter((file) => extensions.some((ext) => file.endsWith(ext.startsWith(".") ? ext : `.${ext}`)));
|
|
3299
|
+
}
|
|
3300
|
+
if (exclude.length > 0) {
|
|
3301
|
+
results = results.filter((file) => !exclude.some((pattern) => minimatch.minimatch(file, pattern)));
|
|
3302
|
+
}
|
|
3303
|
+
if (include.length > 0) {
|
|
3304
|
+
results = results.filter((file) => include.some((pattern) => minimatch.minimatch(file, pattern)));
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
return results;
|
|
3308
|
+
}, "readDirectory"),
|
|
3309
|
+
writeFile(fileName, data) {
|
|
3310
|
+
context.fs.writeFileSync(fileName, data);
|
|
3311
|
+
},
|
|
3312
|
+
resolvePath: /* @__PURE__ */ chunkSHUYVCID_js.__name((fileName) => {
|
|
3313
|
+
if (context.fs.existsSync(fileName)) {
|
|
3314
|
+
return context.fs.resolvePath(fileName);
|
|
3315
|
+
}
|
|
3316
|
+
return ts3__default.default.sys.resolvePath(fileName);
|
|
3317
|
+
}, "resolvePath"),
|
|
3318
|
+
getSourceFile(fileName, languageVersionOrOptions, _, shouldCreateNewSourceFile) {
|
|
3319
|
+
if (context.fs.existsSync(fileName)) {
|
|
3320
|
+
return ts3__default.default.createSourceFile(fileName, context.fs.readFileSync(fileName), languageVersionOrOptions ?? compilerOptions.target ?? getDefaultCompilerOptions().target, false);
|
|
3321
|
+
} else if (shouldCreateNewSourceFile) {
|
|
3322
|
+
const sourceFile = ts3__default.default.createSourceFile(fileName, "", languageVersionOrOptions ?? compilerOptions.target ?? getDefaultCompilerOptions().target, false);
|
|
3323
|
+
context.fs.writeFileSync(fileName, sourceFile.text);
|
|
3324
|
+
return sourceFile;
|
|
3325
|
+
}
|
|
3326
|
+
return void 0;
|
|
3327
|
+
}
|
|
3328
|
+
};
|
|
3329
|
+
return ts3__default.default.createProgram(rootNames, options, host);
|
|
3330
|
+
}
|
|
3331
|
+
chunkSHUYVCID_js.__name(createVirtualProgram, "createVirtualProgram");
|
|
3332
|
+
|
|
3333
|
+
// ../powerlines/src/internal/helpers/tsc.ts
|
|
3334
|
+
async function typeCheck(context, sources) {
|
|
3335
|
+
if (sources) {
|
|
3336
|
+
await Promise.all(sources.entries().map(async ([path2, content]) => context.fs.writeFile(path2, content)));
|
|
3337
|
+
}
|
|
3338
|
+
const program = await createVirtualProgram(sources ? Array.from(sources.keys()) : [], context, {
|
|
3339
|
+
noEmit: true,
|
|
3340
|
+
lib: [
|
|
3341
|
+
"lib.esnext.d.ts"
|
|
3342
|
+
],
|
|
3343
|
+
types: []
|
|
3344
|
+
});
|
|
3345
|
+
const emitResult = program.emit();
|
|
3346
|
+
const allDiagnostics = ts3__default.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
3347
|
+
allDiagnostics.forEach((diagnostic) => {
|
|
3348
|
+
if (diagnostic.file) {
|
|
3349
|
+
const { line, character } = ts3__default.default.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
3350
|
+
const message = ts3__default.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
3351
|
+
context.log(types.LogLevelLabel.ERROR, `${diagnostic.file.fileName}:${line + 1}:${character + 1} : ${message}`);
|
|
3352
|
+
} else {
|
|
3353
|
+
context.log(types.LogLevelLabel.ERROR, ts3__default.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
3354
|
+
}
|
|
3355
|
+
});
|
|
3356
|
+
}
|
|
3357
|
+
chunkSHUYVCID_js.__name(typeCheck, "typeCheck");
|
|
3358
|
+
|
|
3359
|
+
// ../powerlines/src/internal/api.ts
|
|
3360
|
+
var PowerlinesAPI = class _PowerlinesAPI {
|
|
3361
|
+
static {
|
|
3362
|
+
chunkSHUYVCID_js.__name(this, "PowerlinesAPI");
|
|
3363
|
+
}
|
|
3364
|
+
/**
|
|
3365
|
+
* The Powerlines context
|
|
3366
|
+
*/
|
|
3367
|
+
#context;
|
|
3368
|
+
/**
|
|
3369
|
+
* The Powerlines context
|
|
3370
|
+
*/
|
|
3371
|
+
get context() {
|
|
3372
|
+
return this.#context;
|
|
3373
|
+
}
|
|
3374
|
+
/**
|
|
3375
|
+
* Create a new Powerlines API instance
|
|
3376
|
+
*
|
|
3377
|
+
* @param context - The Powerlines context
|
|
3378
|
+
*/
|
|
3379
|
+
constructor(context) {
|
|
3380
|
+
this.#context = context;
|
|
3381
|
+
}
|
|
3382
|
+
/**
|
|
3383
|
+
* Initialize the Powerlines API
|
|
3384
|
+
*/
|
|
3385
|
+
static async from(workspaceRoot, config) {
|
|
3386
|
+
const api = new _PowerlinesAPI(await PowerlinesAPIContext.from(workspaceRoot, config));
|
|
3387
|
+
for (const plugin of api.context.config.plugins ?? []) {
|
|
3388
|
+
await api.#addPlugin(plugin);
|
|
3389
|
+
}
|
|
3390
|
+
if (api.context.plugins.length === 0) {
|
|
3391
|
+
api.context.log(types.LogLevelLabel.WARN, "No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
|
|
3392
|
+
}
|
|
3393
|
+
const pluginConfig = await callHook(await api.context.getEnvironment(), "config", {
|
|
3394
|
+
sequential: true,
|
|
3395
|
+
result: "merge"
|
|
3396
|
+
});
|
|
3397
|
+
await api.context.withUserConfig(pluginConfig, {
|
|
3398
|
+
isHighPriority: false
|
|
3399
|
+
});
|
|
3400
|
+
return api;
|
|
3401
|
+
}
|
|
3402
|
+
/**
|
|
3403
|
+
* Prepare the Powerlines API
|
|
3404
|
+
*/
|
|
3405
|
+
async prepare(inlineConfig = {
|
|
3406
|
+
command: "prepare"
|
|
3407
|
+
}) {
|
|
3408
|
+
this.context.log(types.LogLevelLabel.TRACE, " \u{1F3D7}\uFE0F Preparing the Powerlines project");
|
|
3409
|
+
this.context.log(types.LogLevelLabel.TRACE, " \u2699\uFE0F Aggregating configuration options for the Powerlines project");
|
|
3410
|
+
await this.context.withInlineConfig(inlineConfig);
|
|
3411
|
+
await this.#executeEnvironments(async (context) => {
|
|
3412
|
+
context.log(types.LogLevelLabel.TRACE, `Initializing the processing options for the Powerlines project.`);
|
|
3413
|
+
await this.callPreHook(context, "configResolved");
|
|
3414
|
+
await initializeTsconfig(context);
|
|
3415
|
+
await this.callNormalHook(context, "configResolved");
|
|
3416
|
+
context.log(types.LogLevelLabel.DEBUG, `The configuration provided ${toArray.toArray(context.config.entry).length} entry point(s), Powerlines has found ${context.entry.length} entry files(s) for the ${context.config.title} project${context.entry.length > 0 && context.entry.length < 10 ? `:
|
|
3417
|
+
${context.entry.map((entry) => `- ${entry.input.file || entry.file}${entry.output ? ` -> ${entry.output}` : ""}`).join(" \n")}` : ""}.`);
|
|
3418
|
+
await resolveTsconfig(context);
|
|
3419
|
+
await installDependencies(context);
|
|
3420
|
+
await this.callPostHook(context, "configResolved");
|
|
3421
|
+
context.log(types.LogLevelLabel.TRACE, `Powerlines configuration has been resolved:
|
|
3422
|
+
|
|
3423
|
+
${console$1.formatLogMessage(context.config)}`);
|
|
3424
|
+
context.fs[chunkHHPODCTP_js.__VFS_INIT__]();
|
|
3425
|
+
await chunkHHPODCTP_js.writeMetaFile(context);
|
|
3426
|
+
context.persistedMeta = context.meta;
|
|
3427
|
+
if (!exists.existsSync(context.cachePath)) {
|
|
3428
|
+
await helpers.createDirectory(context.cachePath);
|
|
3429
|
+
}
|
|
3430
|
+
if (!exists.existsSync(context.dataPath)) {
|
|
3431
|
+
await helpers.createDirectory(context.dataPath);
|
|
3432
|
+
}
|
|
3433
|
+
await this.callPreHook(context, "prepare");
|
|
3434
|
+
if (context.config.projectType === "application") {
|
|
3435
|
+
context.log(types.LogLevelLabel.TRACE, "Generating built-in barrel file");
|
|
3436
|
+
await context.fs.writeBuiltinFile("index", joinPaths.joinPaths(context.builtinsPath, "index.ts"), `
|
|
3437
|
+
${getFileHeader()}
|
|
3438
|
+
|
|
3439
|
+
${(await context.fs.listBuiltinFiles()).filter((file) => !isParentPath.isParentPath(file.path, joinPaths.joinPaths(context.builtinsPath, "log")) && !isParentPath.isParentPath(file.path, joinPaths.joinPaths(context.builtinsPath, "storage"))).map((file) => `export * from "./${replace.replacePath(file.path, context.builtinsPath).replace(`.${filePathFns.findFileExtensionSafe(file.path)}`, "")}";`).join("\n")}
|
|
3440
|
+
`);
|
|
3441
|
+
}
|
|
3442
|
+
if (context.config.output.dts !== false) {
|
|
3443
|
+
await generateTypes(context);
|
|
3444
|
+
}
|
|
3445
|
+
await this.callNormalHook(context, "prepare");
|
|
3446
|
+
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
3447
|
+
if (!context.tsconfig) {
|
|
3448
|
+
throw new Error("Failed to parse the TypeScript configuration file.");
|
|
3449
|
+
}
|
|
3450
|
+
await this.callPostHook(context, "prepare");
|
|
3451
|
+
await chunkHHPODCTP_js.writeMetaFile(context);
|
|
3452
|
+
context.fs[chunkHHPODCTP_js.__VFS_REVERT__]();
|
|
3453
|
+
});
|
|
3454
|
+
this.context.log(types.LogLevelLabel.INFO, "Powerlines API has been prepared successfully");
|
|
3455
|
+
}
|
|
3456
|
+
/**
|
|
3457
|
+
* Create a new Powerlines project
|
|
3458
|
+
*
|
|
3459
|
+
* @remarks
|
|
3460
|
+
* This method will create a new Powerlines project in the current directory.
|
|
3461
|
+
*
|
|
3462
|
+
* @param inlineConfig - The inline configuration for the new command
|
|
3463
|
+
* @returns A promise that resolves when the project has been created
|
|
3464
|
+
*/
|
|
3465
|
+
async new(inlineConfig) {
|
|
3466
|
+
this.context.log(types.LogLevelLabel.INFO, "\u{1F195} Creating a new Powerlines project");
|
|
3467
|
+
await this.prepare(inlineConfig);
|
|
3468
|
+
await this.#executeEnvironments(async (context) => {
|
|
3469
|
+
context.log(types.LogLevelLabel.TRACE, `Initializing the processing options for the Powerlines project.`);
|
|
3470
|
+
await this.callPreHook(context, "new");
|
|
3471
|
+
const files = await listFiles.listFiles(joinPaths.joinPaths(context.corePackagePath, "files/common/**/*.hbs"));
|
|
3472
|
+
for (const file of files) {
|
|
3473
|
+
context.log(types.LogLevelLabel.TRACE, `Adding template file: ${file}`);
|
|
3474
|
+
const template = Handlebars__default.default.compile(file);
|
|
3475
|
+
await writeFile2(context.log, joinPaths.joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
|
|
3476
|
+
}
|
|
3477
|
+
await this.callNormalHook(context, "new");
|
|
3478
|
+
if (context.config.projectType === "application") {
|
|
3479
|
+
const files2 = await listFiles.listFiles(joinPaths.joinPaths(context.corePackagePath, "files/application/**/*.hbs"));
|
|
3480
|
+
for (const file of files2) {
|
|
3481
|
+
context.log(types.LogLevelLabel.TRACE, `Adding application template file: ${file}`);
|
|
3482
|
+
const template = Handlebars__default.default.compile(file);
|
|
3483
|
+
await writeFile2(context.log, joinPaths.joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
|
|
3484
|
+
}
|
|
3485
|
+
} else {
|
|
3486
|
+
const files2 = await listFiles.listFiles(joinPaths.joinPaths(context.corePackagePath, "files/library/**/*.hbs"));
|
|
3487
|
+
for (const file of files2) {
|
|
3488
|
+
context.log(types.LogLevelLabel.TRACE, `Adding library template file: ${file}`);
|
|
3489
|
+
const template = Handlebars__default.default.compile(file);
|
|
3490
|
+
await writeFile2(context.log, joinPaths.joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
3493
|
+
await this.callPostHook(context, "new");
|
|
3494
|
+
});
|
|
3495
|
+
this.context.log(types.LogLevelLabel.TRACE, "Powerlines - New command completed");
|
|
3496
|
+
}
|
|
3497
|
+
/**
|
|
3498
|
+
* Clean any previously prepared artifacts
|
|
3499
|
+
*
|
|
3500
|
+
* @remarks
|
|
3501
|
+
* This method will remove the previous Powerlines artifacts from the project.
|
|
3502
|
+
*
|
|
3503
|
+
* @param inlineConfig - The inline configuration for the clean command
|
|
3504
|
+
* @returns A promise that resolves when the clean command has completed
|
|
3505
|
+
*/
|
|
3506
|
+
async clean(inlineConfig = {
|
|
3507
|
+
command: "clean"
|
|
3508
|
+
}) {
|
|
3509
|
+
this.context.log(types.LogLevelLabel.INFO, "\u{1F9F9} Cleaning the previous Powerlines artifacts");
|
|
3510
|
+
await this.prepare(inlineConfig);
|
|
3511
|
+
await this.#executeEnvironments(async (context) => {
|
|
3512
|
+
await callHook(context, "clean", {
|
|
3513
|
+
sequential: true
|
|
3514
|
+
});
|
|
3515
|
+
});
|
|
3516
|
+
this.context.log(types.LogLevelLabel.TRACE, "Powerlines - Clean command completed");
|
|
3517
|
+
}
|
|
3518
|
+
/**
|
|
3519
|
+
* Lint the project
|
|
3520
|
+
*
|
|
3521
|
+
* @param inlineConfig - The inline configuration for the lint command
|
|
3522
|
+
* @returns A promise that resolves when the lint command has completed
|
|
3523
|
+
*/
|
|
3524
|
+
async lint(inlineConfig = {
|
|
3525
|
+
command: "lint"
|
|
3526
|
+
}) {
|
|
3527
|
+
this.context.log(types.LogLevelLabel.INFO, "\u{1F4CB} Linting the Powerlines project");
|
|
3528
|
+
await this.prepare(inlineConfig);
|
|
3529
|
+
await this.#executeEnvironments(async (context) => {
|
|
3530
|
+
if (context.config.lint !== false) {
|
|
3531
|
+
await this.callPreHook(context, "lint");
|
|
3532
|
+
await typeCheck(context);
|
|
3533
|
+
await eslint(context, true, context.config.lint.eslint);
|
|
3534
|
+
await this.callNormalHook(context, "lint");
|
|
3535
|
+
await this.callPostHook(context, "lint");
|
|
3536
|
+
}
|
|
3537
|
+
});
|
|
3538
|
+
this.context.log(types.LogLevelLabel.TRACE, "Powerlines linting completed");
|
|
3539
|
+
}
|
|
3540
|
+
/**
|
|
3541
|
+
* Build the project
|
|
3542
|
+
*
|
|
3543
|
+
* @remarks
|
|
3544
|
+
* This method will build the Powerlines project, generating the necessary artifacts.
|
|
3545
|
+
*
|
|
3546
|
+
* @param inlineConfig - The inline configuration for the build command
|
|
3547
|
+
* @returns A promise that resolves when the build command has completed
|
|
3548
|
+
*/
|
|
3549
|
+
async build(inlineConfig = {
|
|
3550
|
+
command: "build"
|
|
3551
|
+
}) {
|
|
3552
|
+
this.context.log(types.LogLevelLabel.INFO, "\u{1F4E6} Building the Powerlines project");
|
|
3553
|
+
await this.prepare(inlineConfig);
|
|
3554
|
+
await this.#executeEnvironments(async (context) => {
|
|
3555
|
+
await this.callPreHook(context, "build");
|
|
3556
|
+
await this.callNormalHook(context, "build");
|
|
3557
|
+
await Promise.all(context.config.output.assets.map(async (asset) => {
|
|
3558
|
+
context.log(types.LogLevelLabel.DEBUG, `Copying asset(s): ${chalk5__default.default.redBright(context.workspaceConfig.workspaceRoot === asset.input ? asset.glob : joinPaths.joinPaths(replace.replacePath(asset.input, context.workspaceConfig.workspaceRoot), asset.glob))} -> ${chalk5__default.default.greenBright(joinPaths.joinPaths(replace.replacePath(asset.output, context.workspaceConfig.workspaceRoot), asset.glob))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk5__default.default.yellowBright(i)).join(", ")})` : ""}`);
|
|
3559
|
+
await copyFile.copyFiles(asset, asset.output);
|
|
3560
|
+
}));
|
|
3561
|
+
await this.callPostHook(context, "build");
|
|
3562
|
+
});
|
|
3563
|
+
this.context.log(types.LogLevelLabel.TRACE, "Powerlines build completed");
|
|
3564
|
+
}
|
|
3565
|
+
/**
|
|
3566
|
+
* Prepare the documentation for the project
|
|
3567
|
+
*
|
|
3568
|
+
* @param inlineConfig - The inline configuration for the docs command
|
|
3569
|
+
* @returns A promise that resolves when the documentation generation has completed
|
|
3570
|
+
*/
|
|
3571
|
+
async docs(inlineConfig = {
|
|
3572
|
+
command: "docs"
|
|
3573
|
+
}) {
|
|
3574
|
+
this.context.log(types.LogLevelLabel.INFO, "Generating documentation for the Powerlines project");
|
|
3575
|
+
await this.prepare(inlineConfig);
|
|
3576
|
+
await this.#executeEnvironments(async (context) => {
|
|
3577
|
+
context.log(types.LogLevelLabel.TRACE, "Writing API-Reference documentation for the Powerlines project artifacts.");
|
|
3578
|
+
await this.callPreHook(context, "docs");
|
|
3579
|
+
const outputPath = joinPaths.joinPaths(context.config.projectRoot, "docs", "generated", "api-reference");
|
|
3580
|
+
if (exists.existsSync(outputPath)) {
|
|
3581
|
+
await helpers.removeDirectory(outputPath);
|
|
3582
|
+
}
|
|
3583
|
+
await helpers.createDirectory(outputPath);
|
|
3584
|
+
await this.callNormalHook(context, "docs");
|
|
3585
|
+
const { generateDocs, getReflections } = await initTypedoc(context, {
|
|
3586
|
+
outputPath
|
|
3587
|
+
});
|
|
3588
|
+
const project = await getReflections();
|
|
3589
|
+
if (project) {
|
|
3590
|
+
await generateDocs({
|
|
3591
|
+
project
|
|
3592
|
+
});
|
|
3593
|
+
}
|
|
3594
|
+
await this.callPostHook(context, "docs");
|
|
3595
|
+
});
|
|
3596
|
+
this.#context.log(types.LogLevelLabel.TRACE, "Powerlines documentation generation completed");
|
|
3597
|
+
}
|
|
3598
|
+
/**
|
|
3599
|
+
* Release the project
|
|
3600
|
+
*
|
|
3601
|
+
* @remarks
|
|
3602
|
+
* This method will prepare and build the Powerlines project, generating the necessary artifacts for release.
|
|
3603
|
+
*
|
|
3604
|
+
* @param inlineConfig - The inline configuration for the release command
|
|
3605
|
+
*/
|
|
3606
|
+
async release(inlineConfig = {
|
|
3607
|
+
command: "release"
|
|
3608
|
+
}) {
|
|
3609
|
+
this.context.log(types.LogLevelLabel.INFO, "\u{1F4E6} Releasing the Powerlines project");
|
|
3610
|
+
await this.prepare(inlineConfig);
|
|
3611
|
+
await this.#executeEnvironments(async (context) => {
|
|
3612
|
+
await this.callHook(context, "release");
|
|
3613
|
+
});
|
|
3614
|
+
this.context.log(types.LogLevelLabel.TRACE, "Powerlines release completed");
|
|
3615
|
+
}
|
|
3616
|
+
/**
|
|
3617
|
+
* Finalization process
|
|
3618
|
+
*
|
|
3619
|
+
* @remarks
|
|
3620
|
+
* This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
|
|
3621
|
+
*
|
|
3622
|
+
* @returns A promise that resolves when the finalization process has completed
|
|
3623
|
+
*/
|
|
3624
|
+
async finalize() {
|
|
3625
|
+
this.context.log(types.LogLevelLabel.TRACE, "Powerlines finalize execution started");
|
|
3626
|
+
await this.#executeEnvironments(async (context) => {
|
|
3627
|
+
await this.callHook(context, "finalize");
|
|
3628
|
+
context.fs[chunkHHPODCTP_js.__VFS_REVERT__]();
|
|
3629
|
+
});
|
|
3630
|
+
this.context.log(types.LogLevelLabel.TRACE, "Powerlines finalize execution completed");
|
|
3631
|
+
}
|
|
3632
|
+
/**
|
|
3633
|
+
* Calls a hook in parallel
|
|
3634
|
+
*
|
|
3635
|
+
* @param hook - The hook to call
|
|
3636
|
+
* @param options - Options for calling the hook
|
|
3637
|
+
* @param args - The arguments to pass to the hook
|
|
3638
|
+
* @returns The result of the hook call
|
|
3639
|
+
*/
|
|
3640
|
+
async callHookParallel(hook, options, ...args) {
|
|
3641
|
+
return callHook(isSetObject.isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
|
|
3642
|
+
...options,
|
|
3643
|
+
sequential: false
|
|
3644
|
+
}, ...args);
|
|
3645
|
+
}
|
|
3646
|
+
/**
|
|
3647
|
+
* Calls a hook in sequence
|
|
3648
|
+
*
|
|
3649
|
+
* @param hook - The hook to call
|
|
3650
|
+
* @param options - Options for calling the hook
|
|
3651
|
+
* @param args - The arguments to pass to the hook
|
|
3652
|
+
* @returns The result of the hook call
|
|
3653
|
+
*/
|
|
3654
|
+
async callHookSequential(hook, options, ...args) {
|
|
3655
|
+
return callHook(isSetObject.isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
|
|
3656
|
+
...options,
|
|
3657
|
+
sequential: true
|
|
3658
|
+
}, ...args);
|
|
3659
|
+
}
|
|
3660
|
+
/**
|
|
3661
|
+
* Calls the `"pre"` ordered hooks in sequence
|
|
3662
|
+
*
|
|
3663
|
+
* @param environment - The environment to use for the hook call
|
|
3664
|
+
* @param hook - The hook to call
|
|
3665
|
+
* @param args - The arguments to pass to the hook
|
|
3666
|
+
* @returns The result of the hook call
|
|
3667
|
+
*/
|
|
3668
|
+
async callPreHook(environment, hook, ...args) {
|
|
3669
|
+
return this.callHookSequential(hook, {
|
|
3670
|
+
order: "pre",
|
|
3671
|
+
environment
|
|
3672
|
+
}, ...args);
|
|
3673
|
+
}
|
|
3674
|
+
/**
|
|
3675
|
+
* Calls the `"post"` ordered hooks in sequence
|
|
3676
|
+
*
|
|
3677
|
+
* @param environment - The environment to use for the hook call
|
|
3678
|
+
* @param hook - The hook to call
|
|
3679
|
+
* @param args - The arguments to pass to the hook
|
|
3680
|
+
* @returns The result of the hook call
|
|
3681
|
+
*/
|
|
3682
|
+
async callPostHook(environment, hook, ...args) {
|
|
3683
|
+
return this.callHookSequential(hook, {
|
|
3684
|
+
order: "post",
|
|
3685
|
+
environment
|
|
3686
|
+
}, ...args);
|
|
3687
|
+
}
|
|
3688
|
+
/**
|
|
3689
|
+
* Calls a hook in sequence
|
|
3690
|
+
*
|
|
3691
|
+
* @param environment - The environment to use for the hook call
|
|
3692
|
+
* @param hook - The hook to call
|
|
3693
|
+
* @param args - The arguments to pass to the hook
|
|
3694
|
+
* @returns The result of the hook call
|
|
3695
|
+
*/
|
|
3696
|
+
async callNormalHook(environment, hook, ...args) {
|
|
3697
|
+
return this.callHookSequential(hook, {
|
|
3698
|
+
order: "normal",
|
|
3699
|
+
environment
|
|
3700
|
+
}, ...args);
|
|
3701
|
+
}
|
|
3702
|
+
/**
|
|
3703
|
+
* Calls the `"pre"` and `"post"` ordered hooks, as well as the normal hooks in sequence
|
|
3704
|
+
*
|
|
3705
|
+
* @param environment - The environment to use for the hook call
|
|
3706
|
+
* @param hook - The hook to call
|
|
3707
|
+
* @param args - The arguments to pass to the hook
|
|
3708
|
+
* @returns The result of the hook call
|
|
3709
|
+
*/
|
|
3710
|
+
async callHook(environment, hook, ...args) {
|
|
3711
|
+
return this.callHookSequential(hook, {
|
|
3712
|
+
environment
|
|
3713
|
+
}, ...args);
|
|
3714
|
+
}
|
|
3715
|
+
async [Symbol.asyncDispose]() {
|
|
3716
|
+
await this.finalize();
|
|
3717
|
+
}
|
|
3718
|
+
/**
|
|
3719
|
+
* Get the configured environments
|
|
3720
|
+
*
|
|
3721
|
+
* @returns The configured environments
|
|
3722
|
+
*/
|
|
3723
|
+
async #getEnvironments() {
|
|
3724
|
+
if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
|
|
3725
|
+
this.context.log(types.LogLevelLabel.DEBUG, "No environments are configured for this Powerlines project. Using the default environment.");
|
|
3726
|
+
return [
|
|
3727
|
+
await this.context.getEnvironment()
|
|
3728
|
+
];
|
|
3729
|
+
}
|
|
3730
|
+
this.context.log(types.LogLevelLabel.DEBUG, `Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
|
|
3731
|
+
return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
|
|
3732
|
+
const environment = await this.context.getEnvironmentSafe(name);
|
|
3733
|
+
if (!environment) {
|
|
3734
|
+
const resolvedEnvironment = await this.callHookParallel("configEnvironment", {
|
|
3735
|
+
environment: name
|
|
3736
|
+
}, name, config);
|
|
3737
|
+
if (resolvedEnvironment) {
|
|
3738
|
+
this.context.environments[name] = await this.context.in(resolvedEnvironment);
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
return this.context.environments[name];
|
|
3742
|
+
}))).filter((context) => isSet.isSet(context));
|
|
3743
|
+
}
|
|
3744
|
+
/**
|
|
3745
|
+
* Execute a handler function for each environment
|
|
3746
|
+
*
|
|
3747
|
+
* @param handle - The handler function to execute for each environment
|
|
3748
|
+
*/
|
|
3749
|
+
async #executeEnvironments(handle) {
|
|
3750
|
+
await Promise.all((await this.#getEnvironments()).map(async (context) => {
|
|
3751
|
+
return Promise.resolve(handle(context));
|
|
3752
|
+
}));
|
|
3753
|
+
}
|
|
3754
|
+
/**
|
|
3755
|
+
* Add a Powerlines plugin used in the build process
|
|
3756
|
+
*
|
|
3757
|
+
* @param config - The import path of the plugin to add
|
|
3758
|
+
*/
|
|
3759
|
+
async #addPlugin(config) {
|
|
3760
|
+
if (config) {
|
|
3761
|
+
const plugin = await this.#initPlugin(config);
|
|
3762
|
+
if (!plugin) {
|
|
3763
|
+
return;
|
|
3764
|
+
}
|
|
3765
|
+
if (plugin.dependsOn) {
|
|
3766
|
+
for (const required of plugin.dependsOn) {
|
|
3767
|
+
await this.#addPlugin(required);
|
|
3768
|
+
}
|
|
3769
|
+
}
|
|
3770
|
+
this.context.log(types.LogLevelLabel.DEBUG, `Successfully initialized the ${chalk5__default.default.bold.cyanBright(plugin.name)} plugin`);
|
|
3771
|
+
await this.context.addPlugin(plugin);
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
/**
|
|
3775
|
+
* Initialize a Powerlines plugin
|
|
3776
|
+
*
|
|
3777
|
+
* @param config - The configuration for the plugin
|
|
3778
|
+
* @returns The initialized plugin instance, or null if the plugin was a duplicate
|
|
3779
|
+
* @throws Will throw an error if the plugin cannot be found or is invalid
|
|
3780
|
+
*/
|
|
3781
|
+
async #initPlugin(config) {
|
|
3782
|
+
if (!isPluginConfig(config)) {
|
|
3783
|
+
throw new Error(`Invalid plugin specified in the configuration - ${JSON.stringify(config)}. Please ensure the value is a plugin name, an object with the \`plugin\` and \`props\` properties, or an instance of \`Plugin\`.`);
|
|
3784
|
+
}
|
|
3785
|
+
let plugin;
|
|
3786
|
+
if (isPlugin(config)) {
|
|
3787
|
+
plugin = config;
|
|
3788
|
+
} else if (isFunction.isFunction(config)) {
|
|
3789
|
+
plugin = await Promise.resolve(config());
|
|
3790
|
+
} else if (isSetString.isSetString(config)) {
|
|
3791
|
+
const resolved = await this.#resolvePlugin(config);
|
|
3792
|
+
if (isFunction.isFunction(resolved)) {
|
|
3793
|
+
plugin = await Promise.resolve(resolved());
|
|
3794
|
+
} else {
|
|
3795
|
+
plugin = resolved;
|
|
3796
|
+
}
|
|
3797
|
+
} else if (isPluginConfigTuple(config) || isPluginConfigObject(config)) {
|
|
3798
|
+
let pluginConfig;
|
|
3799
|
+
let pluginOptions;
|
|
3800
|
+
if (isPluginConfigTuple(config)) {
|
|
3801
|
+
pluginConfig = config[0];
|
|
3802
|
+
pluginOptions = config?.length === 2 ? config[1] : void 0;
|
|
3803
|
+
} else {
|
|
3804
|
+
pluginConfig = config.plugin;
|
|
3805
|
+
pluginOptions = config.options;
|
|
3806
|
+
}
|
|
3807
|
+
if (isSetString.isSetString(pluginConfig)) {
|
|
3808
|
+
const resolved = await this.#resolvePlugin(pluginConfig);
|
|
3809
|
+
if (isFunction.isFunction(resolved)) {
|
|
3810
|
+
plugin = await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved());
|
|
3811
|
+
} else {
|
|
3812
|
+
plugin = resolved;
|
|
3813
|
+
}
|
|
3814
|
+
} else if (isFunction.isFunction(pluginConfig)) {
|
|
3815
|
+
plugin = await Promise.resolve(pluginConfig(pluginOptions));
|
|
3816
|
+
} else if (isPlugin(pluginConfig)) {
|
|
3817
|
+
plugin = pluginConfig;
|
|
3818
|
+
}
|
|
3819
|
+
}
|
|
3820
|
+
if (!plugin) {
|
|
3821
|
+
throw new Error(`The plugin configuration ${JSON.stringify(config)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
|
|
3822
|
+
}
|
|
3823
|
+
if (!isPlugin(plugin)) {
|
|
3824
|
+
throw new Error(`The plugin option ${JSON.stringify(plugin)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
|
|
3825
|
+
}
|
|
3826
|
+
if (checkDedupe(plugin, this.context.plugins)) {
|
|
3827
|
+
this.context.log(types.LogLevelLabel.TRACE, `Duplicate ${chalk5__default.default.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
|
|
3828
|
+
return null;
|
|
3829
|
+
}
|
|
3830
|
+
this.context.log(types.LogLevelLabel.TRACE, `Initializing the ${chalk5__default.default.bold.cyanBright(plugin.name)} plugin...`);
|
|
3831
|
+
return plugin;
|
|
3832
|
+
}
|
|
3833
|
+
async #resolvePlugin(pluginPath) {
|
|
3834
|
+
if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
|
|
3835
|
+
const splits = pluginPath.split("/").filter(Boolean);
|
|
3836
|
+
pluginPath = `${splits[0]}/${splits[1]}`;
|
|
3837
|
+
}
|
|
3838
|
+
const isInstalled = packageFns.isPackageExists(pluginPath, {
|
|
3839
|
+
paths: [
|
|
3840
|
+
this.context.workspaceConfig.workspaceRoot,
|
|
3841
|
+
this.context.config.projectRoot
|
|
3842
|
+
]
|
|
3843
|
+
});
|
|
3844
|
+
if (!isInstalled && this.context.config.skipInstalls !== true) {
|
|
3845
|
+
this.#context.log(types.LogLevelLabel.WARN, `The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
|
|
3846
|
+
const result = await install.install(pluginPath, {
|
|
3847
|
+
cwd: this.context.config.projectRoot
|
|
3848
|
+
});
|
|
3849
|
+
if (isNumber.isNumber(result.exitCode) && result.exitCode > 0) {
|
|
3850
|
+
this.#context.log(types.LogLevelLabel.ERROR, result.stderr);
|
|
3851
|
+
throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
try {
|
|
3855
|
+
const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(joinPaths.joinPaths(pluginPath, "plugin")));
|
|
3856
|
+
const result = module.plugin ?? module.default;
|
|
3857
|
+
if (!result) {
|
|
3858
|
+
throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
|
|
3859
|
+
}
|
|
3860
|
+
return result;
|
|
3861
|
+
} catch (error) {
|
|
3862
|
+
try {
|
|
3863
|
+
const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
|
|
3864
|
+
const result = module.plugin ?? module.default;
|
|
3865
|
+
if (!result) {
|
|
3866
|
+
throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
|
|
3867
|
+
}
|
|
3868
|
+
return result;
|
|
3869
|
+
} catch {
|
|
3870
|
+
if (!isInstalled) {
|
|
3871
|
+
throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
|
|
3872
|
+
} else {
|
|
3873
|
+
throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
|
|
3874
|
+
${isError.isError(error) ? error.message : String(error)}
|
|
3875
|
+
|
|
3876
|
+
Note: Please ensure the plugin package's default export is a class that extends \`Plugin\` with a constructor that excepts a single arguments of type \`PluginOptions\`.`);
|
|
3877
|
+
}
|
|
3878
|
+
}
|
|
3879
|
+
}
|
|
3880
|
+
}
|
|
3881
|
+
};
|
|
3882
|
+
var DEFAULT_ESBUILD_CONFIG = {
|
|
3883
|
+
target: "esnext",
|
|
3884
|
+
platform: "neutral",
|
|
3885
|
+
format: "esm",
|
|
3886
|
+
write: true,
|
|
3887
|
+
minify: true,
|
|
3888
|
+
sourcemap: false,
|
|
3889
|
+
bundle: true,
|
|
3890
|
+
treeShaking: true,
|
|
3891
|
+
keepNames: true,
|
|
3892
|
+
splitting: true,
|
|
3893
|
+
logLevel: "silent"
|
|
3894
|
+
};
|
|
3895
|
+
function extractESBuildConfig(context) {
|
|
3896
|
+
return defu4__default.default({
|
|
3897
|
+
alias: context.fs.builtinIdMap.keys().reduce((ret, id) => {
|
|
3898
|
+
const path2 = context.fs.builtinIdMap.get(id);
|
|
3899
|
+
if (path2) {
|
|
3900
|
+
ret[id] = path2;
|
|
3901
|
+
}
|
|
3902
|
+
return ret;
|
|
3903
|
+
}, {})
|
|
3904
|
+
}, context.config.build.variant === "esbuild" ? context.config.override : {}, {
|
|
3905
|
+
format: Array.isArray(context.config.output.format) ? context.config.output.format[0] : context.config.output.format,
|
|
3906
|
+
platform: context.config.build.platform,
|
|
3907
|
+
treeShaking: Boolean(context.config.build?.treeshake) || context.config.build?.treeShaking,
|
|
3908
|
+
outdir: context.config.output.outputPath,
|
|
3909
|
+
tsconfig: context.tsconfig.tsconfigFilePath,
|
|
3910
|
+
tsconfigRaw: context.tsconfig.tsconfigJson
|
|
3911
|
+
}, context.config.build.variant === "esbuild" ? context.config.build : {}, {
|
|
3912
|
+
minify: context.config.mode !== "development",
|
|
3913
|
+
metafile: context.config.mode === "development",
|
|
3914
|
+
sourcemap: context.config.mode === "development"
|
|
3915
|
+
}, DEFAULT_ESBUILD_CONFIG);
|
|
3916
|
+
}
|
|
3917
|
+
chunkSHUYVCID_js.__name(extractESBuildConfig, "extractESBuildConfig");
|
|
3918
|
+
|
|
3919
|
+
// ../powerlines/src/lib/build/vite.ts
|
|
3920
|
+
var DEFAULT_VITE_CONFIG = {
|
|
3921
|
+
resolve: {
|
|
3922
|
+
extensions: [
|
|
3923
|
+
".mjs",
|
|
3924
|
+
".js",
|
|
3925
|
+
".mts",
|
|
3926
|
+
".ts",
|
|
3927
|
+
".jsx",
|
|
3928
|
+
".tsx",
|
|
3929
|
+
".json"
|
|
3930
|
+
]
|
|
3931
|
+
},
|
|
3932
|
+
json: {
|
|
3933
|
+
stringify: true
|
|
3934
|
+
},
|
|
3935
|
+
logLevel: "silent",
|
|
3936
|
+
clearScreen: true
|
|
3937
|
+
};
|
|
3938
|
+
function extractViteConfig(context) {
|
|
3939
|
+
return defu4__default.default({
|
|
3940
|
+
resolve: {
|
|
3941
|
+
alias: context.fs.builtinIdMap.keys().reduce((ret, id) => {
|
|
3942
|
+
const path2 = context.fs.builtinIdMap.get(id);
|
|
3943
|
+
if (path2) {
|
|
3944
|
+
ret[id] = path2;
|
|
3945
|
+
}
|
|
3946
|
+
return ret;
|
|
3947
|
+
}, {})
|
|
3948
|
+
}
|
|
3949
|
+
}, context.config.build.variant === "vite" ? context.config.override : {}, {
|
|
3950
|
+
external: context.config.build.external,
|
|
3951
|
+
noExternal: context.config.build.noExternal,
|
|
3952
|
+
skipNodeModulesBundle: context.config.build.skipNodeModulesBundle
|
|
3953
|
+
}, {
|
|
3954
|
+
rootDir: context.config.sourceRoot,
|
|
3955
|
+
platform: context.config.build.platform,
|
|
3956
|
+
mode: context.config.mode === "development" ? "development" : "production",
|
|
3957
|
+
cacheDir: joinPaths.joinPaths(context.cachePath, "vite"),
|
|
3958
|
+
build: {
|
|
3959
|
+
outDir: context.config.output.outputPath,
|
|
3960
|
+
tsconfig: context.tsconfig.tsconfigFilePath,
|
|
3961
|
+
tsconfigRaw: context.tsconfig.tsconfigJson
|
|
3962
|
+
},
|
|
3963
|
+
esbuild: extractESBuildConfig(context),
|
|
3964
|
+
logLevel: context.config.logLevel ?? void 0,
|
|
3965
|
+
envDir: context.config.projectRoot,
|
|
3966
|
+
noExternal: Array.from(context.fs.builtinIdMap.keys())
|
|
3967
|
+
}, context.config.build.variant === "vite" ? context.config.build : {}, {
|
|
3968
|
+
build: {
|
|
3969
|
+
minify: context.config.mode !== "development",
|
|
3970
|
+
metafile: context.config.mode === "development",
|
|
3971
|
+
sourcemap: context.config.mode === "development"
|
|
3972
|
+
}
|
|
3973
|
+
}, DEFAULT_VITE_CONFIG);
|
|
3974
|
+
}
|
|
3975
|
+
chunkSHUYVCID_js.__name(extractViteConfig, "extractViteConfig");
|
|
3976
|
+
var NON_NODE_MODULE_REGEX = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
|
|
3977
|
+
async function handleResolveId(context, args, options = {}) {
|
|
3978
|
+
if (args.id) {
|
|
3979
|
+
if (context.fs.isVirtualFile(args.id) || args.importer && context.fs.isVirtualFile(args.id, {
|
|
3980
|
+
paths: [
|
|
3981
|
+
args.importer
|
|
3982
|
+
]
|
|
3983
|
+
})) {
|
|
3984
|
+
const resolvedPath = args.importer ? context.fs.resolvePath(args.id, {
|
|
3985
|
+
paths: [
|
|
3986
|
+
args.importer
|
|
3987
|
+
]
|
|
3988
|
+
}) : context.fs.resolvePath(args.id);
|
|
3989
|
+
if (resolvedPath) {
|
|
3990
|
+
return {
|
|
3991
|
+
id: resolvedPath,
|
|
3992
|
+
external: context.config.projectType !== "application"
|
|
3993
|
+
};
|
|
3994
|
+
}
|
|
3995
|
+
}
|
|
3996
|
+
if (context.fs.isTsconfigPath(args.id)) {
|
|
3997
|
+
const tsconfigPath = context.fs.resolveTsconfigPath(args.id);
|
|
3998
|
+
const tsconfigPathPackage = context.fs.resolveTsconfigPathPackage(args.id);
|
|
3999
|
+
if (tsconfigPath && tsconfigPathPackage) {
|
|
4000
|
+
return {
|
|
4001
|
+
id: tsconfigPath,
|
|
4002
|
+
external: Boolean(!options.noExternal?.includes(tsconfigPathPackage) && (options.external?.includes(tsconfigPathPackage) ?? context.config.projectType !== "application"))
|
|
4003
|
+
};
|
|
4004
|
+
}
|
|
4005
|
+
}
|
|
4006
|
+
if (options.skipResolve) {
|
|
4007
|
+
return void 0;
|
|
4008
|
+
}
|
|
4009
|
+
if (options.skipNodeModulesBundle) {
|
|
4010
|
+
if (bundleRequire.match(args.id, options.resolvePatterns) || bundleRequire.match(args.id, options.noExternal) || args.id.startsWith("internal:") || args.id.startsWith("virtual:")) {
|
|
4011
|
+
return void 0;
|
|
4012
|
+
}
|
|
4013
|
+
if (bundleRequire.match(args.id, options.external) || args.id.startsWith("node:")) {
|
|
4014
|
+
return {
|
|
4015
|
+
id: args.id,
|
|
4016
|
+
external: true
|
|
4017
|
+
};
|
|
4018
|
+
}
|
|
4019
|
+
if (!NON_NODE_MODULE_REGEX.test(args.id)) {
|
|
4020
|
+
return {
|
|
4021
|
+
id: args.id,
|
|
4022
|
+
external: true
|
|
4023
|
+
};
|
|
4024
|
+
}
|
|
4025
|
+
} else {
|
|
4026
|
+
if (bundleRequire.match(args.id, options.noExternal) || context.fs.isBuiltinFile(args.id) || args.importer && context.fs.isBuiltinFile(args.id, {
|
|
4027
|
+
paths: [
|
|
4028
|
+
args.importer
|
|
4029
|
+
]
|
|
4030
|
+
})) {
|
|
4031
|
+
return void 0;
|
|
4032
|
+
}
|
|
4033
|
+
if (bundleRequire.match(args.id, options.external) || args.id.startsWith("node:")) {
|
|
4034
|
+
return {
|
|
4035
|
+
id: args.id,
|
|
4036
|
+
external: true
|
|
4037
|
+
};
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
return void 0;
|
|
4042
|
+
}
|
|
4043
|
+
chunkSHUYVCID_js.__name(handleResolveId, "handleResolveId");
|
|
4044
|
+
|
|
4045
|
+
// ../powerlines/src/lib/unplugin/factory.ts
|
|
4046
|
+
function createUnpluginFactory(variant, decorate) {
|
|
4047
|
+
return (config, meta) => {
|
|
4048
|
+
const log = createLog("unplugin", config);
|
|
4049
|
+
log(types.LogLevelLabel.DEBUG, "Initializing Unplugin");
|
|
4050
|
+
try {
|
|
4051
|
+
const userConfig = {
|
|
4052
|
+
...config,
|
|
4053
|
+
variant,
|
|
4054
|
+
unplugin: meta
|
|
4055
|
+
};
|
|
4056
|
+
let api;
|
|
4057
|
+
let resolvePatterns = [];
|
|
4058
|
+
async function buildStart() {
|
|
4059
|
+
log(types.LogLevelLabel.DEBUG, "Powerlines build plugin starting...");
|
|
4060
|
+
const workspaceRoot = getWorkspaceRoot.getWorkspaceRoot(process.cwd());
|
|
4061
|
+
api = await PowerlinesAPI.from(workspaceRoot, userConfig);
|
|
4062
|
+
if (api.context.config.build.skipNodeModulesBundle) {
|
|
4063
|
+
resolvePatterns = bundleRequire.tsconfigPathsToRegExp(api.context.tsconfig.options.paths ?? []);
|
|
4064
|
+
}
|
|
4065
|
+
log(types.LogLevelLabel.DEBUG, "Preparing build artifacts for the Powerlines project...");
|
|
4066
|
+
await api.prepare({
|
|
4067
|
+
command: "build"
|
|
4068
|
+
});
|
|
4069
|
+
}
|
|
4070
|
+
chunkSHUYVCID_js.__name(buildStart, "buildStart");
|
|
4071
|
+
async function resolveId(id, importer, options = {
|
|
4072
|
+
isEntry: false
|
|
4073
|
+
}) {
|
|
4074
|
+
return handleResolveId(api.context, {
|
|
4075
|
+
id,
|
|
4076
|
+
importer,
|
|
4077
|
+
options
|
|
4078
|
+
}, {
|
|
4079
|
+
skipNodeModulesBundle: api.context.config.build.skipNodeModulesBundle,
|
|
4080
|
+
external: api.context.config.build.external,
|
|
4081
|
+
noExternal: api.context.config.build.noExternal,
|
|
4082
|
+
resolvePatterns
|
|
4083
|
+
});
|
|
4084
|
+
}
|
|
4085
|
+
chunkSHUYVCID_js.__name(resolveId, "resolveId");
|
|
4086
|
+
async function load(id) {
|
|
4087
|
+
const environment = await api.context.getEnvironment();
|
|
4088
|
+
if (id) {
|
|
4089
|
+
const resolvedPath = environment.fs.resolvePath(id, {
|
|
4090
|
+
type: "file"
|
|
4091
|
+
});
|
|
4092
|
+
if (resolvedPath) {
|
|
4093
|
+
return environment.fs.readFile(resolvedPath);
|
|
4094
|
+
}
|
|
4095
|
+
}
|
|
4096
|
+
let result2 = await api.callPreHook(environment, "load", id);
|
|
4097
|
+
if (result2) {
|
|
4098
|
+
return result2;
|
|
4099
|
+
}
|
|
4100
|
+
result2 = await api.callNormalHook(environment, "load", id);
|
|
4101
|
+
if (result2) {
|
|
4102
|
+
return result2;
|
|
4103
|
+
}
|
|
4104
|
+
return api.callPostHook(environment, "load", id);
|
|
4105
|
+
}
|
|
4106
|
+
chunkSHUYVCID_js.__name(load, "load");
|
|
4107
|
+
async function transform(code, id) {
|
|
4108
|
+
const environment = await api.context.getEnvironment();
|
|
4109
|
+
let transformed = code;
|
|
4110
|
+
let result2 = await api.callPreHook(environment, "transform", getString(transformed), id);
|
|
4111
|
+
if (result2) {
|
|
4112
|
+
transformed = result2;
|
|
4113
|
+
}
|
|
4114
|
+
result2 = await api.callNormalHook(environment, "transform", getString(transformed), id);
|
|
4115
|
+
if (result2) {
|
|
4116
|
+
transformed = result2;
|
|
4117
|
+
}
|
|
4118
|
+
result2 = await api.callPostHook(environment, "transform", getString(transformed), id);
|
|
4119
|
+
if (result2) {
|
|
4120
|
+
transformed = result2;
|
|
4121
|
+
}
|
|
4122
|
+
return transformed;
|
|
4123
|
+
}
|
|
4124
|
+
chunkSHUYVCID_js.__name(transform, "transform");
|
|
4125
|
+
async function writeBundle() {
|
|
4126
|
+
log(types.LogLevelLabel.DEBUG, "Finalizing Powerlines project output...");
|
|
4127
|
+
const environment = await api.context.getEnvironment();
|
|
4128
|
+
await api.callHook(environment, "writeBundle");
|
|
4129
|
+
}
|
|
4130
|
+
chunkSHUYVCID_js.__name(writeBundle, "writeBundle");
|
|
4131
|
+
const result = {
|
|
4132
|
+
name: "powerlines",
|
|
4133
|
+
resolveId: {
|
|
4134
|
+
filter: {
|
|
4135
|
+
id: {
|
|
4136
|
+
include: [
|
|
4137
|
+
/.*/
|
|
4138
|
+
]
|
|
4139
|
+
}
|
|
4140
|
+
},
|
|
4141
|
+
handler: resolveId
|
|
4142
|
+
},
|
|
4143
|
+
load: {
|
|
4144
|
+
filter: {
|
|
4145
|
+
id: {
|
|
4146
|
+
include: [
|
|
4147
|
+
/.*/,
|
|
4148
|
+
/^storm:/
|
|
4149
|
+
]
|
|
4150
|
+
}
|
|
4151
|
+
},
|
|
4152
|
+
handler: load
|
|
4153
|
+
},
|
|
4154
|
+
transform,
|
|
4155
|
+
buildStart,
|
|
4156
|
+
writeBundle
|
|
4157
|
+
};
|
|
4158
|
+
return decorate ? decorate(api, result) : result;
|
|
4159
|
+
} catch (error) {
|
|
4160
|
+
log(types.LogLevelLabel.FATAL, error?.message);
|
|
4161
|
+
throw error;
|
|
4162
|
+
}
|
|
4163
|
+
};
|
|
4164
|
+
}
|
|
4165
|
+
chunkSHUYVCID_js.__name(createUnpluginFactory, "createUnpluginFactory");
|
|
4166
|
+
|
|
4167
|
+
// ../powerlines/src/vite.ts
|
|
4168
|
+
var vite = unplugin.createVitePlugin(createUnpluginFactory("vite", (api, plugin) => {
|
|
4169
|
+
return {
|
|
4170
|
+
...plugin,
|
|
4171
|
+
vite: {
|
|
4172
|
+
sharedDuringBuild: true,
|
|
4173
|
+
async hotUpdate(options) {
|
|
4174
|
+
const environment = await api.context.getEnvironment();
|
|
4175
|
+
return api.callHook(environment, "vite:hotUpdate", options);
|
|
4176
|
+
},
|
|
4177
|
+
async config(config, env) {
|
|
4178
|
+
api.context.config.mode = environmentChecks.isDevelopmentMode(env.mode) ? "development" : environmentChecks.isTestMode(env.mode) ? "test" : "production";
|
|
4179
|
+
const environment = await api.context.getEnvironment();
|
|
4180
|
+
const result = await api.callHook(environment, "config");
|
|
4181
|
+
return defu4__default.default(extractViteConfig(api.context), result?.build ?? {}, config);
|
|
4182
|
+
},
|
|
4183
|
+
async configResolved(_config) {
|
|
4184
|
+
const environment = await api.context.getEnvironment();
|
|
4185
|
+
await api.callHook(environment, "configResolved");
|
|
4186
|
+
},
|
|
4187
|
+
async configureServer(server) {
|
|
4188
|
+
const environment = await api.context.getEnvironment();
|
|
4189
|
+
return api.callHook(environment, "vite:configureServer", server);
|
|
4190
|
+
},
|
|
4191
|
+
async configurePreviewServer(server) {
|
|
4192
|
+
const environment = await api.context.getEnvironment();
|
|
4193
|
+
return api.callHook(environment, "vite:configurePreviewServer", server);
|
|
4194
|
+
},
|
|
4195
|
+
async transformIndexHtml(html, ctx) {
|
|
4196
|
+
const environment = await api.context.getEnvironment();
|
|
4197
|
+
return api.callHook(environment, "vite:transformIndexHtml", html, ctx);
|
|
4198
|
+
},
|
|
4199
|
+
async handleHotUpdate(ctx) {
|
|
4200
|
+
const environment = await api.context.getEnvironment();
|
|
4201
|
+
return api.callHook(environment, "vite:handleHotUpdate", ctx);
|
|
4202
|
+
}
|
|
4203
|
+
}
|
|
4204
|
+
};
|
|
4205
|
+
}));
|
|
4206
|
+
var vite_default = vite;
|
|
4207
|
+
unplugin.createEsbuildPlugin(createUnpluginFactory("esbuild", (api, plugin) => {
|
|
4208
|
+
return {
|
|
4209
|
+
...plugin,
|
|
4210
|
+
esbuild: {
|
|
4211
|
+
config: /* @__PURE__ */ chunkSHUYVCID_js.__name((options) => {
|
|
4212
|
+
options ??= {};
|
|
4213
|
+
const result = extractESBuildConfig(api.context);
|
|
4214
|
+
for (const key in result) {
|
|
4215
|
+
if (isUndefined.isUndefined(options[key]) && !isUndefined.isUndefined(result[key])) {
|
|
4216
|
+
options[key] = result[key];
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
}, "config"),
|
|
4220
|
+
setup: /* @__PURE__ */ chunkSHUYVCID_js.__name(async (build) => {
|
|
4221
|
+
const environment = await api.context.getEnvironment();
|
|
4222
|
+
return api.callHook(environment, "esbuild:setup", build);
|
|
4223
|
+
}, "setup")
|
|
4224
|
+
}
|
|
4225
|
+
};
|
|
4226
|
+
}));
|
|
4227
|
+
var webpack = unplugin.createWebpackPlugin(createUnpluginFactory("webpack"));
|
|
4228
|
+
var webpack_default = webpack;
|
|
4229
|
+
kit.defineNuxtModule({
|
|
4230
|
+
meta: {
|
|
4231
|
+
name: "powerlines",
|
|
4232
|
+
configKey: "storm"
|
|
4233
|
+
},
|
|
4234
|
+
defaults: {},
|
|
4235
|
+
setup(options, _nuxt) {
|
|
4236
|
+
kit.addVitePlugin(() => vite_default(options));
|
|
4237
|
+
kit.addWebpackPlugin(() => webpack_default(options));
|
|
4238
|
+
}
|
|
4239
|
+
});
|
|
4240
|
+
unplugin.createRolldownPlugin(createUnpluginFactory("rolldown"));
|
|
4241
|
+
unplugin.createRollupPlugin(createUnpluginFactory("rollup"));
|
|
4242
|
+
unplugin.createRspackPlugin(createUnpluginFactory("rspack"));
|
|
4243
|
+
unplugin.createUnloaderPlugin(createUnpluginFactory("unloader"));
|
|
4244
|
+
|
|
4245
|
+
// ../powerlines/src/index.ts
|
|
4246
|
+
var src_default = PowerlinesAPI;
|
|
4247
|
+
|
|
4248
|
+
// src/base/base-executor.ts
|
|
4249
|
+
function withExecutor(command, executorFn) {
|
|
4250
|
+
return baseExecutor.withRunExecutor(`Powerlines ${command} command executor`, async (options, context, workspaceConfig) => {
|
|
4251
|
+
if (!context.projectName) {
|
|
4252
|
+
throw new Error("The executor requires `projectName` on the context object.");
|
|
4253
|
+
}
|
|
4254
|
+
if (!context.projectName || !context.projectsConfigurations?.projects || !context.projectsConfigurations.projects[context.projectName] || !context.projectsConfigurations.projects[context.projectName]?.root) {
|
|
4255
|
+
throw new Error("The executor requires `projectsConfigurations` on the context object.");
|
|
4256
|
+
}
|
|
4257
|
+
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
4258
|
+
const api = await src_default.from(workspaceConfig.workspaceRoot, defu4__default.default({
|
|
4259
|
+
root: projectConfig.root,
|
|
4260
|
+
type: projectConfig.projectType,
|
|
4261
|
+
sourceRoot: projectConfig.sourceRoot,
|
|
4262
|
+
tsconfig: options.tsconfig,
|
|
4263
|
+
logLevel: options.logLevel,
|
|
4264
|
+
mode: options.mode,
|
|
4265
|
+
skipCache: options.skipCache,
|
|
4266
|
+
output: {
|
|
4267
|
+
outputPath: options.outputPath ?? projectConfig.targets?.build?.options?.outputPath
|
|
4268
|
+
}
|
|
4269
|
+
}, options));
|
|
4270
|
+
try {
|
|
4271
|
+
return await Promise.resolve(executorFn(defu4__default.default({
|
|
4272
|
+
projectName: context.projectName,
|
|
4273
|
+
options,
|
|
4274
|
+
workspaceConfig,
|
|
4275
|
+
inlineConfig: {
|
|
4276
|
+
command,
|
|
4277
|
+
configFile: options.configFile
|
|
4278
|
+
},
|
|
4279
|
+
command
|
|
4280
|
+
}, context), api));
|
|
4281
|
+
} catch (error) {
|
|
4282
|
+
logger.writeError(`An error occurred while executing the Powerlines ${command} command executor: ${isError.isError(error) ? `${error.message}
|
|
4283
|
+
|
|
4284
|
+
${error.stack}` : "Unknown error"}`);
|
|
4285
|
+
return {
|
|
4286
|
+
success: false
|
|
4287
|
+
};
|
|
4288
|
+
} finally {
|
|
4289
|
+
await api.finalize();
|
|
4290
|
+
}
|
|
4291
|
+
}, {
|
|
4292
|
+
skipReadingConfig: false,
|
|
4293
|
+
hooks: {
|
|
4294
|
+
applyDefaultOptions: /* @__PURE__ */ chunkSHUYVCID_js.__name((options) => {
|
|
4295
|
+
if (options.mode !== "development" && options.mode !== "test") {
|
|
4296
|
+
options.mode = "production";
|
|
4297
|
+
}
|
|
4298
|
+
options.outputPath ??= "dist/{projectRoot}";
|
|
4299
|
+
options.configFile ??= "{projectRoot}/powerlines.config.ts";
|
|
4300
|
+
return options;
|
|
4301
|
+
}, "applyDefaultOptions")
|
|
4302
|
+
}
|
|
4303
|
+
});
|
|
4304
|
+
}
|
|
4305
|
+
chunkSHUYVCID_js.__name(withExecutor, "withExecutor");
|
|
4306
|
+
|
|
4307
|
+
exports.withExecutor = withExecutor;
|