@powerlines/plugin-rollup 0.7.127 → 0.7.129

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 +38 -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/rollup.cjs +134 -1
  29. package/dist/powerlines/src/lib/build/rollup.mjs +127 -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 +10 -10
@@ -1,8 +1,98 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../../lib/typescript/tsconfig.cjs`);let n=require(`@stryke/path/join-paths`),r=require(`@storm-software/config-tools/types`),i=require(`@stryke/fs/package-fns`),a=require(`chalk`);a=e.__toESM(a);let o=require(`@donedeal0/superdiff`),s=require(`@stryke/fs/json`),c=require(`@stryke/json/storm-json`),l=require(`@stryke/path/file-path-fns`),u=require(`@stryke/string-format/title-case`);function d(e){return(0,n.joinPaths)((0,l.relativePath)((0,n.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.projectRoot),(0,l.findFilePath)(e.dtsPath)),(0,l.findFileName)(e.dtsPath))}async function f(e){let n=t.getParsedTypeScriptConfig(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig,e.config.tsconfigRaw),r=await(0,s.readJsonFile)(t.getTsconfigFilePath(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig));if(r.compilerOptions??={},e.config.output.dts!==!1){let n=d(e);r.include?.some(r=>t.isIncludeMatchFound(r,[e.dtsPath,n]))||(r.include??=[],r.include.push(n.startsWith(`./`)?n.slice(2):n))}return n.options.lib?.some(e=>[`lib.esnext.d.ts`,`lib.es2021.d.ts`,`lib.es2022.d.ts`,`lib.es2023.d.ts`].includes(e.toLowerCase()))||(r.compilerOptions.lib??=[],r.compilerOptions.lib.push(`esnext`)),n.options.esModuleInterop!==!0&&(r.compilerOptions.esModuleInterop=!0),n.options.isolatedModules!==!0&&(r.compilerOptions.isolatedModules=!0),e.config.build.platform===`node`&&(n.options.types?.some(e=>e.toLowerCase()===`node`||e.toLowerCase()===`@types/node`)||(r.compilerOptions.types??=[],r.compilerOptions.types.push(`node`))),r}async function p(e){if(e.log(r.LogLevelLabel.TRACE,`Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.`),!(0,i.isPackageExists)(`typescript`))throw Error(`The TypeScript package is not installed. Please install the package using the command: "npm install typescript --save-dev"`);let n=t.getTsconfigFilePath(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig);e.tsconfig.originalTsconfigJson=await(0,s.readJsonFile)(n),e.tsconfig.tsconfigJson=await f(e),e.log(r.LogLevelLabel.TRACE,`Writing updated TypeScript configuration (tsconfig.json) file to disk.`),await e.fs.write(n,c.StormJSON.stringify(e.tsconfig.tsconfigJson)),e.tsconfig=t.getParsedTypeScriptConfig(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig,e.config.tsconfigRaw,e.tsconfig.originalTsconfigJson)}async function m(e){let n=await(0,s.readJsonFile)(e.tsconfig.tsconfigFilePath);n?.compilerOptions?.types&&Array.isArray(n.compilerOptions.types)&&!n.compilerOptions.types.length&&delete n.compilerOptions.types;let i=(0,o.getObjectDiff)(e.tsconfig.originalTsconfigJson,n,{ignoreArrayOrder:!0,showOnly:{statuses:[`added`,`deleted`,`updated`],granularity:`deep`}}),l=[],d=(e,t)=>{if(e.status===`added`||e.status===`deleted`||e.status===`updated`)if(e.diff)for(let n of e.diff)d(n,t?`${t}.${e.property}`:e.property);else l.push({field:t?`${t}.${e.property}`:e.property,status:e.status,previous:e.status===`added`?`---`:c.StormJSON.stringify(e.previousValue),current:e.status===`deleted`?`---`:c.StormJSON.stringify(e.currentValue)})};for(let e of i.diff)d(e);if(l.length>0&&e.log(r.LogLevelLabel.WARN,`Updating the following configuration values in "${e.tsconfig.tsconfigFilePath}" file:
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ const require_tsconfig = require('../../lib/typescript/tsconfig.cjs');
3
+ let __stryke_path_join_paths = require("@stryke/path/join-paths");
4
+ let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
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");
2
13
 
3
- ${l.map((e,t)=>`${a.default.bold.whiteBright(`${t+1}. ${(0,u.titleCase)(e.status)} the ${e.field} field: `)}
4
- ${a.default.red(` - Previous: ${e.previous} `)}
5
- ${a.default.green(` - Updated: ${e.current} `)}
6
- `).join(`
7
- `)}
8
- `),await e.fs.write(e.tsconfig.tsconfigFilePath,c.StormJSON.stringify(n)),e.tsconfig=t.getParsedTypeScriptConfig(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig),!e.tsconfig)throw Error(`Failed to parse the TypeScript configuration file.`)}exports.getTsconfigDtsPath=d,exports.initializeTsconfig=p,exports.resolveTsconfig=m;
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;
@@ -1,8 +1,94 @@
1
- import{getParsedTypeScriptConfig as e,getTsconfigFilePath as t,isIncludeMatchFound as n}from"../../lib/typescript/tsconfig.mjs";import{joinPaths as r}from"@stryke/path/join-paths";import{LogLevelLabel as i}from"@storm-software/config-tools/types";import{isPackageExists as a}from"@stryke/fs/package-fns";import o from"chalk";import{getObjectDiff as s}from"@donedeal0/superdiff";import{readJsonFile as c}from"@stryke/fs/json";import{StormJSON as l}from"@stryke/json/storm-json";import{findFileName as u,findFilePath as d,relativePath as f}from"@stryke/path/file-path-fns";import{titleCase as p}from"@stryke/string-format/title-case";function m(e){return r(f(r(e.workspaceConfig.workspaceRoot,e.config.projectRoot),d(e.dtsPath)),u(e.dtsPath))}async function h(r){let i=e(r.workspaceConfig.workspaceRoot,r.config.projectRoot,r.config.tsconfig,r.config.tsconfigRaw),a=await c(t(r.workspaceConfig.workspaceRoot,r.config.projectRoot,r.config.tsconfig));if(a.compilerOptions??={},r.config.output.dts!==!1){let e=m(r);a.include?.some(t=>n(t,[r.dtsPath,e]))||(a.include??=[],a.include.push(e.startsWith(`./`)?e.slice(2):e))}return i.options.lib?.some(e=>[`lib.esnext.d.ts`,`lib.es2021.d.ts`,`lib.es2022.d.ts`,`lib.es2023.d.ts`].includes(e.toLowerCase()))||(a.compilerOptions.lib??=[],a.compilerOptions.lib.push(`esnext`)),i.options.esModuleInterop!==!0&&(a.compilerOptions.esModuleInterop=!0),i.options.isolatedModules!==!0&&(a.compilerOptions.isolatedModules=!0),r.config.build.platform===`node`&&(i.options.types?.some(e=>e.toLowerCase()===`node`||e.toLowerCase()===`@types/node`)||(a.compilerOptions.types??=[],a.compilerOptions.types.push(`node`))),a}async function g(n){if(n.log(i.TRACE,`Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.`),!a(`typescript`))throw Error(`The TypeScript package is not installed. Please install the package using the command: "npm install typescript --save-dev"`);let r=t(n.workspaceConfig.workspaceRoot,n.config.projectRoot,n.config.tsconfig);n.tsconfig.originalTsconfigJson=await c(r),n.tsconfig.tsconfigJson=await h(n),n.log(i.TRACE,`Writing updated TypeScript configuration (tsconfig.json) file to disk.`),await n.fs.write(r,l.stringify(n.tsconfig.tsconfigJson)),n.tsconfig=e(n.workspaceConfig.workspaceRoot,n.config.projectRoot,n.config.tsconfig,n.config.tsconfigRaw,n.tsconfig.originalTsconfigJson)}async function _(t){let n=await c(t.tsconfig.tsconfigFilePath);n?.compilerOptions?.types&&Array.isArray(n.compilerOptions.types)&&!n.compilerOptions.types.length&&delete n.compilerOptions.types;let r=s(t.tsconfig.originalTsconfigJson,n,{ignoreArrayOrder:!0,showOnly:{statuses:[`added`,`deleted`,`updated`],granularity:`deep`}}),a=[],u=(e,t)=>{if(e.status===`added`||e.status===`deleted`||e.status===`updated`)if(e.diff)for(let n of e.diff)u(n,t?`${t}.${e.property}`:e.property);else a.push({field:t?`${t}.${e.property}`:e.property,status:e.status,previous:e.status===`added`?`---`:l.stringify(e.previousValue),current:e.status===`deleted`?`---`:l.stringify(e.currentValue)})};for(let e of r.diff)u(e);if(a.length>0&&t.log(i.WARN,`Updating the following configuration values in "${t.tsconfig.tsconfigFilePath}" file:
1
+ import { getParsedTypeScriptConfig, getTsconfigFilePath, isIncludeMatchFound } from "../../lib/typescript/tsconfig.mjs";
2
+ import { joinPaths } from "@stryke/path/join-paths";
3
+ import { LogLevelLabel } from "@storm-software/config-tools/types";
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";
2
11
 
3
- ${a.map((e,t)=>`${o.bold.whiteBright(`${t+1}. ${p(e.status)} the ${e.field} field: `)}
4
- ${o.red(` - Previous: ${e.previous} `)}
5
- ${o.green(` - Updated: ${e.current} `)}
6
- `).join(`
7
- `)}
8
- `),await t.fs.write(t.tsconfig.tsconfigFilePath,l.stringify(n)),t.tsconfig=e(t.workspaceConfig.workspaceRoot,t.config.projectRoot,t.config.tsconfig),!t.tsconfig)throw Error(`Failed to parse the TypeScript configuration file.`)}export{m as getTsconfigDtsPath,g as initializeTsconfig,_ as resolveTsconfig};
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 };
@@ -1 +1,43 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`defu`);t=e.__toESM(t);let n=require(`@stryke/path/join-paths`),r=require(`jiti`);function i(e){return(0,t.default)(e,{interopDefault:!0,fsCache:e.mode===`development`?!1:(0,n.joinPaths)(e.cacheDir,`jiti`),moduleCache:e.mode!==`development`})}function a(e){return(0,r.createJiti)((0,n.joinPaths)(e.workspaceRoot,e.projectRoot),i({...e}))}function o(e){let t=(0,r.createJiti)((0,n.joinPaths)(e.workspaceRoot,e.projectRoot),i(e));return t.plugin=a(e),t}exports.createResolver=o;
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;
@@ -1 +1,41 @@
1
- import e from"defu";import{joinPaths as t}from"@stryke/path/join-paths";import{createJiti as n}from"jiti";function r(n){return e(n,{interopDefault:!0,fsCache:n.mode===`development`?!1:t(n.cacheDir,`jiti`),moduleCache:n.mode!==`development`})}function i(e){return n(t(e.workspaceRoot,e.projectRoot),r({...e}))}function a(e){let a=n(t(e.workspaceRoot,e.projectRoot),r(e));return a.plugin=i(e),a}export{a as createResolver};
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 };
@@ -1 +1,134 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`@stryke/convert/to-array`),n=require(`defu`);n=e.__toESM(n);let r=require(`@rollup/plugin-alias`);r=e.__toESM(r);let i=require(`@rollup/plugin-babel`),a=require(`@rollup/plugin-inject`);a=e.__toESM(a);let o=require(`@rollup/plugin-node-resolve`);o=e.__toESM(o);let s=require(`@rollup/plugin-replace`);s=e.__toESM(s);let c=require(`@stryke/helpers/omit`),l=require(`@stryke/path/join-paths`),u=require(`@stryke/type-checks/is-function`),d=require(`@stryke/type-checks/is-string`),f=require(`node:fs`),p=require(`rollup-plugin-typescript2`);p=e.__toESM(p);const m={name:`powerlines:dts-bundle`,async generateBundle(e,t){for(let[,e]of Object.entries(t)){if(e.type===`asset`||!e.isEntry||e.facadeModuleId==null)continue;let t=e.fileName.replace(/(?:\.cjs|\.mjs|\.esm\.js|\.cjs\.js|\.mjs\.js|\.js)$/,`.d.ts`),n=JSON.stringify(`./${e.facadeModuleId.replace(/\.[cm]?[jt]sx?$/,``)}`);this.emitFile({type:`asset`,fileName:t,source:e.exports.includes(`default`)?`export * from ${n};\nexport { default } from ${n};\n`:`export * from ${n};\n`})}}};function h(e){return(0,n.default)({input:(0,f.globSync)((0,t.toArray)(e.entry).map(e=>(0,d.isString)(e)?e:e.file)).flat(),external:(n,r,i)=>{let a=e.config.build.variant===`rollup`&&e.config.build.override.external?(0,u.isFunction)(e.config.build.override.external)?e.config.build.override.external:n=>(0,t.toArray)(e.config.build.override.external).includes(n):e.config.build.variant===`vite`&&e.config.build.override.build?.rollupOptions?.external?(0,u.isFunction)(e.config.build.override.build?.rollupOptions?.external)?e.config.build.override.build?.rollupOptions?.external:n=>(0,t.toArray)(e.config.build?.build?.rollupOptions?.external).includes(n):e.config.build.variant===`rollup`&&e.config.build.external?(0,u.isFunction)(e.config.build.external)?e.config.build.external:n=>(0,t.toArray)(e.config.build.external).includes(n):e.config.build.variant===`vite`&&e.config.build.build?.rollupOptions?.external?(0,u.isFunction)(e.config.build.build?.rollupOptions?.external)?e.config.build.build?.rollupOptions?.external:n=>(0,t.toArray)(e.config.build?.build?.rollupOptions?.external).includes(n):void 0;return(0,u.isFunction)(a)&&a(n,r,i)||e.config.build.external&&(0,t.toArray)(e.config.build.external).includes(n)?!0:e.config.build.noExternal&&(0,t.toArray)(e.config.build.noExternal).includes(n)?!1:e.builtins.includes(n)?e.config.projectType!==`application`:!e.config.build.skipNodeModulesBundle},plugins:[(0,p.default)({check:!1,tsconfig:e.tsconfig.tsconfigFilePath}),e.config.build.define&&Object.keys(e.config.build.define).length>0&&(0,s.default)({sourceMap:e.config.mode===`development`,preventAssignment:!0,...e.config.build.define??{}}),e.config.build.inject&&Object.keys(e.config.build.inject).length>0&&(0,a.default)({sourceMap:e.config.mode===`development`,...e.config.build.inject}),(0,r.default)({entries:e.builtins.reduce((t,n)=>{if(!t.find(e=>e.find===n)){let r=e.fs.ids[n];r&&t.push({find:n,replacement:r})}return t},e.config.build.alias?Array.isArray(e.config.build.alias)?e.config.build.alias:Object.entries(e.config.build.alias).reduce((e,[t,n])=>(e.find(e=>e.find===t)||e.push({find:t,replacement:n}),e),[]):[])}),(0,i.getBabelInputPlugin)((0,n.default)(e.config.transform.babel,{caller:{name:`powerlines`,supportsStaticESM:!0},cwd:e.config.projectRoot,babelrc:!1,extensions:[`.js`,`.jsx`,`.ts`,`.tsx`],babelHelpers:`bundled`,skipPreflightCheck:!0,exclude:/node_modules/})),(0,o.default)({moduleDirectories:[`node_modules`],preferBuiltins:!0}),m].filter(Boolean)},e.config.build.variant===`rollup`?e.config.build.override:{},e.config.build.variant===`vite`?e.config.build.override.build?.rollupOptions:{},e.config.build.variant===`rollup`?(0,c.omit)(e.config.build,[`override`,`variant`]):{},e.config.build.variant===`vite`?e.config.build.build?.rollupOptions:{},{cache:e.config.skipCache?!1:(0,l.joinPaths)(e.cachePath,`rollup`),logLevel:e.config.logLevel,output:[{dir:e.config.output.buildPath,format:`es`,entryFileNames:`[name].js`,preserveModules:!0,sourcemap:e.config.mode===`development`},{dir:e.config.output.buildPath,format:`cjs`,entryFileNames:`[name].cjs`,preserveModules:!0,sourcemap:e.config.mode===`development`}]})}exports.extractRollupConfig=h;
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ let __stryke_convert_to_array = require("@stryke/convert/to-array");
3
+ let defu = require("defu");
4
+ defu = require_rolldown_runtime.__toESM(defu);
5
+ let __rollup_plugin_alias = require("@rollup/plugin-alias");
6
+ __rollup_plugin_alias = require_rolldown_runtime.__toESM(__rollup_plugin_alias);
7
+ let __rollup_plugin_babel = require("@rollup/plugin-babel");
8
+ let __rollup_plugin_inject = require("@rollup/plugin-inject");
9
+ __rollup_plugin_inject = require_rolldown_runtime.__toESM(__rollup_plugin_inject);
10
+ let __rollup_plugin_node_resolve = require("@rollup/plugin-node-resolve");
11
+ __rollup_plugin_node_resolve = require_rolldown_runtime.__toESM(__rollup_plugin_node_resolve);
12
+ let __rollup_plugin_replace = require("@rollup/plugin-replace");
13
+ __rollup_plugin_replace = require_rolldown_runtime.__toESM(__rollup_plugin_replace);
14
+ let __stryke_helpers_omit = require("@stryke/helpers/omit");
15
+ let __stryke_path_join_paths = require("@stryke/path/join-paths");
16
+ let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
17
+ let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
18
+ let node_fs = require("node:fs");
19
+ let rollup_plugin_typescript2 = require("rollup-plugin-typescript2");
20
+ rollup_plugin_typescript2 = require_rolldown_runtime.__toESM(rollup_plugin_typescript2);
21
+
22
+ //#region ../powerlines/src/lib/build/rollup.ts
23
+ /**
24
+ * A Rollup plugin to bundle TypeScript declaration files (.d.ts) alongside the JavaScript output files.
25
+ *
26
+ * @remarks
27
+ * This plugin generates .d.ts files for each entry point in the bundle, ensuring that type definitions are available for consumers of the library.
28
+ */
29
+ const dtsBundlePlugin = {
30
+ name: "powerlines:dts-bundle",
31
+ async generateBundle(_opts, bundle) {
32
+ for (const [, file] of Object.entries(bundle)) {
33
+ if (file.type === "asset" || !file.isEntry || file.facadeModuleId == null) continue;
34
+ const dtsFileName = file.fileName.replace(/(?:\.cjs|\.mjs|\.esm\.js|\.cjs\.js|\.mjs\.js|\.js)$/, ".d.ts");
35
+ const relativeSourceDtsName = JSON.stringify(`./${file.facadeModuleId.replace(/\.[cm]?[jt]sx?$/, "")}`);
36
+ this.emitFile({
37
+ type: "asset",
38
+ fileName: dtsFileName,
39
+ source: file.exports.includes("default") ? `export * from ${relativeSourceDtsName};\nexport { default } from ${relativeSourceDtsName};\n` : `export * from ${relativeSourceDtsName};\n`
40
+ });
41
+ }
42
+ }
43
+ };
44
+ /**
45
+ * Resolves the options for [rollup](https://rollupjs.org).
46
+ *
47
+ * @param context - The build context.
48
+ * @returns The resolved options.
49
+ */
50
+ function extractRollupConfig(context) {
51
+ return (0, defu.default)({
52
+ input: (0, node_fs.globSync)((0, __stryke_convert_to_array.toArray)(context.entry).map((entry) => (0, __stryke_type_checks_is_string.isString)(entry) ? entry : entry.file)).flat(),
53
+ external: (source, importer, isResolved) => {
54
+ const externalFn = context.config.build.variant === "rollup" && context.config.build.override.external ? (0, __stryke_type_checks_is_function.isFunction)(context.config.build.override.external) ? context.config.build.override.external : (id) => (0, __stryke_convert_to_array.toArray)(context.config.build.override.external).includes(id) : context.config.build.variant === "vite" && context.config.build.override.build?.rollupOptions?.external ? (0, __stryke_type_checks_is_function.isFunction)(context.config.build.override.build?.rollupOptions?.external) ? context.config.build.override.build?.rollupOptions?.external : (id) => (0, __stryke_convert_to_array.toArray)(context.config.build?.build?.rollupOptions?.external).includes(id) : context.config.build.variant === "rollup" && context.config.build.external ? (0, __stryke_type_checks_is_function.isFunction)(context.config.build.external) ? context.config.build.external : (id) => (0, __stryke_convert_to_array.toArray)(context.config.build.external).includes(id) : context.config.build.variant === "vite" && context.config.build.build?.rollupOptions?.external ? (0, __stryke_type_checks_is_function.isFunction)(context.config.build.build?.rollupOptions?.external) ? context.config.build.build?.rollupOptions?.external : (id) => (0, __stryke_convert_to_array.toArray)(context.config.build?.build?.rollupOptions?.external).includes(id) : void 0;
55
+ if ((0, __stryke_type_checks_is_function.isFunction)(externalFn) && externalFn(source, importer, isResolved)) return true;
56
+ if (context.config.build.external && (0, __stryke_convert_to_array.toArray)(context.config.build.external).includes(source)) return true;
57
+ if (context.config.build.noExternal && (0, __stryke_convert_to_array.toArray)(context.config.build.noExternal).includes(source)) return false;
58
+ if (context.builtins.includes(source)) return context.config.projectType !== "application";
59
+ return !context.config.build.skipNodeModulesBundle;
60
+ },
61
+ plugins: [
62
+ (0, rollup_plugin_typescript2.default)({
63
+ check: false,
64
+ tsconfig: context.tsconfig.tsconfigFilePath
65
+ }),
66
+ context.config.build.define && Object.keys(context.config.build.define).length > 0 && (0, __rollup_plugin_replace.default)({
67
+ sourceMap: context.config.mode === "development",
68
+ preventAssignment: true,
69
+ ...context.config.build.define ?? {}
70
+ }),
71
+ context.config.build.inject && Object.keys(context.config.build.inject).length > 0 && (0, __rollup_plugin_inject.default)({
72
+ sourceMap: context.config.mode === "development",
73
+ ...context.config.build.inject
74
+ }),
75
+ (0, __rollup_plugin_alias.default)({ entries: context.builtins.reduce((ret, id) => {
76
+ if (!ret.find((e) => e.find === id)) {
77
+ const path = context.fs.ids[id];
78
+ if (path) ret.push({
79
+ find: id,
80
+ replacement: path
81
+ });
82
+ }
83
+ return ret;
84
+ }, context.config.build.alias ? Array.isArray(context.config.build.alias) ? context.config.build.alias : Object.entries(context.config.build.alias).reduce((ret, [id, path]) => {
85
+ if (!ret.find((e) => e.find === id)) ret.push({
86
+ find: id,
87
+ replacement: path
88
+ });
89
+ return ret;
90
+ }, []) : []) }),
91
+ (0, __rollup_plugin_babel.getBabelInputPlugin)((0, defu.default)(context.config.transform.babel, {
92
+ caller: {
93
+ name: "powerlines",
94
+ supportsStaticESM: true
95
+ },
96
+ cwd: context.config.projectRoot,
97
+ babelrc: false,
98
+ extensions: [
99
+ ".js",
100
+ ".jsx",
101
+ ".ts",
102
+ ".tsx"
103
+ ],
104
+ babelHelpers: "bundled",
105
+ skipPreflightCheck: true,
106
+ exclude: /node_modules/
107
+ })),
108
+ (0, __rollup_plugin_node_resolve.default)({
109
+ moduleDirectories: ["node_modules"],
110
+ preferBuiltins: true
111
+ }),
112
+ dtsBundlePlugin
113
+ ].filter(Boolean)
114
+ }, context.config.build.variant === "rollup" ? context.config.build.override : {}, context.config.build.variant === "vite" ? context.config.build.override.build?.rollupOptions : {}, context.config.build.variant === "rollup" ? (0, __stryke_helpers_omit.omit)(context.config.build, ["override", "variant"]) : {}, context.config.build.variant === "vite" ? context.config.build.build?.rollupOptions : {}, {
115
+ cache: !context.config.skipCache ? (0, __stryke_path_join_paths.joinPaths)(context.cachePath, "rollup") : false,
116
+ logLevel: context.config.logLevel,
117
+ output: [{
118
+ dir: context.config.output.buildPath,
119
+ format: "es",
120
+ entryFileNames: "[name].js",
121
+ preserveModules: true,
122
+ sourcemap: context.config.mode === "development"
123
+ }, {
124
+ dir: context.config.output.buildPath,
125
+ format: "cjs",
126
+ entryFileNames: "[name].cjs",
127
+ preserveModules: true,
128
+ sourcemap: context.config.mode === "development"
129
+ }]
130
+ });
131
+ }
132
+
133
+ //#endregion
134
+ exports.extractRollupConfig = extractRollupConfig;
@@ -1 +1,127 @@
1
- import{toArray as e}from"@stryke/convert/to-array";import t from"defu";import n from"@rollup/plugin-alias";import{getBabelInputPlugin as r}from"@rollup/plugin-babel";import i from"@rollup/plugin-inject";import a from"@rollup/plugin-node-resolve";import o from"@rollup/plugin-replace";import{omit as s}from"@stryke/helpers/omit";import{joinPaths as c}from"@stryke/path/join-paths";import{isFunction as l}from"@stryke/type-checks/is-function";import{isString as u}from"@stryke/type-checks/is-string";import{globSync as d}from"node:fs";import f from"rollup-plugin-typescript2";const p={name:`powerlines:dts-bundle`,async generateBundle(e,t){for(let[,e]of Object.entries(t)){if(e.type===`asset`||!e.isEntry||e.facadeModuleId==null)continue;let t=e.fileName.replace(/(?:\.cjs|\.mjs|\.esm\.js|\.cjs\.js|\.mjs\.js|\.js)$/,`.d.ts`),n=JSON.stringify(`./${e.facadeModuleId.replace(/\.[cm]?[jt]sx?$/,``)}`);this.emitFile({type:`asset`,fileName:t,source:e.exports.includes(`default`)?`export * from ${n};\nexport { default } from ${n};\n`:`export * from ${n};\n`})}}};function m(m){return t({input:d(e(m.entry).map(e=>u(e)?e:e.file)).flat(),external:(t,n,r)=>{let i=m.config.build.variant===`rollup`&&m.config.build.override.external?l(m.config.build.override.external)?m.config.build.override.external:t=>e(m.config.build.override.external).includes(t):m.config.build.variant===`vite`&&m.config.build.override.build?.rollupOptions?.external?l(m.config.build.override.build?.rollupOptions?.external)?m.config.build.override.build?.rollupOptions?.external:t=>e(m.config.build?.build?.rollupOptions?.external).includes(t):m.config.build.variant===`rollup`&&m.config.build.external?l(m.config.build.external)?m.config.build.external:t=>e(m.config.build.external).includes(t):m.config.build.variant===`vite`&&m.config.build.build?.rollupOptions?.external?l(m.config.build.build?.rollupOptions?.external)?m.config.build.build?.rollupOptions?.external:t=>e(m.config.build?.build?.rollupOptions?.external).includes(t):void 0;return l(i)&&i(t,n,r)||m.config.build.external&&e(m.config.build.external).includes(t)?!0:m.config.build.noExternal&&e(m.config.build.noExternal).includes(t)?!1:m.builtins.includes(t)?m.config.projectType!==`application`:!m.config.build.skipNodeModulesBundle},plugins:[f({check:!1,tsconfig:m.tsconfig.tsconfigFilePath}),m.config.build.define&&Object.keys(m.config.build.define).length>0&&o({sourceMap:m.config.mode===`development`,preventAssignment:!0,...m.config.build.define??{}}),m.config.build.inject&&Object.keys(m.config.build.inject).length>0&&i({sourceMap:m.config.mode===`development`,...m.config.build.inject}),n({entries:m.builtins.reduce((e,t)=>{if(!e.find(e=>e.find===t)){let n=m.fs.ids[t];n&&e.push({find:t,replacement:n})}return e},m.config.build.alias?Array.isArray(m.config.build.alias)?m.config.build.alias:Object.entries(m.config.build.alias).reduce((e,[t,n])=>(e.find(e=>e.find===t)||e.push({find:t,replacement:n}),e),[]):[])}),r(t(m.config.transform.babel,{caller:{name:`powerlines`,supportsStaticESM:!0},cwd:m.config.projectRoot,babelrc:!1,extensions:[`.js`,`.jsx`,`.ts`,`.tsx`],babelHelpers:`bundled`,skipPreflightCheck:!0,exclude:/node_modules/})),a({moduleDirectories:[`node_modules`],preferBuiltins:!0}),p].filter(Boolean)},m.config.build.variant===`rollup`?m.config.build.override:{},m.config.build.variant===`vite`?m.config.build.override.build?.rollupOptions:{},m.config.build.variant===`rollup`?s(m.config.build,[`override`,`variant`]):{},m.config.build.variant===`vite`?m.config.build.build?.rollupOptions:{},{cache:m.config.skipCache?!1:c(m.cachePath,`rollup`),logLevel:m.config.logLevel,output:[{dir:m.config.output.buildPath,format:`es`,entryFileNames:`[name].js`,preserveModules:!0,sourcemap:m.config.mode===`development`},{dir:m.config.output.buildPath,format:`cjs`,entryFileNames:`[name].cjs`,preserveModules:!0,sourcemap:m.config.mode===`development`}]})}export{m as extractRollupConfig};
1
+ import { toArray } from "@stryke/convert/to-array";
2
+ import defu$1 from "defu";
3
+ import alias from "@rollup/plugin-alias";
4
+ import { getBabelInputPlugin } from "@rollup/plugin-babel";
5
+ import inject from "@rollup/plugin-inject";
6
+ import resolve from "@rollup/plugin-node-resolve";
7
+ import replace from "@rollup/plugin-replace";
8
+ import { omit } from "@stryke/helpers/omit";
9
+ import { joinPaths } from "@stryke/path/join-paths";
10
+ import { isFunction } from "@stryke/type-checks/is-function";
11
+ import { isString } from "@stryke/type-checks/is-string";
12
+ import { globSync } from "node:fs";
13
+ import typescriptPlugin from "rollup-plugin-typescript2";
14
+
15
+ //#region ../powerlines/src/lib/build/rollup.ts
16
+ /**
17
+ * A Rollup plugin to bundle TypeScript declaration files (.d.ts) alongside the JavaScript output files.
18
+ *
19
+ * @remarks
20
+ * This plugin generates .d.ts files for each entry point in the bundle, ensuring that type definitions are available for consumers of the library.
21
+ */
22
+ const dtsBundlePlugin = {
23
+ name: "powerlines:dts-bundle",
24
+ async generateBundle(_opts, bundle) {
25
+ for (const [, file] of Object.entries(bundle)) {
26
+ if (file.type === "asset" || !file.isEntry || file.facadeModuleId == null) continue;
27
+ const dtsFileName = file.fileName.replace(/(?:\.cjs|\.mjs|\.esm\.js|\.cjs\.js|\.mjs\.js|\.js)$/, ".d.ts");
28
+ const relativeSourceDtsName = JSON.stringify(`./${file.facadeModuleId.replace(/\.[cm]?[jt]sx?$/, "")}`);
29
+ this.emitFile({
30
+ type: "asset",
31
+ fileName: dtsFileName,
32
+ source: file.exports.includes("default") ? `export * from ${relativeSourceDtsName};\nexport { default } from ${relativeSourceDtsName};\n` : `export * from ${relativeSourceDtsName};\n`
33
+ });
34
+ }
35
+ }
36
+ };
37
+ /**
38
+ * Resolves the options for [rollup](https://rollupjs.org).
39
+ *
40
+ * @param context - The build context.
41
+ * @returns The resolved options.
42
+ */
43
+ function extractRollupConfig(context) {
44
+ return defu$1({
45
+ input: globSync(toArray(context.entry).map((entry) => isString(entry) ? entry : entry.file)).flat(),
46
+ external: (source, importer, isResolved) => {
47
+ const externalFn = context.config.build.variant === "rollup" && context.config.build.override.external ? isFunction(context.config.build.override.external) ? context.config.build.override.external : (id) => toArray(context.config.build.override.external).includes(id) : context.config.build.variant === "vite" && context.config.build.override.build?.rollupOptions?.external ? isFunction(context.config.build.override.build?.rollupOptions?.external) ? context.config.build.override.build?.rollupOptions?.external : (id) => toArray(context.config.build?.build?.rollupOptions?.external).includes(id) : context.config.build.variant === "rollup" && context.config.build.external ? isFunction(context.config.build.external) ? context.config.build.external : (id) => toArray(context.config.build.external).includes(id) : context.config.build.variant === "vite" && context.config.build.build?.rollupOptions?.external ? isFunction(context.config.build.build?.rollupOptions?.external) ? context.config.build.build?.rollupOptions?.external : (id) => toArray(context.config.build?.build?.rollupOptions?.external).includes(id) : void 0;
48
+ if (isFunction(externalFn) && externalFn(source, importer, isResolved)) return true;
49
+ if (context.config.build.external && toArray(context.config.build.external).includes(source)) return true;
50
+ if (context.config.build.noExternal && toArray(context.config.build.noExternal).includes(source)) return false;
51
+ if (context.builtins.includes(source)) return context.config.projectType !== "application";
52
+ return !context.config.build.skipNodeModulesBundle;
53
+ },
54
+ plugins: [
55
+ typescriptPlugin({
56
+ check: false,
57
+ tsconfig: context.tsconfig.tsconfigFilePath
58
+ }),
59
+ context.config.build.define && Object.keys(context.config.build.define).length > 0 && replace({
60
+ sourceMap: context.config.mode === "development",
61
+ preventAssignment: true,
62
+ ...context.config.build.define ?? {}
63
+ }),
64
+ context.config.build.inject && Object.keys(context.config.build.inject).length > 0 && inject({
65
+ sourceMap: context.config.mode === "development",
66
+ ...context.config.build.inject
67
+ }),
68
+ alias({ entries: context.builtins.reduce((ret, id) => {
69
+ if (!ret.find((e) => e.find === id)) {
70
+ const path = context.fs.ids[id];
71
+ if (path) ret.push({
72
+ find: id,
73
+ replacement: path
74
+ });
75
+ }
76
+ return ret;
77
+ }, context.config.build.alias ? Array.isArray(context.config.build.alias) ? context.config.build.alias : Object.entries(context.config.build.alias).reduce((ret, [id, path]) => {
78
+ if (!ret.find((e) => e.find === id)) ret.push({
79
+ find: id,
80
+ replacement: path
81
+ });
82
+ return ret;
83
+ }, []) : []) }),
84
+ getBabelInputPlugin(defu$1(context.config.transform.babel, {
85
+ caller: {
86
+ name: "powerlines",
87
+ supportsStaticESM: true
88
+ },
89
+ cwd: context.config.projectRoot,
90
+ babelrc: false,
91
+ extensions: [
92
+ ".js",
93
+ ".jsx",
94
+ ".ts",
95
+ ".tsx"
96
+ ],
97
+ babelHelpers: "bundled",
98
+ skipPreflightCheck: true,
99
+ exclude: /node_modules/
100
+ })),
101
+ resolve({
102
+ moduleDirectories: ["node_modules"],
103
+ preferBuiltins: true
104
+ }),
105
+ dtsBundlePlugin
106
+ ].filter(Boolean)
107
+ }, context.config.build.variant === "rollup" ? context.config.build.override : {}, context.config.build.variant === "vite" ? context.config.build.override.build?.rollupOptions : {}, context.config.build.variant === "rollup" ? omit(context.config.build, ["override", "variant"]) : {}, context.config.build.variant === "vite" ? context.config.build.build?.rollupOptions : {}, {
108
+ cache: !context.config.skipCache ? joinPaths(context.cachePath, "rollup") : false,
109
+ logLevel: context.config.logLevel,
110
+ output: [{
111
+ dir: context.config.output.buildPath,
112
+ format: "es",
113
+ entryFileNames: "[name].js",
114
+ preserveModules: true,
115
+ sourcemap: context.config.mode === "development"
116
+ }, {
117
+ dir: context.config.output.buildPath,
118
+ format: "cjs",
119
+ entryFileNames: "[name].cjs",
120
+ preserveModules: true,
121
+ sourcemap: context.config.mode === "development"
122
+ }]
123
+ });
124
+ }
125
+
126
+ //#endregion
127
+ export { extractRollupConfig };