@powerlines/plugin-webpack 0.5.130 → 0.5.132

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 (130) hide show
  1. package/dist/helpers/index.cjs +3 -2
  2. package/dist/helpers/index.d.cts +3 -1
  3. package/dist/helpers/index.d.mts +3 -1
  4. package/dist/helpers/index.mjs +2 -1
  5. package/dist/helpers/unplugin.cjs +2 -11
  6. package/dist/helpers/unplugin.d.cts +2 -6
  7. package/dist/helpers/unplugin.d.mts +2 -6
  8. package/dist/helpers/unplugin.mjs +1 -9
  9. package/dist/helpers-B15z10jN.mjs +1 -0
  10. package/dist/helpers-LF26RHol.cjs +0 -0
  11. package/dist/index-9iG2qHLe.d.mts +1 -0
  12. package/dist/index-D4ELpJXS.d.cts +1 -0
  13. package/dist/index-D6CnpA_r.d.cts +1 -0
  14. package/dist/index-DL0uimUT.d.mts +1 -0
  15. package/dist/index.cjs +50 -8
  16. package/dist/index.d.cts +4 -3
  17. package/dist/index.d.mts +5 -5
  18. package/dist/index.mjs +46 -3
  19. package/dist/plugin-C5bG6Zu0.d.mts +1772 -0
  20. package/dist/plugin-Cl1J-dKa.d.cts +1769 -0
  21. package/dist/plugin-ifZVa20V.mjs +1 -0
  22. package/dist/plugin-pBKbb5K9.cjs +0 -0
  23. package/dist/types/index.cjs +2 -0
  24. package/dist/types/index.d.cts +2 -1
  25. package/dist/types/index.d.mts +2 -1
  26. package/dist/types/index.mjs +3 -0
  27. package/dist/types/plugin.cjs +1 -0
  28. package/dist/types/plugin.d.cts +1 -12
  29. package/dist/types/plugin.d.mts +1 -12
  30. package/dist/types/plugin.mjs +2 -0
  31. package/dist/types-U3zd8PTP.mjs +1 -0
  32. package/dist/types-o3zWarRp.cjs +0 -0
  33. package/dist/unplugin-Bo9KoKSB.d.cts +7 -0
  34. package/dist/unplugin-Ct4wZxE5.d.mts +7 -0
  35. package/dist/unplugin-GJmHohOE.mjs +4617 -0
  36. package/dist/unplugin-bKYETUU8.cjs +4661 -0
  37. package/package.json +5 -5
  38. package/dist/_virtual/rolldown_runtime.cjs +0 -29
  39. package/dist/powerlines/schemas/fs.cjs +0 -226
  40. package/dist/powerlines/schemas/fs.mjs +0 -224
  41. package/dist/powerlines/src/api.cjs +0 -580
  42. package/dist/powerlines/src/api.mjs +0 -578
  43. package/dist/powerlines/src/internal/babel/module-resolver-plugin.cjs +0 -86
  44. package/dist/powerlines/src/internal/babel/module-resolver-plugin.mjs +0 -84
  45. package/dist/powerlines/src/internal/helpers/environment.cjs +0 -52
  46. package/dist/powerlines/src/internal/helpers/environment.mjs +0 -48
  47. package/dist/powerlines/src/internal/helpers/generate-types.cjs +0 -51
  48. package/dist/powerlines/src/internal/helpers/generate-types.mjs +0 -49
  49. package/dist/powerlines/src/internal/helpers/hooks.cjs +0 -63
  50. package/dist/powerlines/src/internal/helpers/hooks.mjs +0 -61
  51. package/dist/powerlines/src/internal/helpers/install-dependencies.cjs +0 -25
  52. package/dist/powerlines/src/internal/helpers/install-dependencies.mjs +0 -24
  53. package/dist/powerlines/src/internal/helpers/install.cjs +0 -37
  54. package/dist/powerlines/src/internal/helpers/install.mjs +0 -36
  55. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.cjs +0 -98
  56. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.mjs +0 -94
  57. package/dist/powerlines/src/internal/helpers/resolver.cjs +0 -43
  58. package/dist/powerlines/src/internal/helpers/resolver.mjs +0 -41
  59. package/dist/powerlines/src/lib/build/webpack.cjs +0 -47
  60. package/dist/powerlines/src/lib/build/webpack.mjs +0 -45
  61. package/dist/powerlines/src/lib/config-file.cjs +0 -79
  62. package/dist/powerlines/src/lib/config-file.mjs +0 -76
  63. package/dist/powerlines/src/lib/contexts/api-context.cjs +0 -184
  64. package/dist/powerlines/src/lib/contexts/api-context.mjs +0 -182
  65. package/dist/powerlines/src/lib/contexts/context.cjs +0 -931
  66. package/dist/powerlines/src/lib/contexts/context.mjs +0 -929
  67. package/dist/powerlines/src/lib/contexts/environment-context.cjs +0 -160
  68. package/dist/powerlines/src/lib/contexts/environment-context.mjs +0 -159
  69. package/dist/powerlines/src/lib/contexts/plugin-context.cjs +0 -75
  70. package/dist/powerlines/src/lib/contexts/plugin-context.mjs +0 -74
  71. package/dist/powerlines/src/lib/entry.cjs +0 -69
  72. package/dist/powerlines/src/lib/entry.mjs +0 -67
  73. package/dist/powerlines/src/lib/fs/helpers.cjs +0 -85
  74. package/dist/powerlines/src/lib/fs/helpers.mjs +0 -81
  75. package/dist/powerlines/src/lib/fs/storage/base.cjs +0 -196
  76. package/dist/powerlines/src/lib/fs/storage/base.mjs +0 -195
  77. package/dist/powerlines/src/lib/fs/storage/file-system.cjs +0 -170
  78. package/dist/powerlines/src/lib/fs/storage/file-system.mjs +0 -169
  79. package/dist/powerlines/src/lib/fs/storage/virtual.cjs +0 -88
  80. package/dist/powerlines/src/lib/fs/storage/virtual.mjs +0 -87
  81. package/dist/powerlines/src/lib/fs/vfs.cjs +0 -830
  82. package/dist/powerlines/src/lib/fs/vfs.mjs +0 -828
  83. package/dist/powerlines/src/lib/logger.cjs +0 -58
  84. package/dist/powerlines/src/lib/logger.mjs +0 -55
  85. package/dist/powerlines/src/lib/typescript/ts-morph.cjs +0 -104
  86. package/dist/powerlines/src/lib/typescript/ts-morph.mjs +0 -102
  87. package/dist/powerlines/src/lib/typescript/tsconfig.cjs +0 -149
  88. package/dist/powerlines/src/lib/typescript/tsconfig.mjs +0 -144
  89. package/dist/powerlines/src/lib/unplugin/factory.cjs +0 -6
  90. package/dist/powerlines/src/lib/unplugin/factory.mjs +0 -8
  91. package/dist/powerlines/src/lib/unplugin/helpers.cjs +0 -17
  92. package/dist/powerlines/src/lib/unplugin/helpers.mjs +0 -16
  93. package/dist/powerlines/src/lib/unplugin/index.cjs +0 -3
  94. package/dist/powerlines/src/lib/unplugin/index.mjs +0 -5
  95. package/dist/powerlines/src/lib/unplugin/plugin.cjs +0 -128
  96. package/dist/powerlines/src/lib/unplugin/plugin.mjs +0 -127
  97. package/dist/powerlines/src/lib/utilities/file-header.cjs +0 -22
  98. package/dist/powerlines/src/lib/utilities/file-header.mjs +0 -21
  99. package/dist/powerlines/src/lib/utilities/meta.cjs +0 -45
  100. package/dist/powerlines/src/lib/utilities/meta.mjs +0 -41
  101. package/dist/powerlines/src/lib/utilities/source-file.cjs +0 -22
  102. package/dist/powerlines/src/lib/utilities/source-file.mjs +0 -21
  103. package/dist/powerlines/src/plugin-utils/helpers.cjs +0 -148
  104. package/dist/powerlines/src/plugin-utils/helpers.mjs +0 -138
  105. package/dist/powerlines/src/plugin-utils/paths.cjs +0 -36
  106. package/dist/powerlines/src/plugin-utils/paths.mjs +0 -35
  107. package/dist/powerlines/src/types/babel.d.mts +0 -4
  108. package/dist/powerlines/src/types/build.cjs +0 -15
  109. package/dist/powerlines/src/types/build.d.cts +0 -149
  110. package/dist/powerlines/src/types/build.d.mts +0 -149
  111. package/dist/powerlines/src/types/build.mjs +0 -14
  112. package/dist/powerlines/src/types/commands.cjs +0 -16
  113. package/dist/powerlines/src/types/commands.d.cts +0 -8
  114. package/dist/powerlines/src/types/commands.d.mts +0 -9
  115. package/dist/powerlines/src/types/commands.mjs +0 -15
  116. package/dist/powerlines/src/types/config.d.cts +0 -370
  117. package/dist/powerlines/src/types/config.d.mts +0 -372
  118. package/dist/powerlines/src/types/context.d.cts +0 -403
  119. package/dist/powerlines/src/types/context.d.mts +0 -405
  120. package/dist/powerlines/src/types/fs.d.cts +0 -486
  121. package/dist/powerlines/src/types/fs.d.mts +0 -486
  122. package/dist/powerlines/src/types/hooks.d.mts +0 -2
  123. package/dist/powerlines/src/types/plugin.cjs +0 -32
  124. package/dist/powerlines/src/types/plugin.d.cts +0 -231
  125. package/dist/powerlines/src/types/plugin.d.mts +0 -231
  126. package/dist/powerlines/src/types/plugin.mjs +0 -31
  127. package/dist/powerlines/src/types/resolved.d.cts +0 -82
  128. package/dist/powerlines/src/types/resolved.d.mts +0 -83
  129. package/dist/powerlines/src/types/tsconfig.d.cts +0 -69
  130. package/dist/powerlines/src/types/tsconfig.d.mts +0 -69
@@ -1,578 +0,0 @@
1
- import { moduleResolverBabelPlugin } from "./internal/babel/module-resolver-plugin.mjs";
2
- import { emitTypes, formatTypes } from "./internal/helpers/generate-types.mjs";
3
- import { callHook } from "./internal/helpers/hooks.mjs";
4
- import { installDependencies } from "./internal/helpers/install-dependencies.mjs";
5
- import { getParsedTypeScriptConfig, isIncludeMatchFound } from "./lib/typescript/tsconfig.mjs";
6
- import { getTsconfigDtsPath, initializeTsconfig, resolveTsconfig } from "./internal/helpers/resolve-tsconfig.mjs";
7
- import { checkDedupe, findInvalidPluginConfig, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple } from "./plugin-utils/helpers.mjs";
8
- import { writeMetaFile } from "./lib/utilities/meta.mjs";
9
- import { PowerlinesAPIContext } from "./lib/contexts/api-context.mjs";
10
- import { getFileHeader } from "./lib/utilities/file-header.mjs";
11
- import { LogLevelLabel } from "@storm-software/config-tools/types";
12
- import { joinPaths } from "@stryke/path/join-paths";
13
- import { transformAsync } from "@babel/core";
14
- import { formatLogMessage } from "@storm-software/config-tools/logger/console";
15
- import { toArray } from "@stryke/convert/to-array";
16
- import { createDirectory } from "@stryke/fs/helpers";
17
- import { install } from "@stryke/fs/install";
18
- import { listFiles } from "@stryke/fs/list-files";
19
- import { isPackageExists } from "@stryke/fs/package-fns";
20
- import { resolvePackage } from "@stryke/fs/resolve";
21
- import { appendPath } from "@stryke/path/append";
22
- import { replacePath } from "@stryke/path/replace";
23
- import { isError } from "@stryke/type-checks/is-error";
24
- import { isFunction } from "@stryke/type-checks/is-function";
25
- import { isNumber } from "@stryke/type-checks/is-number";
26
- import { isObject } from "@stryke/type-checks/is-object";
27
- import { isPromiseLike } from "@stryke/type-checks/is-promise";
28
- import { isSet } from "@stryke/type-checks/is-set";
29
- import { isSetObject } from "@stryke/type-checks/is-set-object";
30
- import { isSetString } from "@stryke/type-checks/is-set-string";
31
- import { isString } from "@stryke/type-checks/is-string";
32
- import chalk from "chalk";
33
- import Handlebars from "handlebars";
34
-
35
- //#region ../powerlines/src/api.ts
36
- /**
37
- * The Powerlines API class
38
- *
39
- * @remarks
40
- * This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.
41
- *
42
- * @public
43
- */
44
- var PowerlinesAPI = class PowerlinesAPI {
45
- /**
46
- * The Powerlines context
47
- */
48
- #context;
49
- /**
50
- * The Powerlines context
51
- */
52
- get context() {
53
- return this.#context;
54
- }
55
- /**
56
- * Create a new Powerlines API instance
57
- *
58
- * @param context - The Powerlines context
59
- */
60
- constructor(context) {
61
- this.#context = context;
62
- }
63
- /**
64
- * Initialize a Powerlines API instance
65
- *
66
- * @param workspaceRoot - The directory of the underlying workspace the Powerlines project exists in
67
- * @param config - An object containing the configuration required to run Powerlines tasks.
68
- * @returns A new instance of the Powerlines API
69
- */
70
- static async from(workspaceRoot, config) {
71
- const api = new PowerlinesAPI(await PowerlinesAPIContext.from(workspaceRoot, config));
72
- api.#context.$$internal = {
73
- api,
74
- addPlugin: api.#addPlugin.bind(api)
75
- };
76
- for (const plugin of api.context.config.plugins ?? []) await api.#addPlugin(plugin);
77
- if (api.context.plugins.length === 0) api.context.log(LogLevelLabel.WARN, "No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
78
- const pluginConfig = await api.callHook("config", {
79
- environment: await api.context.getEnvironment(),
80
- sequential: true,
81
- result: "merge"
82
- });
83
- await api.context.withUserConfig(pluginConfig, { isHighPriority: false });
84
- return api;
85
- }
86
- /**
87
- * Prepare the Powerlines API
88
- *
89
- * @remarks
90
- * This method will prepare the Powerlines API for use, initializing any necessary resources.
91
- *
92
- * @param inlineConfig - The inline configuration for the prepare command
93
- */
94
- async prepare(inlineConfig = { command: "prepare" }) {
95
- this.context.log(LogLevelLabel.TRACE, " 🏗️ Preparing the Powerlines project");
96
- this.context.log(LogLevelLabel.TRACE, " ⚙️ Aggregating configuration options for the Powerlines project");
97
- await this.context.withInlineConfig(inlineConfig);
98
- await this.#executeEnvironments(async (context) => {
99
- context.log(LogLevelLabel.TRACE, `Initializing the processing options for the Powerlines project.`);
100
- await this.callHook("configResolved", {
101
- environment: context,
102
- order: "pre"
103
- });
104
- await initializeTsconfig(context);
105
- await this.callHook("configResolved", {
106
- environment: context,
107
- order: "normal"
108
- });
109
- context.log(LogLevelLabel.DEBUG, `The configuration provided ${toArray(context.config.entry).length} entry point(s), Powerlines has found ${context.entry.length} entry files(s) for the ${context.config.title} project${context.entry.length > 0 && context.entry.length < 10 ? `: \n${context.entry.map((entry) => `- ${entry.file}${entry.output ? ` -> ${entry.output}` : ""}`).join(" \n")}` : ""}.`);
110
- await resolveTsconfig(context);
111
- await installDependencies(context);
112
- await this.callHook("configResolved", {
113
- environment: context,
114
- order: "post"
115
- });
116
- context.log(LogLevelLabel.TRACE, `Powerlines configuration has been resolved: \n\n${formatLogMessage(context.config)}`);
117
- if (!context.fs.existsSync(context.cachePath)) await createDirectory(context.cachePath);
118
- if (!context.fs.existsSync(context.dataPath)) await createDirectory(context.dataPath);
119
- await this.callHook("prepare", {
120
- environment: context,
121
- order: "pre"
122
- });
123
- await this.callHook("prepare", {
124
- environment: context,
125
- order: "normal"
126
- });
127
- if (context.config.output.dts !== false) {
128
- context.log(LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
129
- if (context.fs.existsSync(context.dtsPath)) await context.fs.remove(context.dtsPath);
130
- context.log(LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
131
- const builtinFilePaths = await Promise.all((await context.getBuiltins()).map(async (file) => {
132
- const result$1 = await transformAsync(file.code.toString(), {
133
- highlightCode: true,
134
- code: true,
135
- ast: false,
136
- cloneInputAst: false,
137
- comments: true,
138
- sourceType: "module",
139
- configFile: false,
140
- babelrc: false,
141
- envName: context.config.mode,
142
- caller: { name: "powerlines" },
143
- ...context.config.transform.babel,
144
- filename: file.path,
145
- plugins: [["@babel/plugin-syntax-typescript"], [moduleResolverBabelPlugin(context)]]
146
- });
147
- if (!result$1?.code) throw new Error(`Powerlines - Generate Types failed to compile ${file.id}`);
148
- context.log(LogLevelLabel.TRACE, `Writing transformed built-in runtime file ${file.id}.`);
149
- await context.emitBuiltin(result$1.code, file.id, file.path);
150
- return file.path;
151
- }));
152
- if (!await resolvePackage("typescript")) throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
153
- const files = builtinFilePaths.reduce((ret, fileName) => {
154
- const formatted = replacePath(fileName, context.workspaceConfig.workspaceRoot);
155
- if (!ret.includes(formatted)) ret.push(formatted);
156
- return ret;
157
- }, []);
158
- context.log(LogLevelLabel.TRACE, "Parsing TypeScript configuration for the Powerlines project.");
159
- let types = await emitTypes(context, files);
160
- context.log(LogLevelLabel.TRACE, `Generating TypeScript declaration file ${context.dtsPath}.`);
161
- const directives = [];
162
- const asNextParam = (previousResult) => isObject(previousResult) ? previousResult.code : previousResult;
163
- let result = await this.callHook("types", {
164
- environment: context,
165
- sequential: true,
166
- order: "pre",
167
- result: "merge",
168
- asNextParam
169
- }, types);
170
- if (result) {
171
- if (isSetObject(result)) {
172
- types = result.code;
173
- if (Array.isArray(result.directives) && result.directives.length > 0) directives.push(...result.directives);
174
- } else if (isSetString(result)) types = result;
175
- }
176
- result = await this.callHook("types", {
177
- environment: context,
178
- sequential: true,
179
- order: "normal",
180
- result: "merge",
181
- asNextParam
182
- }, types);
183
- if (result) {
184
- if (isSetObject(result)) {
185
- types = result.code;
186
- if (Array.isArray(result.directives) && result.directives.length > 0) directives.push(...result.directives);
187
- } else if (isSetString(result)) types = result;
188
- }
189
- result = await this.callHook("types", {
190
- environment: context,
191
- sequential: true,
192
- order: "post",
193
- result: "merge",
194
- asNextParam
195
- }, types);
196
- if (result) {
197
- if (isSetObject(result)) {
198
- types = result.code;
199
- if (Array.isArray(result.directives) && result.directives.length > 0) directives.push(...result.directives);
200
- } else if (isSetString(result)) types = result;
201
- }
202
- if (types?.trim() || directives.length > 0) await context.fs.write(context.dtsPath, `${directives ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
203
-
204
- ` : ""}${getFileHeader(context, {
205
- directive: null,
206
- prettierIgnore: false
207
- })}
208
-
209
- ${formatTypes(types)}
210
- `);
211
- else {
212
- const dtsRelativePath = getTsconfigDtsPath(context);
213
- if (context.tsconfig.tsconfigJson.include && isIncludeMatchFound(dtsRelativePath, context.tsconfig.tsconfigJson.include)) {
214
- const normalizedDtsRelativePath = dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath;
215
- context.tsconfig.tsconfigJson.include = context.tsconfig.tsconfigJson.include.filter((includeValue) => includeValue?.toString() !== normalizedDtsRelativePath);
216
- await context.fs.write(context.tsconfig.tsconfigFilePath, JSON.stringify(context.tsconfig.tsconfigJson, null, 2));
217
- }
218
- }
219
- }
220
- context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
221
- if (!context.tsconfig) throw new Error("Failed to parse the TypeScript configuration file.");
222
- await this.callHook("prepare", {
223
- environment: context,
224
- order: "post"
225
- });
226
- await writeMetaFile(context);
227
- context.persistedMeta = context.meta;
228
- });
229
- this.context.log(LogLevelLabel.INFO, "Powerlines API has been prepared successfully");
230
- }
231
- /**
232
- * Create a new Powerlines project
233
- *
234
- * @remarks
235
- * This method will create a new Powerlines project in the current directory.
236
- *
237
- * @param inlineConfig - The inline configuration for the new command
238
- * @returns A promise that resolves when the project has been created
239
- */
240
- async new(inlineConfig) {
241
- this.context.log(LogLevelLabel.INFO, "🆕 Creating a new Powerlines project");
242
- await this.prepare(inlineConfig);
243
- await this.#executeEnvironments(async (context) => {
244
- context.log(LogLevelLabel.TRACE, `Initializing the processing options for the Powerlines project.`);
245
- await this.callHook("new", {
246
- environment: context,
247
- order: "pre"
248
- });
249
- const files = await listFiles(joinPaths(context.powerlinesPath, "files/common/**/*.hbs"));
250
- for (const file of files) {
251
- context.log(LogLevelLabel.TRACE, `Adding template file: ${file}`);
252
- const template = Handlebars.compile(file);
253
- await context.fs.write(joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
254
- }
255
- await this.callHook("new", {
256
- environment: context,
257
- order: "normal"
258
- });
259
- if (context.config.projectType === "application") {
260
- const files$1 = await listFiles(joinPaths(context.powerlinesPath, "files/application/**/*.hbs"));
261
- for (const file of files$1) {
262
- context.log(LogLevelLabel.TRACE, `Adding application template file: ${file}`);
263
- const template = Handlebars.compile(file);
264
- await context.fs.write(joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
265
- }
266
- } else {
267
- const files$1 = await listFiles(joinPaths(context.powerlinesPath, "files/library/**/*.hbs"));
268
- for (const file of files$1) {
269
- context.log(LogLevelLabel.TRACE, `Adding library template file: ${file}`);
270
- const template = Handlebars.compile(file);
271
- await context.fs.write(joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
272
- }
273
- }
274
- await this.callHook("new", {
275
- environment: context,
276
- order: "post"
277
- });
278
- });
279
- this.context.log(LogLevelLabel.TRACE, "Powerlines - New command completed");
280
- }
281
- /**
282
- * Clean any previously prepared artifacts
283
- *
284
- * @remarks
285
- * This method will remove the previous Powerlines artifacts from the project.
286
- *
287
- * @param inlineConfig - The inline configuration for the clean command
288
- * @returns A promise that resolves when the clean command has completed
289
- */
290
- async clean(inlineConfig = { command: "clean" }) {
291
- this.context.log(LogLevelLabel.INFO, "🧹 Cleaning the previous Powerlines artifacts");
292
- await this.prepare(inlineConfig);
293
- await this.#executeEnvironments(async (context) => {
294
- this.context.log(LogLevelLabel.TRACE, "Cleaning the project's dist and artifacts directories.");
295
- await context.fs.remove(joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.buildPath));
296
- await context.fs.remove(joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.artifactsPath));
297
- await this.callHook("clean", {
298
- environment: context,
299
- sequential: false
300
- });
301
- });
302
- this.context.log(LogLevelLabel.TRACE, "Powerlines - Clean command completed");
303
- }
304
- /**
305
- * Lint the project
306
- *
307
- * @param inlineConfig - The inline configuration for the lint command
308
- * @returns A promise that resolves when the lint command has completed
309
- */
310
- async lint(inlineConfig = { command: "lint" }) {
311
- this.context.log(LogLevelLabel.INFO, "📋 Linting the Powerlines project");
312
- await this.prepare(inlineConfig);
313
- await this.#executeEnvironments(async (context) => {
314
- if (context.config.lint !== false) await this.callHook("lint", {
315
- environment: context,
316
- sequential: false
317
- });
318
- });
319
- this.context.log(LogLevelLabel.TRACE, "Powerlines linting completed");
320
- }
321
- /**
322
- * Build the project
323
- *
324
- * @remarks
325
- * This method will build the Powerlines project, generating the necessary artifacts.
326
- *
327
- * @param inlineConfig - The inline configuration for the build command
328
- * @returns A promise that resolves when the build command has completed
329
- */
330
- async build(inlineConfig = { command: "build" }) {
331
- this.context.log(LogLevelLabel.INFO, "📦 Building the Powerlines project");
332
- await this.prepare(inlineConfig);
333
- if (this.context.config.singleBuild) await this.#handleBuild(await this.#context.toEnvironment());
334
- else await this.#executeEnvironments(async (context) => {
335
- await this.#handleBuild(context);
336
- });
337
- this.context.log(LogLevelLabel.TRACE, "Powerlines build completed");
338
- }
339
- /**
340
- * Prepare the documentation for the project
341
- *
342
- * @param inlineConfig - The inline configuration for the docs command
343
- * @returns A promise that resolves when the documentation generation has completed
344
- */
345
- async docs(inlineConfig = { command: "docs" }) {
346
- this.context.log(LogLevelLabel.INFO, "📓 Generating documentation for the Powerlines project");
347
- await this.prepare(inlineConfig);
348
- await this.#executeEnvironments(async (context) => {
349
- context.log(LogLevelLabel.TRACE, "Writing documentation for the Powerlines project artifacts.");
350
- await this.prepare(inlineConfig);
351
- await this.#executeEnvironments(async (context$1) => {
352
- await this.callHook("docs", { environment: context$1 });
353
- });
354
- });
355
- this.#context.log(LogLevelLabel.TRACE, "Powerlines documentation generation completed");
356
- }
357
- /**
358
- * Deploy the project source code
359
- *
360
- * @remarks
361
- * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
362
- *
363
- * @param inlineConfig - The inline configuration for the deploy command
364
- */
365
- async deploy(inlineConfig = { command: "deploy" }) {
366
- this.context.log(LogLevelLabel.INFO, "📦 Deploying the Powerlines project");
367
- await this.prepare(inlineConfig);
368
- await this.#executeEnvironments(async (context) => {
369
- await this.callHook("deploy", { environment: context });
370
- });
371
- this.context.log(LogLevelLabel.TRACE, "Powerlines deploy completed");
372
- }
373
- /**
374
- * Finalization process
375
- *
376
- * @remarks
377
- * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
378
- *
379
- * @returns A promise that resolves when the finalization process has completed
380
- */
381
- async finalize() {
382
- this.context.log(LogLevelLabel.TRACE, "Powerlines finalize execution started");
383
- await this.#executeEnvironments(async (context) => {
384
- await this.callHook("finalize", { environment: context });
385
- await context.fs.dispose();
386
- });
387
- this.context.log(LogLevelLabel.TRACE, "Powerlines finalize execution completed");
388
- }
389
- /**
390
- * Invokes the configured plugin hooks
391
- *
392
- * @remarks
393
- * By default, it will call the `"pre"`, `"normal"`, and `"post"` ordered hooks in sequence
394
- *
395
- * @param hook - The hook to call
396
- * @param options - The options to provide to the hook
397
- * @param args - The arguments to pass to the hook
398
- * @returns The result of the hook call
399
- */
400
- async callHook(hook, options, ...args) {
401
- return callHook(isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
402
- sequential: true,
403
- ...options
404
- }, ...args);
405
- }
406
- /**
407
- * Dispose of the Powerlines API instance
408
- *
409
- * @remarks
410
- * This method will finalize the Powerlines API instance, cleaning up any resources used.
411
- */
412
- async [Symbol.asyncDispose]() {
413
- await this.finalize();
414
- }
415
- async #handleBuild(context) {
416
- await this.callHook("build", {
417
- environment: context,
418
- order: "pre"
419
- });
420
- await this.callHook("build", {
421
- environment: context,
422
- order: "normal"
423
- });
424
- if (context.config.output.buildPath !== context.config.output.outputPath) {
425
- const sourcePath = appendPath(context.config.output.buildPath, context.workspaceConfig.workspaceRoot);
426
- const destinationPath = joinPaths(appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot), "dist");
427
- if (context.fs.existsSync(sourcePath) && sourcePath !== destinationPath) {
428
- context.log(LogLevelLabel.INFO, `Copying build output files from project's build directory (${context.config.output.buildPath}) to the workspace's output directory (${context.config.output.outputPath}).`);
429
- await context.fs.copy(sourcePath, destinationPath);
430
- }
431
- }
432
- await Promise.all(context.config.output.assets.map(async (asset) => {
433
- context.log(LogLevelLabel.DEBUG, `Copying asset(s): ${chalk.redBright(context.workspaceConfig.workspaceRoot === asset.input ? asset.glob : joinPaths(replacePath(asset.input, context.workspaceConfig.workspaceRoot), asset.glob))} -> ${chalk.greenBright(joinPaths(replacePath(asset.output, context.workspaceConfig.workspaceRoot), asset.glob))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk.yellowBright(i)).join(", ")})` : ""}`);
434
- await context.fs.copy(asset, asset.output);
435
- }));
436
- await this.callHook("build", {
437
- environment: context,
438
- order: "post"
439
- });
440
- }
441
- /**
442
- * Get the configured environments
443
- *
444
- * @returns The configured environments
445
- */
446
- async #getEnvironments() {
447
- if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
448
- this.context.log(LogLevelLabel.DEBUG, "No environments are configured for this Powerlines project. Using the default environment.");
449
- return [await this.context.getEnvironment()];
450
- }
451
- this.context.log(LogLevelLabel.DEBUG, `Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
452
- return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
453
- if (!await this.context.getEnvironmentSafe(name)) {
454
- const resolvedEnvironment = await this.callHook("configEnvironment", { environment: name }, name, config);
455
- if (resolvedEnvironment) this.context.environments[name] = await this.context.in(resolvedEnvironment);
456
- }
457
- return this.context.environments[name];
458
- }))).filter((context) => isSet(context));
459
- }
460
- /**
461
- * Execute a handler function for each environment
462
- *
463
- * @param handle - The handler function to execute for each environment
464
- */
465
- async #executeEnvironments(handle) {
466
- await Promise.all((await this.#getEnvironments()).map(async (context) => {
467
- return Promise.resolve(handle(context));
468
- }));
469
- }
470
- /**
471
- * Add a Powerlines plugin used in the build process
472
- *
473
- * @param config - The import path of the plugin to add
474
- */
475
- async #addPlugin(config) {
476
- if (config) {
477
- const result = await this.#initPlugin(config);
478
- if (!result) return;
479
- for (const plugin of result) {
480
- this.context.log(LogLevelLabel.DEBUG, `Successfully initialized the ${chalk.bold.cyanBright(plugin.name)} plugin`);
481
- await this.context.addPlugin(plugin);
482
- }
483
- }
484
- }
485
- /**
486
- * Initialize a Powerlines plugin
487
- *
488
- * @param config - The configuration for the plugin
489
- * @returns The initialized plugin instance, or null if the plugin was a duplicate
490
- * @throws Will throw an error if the plugin cannot be found or is invalid
491
- */
492
- async #initPlugin(config) {
493
- let awaited = config;
494
- if (isPromiseLike(config)) awaited = await Promise.resolve(config);
495
- if (!isPluginConfig(awaited)) {
496
- const invalid = findInvalidPluginConfig(awaited);
497
- 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`);
498
- }
499
- let plugins;
500
- if (isPlugin(awaited)) plugins = [awaited];
501
- else if (isFunction(awaited)) plugins = toArray(await Promise.resolve(awaited()));
502
- else if (isString(awaited)) {
503
- const resolved = await this.#resolvePlugin(awaited);
504
- if (isFunction(resolved)) plugins = toArray(await Promise.resolve(resolved()));
505
- else plugins = toArray(resolved);
506
- } else if (Array.isArray(awaited) && awaited.every(isPlugin)) plugins = awaited;
507
- else if (Array.isArray(awaited) && awaited.every(isPluginConfig)) {
508
- plugins = [];
509
- for (const pluginConfig of awaited) {
510
- const initialized = await this.#initPlugin(pluginConfig);
511
- if (initialized) plugins.push(...initialized);
512
- }
513
- } else if (isPluginConfigTuple(awaited) || isPluginConfigObject(awaited)) {
514
- let pluginConfig;
515
- let pluginOptions;
516
- if (isPluginConfigTuple(awaited)) {
517
- pluginConfig = awaited[0];
518
- pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
519
- } else {
520
- pluginConfig = awaited.plugin;
521
- pluginOptions = awaited.options;
522
- }
523
- if (isSetString(pluginConfig)) {
524
- const resolved = await this.#resolvePlugin(pluginConfig);
525
- if (isFunction(resolved)) plugins = toArray(await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved()));
526
- else plugins = toArray(resolved);
527
- } else if (isFunction(pluginConfig)) plugins = toArray(await Promise.resolve(pluginConfig(pluginOptions)));
528
- else if (Array.isArray(pluginConfig) && pluginConfig.every(isPlugin)) plugins = pluginConfig;
529
- else if (isPlugin(pluginConfig)) plugins = toArray(pluginConfig);
530
- }
531
- if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
532
- if (plugins.length > 0 && !plugins.every(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.`);
533
- const result = [];
534
- for (const plugin of plugins) if (checkDedupe(plugin, this.context.plugins)) this.context.log(LogLevelLabel.TRACE, `Duplicate ${chalk.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
535
- else {
536
- result.push(plugin);
537
- this.context.log(LogLevelLabel.TRACE, `Initializing the ${chalk.bold.cyanBright(plugin.name)} plugin...`);
538
- }
539
- return result;
540
- }
541
- async #resolvePlugin(pluginPath) {
542
- if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
543
- const splits = pluginPath.split("/").filter(Boolean);
544
- pluginPath = `${splits[0]}/${splits[1]}`;
545
- }
546
- const isInstalled = isPackageExists(pluginPath, { paths: [this.context.workspaceConfig.workspaceRoot, this.context.config.projectRoot] });
547
- if (!isInstalled && this.context.config.skipInstalls !== true) {
548
- this.#context.log(LogLevelLabel.WARN, `The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
549
- const result = await install(pluginPath, { cwd: this.context.config.projectRoot });
550
- if (isNumber(result.exitCode) && result.exitCode > 0) {
551
- this.#context.log(LogLevelLabel.ERROR, result.stderr);
552
- throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
553
- }
554
- }
555
- try {
556
- const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(joinPaths(pluginPath, "plugin")));
557
- const result = module.plugin ?? module.default;
558
- if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
559
- return result;
560
- } catch (error) {
561
- try {
562
- const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
563
- const result = module.plugin ?? module.default;
564
- if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
565
- return result;
566
- } catch {
567
- if (!isInstalled) throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
568
- else throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
569
- ${isError(error) ? error.message : String(error)}
570
-
571
- 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\`.`);
572
- }
573
- }
574
- }
575
- };
576
-
577
- //#endregion
578
- export { };
@@ -1,86 +0,0 @@
1
- const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
- let __babel_helper_plugin_utils = require("@babel/helper-plugin-utils");
3
- let __babel_types = require("@babel/types");
4
- __babel_types = require_rolldown_runtime.__toESM(__babel_types);
5
-
6
- //#region ../powerlines/src/internal/babel/module-resolver-plugin.ts
7
- function resolveModulePath(nodePath, state) {
8
- if (!__babel_types.isStringLiteral(nodePath.node)) return;
9
- const resolvedPath = state.context?.fs.resolveSync(nodePath.node.value);
10
- if (resolvedPath) nodePath.replaceWith(__babel_types.stringLiteral(resolvedPath.replace(/\.(?:ts|mts|cts)x?$/, "")));
11
- }
12
- const TRANSFORM_FUNCTIONS = [
13
- "require",
14
- "require.resolve",
15
- "System.import",
16
- "jest.genMockFromModule",
17
- "jest.mock",
18
- "jest.unmock",
19
- "jest.doMock",
20
- "jest.dontMock",
21
- "jest.setMock",
22
- "jest.requireActual",
23
- "jest.requireMock",
24
- "require.requireActual",
25
- "require.requireMock"
26
- ];
27
- function matchesPattern(state, calleePath, pattern) {
28
- const { node } = calleePath;
29
- if (__babel_types.isMemberExpression(node)) return calleePath.matchesPattern(pattern);
30
- if (!__babel_types.isIdentifier(node) || pattern.includes(".")) return false;
31
- const name = pattern.split(".")[0];
32
- return node.name === name;
33
- }
34
- const importVisitors = {
35
- CallExpression: (nodePath, state) => {
36
- if (state.moduleResolverVisited.has(nodePath)) return;
37
- const calleePath = nodePath.get("callee");
38
- if (calleePath && TRANSFORM_FUNCTIONS.some((pattern) => matchesPattern(state, calleePath, pattern)) || __babel_types.isImport(nodePath.node.callee)) {
39
- state.moduleResolverVisited.add(nodePath);
40
- resolveModulePath(nodePath.get("arguments.0"), state);
41
- }
42
- },
43
- "ImportDeclaration|ExportDeclaration|ExportAllDeclaration": (nodePath, state) => {
44
- if (!nodePath || !nodePath.get("source") || state.moduleResolverVisited.has(nodePath)) return;
45
- state.moduleResolverVisited.add(nodePath);
46
- resolveModulePath(nodePath.get("source"), state);
47
- }
48
- };
49
- const moduleResolverBabelPlugin = (context) => {
50
- return (0, __babel_helper_plugin_utils.declare)(function builder(api) {
51
- let moduleResolverVisited = /* @__PURE__ */ new Set();
52
- return {
53
- name: "powerlines:module-resolver",
54
- manipulateOptions(opts) {
55
- opts.filename ??= "unknown";
56
- },
57
- pre() {
58
- moduleResolverVisited = /* @__PURE__ */ new Set();
59
- },
60
- visitor: { Program: {
61
- enter(programPath, state) {
62
- programPath.traverse(importVisitors, {
63
- ...state,
64
- context,
65
- moduleResolverVisited,
66
- api
67
- });
68
- },
69
- exit(programPath, state) {
70
- programPath.traverse(importVisitors, {
71
- ...state,
72
- context,
73
- moduleResolverVisited,
74
- api
75
- });
76
- }
77
- } },
78
- post() {
79
- moduleResolverVisited.clear();
80
- }
81
- };
82
- });
83
- };
84
-
85
- //#endregion
86
- exports.moduleResolverBabelPlugin = moduleResolverBabelPlugin;