@powerlines/plugin-webpack 0.5.130 → 0.5.131

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-CsQFPhIt.d.cts +1762 -0
  20. package/dist/plugin-ifZVa20V.mjs +1 -0
  21. package/dist/plugin-pBKbb5K9.cjs +0 -0
  22. package/dist/plugin-wiaZGMv0.d.mts +1764 -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-BVSyqmCe.d.cts +7 -0
  34. package/dist/unplugin-CVrlqRhX.mjs +4615 -0
  35. package/dist/unplugin-Cemsz8kP.cjs +4659 -0
  36. package/dist/unplugin-vRGq3odL.d.mts +7 -0
  37. package/package.json +3 -3
  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,84 +0,0 @@
1
- import { declare } from "@babel/helper-plugin-utils";
2
- import * as t from "@babel/types";
3
-
4
- //#region ../powerlines/src/internal/babel/module-resolver-plugin.ts
5
- function resolveModulePath(nodePath, state) {
6
- if (!t.isStringLiteral(nodePath.node)) return;
7
- const resolvedPath = state.context?.fs.resolveSync(nodePath.node.value);
8
- if (resolvedPath) nodePath.replaceWith(t.stringLiteral(resolvedPath.replace(/\.(?:ts|mts|cts)x?$/, "")));
9
- }
10
- const TRANSFORM_FUNCTIONS = [
11
- "require",
12
- "require.resolve",
13
- "System.import",
14
- "jest.genMockFromModule",
15
- "jest.mock",
16
- "jest.unmock",
17
- "jest.doMock",
18
- "jest.dontMock",
19
- "jest.setMock",
20
- "jest.requireActual",
21
- "jest.requireMock",
22
- "require.requireActual",
23
- "require.requireMock"
24
- ];
25
- function matchesPattern(state, calleePath, pattern) {
26
- const { node } = calleePath;
27
- if (t.isMemberExpression(node)) return calleePath.matchesPattern(pattern);
28
- if (!t.isIdentifier(node) || pattern.includes(".")) return false;
29
- const name = pattern.split(".")[0];
30
- return node.name === name;
31
- }
32
- const importVisitors = {
33
- CallExpression: (nodePath, state) => {
34
- if (state.moduleResolverVisited.has(nodePath)) return;
35
- const calleePath = nodePath.get("callee");
36
- if (calleePath && TRANSFORM_FUNCTIONS.some((pattern) => matchesPattern(state, calleePath, pattern)) || t.isImport(nodePath.node.callee)) {
37
- state.moduleResolverVisited.add(nodePath);
38
- resolveModulePath(nodePath.get("arguments.0"), state);
39
- }
40
- },
41
- "ImportDeclaration|ExportDeclaration|ExportAllDeclaration": (nodePath, state) => {
42
- if (!nodePath || !nodePath.get("source") || state.moduleResolverVisited.has(nodePath)) return;
43
- state.moduleResolverVisited.add(nodePath);
44
- resolveModulePath(nodePath.get("source"), state);
45
- }
46
- };
47
- const moduleResolverBabelPlugin = (context) => {
48
- return declare(function builder(api) {
49
- let moduleResolverVisited = /* @__PURE__ */ new Set();
50
- return {
51
- name: "powerlines:module-resolver",
52
- manipulateOptions(opts) {
53
- opts.filename ??= "unknown";
54
- },
55
- pre() {
56
- moduleResolverVisited = /* @__PURE__ */ new Set();
57
- },
58
- visitor: { Program: {
59
- enter(programPath, state) {
60
- programPath.traverse(importVisitors, {
61
- ...state,
62
- context,
63
- moduleResolverVisited,
64
- api
65
- });
66
- },
67
- exit(programPath, state) {
68
- programPath.traverse(importVisitors, {
69
- ...state,
70
- context,
71
- moduleResolverVisited,
72
- api
73
- });
74
- }
75
- } },
76
- post() {
77
- moduleResolverVisited.clear();
78
- }
79
- };
80
- });
81
- };
82
-
83
- //#endregion
84
- export { moduleResolverBabelPlugin };
@@ -1,52 +0,0 @@
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_string_format_title_case = require("@stryke/string-format/title-case");
5
-
6
- //#region ../powerlines/src/internal/helpers/environment.ts
7
- const DEFAULT_ENVIRONMENT = "default";
8
- const GLOBAL_ENVIRONMENT = "__GLOBAL__";
9
- function createEnvironment(name, userConfig) {
10
- return (0, defu.default)(userConfig.environments?.[name] ?? {}, {
11
- name,
12
- title: userConfig.title || (0, __stryke_string_format_title_case.titleCase)(userConfig.name),
13
- ssr: false,
14
- mainFields: userConfig.build?.platform === "browser" ? [
15
- "browser",
16
- "module",
17
- "jsnext:main",
18
- "jsnext"
19
- ] : [
20
- "module",
21
- "jsnext:main",
22
- "jsnext"
23
- ],
24
- extensions: [
25
- ".mjs",
26
- ".js",
27
- ".mts",
28
- ".ts",
29
- ".jsx",
30
- ".tsx",
31
- ".json"
32
- ],
33
- consumer: userConfig.build?.platform === "browser" ? "client" : "server",
34
- preview: userConfig.build?.platform === "browser" ? {
35
- port: 5173,
36
- open: true,
37
- strictPort: false,
38
- host: "localhost",
39
- allowedHosts: ["."],
40
- cors: true,
41
- headers: {}
42
- } : void 0
43
- }, userConfig);
44
- }
45
- function createDefaultEnvironment(userConfig) {
46
- return createEnvironment(DEFAULT_ENVIRONMENT, userConfig);
47
- }
48
-
49
- //#endregion
50
- exports.GLOBAL_ENVIRONMENT = GLOBAL_ENVIRONMENT;
51
- exports.createDefaultEnvironment = createDefaultEnvironment;
52
- exports.createEnvironment = createEnvironment;
@@ -1,48 +0,0 @@
1
- import defu$1 from "defu";
2
- import { titleCase } from "@stryke/string-format/title-case";
3
-
4
- //#region ../powerlines/src/internal/helpers/environment.ts
5
- const DEFAULT_ENVIRONMENT = "default";
6
- const GLOBAL_ENVIRONMENT = "__GLOBAL__";
7
- function createEnvironment(name, userConfig) {
8
- return defu$1(userConfig.environments?.[name] ?? {}, {
9
- name,
10
- title: userConfig.title || titleCase(userConfig.name),
11
- ssr: false,
12
- mainFields: userConfig.build?.platform === "browser" ? [
13
- "browser",
14
- "module",
15
- "jsnext:main",
16
- "jsnext"
17
- ] : [
18
- "module",
19
- "jsnext:main",
20
- "jsnext"
21
- ],
22
- extensions: [
23
- ".mjs",
24
- ".js",
25
- ".mts",
26
- ".ts",
27
- ".jsx",
28
- ".tsx",
29
- ".json"
30
- ],
31
- consumer: userConfig.build?.platform === "browser" ? "client" : "server",
32
- preview: userConfig.build?.platform === "browser" ? {
33
- port: 5173,
34
- open: true,
35
- strictPort: false,
36
- host: "localhost",
37
- allowedHosts: ["."],
38
- cors: true,
39
- headers: {}
40
- } : void 0
41
- }, userConfig);
42
- }
43
- function createDefaultEnvironment(userConfig) {
44
- return createEnvironment(DEFAULT_ENVIRONMENT, userConfig);
45
- }
46
-
47
- //#endregion
48
- export { GLOBAL_ENVIRONMENT, createDefaultEnvironment, createEnvironment };
@@ -1,51 +0,0 @@
1
- const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
- const require_ts_morph = require('../../lib/typescript/ts-morph.cjs');
3
- let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
4
- let typescript = require("typescript");
5
-
6
- //#region ../powerlines/src/internal/helpers/generate-types.ts
7
- /**
8
- * Formats the generated TypeScript types source code.
9
- *
10
- * @param code - The generated TypeScript code.
11
- * @returns The formatted TypeScript code.
12
- */
13
- function formatTypes(code) {
14
- return code.replace(/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g, "").replaceAll("#private;", "").replace(/__Ω/g, "");
15
- }
16
- /**
17
- * Emits TypeScript declaration types for the provided files using the given TypeScript configuration.
18
- *
19
- * @param context - The context containing options and environment paths.
20
- * @param files - The list of files to generate types for.
21
- * @returns A promise that resolves to the generated TypeScript declaration types.
22
- */
23
- async function emitTypes(context, files) {
24
- context.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Running the TypeScript compiler for ${files.length} generated runtime files.`);
25
- const program = require_ts_morph.createProgram(context, { skipAddingFilesFromTsConfig: true });
26
- program.addSourceFilesAtPaths(files);
27
- const result = program.emitToMemory({ emitOnlyDtsFiles: true });
28
- let builtinModules = "";
29
- for (const file of result.getFiles()) if (!file.filePath.endsWith(".map")) {
30
- if (context.builtins.some((builtin) => builtin === file.filePath || context.fs.metadata[builtin]?.id && context.fs.metadata[builtin]?.id === file.filePath)) {
31
- const module$1 = await context.fs.resolve(file.filePath);
32
- builtinModules += `
33
- declare module "${module$1}" {
34
- ${file.text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
35
- }
36
- `;
37
- }
38
- }
39
- const diagnosticMessages = [];
40
- result.getDiagnostics().forEach((diagnostic) => {
41
- if (diagnostic.getSourceFile()?.getBaseName()) diagnosticMessages.push(`${diagnostic.getSourceFile()?.getBaseName()} (${(diagnostic.getLineNumber() ?? 0) + 1}): ${(0, typescript.flattenDiagnosticMessageText)(diagnostic.getMessageText().toString(), "\n")}`);
42
- else diagnosticMessages.push((0, typescript.flattenDiagnosticMessageText)(diagnostic.getMessageText().toString(), "\n"));
43
- });
44
- const diagnosticMessage = diagnosticMessages.join("\n");
45
- if (diagnosticMessage) throw new Error(`TypeScript compilation failed: \n\n${diagnosticMessage.length > 5e3 ? `${diagnosticMessage.slice(0, 5e3)}...` : diagnosticMessage}`);
46
- return formatTypes(builtinModules);
47
- }
48
-
49
- //#endregion
50
- exports.emitTypes = emitTypes;
51
- exports.formatTypes = formatTypes;
@@ -1,49 +0,0 @@
1
- import { createProgram } from "../../lib/typescript/ts-morph.mjs";
2
- import { LogLevelLabel } from "@storm-software/config-tools/types";
3
- import { flattenDiagnosticMessageText } from "typescript";
4
-
5
- //#region ../powerlines/src/internal/helpers/generate-types.ts
6
- /**
7
- * Formats the generated TypeScript types source code.
8
- *
9
- * @param code - The generated TypeScript code.
10
- * @returns The formatted TypeScript code.
11
- */
12
- function formatTypes(code) {
13
- return code.replace(/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g, "").replaceAll("#private;", "").replace(/__Ω/g, "");
14
- }
15
- /**
16
- * Emits TypeScript declaration types for the provided files using the given TypeScript configuration.
17
- *
18
- * @param context - The context containing options and environment paths.
19
- * @param files - The list of files to generate types for.
20
- * @returns A promise that resolves to the generated TypeScript declaration types.
21
- */
22
- async function emitTypes(context, files) {
23
- context.log(LogLevelLabel.TRACE, `Running the TypeScript compiler for ${files.length} generated runtime files.`);
24
- const program = createProgram(context, { skipAddingFilesFromTsConfig: true });
25
- program.addSourceFilesAtPaths(files);
26
- const result = program.emitToMemory({ emitOnlyDtsFiles: true });
27
- let builtinModules = "";
28
- for (const file of result.getFiles()) if (!file.filePath.endsWith(".map")) {
29
- if (context.builtins.some((builtin) => builtin === file.filePath || context.fs.metadata[builtin]?.id && context.fs.metadata[builtin]?.id === file.filePath)) {
30
- const module = await context.fs.resolve(file.filePath);
31
- builtinModules += `
32
- declare module "${module}" {
33
- ${file.text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
34
- }
35
- `;
36
- }
37
- }
38
- const diagnosticMessages = [];
39
- result.getDiagnostics().forEach((diagnostic) => {
40
- if (diagnostic.getSourceFile()?.getBaseName()) diagnosticMessages.push(`${diagnostic.getSourceFile()?.getBaseName()} (${(diagnostic.getLineNumber() ?? 0) + 1}): ${flattenDiagnosticMessageText(diagnostic.getMessageText().toString(), "\n")}`);
41
- else diagnosticMessages.push(flattenDiagnosticMessageText(diagnostic.getMessageText().toString(), "\n"));
42
- });
43
- const diagnosticMessage = diagnosticMessages.join("\n");
44
- if (diagnosticMessage) throw new Error(`TypeScript compilation failed: \n\n${diagnosticMessage.length > 5e3 ? `${diagnosticMessage.slice(0, 5e3)}...` : diagnosticMessage}`);
45
- return formatTypes(builtinModules);
46
- }
47
-
48
- //#endregion
49
- export { emitTypes, formatTypes };
@@ -1,63 +0,0 @@
1
- const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
- let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
3
- let defu = require("defu");
4
- let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
5
- let __stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
6
- let __stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
7
- let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
8
- let chalk = require("chalk");
9
- chalk = require_rolldown_runtime.__toESM(chalk);
10
-
11
- //#region ../powerlines/src/internal/helpers/hooks.ts
12
- const mergeResults = (0, defu.createDefu)((obj, key, value) => {
13
- if ((0, __stryke_type_checks_is_string.isString)(obj[key]) && (0, __stryke_type_checks_is_string.isString)(value)) {
14
- obj[key] = `${obj[key] || ""}\n${value || ""}`.trim();
15
- return true;
16
- }
17
- return false;
18
- });
19
- /**
20
- * Calls a hook with the given context, options, and arguments.
21
- *
22
- * @param context - The context to use when calling the hook.
23
- * @param hook - The hook to call.
24
- * @param options - Options for calling the hook.
25
- * @param args - Arguments to pass to the hook.
26
- * @returns The return value of the hook.
27
- */
28
- async function callHook(context, hook, options, ...args) {
29
- const handlers = context.selectHooks(hook, options);
30
- if (handlers.length > 0) {
31
- context.log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, ` 🧩 Calling plugin hook: ${chalk.default.bold.cyanBright(`${hook}${options?.order ? ` (${options.order})` : ""}`)}`);
32
- let results = [];
33
- if (options?.sequential === false) results = await Promise.all(handlers.map(async (handler) => {
34
- if (!(0, __stryke_type_checks_is_function.isFunction)(handler.handle)) throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
35
- return Promise.resolve(handler.handle.apply(handler.context, [...args]));
36
- }));
37
- else for (const handler of handlers) {
38
- if (!(0, __stryke_type_checks_is_function.isFunction)(handler.handle)) throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
39
- if (options?.result === "first" || options?.asNextParam === false) {
40
- results.push(await Promise.resolve(handler.handle.apply(handler.context, [...args])));
41
- if (options?.result === "first" && (0, __stryke_type_checks_is_set.isSet)(results[results.length - 1])) break;
42
- } else {
43
- const sequenceArgs = [...args];
44
- if (results.length > 0 && sequenceArgs.length > 0) sequenceArgs[0] = (0, __stryke_type_checks_is_function.isFunction)(options.asNextParam) ? await Promise.resolve(options.asNextParam(results[0])) : results[0];
45
- const result = await Promise.resolve(handler.handle.apply(handler.context, [...sequenceArgs]));
46
- if (result) {
47
- if (options?.result === "last") results = [result];
48
- else if ((0, __stryke_type_checks_is_string.isString)(result)) results = [`${(0, __stryke_type_checks_is_string.isString)(results[0]) ? results[0] || "" : ""}\n${result || ""}`.trim()];
49
- else if ((0, __stryke_type_checks_is_object.isObject)(result)) results = [mergeResults(result, results[0] ?? {})];
50
- }
51
- }
52
- }
53
- const definedResults = results.filter((result) => (0, __stryke_type_checks_is_set.isSet)(result));
54
- if (definedResults.length > 0) {
55
- let mergedResult = void 0;
56
- for (const result of definedResults) mergedResult = (0, defu.defu)(result, mergedResult ?? {});
57
- return mergedResult;
58
- }
59
- }
60
- }
61
-
62
- //#endregion
63
- exports.callHook = callHook;
@@ -1,61 +0,0 @@
1
- import { LogLevelLabel } from "@storm-software/config-tools/types";
2
- import { createDefu, defu } from "defu";
3
- import { isFunction } from "@stryke/type-checks/is-function";
4
- import { isObject } from "@stryke/type-checks/is-object";
5
- import { isSet } from "@stryke/type-checks/is-set";
6
- import { isString } from "@stryke/type-checks/is-string";
7
- import chalk from "chalk";
8
-
9
- //#region ../powerlines/src/internal/helpers/hooks.ts
10
- const mergeResults = createDefu((obj, key, value) => {
11
- if (isString(obj[key]) && isString(value)) {
12
- obj[key] = `${obj[key] || ""}\n${value || ""}`.trim();
13
- return true;
14
- }
15
- return false;
16
- });
17
- /**
18
- * Calls a hook with the given context, options, and arguments.
19
- *
20
- * @param context - The context to use when calling the hook.
21
- * @param hook - The hook to call.
22
- * @param options - Options for calling the hook.
23
- * @param args - Arguments to pass to the hook.
24
- * @returns The return value of the hook.
25
- */
26
- async function callHook(context, hook, options, ...args) {
27
- const handlers = context.selectHooks(hook, options);
28
- if (handlers.length > 0) {
29
- context.log(LogLevelLabel.DEBUG, ` 🧩 Calling plugin hook: ${chalk.bold.cyanBright(`${hook}${options?.order ? ` (${options.order})` : ""}`)}`);
30
- let results = [];
31
- if (options?.sequential === false) results = await Promise.all(handlers.map(async (handler) => {
32
- if (!isFunction(handler.handle)) throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
33
- return Promise.resolve(handler.handle.apply(handler.context, [...args]));
34
- }));
35
- else for (const handler of handlers) {
36
- if (!isFunction(handler.handle)) throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
37
- if (options?.result === "first" || options?.asNextParam === false) {
38
- results.push(await Promise.resolve(handler.handle.apply(handler.context, [...args])));
39
- if (options?.result === "first" && isSet(results[results.length - 1])) break;
40
- } else {
41
- const sequenceArgs = [...args];
42
- if (results.length > 0 && sequenceArgs.length > 0) sequenceArgs[0] = isFunction(options.asNextParam) ? await Promise.resolve(options.asNextParam(results[0])) : results[0];
43
- const result = await Promise.resolve(handler.handle.apply(handler.context, [...sequenceArgs]));
44
- if (result) {
45
- if (options?.result === "last") results = [result];
46
- else if (isString(result)) results = [`${isString(results[0]) ? results[0] || "" : ""}\n${result || ""}`.trim()];
47
- else if (isObject(result)) results = [mergeResults(result, results[0] ?? {})];
48
- }
49
- }
50
- }
51
- const definedResults = results.filter((result) => isSet(result));
52
- if (definedResults.length > 0) {
53
- let mergedResult = void 0;
54
- for (const result of definedResults) mergedResult = defu(result, mergedResult ?? {});
55
- return mergedResult;
56
- }
57
- }
58
- }
59
-
60
- //#endregion
61
- export { callHook };
@@ -1,25 +0,0 @@
1
- const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
- const require_install = require('./install.cjs');
3
- let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
4
- let __stryke_string_format_package = require("@stryke/string-format/package");
5
-
6
- //#region ../powerlines/src/internal/helpers/install-dependencies.ts
7
- /**
8
- * Install missing project dependencies.
9
- *
10
- * @param context - The build context.
11
- */
12
- async function installDependencies(context) {
13
- context.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Checking and installing missing project dependencies.`);
14
- context.dependencies ??= {};
15
- context.devDependencies ??= {};
16
- if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
17
- context.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `No dependencies or devDependencies to install. Skipping installation step.`);
18
- return;
19
- }
20
- context.log(__storm_software_config_tools_types.LogLevelLabel.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")}`);
21
- await Promise.all([Promise.all(Object.entries(context.dependencies).map(async ([name, version]) => require_install.installPackage(context, `${(0, __stryke_string_format_package.getPackageName)(name)}@${String(version)}`, false))), Promise.all(Object.entries(context.devDependencies).map(async ([name, version]) => require_install.installPackage(context, `${(0, __stryke_string_format_package.getPackageName)(name)}@${String(version)}`, true)))]);
22
- }
23
-
24
- //#endregion
25
- exports.installDependencies = installDependencies;
@@ -1,24 +0,0 @@
1
- import { installPackage } from "./install.mjs";
2
- import { LogLevelLabel } from "@storm-software/config-tools/types";
3
- import { getPackageName } from "@stryke/string-format/package";
4
-
5
- //#region ../powerlines/src/internal/helpers/install-dependencies.ts
6
- /**
7
- * Install missing project dependencies.
8
- *
9
- * @param context - The build context.
10
- */
11
- async function installDependencies(context) {
12
- context.log(LogLevelLabel.TRACE, `Checking and installing missing project dependencies.`);
13
- context.dependencies ??= {};
14
- context.devDependencies ??= {};
15
- if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
16
- context.log(LogLevelLabel.TRACE, `No dependencies or devDependencies to install. Skipping installation step.`);
17
- return;
18
- }
19
- context.log(LogLevelLabel.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")}`);
20
- 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)))]);
21
- }
22
-
23
- //#endregion
24
- export { installDependencies };
@@ -1,37 +0,0 @@
1
- const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
- let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
3
- let __stryke_fs_install = require("@stryke/fs/install");
4
- let __stryke_fs_package_fns = require("@stryke/fs/package-fns");
5
- let __stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
6
- let __stryke_string_format_package = require("@stryke/string-format/package");
7
-
8
- //#region ../powerlines/src/internal/helpers/install.ts
9
- /**
10
- * Installs a package if it is not already installed.
11
- *
12
- * @param context - The resolved options
13
- * @param packageName - The name of the package to install
14
- * @param dev - Whether to install the package as a dev dependency
15
- */
16
- async function installPackage(context, packageName, dev = false) {
17
- if (!await (0, __stryke_fs_package_fns.isPackageListed)((0, __stryke_string_format_package.getPackageName)(packageName), { cwd: context.config.projectRoot })) if (context.config.skipInstalls !== true) {
18
- context.log(__storm_software_config_tools_types.LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`);
19
- const result = await (0, __stryke_fs_install.install)(packageName, {
20
- cwd: context.config.projectRoot,
21
- dev
22
- });
23
- if ((0, __stryke_type_checks_is_number.isNumber)(result.exitCode) && result.exitCode > 0) {
24
- context.log(__storm_software_config_tools_types.LogLevelLabel.ERROR, result.stderr);
25
- throw new Error(`An error occurred while installing the package "${packageName}"`);
26
- }
27
- } else context.log(__storm_software_config_tools_types.LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`);
28
- else if ((0, __stryke_string_format_package.hasPackageVersion)(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
29
- if (!await (0, __stryke_fs_package_fns.doesPackageMatch)((0, __stryke_string_format_package.getPackageName)(packageName), (0, __stryke_string_format_package.getPackageVersion)(packageName), context.config.projectRoot)) {
30
- const packageListing = await (0, __stryke_fs_package_fns.getPackageListing)((0, __stryke_string_format_package.getPackageName)(packageName), { cwd: context.config.projectRoot });
31
- if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) context.log(__storm_software_config_tools_types.LogLevelLabel.WARN, `The package "${(0, __stryke_string_format_package.getPackageName)(packageName)}" is installed but does not match the expected version ${(0, __stryke_string_format_package.getPackageVersion)(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`);
32
- }
33
- }
34
- }
35
-
36
- //#endregion
37
- exports.installPackage = installPackage;
@@ -1,36 +0,0 @@
1
- import { LogLevelLabel } from "@storm-software/config-tools/types";
2
- import { install } from "@stryke/fs/install";
3
- import { doesPackageMatch, getPackageListing, isPackageListed } from "@stryke/fs/package-fns";
4
- import { isNumber } from "@stryke/type-checks/is-number";
5
- import { getPackageName, getPackageVersion, hasPackageVersion } from "@stryke/string-format/package";
6
-
7
- //#region ../powerlines/src/internal/helpers/install.ts
8
- /**
9
- * Installs a package if it is not already installed.
10
- *
11
- * @param context - The resolved options
12
- * @param packageName - The name of the package to install
13
- * @param dev - Whether to install the package as a dev dependency
14
- */
15
- async function installPackage(context, packageName, dev = false) {
16
- if (!await isPackageListed(getPackageName(packageName), { cwd: context.config.projectRoot })) if (context.config.skipInstalls !== true) {
17
- context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`);
18
- const result = await install(packageName, {
19
- cwd: context.config.projectRoot,
20
- dev
21
- });
22
- if (isNumber(result.exitCode) && result.exitCode > 0) {
23
- context.log(LogLevelLabel.ERROR, result.stderr);
24
- throw new Error(`An error occurred while installing the package "${packageName}"`);
25
- }
26
- } else context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`);
27
- else if (hasPackageVersion(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
28
- if (!await doesPackageMatch(getPackageName(packageName), getPackageVersion(packageName), context.config.projectRoot)) {
29
- const packageListing = await getPackageListing(getPackageName(packageName), { cwd: context.config.projectRoot });
30
- if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) context.log(LogLevelLabel.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.`);
31
- }
32
- }
33
- }
34
-
35
- //#endregion
36
- export { installPackage };
@@ -1,98 +0,0 @@
1
- const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
- const require_tsconfig = require('../../lib/typescript/tsconfig.cjs');
3
- let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
4
- let __stryke_path_join_paths = require("@stryke/path/join-paths");
5
- let __stryke_fs_package_fns = require("@stryke/fs/package-fns");
6
- let chalk = require("chalk");
7
- chalk = require_rolldown_runtime.__toESM(chalk);
8
- let __donedeal0_superdiff = require("@donedeal0/superdiff");
9
- let __stryke_fs_json = require("@stryke/fs/json");
10
- let __stryke_json_storm_json = require("@stryke/json/storm-json");
11
- let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
12
- let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
13
-
14
- //#region ../powerlines/src/internal/helpers/resolve-tsconfig.ts
15
- function getTsconfigDtsPath(context) {
16
- return (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_file_path_fns.relativePath)((0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.projectRoot), (0, __stryke_path_file_path_fns.findFilePath)(context.dtsPath)), (0, __stryke_path_file_path_fns.findFileName)(context.dtsPath));
17
- }
18
- async function resolveTsconfigChanges(context) {
19
- const tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw);
20
- const tsconfigJson = await (0, __stryke_fs_json.readJsonFile)(require_tsconfig.getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig));
21
- tsconfigJson.compilerOptions ??= {};
22
- if (context.config.output.dts !== false) {
23
- const dtsRelativePath = getTsconfigDtsPath(context);
24
- if (!tsconfigJson.include?.some((filePattern) => require_tsconfig.isIncludeMatchFound(filePattern, [context.dtsPath, dtsRelativePath]))) {
25
- tsconfigJson.include ??= [];
26
- tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
27
- }
28
- }
29
- if (!tsconfig.options.lib?.some((lib) => [
30
- "lib.esnext.d.ts",
31
- "lib.es2021.d.ts",
32
- "lib.es2022.d.ts",
33
- "lib.es2023.d.ts"
34
- ].includes(lib.toLowerCase()))) {
35
- tsconfigJson.compilerOptions.lib ??= [];
36
- tsconfigJson.compilerOptions.lib.push("esnext");
37
- }
38
- if (tsconfig.options.esModuleInterop !== true) tsconfigJson.compilerOptions.esModuleInterop = true;
39
- if (tsconfig.options.isolatedModules !== true) tsconfigJson.compilerOptions.isolatedModules = true;
40
- if (context.config.build.platform === "node") {
41
- if (!tsconfig.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
42
- tsconfigJson.compilerOptions.types ??= [];
43
- tsconfigJson.compilerOptions.types.push("node");
44
- }
45
- }
46
- return tsconfigJson;
47
- }
48
- async function initializeTsconfig(context) {
49
- context.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, "Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
50
- if (!(0, __stryke_fs_package_fns.isPackageExists)("typescript")) throw new Error("The TypeScript package is not installed. Please install the package using the command: \"npm install typescript --save-dev\"");
51
- const tsconfigFilePath = require_tsconfig.getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
52
- context.tsconfig.originalTsconfigJson = await (0, __stryke_fs_json.readJsonFile)(tsconfigFilePath);
53
- context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
54
- context.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, "Writing updated TypeScript configuration (tsconfig.json) file to disk.");
55
- await context.fs.write(tsconfigFilePath, __stryke_json_storm_json.StormJSON.stringify(context.tsconfig.tsconfigJson));
56
- context.tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
57
- }
58
- async function resolveTsconfig(context) {
59
- const updateTsconfigJson = await (0, __stryke_fs_json.readJsonFile)(context.tsconfig.tsconfigFilePath);
60
- if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) delete updateTsconfigJson.compilerOptions.types;
61
- const result = (0, __donedeal0_superdiff.getObjectDiff)(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
62
- ignoreArrayOrder: true,
63
- showOnly: {
64
- statuses: [
65
- "added",
66
- "deleted",
67
- "updated"
68
- ],
69
- granularity: "deep"
70
- }
71
- });
72
- const changes = [];
73
- const getChanges = (difference, property) => {
74
- 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);
75
- else changes.push({
76
- field: property ? `${property}.${difference.property}` : difference.property,
77
- status: difference.status,
78
- previous: difference.status === "added" ? "---" : __stryke_json_storm_json.StormJSON.stringify(difference.previousValue),
79
- current: difference.status === "deleted" ? "---" : __stryke_json_storm_json.StormJSON.stringify(difference.currentValue)
80
- });
81
- };
82
- for (const diff of result.diff) getChanges(diff);
83
- if (changes.length > 0) context.log(__storm_software_config_tools_types.LogLevelLabel.WARN, `Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
84
-
85
- ${changes.map((change, i) => `${chalk.default.bold.whiteBright(`${i + 1}. ${(0, __stryke_string_format_title_case.titleCase)(change.status)} the ${change.field} field: `)}
86
- ${chalk.default.red(` - Previous: ${change.previous} `)}
87
- ${chalk.default.green(` - Updated: ${change.current} `)}
88
- `).join("\n")}
89
- `);
90
- await context.fs.write(context.tsconfig.tsconfigFilePath, __stryke_json_storm_json.StormJSON.stringify(updateTsconfigJson));
91
- context.tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
92
- if (!context.tsconfig) throw new Error("Failed to parse the TypeScript configuration file.");
93
- }
94
-
95
- //#endregion
96
- exports.getTsconfigDtsPath = getTsconfigDtsPath;
97
- exports.initializeTsconfig = initializeTsconfig;
98
- exports.resolveTsconfig = resolveTsconfig;