powerlines 0.42.30 → 0.42.32

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.
Files changed (141) hide show
  1. package/dist/api-D6i8MmbC.mjs +6063 -0
  2. package/dist/api-D6i8MmbC.mjs.map +1 -0
  3. package/dist/api-DZoRNTY7.cjs +6083 -0
  4. package/dist/{api-context-AY_byIdN.mjs → api-context-BQi9M07D.mjs} +414 -6
  5. package/dist/api-context-BQi9M07D.mjs.map +1 -0
  6. package/dist/{api-context-BTrJUKNX.cjs → api-context-k3dnn5KR.cjs} +425 -9
  7. package/dist/astro.cjs +4 -5
  8. package/dist/astro.d.cts +2 -2
  9. package/dist/astro.d.cts.map +1 -1
  10. package/dist/astro.d.mts +2 -2
  11. package/dist/astro.d.mts.map +1 -1
  12. package/dist/astro.mjs +3 -3
  13. package/dist/astro.mjs.map +1 -1
  14. package/dist/base-Bl_AMAlI.d.cts +12 -0
  15. package/dist/base-Bl_AMAlI.d.cts.map +1 -0
  16. package/dist/base-hjCHfNY6.d.mts +12 -0
  17. package/dist/base-hjCHfNY6.d.mts.map +1 -0
  18. package/dist/{chunk-AIJqnxB6.cjs → chunk-7azAqIA9.cjs} +7 -0
  19. package/dist/{chunk-CtajNgzt.mjs → chunk-WJdhOJK3.mjs} +10 -1
  20. package/dist/config.cjs +1 -1
  21. package/dist/config.mjs +1 -1
  22. package/dist/constants.cjs +1 -1
  23. package/dist/constants.mjs +1 -1
  24. package/dist/context/index.cjs +1 -1
  25. package/dist/context/index.d.cts +260 -1
  26. package/dist/context/index.d.cts.map +1 -1
  27. package/dist/context/index.d.mts +260 -1
  28. package/dist/context/index.d.mts.map +1 -1
  29. package/dist/context/index.mjs +1 -1
  30. package/dist/esbuild.cjs +3 -10
  31. package/dist/esbuild.d.cts +2 -2
  32. package/dist/esbuild.d.cts.map +1 -1
  33. package/dist/esbuild.d.mts +2 -2
  34. package/dist/esbuild.d.mts.map +1 -1
  35. package/dist/esbuild.mjs +2 -2
  36. package/dist/esbuild.mjs.map +1 -1
  37. package/dist/farm.cjs +5 -6
  38. package/dist/farm.d.cts +2 -2
  39. package/dist/farm.d.cts.map +1 -1
  40. package/dist/farm.d.mts +2 -2
  41. package/dist/farm.d.mts.map +1 -1
  42. package/dist/farm.mjs +2 -2
  43. package/dist/farm.mjs.map +1 -1
  44. package/dist/index.cjs +5 -7
  45. package/dist/index.d.cts +3 -3
  46. package/dist/index.d.mts +3 -3
  47. package/dist/index.mjs +3 -4
  48. package/dist/index.mjs.map +1 -1
  49. package/dist/next.cjs +5 -6
  50. package/dist/next.d.cts +2 -2
  51. package/dist/next.d.cts.map +1 -1
  52. package/dist/next.d.mts +2 -2
  53. package/dist/next.d.mts.map +1 -1
  54. package/dist/next.mjs +4 -4
  55. package/dist/next.mjs.map +1 -1
  56. package/dist/nuxt.cjs +8 -9
  57. package/dist/nuxt.d.cts +2 -2
  58. package/dist/nuxt.d.cts.map +1 -1
  59. package/dist/nuxt.d.mts +2 -2
  60. package/dist/nuxt.d.mts.map +1 -1
  61. package/dist/nuxt.mjs +7 -7
  62. package/dist/nuxt.mjs.map +1 -1
  63. package/dist/plugin-utils.cjs +1 -1
  64. package/dist/plugin-utils.mjs +1 -1
  65. package/dist/rolldown.cjs +4 -11
  66. package/dist/rolldown.d.cts +2 -2
  67. package/dist/rolldown.d.cts.map +1 -1
  68. package/dist/rolldown.d.mts +2 -2
  69. package/dist/rolldown.d.mts.map +1 -1
  70. package/dist/rolldown.mjs +2 -2
  71. package/dist/rolldown.mjs.map +1 -1
  72. package/dist/rollup.cjs +4 -11
  73. package/dist/rollup.d.cts +2 -2
  74. package/dist/rollup.d.cts.map +1 -1
  75. package/dist/rollup.d.mts +2 -2
  76. package/dist/rollup.d.mts.map +1 -1
  77. package/dist/rollup.mjs +2 -2
  78. package/dist/rollup.mjs.map +1 -1
  79. package/dist/rspack.cjs +4 -11
  80. package/dist/rspack.d.cts +2 -2
  81. package/dist/rspack.d.cts.map +1 -1
  82. package/dist/rspack.d.mts +2 -2
  83. package/dist/rspack.d.mts.map +1 -1
  84. package/dist/rspack.mjs +2 -2
  85. package/dist/rspack.mjs.map +1 -1
  86. package/dist/storage/index.cjs +1 -1
  87. package/dist/storage/index.d.cts +1 -1
  88. package/dist/storage/index.d.mts +1 -1
  89. package/dist/storage/index.mjs +1 -1
  90. package/dist/{tsconfig-B0kfe_iM.cjs → tsconfig-BhVGZ2DK.cjs} +2 -2
  91. package/dist/{tsconfig-B8RooiIp.mjs → tsconfig-CzYPBpDS.mjs} +2 -2
  92. package/dist/{tsconfig-B8RooiIp.mjs.map → tsconfig-CzYPBpDS.mjs.map} +1 -1
  93. package/dist/tsdown.cjs +5 -12
  94. package/dist/tsdown.d.cts +2 -2
  95. package/dist/tsdown.d.cts.map +1 -1
  96. package/dist/tsdown.d.mts +2 -2
  97. package/dist/tsdown.d.mts.map +1 -1
  98. package/dist/tsdown.mjs +3 -3
  99. package/dist/tsdown.mjs.map +1 -1
  100. package/dist/tsup.cjs +5 -12
  101. package/dist/tsup.d.cts +547 -3
  102. package/dist/tsup.d.cts.map +1 -1
  103. package/dist/tsup.d.mts +547 -3
  104. package/dist/tsup.d.mts.map +1 -1
  105. package/dist/tsup.mjs +3 -3
  106. package/dist/tsup.mjs.map +1 -1
  107. package/dist/typescript/index.cjs +2 -2
  108. package/dist/typescript/index.d.cts +6 -1
  109. package/dist/typescript/index.d.cts.map +1 -1
  110. package/dist/typescript/index.d.mts +6 -1
  111. package/dist/typescript/index.d.mts.map +1 -1
  112. package/dist/typescript/index.mjs +1 -1
  113. package/dist/unloader.cjs +5 -6
  114. package/dist/unloader.d.cts +2 -2
  115. package/dist/unloader.d.mts +2 -2
  116. package/dist/unloader.mjs +2 -2
  117. package/dist/unloader.mjs.map +1 -1
  118. package/dist/unplugin.cjs +2 -2
  119. package/dist/unplugin.mjs +1 -1
  120. package/dist/utils.cjs +1 -1
  121. package/dist/utils.mjs +1 -1
  122. package/dist/{virtual-CJChzKrr.cjs → virtual-BHb4iMd_.cjs} +3 -3
  123. package/dist/{virtual-DB9ki0Y6.mjs → virtual-OEHgBu0s.mjs} +3 -3
  124. package/dist/{virtual-DB9ki0Y6.mjs.map → virtual-OEHgBu0s.mjs.map} +1 -1
  125. package/dist/vite.cjs +4 -11
  126. package/dist/vite.d.cts +2 -2
  127. package/dist/vite.d.mts +2 -2
  128. package/dist/vite.mjs +2 -2
  129. package/dist/vite.mjs.map +1 -1
  130. package/dist/webpack.cjs +4 -11
  131. package/dist/webpack.d.cts +2 -2
  132. package/dist/webpack.d.cts.map +1 -1
  133. package/dist/webpack.d.mts +2 -2
  134. package/dist/webpack.d.mts.map +1 -1
  135. package/dist/webpack.mjs +2 -2
  136. package/dist/webpack.mjs.map +1 -1
  137. package/package.json +14 -14
  138. package/dist/api-BQswQ9mT.mjs +0 -861
  139. package/dist/api-BQswQ9mT.mjs.map +0 -1
  140. package/dist/api-D7HzHvkw.cjs +0 -881
  141. package/dist/api-context-AY_byIdN.mjs.map +0 -1
@@ -1,861 +0,0 @@
1
- import { t as utils_exports } from "./utils.mjs";
2
- import { t as plugin_utils_exports } from "./plugin-utils.mjs";
3
- import { d as writeMetaFile, f as callHook, p as mergeConfigs, t as PowerlinesAPIContext } from "./api-context-AY_byIdN.mjs";
4
- import { a as isIncludeMatchFound, i as getTsconfigFilePath, r as getParsedTypeScriptConfig } from "./tsconfig-B8RooiIp.mjs";
5
- import { formatLogMessage } from "@storm-software/config-tools/logger/console";
6
- import { toArray } from "@stryke/convert/to-array";
7
- import { copyFiles } from "@stryke/fs/copy-file";
8
- import { existsSync } from "@stryke/fs/exists";
9
- import { createDirectory, removeDirectory } from "@stryke/fs/helpers";
10
- import { install } from "@stryke/fs/install";
11
- import { listFiles } from "@stryke/fs/list-files";
12
- import { doesPackageMatch, getPackageListing, isPackageExists, isPackageListed } from "@stryke/fs/package-fns";
13
- import { resolvePackage } from "@stryke/fs/resolve";
14
- import { getUnique } from "@stryke/helpers/get-unique";
15
- import { omit } from "@stryke/helpers/omit";
16
- import { appendPath } from "@stryke/path/append";
17
- import { findFileName, findFilePath, relativePath } from "@stryke/path/file-path-fns";
18
- import { isParentPath } from "@stryke/path/is-parent-path";
19
- import { joinPaths } from "@stryke/path/join-paths";
20
- import { replacePath } from "@stryke/path/replace";
21
- import { titleCase } from "@stryke/string-format/title-case";
22
- import { isError } from "@stryke/type-checks/is-error";
23
- import { isFunction } from "@stryke/type-checks/is-function";
24
- import { isNumber } from "@stryke/type-checks/is-number";
25
- import { isObject } from "@stryke/type-checks/is-object";
26
- import { isPromiseLike } from "@stryke/type-checks/is-promise";
27
- import { isSet } from "@stryke/type-checks/is-set";
28
- import { isSetObject } from "@stryke/type-checks/is-set-object";
29
- import { isSetString } from "@stryke/type-checks/is-set-string";
30
- import { isString } from "@stryke/type-checks/is-string";
31
- import chalk from "chalk";
32
- import defu$1 from "defu";
33
- import Handlebars from "handlebars";
34
- import { isParentPath as isParentPath$1 } from "@stryke/path";
35
- import { prettyBytes } from "@stryke/string-format/pretty-bytes";
36
- import { match } from "bundle-require";
37
- import { createBundle } from "dts-buddy";
38
- import { getPackageName, getPackageVersion, hasPackageVersion } from "@stryke/string-format/package";
39
- import { readJsonFile } from "@stryke/fs/json";
40
- import { getObjectDiff } from "@donedeal0/superdiff";
41
- import { StormJSON } from "@stryke/json/storm-json";
42
-
43
- //#region package.json
44
- var name = "powerlines";
45
- var version = "0.42.30";
46
-
47
- //#endregion
48
- //#region src/_internal/helpers/generate-types.ts
49
- /**
50
- * Formats the generated TypeScript types source code.
51
- *
52
- * @param code - The generated TypeScript code.
53
- * @returns The formatted TypeScript code.
54
- */
55
- function formatTypes(code = "") {
56
- return code.replaceAll("#private;", "").replace(/__Ω/g, "");
57
- }
58
- /**
59
- * Emits TypeScript declaration types for the provided files using the given TypeScript configuration.
60
- *
61
- * @param context - The context containing options and environment paths.
62
- * @param files - The list of files to generate types for.
63
- * @returns A promise that resolves to the generated TypeScript declaration types.
64
- */
65
- async function emitBuiltinTypes(context, files) {
66
- if (files.length === 0) {
67
- context.debug("No files provided for TypeScript types generation. Typescript compilation for built-in modules will be skipped.");
68
- return {
69
- code: "",
70
- directives: []
71
- };
72
- }
73
- context.debug(`Running the TypeScript compiler for ${files.length} generated built-in module files.`);
74
- let result = await createBundle({
75
- context,
76
- project: context.tsconfig.tsconfigFilePath,
77
- output: context.typesPath,
78
- include: files.map((file) => appendPath(file, context.workspaceConfig.workspaceRoot)),
79
- modules: (await context.getBuiltins()).reduce((ret, file) => {
80
- ret[`${context.config.framework}:${file.id}`] = file.path;
81
- return ret;
82
- }, {}),
83
- compilerOptions: {
84
- declaration: true,
85
- declarationMap: false,
86
- emitDeclarationOnly: true,
87
- sourceMap: false,
88
- outDir: replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot),
89
- composite: false,
90
- incremental: false,
91
- tsBuildInfoFile: void 0
92
- }
93
- });
94
- result = formatTypes(result);
95
- for (const file of files.map((file) => appendPath(file, context.workspaceConfig.workspaceRoot)).filter((file) => isParentPath$1(file, context.builtinsPath))) {
96
- const content = await context.fs.read(file);
97
- if (isSetString(content)) {
98
- const moduleComment = content.match(new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${context.config.framework}:(?:${context.builtins.join("|")})(?s:.)*?\\*\\/\\s+`))?.find((comment) => isSetString(comment?.trim()));
99
- if (moduleComment) {
100
- context.debug(`Adding module-level comment for the built-in module types declaration for file: ${file}`);
101
- const metadata = context.fs.getMetadata(file);
102
- if (metadata?.id) result = result.replace(`declare module "${context.config.framework}:${metadata.id}" {`, `${moduleComment.trim()}
103
- declare module "${context.config.framework}:${metadata.id}" {`);
104
- }
105
- }
106
- }
107
- result = await (0, utils_exports.format)(context, context.typesPath, result);
108
- context.debug(`A TypeScript declaration file (size: ${prettyBytes(new Blob(toArray(result)).size)}) emitted for the built-in modules types.`);
109
- return {
110
- code: result,
111
- directives: []
112
- };
113
- }
114
-
115
- //#endregion
116
- //#region src/_internal/helpers/install.ts
117
- /**
118
- * Installs a package if it is not already installed.
119
- *
120
- * @param context - The resolved options
121
- * @param packageName - The name of the package to install
122
- * @param dev - Whether to install the package as a dev dependency
123
- */
124
- async function installPackage(context, packageName, dev = false) {
125
- if (!await isPackageListed(getPackageName(packageName), { cwd: context.config.root })) if (context.config.autoInstall) {
126
- context.warn(`The package "${packageName}" is not installed. It will be installed automatically.`);
127
- const result = await install(packageName, {
128
- cwd: context.config.root,
129
- dev
130
- });
131
- if (isNumber(result.exitCode) && result.exitCode > 0) {
132
- context.error(result.stderr);
133
- throw new Error(`An error occurred while installing the package "${packageName}"`);
134
- }
135
- } else context.warn(`The package "${packageName}" is not installed. Since the "autoInstall" option is set to false, it will not be installed automatically.`);
136
- else if (hasPackageVersion(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
137
- if (!await doesPackageMatch(getPackageName(packageName), getPackageVersion(packageName), context.config.root)) {
138
- const packageListing = await getPackageListing(getPackageName(packageName), { cwd: context.config.root });
139
- if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) context.warn(`The package "${getPackageName(packageName)}" is installed but does not match the expected version ${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.`);
140
- }
141
- }
142
- }
143
-
144
- //#endregion
145
- //#region src/_internal/helpers/install-dependencies.ts
146
- /**
147
- * Install missing project dependencies.
148
- *
149
- * @param context - The build context.
150
- */
151
- async function installDependencies(context) {
152
- context.debug(`Checking and installing missing project dependencies.`);
153
- context.dependencies ??= {};
154
- context.devDependencies ??= {};
155
- if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
156
- context.debug(`No dependencies or devDependencies to install. Skipping installation step.`);
157
- return;
158
- }
159
- context.debug(`The following packages are required: \nDependencies: \n${Object.entries(context.dependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}\n\nDevDependencies: \n${Object.entries(context.devDependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}`);
160
- await Promise.all([Promise.all(Object.entries(context.dependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, false))), Promise.all(Object.entries(context.devDependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, true)))]);
161
- }
162
-
163
- //#endregion
164
- //#region src/_internal/helpers/resolve-tsconfig.ts
165
- function getTsconfigDtsPath(context) {
166
- return joinPaths(relativePath(joinPaths(context.workspaceConfig.workspaceRoot, context.config.root), findFilePath(context.typesPath)), findFileName(context.typesPath));
167
- }
168
- async function resolveTsconfigChanges(context) {
169
- const tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig, context.config.tsconfigRaw);
170
- const tsconfigJson = await readJsonFile(getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig));
171
- tsconfigJson.compilerOptions ??= {};
172
- if (context.config.output.dts !== false) {
173
- const dtsRelativePath = getTsconfigDtsPath(context);
174
- if (!tsconfigJson.include?.some((filePattern) => isIncludeMatchFound(filePattern, [context.typesPath, dtsRelativePath]))) {
175
- tsconfigJson.include ??= [];
176
- tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
177
- }
178
- }
179
- if (!tsconfig.options.lib?.some((lib) => [
180
- "lib.esnext.d.ts",
181
- "lib.es2021.d.ts",
182
- "lib.es2022.d.ts",
183
- "lib.es2023.d.ts"
184
- ].includes(lib.toLowerCase()))) {
185
- tsconfigJson.compilerOptions.lib ??= [];
186
- tsconfigJson.compilerOptions.lib.push("esnext");
187
- }
188
- if (tsconfig.options.esModuleInterop !== true) tsconfigJson.compilerOptions.esModuleInterop = true;
189
- if (tsconfig.options.isolatedModules !== true) tsconfigJson.compilerOptions.isolatedModules = true;
190
- if (context.config.platform === "node") {
191
- if (!tsconfig.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
192
- tsconfigJson.compilerOptions.types ??= [];
193
- tsconfigJson.compilerOptions.types.push("node");
194
- }
195
- }
196
- return tsconfigJson;
197
- }
198
- async function initializeTsconfig(context) {
199
- context.debug("Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
200
- if (!isPackageExists("typescript")) throw new Error("The TypeScript package is not installed. Please install the package using the command: \"npm install typescript --save-dev\"");
201
- const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig);
202
- context.tsconfig.originalTsconfigJson = await readJsonFile(tsconfigFilePath);
203
- context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
204
- context.debug("Writing updated TypeScript configuration (tsconfig.json) file to disk.");
205
- await context.fs.write(tsconfigFilePath, StormJSON.stringify(context.tsconfig.tsconfigJson));
206
- context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
207
- }
208
- async function resolveTsconfig(context) {
209
- const updateTsconfigJson = await readJsonFile(context.tsconfig.tsconfigFilePath);
210
- if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) delete updateTsconfigJson.compilerOptions.types;
211
- const result = getObjectDiff(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
212
- ignoreArrayOrder: true,
213
- showOnly: {
214
- statuses: [
215
- "added",
216
- "deleted",
217
- "updated"
218
- ],
219
- granularity: "deep"
220
- }
221
- });
222
- const changes = [];
223
- const getChanges = (difference, property) => {
224
- if (difference.status === "added" || difference.status === "deleted" || difference.status === "updated") if (difference.diff) for (const diff of difference.diff) getChanges(diff, property ? `${property}.${difference.property}` : difference.property);
225
- else changes.push({
226
- field: property ? `${property}.${difference.property}` : difference.property,
227
- status: difference.status,
228
- previous: difference.status === "added" ? "---" : StormJSON.stringify(difference.previousValue),
229
- current: difference.status === "deleted" ? "---" : StormJSON.stringify(difference.currentValue)
230
- });
231
- };
232
- for (const diff of result.diff) getChanges(diff);
233
- if (changes.length > 0) context.warn(`Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
234
-
235
- ${changes.map((change, i) => `${chalk.bold.whiteBright(`${i + 1}. ${titleCase(change.status)} the ${change.field} field: `)}
236
- ${chalk.red(` - Previous: ${change.previous} `)}
237
- ${chalk.green(` - Updated: ${change.current} `)}
238
- `).join("\n")}
239
- `);
240
- await context.fs.write(context.tsconfig.tsconfigFilePath, StormJSON.stringify(updateTsconfigJson));
241
- context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig);
242
- if (!context.tsconfig) throw new Error("Failed to parse the TypeScript configuration file.");
243
- }
244
-
245
- //#endregion
246
- //#region src/api.ts
247
- /**
248
- * The Powerlines API class
249
- *
250
- * @remarks
251
- * This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.
252
- *
253
- * @public
254
- */
255
- var PowerlinesAPI = class PowerlinesAPI {
256
- /**
257
- * The Powerlines context
258
- */
259
- #context;
260
- /**
261
- * The Powerlines context
262
- */
263
- get context() {
264
- return this.#context;
265
- }
266
- /**
267
- * Create a new Powerlines API instance
268
- *
269
- * @param context - The Powerlines context
270
- */
271
- constructor(context) {
272
- this.#context = context;
273
- }
274
- /**
275
- * Initialize a Powerlines API instance
276
- *
277
- * @param workspaceRoot - The directory of the underlying workspace the Powerlines project exists in
278
- * @param config - An object containing the configuration required to run Powerlines tasks.
279
- * @returns A new instance of the Powerlines API
280
- */
281
- static async from(workspaceRoot, config) {
282
- const api = new PowerlinesAPI(await PowerlinesAPIContext.from(workspaceRoot, config));
283
- api.#context.$$internal = {
284
- api,
285
- addPlugin: api.#addPlugin.bind(api)
286
- };
287
- api.context.info(`🔌 The Powerlines Engine v${version} has started`);
288
- for (const plugin of api.context.config.plugins.flat(10) ?? []) await api.#addPlugin(plugin);
289
- if (api.context.plugins.length === 0) api.context.warn("No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
290
- else api.context.info(`🔌 Loaded ${api.context.plugins.length} ${titleCase(api.context.config.framework)} plugin${api.context.plugins.length > 1 ? "s" : ""}: \n\n${api.context.plugins.map((plugin, index) => ` ${index + 1}. ${(0, utils_exports.colorText)(plugin.name)}`).join("\n")}`);
291
- const pluginConfig = await api.callHook("config", {
292
- environment: await api.context.getEnvironment(),
293
- sequential: true,
294
- result: "merge",
295
- merge: mergeConfigs
296
- });
297
- await api.context.withUserConfig(pluginConfig, { isHighPriority: false });
298
- return api;
299
- }
300
- /**
301
- * Generate the Powerlines typescript declaration file
302
- *
303
- * @remarks
304
- * This method will only generate the typescript declaration file for the Powerlines project. It is generally recommended to run the full `prepare` command, which will run this method as part of its process.
305
- *
306
- * @param inlineConfig - The inline configuration for the types command
307
- */
308
- async types(inlineConfig = { command: "types" }) {
309
- this.context.info(" 🏗️ Generating typescript declarations for the Powerlines project");
310
- this.context.debug(" Aggregating configuration options for the Powerlines project");
311
- inlineConfig.command ??= "types";
312
- await this.context.withInlineConfig(inlineConfig);
313
- await this.#executeEnvironments(async (context) => {
314
- context.debug(`Initializing the processing options for the Powerlines project.`);
315
- await this.callHook("configResolved", {
316
- environment: context,
317
- order: "pre"
318
- });
319
- await initializeTsconfig(context);
320
- await this.callHook("configResolved", {
321
- environment: context,
322
- order: "normal"
323
- });
324
- if (context.entry.length > 0) context.debug(`The configuration provided ${isObject(context.config.input) ? Object.keys(context.config.input).length : toArray(context.config.input).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 ? `: \n${context.entry.map((entry) => `- ${entry.file}${entry.output ? ` -> ${entry.output}` : ""}`).join(" \n")}` : ""}`);
325
- else context.warn(`No entry files were found for the ${context.config.title} project. Please ensure this is correct. Powerlines plugins generally require at least one entry point to function properly.`);
326
- await resolveTsconfig(context);
327
- await installDependencies(context);
328
- await this.callHook("configResolved", {
329
- environment: context,
330
- order: "post"
331
- });
332
- context.trace(`Powerlines configuration has been resolved: \n\n${formatLogMessage({
333
- ...context.config,
334
- userConfig: isSetObject(context.config.userConfig) ? omit(context.config.userConfig, ["plugins"]) : void 0,
335
- inlineConfig: isSetObject(context.config.inlineConfig) ? omit(context.config.inlineConfig, ["plugins"]) : void 0,
336
- plugins: context.plugins.map((plugin) => plugin.plugin.name)
337
- })}`);
338
- if (!context.fs.existsSync(context.cachePath)) await createDirectory(context.cachePath);
339
- if (!context.fs.existsSync(context.dataPath)) await createDirectory(context.dataPath);
340
- if (context.config.skipCache === true || context.persistedMeta?.checksum !== context.meta.checksum) context.debug(`Using previously prepared files as the meta checksum has not changed.`);
341
- else {
342
- context.info(`Running \`prepare\` command as the meta checksum has changed since the last run.`);
343
- await this.prepare(defu$1({ output: { types: false } }, inlineConfig));
344
- }
345
- await this.#types(context);
346
- this.context.debug("Formatting files generated during the types step.");
347
- await (0, utils_exports.format)(context, context.typesPath, await context.fs.read(context.typesPath) ?? "");
348
- await writeMetaFile(context);
349
- context.persistedMeta = context.meta;
350
- });
351
- this.context.debug("✔ Powerlines types generation has completed successfully");
352
- }
353
- /**
354
- * Prepare the Powerlines API
355
- *
356
- * @remarks
357
- * This method will prepare the Powerlines API for use, initializing any necessary resources.
358
- *
359
- * @param inlineConfig - The inline configuration for the prepare command
360
- */
361
- async prepare(inlineConfig = { command: "prepare" }) {
362
- this.context.info(" 🏗️ Preparing the Powerlines project");
363
- this.context.debug(" Aggregating configuration options for the Powerlines project");
364
- inlineConfig.command ??= "prepare";
365
- await this.context.withInlineConfig(inlineConfig);
366
- await this.#executeEnvironments(async (context) => {
367
- context.debug(`Initializing the processing options for the Powerlines project.`);
368
- await this.callHook("configResolved", {
369
- environment: context,
370
- order: "pre"
371
- });
372
- await initializeTsconfig(context);
373
- await this.callHook("configResolved", {
374
- environment: context,
375
- order: "normal"
376
- });
377
- if (context.entry.length > 0) context.debug(`The configuration provided ${isObject(context.config.input) ? Object.keys(context.config.input).length : toArray(context.config.input).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 ? `: \n${context.entry.map((entry) => `- ${entry.file}${entry.output ? ` -> ${entry.output}` : ""}`).join(" \n")}` : ""}`);
378
- else context.warn(`No entry files were found for the ${context.config.title} project. Please ensure this is correct. Powerlines plugins generally require at least one entry point to function properly.`);
379
- await resolveTsconfig(context);
380
- await installDependencies(context);
381
- await this.callHook("configResolved", {
382
- environment: context,
383
- order: "post"
384
- });
385
- context.trace(`Powerlines configuration has been resolved: \n\n${formatLogMessage({
386
- ...context.config,
387
- userConfig: isSetObject(context.config.userConfig) ? omit(context.config.userConfig, ["plugins"]) : void 0,
388
- inlineConfig: isSetObject(context.config.inlineConfig) ? omit(context.config.inlineConfig, ["plugins"]) : void 0,
389
- plugins: context.plugins.map((plugin) => plugin.plugin.name)
390
- })}`);
391
- if (!context.fs.existsSync(context.cachePath)) await createDirectory(context.cachePath);
392
- if (!context.fs.existsSync(context.dataPath)) await createDirectory(context.dataPath);
393
- await this.callHook("prepare", {
394
- environment: context,
395
- order: "pre"
396
- });
397
- await this.callHook("prepare", {
398
- environment: context,
399
- order: "normal"
400
- });
401
- await this.callHook("prepare", {
402
- environment: context,
403
- order: "post"
404
- });
405
- if (context.config.output.types !== false) await this.#types(context);
406
- this.context.debug("Formatting files generated during the prepare step.");
407
- await Promise.all([(0, utils_exports.formatFolder)(context, context.builtinsPath), (0, utils_exports.formatFolder)(context, context.entryPath)]);
408
- await writeMetaFile(context);
409
- context.persistedMeta = context.meta;
410
- });
411
- this.context.debug("✔ Powerlines preparation has completed successfully");
412
- }
413
- /**
414
- * Create a new Powerlines project
415
- *
416
- * @remarks
417
- * This method will create a new Powerlines project in the current directory.
418
- *
419
- * @param inlineConfig - The inline configuration for the new command
420
- * @returns A promise that resolves when the project has been created
421
- */
422
- async new(inlineConfig) {
423
- this.context.info(" 🆕 Creating a new Powerlines project");
424
- inlineConfig.command ??= "new";
425
- await this.prepare(inlineConfig);
426
- await this.#executeEnvironments(async (context) => {
427
- context.debug("Initializing the processing options for the Powerlines project.");
428
- await this.callHook("new", {
429
- environment: context,
430
- order: "pre"
431
- });
432
- const files = await listFiles(joinPaths(context.powerlinesPath, "files/common/**/*.hbs"));
433
- for (const file of files) {
434
- context.trace(`Adding template file to project: ${file}`);
435
- const template = Handlebars.compile(file);
436
- await context.fs.write(joinPaths(context.config.root, file.replace(".hbs", "")), template(context));
437
- }
438
- await this.callHook("new", {
439
- environment: context,
440
- order: "normal"
441
- });
442
- if (context.config.projectType === "application") {
443
- const files = await listFiles(joinPaths(context.powerlinesPath, "files/application/**/*.hbs"));
444
- for (const file of files) {
445
- context.trace(`Adding application template file: ${file}`);
446
- const template = Handlebars.compile(file);
447
- await context.fs.write(joinPaths(context.config.root, file.replace(".hbs", "")), template(context));
448
- }
449
- } else {
450
- const files = await listFiles(joinPaths(context.powerlinesPath, "files/library/**/*.hbs"));
451
- for (const file of files) {
452
- context.trace(`Adding library template file: ${file}`);
453
- const template = Handlebars.compile(file);
454
- await context.fs.write(joinPaths(context.config.root, file.replace(".hbs", "")), template(context));
455
- }
456
- }
457
- await this.callHook("new", {
458
- environment: context,
459
- order: "post"
460
- });
461
- });
462
- this.context.debug("✔ Powerlines new command completed successfully");
463
- }
464
- /**
465
- * Clean any previously prepared artifacts
466
- *
467
- * @remarks
468
- * This method will remove the previous Powerlines artifacts from the project.
469
- *
470
- * @param inlineConfig - The inline configuration for the clean command
471
- * @returns A promise that resolves when the clean command has completed
472
- */
473
- async clean(inlineConfig = { command: "clean" }) {
474
- this.context.info(" 🧹 Cleaning the previous Powerlines artifacts");
475
- inlineConfig.command ??= "clean";
476
- await this.prepare(inlineConfig);
477
- await this.#executeEnvironments(async (context) => {
478
- context.debug("Cleaning the project's dist and artifacts directories.");
479
- await context.fs.remove(joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.path));
480
- await context.fs.remove(joinPaths(context.workspaceConfig.workspaceRoot, context.config.root, context.config.output.artifactsPath));
481
- await this.callHook("clean", {
482
- environment: context,
483
- sequential: false
484
- });
485
- });
486
- this.context.debug("✔ Powerlines cleaning completed successfully");
487
- }
488
- /**
489
- * Lint the project
490
- *
491
- * @param inlineConfig - The inline configuration for the lint command
492
- * @returns A promise that resolves when the lint command has completed
493
- */
494
- async lint(inlineConfig = { command: "lint" }) {
495
- this.context.info(" 📝 Linting the Powerlines project");
496
- inlineConfig.command ??= "lint";
497
- await this.prepare(inlineConfig);
498
- await this.#executeEnvironments(async (context) => {
499
- await this.callHook("lint", {
500
- environment: context,
501
- sequential: false
502
- });
503
- });
504
- this.context.debug("✔ Powerlines linting completed successfully");
505
- }
506
- /**
507
- * Build the project
508
- *
509
- * @remarks
510
- * This method will build the Powerlines project, generating the necessary artifacts.
511
- *
512
- * @param inlineConfig - The inline configuration for the build command
513
- * @returns A promise that resolves when the build command has completed
514
- */
515
- async build(inlineConfig = { command: "build" }) {
516
- this.context.info(" 📦 Building the Powerlines project");
517
- await this.context.generateChecksum();
518
- if (this.context.meta.checksum !== this.context.persistedMeta?.checksum || this.context.config.skipCache) {
519
- this.context.info(!this.context.persistedMeta?.checksum ? "No previous build cache found. Preparing the project for the initial build." : this.context.meta.checksum !== this.context.persistedMeta.checksum ? "The project has been modified since the last time `prepare` was ran. Re-preparing the project." : "The project is configured to skip cache. Re-preparing the project.");
520
- inlineConfig.command ??= "build";
521
- await this.prepare(inlineConfig);
522
- }
523
- if (this.context.config.singleBuild) await this.#handleBuild(await this.#context.toEnvironment());
524
- else await this.#executeEnvironments(async (context) => {
525
- await this.#handleBuild(context);
526
- });
527
- this.context.debug("✔ Powerlines build completed successfully");
528
- }
529
- /**
530
- * Prepare the documentation for the project
531
- *
532
- * @param inlineConfig - The inline configuration for the docs command
533
- * @returns A promise that resolves when the documentation generation has completed
534
- */
535
- async docs(inlineConfig = { command: "docs" }) {
536
- this.context.info(" 📓 Generating documentation for the Powerlines project");
537
- inlineConfig.command ??= "docs";
538
- await this.prepare(inlineConfig);
539
- await this.#executeEnvironments(async (context) => {
540
- context.debug("Writing documentation for the Powerlines project artifacts.");
541
- inlineConfig.command ??= "docs";
542
- await this.prepare(inlineConfig);
543
- await this.#executeEnvironments(async (context) => {
544
- await this.callHook("docs", { environment: context });
545
- });
546
- });
547
- this.context.debug("✔ Powerlines documentation generation completed successfully");
548
- }
549
- /**
550
- * Deploy the project source code
551
- *
552
- * @remarks
553
- * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
554
- *
555
- * @param inlineConfig - The inline configuration for the deploy command
556
- */
557
- async deploy(inlineConfig = { command: "deploy" }) {
558
- this.context.info(" 🚀 Deploying the Powerlines project");
559
- inlineConfig.command ??= "deploy";
560
- await this.prepare(inlineConfig);
561
- await this.#executeEnvironments(async (context) => {
562
- await this.callHook("deploy", { environment: context });
563
- });
564
- this.context.debug("✔ Powerlines deploy completed successfully");
565
- }
566
- /**
567
- * Finalization process
568
- *
569
- * @remarks
570
- * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
571
- *
572
- * @returns A promise that resolves when the finalization process has completed
573
- */
574
- async finalize() {
575
- this.context.info(" 🏁 Powerlines finalization processes started");
576
- await this.#executeEnvironments(async (context) => {
577
- await this.callHook("finalize", { environment: context });
578
- await context.fs.dispose();
579
- if (existsSync(context.cachePath) && !(await listFiles(joinPaths(context.cachePath, "**/*")))?.length) await removeDirectory(context.cachePath);
580
- });
581
- this.context.debug("✔ Powerlines finalization completed successfully");
582
- }
583
- /**
584
- * Invokes the configured plugin hooks
585
- *
586
- * @remarks
587
- * By default, it will call the `"pre"`, `"normal"`, and `"post"` ordered hooks in sequence
588
- *
589
- * @param hook - The hook to call
590
- * @param options - The options to provide to the hook
591
- * @param args - The arguments to pass to the hook
592
- * @returns The result of the hook call
593
- */
594
- async callHook(hook, options, ...args) {
595
- return callHook(isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
596
- sequential: true,
597
- ...options
598
- }, ...args);
599
- }
600
- /**
601
- * Dispose of the Powerlines API instance
602
- *
603
- * @remarks
604
- * This method will finalize the Powerlines API instance, cleaning up any resources used.
605
- */
606
- async [Symbol.asyncDispose]() {
607
- await this.finalize();
608
- }
609
- async #handleBuild(context) {
610
- await this.callHook("build", {
611
- environment: context,
612
- order: "pre"
613
- });
614
- context.debug("Formatting the generated entry files before the build process starts.");
615
- await (0, utils_exports.formatFolder)(context, context.entryPath);
616
- await this.callHook("build", {
617
- environment: context,
618
- order: "normal"
619
- });
620
- if (context.config.output.copy) {
621
- context.debug("Copying project's files from build output directory.");
622
- const destinationPath = isParentPath(appendPath(context.config.output.path, context.workspaceConfig.workspaceRoot), appendPath(context.config.root, context.workspaceConfig.workspaceRoot)) ? joinPaths(context.config.output.copy.path, relativePath(appendPath(context.config.root, context.workspaceConfig.workspaceRoot), appendPath(context.config.output.path, context.workspaceConfig.workspaceRoot))) : joinPaths(context.config.output.copy.path, "dist");
623
- const sourcePath = appendPath(context.config.output.path, context.workspaceConfig.workspaceRoot);
624
- if (existsSync(sourcePath) && sourcePath !== destinationPath) {
625
- context.debug(`Copying files from project's build output directory (${context.config.output.path}) to the project's copy/publish directory (${destinationPath}).`);
626
- await copyFiles(sourcePath, destinationPath);
627
- } else context.warn(`The source path for the copy operation ${!existsSync(sourcePath) ? "does not exist" : "is the same as the destination path"}. Source: ${sourcePath}, Destination: ${destinationPath}. Skipping copying of build output files.`);
628
- if (context.config.output.copy.assets && Array.isArray(context.config.output.copy.assets)) await Promise.all(context.config.output.copy.assets.map(async (asset) => {
629
- context.trace(`Copying asset(s): ${chalk.redBright(context.workspaceConfig.workspaceRoot === asset.input ? asset.glob : appendPath(asset.glob, replacePath(asset.input, context.workspaceConfig.workspaceRoot)))} -> ${chalk.greenBright(appendPath(asset.glob, replacePath(asset.output, context.workspaceConfig.workspaceRoot)))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk.yellowBright(i)).join(", ")})` : ""}`);
630
- await context.fs.copy(asset, asset.output);
631
- }));
632
- } else context.debug("No copy configuration found for the project output. Skipping the copying of build output files.");
633
- await this.callHook("build", {
634
- environment: context,
635
- order: "post"
636
- });
637
- }
638
- /**
639
- * Get the configured environments
640
- *
641
- * @returns The configured environments
642
- */
643
- async #getEnvironments() {
644
- if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
645
- this.context.debug("No environments are configured for this Powerlines project. Using the default environment.");
646
- return [await this.context.getEnvironment()];
647
- }
648
- this.context.debug(`Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
649
- return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
650
- if (!await this.context.getEnvironmentSafe(name)) {
651
- const resolvedEnvironment = await this.callHook("configEnvironment", { environment: name }, name, config);
652
- if (resolvedEnvironment) this.context.environments[name] = await this.context.in(resolvedEnvironment);
653
- }
654
- return this.context.environments[name];
655
- }))).filter((context) => isSet(context));
656
- }
657
- /**
658
- * Execute a handler function for each environment
659
- *
660
- * @param handle - The handler function to execute for each environment
661
- */
662
- async #executeEnvironments(handle) {
663
- await Promise.all((await this.#getEnvironments()).map(async (context) => {
664
- return Promise.resolve(handle(context));
665
- }));
666
- }
667
- /**
668
- * Add a Powerlines plugin used in the build process
669
- *
670
- * @param config - The import path of the plugin to add
671
- */
672
- async #addPlugin(config) {
673
- if (config) {
674
- const result = await this.#initPlugin(config);
675
- if (!result) return;
676
- for (const plugin of result) {
677
- this.context.debug(`Successfully initialized the ${chalk.bold.cyanBright(plugin.name)} plugin`);
678
- await this.context.addPlugin(plugin);
679
- }
680
- }
681
- }
682
- /**
683
- * Initialize a Powerlines plugin
684
- *
685
- * @param config - The configuration for the plugin
686
- * @returns The initialized plugin instance, or null if the plugin was a duplicate
687
- * @throws Will throw an error if the plugin cannot be found or is invalid
688
- */
689
- async #initPlugin(config) {
690
- let awaited = config;
691
- if (isPromiseLike(config)) awaited = await Promise.resolve(config);
692
- if (!(0, plugin_utils_exports.isPluginConfig)(awaited)) {
693
- const invalid = (0, plugin_utils_exports.findInvalidPluginConfig)(awaited);
694
- throw new Error(`Invalid ${invalid && invalid.length > 1 ? "plugins" : "plugin"} specified in the configuration - ${invalid && invalid.length > 0 ? JSON.stringify(awaited) : invalid?.join("\n\n")} \n\nPlease ensure the value is one of the following: \n - an instance of \`Plugin\` \n - a plugin name \n - an object with the \`plugin\` and \`options\` properties \n - a tuple array with the plugin and options \n - a factory function that returns a plugin or array of plugins \n - an array of plugins or plugin configurations`);
695
- }
696
- let plugins;
697
- if ((0, plugin_utils_exports.isPlugin)(awaited)) plugins = [awaited];
698
- else if (isFunction(awaited)) plugins = toArray(await Promise.resolve(awaited()));
699
- else if (isString(awaited)) {
700
- const resolved = await this.#resolvePlugin(awaited);
701
- if (isFunction(resolved)) plugins = toArray(await Promise.resolve(resolved()));
702
- else plugins = toArray(resolved);
703
- } else if (Array.isArray(awaited) && awaited.every(plugin_utils_exports.isPlugin)) plugins = awaited;
704
- else if (Array.isArray(awaited) && awaited.every(plugin_utils_exports.isPluginConfig)) {
705
- plugins = [];
706
- for (const pluginConfig of awaited) {
707
- const initialized = await this.#initPlugin(pluginConfig);
708
- if (initialized) plugins.push(...initialized);
709
- }
710
- } else if ((0, plugin_utils_exports.isPluginConfigTuple)(awaited) || (0, plugin_utils_exports.isPluginConfigObject)(awaited)) {
711
- let pluginConfig;
712
- let pluginOptions;
713
- if ((0, plugin_utils_exports.isPluginConfigTuple)(awaited)) {
714
- pluginConfig = awaited[0];
715
- pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
716
- } else {
717
- pluginConfig = awaited.plugin;
718
- pluginOptions = awaited.options;
719
- }
720
- if (isSetString(pluginConfig)) {
721
- const resolved = await this.#resolvePlugin(pluginConfig);
722
- if (isFunction(resolved)) plugins = toArray(await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved()));
723
- else plugins = toArray(resolved);
724
- } else if (isFunction(pluginConfig)) plugins = toArray(await Promise.resolve(pluginConfig(pluginOptions)));
725
- else if (Array.isArray(pluginConfig) && pluginConfig.every(plugin_utils_exports.isPlugin)) plugins = pluginConfig;
726
- else if ((0, plugin_utils_exports.isPlugin)(pluginConfig)) plugins = toArray(pluginConfig);
727
- }
728
- if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
729
- if (plugins.length > 0 && !plugins.every(plugin_utils_exports.isPlugin)) throw new Error(`The plugin option ${JSON.stringify(plugins)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
730
- const result = [];
731
- for (const plugin of plugins) if ((0, plugin_utils_exports.checkDedupe)(plugin, this.context.plugins)) this.context.trace(`Duplicate ${chalk.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
732
- else {
733
- result.push(plugin);
734
- this.context.trace(`Initializing the ${chalk.bold.cyanBright(plugin.name)} plugin...`);
735
- }
736
- return result;
737
- }
738
- async #resolvePlugin(pluginPath) {
739
- if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
740
- const splits = pluginPath.split("/").filter(Boolean);
741
- pluginPath = `${splits[0]}/${splits[1]}`;
742
- }
743
- const isInstalled = isPackageExists(pluginPath, { paths: [this.context.workspaceConfig.workspaceRoot, this.context.config.root] });
744
- if (!isInstalled && this.context.config.autoInstall) {
745
- this.#context.warn(`The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
746
- const result = await install(pluginPath, { cwd: this.context.config.root });
747
- if (isNumber(result.exitCode) && result.exitCode > 0) {
748
- this.#context.error(result.stderr);
749
- throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
750
- }
751
- }
752
- try {
753
- const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(joinPaths(pluginPath, "plugin")));
754
- const result = module.plugin ?? module.default;
755
- if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
756
- return result;
757
- } catch (error) {
758
- try {
759
- const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
760
- const result = module.plugin ?? module.default;
761
- if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
762
- return result;
763
- } catch {
764
- if (!isInstalled) throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
765
- else throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
766
- ${isError(error) ? error.message : String(error)}
767
-
768
- 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\`.`);
769
- }
770
- }
771
- }
772
- /**
773
- * Generate the Powerlines TypeScript declaration file
774
- *
775
- * @remarks
776
- * This method will generate the TypeScript declaration file for the Powerlines project, including any types provided by plugins.
777
- *
778
- * @param context - The environment context to use for generating the TypeScript declaration file
779
- * @returns A promise that resolves when the TypeScript declaration file has been generated
780
- */
781
- async #types(context) {
782
- context.debug(`Preparing the TypeScript definitions for the Powerlines project.`);
783
- if (context.fs.existsSync(context.typesPath)) await context.fs.remove(context.typesPath);
784
- if (!await resolvePackage("typescript")) throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
785
- context.debug("Running TypeScript compiler for built-in runtime module files.");
786
- let { code, directives } = await emitBuiltinTypes(context, (await context.getBuiltins()).reduce((ret, builtin) => {
787
- const formatted = replacePath(builtin.path, context.workspaceConfig.workspaceRoot);
788
- if (!ret.includes(formatted)) ret.push(formatted);
789
- return ret;
790
- }, []));
791
- context.debug(`Generating TypeScript declaration file ${context.typesPath}.`);
792
- const merge = async (currentResult, previousResult) => {
793
- if (!isSetString(currentResult) && !isSetObject(currentResult) && !isSetString(previousResult) && !isSetObject(previousResult)) return {
794
- code,
795
- directives
796
- };
797
- const previous = (await (0, utils_exports.format)(context, context.typesPath, isSetString(previousResult) ? previousResult : isSetObject(previousResult) ? previousResult.code : "")).trim().replace(code, "").trim();
798
- const current = (await (0, utils_exports.format)(context, context.typesPath, isSetString(currentResult) ? currentResult : isSetObject(currentResult) ? currentResult.code : "")).trim().replace(previous, "").trim().replace(code, "").trim();
799
- return {
800
- directives: [...isSetObject(currentResult) && currentResult.directives ? currentResult.directives : [], ...isSetObject(previousResult) && previousResult.directives ? previousResult.directives : []],
801
- code: await (0, utils_exports.format)(context, context.typesPath, `${!previous.includes((0, utils_exports.getTypescriptFileHeader)(context)) && !current.includes((0, utils_exports.getTypescriptFileHeader)(context)) ? `${code}\n` : ""}${previous}\n${current}`.trim())
802
- };
803
- };
804
- const asNextParam = (previousResult) => isObject(previousResult) ? previousResult.code : previousResult;
805
- let result = await this.callHook("types", {
806
- environment: context,
807
- sequential: true,
808
- order: "pre",
809
- result: "merge",
810
- merge,
811
- asNextParam
812
- }, code);
813
- if (result) {
814
- if (isSetObject(result)) {
815
- code = result.code;
816
- if (Array.isArray(result.directives) && result.directives.length > 0) directives = getUnique([...directives, ...result.directives]).filter(Boolean);
817
- } else if (isSetString(result)) code = result;
818
- }
819
- result = await this.callHook("types", {
820
- environment: context,
821
- sequential: true,
822
- order: "normal",
823
- result: "merge",
824
- merge,
825
- asNextParam
826
- }, code);
827
- if (result) {
828
- if (isSetObject(result)) {
829
- code = result.code;
830
- if (Array.isArray(result.directives) && result.directives.length > 0) directives = getUnique([...directives, ...result.directives]).filter(Boolean);
831
- } else if (isSetString(result)) code = result;
832
- }
833
- result = await this.callHook("types", {
834
- environment: context,
835
- sequential: true,
836
- order: "post",
837
- result: "merge",
838
- merge,
839
- asNextParam
840
- }, code);
841
- if (result) {
842
- if (isSetObject(result)) {
843
- code = result.code;
844
- if (Array.isArray(result.directives) && result.directives.length > 0) directives = getUnique([...directives, ...result.directives]).filter(Boolean);
845
- } else if (isSetString(result)) code = result;
846
- }
847
- if (isSetString(code?.trim()) || directives.length > 0) await context.fs.write(context.typesPath, `${directives.length > 0 ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
848
-
849
- ` : ""}${(0, utils_exports.getTypescriptFileHeader)(context, {
850
- directive: null,
851
- prettierIgnore: false
852
- })}
853
-
854
- ${formatTypes(code)}
855
- `);
856
- }
857
- };
858
-
859
- //#endregion
860
- export { name as n, version as r, PowerlinesAPI as t };
861
- //# sourceMappingURL=api-BQswQ9mT.mjs.map