@powerlines/plugin-unbuild 0.5.241 → 0.5.242

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 (39) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  2. package/dist/index.cjs +4 -3
  3. package/dist/index.d.cts +1 -2
  4. package/dist/index.d.mts +1 -1
  5. package/dist/index.mjs +1 -1
  6. package/dist/powerlines/src/internal/helpers/hooks.d.cts +47 -0
  7. package/dist/powerlines/src/internal/helpers/hooks.d.mts +49 -0
  8. package/dist/powerlines/src/lib/build/rollup.cjs +126 -0
  9. package/dist/powerlines/src/lib/build/rollup.mjs +119 -0
  10. package/dist/powerlines/src/lib/build/unbuild.cjs +126 -0
  11. package/dist/powerlines/src/lib/build/unbuild.mjs +123 -0
  12. package/dist/powerlines/src/lib/utilities/source-file.cjs +22 -0
  13. package/dist/powerlines/src/lib/utilities/source-file.mjs +21 -0
  14. package/dist/powerlines/src/types/api.d.cts +104 -0
  15. package/dist/powerlines/src/types/api.d.mts +104 -0
  16. package/dist/powerlines/src/types/babel.d.mts +2 -0
  17. package/dist/powerlines/src/types/build.d.cts +185 -0
  18. package/dist/powerlines/src/types/build.d.mts +185 -0
  19. package/dist/powerlines/src/types/commands.d.cts +8 -0
  20. package/dist/powerlines/src/types/commands.d.mts +9 -0
  21. package/dist/powerlines/src/types/config.d.cts +424 -0
  22. package/dist/powerlines/src/types/config.d.mts +424 -0
  23. package/dist/powerlines/src/types/context.d.cts +514 -0
  24. package/dist/powerlines/src/types/context.d.mts +514 -0
  25. package/dist/powerlines/src/types/fs.d.cts +486 -0
  26. package/dist/powerlines/src/types/fs.d.mts +486 -0
  27. package/dist/powerlines/src/types/hooks.d.cts +32 -0
  28. package/dist/powerlines/src/types/hooks.d.mts +32 -0
  29. package/dist/powerlines/src/types/plugin.d.cts +205 -0
  30. package/dist/powerlines/src/types/plugin.d.mts +205 -0
  31. package/dist/powerlines/src/types/resolved.d.cts +93 -0
  32. package/dist/powerlines/src/types/resolved.d.mts +93 -0
  33. package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
  34. package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
  35. package/dist/powerlines/src/types/unplugin.d.cts +22 -0
  36. package/dist/powerlines/src/types/unplugin.d.mts +23 -0
  37. package/dist/types/plugin.d.cts +3 -3
  38. package/dist/types/plugin.d.mts +3 -3
  39. package/package.json +4 -4
@@ -0,0 +1,29 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
package/dist/index.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
+ const require_unbuild = require('./powerlines/src/lib/build/unbuild.cjs');
2
4
  let __storm_software_unbuild = require("@storm-software/unbuild");
3
- let powerlines_lib_build_unbuild = require("powerlines/lib/build/unbuild");
4
5
 
5
6
  //#region src/index.ts
6
7
  /**
@@ -13,14 +14,14 @@ const plugin = (options = {}) => {
13
14
  return {
14
15
  output: { format: ["esm"] },
15
16
  build: {
16
- ...powerlines_lib_build_unbuild.DEFAULT_UNBUILD_CONFIG,
17
+ ...require_unbuild.DEFAULT_UNBUILD_CONFIG,
17
18
  ...options,
18
19
  variant: "unbuild"
19
20
  }
20
21
  };
21
22
  },
22
23
  async build() {
23
- await (0, __storm_software_unbuild.build)((0, powerlines_lib_build_unbuild.extractUnbuildConfig)(this));
24
+ await (0, __storm_software_unbuild.build)(require_unbuild.extractUnbuildConfig(this));
24
25
  }
25
26
  };
26
27
  };
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
+ import { Plugin } from "./powerlines/src/types/plugin.cjs";
1
2
  import { UnbuildPluginContext, UnbuildPluginOptions, UnbuildPluginResolvedConfig, __ΩUnbuildPluginContext, __ΩUnbuildPluginOptions, __ΩUnbuildPluginResolvedConfig } from "./types/plugin.cjs";
2
- import "./types/index.cjs";
3
- import { Plugin } from "powerlines/types/plugin";
4
3
 
5
4
  //#region src/index.d.ts
6
5
 
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
+ import { Plugin } from "./powerlines/src/types/plugin.mjs";
1
2
  import { UnbuildPluginContext, UnbuildPluginOptions, UnbuildPluginResolvedConfig, __ΩUnbuildPluginContext, __ΩUnbuildPluginOptions, __ΩUnbuildPluginResolvedConfig } from "./types/plugin.mjs";
2
3
  import "./types/index.mjs";
3
- import { Plugin } from "powerlines/types/plugin";
4
4
 
5
5
  //#region src/index.d.ts
6
6
 
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
+ import { DEFAULT_UNBUILD_CONFIG, extractUnbuildConfig } from "./powerlines/src/lib/build/unbuild.mjs";
1
2
  import { build } from "@storm-software/unbuild";
2
- import { DEFAULT_UNBUILD_CONFIG, extractUnbuildConfig } from "powerlines/lib/build/unbuild";
3
3
 
4
4
  //#region src/index.ts
5
5
  /**
@@ -0,0 +1,47 @@
1
+ import { SelectHooksOptions } from "../../types/context.cjs";
2
+ import { MaybePromise } from "@stryke/types/base";
3
+
4
+ //#region ../powerlines/src/internal/helpers/hooks.d.ts
5
+ type CallHookOptions = SelectHooksOptions & (({
6
+ /**
7
+ * Whether to call the hooks sequentially or in parallel.
8
+ *
9
+ * @defaultValue true
10
+ */
11
+ sequential?: true;
12
+ } & ({
13
+ /**
14
+ * How to handle multiple return values from hooks.
15
+ * - "merge": Merge all non-undefined return values (if they are objects).
16
+ * - "first": Return the first non-undefined value.
17
+ *
18
+ * @remarks
19
+ * Merging only works if the return values are objects.
20
+ *
21
+ * @defaultValue "merge"
22
+ */
23
+ result: "first";
24
+ } | {
25
+ /**
26
+ * How to handle multiple return values from hooks.
27
+ * - "merge": Merge all non-undefined return values (if they are objects).
28
+ * - "first": Return the first non-undefined value.
29
+ *
30
+ * @remarks
31
+ * Merging only works if the return values are objects.
32
+ *
33
+ * @defaultValue "merge"
34
+ */
35
+ result?: "merge" | "last";
36
+ /**
37
+ * An indicator specifying if the results of the previous hook should be provided as the **first** parameter of the next hook function, or a function to process the result of the previous hook function and pass the returned value as the next hook's **first** parameter
38
+ */
39
+ asNextParam?: false | ((previousResult: any) => MaybePromise<any>);
40
+ })) | {
41
+ /**
42
+ * Whether to call the hooks sequentially or in parallel.
43
+ */
44
+ sequential: false;
45
+ });
46
+ //#endregion
47
+ export { CallHookOptions };
@@ -0,0 +1,49 @@
1
+ import "../../types/hooks.mjs";
2
+ import "../../types/resolved.mjs";
3
+ import { SelectHooksOptions } from "../../types/context.mjs";
4
+ import { MaybePromise } from "@stryke/types/base";
5
+
6
+ //#region ../powerlines/src/internal/helpers/hooks.d.ts
7
+ type CallHookOptions = SelectHooksOptions & (({
8
+ /**
9
+ * Whether to call the hooks sequentially or in parallel.
10
+ *
11
+ * @defaultValue true
12
+ */
13
+ sequential?: true;
14
+ } & ({
15
+ /**
16
+ * How to handle multiple return values from hooks.
17
+ * - "merge": Merge all non-undefined return values (if they are objects).
18
+ * - "first": Return the first non-undefined value.
19
+ *
20
+ * @remarks
21
+ * Merging only works if the return values are objects.
22
+ *
23
+ * @defaultValue "merge"
24
+ */
25
+ result: "first";
26
+ } | {
27
+ /**
28
+ * How to handle multiple return values from hooks.
29
+ * - "merge": Merge all non-undefined return values (if they are objects).
30
+ * - "first": Return the first non-undefined value.
31
+ *
32
+ * @remarks
33
+ * Merging only works if the return values are objects.
34
+ *
35
+ * @defaultValue "merge"
36
+ */
37
+ result?: "merge" | "last";
38
+ /**
39
+ * An indicator specifying if the results of the previous hook should be provided as the **first** parameter of the next hook function, or a function to process the result of the previous hook function and pass the returned value as the next hook's **first** parameter
40
+ */
41
+ asNextParam?: false | ((previousResult: any) => MaybePromise<any>);
42
+ })) | {
43
+ /**
44
+ * Whether to call the hooks sequentially or in parallel.
45
+ */
46
+ sequential: false;
47
+ });
48
+ //#endregion
49
+ export { CallHookOptions };
@@ -0,0 +1,126 @@
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ let __stryke_helpers_omit = require("@stryke/helpers/omit");
3
+ let __stryke_path_join_paths = require("@stryke/path/join-paths");
4
+ let defu = require("defu");
5
+ defu = require_rolldown_runtime.__toESM(defu);
6
+ let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
7
+ let __rollup_plugin_alias = require("@rollup/plugin-alias");
8
+ __rollup_plugin_alias = require_rolldown_runtime.__toESM(__rollup_plugin_alias);
9
+ let __rollup_plugin_babel = require("@rollup/plugin-babel");
10
+ let __rollup_plugin_inject = require("@rollup/plugin-inject");
11
+ __rollup_plugin_inject = require_rolldown_runtime.__toESM(__rollup_plugin_inject);
12
+ let __rollup_plugin_node_resolve = require("@rollup/plugin-node-resolve");
13
+ __rollup_plugin_node_resolve = require_rolldown_runtime.__toESM(__rollup_plugin_node_resolve);
14
+ let __rollup_plugin_replace = require("@rollup/plugin-replace");
15
+ __rollup_plugin_replace = require_rolldown_runtime.__toESM(__rollup_plugin_replace);
16
+ let __stryke_convert_to_array = require("@stryke/convert/to-array");
17
+ let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
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: Object.entries(context.alias).reduce((ret, [id, path]) => {
76
+ if (!ret.find((e) => e.find === id)) ret.push({
77
+ find: id,
78
+ replacement: path
79
+ });
80
+ else context.warn(`Duplicate alias entry for '${id}' detected. The first entry will be used.`);
81
+ return ret;
82
+ }, []) }),
83
+ (0, __rollup_plugin_babel.getBabelInputPlugin)((0, defu.default)(context.config.transform.babel, {
84
+ caller: {
85
+ name: "powerlines",
86
+ supportsStaticESM: true
87
+ },
88
+ cwd: context.config.projectRoot,
89
+ babelrc: false,
90
+ extensions: [
91
+ ".js",
92
+ ".jsx",
93
+ ".ts",
94
+ ".tsx"
95
+ ],
96
+ babelHelpers: "bundled",
97
+ skipPreflightCheck: true,
98
+ exclude: /node_modules/
99
+ })),
100
+ (0, __rollup_plugin_node_resolve.default)({
101
+ moduleDirectories: ["node_modules"],
102
+ preferBuiltins: true
103
+ }),
104
+ dtsBundlePlugin
105
+ ].filter(Boolean)
106
+ }, 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 : {}, {
107
+ cache: !context.config.skipCache ? (0, __stryke_path_join_paths.joinPaths)(context.cachePath, "rollup") : false,
108
+ logLevel: context.config.logLevel,
109
+ output: [{
110
+ dir: context.config.output.buildPath,
111
+ format: "es",
112
+ entryFileNames: "[name].js",
113
+ preserveModules: true,
114
+ sourcemap: context.config.mode === "development"
115
+ }, {
116
+ dir: context.config.output.buildPath,
117
+ format: "cjs",
118
+ entryFileNames: "[name].cjs",
119
+ preserveModules: true,
120
+ sourcemap: context.config.mode === "development"
121
+ }]
122
+ });
123
+ }
124
+
125
+ //#endregion
126
+ exports.extractRollupConfig = extractRollupConfig;
@@ -0,0 +1,119 @@
1
+ import { omit } from "@stryke/helpers/omit";
2
+ import { joinPaths } from "@stryke/path/join-paths";
3
+ import defu from "defu";
4
+ import { isString } from "@stryke/type-checks/is-string";
5
+ import alias from "@rollup/plugin-alias";
6
+ import { getBabelInputPlugin } from "@rollup/plugin-babel";
7
+ import inject from "@rollup/plugin-inject";
8
+ import resolve from "@rollup/plugin-node-resolve";
9
+ import replace from "@rollup/plugin-replace";
10
+ import { toArray } from "@stryke/convert/to-array";
11
+ import { isFunction } from "@stryke/type-checks/is-function";
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({
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: Object.entries(context.alias).reduce((ret, [id, path]) => {
69
+ if (!ret.find((e) => e.find === id)) ret.push({
70
+ find: id,
71
+ replacement: path
72
+ });
73
+ else context.warn(`Duplicate alias entry for '${id}' detected. The first entry will be used.`);
74
+ return ret;
75
+ }, []) }),
76
+ getBabelInputPlugin(defu(context.config.transform.babel, {
77
+ caller: {
78
+ name: "powerlines",
79
+ supportsStaticESM: true
80
+ },
81
+ cwd: context.config.projectRoot,
82
+ babelrc: false,
83
+ extensions: [
84
+ ".js",
85
+ ".jsx",
86
+ ".ts",
87
+ ".tsx"
88
+ ],
89
+ babelHelpers: "bundled",
90
+ skipPreflightCheck: true,
91
+ exclude: /node_modules/
92
+ })),
93
+ resolve({
94
+ moduleDirectories: ["node_modules"],
95
+ preferBuiltins: true
96
+ }),
97
+ dtsBundlePlugin
98
+ ].filter(Boolean)
99
+ }, 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 : {}, {
100
+ cache: !context.config.skipCache ? joinPaths(context.cachePath, "rollup") : false,
101
+ logLevel: context.config.logLevel,
102
+ output: [{
103
+ dir: context.config.output.buildPath,
104
+ format: "es",
105
+ entryFileNames: "[name].js",
106
+ preserveModules: true,
107
+ sourcemap: context.config.mode === "development"
108
+ }, {
109
+ dir: context.config.output.buildPath,
110
+ format: "cjs",
111
+ entryFileNames: "[name].cjs",
112
+ preserveModules: true,
113
+ sourcemap: context.config.mode === "development"
114
+ }]
115
+ });
116
+ }
117
+
118
+ //#endregion
119
+ export { extractRollupConfig };
@@ -0,0 +1,126 @@
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ const require_source_file = require('../utilities/source-file.cjs');
3
+ const require_rollup = require('./rollup.cjs');
4
+ let __stryke_helpers_omit = require("@stryke/helpers/omit");
5
+ let __stryke_path_join_paths = require("@stryke/path/join-paths");
6
+ let __stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
7
+ let defu = require("defu");
8
+ defu = require_rolldown_runtime.__toESM(defu);
9
+ let esbuild = require("esbuild");
10
+
11
+ //#region ../powerlines/src/lib/build/unbuild.ts
12
+ const DEFAULT_UNBUILD_CONFIG = {
13
+ dts: true,
14
+ clean: false,
15
+ includeSrc: false,
16
+ treeShaking: true,
17
+ splitting: true,
18
+ stub: false,
19
+ watchOptions: {},
20
+ outputPath: "dist",
21
+ generatePackageJson: true,
22
+ banner: " ",
23
+ rollup: {
24
+ dts: {},
25
+ emitCJS: true,
26
+ replace: {},
27
+ resolve: {},
28
+ json: {},
29
+ esbuild: { target: "es2020" },
30
+ commonjs: {},
31
+ alias: {}
32
+ }
33
+ };
34
+ const unbuildLoader = (context) => {
35
+ return async (input, { options }) => {
36
+ if (!/\.(?:c|m)?[jt]sx?$/.test(input.path) || /\.d\.[cm]?ts$/.test(input.path)) return;
37
+ const output = [];
38
+ let contents = await input.getContents();
39
+ if (options.declaration && !input.srcPath?.match(/\.d\.[cm]?ts$/)) {
40
+ const extension$1 = `.d.${input.srcPath?.match(/(?<=\.)(?:c|m)(?=[jt]s$)/)?.[0] || ""}ts`;
41
+ output.push({
42
+ contents,
43
+ srcPath: input.srcPath,
44
+ path: input.path,
45
+ extension: extension$1,
46
+ declaration: true
47
+ });
48
+ }
49
+ let transformed = contents;
50
+ let result = await context.$$internal.callHook("transform", {
51
+ sequential: true,
52
+ order: "pre"
53
+ }, transformed, input.path);
54
+ if (result) transformed = result;
55
+ result = await context.$$internal.callHook("transform", {
56
+ sequential: true,
57
+ order: "normal"
58
+ }, require_source_file.getString(transformed), input.path);
59
+ if (result) transformed = result;
60
+ result = await context.$$internal.callHook("transform", {
61
+ sequential: true,
62
+ order: "post"
63
+ }, require_source_file.getString(transformed), input.path);
64
+ if (result) transformed = result;
65
+ if ([
66
+ ".ts",
67
+ ".mts",
68
+ ".cts"
69
+ ].includes(input.extension)) contents = await (0, esbuild.transform)(require_source_file.getString(transformed), {
70
+ ...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths")),
71
+ loader: "ts"
72
+ }).then((r) => r.code);
73
+ else if ([".tsx", ".jsx"].includes(input.extension)) contents = await (0, esbuild.transform)(require_source_file.getString(transformed), {
74
+ loader: input.extension === ".tsx" ? "tsx" : "jsx",
75
+ ...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths"))
76
+ }).then((r) => r.code);
77
+ const isCjs = options.format === "cjs";
78
+ if (isCjs) contents = context.resolver.transform({
79
+ source: contents,
80
+ retainLines: false
81
+ }).replace(/^exports.default = /gm, "module.exports = ").replace(/^var _default = exports.default = /gm, "module.exports = ").replace("module.exports = void 0;", "");
82
+ let extension = isCjs ? ".js" : ".mjs";
83
+ if (options.ext) extension = options.ext.startsWith(".") ? options.ext : `.${options.ext}`;
84
+ output.push({
85
+ contents,
86
+ path: input.path,
87
+ extension
88
+ });
89
+ return output;
90
+ };
91
+ };
92
+ /**
93
+ * Extracts the unbuild configuration from the context.
94
+ *
95
+ * @param context - The build context.
96
+ * @returns The resolved unbuild configuration.
97
+ */
98
+ function extractUnbuildConfig(context) {
99
+ return (0, defu.default)({ alias: context.alias }, context.config.build.variant === "unbuild" ? context.config.build.override : {}, context.config.build.variant === "unbuild" ? (0, __stryke_helpers_omit.omit)(context.config.build, ["override", "variant"]) : {}, {
100
+ projectName: context.config.name,
101
+ name: context.config.name,
102
+ orgName: (0, __stryke_type_checks_is_object.isObject)(context.workspaceConfig.organization) ? context.workspaceConfig.organization.name : context.workspaceConfig.organization,
103
+ sourceRoot: context.config.sourceRoot,
104
+ projectRoot: context.config.projectRoot,
105
+ outputPath: context.config.output.buildPath || "dist",
106
+ platform: context.config.build.platform,
107
+ external: context.builtins.reduce((ret, id) => {
108
+ if (!ret.includes(id)) ret.push(id);
109
+ return ret;
110
+ }, context.config.build.external ?? []),
111
+ loaders: [unbuildLoader(context)],
112
+ jiti: {
113
+ interopDefault: true,
114
+ fsCache: (0, __stryke_path_join_paths.joinPaths)(context.envPaths.cache, "jiti"),
115
+ moduleCache: true
116
+ },
117
+ rollup: require_rollup.extractRollupConfig(context),
118
+ debug: context.config.mode === "development",
119
+ minify: context.config.mode !== "development",
120
+ sourcemap: context.config.mode === "development"
121
+ }, DEFAULT_UNBUILD_CONFIG);
122
+ }
123
+
124
+ //#endregion
125
+ exports.DEFAULT_UNBUILD_CONFIG = DEFAULT_UNBUILD_CONFIG;
126
+ exports.extractUnbuildConfig = extractUnbuildConfig;
@@ -0,0 +1,123 @@
1
+ import { getString } from "../utilities/source-file.mjs";
2
+ import { extractRollupConfig } from "./rollup.mjs";
3
+ import { omit } from "@stryke/helpers/omit";
4
+ import { joinPaths } from "@stryke/path/join-paths";
5
+ import { isObject } from "@stryke/type-checks/is-object";
6
+ import defu from "defu";
7
+ import { transform } from "esbuild";
8
+
9
+ //#region ../powerlines/src/lib/build/unbuild.ts
10
+ const DEFAULT_UNBUILD_CONFIG = {
11
+ dts: true,
12
+ clean: false,
13
+ includeSrc: false,
14
+ treeShaking: true,
15
+ splitting: true,
16
+ stub: false,
17
+ watchOptions: {},
18
+ outputPath: "dist",
19
+ generatePackageJson: true,
20
+ banner: " ",
21
+ rollup: {
22
+ dts: {},
23
+ emitCJS: true,
24
+ replace: {},
25
+ resolve: {},
26
+ json: {},
27
+ esbuild: { target: "es2020" },
28
+ commonjs: {},
29
+ alias: {}
30
+ }
31
+ };
32
+ const unbuildLoader = (context) => {
33
+ return async (input, { options }) => {
34
+ if (!/\.(?:c|m)?[jt]sx?$/.test(input.path) || /\.d\.[cm]?ts$/.test(input.path)) return;
35
+ const output = [];
36
+ let contents = await input.getContents();
37
+ if (options.declaration && !input.srcPath?.match(/\.d\.[cm]?ts$/)) {
38
+ const extension$1 = `.d.${input.srcPath?.match(/(?<=\.)(?:c|m)(?=[jt]s$)/)?.[0] || ""}ts`;
39
+ output.push({
40
+ contents,
41
+ srcPath: input.srcPath,
42
+ path: input.path,
43
+ extension: extension$1,
44
+ declaration: true
45
+ });
46
+ }
47
+ let transformed = contents;
48
+ let result = await context.$$internal.callHook("transform", {
49
+ sequential: true,
50
+ order: "pre"
51
+ }, transformed, input.path);
52
+ if (result) transformed = result;
53
+ result = await context.$$internal.callHook("transform", {
54
+ sequential: true,
55
+ order: "normal"
56
+ }, getString(transformed), input.path);
57
+ if (result) transformed = result;
58
+ result = await context.$$internal.callHook("transform", {
59
+ sequential: true,
60
+ order: "post"
61
+ }, getString(transformed), input.path);
62
+ if (result) transformed = result;
63
+ if ([
64
+ ".ts",
65
+ ".mts",
66
+ ".cts"
67
+ ].includes(input.extension)) contents = await transform(getString(transformed), {
68
+ ...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths")),
69
+ loader: "ts"
70
+ }).then((r) => r.code);
71
+ else if ([".tsx", ".jsx"].includes(input.extension)) contents = await transform(getString(transformed), {
72
+ loader: input.extension === ".tsx" ? "tsx" : "jsx",
73
+ ...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths"))
74
+ }).then((r) => r.code);
75
+ const isCjs = options.format === "cjs";
76
+ if (isCjs) contents = context.resolver.transform({
77
+ source: contents,
78
+ retainLines: false
79
+ }).replace(/^exports.default = /gm, "module.exports = ").replace(/^var _default = exports.default = /gm, "module.exports = ").replace("module.exports = void 0;", "");
80
+ let extension = isCjs ? ".js" : ".mjs";
81
+ if (options.ext) extension = options.ext.startsWith(".") ? options.ext : `.${options.ext}`;
82
+ output.push({
83
+ contents,
84
+ path: input.path,
85
+ extension
86
+ });
87
+ return output;
88
+ };
89
+ };
90
+ /**
91
+ * Extracts the unbuild configuration from the context.
92
+ *
93
+ * @param context - The build context.
94
+ * @returns The resolved unbuild configuration.
95
+ */
96
+ function extractUnbuildConfig(context) {
97
+ return defu({ alias: context.alias }, context.config.build.variant === "unbuild" ? context.config.build.override : {}, context.config.build.variant === "unbuild" ? omit(context.config.build, ["override", "variant"]) : {}, {
98
+ projectName: context.config.name,
99
+ name: context.config.name,
100
+ orgName: isObject(context.workspaceConfig.organization) ? context.workspaceConfig.organization.name : context.workspaceConfig.organization,
101
+ sourceRoot: context.config.sourceRoot,
102
+ projectRoot: context.config.projectRoot,
103
+ outputPath: context.config.output.buildPath || "dist",
104
+ platform: context.config.build.platform,
105
+ external: context.builtins.reduce((ret, id) => {
106
+ if (!ret.includes(id)) ret.push(id);
107
+ return ret;
108
+ }, context.config.build.external ?? []),
109
+ loaders: [unbuildLoader(context)],
110
+ jiti: {
111
+ interopDefault: true,
112
+ fsCache: joinPaths(context.envPaths.cache, "jiti"),
113
+ moduleCache: true
114
+ },
115
+ rollup: extractRollupConfig(context),
116
+ debug: context.config.mode === "development",
117
+ minify: context.config.mode !== "development",
118
+ sourcemap: context.config.mode === "development"
119
+ }, DEFAULT_UNBUILD_CONFIG);
120
+ }
121
+
122
+ //#endregion
123
+ export { DEFAULT_UNBUILD_CONFIG, extractUnbuildConfig };