@powerlines/plugin-webpack 0.5.132 → 0.5.134

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/_virtual/rolldown_runtime.cjs +29 -0
  2. package/dist/helpers/index.cjs +2 -3
  3. package/dist/helpers/index.d.cts +1 -3
  4. package/dist/helpers/index.d.mts +1 -3
  5. package/dist/helpers/index.mjs +1 -2
  6. package/dist/helpers/unplugin.cjs +11 -2
  7. package/dist/helpers/unplugin.d.cts +6 -2
  8. package/dist/helpers/unplugin.d.mts +6 -2
  9. package/dist/helpers/unplugin.mjs +9 -1
  10. package/dist/index.cjs +8 -50
  11. package/dist/index.d.cts +3 -4
  12. package/dist/index.d.mts +5 -5
  13. package/dist/index.mjs +3 -46
  14. package/dist/powerlines/schemas/fs.cjs +226 -0
  15. package/dist/powerlines/schemas/fs.mjs +224 -0
  16. package/dist/powerlines/src/api.cjs +580 -0
  17. package/dist/powerlines/src/api.mjs +578 -0
  18. package/dist/powerlines/src/internal/babel/module-resolver-plugin.cjs +86 -0
  19. package/dist/powerlines/src/internal/babel/module-resolver-plugin.mjs +84 -0
  20. package/dist/powerlines/src/internal/helpers/environment.cjs +52 -0
  21. package/dist/powerlines/src/internal/helpers/environment.mjs +48 -0
  22. package/dist/powerlines/src/internal/helpers/generate-types.cjs +51 -0
  23. package/dist/powerlines/src/internal/helpers/generate-types.mjs +49 -0
  24. package/dist/powerlines/src/internal/helpers/hooks.cjs +63 -0
  25. package/dist/powerlines/src/internal/helpers/hooks.mjs +61 -0
  26. package/dist/powerlines/src/internal/helpers/install-dependencies.cjs +25 -0
  27. package/dist/powerlines/src/internal/helpers/install-dependencies.mjs +24 -0
  28. package/dist/powerlines/src/internal/helpers/install.cjs +37 -0
  29. package/dist/powerlines/src/internal/helpers/install.mjs +36 -0
  30. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.cjs +98 -0
  31. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.mjs +94 -0
  32. package/dist/powerlines/src/internal/helpers/resolver.cjs +43 -0
  33. package/dist/powerlines/src/internal/helpers/resolver.mjs +41 -0
  34. package/dist/powerlines/src/lib/build/webpack.cjs +47 -0
  35. package/dist/powerlines/src/lib/build/webpack.mjs +45 -0
  36. package/dist/powerlines/src/lib/config-file.cjs +79 -0
  37. package/dist/powerlines/src/lib/config-file.mjs +76 -0
  38. package/dist/powerlines/src/lib/contexts/api-context.cjs +184 -0
  39. package/dist/powerlines/src/lib/contexts/api-context.mjs +182 -0
  40. package/dist/powerlines/src/lib/contexts/context.cjs +933 -0
  41. package/dist/powerlines/src/lib/contexts/context.mjs +931 -0
  42. package/dist/powerlines/src/lib/contexts/environment-context.cjs +160 -0
  43. package/dist/powerlines/src/lib/contexts/environment-context.mjs +159 -0
  44. package/dist/powerlines/src/lib/contexts/plugin-context.cjs +75 -0
  45. package/dist/powerlines/src/lib/contexts/plugin-context.mjs +74 -0
  46. package/dist/powerlines/src/lib/entry.cjs +69 -0
  47. package/dist/powerlines/src/lib/entry.mjs +67 -0
  48. package/dist/powerlines/src/lib/fs/helpers.cjs +85 -0
  49. package/dist/powerlines/src/lib/fs/helpers.mjs +81 -0
  50. package/dist/powerlines/src/lib/fs/storage/base.cjs +196 -0
  51. package/dist/powerlines/src/lib/fs/storage/base.mjs +195 -0
  52. package/dist/powerlines/src/lib/fs/storage/file-system.cjs +170 -0
  53. package/dist/powerlines/src/lib/fs/storage/file-system.mjs +169 -0
  54. package/dist/powerlines/src/lib/fs/storage/virtual.cjs +88 -0
  55. package/dist/powerlines/src/lib/fs/storage/virtual.mjs +87 -0
  56. package/dist/powerlines/src/lib/fs/vfs.cjs +830 -0
  57. package/dist/powerlines/src/lib/fs/vfs.mjs +828 -0
  58. package/dist/powerlines/src/lib/logger.cjs +58 -0
  59. package/dist/powerlines/src/lib/logger.mjs +55 -0
  60. package/dist/powerlines/src/lib/typescript/ts-morph.cjs +104 -0
  61. package/dist/powerlines/src/lib/typescript/ts-morph.mjs +102 -0
  62. package/dist/powerlines/src/lib/typescript/tsconfig.cjs +149 -0
  63. package/dist/powerlines/src/lib/typescript/tsconfig.mjs +144 -0
  64. package/dist/powerlines/src/lib/unplugin/factory.cjs +6 -0
  65. package/dist/powerlines/src/lib/unplugin/factory.mjs +8 -0
  66. package/dist/powerlines/src/lib/unplugin/helpers.cjs +17 -0
  67. package/dist/powerlines/src/lib/unplugin/helpers.mjs +16 -0
  68. package/dist/powerlines/src/lib/unplugin/index.cjs +3 -0
  69. package/dist/powerlines/src/lib/unplugin/index.mjs +5 -0
  70. package/dist/powerlines/src/lib/unplugin/plugin.cjs +128 -0
  71. package/dist/powerlines/src/lib/unplugin/plugin.mjs +127 -0
  72. package/dist/powerlines/src/lib/utilities/file-header.cjs +22 -0
  73. package/dist/powerlines/src/lib/utilities/file-header.mjs +21 -0
  74. package/dist/powerlines/src/lib/utilities/meta.cjs +45 -0
  75. package/dist/powerlines/src/lib/utilities/meta.mjs +41 -0
  76. package/dist/powerlines/src/lib/utilities/source-file.cjs +22 -0
  77. package/dist/powerlines/src/lib/utilities/source-file.mjs +21 -0
  78. package/dist/powerlines/src/plugin-utils/helpers.cjs +148 -0
  79. package/dist/powerlines/src/plugin-utils/helpers.mjs +138 -0
  80. package/dist/powerlines/src/plugin-utils/paths.cjs +36 -0
  81. package/dist/powerlines/src/plugin-utils/paths.mjs +35 -0
  82. package/dist/powerlines/src/types/babel.d.mts +4 -0
  83. package/dist/powerlines/src/types/build.cjs +15 -0
  84. package/dist/powerlines/src/types/build.d.cts +149 -0
  85. package/dist/powerlines/src/types/build.d.mts +149 -0
  86. package/dist/powerlines/src/types/build.mjs +14 -0
  87. package/dist/powerlines/src/types/commands.cjs +16 -0
  88. package/dist/powerlines/src/types/commands.d.cts +8 -0
  89. package/dist/powerlines/src/types/commands.d.mts +9 -0
  90. package/dist/powerlines/src/types/commands.mjs +15 -0
  91. package/dist/powerlines/src/types/config.d.cts +377 -0
  92. package/dist/powerlines/src/types/config.d.mts +379 -0
  93. package/dist/powerlines/src/types/context.d.cts +403 -0
  94. package/dist/powerlines/src/types/context.d.mts +405 -0
  95. package/dist/powerlines/src/types/fs.d.cts +486 -0
  96. package/dist/powerlines/src/types/fs.d.mts +486 -0
  97. package/dist/powerlines/src/types/hooks.d.mts +2 -0
  98. package/dist/powerlines/src/types/plugin.cjs +32 -0
  99. package/dist/powerlines/src/types/plugin.d.cts +231 -0
  100. package/dist/powerlines/src/types/plugin.d.mts +231 -0
  101. package/dist/powerlines/src/types/plugin.mjs +31 -0
  102. package/dist/powerlines/src/types/resolved.d.cts +82 -0
  103. package/dist/powerlines/src/types/resolved.d.mts +83 -0
  104. package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
  105. package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
  106. package/dist/types/index.cjs +0 -2
  107. package/dist/types/index.d.cts +1 -2
  108. package/dist/types/index.d.mts +1 -2
  109. package/dist/types/index.mjs +0 -3
  110. package/dist/types/plugin.cjs +0 -1
  111. package/dist/types/plugin.d.cts +12 -1
  112. package/dist/types/plugin.d.mts +12 -1
  113. package/dist/types/plugin.mjs +0 -2
  114. package/package.json +5 -5
  115. package/dist/helpers-B15z10jN.mjs +0 -1
  116. package/dist/helpers-LF26RHol.cjs +0 -0
  117. package/dist/index-9iG2qHLe.d.mts +0 -1
  118. package/dist/index-D4ELpJXS.d.cts +0 -1
  119. package/dist/index-D6CnpA_r.d.cts +0 -1
  120. package/dist/index-DL0uimUT.d.mts +0 -1
  121. package/dist/plugin-C5bG6Zu0.d.mts +0 -1772
  122. package/dist/plugin-Cl1J-dKa.d.cts +0 -1769
  123. package/dist/plugin-ifZVa20V.mjs +0 -1
  124. package/dist/plugin-pBKbb5K9.cjs +0 -0
  125. package/dist/types-U3zd8PTP.mjs +0 -1
  126. package/dist/types-o3zWarRp.cjs +0 -0
  127. package/dist/unplugin-Bo9KoKSB.d.cts +0 -7
  128. package/dist/unplugin-Ct4wZxE5.d.mts +0 -7
  129. package/dist/unplugin-GJmHohOE.mjs +0 -4617
  130. package/dist/unplugin-bKYETUU8.cjs +0 -4661
@@ -0,0 +1,94 @@
1
+ import { getParsedTypeScriptConfig, getTsconfigFilePath, isIncludeMatchFound } from "../../lib/typescript/tsconfig.mjs";
2
+ import { LogLevelLabel } from "@storm-software/config-tools/types";
3
+ import { joinPaths } from "@stryke/path/join-paths";
4
+ import { isPackageExists } from "@stryke/fs/package-fns";
5
+ import chalk from "chalk";
6
+ import { getObjectDiff } from "@donedeal0/superdiff";
7
+ import { readJsonFile } from "@stryke/fs/json";
8
+ import { StormJSON } from "@stryke/json/storm-json";
9
+ import { findFileName, findFilePath, relativePath } from "@stryke/path/file-path-fns";
10
+ import { titleCase } from "@stryke/string-format/title-case";
11
+
12
+ //#region ../powerlines/src/internal/helpers/resolve-tsconfig.ts
13
+ function getTsconfigDtsPath(context) {
14
+ return joinPaths(relativePath(joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot), findFilePath(context.dtsPath)), findFileName(context.dtsPath));
15
+ }
16
+ async function resolveTsconfigChanges(context) {
17
+ const tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw);
18
+ const tsconfigJson = await readJsonFile(getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig));
19
+ tsconfigJson.compilerOptions ??= {};
20
+ if (context.config.output.dts !== false) {
21
+ const dtsRelativePath = getTsconfigDtsPath(context);
22
+ if (!tsconfigJson.include?.some((filePattern) => isIncludeMatchFound(filePattern, [context.dtsPath, dtsRelativePath]))) {
23
+ tsconfigJson.include ??= [];
24
+ tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
25
+ }
26
+ }
27
+ if (!tsconfig.options.lib?.some((lib) => [
28
+ "lib.esnext.d.ts",
29
+ "lib.es2021.d.ts",
30
+ "lib.es2022.d.ts",
31
+ "lib.es2023.d.ts"
32
+ ].includes(lib.toLowerCase()))) {
33
+ tsconfigJson.compilerOptions.lib ??= [];
34
+ tsconfigJson.compilerOptions.lib.push("esnext");
35
+ }
36
+ if (tsconfig.options.esModuleInterop !== true) tsconfigJson.compilerOptions.esModuleInterop = true;
37
+ if (tsconfig.options.isolatedModules !== true) tsconfigJson.compilerOptions.isolatedModules = true;
38
+ if (context.config.build.platform === "node") {
39
+ if (!tsconfig.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
40
+ tsconfigJson.compilerOptions.types ??= [];
41
+ tsconfigJson.compilerOptions.types.push("node");
42
+ }
43
+ }
44
+ return tsconfigJson;
45
+ }
46
+ async function initializeTsconfig(context) {
47
+ context.log(LogLevelLabel.TRACE, "Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
48
+ if (!isPackageExists("typescript")) throw new Error("The TypeScript package is not installed. Please install the package using the command: \"npm install typescript --save-dev\"");
49
+ const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
50
+ context.tsconfig.originalTsconfigJson = await readJsonFile(tsconfigFilePath);
51
+ context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
52
+ context.log(LogLevelLabel.TRACE, "Writing updated TypeScript configuration (tsconfig.json) file to disk.");
53
+ await context.fs.write(tsconfigFilePath, StormJSON.stringify(context.tsconfig.tsconfigJson));
54
+ context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
55
+ }
56
+ async function resolveTsconfig(context) {
57
+ const updateTsconfigJson = await readJsonFile(context.tsconfig.tsconfigFilePath);
58
+ if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) delete updateTsconfigJson.compilerOptions.types;
59
+ const result = getObjectDiff(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
60
+ ignoreArrayOrder: true,
61
+ showOnly: {
62
+ statuses: [
63
+ "added",
64
+ "deleted",
65
+ "updated"
66
+ ],
67
+ granularity: "deep"
68
+ }
69
+ });
70
+ const changes = [];
71
+ const getChanges = (difference, property) => {
72
+ 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);
73
+ else changes.push({
74
+ field: property ? `${property}.${difference.property}` : difference.property,
75
+ status: difference.status,
76
+ previous: difference.status === "added" ? "---" : StormJSON.stringify(difference.previousValue),
77
+ current: difference.status === "deleted" ? "---" : StormJSON.stringify(difference.currentValue)
78
+ });
79
+ };
80
+ for (const diff of result.diff) getChanges(diff);
81
+ if (changes.length > 0) context.log(LogLevelLabel.WARN, `Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
82
+
83
+ ${changes.map((change, i) => `${chalk.bold.whiteBright(`${i + 1}. ${titleCase(change.status)} the ${change.field} field: `)}
84
+ ${chalk.red(` - Previous: ${change.previous} `)}
85
+ ${chalk.green(` - Updated: ${change.current} `)}
86
+ `).join("\n")}
87
+ `);
88
+ await context.fs.write(context.tsconfig.tsconfigFilePath, StormJSON.stringify(updateTsconfigJson));
89
+ context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
90
+ if (!context.tsconfig) throw new Error("Failed to parse the TypeScript configuration file.");
91
+ }
92
+
93
+ //#endregion
94
+ export { getTsconfigDtsPath, initializeTsconfig, resolveTsconfig };
@@ -0,0 +1,43 @@
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ let defu = require("defu");
3
+ defu = require_rolldown_runtime.__toESM(defu);
4
+ let __stryke_path_join_paths = require("@stryke/path/join-paths");
5
+ let jiti = require("jiti");
6
+
7
+ //#region ../powerlines/src/internal/helpers/resolver.ts
8
+ /**
9
+ * Create a Jiti resolver for the given workspace and project root.
10
+ *
11
+ * @param options - The options for creating the resolver.
12
+ * @returns A Jiti instance configured for the specified workspace and project root.
13
+ */
14
+ function resolveOptions(options) {
15
+ return (0, defu.default)(options, {
16
+ interopDefault: true,
17
+ fsCache: options.mode !== "development" ? (0, __stryke_path_join_paths.joinPaths)(options.cacheDir, "jiti") : false,
18
+ moduleCache: options.mode !== "development"
19
+ });
20
+ }
21
+ /**
22
+ * Create a Jiti resolver for the given workspace and project root.
23
+ *
24
+ * @param options - The options for creating the resolver.
25
+ * @returns A Jiti instance configured for the specified workspace and project root.
26
+ */
27
+ function createPluginResolver(options) {
28
+ return (0, jiti.createJiti)((0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, options.projectRoot), resolveOptions({ ...options }));
29
+ }
30
+ /**
31
+ * Create a Jiti resolver for the given workspace and project root.
32
+ *
33
+ * @param options - The options for creating the resolver.
34
+ * @returns A Jiti instance configured for the specified workspace and project root.
35
+ */
36
+ function createResolver(options) {
37
+ const baseResolver = (0, jiti.createJiti)((0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, options.projectRoot), resolveOptions(options));
38
+ baseResolver.plugin = createPluginResolver(options);
39
+ return baseResolver;
40
+ }
41
+
42
+ //#endregion
43
+ exports.createResolver = createResolver;
@@ -0,0 +1,41 @@
1
+ import defu$1 from "defu";
2
+ import { joinPaths } from "@stryke/path/join-paths";
3
+ import { createJiti } from "jiti";
4
+
5
+ //#region ../powerlines/src/internal/helpers/resolver.ts
6
+ /**
7
+ * Create a Jiti resolver for the given workspace and project root.
8
+ *
9
+ * @param options - The options for creating the resolver.
10
+ * @returns A Jiti instance configured for the specified workspace and project root.
11
+ */
12
+ function resolveOptions(options) {
13
+ return defu$1(options, {
14
+ interopDefault: true,
15
+ fsCache: options.mode !== "development" ? joinPaths(options.cacheDir, "jiti") : false,
16
+ moduleCache: options.mode !== "development"
17
+ });
18
+ }
19
+ /**
20
+ * Create a Jiti resolver for the given workspace and project root.
21
+ *
22
+ * @param options - The options for creating the resolver.
23
+ * @returns A Jiti instance configured for the specified workspace and project root.
24
+ */
25
+ function createPluginResolver(options) {
26
+ return createJiti(joinPaths(options.workspaceRoot, options.projectRoot), resolveOptions({ ...options }));
27
+ }
28
+ /**
29
+ * Create a Jiti resolver for the given workspace and project root.
30
+ *
31
+ * @param options - The options for creating the resolver.
32
+ * @returns A Jiti instance configured for the specified workspace and project root.
33
+ */
34
+ function createResolver(options) {
35
+ const baseResolver = createJiti(joinPaths(options.workspaceRoot, options.projectRoot), resolveOptions(options));
36
+ baseResolver.plugin = createPluginResolver(options);
37
+ return baseResolver;
38
+ }
39
+
40
+ //#endregion
41
+ export { createResolver };
@@ -0,0 +1,47 @@
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ let defu = require("defu");
3
+ defu = require_rolldown_runtime.__toESM(defu);
4
+ let __stryke_helpers_omit = require("@stryke/helpers/omit");
5
+ let __stryke_path_join_paths = require("@stryke/path/join-paths");
6
+
7
+ //#region ../powerlines/src/lib/build/webpack.ts
8
+ /**
9
+ * Resolves the options for [webpack](https://webpack.js.org/).
10
+ *
11
+ * @param context - The build context.
12
+ * @returns The resolved options.
13
+ */
14
+ function extractWebpackConfig(context) {
15
+ return (0, defu.default)({ resolve: { alias: context.builtins.reduce((ret, id) => {
16
+ if (!ret[id]) {
17
+ const path = context.fs.ids[id];
18
+ if (path) ret[id] = path;
19
+ }
20
+ return ret;
21
+ }, context.config.build.alias ? Array.isArray(context.config.build.alias) ? context.config.build.alias.reduce((ret, alias) => {
22
+ if (!ret[alias.find.toString()]) ret[alias.find.toString()] = alias.replacement;
23
+ return ret;
24
+ }, {}) : context.config.build.alias : {}) } }, context.config.build.variant === "webpack" ? context.config.build.override : {}, context.config.build.variant === "webpack" ? (0, __stryke_helpers_omit.omit)(context.config.build, ["override", "variant"]) : {}, {
25
+ output: { path: (0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.output.buildPath) },
26
+ name: context.config.name,
27
+ node: context.config.build.platform === "node" ? {
28
+ __dirname: true,
29
+ __filename: true,
30
+ global: true
31
+ } : false,
32
+ mode: context.config.mode === "development" ? "development" : "production",
33
+ cache: {
34
+ type: "filesystem",
35
+ cacheDirectory: (0, __stryke_path_join_paths.joinPaths)(context.cachePath, "webpack", "cache")
36
+ },
37
+ recordsInputPath: (0, __stryke_path_join_paths.joinPaths)(context.cachePath, "webpack", ".webpack-records.json"),
38
+ recordsOutputPath: (0, __stryke_path_join_paths.joinPaths)(context.cachePath, "webpack", ".webpack-records.json"),
39
+ context: (0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.projectRoot),
40
+ noExternal: context.builtins,
41
+ devtool: context.config.mode !== "development" ? false : "source-map",
42
+ optimization: { minimize: context.config.mode !== "development" }
43
+ });
44
+ }
45
+
46
+ //#endregion
47
+ exports.extractWebpackConfig = extractWebpackConfig;
@@ -0,0 +1,45 @@
1
+ import defu$1 from "defu";
2
+ import { omit } from "@stryke/helpers/omit";
3
+ import { joinPaths } from "@stryke/path/join-paths";
4
+
5
+ //#region ../powerlines/src/lib/build/webpack.ts
6
+ /**
7
+ * Resolves the options for [webpack](https://webpack.js.org/).
8
+ *
9
+ * @param context - The build context.
10
+ * @returns The resolved options.
11
+ */
12
+ function extractWebpackConfig(context) {
13
+ return defu$1({ resolve: { alias: context.builtins.reduce((ret, id) => {
14
+ if (!ret[id]) {
15
+ const path = context.fs.ids[id];
16
+ if (path) ret[id] = path;
17
+ }
18
+ return ret;
19
+ }, context.config.build.alias ? Array.isArray(context.config.build.alias) ? context.config.build.alias.reduce((ret, alias) => {
20
+ if (!ret[alias.find.toString()]) ret[alias.find.toString()] = alias.replacement;
21
+ return ret;
22
+ }, {}) : context.config.build.alias : {}) } }, context.config.build.variant === "webpack" ? context.config.build.override : {}, context.config.build.variant === "webpack" ? omit(context.config.build, ["override", "variant"]) : {}, {
23
+ output: { path: joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.buildPath) },
24
+ name: context.config.name,
25
+ node: context.config.build.platform === "node" ? {
26
+ __dirname: true,
27
+ __filename: true,
28
+ global: true
29
+ } : false,
30
+ mode: context.config.mode === "development" ? "development" : "production",
31
+ cache: {
32
+ type: "filesystem",
33
+ cacheDirectory: joinPaths(context.cachePath, "webpack", "cache")
34
+ },
35
+ recordsInputPath: joinPaths(context.cachePath, "webpack", ".webpack-records.json"),
36
+ recordsOutputPath: joinPaths(context.cachePath, "webpack", ".webpack-records.json"),
37
+ context: joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot),
38
+ noExternal: context.builtins,
39
+ devtool: context.config.mode !== "development" ? false : "source-map",
40
+ optimization: { minimize: context.config.mode !== "development" }
41
+ });
42
+ }
43
+
44
+ //#endregion
45
+ export { extractWebpackConfig };
@@ -0,0 +1,79 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let defu = require("defu");
3
+ defu = require_rolldown_runtime.__toESM(defu);
4
+ let __stryke_path_join_paths = require("@stryke/path/join-paths");
5
+ let __stryke_path_append = require("@stryke/path/append");
6
+ let __stryke_path_replace = require("@stryke/path/replace");
7
+ let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
8
+ let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
9
+ let __stryke_fs_exists = require("@stryke/fs/exists");
10
+ let __storm_software_config_tools_get_config = require("@storm-software/config-tools/get-config");
11
+ let c12 = require("c12");
12
+
13
+ //#region ../powerlines/src/lib/config-file.ts
14
+ /**
15
+ * Loads the workspace configuration.
16
+ *
17
+ * @param workspaceRoot - The root directory of the workspace.
18
+ * @param cwd - The current working directory to start searching from.
19
+ * @returns A promise that resolves to the loaded workspace configuration.
20
+ */
21
+ async function loadWorkspaceConfig(workspaceRoot, cwd) {
22
+ return (0, defu.default)({ workspaceRoot }, await (0, __storm_software_config_tools_get_config.getWorkspaceConfig)(true, {
23
+ cwd,
24
+ workspaceRoot,
25
+ useDefault: true
26
+ }));
27
+ }
28
+ /**
29
+ * Loads the user configuration file for the project.
30
+ *
31
+ * @param projectRoot - The root directory of the project.
32
+ * @param workspaceRoot - The root directory of the workspace.
33
+ * @param jiti - An instance of Jiti to resolve modules from
34
+ * @param command - The {@link PowerlinesCommand} string associated with the current running process
35
+ * @param mode - The mode in which the project is running (default is "production").
36
+ * @param configFile - An optional path to a specific configuration file.
37
+ * @param framework - The framework name to use for default configuration file names.
38
+ * @returns A promise that resolves to the resolved user configuration.
39
+ */
40
+ async function loadUserConfigFile(projectRoot, workspaceRoot, jiti, command, mode = "production", configFile, framework = "powerlines") {
41
+ let resolvedUserConfig = {};
42
+ let resolvedUserConfigFile;
43
+ if (configFile) resolvedUserConfigFile = (0, __stryke_fs_exists.existsSync)((0, __stryke_path_replace.replacePath)(configFile, projectRoot)) ? (0, __stryke_path_replace.replacePath)(configFile, projectRoot) : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), (0, __stryke_path_replace.replacePath)(configFile, projectRoot))) ? (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), (0, __stryke_path_replace.replacePath)(configFile, projectRoot)) : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), configFile)) ? (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), configFile) : void 0;
44
+ if (!resolvedUserConfigFile) resolvedUserConfigFile = (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.${mode}.config.ts`)) ? (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.${mode}.config.ts`) : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.${mode}.config.js`)) ? (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.${mode}.config.js`) : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.${mode}.config.mts`)) ? (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.${mode}.config.mts`) : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.${mode}.config.mjs`)) ? (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.${mode}.config.mjs`) : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.config.ts`)) ? (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.config.ts`) : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.config.js`)) ? (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.config.js`) : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.config.mts`)) ? (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.config.mts`) : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.config.mjs`)) ? (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(projectRoot, workspaceRoot), `${framework}.config.mjs`) : void 0;
45
+ if (resolvedUserConfigFile) {
46
+ const resolved = await jiti.import(jiti.esmResolve(resolvedUserConfigFile));
47
+ if (resolved) {
48
+ let config = {};
49
+ if ((0, __stryke_type_checks_is_function.isFunction)(resolved)) config = await Promise.resolve(resolved({
50
+ command,
51
+ mode,
52
+ isSsrBuild: false,
53
+ isPreview: false
54
+ }));
55
+ if ((0, __stryke_type_checks_is_set_object.isSetObject)(config)) resolvedUserConfig = {
56
+ ...config,
57
+ config,
58
+ configFile: resolvedUserConfigFile
59
+ };
60
+ }
61
+ }
62
+ const result = await (0, c12.loadConfig)({
63
+ cwd: projectRoot,
64
+ name: framework,
65
+ envName: mode,
66
+ globalRc: true,
67
+ packageJson: true,
68
+ dotenv: true,
69
+ jiti
70
+ });
71
+ return (0, defu.default)(resolvedUserConfig, (0, __stryke_type_checks_is_set_object.isSetObject)(result?.config) ? {
72
+ ...result.config,
73
+ ...result
74
+ } : {});
75
+ }
76
+
77
+ //#endregion
78
+ exports.loadUserConfigFile = loadUserConfigFile;
79
+ exports.loadWorkspaceConfig = loadWorkspaceConfig;
@@ -0,0 +1,76 @@
1
+ import defu$1 from "defu";
2
+ import { joinPaths } from "@stryke/path/join-paths";
3
+ import { appendPath } from "@stryke/path/append";
4
+ import { replacePath } from "@stryke/path/replace";
5
+ import { isFunction } from "@stryke/type-checks/is-function";
6
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
7
+ import { existsSync } from "@stryke/fs/exists";
8
+ import { getWorkspaceConfig } from "@storm-software/config-tools/get-config";
9
+ import { loadConfig } from "c12";
10
+
11
+ //#region ../powerlines/src/lib/config-file.ts
12
+ /**
13
+ * Loads the workspace configuration.
14
+ *
15
+ * @param workspaceRoot - The root directory of the workspace.
16
+ * @param cwd - The current working directory to start searching from.
17
+ * @returns A promise that resolves to the loaded workspace configuration.
18
+ */
19
+ async function loadWorkspaceConfig(workspaceRoot, cwd) {
20
+ return defu$1({ workspaceRoot }, await getWorkspaceConfig(true, {
21
+ cwd,
22
+ workspaceRoot,
23
+ useDefault: true
24
+ }));
25
+ }
26
+ /**
27
+ * Loads the user configuration file for the project.
28
+ *
29
+ * @param projectRoot - The root directory of the project.
30
+ * @param workspaceRoot - The root directory of the workspace.
31
+ * @param jiti - An instance of Jiti to resolve modules from
32
+ * @param command - The {@link PowerlinesCommand} string associated with the current running process
33
+ * @param mode - The mode in which the project is running (default is "production").
34
+ * @param configFile - An optional path to a specific configuration file.
35
+ * @param framework - The framework name to use for default configuration file names.
36
+ * @returns A promise that resolves to the resolved user configuration.
37
+ */
38
+ async function loadUserConfigFile(projectRoot, workspaceRoot, jiti, command, mode = "production", configFile, framework = "powerlines") {
39
+ let resolvedUserConfig = {};
40
+ let resolvedUserConfigFile;
41
+ if (configFile) resolvedUserConfigFile = existsSync(replacePath(configFile, projectRoot)) ? replacePath(configFile, projectRoot) : existsSync(joinPaths(appendPath(projectRoot, workspaceRoot), replacePath(configFile, projectRoot))) ? joinPaths(appendPath(projectRoot, workspaceRoot), replacePath(configFile, projectRoot)) : existsSync(joinPaths(appendPath(projectRoot, workspaceRoot), configFile)) ? joinPaths(appendPath(projectRoot, workspaceRoot), configFile) : void 0;
42
+ if (!resolvedUserConfigFile) resolvedUserConfigFile = existsSync(joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.ts`)) ? joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.ts`) : existsSync(joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.js`)) ? joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.js`) : existsSync(joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.mts`)) ? joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.mts`) : existsSync(joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.mjs`)) ? joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.mjs`) : existsSync(joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.config.ts`)) ? joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.config.ts`) : existsSync(joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.config.js`)) ? joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.config.js`) : existsSync(joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.config.mts`)) ? joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.config.mts`) : existsSync(joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.config.mjs`)) ? joinPaths(appendPath(projectRoot, workspaceRoot), `${framework}.config.mjs`) : void 0;
43
+ if (resolvedUserConfigFile) {
44
+ const resolved = await jiti.import(jiti.esmResolve(resolvedUserConfigFile));
45
+ if (resolved) {
46
+ let config = {};
47
+ if (isFunction(resolved)) config = await Promise.resolve(resolved({
48
+ command,
49
+ mode,
50
+ isSsrBuild: false,
51
+ isPreview: false
52
+ }));
53
+ if (isSetObject(config)) resolvedUserConfig = {
54
+ ...config,
55
+ config,
56
+ configFile: resolvedUserConfigFile
57
+ };
58
+ }
59
+ }
60
+ const result = await loadConfig({
61
+ cwd: projectRoot,
62
+ name: framework,
63
+ envName: mode,
64
+ globalRc: true,
65
+ packageJson: true,
66
+ dotenv: true,
67
+ jiti
68
+ });
69
+ return defu$1(resolvedUserConfig, isSetObject(result?.config) ? {
70
+ ...result.config,
71
+ ...result
72
+ } : {});
73
+ }
74
+
75
+ //#endregion
76
+ export { loadUserConfigFile, loadWorkspaceConfig };
@@ -0,0 +1,184 @@
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ const require_environment = require('../../internal/helpers/environment.cjs');
3
+ const require_config_file = require('../config-file.cjs');
4
+ const require_context = require('./context.cjs');
5
+ const require_environment_context = require('./environment-context.cjs');
6
+ let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
7
+ let __stryke_convert_to_array = require("@stryke/convert/to-array");
8
+ let __stryke_fs_resolve = require("@stryke/fs/resolve");
9
+ let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
10
+ let chalk = require("chalk");
11
+ chalk = require_rolldown_runtime.__toESM(chalk);
12
+
13
+ //#region ../powerlines/src/lib/contexts/api-context.ts
14
+ var PowerlinesAPIContext = class PowerlinesAPIContext extends require_context.PowerlinesContext {
15
+ #environments = {};
16
+ #plugins = [];
17
+ #log;
18
+ /**
19
+ * Create a new Storm context from the workspace root and user config.
20
+ *
21
+ * @param workspaceRoot - The root directory of the workspace.
22
+ * @param config - The user configuration options.
23
+ * @returns A promise that resolves to the new context.
24
+ */
25
+ static async from(workspaceRoot, config) {
26
+ const context = new PowerlinesAPIContext(await require_config_file.loadWorkspaceConfig(workspaceRoot, config.root));
27
+ await context.withUserConfig(config);
28
+ const powerlinesPath = await (0, __stryke_fs_resolve.resolvePackage)("powerlines");
29
+ if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
30
+ context.powerlinesPath = powerlinesPath;
31
+ return context;
32
+ }
33
+ /**
34
+ * Internal context fields and methods
35
+ *
36
+ * @danger
37
+ * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
38
+ *
39
+ * @internal
40
+ */
41
+ get $$internal() {
42
+ return super.$$internal;
43
+ }
44
+ /**
45
+ * Internal context fields and methods
46
+ *
47
+ * @danger
48
+ * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
49
+ *
50
+ * @internal
51
+ */
52
+ set $$internal(value) {
53
+ super.$$internal = value;
54
+ for (const environment of Object.values(this.environments)) environment.$$internal = super.$$internal;
55
+ }
56
+ /**
57
+ * A record of all environments by name
58
+ */
59
+ get environments() {
60
+ return this.#environments;
61
+ }
62
+ get log() {
63
+ if (!this.#log) this.#log = this.createLog();
64
+ return this.#log;
65
+ }
66
+ get plugins() {
67
+ return this.#plugins;
68
+ }
69
+ constructor(workspaceConfig) {
70
+ super(workspaceConfig);
71
+ }
72
+ /**
73
+ * Initialize the context with the provided configuration options
74
+ *
75
+ * @param config - The partial user configuration to use for initialization.
76
+ */
77
+ async init(config = {}) {
78
+ await super.init(config);
79
+ await Promise.all((0, __stryke_convert_to_array.toArray)(this.config.userConfig.environments && Object.keys(this.config.userConfig.environments).length > 0 ? Object.keys(this.config.userConfig.environments).map((name) => require_environment.createEnvironment(name, this.config.userConfig)) : require_environment.createDefaultEnvironment(this.config.userConfig)).map(async (env) => {
80
+ this.#environments[env.name] = await this.in(env);
81
+ }));
82
+ }
83
+ /**
84
+ * A function to copy the context and update the fields for a specific environment
85
+ *
86
+ * @param environment - The environment configuration to use.
87
+ * @returns A new context instance with the updated environment.
88
+ */
89
+ async in(environment) {
90
+ let context;
91
+ if (this.environments[environment.name]) context = this.environments[environment.name];
92
+ else context = await require_environment_context.PowerlinesEnvironmentContext.fromConfig(this.workspaceConfig, this.config);
93
+ if ((0, __stryke_type_checks_is_set_object.isSetObject)(this.config.inlineConfig)) await context.withInlineConfig(this.config.inlineConfig);
94
+ context.environment = environment;
95
+ context.plugins = [];
96
+ for (const plugin of this.plugins) await context.addPlugin(plugin);
97
+ return context;
98
+ }
99
+ /**
100
+ * Update the context using a new user configuration options
101
+ *
102
+ * @param userConfig - The new user configuration options.
103
+ */
104
+ async withUserConfig(userConfig, options = { isHighPriority: true }) {
105
+ await super.withUserConfig(userConfig, options);
106
+ await Promise.all(Object.keys(this.#environments).map(async (name) => {
107
+ await this.#environments[name].withUserConfig(userConfig, options);
108
+ }));
109
+ }
110
+ /**
111
+ * Update the context using a new inline configuration options
112
+ *
113
+ * @param inlineConfig - The new inline configuration options.
114
+ */
115
+ async withInlineConfig(inlineConfig, options = { isHighPriority: true }) {
116
+ await super.withInlineConfig(inlineConfig, options);
117
+ await Promise.all(Object.keys(this.#environments).map(async (name) => {
118
+ await this.#environments[name].withInlineConfig(inlineConfig, options);
119
+ }));
120
+ }
121
+ /**
122
+ * Add a plugin to the API context and all environments
123
+ *
124
+ * @param plugin - The plugin to add.
125
+ */
126
+ async addPlugin(plugin) {
127
+ this.plugins.push(plugin);
128
+ await Promise.all(Object.keys(this.environments).map(async (name) => {
129
+ await this.environments[name].addPlugin(plugin);
130
+ }));
131
+ }
132
+ /**
133
+ * Get an environment by name, or the default environment if no name is provided
134
+ *
135
+ * @param name - The name of the environment to retrieve.
136
+ * @returns The requested environment context.
137
+ */
138
+ async getEnvironment(name) {
139
+ let environment;
140
+ if (name) environment = this.environments[name];
141
+ if (Object.keys(this.environments).length === 1) {
142
+ environment = this.environments[Object.keys(this.environments)[0]];
143
+ this.log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, `Applying the only configured environment: ${chalk.default.bold.cyanBright(environment?.environment.name)}`);
144
+ }
145
+ if (!environment) {
146
+ if (name) throw new Error(`Environment "${name}" not found.`);
147
+ environment = await this.in(require_environment.createDefaultEnvironment(this.config.userConfig));
148
+ this.log(__storm_software_config_tools_types.LogLevelLabel.WARN, `No environment specified, and no default environment found. Using a temporary default environment: ${chalk.default.bold.cyanBright(environment?.environment.name)}`);
149
+ }
150
+ return environment;
151
+ }
152
+ /**
153
+ * A safe version of `getEnvironment` that returns `undefined` if the environment is not found
154
+ *
155
+ * @param name - The name of the environment to retrieve.
156
+ * @returns The requested environment context or `undefined` if not found.
157
+ */
158
+ async getEnvironmentSafe(name) {
159
+ try {
160
+ return await this.getEnvironment(name);
161
+ } catch {
162
+ return;
163
+ }
164
+ }
165
+ /**
166
+ * A function to merge all configured environments into a single context.
167
+ *
168
+ * @remarks
169
+ * If only one environment is configured, that environment will be returned directly.
170
+ *
171
+ * @returns A promise that resolves to a merged/global environment context.
172
+ */
173
+ async toEnvironment() {
174
+ let environment;
175
+ if (Object.keys(this.environments).length > 1) {
176
+ environment = await this.in(require_environment.createEnvironment(require_environment.GLOBAL_ENVIRONMENT, this.config.userConfig));
177
+ this.log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, `Combined all ${Object.keys(this.environments).length} environments into a single global context.`);
178
+ } else environment = await this.getEnvironment();
179
+ return environment;
180
+ }
181
+ };
182
+
183
+ //#endregion
184
+ exports.PowerlinesAPIContext = PowerlinesAPIContext;