@powerlines/plugin-unbuild 0.5.232 → 0.5.233

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.
@@ -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.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Plugin } from "./powerlines/src/types/plugin.mjs";
2
2
  import { UnbuildPluginContext, UnbuildPluginOptions, UnbuildPluginResolvedConfig, __ΩUnbuildPluginContext, __ΩUnbuildPluginOptions, __ΩUnbuildPluginResolvedConfig } from "./types/plugin.mjs";
3
+ import "./types/index.mjs";
3
4
 
4
5
  //#region src/index.d.ts
5
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
  /**
@@ -1,3 +1,5 @@
1
+ import "../../types/hooks.mjs";
2
+ import "../../types/resolved.mjs";
1
3
  import { SelectHooksOptions } from "../../types/context.mjs";
2
4
  import { MaybePromise } from "@stryke/types/base";
3
5
 
@@ -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 };
@@ -0,0 +1,22 @@
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ require("@stryke/fs/read-file");
3
+ let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
4
+ let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
5
+ require("magic-string");
6
+
7
+ //#region ../powerlines/src/lib/utilities/source-file.ts
8
+ /**
9
+ * Get the string from the source.
10
+ *
11
+ * @param code - The source string or magic string.
12
+ * @returns The source string.
13
+ */
14
+ function getString(code) {
15
+ if (!code) return "";
16
+ if ((0, __stryke_type_checks_is_string.isString)(code)) return code;
17
+ if ((0, __stryke_type_checks_is_set_object.isSetObject)(code) && "code" in code) return code.code;
18
+ return code.toString();
19
+ }
20
+
21
+ //#endregion
22
+ exports.getString = getString;
@@ -0,0 +1,21 @@
1
+ import "@stryke/fs/read-file";
2
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
3
+ import { isString } from "@stryke/type-checks/is-string";
4
+ import "magic-string";
5
+
6
+ //#region ../powerlines/src/lib/utilities/source-file.ts
7
+ /**
8
+ * Get the string from the source.
9
+ *
10
+ * @param code - The source string or magic string.
11
+ * @returns The source string.
12
+ */
13
+ function getString(code) {
14
+ if (!code) return "";
15
+ if (isString(code)) return code;
16
+ if (isSetObject(code) && "code" in code) return code.code;
17
+ return code.toString();
18
+ }
19
+
20
+ //#endregion
21
+ export { getString };
@@ -0,0 +1,2 @@
1
+ import "./config.mjs";
2
+ import "./context.mjs";
@@ -1,9 +1,9 @@
1
+ import { BuildOptions } from "esbuild";
1
2
  import { OutputOptions, RollupOptions } from "rollup";
2
3
  import { UserConfig } from "@farmfe/core";
3
4
  import { Configuration } from "@rspack/core";
4
- import { BuildOptions } from "@storm-software/tsup/types";
5
+ import { BuildOptions as BuildOptions$1 } from "@storm-software/tsup/types";
5
6
  import { UnbuildOptions } from "@storm-software/unbuild/types";
6
- import { BuildOptions as BuildOptions$1 } from "esbuild";
7
7
  import { RolldownOptions } from "rolldown";
8
8
  import { UserConfig as UserConfig$1 } from "tsdown";
9
9
  import { DepOptimizationOptions, UserConfig as UserConfig$2 } from "vite";
@@ -153,8 +153,8 @@ interface BuildConfig {
153
153
  override?: Record<string, any>;
154
154
  }
155
155
  type BuildResolvedConfig = Omit<BuildConfig, "override">;
156
- type ESBuildBuildConfig = Omit<BuildOptions$1, "entryPoints" | "sourceRoot" | "platform" | "outdir" | "env" | "assets" | "external" | "inject" | "tsconfig" | "tsconfigRaw" | "logLevel"> & BuildConfig;
157
- type ESBuildResolvedBuildConfig = Omit<BuildOptions$1, "inject"> & BuildResolvedConfig;
156
+ type ESBuildBuildConfig = Omit<BuildOptions, "entryPoints" | "sourceRoot" | "platform" | "outdir" | "env" | "assets" | "external" | "inject" | "tsconfig" | "tsconfigRaw" | "logLevel"> & BuildConfig;
157
+ type ESBuildResolvedBuildConfig = Omit<BuildOptions, "inject"> & BuildResolvedConfig;
158
158
  type ViteBuildConfig = Omit<UserConfig$2, "entry" | "entryPoints" | "tsconfig" | "tsconfigRaw" | "environments" | "output"> & BuildConfig & {
159
159
  /**
160
160
  * Optimize deps config
@@ -173,8 +173,8 @@ type RollupBuildConfig = Omit<RollupOptions, "entry" | "external" | "input" | "o
173
173
  type RollupResolvedBuildConfig = RollupOptions & BuildResolvedConfig;
174
174
  type RolldownBuildConfig = Omit<RolldownOptions, "input" | "external" | "tsconfig" | "logLevel" | "output"> & BuildConfig;
175
175
  type RolldownResolvedBuildConfig = RolldownOptions & BuildResolvedConfig;
176
- type TsupBuildConfig = Partial<Omit<BuildOptions, "userOptions" | "tsconfig" | "tsconfigRaw" | "assets" | "outputPath" | "mode" | "format" | "platform" | "projectRoot" | "clean" | "env" | "entry" | "entryPoints" | "external" | "noExternal" | "skipNodeModulesBundle">> & BuildConfig;
177
- type TsupResolvedBuildConfig = BuildOptions & BuildResolvedConfig;
176
+ type TsupBuildConfig = Partial<Omit<BuildOptions$1, "userOptions" | "tsconfig" | "tsconfigRaw" | "assets" | "outputPath" | "mode" | "format" | "platform" | "projectRoot" | "clean" | "env" | "entry" | "entryPoints" | "external" | "noExternal" | "skipNodeModulesBundle">> & BuildConfig;
177
+ type TsupResolvedBuildConfig = BuildOptions$1 & BuildResolvedConfig;
178
178
  type TsdownBuildConfig = Partial<Omit<UserConfig$1, "name" | "outDir" | "clean" | "cwd" | "tsconfig" | "publicDir" | "copy" | "alias" | "format" | "platform" | "env" | "define" | "entry" | "external" | "noExternal" | "skipNodeModulesBundle">> & BuildConfig;
179
179
  type TsdownResolvedBuildConfig = UserConfig$1 & BuildResolvedConfig;
180
180
  type UnbuildBuildConfig = Partial<Omit<UnbuildOptions, "tsconfig" | "tsconfigRaw" | "assets" | "outputPath" | "mode" | "format" | "platform" | "projectRoot" | "env" | "entry" | "entryPoints">> & BuildConfig;
@@ -1,3 +1,4 @@
1
+ import "./context.mjs";
1
2
  import { ArrayValues } from "@stryke/types/array";
2
3
  import { MaybePromise } from "@stryke/types/base";
3
4
 
@@ -1,4 +1,5 @@
1
1
  import { BuildConfig, BuildResolvedConfig, ESBuildBuildConfig, ESBuildResolvedBuildConfig, FarmBuildConfig, FarmResolvedBuildConfig, RolldownBuildConfig, RolldownResolvedBuildConfig, RollupBuildConfig, RollupResolvedBuildConfig, RspackBuildConfig, RspackResolvedBuildConfig, TsdownBuildConfig, TsdownResolvedBuildConfig, TsupBuildConfig, TsupResolvedBuildConfig, UnbuildBuildConfig, UnbuildResolvedBuildConfig, ViteBuildConfig, ViteResolvedBuildConfig, WebpackBuildConfig, WebpackResolvedBuildConfig } from "./build.mjs";
2
+ import "./babel.mjs";
2
3
  import { StoragePort, StoragePreset } from "./fs.mjs";
3
4
  import { TSConfig } from "./tsconfig.mjs";
4
5
  import { PluginContext } from "./context.mjs";
@@ -13,7 +14,6 @@ import { AssetGlob } from "@stryke/types/file";
13
14
  import { DateString } from "compatx";
14
15
 
15
16
  //#region ../powerlines/src/types/config.d.ts
16
-
17
17
  type LogLevel = "error" | "warn" | "info" | "debug" | "trace";
18
18
  type LogFn = (type: LogLevelLabel, ...args: string[]) => void;
19
19
  /**
@@ -4,13 +4,13 @@ import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.mjs";
4
4
  import { HooksList, InferHooksListItem } from "./hooks.mjs";
5
5
  import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.mjs";
6
6
  import { Plugin } from "./plugin.mjs";
7
+ import { SourceMap } from "magic-string";
7
8
  import { NonUndefined } from "@stryke/types/base";
8
9
  import { ExternalIdResult, UnpluginBuildContext, UnpluginContext, UnpluginMessage } from "unplugin";
9
10
  import { EnvPaths } from "@stryke/env/get-env-paths";
10
11
  import { FetchRequestOptions } from "@stryke/http/fetch";
11
12
  import { PackageJson } from "@stryke/types/package-json";
12
13
  import { Jiti } from "jiti";
13
- import { SourceMap } from "magic-string";
14
14
  import { ParseResult, ParserOptions } from "oxc-parser";
15
15
  import { Range } from "semver";
16
16
  import { RequestInfo, Response } from "undici";
@@ -1,4 +1,5 @@
1
1
  import { BuilderVariant, InferUnpluginVariant, UnpluginBuilderVariant } from "./build.mjs";
2
+ import "./config.mjs";
2
3
  import { InferResolvedConfig } from "./resolved.mjs";
3
4
  import { Context } from "./context.mjs";
4
5
  import { API } from "./api.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-unbuild",
3
- "version": "0.5.232",
3
+ "version": "0.5.233",
4
4
  "type": "module",
5
5
  "description": "A package containing a Powerlines plugin to build projects using Unbuild.",
6
6
  "repository": {
@@ -149,9 +149,9 @@
149
149
  "powerlines": "^0.37.95"
150
150
  },
151
151
  "devDependencies": {
152
- "@powerlines/plugin-plugin": "^0.12.173",
152
+ "@powerlines/plugin-plugin": "^0.12.174",
153
153
  "@types/node": "^24.10.9"
154
154
  },
155
155
  "publishConfig": { "access": "public" },
156
- "gitHead": "f7483367fc2dba244e8d11af31db5b1071e0a888"
156
+ "gitHead": "2852dab8ff7cad2d1aa4a44d7fd2479d62f65d47"
157
157
  }