@powerlines/plugin-webpack 0.5.126 → 0.5.128

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 (87) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  2. package/dist/helpers/index.cjs +3 -1
  3. package/dist/helpers/index.mjs +3 -1
  4. package/dist/helpers/unplugin.cjs +12 -1
  5. package/dist/helpers/unplugin.mjs +11 -1
  6. package/dist/index.cjs +39 -1
  7. package/dist/index.mjs +33 -1
  8. package/dist/powerlines/schemas/fs.cjs +226 -1
  9. package/dist/powerlines/schemas/fs.mjs +224 -1
  10. package/dist/powerlines/src/api.cjs +576 -9
  11. package/dist/powerlines/src/api.mjs +578 -1
  12. package/dist/powerlines/src/internal/babel/module-resolver-plugin.cjs +86 -1
  13. package/dist/powerlines/src/internal/babel/module-resolver-plugin.mjs +84 -1
  14. package/dist/powerlines/src/internal/helpers/environment.cjs +52 -1
  15. package/dist/powerlines/src/internal/helpers/environment.mjs +48 -1
  16. package/dist/powerlines/src/internal/helpers/generate-types.cjs +50 -7
  17. package/dist/powerlines/src/internal/helpers/generate-types.mjs +48 -7
  18. package/dist/powerlines/src/internal/helpers/hooks.cjs +63 -1
  19. package/dist/powerlines/src/internal/helpers/hooks.mjs +61 -1
  20. package/dist/powerlines/src/internal/helpers/install-dependencies.cjs +25 -3
  21. package/dist/powerlines/src/internal/helpers/install-dependencies.mjs +24 -3
  22. package/dist/powerlines/src/internal/helpers/install.cjs +37 -1
  23. package/dist/powerlines/src/internal/helpers/install.mjs +36 -1
  24. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.cjs +97 -7
  25. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.mjs +93 -7
  26. package/dist/powerlines/src/internal/helpers/resolver.cjs +43 -1
  27. package/dist/powerlines/src/internal/helpers/resolver.mjs +41 -1
  28. package/dist/powerlines/src/lib/build/webpack.cjs +47 -1
  29. package/dist/powerlines/src/lib/build/webpack.mjs +45 -1
  30. package/dist/powerlines/src/lib/config-file.cjs +79 -1
  31. package/dist/powerlines/src/lib/config-file.mjs +76 -1
  32. package/dist/powerlines/src/lib/contexts/api-context.cjs +184 -1
  33. package/dist/powerlines/src/lib/contexts/api-context.mjs +182 -1
  34. package/dist/powerlines/src/lib/contexts/context.cjs +931 -1
  35. package/dist/powerlines/src/lib/contexts/context.mjs +929 -1
  36. package/dist/powerlines/src/lib/contexts/environment-context.cjs +160 -1
  37. package/dist/powerlines/src/lib/contexts/environment-context.mjs +159 -1
  38. package/dist/powerlines/src/lib/contexts/plugin-context.cjs +75 -1
  39. package/dist/powerlines/src/lib/contexts/plugin-context.mjs +74 -1
  40. package/dist/powerlines/src/lib/entry.cjs +69 -1
  41. package/dist/powerlines/src/lib/entry.mjs +67 -1
  42. package/dist/powerlines/src/lib/fs/helpers.cjs +85 -1
  43. package/dist/powerlines/src/lib/fs/helpers.mjs +81 -1
  44. package/dist/powerlines/src/lib/fs/storage/base.cjs +196 -1
  45. package/dist/powerlines/src/lib/fs/storage/base.mjs +195 -1
  46. package/dist/powerlines/src/lib/fs/storage/file-system.cjs +170 -1
  47. package/dist/powerlines/src/lib/fs/storage/file-system.mjs +169 -1
  48. package/dist/powerlines/src/lib/fs/storage/virtual.cjs +88 -1
  49. package/dist/powerlines/src/lib/fs/storage/virtual.mjs +87 -1
  50. package/dist/powerlines/src/lib/fs/vfs.cjs +830 -1
  51. package/dist/powerlines/src/lib/fs/vfs.mjs +828 -1
  52. package/dist/powerlines/src/lib/logger.cjs +58 -1
  53. package/dist/powerlines/src/lib/logger.mjs +55 -1
  54. package/dist/powerlines/src/lib/typescript/ts-morph.cjs +104 -1
  55. package/dist/powerlines/src/lib/typescript/ts-morph.mjs +102 -1
  56. package/dist/powerlines/src/lib/typescript/tsconfig.cjs +149 -4
  57. package/dist/powerlines/src/lib/typescript/tsconfig.mjs +144 -4
  58. package/dist/powerlines/src/lib/unplugin/factory.cjs +6 -1
  59. package/dist/powerlines/src/lib/unplugin/factory.mjs +8 -1
  60. package/dist/powerlines/src/lib/unplugin/helpers.cjs +17 -1
  61. package/dist/powerlines/src/lib/unplugin/helpers.mjs +16 -1
  62. package/dist/powerlines/src/lib/unplugin/index.cjs +3 -1
  63. package/dist/powerlines/src/lib/unplugin/index.mjs +5 -1
  64. package/dist/powerlines/src/lib/unplugin/plugin.cjs +127 -5
  65. package/dist/powerlines/src/lib/unplugin/plugin.mjs +126 -5
  66. package/dist/powerlines/src/lib/utilities/file-header.cjs +19 -7
  67. package/dist/powerlines/src/lib/utilities/file-header.mjs +18 -7
  68. package/dist/powerlines/src/lib/utilities/meta.cjs +45 -1
  69. package/dist/powerlines/src/lib/utilities/meta.mjs +41 -1
  70. package/dist/powerlines/src/lib/utilities/source-file.cjs +22 -1
  71. package/dist/powerlines/src/lib/utilities/source-file.mjs +21 -1
  72. package/dist/powerlines/src/plugin-utils/helpers.cjs +148 -1
  73. package/dist/powerlines/src/plugin-utils/helpers.mjs +138 -1
  74. package/dist/powerlines/src/plugin-utils/paths.cjs +36 -1
  75. package/dist/powerlines/src/plugin-utils/paths.mjs +35 -1
  76. package/dist/powerlines/src/types/build.cjs +15 -1
  77. package/dist/powerlines/src/types/build.mjs +14 -1
  78. package/dist/powerlines/src/types/commands.cjs +16 -1
  79. package/dist/powerlines/src/types/commands.mjs +15 -1
  80. package/dist/powerlines/src/types/config.d.mts +1 -0
  81. package/dist/powerlines/src/types/context.d.cts +27 -3
  82. package/dist/powerlines/src/types/context.d.mts +27 -3
  83. package/dist/powerlines/src/types/plugin.cjs +32 -1
  84. package/dist/powerlines/src/types/plugin.mjs +31 -1
  85. package/dist/types/index.mjs +1 -1
  86. package/dist/types/plugin.mjs +1 -1
  87. package/package.json +9 -9
@@ -1 +1,84 @@
1
- import{declare as e}from"@babel/helper-plugin-utils";import*as t from"@babel/types";function n(e,n){if(!t.isStringLiteral(e.node))return;let r=n.context?.fs.resolveSync(e.node.value);r&&e.replaceWith(t.stringLiteral(r.replace(/\.(?:ts|mts|cts)x?$/,``)))}const r=[`require`,`require.resolve`,`System.import`,`jest.genMockFromModule`,`jest.mock`,`jest.unmock`,`jest.doMock`,`jest.dontMock`,`jest.setMock`,`jest.requireActual`,`jest.requireMock`,`require.requireActual`,`require.requireMock`];function i(e,n,r){let{node:i}=n;if(t.isMemberExpression(i))return n.matchesPattern(r);if(!t.isIdentifier(i)||r.includes(`.`))return!1;let a=r.split(`.`)[0];return i.name===a}const a={CallExpression:(e,a)=>{if(a.moduleResolverVisited.has(e))return;let o=e.get(`callee`);(o&&r.some(e=>i(a,o,e))||t.isImport(e.node.callee))&&(a.moduleResolverVisited.add(e),n(e.get(`arguments.0`),a))},"ImportDeclaration|ExportDeclaration|ExportAllDeclaration":(e,t)=>{!e||!e.get(`source`)||t.moduleResolverVisited.has(e)||(t.moduleResolverVisited.add(e),n(e.get(`source`),t))}},o=t=>e(function(e){let n=new Set;return{name:`powerlines:module-resolver`,manipulateOptions(e){e.filename??=`unknown`},pre(){n=new Set},visitor:{Program:{enter(r,i){r.traverse(a,{...i,context:t,moduleResolverVisited:n,api:e})},exit(r,i){r.traverse(a,{...i,context:t,moduleResolverVisited:n,api:e})}}},post(){n.clear()}}});export{o as moduleResolverBabelPlugin};
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 +1,52 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`defu`);t=e.__toESM(t);let n=require(`@stryke/string-format/title-case`);const r=`default`,i=`__GLOBAL__`;function a(e,r){return(0,t.default)(r.environments?.[e]??{},{name:e,title:r.title||(0,n.titleCase)(r.name),ssr:!1,mainFields:r.build?.platform===`browser`?[`browser`,`module`,`jsnext:main`,`jsnext`]:[`module`,`jsnext:main`,`jsnext`],extensions:[`.mjs`,`.js`,`.mts`,`.ts`,`.jsx`,`.tsx`,`.json`],consumer:r.build?.platform===`browser`?`client`:`server`,preview:r.build?.platform===`browser`?{port:5173,open:!0,strictPort:!1,host:`localhost`,allowedHosts:[`.`],cors:!0,headers:{}}:void 0},r)}function o(e){return a(`default`,e)}exports.GLOBAL_ENVIRONMENT=`__GLOBAL__`,exports.createDefaultEnvironment=o,exports.createEnvironment=a;
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 +1,48 @@
1
- import e from"defu";import{titleCase as t}from"@stryke/string-format/title-case";const n=`__GLOBAL__`;function r(n,r){return e(r.environments?.[n]??{},{name:n,title:r.title||t(r.name),ssr:!1,mainFields:r.build?.platform===`browser`?[`browser`,`module`,`jsnext:main`,`jsnext`]:[`module`,`jsnext:main`,`jsnext`],extensions:[`.mjs`,`.js`,`.mts`,`.ts`,`.jsx`,`.tsx`,`.json`],consumer:r.build?.platform===`browser`?`client`:`server`,preview:r.build?.platform===`browser`?{port:5173,open:!0,strictPort:!1,host:`localhost`,allowedHosts:[`.`],cors:!0,headers:{}}:void 0},r)}function i(e){return r(`default`,e)}export{n as GLOBAL_ENVIRONMENT,i as createDefaultEnvironment,r as createEnvironment};
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,8 +1,51 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../../lib/typescript/ts-morph.cjs`);let n=require(`@storm-software/config-tools/types`),r=require(`typescript`);function i(e){return e.replace(/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g,``).replaceAll(`#private;`,``).replace(/__Ω/g,``)}async function a(e,a){e.log(n.LogLevelLabel.TRACE,`Running the TypeScript compiler for ${a.length} generated runtime files.`);let o=t.createProgram(e,{skipAddingFilesFromTsConfig:!0});o.addSourceFilesAtPaths(a);let s=o.emitToMemory({emitOnlyDtsFiles:!0}),c=``;for(let t of s.getFiles())if(!t.filePath.endsWith(`.map`)&&e.builtins.some(n=>n===t.filePath||e.fs.metadata[n]?.id&&e.fs.metadata[n]?.id===t.filePath)){let n=await e.fs.resolve(t.filePath);c+=`
2
- declare module "${n}" {
3
- ${t.text.trim().replace(/^\s*export\s*declare\s*/gm,`export `).replace(/^\s*declare\s*/gm,``)}
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, "")}
4
35
  }
5
- `}let l=[];s.getDiagnostics().forEach(e=>{e.getSourceFile()?.getBaseName()?l.push(`${e.getSourceFile()?.getBaseName()} (${(e.getLineNumber()??0)+1}): ${(0,r.flattenDiagnosticMessageText)(e.getMessageText().toString(),`
6
- `)}`):l.push((0,r.flattenDiagnosticMessageText)(e.getMessageText().toString(),`
7
- `))});let u=l.join(`
8
- `);if(u)throw Error(`TypeScript compilation failed: \n\n${u.length>5e3?`${u.slice(0,5e3)}...`:u}`);return i(c)}exports.emitTypes=a,exports.formatTypes=i;
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,8 +1,49 @@
1
- import{createProgram as e}from"../../lib/typescript/ts-morph.mjs";import{LogLevelLabel as t}from"@storm-software/config-tools/types";import{flattenDiagnosticMessageText as n}from"typescript";function r(e){return e.replace(/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g,``).replaceAll(`#private;`,``).replace(/__Ω/g,``)}async function i(i,a){i.log(t.TRACE,`Running the TypeScript compiler for ${a.length} generated runtime files.`);let o=e(i,{skipAddingFilesFromTsConfig:!0});o.addSourceFilesAtPaths(a);let s=o.emitToMemory({emitOnlyDtsFiles:!0}),c=``;for(let e of s.getFiles())if(!e.filePath.endsWith(`.map`)&&i.builtins.some(t=>t===e.filePath||i.fs.metadata[t]?.id&&i.fs.metadata[t]?.id===e.filePath)){let t=await i.fs.resolve(e.filePath);c+=`
2
- declare module "${t}" {
3
- ${e.text.trim().replace(/^\s*export\s*declare\s*/gm,`export `).replace(/^\s*declare\s*/gm,``)}
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, "")}
4
34
  }
5
- `}let l=[];s.getDiagnostics().forEach(e=>{e.getSourceFile()?.getBaseName()?l.push(`${e.getSourceFile()?.getBaseName()} (${(e.getLineNumber()??0)+1}): ${n(e.getMessageText().toString(),`
6
- `)}`):l.push(n(e.getMessageText().toString(),`
7
- `))});let u=l.join(`
8
- `);if(u)throw Error(`TypeScript compilation failed: \n\n${u.length>5e3?`${u.slice(0,5e3)}...`:u}`);return r(c)}export{i as emitTypes,r as formatTypes};
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 +1,63 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`@storm-software/config-tools/types`),n=require(`defu`),r=require(`@stryke/type-checks/is-function`),i=require(`@stryke/type-checks/is-object`),a=require(`@stryke/type-checks/is-set`),o=require(`@stryke/type-checks/is-string`),s=require(`chalk`);s=e.__toESM(s);const c=(0,n.createDefu)((e,t,n)=>(0,o.isString)(e[t])&&(0,o.isString)(n)?(e[t]=`${e[t]||``}\n${n||``}`.trim(),!0):!1);async function l(e,l,u,...d){let f=e.selectHooks(l,u);if(f.length>0){e.log(t.LogLevelLabel.DEBUG,` 🧩 Calling plugin hook: ${s.default.bold.cyanBright(`${l}${u?.order?` (${u.order})`:``}`)}`);let p=[];if(u?.sequential===!1)p=await Promise.all(f.map(async e=>{if(!(0,r.isFunction)(e.handle))throw Error(`Plugin hook handler for hook "${l}" is not a function.`);return Promise.resolve(e.handle.apply(e.context,[...d]))}));else for(let e of f){if(!(0,r.isFunction)(e.handle))throw Error(`Plugin hook handler for hook "${l}" is not a function.`);if(u?.result===`first`||u?.asNextParam===!1){if(p.push(await Promise.resolve(e.handle.apply(e.context,[...d]))),u?.result===`first`&&(0,a.isSet)(p[p.length-1]))break}else{let t=[...d];p.length>0&&t.length>0&&(t[0]=(0,r.isFunction)(u.asNextParam)?await Promise.resolve(u.asNextParam(p[0])):p[0]);let n=await Promise.resolve(e.handle.apply(e.context,[...t]));n&&(u?.result===`last`?p=[n]:(0,o.isString)(n)?p=[`${(0,o.isString)(p[0])&&p[0]||``}\n${n||``}`.trim()]:(0,i.isObject)(n)&&(p=[c(n,p[0]??{})]))}}let m=p.filter(e=>(0,a.isSet)(e));if(m.length>0){let e;for(let t of m)e=(0,n.defu)(t,e??{});return e}}}exports.callHook=l;
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 +1,61 @@
1
- import{LogLevelLabel as e}from"@storm-software/config-tools/types";import{createDefu as t,defu as n}from"defu";import{isFunction as r}from"@stryke/type-checks/is-function";import{isObject as i}from"@stryke/type-checks/is-object";import{isSet as a}from"@stryke/type-checks/is-set";import{isString as o}from"@stryke/type-checks/is-string";import s from"chalk";const c=t((e,t,n)=>o(e[t])&&o(n)?(e[t]=`${e[t]||``}\n${n||``}`.trim(),!0):!1);async function l(t,l,u,...d){let f=t.selectHooks(l,u);if(f.length>0){t.log(e.DEBUG,` 🧩 Calling plugin hook: ${s.bold.cyanBright(`${l}${u?.order?` (${u.order})`:``}`)}`);let p=[];if(u?.sequential===!1)p=await Promise.all(f.map(async e=>{if(!r(e.handle))throw Error(`Plugin hook handler for hook "${l}" is not a function.`);return Promise.resolve(e.handle.apply(e.context,[...d]))}));else for(let e of f){if(!r(e.handle))throw Error(`Plugin hook handler for hook "${l}" is not a function.`);if(u?.result===`first`||u?.asNextParam===!1){if(p.push(await Promise.resolve(e.handle.apply(e.context,[...d]))),u?.result===`first`&&a(p[p.length-1]))break}else{let t=[...d];p.length>0&&t.length>0&&(t[0]=r(u.asNextParam)?await Promise.resolve(u.asNextParam(p[0])):p[0]);let n=await Promise.resolve(e.handle.apply(e.context,[...t]));n&&(u?.result===`last`?p=[n]:o(n)?p=[`${o(p[0])&&p[0]||``}\n${n||``}`.trim()]:i(n)&&(p=[c(n,p[0]??{})]))}}let m=p.filter(e=>a(e));if(m.length>0){let e;for(let t of m)e=n(t,e??{});return e}}}export{l as callHook};
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,3 +1,25 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`./install.cjs`);let n=require(`@storm-software/config-tools/types`),r=require(`@stryke/string-format/package`);async function i(e){if(e.log(n.LogLevelLabel.TRACE,`Checking and installing missing project dependencies.`),e.dependencies??={},e.devDependencies??={},Object.keys(e.dependencies).length===0&&Object.keys(e.devDependencies).length===0){e.log(n.LogLevelLabel.TRACE,`No dependencies or devDependencies to install. Skipping installation step.`);return}e.log(n.LogLevelLabel.DEBUG,`The following packages are required: \nDependencies: \n${Object.entries(e.dependencies).map(([e,t])=>`- ${e}@${String(t)}`).join(`
2
- `)}\n\nDevDependencies: \n${Object.entries(e.devDependencies).map(([e,t])=>`- ${e}@${String(t)}`).join(`
3
- `)}`),await Promise.all([Promise.all(Object.entries(e.dependencies).map(async([n,i])=>t.installPackage(e,`${(0,r.getPackageName)(n)}@${String(i)}`,!1))),Promise.all(Object.entries(e.devDependencies).map(async([n,i])=>t.installPackage(e,`${(0,r.getPackageName)(n)}@${String(i)}`,!0)))])}exports.installDependencies=i;
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,3 +1,24 @@
1
- import{installPackage as e}from"./install.mjs";import{LogLevelLabel as t}from"@storm-software/config-tools/types";import{getPackageName as n}from"@stryke/string-format/package";async function r(r){if(r.log(t.TRACE,`Checking and installing missing project dependencies.`),r.dependencies??={},r.devDependencies??={},Object.keys(r.dependencies).length===0&&Object.keys(r.devDependencies).length===0){r.log(t.TRACE,`No dependencies or devDependencies to install. Skipping installation step.`);return}r.log(t.DEBUG,`The following packages are required: \nDependencies: \n${Object.entries(r.dependencies).map(([e,t])=>`- ${e}@${String(t)}`).join(`
2
- `)}\n\nDevDependencies: \n${Object.entries(r.devDependencies).map(([e,t])=>`- ${e}@${String(t)}`).join(`
3
- `)}`),await Promise.all([Promise.all(Object.entries(r.dependencies).map(async([t,i])=>e(r,`${n(t)}@${String(i)}`,!1))),Promise.all(Object.entries(r.devDependencies).map(async([t,i])=>e(r,`${n(t)}@${String(i)}`,!0)))])}export{r as installDependencies};
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 +1,37 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`@storm-software/config-tools/types`),n=require(`@stryke/fs/install`),r=require(`@stryke/fs/package-fns`),i=require(`@stryke/type-checks/is-number`),a=require(`@stryke/string-format/package`);async function o(e,o,s=!1){if(await(0,r.isPackageListed)((0,a.getPackageName)(o),{cwd:e.config.projectRoot})){if((0,a.hasPackageVersion)(o)&&!process.env.POWERLINES_SKIP_VERSION_CHECK&&!await(0,r.doesPackageMatch)((0,a.getPackageName)(o),(0,a.getPackageVersion)(o),e.config.projectRoot)){let n=await(0,r.getPackageListing)((0,a.getPackageName)(o),{cwd:e.config.projectRoot});!n?.version.startsWith(`catalog:`)&&!n?.version.startsWith(`workspace:`)&&e.log(t.LogLevelLabel.WARN,`The package "${(0,a.getPackageName)(o)}" is installed but does not match the expected version ${(0,a.getPackageVersion)(o)} (installed version: ${n?.version||`<Unknown>`}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`)}}else if(e.config.skipInstalls!==!0){e.log(t.LogLevelLabel.WARN,`The package "${o}" is not installed. It will be installed automatically.`);let r=await(0,n.install)(o,{cwd:e.config.projectRoot,dev:s});if((0,i.isNumber)(r.exitCode)&&r.exitCode>0)throw e.log(t.LogLevelLabel.ERROR,r.stderr),Error(`An error occurred while installing the package "${o}"`)}else e.log(t.LogLevelLabel.WARN,`The package "${o}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`)}exports.installPackage=o;
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 +1,36 @@
1
- import{LogLevelLabel as e}from"@storm-software/config-tools/types";import{install as t}from"@stryke/fs/install";import{doesPackageMatch as n,getPackageListing as r,isPackageListed as i}from"@stryke/fs/package-fns";import{isNumber as a}from"@stryke/type-checks/is-number";import{getPackageName as o,getPackageVersion as s,hasPackageVersion as c}from"@stryke/string-format/package";async function l(l,u,d=!1){if(await i(o(u),{cwd:l.config.projectRoot})){if(c(u)&&!process.env.POWERLINES_SKIP_VERSION_CHECK&&!await n(o(u),s(u),l.config.projectRoot)){let t=await r(o(u),{cwd:l.config.projectRoot});!t?.version.startsWith(`catalog:`)&&!t?.version.startsWith(`workspace:`)&&l.log(e.WARN,`The package "${o(u)}" is installed but does not match the expected version ${s(u)} (installed version: ${t?.version||`<Unknown>`}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`)}}else if(l.config.skipInstalls!==!0){l.log(e.WARN,`The package "${u}" is not installed. It will be installed automatically.`);let n=await t(u,{cwd:l.config.projectRoot,dev:d});if(a(n.exitCode)&&n.exitCode>0)throw l.log(e.ERROR,n.stderr),Error(`An error occurred while installing the package "${u}"`)}else l.log(e.WARN,`The package "${u}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`)}export{l as installPackage};
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 };