@powerlines/nx 0.9.5 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +34 -32
- package/dist/{chunk-RLV2BDHW.mjs → chunk-3E654WM2.mjs} +1 -1
- package/dist/{chunk-JMPM6JPD.js → chunk-5BPEG52U.js} +2 -2
- package/dist/chunk-67ALH5AX.js +327 -0
- package/dist/{chunk-Y2I6ZDWH.js → chunk-DODH7R3U.js} +2 -2
- package/dist/{chunk-SV7QXBCB.mjs → chunk-DVGRVHRD.mjs} +51 -52
- package/dist/{chunk-EVC3CWDX.mjs → chunk-H4ROBXJM.mjs} +1 -1
- package/dist/{chunk-P5UNWOB6.js → chunk-IS2MEDGI.js} +2 -2
- package/dist/chunk-KBRKYARM.mjs +320 -0
- package/dist/{chunk-IXFAMU7J.js → chunk-MI5C7LYS.js} +2 -2
- package/dist/{chunk-TEBG7V3S.mjs → chunk-MSR5HSGP.mjs} +513 -481
- package/dist/{chunk-GW5UQFFS.js → chunk-NFAKPYKX.js} +2 -2
- package/dist/{chunk-HTYRXIRM.mjs → chunk-QEHHWZYD.mjs} +1 -1
- package/dist/{chunk-F3XVH3HG.mjs → chunk-QY2HEZSZ.mjs} +1 -1
- package/dist/{chunk-OVUCSGTD.mjs → chunk-RPI3PNLJ.mjs} +1 -1
- package/dist/{chunk-JTW7QFIT.js → chunk-SXA7B3TE.js} +533 -502
- package/dist/{chunk-4UWZOCEA.js → chunk-UOTRU26N.js} +51 -52
- package/dist/executors.js +12 -12
- package/dist/executors.mjs +7 -7
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -15
- package/dist/index.mjs +8 -8
- package/dist/src/base/base-executor.js +3 -3
- package/dist/src/base/base-executor.mjs +2 -2
- package/dist/src/executors/build/executor.js +5 -5
- package/dist/src/executors/build/executor.mjs +3 -3
- package/dist/src/executors/clean/executor.js +5 -5
- package/dist/src/executors/clean/executor.mjs +3 -3
- package/dist/src/executors/docs/executor.js +5 -5
- package/dist/src/executors/docs/executor.mjs +3 -3
- package/dist/src/executors/lint/executor.js +5 -5
- package/dist/src/executors/lint/executor.mjs +3 -3
- package/dist/src/executors/prepare/executor.js +5 -5
- package/dist/src/executors/prepare/executor.mjs +3 -3
- package/dist/src/plugin/index.d.mts +173 -11
- package/dist/src/plugin/index.d.ts +173 -11
- package/dist/src/plugin/index.js +4 -4
- package/dist/src/plugin/index.mjs +2 -2
- package/package.json +18 -18
- package/dist/chunk-FFBOHADM.mjs +0 -286
- package/dist/chunk-IFMXBBI7.js +0 -293
- package/dist/src/executors/build/schema.d.ts +0 -85
- package/dist/src/executors/build/schema.json +0 -96
- package/dist/src/executors/clean/schema.d.ts +0 -75
- package/dist/src/executors/clean/schema.json +0 -77
- package/dist/src/executors/docs/schema.d.ts +0 -75
- package/dist/src/executors/docs/schema.json +0 -77
- package/dist/src/executors/lint/schema.d.ts +0 -75
- package/dist/src/executors/lint/schema.json +0 -77
- package/dist/src/executors/prepare/schema.d.ts +0 -75
- package/dist/src/executors/prepare/schema.json +0 -77
- package/dist/src/generators/sync/schema.d.ts +0 -15
- package/dist/src/generators/sync/schema.json +0 -19
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { __VFS_CACHE__, __VFS_RESOLVER__, __VFS_VIRTUAL__, __VFS_UNIFIED__, __VFS_INIT__, __VFS_REVERT__, loadWorkspaceConfig, CACHE_HASH_LENGTH, PROJECT_ROOT_HASH_LENGTH, getPrefixedProjectRootHash, getChecksum, loadUserConfigFile, writeMetaFile } from './chunk-
|
|
1
|
+
import { __VFS_CACHE__, __VFS_RESOLVER__, __VFS_VIRTUAL__, __VFS_UNIFIED__, __VFS_INIT__, __VFS_REVERT__, loadWorkspaceConfig, CACHE_HASH_LENGTH, PROJECT_ROOT_HASH_LENGTH, getPrefixedProjectRootHash, getChecksum, loadUserConfigFile, writeMetaFile } from './chunk-DVGRVHRD.mjs';
|
|
2
2
|
import { __name } from './chunk-O6YSETKJ.mjs';
|
|
3
3
|
import { getLogFn, getLogLevel, writeError } from '@storm-software/config-tools/logger';
|
|
4
4
|
import { withRunExecutor } from '@storm-software/workspace-tools/base/base-executor';
|
|
5
5
|
import { isError } from '@stryke/type-checks/is-error';
|
|
6
|
-
import
|
|
6
|
+
import defu3, { defu } from 'defu';
|
|
7
|
+
import { transformAsync } from '@babel/core';
|
|
7
8
|
import { formatLogMessage } from '@storm-software/config-tools/logger/console';
|
|
8
9
|
import { LogLevelLabel } from '@storm-software/config-tools/types';
|
|
9
10
|
import { toArray } from '@stryke/convert/to-array';
|
|
@@ -13,8 +14,9 @@ import { createDirectory } from '@stryke/fs/helpers';
|
|
|
13
14
|
import { install } from '@stryke/fs/install';
|
|
14
15
|
import { listFiles, listFilesSync } from '@stryke/fs/list-files';
|
|
15
16
|
import { isPackageExists, isPackageListed, doesPackageMatch, getPackageListing } from '@stryke/fs/package-fns';
|
|
17
|
+
import { resolvePackage } from '@stryke/fs/resolve';
|
|
16
18
|
import { joinPaths } from '@stryke/path/join-paths';
|
|
17
|
-
import { replacePath } from '@stryke/path/replace';
|
|
19
|
+
import { replacePath, replaceExtension } from '@stryke/path/replace';
|
|
18
20
|
import { isFunction } from '@stryke/type-checks/is-function';
|
|
19
21
|
import { isNumber } from '@stryke/type-checks/is-number';
|
|
20
22
|
import { isPromiseLike } from '@stryke/type-checks/is-promise';
|
|
@@ -23,20 +25,17 @@ import { isSetObject } from '@stryke/type-checks/is-set-object';
|
|
|
23
25
|
import { isSetString } from '@stryke/type-checks/is-set-string';
|
|
24
26
|
import chalk5 from 'chalk';
|
|
25
27
|
import Handlebars from 'handlebars';
|
|
26
|
-
import {
|
|
27
|
-
import
|
|
28
|
-
import ts2, { createProgram, createCompilerHost, getPreEmitDiagnostics, getLineAndCharacterOfPosition, flattenDiagnosticMessageText } from 'typescript';
|
|
29
|
-
import { isUndefined } from '@stryke/type-checks/is-undefined';
|
|
30
|
-
import { writeFile as writeFile$1 } from '@stryke/fs/write-file';
|
|
31
|
-
import { resolveConfig, format } from 'prettier';
|
|
32
|
-
import { resolvePackage } from '@stryke/fs/resolve';
|
|
28
|
+
import { declare } from '@babel/helper-plugin-utils';
|
|
29
|
+
import * as t from '@babel/types';
|
|
33
30
|
import { titleCase } from '@stryke/string-format/title-case';
|
|
34
31
|
import { getEnvPaths } from '@stryke/env/get-env-paths';
|
|
35
32
|
import { relativeToWorkspaceRoot, getWorkspaceRoot } from '@stryke/fs/get-workspace-root';
|
|
33
|
+
import { readJsonFile, readJsonFileSync } from '@stryke/fs/json';
|
|
36
34
|
import { murmurhash } from '@stryke/hash/murmurhash';
|
|
37
35
|
import { getUnique, getUniqueBy } from '@stryke/helpers/get-unique';
|
|
38
36
|
import { omit } from '@stryke/helpers/omit';
|
|
39
|
-
import {
|
|
37
|
+
import { appendPath } from '@stryke/path/append';
|
|
38
|
+
import { findFilePath, findFileDotExtensionSafe, hasFileExtension, relativePath, findFileName } from '@stryke/path/file-path-fns';
|
|
40
39
|
import { isAbsolutePath, isAbsolute } from '@stryke/path/is-type';
|
|
41
40
|
import { joinPaths as joinPaths$1 } from '@stryke/path/join';
|
|
42
41
|
import { isNull } from '@stryke/type-checks/is-null';
|
|
@@ -44,8 +43,10 @@ import { isString } from '@stryke/type-checks/is-string';
|
|
|
44
43
|
import { uuid } from '@stryke/unique-id/uuid';
|
|
45
44
|
import { parseAsync } from 'oxc-parser';
|
|
46
45
|
import { parseTypeDefinition } from '@stryke/convert/parse-type-definition';
|
|
46
|
+
import { isFile } from '@stryke/fs/is-file';
|
|
47
47
|
import { getColor } from '@storm-software/config-tools/utilities/colors';
|
|
48
48
|
import { noop } from '@stryke/helpers/noop';
|
|
49
|
+
import { isUndefined } from '@stryke/type-checks/is-undefined';
|
|
49
50
|
import { createJiti } from 'jiti';
|
|
50
51
|
import { bufferToString } from '@stryke/convert/buffer-to-string';
|
|
51
52
|
import { isParentPath } from '@stryke/path/is-parent-path';
|
|
@@ -54,194 +55,127 @@ import { isBuffer } from '@stryke/type-checks/is-buffer';
|
|
|
54
55
|
import { Volume } from 'memfs';
|
|
55
56
|
import { Blob } from 'node:buffer';
|
|
56
57
|
import fs from 'node:fs';
|
|
58
|
+
import { resolveConfig, format } from 'prettier';
|
|
57
59
|
import { Union } from 'unionfs';
|
|
58
60
|
import { isObject } from '@stryke/type-checks/is-object';
|
|
59
|
-
import {
|
|
60
|
-
import { readFileIfExistingSync } from '@stryke/fs/read-file';
|
|
61
|
-
import MagicString from 'magic-string';
|
|
62
|
-
import { declare } from '@babel/helper-plugin-utils';
|
|
63
|
-
import * as t from '@babel/types';
|
|
61
|
+
import ts2, { createProgram, createCompilerHost, getPreEmitDiagnostics, getLineAndCharacterOfPosition, flattenDiagnosticMessageText } from 'typescript';
|
|
64
62
|
import { getPackageName, hasPackageVersion, getPackageVersion } from '@stryke/string-format/package';
|
|
65
63
|
import { getObjectDiff } from '@donedeal0/superdiff';
|
|
66
64
|
import { loadTsConfig } from '@stryke/fs/tsconfig';
|
|
67
65
|
import { StormJSON } from '@stryke/json/storm-json';
|
|
66
|
+
import { writeFile as writeFile$1 } from '@stryke/fs/write-file';
|
|
68
67
|
import { isDevelopmentMode, isTestMode } from '@stryke/env/environment-checks';
|
|
69
68
|
import { createVitePlugin, createEsbuildPlugin, createWebpackPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin } from 'unplugin';
|
|
70
69
|
import { match, tsconfigPathsToRegExp } from 'bundle-require';
|
|
70
|
+
import '@stryke/fs/read-file';
|
|
71
|
+
import 'magic-string';
|
|
71
72
|
import { defineNuxtModule, addVitePlugin, addWebpackPlugin } from '@nuxt/kit';
|
|
72
73
|
import '@nuxt/schema';
|
|
73
74
|
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
tsconfigFilePath = appendPath(tsconfig, projectRoot);
|
|
78
|
-
if (!existsSync(tsconfigFilePath)) {
|
|
79
|
-
tsconfigFilePath = appendPath(tsconfig, workspaceRoot);
|
|
80
|
-
if (!existsSync(tsconfigFilePath)) {
|
|
81
|
-
tsconfigFilePath = appendPath(tsconfig, joinPaths(workspaceRoot, projectRoot));
|
|
82
|
-
if (!existsSync(tsconfigFilePath)) {
|
|
83
|
-
throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${tsconfig}, ${appendPath(tsconfig, projectRoot)}, ${appendPath(tsconfig, workspaceRoot)}, or ${tsconfigFilePath}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return tsconfigFilePath;
|
|
89
|
-
}
|
|
90
|
-
__name(getTsconfigFilePath, "getTsconfigFilePath");
|
|
91
|
-
function findMatch(tsconfigType, types, extensions = [
|
|
92
|
-
".ts",
|
|
93
|
-
".tsx",
|
|
94
|
-
".d.ts"
|
|
95
|
-
]) {
|
|
96
|
-
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}`));
|
|
97
|
-
}
|
|
98
|
-
__name(findMatch, "findMatch");
|
|
99
|
-
function findIncludeMatch(tsconfigType, types) {
|
|
100
|
-
return findMatch(tsconfigType, types, [
|
|
101
|
-
".ts",
|
|
102
|
-
".tsx",
|
|
103
|
-
".d.ts",
|
|
104
|
-
".js",
|
|
105
|
-
".jsx",
|
|
106
|
-
".mjs",
|
|
107
|
-
".cjs",
|
|
108
|
-
".mts",
|
|
109
|
-
".cts",
|
|
110
|
-
"/*.ts",
|
|
111
|
-
"/*.tsx",
|
|
112
|
-
"/*.d.ts",
|
|
113
|
-
"/*.js",
|
|
114
|
-
"/*.jsx",
|
|
115
|
-
"/*.mjs",
|
|
116
|
-
"/*.cjs",
|
|
117
|
-
"/*.mts",
|
|
118
|
-
"/*.cts",
|
|
119
|
-
"/**/*.ts",
|
|
120
|
-
"/**/*.tsx",
|
|
121
|
-
"/**/*.d.ts",
|
|
122
|
-
"/**/*.js",
|
|
123
|
-
"/**/*.jsx",
|
|
124
|
-
"/**/*.mjs",
|
|
125
|
-
"/**/*.cjs",
|
|
126
|
-
"/**/*.mts",
|
|
127
|
-
"/**/*.cts"
|
|
128
|
-
]);
|
|
129
|
-
}
|
|
130
|
-
__name(findIncludeMatch, "findIncludeMatch");
|
|
131
|
-
function isIncludeMatchFound(tsconfigType, types) {
|
|
132
|
-
return findIncludeMatch(tsconfigType, types) !== void 0;
|
|
133
|
-
}
|
|
134
|
-
__name(isIncludeMatchFound, "isIncludeMatchFound");
|
|
135
|
-
function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfigRaw = {}, originalTsconfigJson, host = ts2.sys) {
|
|
136
|
-
const tsconfigFilePath = getTsconfigFilePath(workspaceRoot, projectRoot, tsconfig);
|
|
137
|
-
const tsconfigJson = readJsonFileSync(tsconfigFilePath);
|
|
138
|
-
if (!tsconfigJson) {
|
|
139
|
-
throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${joinPaths(projectRoot, tsconfig ?? "tsconfig.json")}`);
|
|
75
|
+
function resolveModulePath(nodePath, state) {
|
|
76
|
+
if (!t.isStringLiteral(nodePath.node)) {
|
|
77
|
+
return;
|
|
140
78
|
}
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
79
|
+
const sourcePath = nodePath.node.value;
|
|
80
|
+
const resolvedPath = state.context?.fs.resolve(sourcePath);
|
|
81
|
+
if (resolvedPath) {
|
|
82
|
+
nodePath.replaceWith(t.stringLiteral(
|
|
83
|
+
// Remove the file extension if it exists
|
|
84
|
+
resolvedPath.replace(/\.(?:ts|mts|cts)x?$/, "")
|
|
85
|
+
));
|
|
147
86
|
}
|
|
148
|
-
return {
|
|
149
|
-
...parsedCommandLine,
|
|
150
|
-
originalTsconfigJson: originalTsconfigJson ?? tsconfigJson,
|
|
151
|
-
tsconfigJson,
|
|
152
|
-
tsconfigFilePath
|
|
153
|
-
};
|
|
154
87
|
}
|
|
155
|
-
__name(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
"
|
|
160
|
-
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
|
|
166
|
-
"
|
|
167
|
-
"
|
|
88
|
+
__name(resolveModulePath, "resolveModulePath");
|
|
89
|
+
var TRANSFORM_FUNCTIONS = [
|
|
90
|
+
"require",
|
|
91
|
+
"require.resolve",
|
|
92
|
+
"System.import",
|
|
93
|
+
// Jest methods
|
|
94
|
+
"jest.genMockFromModule",
|
|
95
|
+
"jest.mock",
|
|
96
|
+
"jest.unmock",
|
|
97
|
+
"jest.doMock",
|
|
98
|
+
// eslint-disable-next-line @cspell/spellchecker
|
|
99
|
+
"jest.dontMock",
|
|
100
|
+
"jest.setMock",
|
|
101
|
+
"jest.requireActual",
|
|
102
|
+
"jest.requireMock",
|
|
103
|
+
// Older Jest methods
|
|
104
|
+
"require.requireActual",
|
|
105
|
+
"require.requireMock"
|
|
168
106
|
];
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
__name(isPlugin, "isPlugin");
|
|
175
|
-
function isPluginConfigObject(value) {
|
|
176
|
-
return isSetObject(value) && "plugin" in value && ((isSetString(value.plugin) || isFunction(value.plugin)) && "options" in value && isSetObject(value.options) || isPlugin(value.plugin));
|
|
177
|
-
}
|
|
178
|
-
__name(isPluginConfigObject, "isPluginConfigObject");
|
|
179
|
-
function isPluginConfigTuple(value) {
|
|
180
|
-
return Array.isArray(value) && (value.length === 1 || value.length === 2) && ((isSetString(value[0]) || isFunction(value[0])) && value.length > 1 && isSetObject(value[1]) || isPlugin(value[0]));
|
|
181
|
-
}
|
|
182
|
-
__name(isPluginConfigTuple, "isPluginConfigTuple");
|
|
183
|
-
function isPluginConfig(value) {
|
|
184
|
-
return isSetString(value) || isFunction(value) || isPlugin(value) || isPluginConfigObject(value) || isPluginConfigTuple(value);
|
|
185
|
-
}
|
|
186
|
-
__name(isPluginConfig, "isPluginConfig");
|
|
187
|
-
function isPluginHookFunction(value) {
|
|
188
|
-
return isFunction(value) || isSetObject(value) && "handler" in value && isFunction(value.handler);
|
|
189
|
-
}
|
|
190
|
-
__name(isPluginHookFunction, "isPluginHookFunction");
|
|
191
|
-
function isPluginHookObject(value) {
|
|
192
|
-
return isSetObject(value) && "handler" in value && isFunction(value.handler);
|
|
193
|
-
}
|
|
194
|
-
__name(isPluginHookObject, "isPluginHookObject");
|
|
195
|
-
function isPluginHook(value) {
|
|
196
|
-
return isPluginHookFunction(value) || isPluginHookObject(value);
|
|
197
|
-
}
|
|
198
|
-
__name(isPluginHook, "isPluginHook");
|
|
199
|
-
function getHookHandler(pluginHook) {
|
|
200
|
-
return isFunction(pluginHook) ? pluginHook : pluginHook.handler;
|
|
201
|
-
}
|
|
202
|
-
__name(getHookHandler, "getHookHandler");
|
|
203
|
-
function isHookExternal(hook) {
|
|
204
|
-
return hook.startsWith("vite:") || hook.startsWith("esbuild:") || hook.startsWith("rolldown:") || hook.startsWith("rollup:") || hook.startsWith("webpack:") || hook.startsWith("rspack:") || hook.startsWith("farm:");
|
|
205
|
-
}
|
|
206
|
-
__name(isHookExternal, "isHookExternal");
|
|
207
|
-
function checkDedupe(plugin, plugins2) {
|
|
208
|
-
return plugin.dedupe === false || plugins2.some((p) => p.dedupe !== false && (isFunction(p.dedupe) && p.dedupe(plugin) || p.name === plugin.name));
|
|
209
|
-
}
|
|
210
|
-
__name(checkDedupe, "checkDedupe");
|
|
211
|
-
function addPluginHook(context, plugin, pluginHook, hooksList) {
|
|
212
|
-
if (!checkDedupe(plugin, hooksList.map((hook) => hook.plugin))) {
|
|
213
|
-
hooksList.push(isFunction(pluginHook) ? {
|
|
214
|
-
plugin,
|
|
215
|
-
handler: getHookHandler(pluginHook).bind(context)
|
|
216
|
-
} : {
|
|
217
|
-
plugin,
|
|
218
|
-
...pluginHook,
|
|
219
|
-
handler: getHookHandler(pluginHook).bind(context)
|
|
220
|
-
});
|
|
107
|
+
function matchesPattern(state, calleePath, pattern) {
|
|
108
|
+
const { node } = calleePath;
|
|
109
|
+
if (t.isMemberExpression(node)) {
|
|
110
|
+
return calleePath.matchesPattern(pattern);
|
|
221
111
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
async function writeFile(log, filepath, content, skipFormat = false) {
|
|
225
|
-
try {
|
|
226
|
-
if (skipFormat) {
|
|
227
|
-
await writeFile$1(filepath, content);
|
|
228
|
-
} else {
|
|
229
|
-
const config = await resolveConfig(filepath);
|
|
230
|
-
const formatted = await format(content, {
|
|
231
|
-
...config ?? {},
|
|
232
|
-
filepath
|
|
233
|
-
});
|
|
234
|
-
await writeFile$1(filepath, formatted || "");
|
|
235
|
-
}
|
|
236
|
-
} catch (error) {
|
|
237
|
-
log(LogLevelLabel.ERROR, `Failed to write file ${filepath} to disk
|
|
238
|
-
${error?.message ? error.message : ""}`);
|
|
112
|
+
if (!t.isIdentifier(node) || pattern.includes(".")) {
|
|
113
|
+
return false;
|
|
239
114
|
}
|
|
115
|
+
const name = pattern.split(".")[0];
|
|
116
|
+
return node.name === name;
|
|
240
117
|
}
|
|
241
|
-
__name(
|
|
118
|
+
__name(matchesPattern, "matchesPattern");
|
|
119
|
+
var importVisitors = {
|
|
120
|
+
CallExpression: /* @__PURE__ */ __name((nodePath, state) => {
|
|
121
|
+
if (state.moduleResolverVisited.has(nodePath)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const calleePath = nodePath.get("callee");
|
|
125
|
+
if (calleePath && TRANSFORM_FUNCTIONS.some((pattern) => matchesPattern(state, calleePath, pattern)) || t.isImport(nodePath.node.callee)) {
|
|
126
|
+
state.moduleResolverVisited.add(nodePath);
|
|
127
|
+
resolveModulePath(nodePath.get("arguments.0"), state);
|
|
128
|
+
}
|
|
129
|
+
}, "CallExpression"),
|
|
130
|
+
// eslint-disable-next-line ts/naming-convention
|
|
131
|
+
"ImportDeclaration|ExportDeclaration|ExportAllDeclaration": /* @__PURE__ */ __name((nodePath, state) => {
|
|
132
|
+
if (!nodePath || !nodePath.get("source") || state.moduleResolverVisited.has(nodePath)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
state.moduleResolverVisited.add(nodePath);
|
|
136
|
+
resolveModulePath(nodePath.get("source"), state);
|
|
137
|
+
}, "ImportDeclaration|ExportDeclaration|ExportAllDeclaration")
|
|
138
|
+
};
|
|
139
|
+
var moduleResolverBabelPlugin = /* @__PURE__ */ __name((context) => {
|
|
140
|
+
return declare(/* @__PURE__ */ __name(function builder(api) {
|
|
141
|
+
let moduleResolverVisited = /* @__PURE__ */ new Set();
|
|
142
|
+
return {
|
|
143
|
+
name: "powerlines:module-resolver",
|
|
144
|
+
manipulateOptions(opts) {
|
|
145
|
+
opts.filename ??= "unknown";
|
|
146
|
+
},
|
|
147
|
+
pre() {
|
|
148
|
+
moduleResolverVisited = /* @__PURE__ */ new Set();
|
|
149
|
+
},
|
|
150
|
+
visitor: {
|
|
151
|
+
Program: {
|
|
152
|
+
enter(programPath, state) {
|
|
153
|
+
programPath.traverse(importVisitors, {
|
|
154
|
+
...state,
|
|
155
|
+
context,
|
|
156
|
+
moduleResolverVisited,
|
|
157
|
+
api
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
exit(programPath, state) {
|
|
161
|
+
programPath.traverse(importVisitors, {
|
|
162
|
+
...state,
|
|
163
|
+
context,
|
|
164
|
+
moduleResolverVisited,
|
|
165
|
+
api
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
post() {
|
|
171
|
+
moduleResolverVisited.clear();
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}, "builder"));
|
|
175
|
+
}, "moduleResolverBabelPlugin");
|
|
242
176
|
var DEFAULT_ENVIRONMENT = "default";
|
|
243
177
|
function createEnvironment(name, userConfig) {
|
|
244
|
-
return
|
|
178
|
+
return defu3(userConfig.environments?.[name] ?? {}, {
|
|
245
179
|
name,
|
|
246
180
|
title: userConfig.title || titleCase(userConfig.name),
|
|
247
181
|
ssr: false,
|
|
@@ -296,7 +230,7 @@ function resolveEntryInput(context, typeDefinition) {
|
|
|
296
230
|
}
|
|
297
231
|
__name(resolveEntryInput, "resolveEntryInput");
|
|
298
232
|
function resolveEntryOutput(context, typeDefinition) {
|
|
299
|
-
return joinPaths(replacePath(replacePath(replacePath(replacePath(typeDefinition.file, joinPaths(context.workspaceConfig.workspaceRoot, context.config.sourceRoot)), joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot)), context.config.sourceRoot), context.config.projectRoot))
|
|
233
|
+
return replaceExtension(joinPaths(replacePath(replacePath(replacePath(replacePath(typeDefinition.file, joinPaths(context.workspaceConfig.workspaceRoot, context.config.sourceRoot)), joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot)), context.config.sourceRoot), context.config.projectRoot)));
|
|
300
234
|
}
|
|
301
235
|
__name(resolveEntryOutput, "resolveEntryOutput");
|
|
302
236
|
function resolveEntry(context, typeDefinition) {
|
|
@@ -311,7 +245,14 @@ __name(resolveEntry, "resolveEntry");
|
|
|
311
245
|
function resolveEntriesSync(context, typeDefinitions) {
|
|
312
246
|
return typeDefinitions.map((typeDefinition) => {
|
|
313
247
|
const parsed = parseTypeDefinition(typeDefinition);
|
|
314
|
-
|
|
248
|
+
const filePath = appendPath(parsed.file, context.config.projectRoot);
|
|
249
|
+
if (isFile(filePath)) {
|
|
250
|
+
return resolveEntry(context, {
|
|
251
|
+
file: replacePath(filePath, context.config.projectRoot),
|
|
252
|
+
name: parsed.name
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return listFilesSync(filePath).map((file) => resolveEntry(context, {
|
|
315
256
|
file,
|
|
316
257
|
name: parsed.name
|
|
317
258
|
}));
|
|
@@ -362,8 +303,76 @@ var BADGE_COLORS = [
|
|
|
362
303
|
var extendLog = /* @__PURE__ */ __name((logFn, name) => {
|
|
363
304
|
return (type, ...args) => logFn(type, ` ${chalk5.inverse.hex(BADGE_COLORS[name.split("").map((char) => char.charCodeAt(0)).reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length] || BADGE_COLORS[0])(` ${titleCase(name)} `)} ${args.join(" ")} `);
|
|
364
305
|
}, "extendLog");
|
|
306
|
+
|
|
307
|
+
// ../powerlines/src/types/commands.ts
|
|
308
|
+
var SUPPORTED_COMMANDS = [
|
|
309
|
+
"new",
|
|
310
|
+
"clean",
|
|
311
|
+
"prepare",
|
|
312
|
+
"lint",
|
|
313
|
+
"test",
|
|
314
|
+
"build",
|
|
315
|
+
"docs",
|
|
316
|
+
"release",
|
|
317
|
+
"finalize"
|
|
318
|
+
];
|
|
319
|
+
|
|
320
|
+
// ../powerlines/src/plugin-utils/helpers.ts
|
|
321
|
+
function isPlugin(value) {
|
|
322
|
+
return isSetObject(value) && "name" in value && isSetString(value.name) && (isUndefined(value.applyToEnvironment) || "applyToEnvironment" in value && isFunction(value.applyToEnvironment)) && (isUndefined(value.dedupe) || "dedupe" in value && isFunction(value.dedupe)) && (isUndefined(value.dependsOn) || "dependsOn" in value && Array.isArray(value.dependsOn) && value.dependsOn.every(isPluginConfig)) && SUPPORTED_COMMANDS.every((command) => isUndefined(value[command]) || command in value && (isFunction(value[command]) || isSetObject(value[command]) && "handler" in value[command] && isFunction(value[command].handler)));
|
|
323
|
+
}
|
|
324
|
+
__name(isPlugin, "isPlugin");
|
|
325
|
+
function isPluginConfigObject(value) {
|
|
326
|
+
return isSetObject(value) && "plugin" in value && ((isSetString(value.plugin) || isFunction(value.plugin)) && "options" in value && isSetObject(value.options) || isPlugin(value.plugin));
|
|
327
|
+
}
|
|
328
|
+
__name(isPluginConfigObject, "isPluginConfigObject");
|
|
329
|
+
function isPluginConfigTuple(value) {
|
|
330
|
+
return Array.isArray(value) && (value.length === 1 || value.length === 2) && ((isSetString(value[0]) || isFunction(value[0])) && value.length > 1 && isSetObject(value[1]) || isPlugin(value[0]));
|
|
331
|
+
}
|
|
332
|
+
__name(isPluginConfigTuple, "isPluginConfigTuple");
|
|
333
|
+
function isPluginConfig(value) {
|
|
334
|
+
return isSetString(value) || isFunction(value) || isPlugin(value) || isPluginConfigObject(value) || isPluginConfigTuple(value);
|
|
335
|
+
}
|
|
336
|
+
__name(isPluginConfig, "isPluginConfig");
|
|
337
|
+
function isPluginHookFunction(value) {
|
|
338
|
+
return isFunction(value) || isSetObject(value) && "handler" in value && isFunction(value.handler);
|
|
339
|
+
}
|
|
340
|
+
__name(isPluginHookFunction, "isPluginHookFunction");
|
|
341
|
+
function isPluginHookObject(value) {
|
|
342
|
+
return isSetObject(value) && "handler" in value && isFunction(value.handler);
|
|
343
|
+
}
|
|
344
|
+
__name(isPluginHookObject, "isPluginHookObject");
|
|
345
|
+
function isPluginHook(value) {
|
|
346
|
+
return isPluginHookFunction(value) || isPluginHookObject(value);
|
|
347
|
+
}
|
|
348
|
+
__name(isPluginHook, "isPluginHook");
|
|
349
|
+
function getHookHandler(pluginHook) {
|
|
350
|
+
return isFunction(pluginHook) ? pluginHook : pluginHook.handler;
|
|
351
|
+
}
|
|
352
|
+
__name(getHookHandler, "getHookHandler");
|
|
353
|
+
function isHookExternal(hook) {
|
|
354
|
+
return hook.startsWith("vite:") || hook.startsWith("esbuild:") || hook.startsWith("rolldown:") || hook.startsWith("rollup:") || hook.startsWith("webpack:") || hook.startsWith("rspack:") || hook.startsWith("farm:");
|
|
355
|
+
}
|
|
356
|
+
__name(isHookExternal, "isHookExternal");
|
|
357
|
+
function checkDedupe(plugin, plugins2) {
|
|
358
|
+
return plugin.dedupe === false || plugins2.some((p) => p.dedupe !== false && (isFunction(p.dedupe) && p.dedupe(plugin) || p.name === plugin.name));
|
|
359
|
+
}
|
|
360
|
+
__name(checkDedupe, "checkDedupe");
|
|
361
|
+
function addPluginHook(context, plugin, pluginHook, hooksList) {
|
|
362
|
+
if (!checkDedupe(plugin, hooksList.map((hook) => hook.plugin))) {
|
|
363
|
+
hooksList.push(isFunction(pluginHook) ? {
|
|
364
|
+
plugin,
|
|
365
|
+
handler: getHookHandler(pluginHook).bind(context)
|
|
366
|
+
} : {
|
|
367
|
+
plugin,
|
|
368
|
+
...pluginHook,
|
|
369
|
+
handler: getHookHandler(pluginHook).bind(context)
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
__name(addPluginHook, "addPluginHook");
|
|
365
374
|
function resolveOptions(options) {
|
|
366
|
-
return
|
|
375
|
+
return defu3(options, {
|
|
367
376
|
interopDefault: true,
|
|
368
377
|
fsCache: options.mode !== "development" ? joinPaths(options.cacheDir, "jiti") : false,
|
|
369
378
|
moduleCache: options.mode !== "development"
|
|
@@ -851,7 +860,7 @@ var VirtualFileSystem = class {
|
|
|
851
860
|
return;
|
|
852
861
|
}
|
|
853
862
|
this.#log(LogLevelLabel.TRACE, `Synchronously removing directory: ${formattedPath}`);
|
|
854
|
-
this.resolveFS(path, options).rmdirSync(formattedPath,
|
|
863
|
+
this.resolveFS(path, options).rmdirSync(formattedPath, defu3(options, {
|
|
855
864
|
recursive: true
|
|
856
865
|
}));
|
|
857
866
|
this.#cachedFS.delete(formattedPath);
|
|
@@ -871,14 +880,14 @@ var VirtualFileSystem = class {
|
|
|
871
880
|
}
|
|
872
881
|
this.#log(LogLevelLabel.TRACE, `Removing directory: ${formattedPath}`);
|
|
873
882
|
if (isFunction(this.resolveFS(path, options).promises.rm)) {
|
|
874
|
-
await this.resolveFS(path, options).promises.rm(formattedPath,
|
|
883
|
+
await this.resolveFS(path, options).promises.rm(formattedPath, defu3(options, {
|
|
875
884
|
force: true,
|
|
876
885
|
recursive: true
|
|
877
886
|
}));
|
|
878
887
|
this.#cachedFS.delete(formattedPath);
|
|
879
888
|
this.clearResolverCache(formattedPath);
|
|
880
889
|
} else {
|
|
881
|
-
this.rmdirSync(formattedPath,
|
|
890
|
+
this.rmdirSync(formattedPath, defu3(options ?? {}, {
|
|
882
891
|
force: true,
|
|
883
892
|
recursive: true
|
|
884
893
|
}));
|
|
@@ -921,7 +930,7 @@ var VirtualFileSystem = class {
|
|
|
921
930
|
mkdirSync(path, options = {}) {
|
|
922
931
|
const filePath = toFilePath(path);
|
|
923
932
|
this.clearResolverCache(filePath);
|
|
924
|
-
return this.resolveFS(filePath, options).mkdirSync(filePath,
|
|
933
|
+
return this.resolveFS(filePath, options).mkdirSync(filePath, defu3(options ?? {}, {
|
|
925
934
|
recursive: true
|
|
926
935
|
}));
|
|
927
936
|
}
|
|
@@ -936,11 +945,11 @@ var VirtualFileSystem = class {
|
|
|
936
945
|
let result;
|
|
937
946
|
const filePath = toFilePath(path);
|
|
938
947
|
if (isFunction(this.resolveFS(filePath, options).promises.mkdir)) {
|
|
939
|
-
result = await this.resolveFS(filePath, options).promises.mkdir(filePath,
|
|
948
|
+
result = await this.resolveFS(filePath, options).promises.mkdir(filePath, defu3(options ?? {}, {
|
|
940
949
|
recursive: true
|
|
941
950
|
}));
|
|
942
951
|
} else {
|
|
943
|
-
result = this.resolveFS(filePath, options).mkdirSync(filePath,
|
|
952
|
+
result = this.resolveFS(filePath, options).mkdirSync(filePath, defu3(options ?? {}, {
|
|
944
953
|
recursive: true
|
|
945
954
|
}));
|
|
946
955
|
}
|
|
@@ -1882,7 +1891,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1882
1891
|
return this.fs.writeFile(isAbsolute(path) ? path : appendPath(path, this.entryPath), {
|
|
1883
1892
|
code,
|
|
1884
1893
|
variant: "entry"
|
|
1885
|
-
},
|
|
1894
|
+
}, defu3(options, {
|
|
1886
1895
|
mode: this.config.output.mode
|
|
1887
1896
|
}));
|
|
1888
1897
|
}
|
|
@@ -1899,7 +1908,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1899
1908
|
id,
|
|
1900
1909
|
code,
|
|
1901
1910
|
variant: "builtin"
|
|
1902
|
-
},
|
|
1911
|
+
}, defu3(options, {
|
|
1903
1912
|
mode: this.config.output.mode
|
|
1904
1913
|
}));
|
|
1905
1914
|
}
|
|
@@ -1921,7 +1930,7 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1921
1930
|
options
|
|
1922
1931
|
});
|
|
1923
1932
|
}
|
|
1924
|
-
const result = await parseAsync(id, code,
|
|
1933
|
+
const result = await parseAsync(id, code, defu3(options ?? {}, {
|
|
1925
1934
|
lang: hasFileExtension(id) ? void 0 : "ts",
|
|
1926
1935
|
astType: hasFileExtension(id) ? void 0 : "ts",
|
|
1927
1936
|
sourceType: "module",
|
|
@@ -2023,6 +2032,7 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
|
|
|
2023
2032
|
mode: (config.mode ?? this.config.mode) || this.workspaceConfig.mode,
|
|
2024
2033
|
skipCache: config.skipCache ?? this.config.skipCache ?? false,
|
|
2025
2034
|
configFile: config.configFile ?? this.config.configFile,
|
|
2035
|
+
framework: config.framework ?? this.config.framework ?? "powerlines",
|
|
2026
2036
|
command: this.config.inlineConfig?.command
|
|
2027
2037
|
};
|
|
2028
2038
|
if (configCache.has(cacheKey)) {
|
|
@@ -2049,7 +2059,7 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
|
|
|
2049
2059
|
mode: cacheKey.mode,
|
|
2050
2060
|
skipCache: cacheKey.skipCache
|
|
2051
2061
|
});
|
|
2052
|
-
const userConfig = await loadUserConfigFile(cacheKey.projectRoot, this.resolver, cacheKey.command, cacheKey.mode, cacheKey.configFile);
|
|
2062
|
+
const userConfig = await loadUserConfigFile(cacheKey.projectRoot, this.resolver, cacheKey.command, cacheKey.mode, cacheKey.configFile, cacheKey.framework);
|
|
2053
2063
|
this.mergeUserConfig(userConfig.config);
|
|
2054
2064
|
configCache.set(cacheKey, {
|
|
2055
2065
|
projectJson: this.projectJson,
|
|
@@ -2060,7 +2070,7 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
|
|
|
2060
2070
|
});
|
|
2061
2071
|
}
|
|
2062
2072
|
if (isSetObject(config)) {
|
|
2063
|
-
this.resolvedConfig =
|
|
2073
|
+
this.resolvedConfig = defu3({
|
|
2064
2074
|
inlineConfig: this.config.inlineConfig,
|
|
2065
2075
|
userConfig: this.config.userConfig
|
|
2066
2076
|
}, options.isHighPriority ? this.#getConfigProps(config) : {}, {
|
|
@@ -2156,7 +2166,7 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
|
|
|
2156
2166
|
}, []);
|
|
2157
2167
|
}
|
|
2158
2168
|
mergeUserConfig(from = {}, into = this.config.userConfig ?? {}) {
|
|
2159
|
-
this.config.userConfig =
|
|
2169
|
+
this.config.userConfig = defu3({
|
|
2160
2170
|
entry: Array.isArray(from.entry) && from.entry.length > 0 ? from.entry : Array.isArray(into?.entry) && into.entry.length > 0 ? into.entry : []
|
|
2161
2171
|
}, omit(from ?? {}, [
|
|
2162
2172
|
"entry"
|
|
@@ -2469,272 +2479,61 @@ var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext
|
|
|
2469
2479
|
context.environment = environment;
|
|
2470
2480
|
context.plugins = [];
|
|
2471
2481
|
for (const plugin of this.plugins) {
|
|
2472
|
-
await context.addPlugin(plugin);
|
|
2473
|
-
}
|
|
2474
|
-
return context;
|
|
2475
|
-
}
|
|
2476
|
-
async addPlugin(plugin) {
|
|
2477
|
-
this.plugins.push(plugin);
|
|
2478
|
-
await Promise.all(Object.keys(this.environments).map(async (name) => {
|
|
2479
|
-
await this.environments[name].addPlugin(plugin);
|
|
2480
|
-
}));
|
|
2481
|
-
}
|
|
2482
|
-
async getEnvironment(name) {
|
|
2483
|
-
let environment;
|
|
2484
|
-
if (name) {
|
|
2485
|
-
environment = this.environments[name];
|
|
2486
|
-
}
|
|
2487
|
-
if (Object.keys(this.environments).length === 1) {
|
|
2488
|
-
environment = this.environments[Object.keys(this.environments)[0]];
|
|
2489
|
-
this.log(LogLevelLabel.DEBUG, `Applying the only configured environment: ${chalk5.bold.cyanBright(environment?.environment.name)}`);
|
|
2490
|
-
}
|
|
2491
|
-
if (!environment) {
|
|
2492
|
-
if (name) {
|
|
2493
|
-
throw new Error(`Environment "${name}" not found.`);
|
|
2494
|
-
}
|
|
2495
|
-
environment = await this.in(createDefaultEnvironment(this.config.userConfig));
|
|
2496
|
-
this.log(LogLevelLabel.WARN, `No environment specified, and no default environment found. Using a temporary default environment: ${chalk5.bold.cyanBright(environment?.environment.name)}`);
|
|
2497
|
-
}
|
|
2498
|
-
return environment;
|
|
2499
|
-
}
|
|
2500
|
-
async getEnvironmentSafe(name) {
|
|
2501
|
-
try {
|
|
2502
|
-
return await this.getEnvironment(name);
|
|
2503
|
-
} catch {
|
|
2504
|
-
return void 0;
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
};
|
|
2508
|
-
function getBaseFileHeader(context) {
|
|
2509
|
-
return `
|
|
2510
|
-
// Generated with ${titleCase(context.config.framework)}
|
|
2511
|
-
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
2512
|
-
`;
|
|
2513
|
-
}
|
|
2514
|
-
__name(getBaseFileHeader, "getBaseFileHeader");
|
|
2515
|
-
function getFileHeader(context, options = {}) {
|
|
2516
|
-
const { directive = null, prettierIgnore = false } = options;
|
|
2517
|
-
return `/* eslint-disable */
|
|
2518
|
-
// biome-ignore lint: disable
|
|
2519
|
-
${prettierIgnore ? `// prettier-ignore` : ""}${directive ? `
|
|
2520
|
-
|
|
2521
|
-
${directive}
|
|
2522
|
-
` : "\n"}
|
|
2523
|
-
${getBaseFileHeader(context)}
|
|
2524
|
-
|
|
2525
|
-
`;
|
|
2526
|
-
}
|
|
2527
|
-
__name(getFileHeader, "getFileHeader");
|
|
2528
|
-
function getString(code) {
|
|
2529
|
-
if (!code) {
|
|
2530
|
-
return "";
|
|
2531
|
-
}
|
|
2532
|
-
if (isString(code)) {
|
|
2533
|
-
return code;
|
|
2534
|
-
}
|
|
2535
|
-
if (isSetObject(code) && "code" in code) {
|
|
2536
|
-
return code.code;
|
|
2537
|
-
}
|
|
2538
|
-
return code.toString();
|
|
2539
|
-
}
|
|
2540
|
-
__name(getString, "getString");
|
|
2541
|
-
function getMagicString(code) {
|
|
2542
|
-
if (isString(code)) {
|
|
2543
|
-
return new MagicString(code);
|
|
2544
|
-
}
|
|
2545
|
-
return code;
|
|
2546
|
-
}
|
|
2547
|
-
__name(getMagicString, "getMagicString");
|
|
2548
|
-
function getSourceFile(code, id) {
|
|
2549
|
-
const content = code ?? readFileIfExistingSync(id);
|
|
2550
|
-
return {
|
|
2551
|
-
id,
|
|
2552
|
-
code: getMagicString(content),
|
|
2553
|
-
env: []
|
|
2554
|
-
};
|
|
2555
|
-
}
|
|
2556
|
-
__name(getSourceFile, "getSourceFile");
|
|
2557
|
-
function resolveModulePath(nodePath, state) {
|
|
2558
|
-
if (!t.isStringLiteral(nodePath.node)) {
|
|
2559
|
-
return;
|
|
2560
|
-
}
|
|
2561
|
-
const sourcePath = nodePath.node.value;
|
|
2562
|
-
const resolvedPath = state.context?.fs.resolve(sourcePath);
|
|
2563
|
-
if (resolvedPath) {
|
|
2564
|
-
nodePath.replaceWith(t.stringLiteral(
|
|
2565
|
-
// Remove the file extension if it exists
|
|
2566
|
-
resolvedPath.replace(/\.(?:ts|mts|cts)x?$/, "")
|
|
2567
|
-
));
|
|
2568
|
-
}
|
|
2569
|
-
}
|
|
2570
|
-
__name(resolveModulePath, "resolveModulePath");
|
|
2571
|
-
var TRANSFORM_FUNCTIONS = [
|
|
2572
|
-
"require",
|
|
2573
|
-
"require.resolve",
|
|
2574
|
-
"System.import",
|
|
2575
|
-
// Jest methods
|
|
2576
|
-
"jest.genMockFromModule",
|
|
2577
|
-
"jest.mock",
|
|
2578
|
-
"jest.unmock",
|
|
2579
|
-
"jest.doMock",
|
|
2580
|
-
// eslint-disable-next-line @cspell/spellchecker
|
|
2581
|
-
"jest.dontMock",
|
|
2582
|
-
"jest.setMock",
|
|
2583
|
-
"jest.requireActual",
|
|
2584
|
-
"jest.requireMock",
|
|
2585
|
-
// Older Jest methods
|
|
2586
|
-
"require.requireActual",
|
|
2587
|
-
"require.requireMock"
|
|
2588
|
-
];
|
|
2589
|
-
function matchesPattern(state, calleePath, pattern) {
|
|
2590
|
-
const { node } = calleePath;
|
|
2591
|
-
if (t.isMemberExpression(node)) {
|
|
2592
|
-
return calleePath.matchesPattern(pattern);
|
|
2593
|
-
}
|
|
2594
|
-
if (!t.isIdentifier(node) || pattern.includes(".")) {
|
|
2595
|
-
return false;
|
|
2596
|
-
}
|
|
2597
|
-
const name = pattern.split(".")[0];
|
|
2598
|
-
return node.name === name;
|
|
2599
|
-
}
|
|
2600
|
-
__name(matchesPattern, "matchesPattern");
|
|
2601
|
-
var importVisitors = {
|
|
2602
|
-
CallExpression: /* @__PURE__ */ __name((nodePath, state) => {
|
|
2603
|
-
if (state.moduleResolverVisited.has(nodePath)) {
|
|
2604
|
-
return;
|
|
2605
|
-
}
|
|
2606
|
-
const calleePath = nodePath.get("callee");
|
|
2607
|
-
if (calleePath && TRANSFORM_FUNCTIONS.some((pattern) => matchesPattern(state, calleePath, pattern)) || t.isImport(nodePath.node.callee)) {
|
|
2608
|
-
state.moduleResolverVisited.add(nodePath);
|
|
2609
|
-
resolveModulePath(nodePath.get("arguments.0"), state);
|
|
2482
|
+
await context.addPlugin(plugin);
|
|
2610
2483
|
}
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2484
|
+
return context;
|
|
2485
|
+
}
|
|
2486
|
+
async addPlugin(plugin) {
|
|
2487
|
+
this.plugins.push(plugin);
|
|
2488
|
+
await Promise.all(Object.keys(this.environments).map(async (name) => {
|
|
2489
|
+
await this.environments[name].addPlugin(plugin);
|
|
2490
|
+
}));
|
|
2491
|
+
}
|
|
2492
|
+
async getEnvironment(name) {
|
|
2493
|
+
let environment;
|
|
2494
|
+
if (name) {
|
|
2495
|
+
environment = this.environments[name];
|
|
2616
2496
|
}
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
}
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
return {
|
|
2625
|
-
name: "powerlines:module-resolver",
|
|
2626
|
-
manipulateOptions(opts) {
|
|
2627
|
-
opts.filename ??= "unknown";
|
|
2628
|
-
},
|
|
2629
|
-
pre() {
|
|
2630
|
-
moduleResolverVisited = /* @__PURE__ */ new Set();
|
|
2631
|
-
},
|
|
2632
|
-
visitor: {
|
|
2633
|
-
Program: {
|
|
2634
|
-
enter(programPath, state) {
|
|
2635
|
-
programPath.traverse(importVisitors, {
|
|
2636
|
-
...state,
|
|
2637
|
-
context,
|
|
2638
|
-
moduleResolverVisited,
|
|
2639
|
-
api
|
|
2640
|
-
});
|
|
2641
|
-
},
|
|
2642
|
-
exit(programPath, state) {
|
|
2643
|
-
programPath.traverse(importVisitors, {
|
|
2644
|
-
...state,
|
|
2645
|
-
context,
|
|
2646
|
-
moduleResolverVisited,
|
|
2647
|
-
api
|
|
2648
|
-
});
|
|
2649
|
-
}
|
|
2650
|
-
}
|
|
2651
|
-
},
|
|
2652
|
-
post() {
|
|
2653
|
-
moduleResolverVisited.clear();
|
|
2497
|
+
if (Object.keys(this.environments).length === 1) {
|
|
2498
|
+
environment = this.environments[Object.keys(this.environments)[0]];
|
|
2499
|
+
this.log(LogLevelLabel.DEBUG, `Applying the only configured environment: ${chalk5.bold.cyanBright(environment?.environment.name)}`);
|
|
2500
|
+
}
|
|
2501
|
+
if (!environment) {
|
|
2502
|
+
if (name) {
|
|
2503
|
+
throw new Error(`Environment "${name}" not found.`);
|
|
2654
2504
|
}
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
}, "moduleResolverBabelPlugin");
|
|
2658
|
-
|
|
2659
|
-
// ../powerlines/src/internal/helpers/generate-types.ts
|
|
2660
|
-
async function generateTypes(context) {
|
|
2661
|
-
context.log(LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
|
|
2662
|
-
context.log(LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
|
|
2663
|
-
const builtinFiles = await context.getBuiltins();
|
|
2664
|
-
const builtinFilePaths = await Promise.all(builtinFiles.map(async (file) => {
|
|
2665
|
-
const result = await transformAsync(file.code.toString(), {
|
|
2666
|
-
highlightCode: true,
|
|
2667
|
-
code: true,
|
|
2668
|
-
ast: false,
|
|
2669
|
-
cloneInputAst: false,
|
|
2670
|
-
comments: true,
|
|
2671
|
-
sourceType: "module",
|
|
2672
|
-
configFile: false,
|
|
2673
|
-
babelrc: false,
|
|
2674
|
-
envName: context.config.mode,
|
|
2675
|
-
caller: {
|
|
2676
|
-
name: "powerlines"
|
|
2677
|
-
},
|
|
2678
|
-
...context.config.transform.babel,
|
|
2679
|
-
filename: file.path,
|
|
2680
|
-
plugins: [
|
|
2681
|
-
[
|
|
2682
|
-
"@babel/plugin-syntax-typescript"
|
|
2683
|
-
],
|
|
2684
|
-
[
|
|
2685
|
-
moduleResolverBabelPlugin(context)
|
|
2686
|
-
]
|
|
2687
|
-
]
|
|
2688
|
-
});
|
|
2689
|
-
if (!result?.code) {
|
|
2690
|
-
throw new Error(`Powerlines - Generate Types failed to compile ${file.id}`);
|
|
2505
|
+
environment = await this.in(createDefaultEnvironment(this.config.userConfig));
|
|
2506
|
+
this.log(LogLevelLabel.WARN, `No environment specified, and no default environment found. Using a temporary default environment: ${chalk5.bold.cyanBright(environment?.environment.name)}`);
|
|
2691
2507
|
}
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
compilerOptions: {
|
|
2712
|
-
strict: false,
|
|
2713
|
-
noEmit: false,
|
|
2714
|
-
declaration: true,
|
|
2715
|
-
declarationMap: false,
|
|
2716
|
-
emitDeclarationOnly: true,
|
|
2717
|
-
skipLibCheck: true
|
|
2718
|
-
},
|
|
2719
|
-
exclude: [
|
|
2720
|
-
"node_modules",
|
|
2721
|
-
"dist"
|
|
2722
|
-
],
|
|
2723
|
-
include: files
|
|
2724
|
-
}, context.config.tsconfigRaw ?? {}));
|
|
2725
|
-
resolvedTsconfig.options.configFilePath = joinPaths(context.workspaceConfig.workspaceRoot, context.tsconfig.tsconfigFilePath);
|
|
2726
|
-
resolvedTsconfig.options.pathsBasePath = context.workspaceConfig.workspaceRoot;
|
|
2727
|
-
resolvedTsconfig.options.suppressOutputPathCheck = true;
|
|
2508
|
+
return environment;
|
|
2509
|
+
}
|
|
2510
|
+
async getEnvironmentSafe(name) {
|
|
2511
|
+
try {
|
|
2512
|
+
return await this.getEnvironment(name);
|
|
2513
|
+
} catch {
|
|
2514
|
+
return void 0;
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
};
|
|
2518
|
+
function formatTypes(code) {
|
|
2519
|
+
return code.replace(
|
|
2520
|
+
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
|
2521
|
+
/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g,
|
|
2522
|
+
""
|
|
2523
|
+
).replaceAll("#private;", "").replace(/__Ω/g, "");
|
|
2524
|
+
}
|
|
2525
|
+
__name(formatTypes, "formatTypes");
|
|
2526
|
+
async function emitTypes(context, tsconfig, files) {
|
|
2728
2527
|
context.log(LogLevelLabel.TRACE, "Creating the TypeScript compiler host");
|
|
2729
|
-
const program = createProgram(files,
|
|
2730
|
-
context.log(LogLevelLabel.TRACE, `Running TypeScript compiler
|
|
2528
|
+
const program = createProgram(files, tsconfig.options, createCompilerHost(tsconfig.options));
|
|
2529
|
+
context.log(LogLevelLabel.TRACE, `Running the TypeScript compiler for ${context.builtins.length} built-in runtime files.`);
|
|
2731
2530
|
let builtinModules = "";
|
|
2732
2531
|
const emitResult = program.emit(void 0, (fileName, text, _, __, sourceFiles, _data) => {
|
|
2733
|
-
const
|
|
2734
|
-
if (
|
|
2735
|
-
if (
|
|
2532
|
+
const sourceFile = sourceFiles?.[0];
|
|
2533
|
+
if (sourceFile?.fileName && !fileName.endsWith(".map")) {
|
|
2534
|
+
if (context.builtins.some((file) => file === sourceFile.fileName || context.fs.meta[file]?.id && context.fs.meta[file]?.id === sourceFile.fileName)) {
|
|
2736
2535
|
builtinModules += `
|
|
2737
|
-
declare module "${context.fs.resolve(
|
|
2536
|
+
declare module "${context.fs.resolve(sourceFile.fileName)}" {
|
|
2738
2537
|
${text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
|
|
2739
2538
|
}
|
|
2740
2539
|
`;
|
|
@@ -2759,25 +2558,9 @@ declare module "${context.fs.resolve(sourceFile2.fileName)}" {
|
|
|
2759
2558
|
|
|
2760
2559
|
${diagnosticMessage.length > 5e3 ? `${diagnosticMessage.slice(0, 5e3)}...` : diagnosticMessage}`);
|
|
2761
2560
|
}
|
|
2762
|
-
|
|
2763
|
-
const sourceFile = getSourceFile(String(context.config.output.dts), `/// <reference types="powerlines/shared" />${context.config.build.platform !== "neutral" ? `
|
|
2764
|
-
/// <reference types="powerlines/${context.config.build.platform}" />` : ""}
|
|
2765
|
-
|
|
2766
|
-
${getFileHeader(context, {
|
|
2767
|
-
directive: null,
|
|
2768
|
-
prettierIgnore: false
|
|
2769
|
-
})}
|
|
2770
|
-
|
|
2771
|
-
${builtinModules}`.replace(
|
|
2772
|
-
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
|
2773
|
-
/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g,
|
|
2774
|
-
""
|
|
2775
|
-
).replaceAll("#private;", "").replace(/__Ω/g, ""));
|
|
2776
|
-
await context.fs.writeFile(sourceFile.id, getString(sourceFile.code), {
|
|
2777
|
-
mode: "fs"
|
|
2778
|
-
});
|
|
2561
|
+
return formatTypes(builtinModules);
|
|
2779
2562
|
}
|
|
2780
|
-
__name(
|
|
2563
|
+
__name(emitTypes, "emitTypes");
|
|
2781
2564
|
async function installPackage(context, packageName, dev = false) {
|
|
2782
2565
|
if (!await isPackageListed(getPackageName(packageName), {
|
|
2783
2566
|
cwd: context.config.projectRoot
|
|
@@ -2813,7 +2596,12 @@ __name(installPackage, "installPackage");
|
|
|
2813
2596
|
async function installDependencies(context) {
|
|
2814
2597
|
context.log(LogLevelLabel.TRACE, `Checking and installing missing project dependencies.`);
|
|
2815
2598
|
context.dependencies ??= {};
|
|
2816
|
-
context.
|
|
2599
|
+
context.devDependencies ??= {};
|
|
2600
|
+
if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
|
|
2601
|
+
context.log(LogLevelLabel.TRACE, `No dependencies or devDependencies to install. Skipping installation step.`);
|
|
2602
|
+
return;
|
|
2603
|
+
}
|
|
2604
|
+
context.log(LogLevelLabel.DEBUG, `The following packages are required:
|
|
2817
2605
|
Dependencies:
|
|
2818
2606
|
${Object.entries(context.dependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}
|
|
2819
2607
|
|
|
@@ -2825,6 +2613,108 @@ ${Object.entries(context.devDependencies).map(([name, version]) => `- ${name}@${
|
|
|
2825
2613
|
]);
|
|
2826
2614
|
}
|
|
2827
2615
|
__name(installDependencies, "installDependencies");
|
|
2616
|
+
function getTsconfigFilePath(workspaceRoot, projectRoot, tsconfig = "tsconfig.json") {
|
|
2617
|
+
let tsconfigFilePath = tsconfig;
|
|
2618
|
+
if (!existsSync(tsconfigFilePath)) {
|
|
2619
|
+
tsconfigFilePath = appendPath(tsconfig, projectRoot);
|
|
2620
|
+
if (!existsSync(tsconfigFilePath)) {
|
|
2621
|
+
tsconfigFilePath = appendPath(tsconfig, workspaceRoot);
|
|
2622
|
+
if (!existsSync(tsconfigFilePath)) {
|
|
2623
|
+
tsconfigFilePath = appendPath(tsconfig, joinPaths(workspaceRoot, projectRoot));
|
|
2624
|
+
if (!existsSync(tsconfigFilePath)) {
|
|
2625
|
+
throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${tsconfig}, ${appendPath(tsconfig, projectRoot)}, ${appendPath(tsconfig, workspaceRoot)}, or ${tsconfigFilePath}`);
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
return tsconfigFilePath;
|
|
2631
|
+
}
|
|
2632
|
+
__name(getTsconfigFilePath, "getTsconfigFilePath");
|
|
2633
|
+
function findMatch(tsconfigType, types, extensions = [
|
|
2634
|
+
".ts",
|
|
2635
|
+
".tsx",
|
|
2636
|
+
".d.ts"
|
|
2637
|
+
]) {
|
|
2638
|
+
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}`));
|
|
2639
|
+
}
|
|
2640
|
+
__name(findMatch, "findMatch");
|
|
2641
|
+
function findIncludeMatch(tsconfigType, types) {
|
|
2642
|
+
return findMatch(tsconfigType, types, [
|
|
2643
|
+
".ts",
|
|
2644
|
+
".tsx",
|
|
2645
|
+
".d.ts",
|
|
2646
|
+
".js",
|
|
2647
|
+
".jsx",
|
|
2648
|
+
".mjs",
|
|
2649
|
+
".cjs",
|
|
2650
|
+
".mts",
|
|
2651
|
+
".cts",
|
|
2652
|
+
"/*.ts",
|
|
2653
|
+
"/*.tsx",
|
|
2654
|
+
"/*.d.ts",
|
|
2655
|
+
"/*.js",
|
|
2656
|
+
"/*.jsx",
|
|
2657
|
+
"/*.mjs",
|
|
2658
|
+
"/*.cjs",
|
|
2659
|
+
"/*.mts",
|
|
2660
|
+
"/*.cts",
|
|
2661
|
+
"/**/*.ts",
|
|
2662
|
+
"/**/*.tsx",
|
|
2663
|
+
"/**/*.d.ts",
|
|
2664
|
+
"/**/*.js",
|
|
2665
|
+
"/**/*.jsx",
|
|
2666
|
+
"/**/*.mjs",
|
|
2667
|
+
"/**/*.cjs",
|
|
2668
|
+
"/**/*.mts",
|
|
2669
|
+
"/**/*.cts"
|
|
2670
|
+
]);
|
|
2671
|
+
}
|
|
2672
|
+
__name(findIncludeMatch, "findIncludeMatch");
|
|
2673
|
+
function isIncludeMatchFound(tsconfigType, types) {
|
|
2674
|
+
return findIncludeMatch(tsconfigType, types) !== void 0;
|
|
2675
|
+
}
|
|
2676
|
+
__name(isIncludeMatchFound, "isIncludeMatchFound");
|
|
2677
|
+
function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfigRaw = {}, originalTsconfigJson, host = ts2.sys) {
|
|
2678
|
+
const tsconfigFilePath = getTsconfigFilePath(workspaceRoot, projectRoot, tsconfig);
|
|
2679
|
+
const tsconfigJson = readJsonFileSync(tsconfigFilePath);
|
|
2680
|
+
if (!tsconfigJson) {
|
|
2681
|
+
throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${joinPaths(projectRoot, tsconfig ?? "tsconfig.json")}`);
|
|
2682
|
+
}
|
|
2683
|
+
const parsedCommandLine = ts2.parseJsonConfigFileContent(defu3(tsconfigRaw ?? {}, tsconfigJson), host, appendPath(projectRoot, workspaceRoot));
|
|
2684
|
+
if (parsedCommandLine.errors.length > 0) {
|
|
2685
|
+
const errorMessage = `Cannot parse the TypeScript compiler options. Please investigate the following issues:
|
|
2686
|
+
${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && error.code ? `[${error.category}-${error.code}]: ` : "") + error.messageText.toString()}`).join("\n")}
|
|
2687
|
+
`;
|
|
2688
|
+
throw new Error(errorMessage);
|
|
2689
|
+
}
|
|
2690
|
+
return {
|
|
2691
|
+
...parsedCommandLine,
|
|
2692
|
+
originalTsconfigJson: originalTsconfigJson ?? tsconfigJson,
|
|
2693
|
+
tsconfigJson,
|
|
2694
|
+
tsconfigFilePath
|
|
2695
|
+
};
|
|
2696
|
+
}
|
|
2697
|
+
__name(getParsedTypeScriptConfig, "getParsedTypeScriptConfig");
|
|
2698
|
+
async function writeFile(log, filepath, content, skipFormat = false) {
|
|
2699
|
+
try {
|
|
2700
|
+
if (skipFormat) {
|
|
2701
|
+
await writeFile$1(filepath, content);
|
|
2702
|
+
} else {
|
|
2703
|
+
const config = await resolveConfig(filepath);
|
|
2704
|
+
const formatted = await format(content, {
|
|
2705
|
+
...config ?? {},
|
|
2706
|
+
filepath
|
|
2707
|
+
});
|
|
2708
|
+
await writeFile$1(filepath, formatted || "");
|
|
2709
|
+
}
|
|
2710
|
+
} catch (error) {
|
|
2711
|
+
log(LogLevelLabel.ERROR, `Failed to write file ${filepath} to disk
|
|
2712
|
+
${error?.message ? error.message : ""}`);
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
__name(writeFile, "writeFile");
|
|
2716
|
+
|
|
2717
|
+
// ../powerlines/src/internal/helpers/resolve-tsconfig.ts
|
|
2828
2718
|
async function resolveTsconfigChanges(context) {
|
|
2829
2719
|
const tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw);
|
|
2830
2720
|
const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
@@ -2999,8 +2889,28 @@ async function resolveTsconfig(context) {
|
|
|
2999
2889
|
context.tsconfig.tsconfigJson.compilerOptions.strict = false;
|
|
3000
2890
|
}
|
|
3001
2891
|
__name(resolveTsconfig, "resolveTsconfig");
|
|
2892
|
+
function getBaseFileHeader(context) {
|
|
2893
|
+
return `
|
|
2894
|
+
// Generated with ${titleCase(context.config.framework)}
|
|
2895
|
+
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
2896
|
+
`;
|
|
2897
|
+
}
|
|
2898
|
+
__name(getBaseFileHeader, "getBaseFileHeader");
|
|
2899
|
+
function getFileHeader(context, options = {}) {
|
|
2900
|
+
const { directive = null, prettierIgnore = false } = options;
|
|
2901
|
+
return `/* eslint-disable */
|
|
2902
|
+
// biome-ignore lint: disable
|
|
2903
|
+
${prettierIgnore ? `// prettier-ignore` : ""}${directive ? `
|
|
2904
|
+
|
|
2905
|
+
${directive}
|
|
2906
|
+
` : "\n"}
|
|
2907
|
+
${getBaseFileHeader(context)}
|
|
3002
2908
|
|
|
3003
|
-
|
|
2909
|
+
`;
|
|
2910
|
+
}
|
|
2911
|
+
__name(getFileHeader, "getFileHeader");
|
|
2912
|
+
|
|
2913
|
+
// ../powerlines/src/api.ts
|
|
3004
2914
|
var PowerlinesAPI = class _PowerlinesAPI {
|
|
3005
2915
|
static {
|
|
3006
2916
|
__name(this, "PowerlinesAPI");
|
|
@@ -3075,13 +2985,122 @@ ${formatLogMessage(context.config)}`);
|
|
|
3075
2985
|
await createDirectory(context.dataPath);
|
|
3076
2986
|
}
|
|
3077
2987
|
await this.callPreHook(context, "prepare");
|
|
3078
|
-
|
|
3079
|
-
context.log(LogLevelLabel.TRACE, "Generating built-in barrel file");
|
|
3080
|
-
}
|
|
2988
|
+
await this.callNormalHook(context, "prepare");
|
|
3081
2989
|
if (context.config.output.dts !== false) {
|
|
3082
|
-
|
|
2990
|
+
context.log(LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
|
|
2991
|
+
context.log(LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
|
|
2992
|
+
const builtinFilePaths = await Promise.all((await context.getBuiltins()).map(async (file) => {
|
|
2993
|
+
const result2 = await transformAsync(file.code.toString(), {
|
|
2994
|
+
highlightCode: true,
|
|
2995
|
+
code: true,
|
|
2996
|
+
ast: false,
|
|
2997
|
+
cloneInputAst: false,
|
|
2998
|
+
comments: true,
|
|
2999
|
+
sourceType: "module",
|
|
3000
|
+
configFile: false,
|
|
3001
|
+
babelrc: false,
|
|
3002
|
+
envName: context.config.mode,
|
|
3003
|
+
caller: {
|
|
3004
|
+
name: "powerlines"
|
|
3005
|
+
},
|
|
3006
|
+
...context.config.transform.babel,
|
|
3007
|
+
filename: file.path,
|
|
3008
|
+
plugins: [
|
|
3009
|
+
[
|
|
3010
|
+
"@babel/plugin-syntax-typescript"
|
|
3011
|
+
],
|
|
3012
|
+
[
|
|
3013
|
+
moduleResolverBabelPlugin(context)
|
|
3014
|
+
]
|
|
3015
|
+
]
|
|
3016
|
+
});
|
|
3017
|
+
if (!result2?.code) {
|
|
3018
|
+
throw new Error(`Powerlines - Generate Types failed to compile ${file.id}`);
|
|
3019
|
+
}
|
|
3020
|
+
context.log(LogLevelLabel.TRACE, `Writing transformed built-in runtime file ${file.id}.`);
|
|
3021
|
+
await context.writeBuiltin(result2.code, file.id, file.path);
|
|
3022
|
+
return file.path;
|
|
3023
|
+
}));
|
|
3024
|
+
const typescriptPath = await resolvePackage("typescript");
|
|
3025
|
+
if (!typescriptPath) {
|
|
3026
|
+
throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
|
|
3027
|
+
}
|
|
3028
|
+
const files = builtinFilePaths.reduce((ret, fileName) => {
|
|
3029
|
+
const formatted = replacePath(fileName, context.workspaceConfig.workspaceRoot);
|
|
3030
|
+
if (!ret.includes(formatted)) {
|
|
3031
|
+
ret.push(formatted);
|
|
3032
|
+
}
|
|
3033
|
+
return ret;
|
|
3034
|
+
}, [
|
|
3035
|
+
joinPaths(typescriptPath, "lib", "lib.esnext.full.d.ts")
|
|
3036
|
+
]);
|
|
3037
|
+
context.log(LogLevelLabel.TRACE, "Parsing TypeScript configuration for the Powerlines project.");
|
|
3038
|
+
const resolvedTsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.tsconfig.tsconfigFilePath, defu3({
|
|
3039
|
+
compilerOptions: {
|
|
3040
|
+
strict: false,
|
|
3041
|
+
noEmit: false,
|
|
3042
|
+
declaration: true,
|
|
3043
|
+
declarationMap: false,
|
|
3044
|
+
emitDeclarationOnly: true,
|
|
3045
|
+
skipLibCheck: true
|
|
3046
|
+
},
|
|
3047
|
+
exclude: [
|
|
3048
|
+
"node_modules",
|
|
3049
|
+
"dist"
|
|
3050
|
+
],
|
|
3051
|
+
include: files
|
|
3052
|
+
}, context.config.tsconfigRaw ?? {}));
|
|
3053
|
+
resolvedTsconfig.options.configFilePath = joinPaths(context.workspaceConfig.workspaceRoot, context.tsconfig.tsconfigFilePath);
|
|
3054
|
+
resolvedTsconfig.options.pathsBasePath = context.workspaceConfig.workspaceRoot;
|
|
3055
|
+
resolvedTsconfig.options.suppressOutputPathCheck = true;
|
|
3056
|
+
let generatedTypes = await emitTypes(context, resolvedTsconfig, files);
|
|
3057
|
+
context.log(LogLevelLabel.TRACE, `Generating TypeScript declaration file in ${context.config.output.dts}.`);
|
|
3058
|
+
const directives = [];
|
|
3059
|
+
let result = await this.callPreHook(context, "generateTypes", generatedTypes);
|
|
3060
|
+
if (result) {
|
|
3061
|
+
if (isSetObject(result)) {
|
|
3062
|
+
generatedTypes = result.code;
|
|
3063
|
+
if (Array.isArray(result.directives) && result.directives.length > 0) {
|
|
3064
|
+
directives.push(...result.directives);
|
|
3065
|
+
}
|
|
3066
|
+
} else if (isSetString(result)) {
|
|
3067
|
+
generatedTypes = result;
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
result = await this.callNormalHook(context, "generateTypes", generatedTypes);
|
|
3071
|
+
if (result) {
|
|
3072
|
+
if (isSetObject(result)) {
|
|
3073
|
+
generatedTypes = result.code;
|
|
3074
|
+
if (Array.isArray(result.directives) && result.directives.length > 0) {
|
|
3075
|
+
directives.push(...result.directives);
|
|
3076
|
+
}
|
|
3077
|
+
} else if (isSetString(result)) {
|
|
3078
|
+
generatedTypes = result;
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
result = await this.callPostHook(context, "generateTypes", generatedTypes);
|
|
3082
|
+
if (result) {
|
|
3083
|
+
if (isSetObject(result)) {
|
|
3084
|
+
generatedTypes = result.code;
|
|
3085
|
+
if (Array.isArray(result.directives) && result.directives.length > 0) {
|
|
3086
|
+
directives.push(...result.directives);
|
|
3087
|
+
}
|
|
3088
|
+
} else if (isSetString(result)) {
|
|
3089
|
+
generatedTypes = result;
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
await context.fs.writeFile(context.config.output.dts, `${directives ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
|
|
3093
|
+
|
|
3094
|
+
` : ""}${getFileHeader(context, {
|
|
3095
|
+
directive: null,
|
|
3096
|
+
prettierIgnore: false
|
|
3097
|
+
})}
|
|
3098
|
+
|
|
3099
|
+
${formatTypes(generatedTypes)}
|
|
3100
|
+
`, {
|
|
3101
|
+
mode: "fs"
|
|
3102
|
+
});
|
|
3083
3103
|
}
|
|
3084
|
-
await this.callNormalHook(context, "prepare");
|
|
3085
3104
|
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
3086
3105
|
if (!context.tsconfig) {
|
|
3087
3106
|
throw new Error("Failed to parse the TypeScript configuration file.");
|
|
@@ -3519,7 +3538,7 @@ var DEFAULT_ESBUILD_CONFIG = {
|
|
|
3519
3538
|
logLevel: "silent"
|
|
3520
3539
|
};
|
|
3521
3540
|
function extractESBuildConfig(context) {
|
|
3522
|
-
return
|
|
3541
|
+
return defu3({
|
|
3523
3542
|
alias: context.builtins.reduce((ret, id) => {
|
|
3524
3543
|
const path = context.fs.ids[id];
|
|
3525
3544
|
if (path) {
|
|
@@ -3562,7 +3581,7 @@ var DEFAULT_VITE_CONFIG = {
|
|
|
3562
3581
|
clearScreen: true
|
|
3563
3582
|
};
|
|
3564
3583
|
function extractViteConfig(context) {
|
|
3565
|
-
return
|
|
3584
|
+
return defu3({
|
|
3566
3585
|
resolve: {
|
|
3567
3586
|
alias: context.builtins.reduce((ret, id) => {
|
|
3568
3587
|
const path = context.fs.ids[id];
|
|
@@ -3599,6 +3618,19 @@ function extractViteConfig(context) {
|
|
|
3599
3618
|
}, DEFAULT_VITE_CONFIG);
|
|
3600
3619
|
}
|
|
3601
3620
|
__name(extractViteConfig, "extractViteConfig");
|
|
3621
|
+
function getString(code) {
|
|
3622
|
+
if (!code) {
|
|
3623
|
+
return "";
|
|
3624
|
+
}
|
|
3625
|
+
if (isString(code)) {
|
|
3626
|
+
return code;
|
|
3627
|
+
}
|
|
3628
|
+
if (isSetObject(code) && "code" in code) {
|
|
3629
|
+
return code.code;
|
|
3630
|
+
}
|
|
3631
|
+
return code.toString();
|
|
3632
|
+
}
|
|
3633
|
+
__name(getString, "getString");
|
|
3602
3634
|
var NON_NODE_MODULE_REGEX = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
|
|
3603
3635
|
async function handleResolveId(context, args, options = {}) {
|
|
3604
3636
|
if (args.id) {
|
|
@@ -3803,7 +3835,7 @@ var vite = createVitePlugin(createUnpluginFactory("vite", (api, plugin) => {
|
|
|
3803
3835
|
api.context.config.mode = isDevelopmentMode(env.mode) ? "development" : isTestMode(env.mode) ? "test" : "production";
|
|
3804
3836
|
const environment = await api.context.getEnvironment();
|
|
3805
3837
|
const result = await api.callHook(environment, "config");
|
|
3806
|
-
return
|
|
3838
|
+
return defu3(extractViteConfig(api.context), result?.build ?? {}, config);
|
|
3807
3839
|
},
|
|
3808
3840
|
async configResolved(_config) {
|
|
3809
3841
|
const environment = await api.context.getEnvironment();
|
|
@@ -3880,7 +3912,7 @@ function withExecutor(command, executorFn) {
|
|
|
3880
3912
|
throw new Error("The executor requires `projectsConfigurations` on the context object.");
|
|
3881
3913
|
}
|
|
3882
3914
|
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
3883
|
-
const api = await src_default.from(workspaceConfig.workspaceRoot,
|
|
3915
|
+
const api = await src_default.from(workspaceConfig.workspaceRoot, defu3({
|
|
3884
3916
|
root: projectConfig.root,
|
|
3885
3917
|
type: projectConfig.projectType,
|
|
3886
3918
|
sourceRoot: projectConfig.sourceRoot,
|
|
@@ -3893,7 +3925,7 @@ function withExecutor(command, executorFn) {
|
|
|
3893
3925
|
}
|
|
3894
3926
|
}, options));
|
|
3895
3927
|
try {
|
|
3896
|
-
return await Promise.resolve(executorFn(
|
|
3928
|
+
return await Promise.resolve(executorFn(defu3({
|
|
3897
3929
|
projectName: context.projectName,
|
|
3898
3930
|
options,
|
|
3899
3931
|
workspaceConfig,
|