@powerlines/plugin-unbuild 0.5.133 → 0.5.135
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.
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/index.cjs +4 -305
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +1 -270
- package/dist/powerlines/src/lib/build/rollup.cjs +134 -0
- package/dist/powerlines/src/lib/build/rollup.mjs +127 -0
- package/dist/powerlines/src/lib/build/unbuild.cjs +135 -0
- package/dist/powerlines/src/lib/build/unbuild.mjs +132 -0
- package/dist/powerlines/src/lib/utilities/source-file.cjs +22 -0
- package/dist/powerlines/src/lib/utilities/source-file.mjs +21 -0
- package/dist/powerlines/src/types/babel.d.mts +2 -0
- package/dist/powerlines/src/types/build.d.cts +149 -0
- package/dist/powerlines/src/types/build.d.mts +150 -0
- package/dist/powerlines/src/types/commands.d.cts +8 -0
- package/dist/powerlines/src/types/commands.d.mts +9 -0
- package/dist/powerlines/src/types/config.d.cts +377 -0
- package/dist/powerlines/src/types/config.d.mts +377 -0
- package/dist/powerlines/src/types/context.d.cts +403 -0
- package/dist/powerlines/src/types/context.d.mts +405 -0
- package/dist/powerlines/src/types/fs.d.cts +486 -0
- package/dist/powerlines/src/types/fs.d.mts +486 -0
- package/dist/powerlines/src/types/hooks.d.mts +2 -0
- package/dist/powerlines/src/types/plugin.d.cts +231 -0
- package/dist/powerlines/src/types/plugin.d.mts +231 -0
- package/dist/powerlines/src/types/resolved.d.cts +82 -0
- package/dist/powerlines/src/types/resolved.d.mts +83 -0
- package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
- package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
- package/dist/types/index.cjs +0 -2
- package/dist/types/index.d.cts +1 -2
- package/dist/types/index.d.mts +1 -2
- package/dist/types/index.mjs +0 -3
- package/dist/types/plugin.cjs +0 -1
- package/dist/types/plugin.d.cts +12 -1
- package/dist/types/plugin.d.mts +12 -1
- package/dist/types/plugin.mjs +0 -2
- package/package.json +5 -5
- package/dist/index-BgAdqTbb.d.mts +0 -1
- package/dist/index-CEgs-Dz2.d.cts +0 -1
- package/dist/plugin-Bsywsksv.d.mts +0 -1770
- package/dist/plugin-C3MaN5jp.mjs +0 -1
- package/dist/plugin-D6biD8cM.d.cts +0 -1769
- package/dist/plugin-DHXHjv16.cjs +0 -0
- package/dist/types-CTUnla4x.mjs +0 -1
- package/dist/types-DHkg7xmX.cjs +0 -0
|
@@ -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,309 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
-
key = keys[i];
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: ((k) => from[k]).bind(null, key),
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
-
value: mod,
|
|
25
|
-
enumerable: true
|
|
26
|
-
}) : target, mod));
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
require('./plugin-DHXHjv16.cjs');
|
|
30
|
-
require('./types-DHkg7xmX.cjs');
|
|
2
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_unbuild = require('./powerlines/src/lib/build/unbuild.cjs');
|
|
31
4
|
let __storm_software_unbuild = require("@storm-software/unbuild");
|
|
32
|
-
let __stryke_helpers_omit = require("@stryke/helpers/omit");
|
|
33
|
-
let __stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
34
|
-
let __stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
|
|
35
|
-
let defu = require("defu");
|
|
36
|
-
defu = __toESM(defu);
|
|
37
|
-
let esbuild = require("esbuild");
|
|
38
|
-
require("@stryke/fs/read-file");
|
|
39
|
-
let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
40
|
-
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
41
|
-
require("magic-string");
|
|
42
|
-
let __rollup_plugin_alias = require("@rollup/plugin-alias");
|
|
43
|
-
__rollup_plugin_alias = __toESM(__rollup_plugin_alias);
|
|
44
|
-
let __rollup_plugin_babel = require("@rollup/plugin-babel");
|
|
45
|
-
let __rollup_plugin_inject = require("@rollup/plugin-inject");
|
|
46
|
-
__rollup_plugin_inject = __toESM(__rollup_plugin_inject);
|
|
47
|
-
let __rollup_plugin_node_resolve = require("@rollup/plugin-node-resolve");
|
|
48
|
-
__rollup_plugin_node_resolve = __toESM(__rollup_plugin_node_resolve);
|
|
49
|
-
let __rollup_plugin_replace = require("@rollup/plugin-replace");
|
|
50
|
-
__rollup_plugin_replace = __toESM(__rollup_plugin_replace);
|
|
51
|
-
let __stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
52
|
-
let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
53
|
-
let node_fs = require("node:fs");
|
|
54
|
-
let rollup_plugin_typescript2 = require("rollup-plugin-typescript2");
|
|
55
|
-
rollup_plugin_typescript2 = __toESM(rollup_plugin_typescript2);
|
|
56
|
-
|
|
57
|
-
//#region ../powerlines/src/lib/utilities/source-file.ts
|
|
58
|
-
/**
|
|
59
|
-
* Get the string from the source.
|
|
60
|
-
*
|
|
61
|
-
* @param code - The source string or magic string.
|
|
62
|
-
* @returns The source string.
|
|
63
|
-
*/
|
|
64
|
-
function getString(code) {
|
|
65
|
-
if (!code) return "";
|
|
66
|
-
if ((0, __stryke_type_checks_is_string.isString)(code)) return code;
|
|
67
|
-
if ((0, __stryke_type_checks_is_set_object.isSetObject)(code) && "code" in code) return code.code;
|
|
68
|
-
return code.toString();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region ../powerlines/src/lib/build/rollup.ts
|
|
73
|
-
/**
|
|
74
|
-
* A Rollup plugin to bundle TypeScript declaration files (.d.ts) alongside the JavaScript output files.
|
|
75
|
-
*
|
|
76
|
-
* @remarks
|
|
77
|
-
* This plugin generates .d.ts files for each entry point in the bundle, ensuring that type definitions are available for consumers of the library.
|
|
78
|
-
*/
|
|
79
|
-
const dtsBundlePlugin = {
|
|
80
|
-
name: "powerlines:dts-bundle",
|
|
81
|
-
async generateBundle(_opts, bundle) {
|
|
82
|
-
for (const [, file] of Object.entries(bundle)) {
|
|
83
|
-
if (file.type === "asset" || !file.isEntry || file.facadeModuleId == null) continue;
|
|
84
|
-
const dtsFileName = file.fileName.replace(/(?:\.cjs|\.mjs|\.esm\.js|\.cjs\.js|\.mjs\.js|\.js)$/, ".d.ts");
|
|
85
|
-
const relativeSourceDtsName = JSON.stringify(`./${file.facadeModuleId.replace(/\.[cm]?[jt]sx?$/, "")}`);
|
|
86
|
-
this.emitFile({
|
|
87
|
-
type: "asset",
|
|
88
|
-
fileName: dtsFileName,
|
|
89
|
-
source: file.exports.includes("default") ? `export * from ${relativeSourceDtsName};\nexport { default } from ${relativeSourceDtsName};\n` : `export * from ${relativeSourceDtsName};\n`
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Resolves the options for [rollup](https://rollupjs.org).
|
|
96
|
-
*
|
|
97
|
-
* @param context - The build context.
|
|
98
|
-
* @returns The resolved options.
|
|
99
|
-
*/
|
|
100
|
-
function extractRollupConfig(context) {
|
|
101
|
-
return (0, defu.default)({
|
|
102
|
-
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(),
|
|
103
|
-
external: (source, importer, isResolved) => {
|
|
104
|
-
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;
|
|
105
|
-
if ((0, __stryke_type_checks_is_function.isFunction)(externalFn) && externalFn(source, importer, isResolved)) return true;
|
|
106
|
-
if (context.config.build.external && (0, __stryke_convert_to_array.toArray)(context.config.build.external).includes(source)) return true;
|
|
107
|
-
if (context.config.build.noExternal && (0, __stryke_convert_to_array.toArray)(context.config.build.noExternal).includes(source)) return false;
|
|
108
|
-
if (context.builtins.includes(source)) return context.config.projectType !== "application";
|
|
109
|
-
return !context.config.build.skipNodeModulesBundle;
|
|
110
|
-
},
|
|
111
|
-
plugins: [
|
|
112
|
-
(0, rollup_plugin_typescript2.default)({
|
|
113
|
-
check: false,
|
|
114
|
-
tsconfig: context.tsconfig.tsconfigFilePath
|
|
115
|
-
}),
|
|
116
|
-
context.config.build.define && Object.keys(context.config.build.define).length > 0 && (0, __rollup_plugin_replace.default)({
|
|
117
|
-
sourceMap: context.config.mode === "development",
|
|
118
|
-
preventAssignment: true,
|
|
119
|
-
...context.config.build.define ?? {}
|
|
120
|
-
}),
|
|
121
|
-
context.config.build.inject && Object.keys(context.config.build.inject).length > 0 && (0, __rollup_plugin_inject.default)({
|
|
122
|
-
sourceMap: context.config.mode === "development",
|
|
123
|
-
...context.config.build.inject
|
|
124
|
-
}),
|
|
125
|
-
(0, __rollup_plugin_alias.default)({ entries: context.builtins.reduce((ret, id) => {
|
|
126
|
-
if (!ret.find((e) => e.find === id)) {
|
|
127
|
-
const path = context.fs.ids[id];
|
|
128
|
-
if (path) ret.push({
|
|
129
|
-
find: id,
|
|
130
|
-
replacement: path
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return ret;
|
|
134
|
-
}, context.config.build.alias ? Array.isArray(context.config.build.alias) ? context.config.build.alias : Object.entries(context.config.build.alias).reduce((ret, [id, path]) => {
|
|
135
|
-
if (!ret.find((e) => e.find === id)) ret.push({
|
|
136
|
-
find: id,
|
|
137
|
-
replacement: path
|
|
138
|
-
});
|
|
139
|
-
return ret;
|
|
140
|
-
}, []) : []) }),
|
|
141
|
-
(0, __rollup_plugin_babel.getBabelInputPlugin)((0, defu.default)(context.config.transform.babel, {
|
|
142
|
-
caller: {
|
|
143
|
-
name: "powerlines",
|
|
144
|
-
supportsStaticESM: true
|
|
145
|
-
},
|
|
146
|
-
cwd: context.config.projectRoot,
|
|
147
|
-
babelrc: false,
|
|
148
|
-
extensions: [
|
|
149
|
-
".js",
|
|
150
|
-
".jsx",
|
|
151
|
-
".ts",
|
|
152
|
-
".tsx"
|
|
153
|
-
],
|
|
154
|
-
babelHelpers: "bundled",
|
|
155
|
-
skipPreflightCheck: true,
|
|
156
|
-
exclude: /node_modules/
|
|
157
|
-
})),
|
|
158
|
-
(0, __rollup_plugin_node_resolve.default)({
|
|
159
|
-
moduleDirectories: ["node_modules"],
|
|
160
|
-
preferBuiltins: true
|
|
161
|
-
}),
|
|
162
|
-
dtsBundlePlugin
|
|
163
|
-
].filter(Boolean)
|
|
164
|
-
}, 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 : {}, {
|
|
165
|
-
cache: !context.config.skipCache ? (0, __stryke_path_join_paths.joinPaths)(context.cachePath, "rollup") : false,
|
|
166
|
-
logLevel: context.config.logLevel,
|
|
167
|
-
output: [{
|
|
168
|
-
dir: context.config.output.buildPath,
|
|
169
|
-
format: "es",
|
|
170
|
-
entryFileNames: "[name].js",
|
|
171
|
-
preserveModules: true,
|
|
172
|
-
sourcemap: context.config.mode === "development"
|
|
173
|
-
}, {
|
|
174
|
-
dir: context.config.output.buildPath,
|
|
175
|
-
format: "cjs",
|
|
176
|
-
entryFileNames: "[name].cjs",
|
|
177
|
-
preserveModules: true,
|
|
178
|
-
sourcemap: context.config.mode === "development"
|
|
179
|
-
}]
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
//#endregion
|
|
184
|
-
//#region ../powerlines/src/lib/build/unbuild.ts
|
|
185
|
-
const DEFAULT_UNBUILD_CONFIG = {
|
|
186
|
-
dts: true,
|
|
187
|
-
clean: false,
|
|
188
|
-
includeSrc: false,
|
|
189
|
-
treeShaking: true,
|
|
190
|
-
splitting: true,
|
|
191
|
-
stub: false,
|
|
192
|
-
watchOptions: {},
|
|
193
|
-
outputPath: "dist",
|
|
194
|
-
generatePackageJson: true,
|
|
195
|
-
banner: " ",
|
|
196
|
-
rollup: {
|
|
197
|
-
dts: {},
|
|
198
|
-
emitCJS: true,
|
|
199
|
-
replace: {},
|
|
200
|
-
resolve: {},
|
|
201
|
-
json: {},
|
|
202
|
-
esbuild: { target: "es2020" },
|
|
203
|
-
commonjs: {},
|
|
204
|
-
alias: {}
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
const unbuildLoader = (context) => {
|
|
208
|
-
return async (input, { options }) => {
|
|
209
|
-
if (!/\.(?:c|m)?[jt]sx?$/.test(input.path) || /\.d\.[cm]?ts$/.test(input.path)) return;
|
|
210
|
-
const output = [];
|
|
211
|
-
let contents = await input.getContents();
|
|
212
|
-
if (options.declaration && !input.srcPath?.match(/\.d\.[cm]?ts$/)) {
|
|
213
|
-
const extension$1 = `.d.${input.srcPath?.match(/(?<=\.)(?:c|m)(?=[jt]s$)/)?.[0] || ""}ts`;
|
|
214
|
-
output.push({
|
|
215
|
-
contents,
|
|
216
|
-
srcPath: input.srcPath,
|
|
217
|
-
path: input.path,
|
|
218
|
-
extension: extension$1,
|
|
219
|
-
declaration: true
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
let transformed = contents;
|
|
223
|
-
let result = await context.$$internal.callHook("transform", {
|
|
224
|
-
sequential: true,
|
|
225
|
-
order: "pre"
|
|
226
|
-
}, transformed, input.path);
|
|
227
|
-
if (result) transformed = result;
|
|
228
|
-
result = await context.$$internal.callHook("transform", {
|
|
229
|
-
sequential: true,
|
|
230
|
-
order: "normal"
|
|
231
|
-
}, getString(transformed), input.path);
|
|
232
|
-
if (result) transformed = result;
|
|
233
|
-
result = await context.$$internal.callHook("transform", {
|
|
234
|
-
sequential: true,
|
|
235
|
-
order: "post"
|
|
236
|
-
}, getString(transformed), input.path);
|
|
237
|
-
if (result) transformed = result;
|
|
238
|
-
if ([
|
|
239
|
-
".ts",
|
|
240
|
-
".mts",
|
|
241
|
-
".cts"
|
|
242
|
-
].includes(input.extension)) contents = await (0, esbuild.transform)(getString(transformed), {
|
|
243
|
-
...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths")),
|
|
244
|
-
loader: "ts"
|
|
245
|
-
}).then((r) => r.code);
|
|
246
|
-
else if ([".tsx", ".jsx"].includes(input.extension)) contents = await (0, esbuild.transform)(getString(transformed), {
|
|
247
|
-
loader: input.extension === ".tsx" ? "tsx" : "jsx",
|
|
248
|
-
...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths"))
|
|
249
|
-
}).then((r) => r.code);
|
|
250
|
-
const isCjs = options.format === "cjs";
|
|
251
|
-
if (isCjs) contents = context.resolver.transform({
|
|
252
|
-
source: contents,
|
|
253
|
-
retainLines: false
|
|
254
|
-
}).replace(/^exports.default = /gm, "module.exports = ").replace(/^var _default = exports.default = /gm, "module.exports = ").replace("module.exports = void 0;", "");
|
|
255
|
-
let extension = isCjs ? ".js" : ".mjs";
|
|
256
|
-
if (options.ext) extension = options.ext.startsWith(".") ? options.ext : `.${options.ext}`;
|
|
257
|
-
output.push({
|
|
258
|
-
contents,
|
|
259
|
-
path: input.path,
|
|
260
|
-
extension
|
|
261
|
-
});
|
|
262
|
-
return output;
|
|
263
|
-
};
|
|
264
|
-
};
|
|
265
|
-
/**
|
|
266
|
-
* Extracts the unbuild configuration from the context.
|
|
267
|
-
*
|
|
268
|
-
* @param context - The build context.
|
|
269
|
-
* @returns The resolved unbuild configuration.
|
|
270
|
-
*/
|
|
271
|
-
function extractUnbuildConfig(context) {
|
|
272
|
-
return (0, defu.default)({ alias: context.builtins.reduce((ret, id) => {
|
|
273
|
-
if (!ret[id]) {
|
|
274
|
-
const path = context.fs.ids[id];
|
|
275
|
-
if (path) ret[id] = path;
|
|
276
|
-
}
|
|
277
|
-
return ret;
|
|
278
|
-
}, context.config.build.alias ? Array.isArray(context.config.build.alias) ? context.config.build.alias.reduce((ret, alias$1) => {
|
|
279
|
-
if (!ret[alias$1.find.toString()]) ret[alias$1.find.toString()] = alias$1.replacement;
|
|
280
|
-
return ret;
|
|
281
|
-
}, {}) : context.config.build.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"]) : {}, {
|
|
282
|
-
projectName: context.config.name,
|
|
283
|
-
name: context.config.name,
|
|
284
|
-
orgName: (0, __stryke_type_checks_is_object.isObject)(context.workspaceConfig.organization) ? context.workspaceConfig.organization.name : context.workspaceConfig.organization,
|
|
285
|
-
sourceRoot: context.config.sourceRoot,
|
|
286
|
-
projectRoot: context.config.projectRoot,
|
|
287
|
-
outputPath: context.config.output.buildPath || "dist",
|
|
288
|
-
platform: context.config.build.platform,
|
|
289
|
-
external: context.builtins.reduce((ret, id) => {
|
|
290
|
-
if (!ret.includes(id)) ret.push(id);
|
|
291
|
-
return ret;
|
|
292
|
-
}, context.config.build.external ?? []),
|
|
293
|
-
loaders: [unbuildLoader(context)],
|
|
294
|
-
jiti: {
|
|
295
|
-
interopDefault: true,
|
|
296
|
-
fsCache: (0, __stryke_path_join_paths.joinPaths)(context.envPaths.cache, "jiti"),
|
|
297
|
-
moduleCache: true
|
|
298
|
-
},
|
|
299
|
-
rollup: extractRollupConfig(context),
|
|
300
|
-
debug: context.config.mode === "development",
|
|
301
|
-
minify: context.config.mode !== "development",
|
|
302
|
-
sourcemap: context.config.mode === "development"
|
|
303
|
-
}, DEFAULT_UNBUILD_CONFIG);
|
|
304
|
-
}
|
|
305
5
|
|
|
306
|
-
//#endregion
|
|
307
6
|
//#region src/index.ts
|
|
308
7
|
/**
|
|
309
8
|
* A Powerlines plugin to build projects using Unbuild.
|
|
@@ -315,14 +14,14 @@ const plugin = (options = {}) => {
|
|
|
315
14
|
return {
|
|
316
15
|
output: { format: ["esm"] },
|
|
317
16
|
build: {
|
|
318
|
-
...DEFAULT_UNBUILD_CONFIG,
|
|
17
|
+
...require_unbuild.DEFAULT_UNBUILD_CONFIG,
|
|
319
18
|
...options,
|
|
320
19
|
variant: "unbuild"
|
|
321
20
|
}
|
|
322
21
|
};
|
|
323
22
|
},
|
|
324
23
|
async build() {
|
|
325
|
-
await (0, __storm_software_unbuild.build)(extractUnbuildConfig(this));
|
|
24
|
+
await (0, __storm_software_unbuild.build)(require_unbuild.extractUnbuildConfig(this));
|
|
326
25
|
}
|
|
327
26
|
};
|
|
328
27
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
1
|
+
import { Plugin } from "./powerlines/src/types/plugin.cjs";
|
|
2
|
+
import { UnbuildPluginContext, UnbuildPluginOptions, UnbuildPluginResolvedConfig, __ΩUnbuildPluginContext, __ΩUnbuildPluginOptions, __ΩUnbuildPluginResolvedConfig } from "./types/plugin.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
5
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
1
|
+
import { Plugin } from "./powerlines/src/types/plugin.mjs";
|
|
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,275 +1,6 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./types-CTUnla4x.mjs";
|
|
1
|
+
import { DEFAULT_UNBUILD_CONFIG, extractUnbuildConfig } from "./powerlines/src/lib/build/unbuild.mjs";
|
|
3
2
|
import { build } from "@storm-software/unbuild";
|
|
4
|
-
import { omit } from "@stryke/helpers/omit";
|
|
5
|
-
import { joinPaths } from "@stryke/path/join-paths";
|
|
6
|
-
import { isObject } from "@stryke/type-checks/is-object";
|
|
7
|
-
import defu from "defu";
|
|
8
|
-
import { transform } from "esbuild";
|
|
9
|
-
import "@stryke/fs/read-file";
|
|
10
|
-
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
11
|
-
import { isString } from "@stryke/type-checks/is-string";
|
|
12
|
-
import "magic-string";
|
|
13
|
-
import alias from "@rollup/plugin-alias";
|
|
14
|
-
import { getBabelInputPlugin } from "@rollup/plugin-babel";
|
|
15
|
-
import inject from "@rollup/plugin-inject";
|
|
16
|
-
import resolve from "@rollup/plugin-node-resolve";
|
|
17
|
-
import replace from "@rollup/plugin-replace";
|
|
18
|
-
import { toArray } from "@stryke/convert/to-array";
|
|
19
|
-
import { isFunction } from "@stryke/type-checks/is-function";
|
|
20
|
-
import { globSync } from "node:fs";
|
|
21
|
-
import typescriptPlugin from "rollup-plugin-typescript2";
|
|
22
3
|
|
|
23
|
-
//#region ../powerlines/src/lib/utilities/source-file.ts
|
|
24
|
-
/**
|
|
25
|
-
* Get the string from the source.
|
|
26
|
-
*
|
|
27
|
-
* @param code - The source string or magic string.
|
|
28
|
-
* @returns The source string.
|
|
29
|
-
*/
|
|
30
|
-
function getString(code) {
|
|
31
|
-
if (!code) return "";
|
|
32
|
-
if (isString(code)) return code;
|
|
33
|
-
if (isSetObject(code) && "code" in code) return code.code;
|
|
34
|
-
return code.toString();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region ../powerlines/src/lib/build/rollup.ts
|
|
39
|
-
/**
|
|
40
|
-
* A Rollup plugin to bundle TypeScript declaration files (.d.ts) alongside the JavaScript output files.
|
|
41
|
-
*
|
|
42
|
-
* @remarks
|
|
43
|
-
* This plugin generates .d.ts files for each entry point in the bundle, ensuring that type definitions are available for consumers of the library.
|
|
44
|
-
*/
|
|
45
|
-
const dtsBundlePlugin = {
|
|
46
|
-
name: "powerlines:dts-bundle",
|
|
47
|
-
async generateBundle(_opts, bundle) {
|
|
48
|
-
for (const [, file] of Object.entries(bundle)) {
|
|
49
|
-
if (file.type === "asset" || !file.isEntry || file.facadeModuleId == null) continue;
|
|
50
|
-
const dtsFileName = file.fileName.replace(/(?:\.cjs|\.mjs|\.esm\.js|\.cjs\.js|\.mjs\.js|\.js)$/, ".d.ts");
|
|
51
|
-
const relativeSourceDtsName = JSON.stringify(`./${file.facadeModuleId.replace(/\.[cm]?[jt]sx?$/, "")}`);
|
|
52
|
-
this.emitFile({
|
|
53
|
-
type: "asset",
|
|
54
|
-
fileName: dtsFileName,
|
|
55
|
-
source: file.exports.includes("default") ? `export * from ${relativeSourceDtsName};\nexport { default } from ${relativeSourceDtsName};\n` : `export * from ${relativeSourceDtsName};\n`
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Resolves the options for [rollup](https://rollupjs.org).
|
|
62
|
-
*
|
|
63
|
-
* @param context - The build context.
|
|
64
|
-
* @returns The resolved options.
|
|
65
|
-
*/
|
|
66
|
-
function extractRollupConfig(context) {
|
|
67
|
-
return defu({
|
|
68
|
-
input: globSync(toArray(context.entry).map((entry) => isString(entry) ? entry : entry.file)).flat(),
|
|
69
|
-
external: (source, importer, isResolved) => {
|
|
70
|
-
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;
|
|
71
|
-
if (isFunction(externalFn) && externalFn(source, importer, isResolved)) return true;
|
|
72
|
-
if (context.config.build.external && toArray(context.config.build.external).includes(source)) return true;
|
|
73
|
-
if (context.config.build.noExternal && toArray(context.config.build.noExternal).includes(source)) return false;
|
|
74
|
-
if (context.builtins.includes(source)) return context.config.projectType !== "application";
|
|
75
|
-
return !context.config.build.skipNodeModulesBundle;
|
|
76
|
-
},
|
|
77
|
-
plugins: [
|
|
78
|
-
typescriptPlugin({
|
|
79
|
-
check: false,
|
|
80
|
-
tsconfig: context.tsconfig.tsconfigFilePath
|
|
81
|
-
}),
|
|
82
|
-
context.config.build.define && Object.keys(context.config.build.define).length > 0 && replace({
|
|
83
|
-
sourceMap: context.config.mode === "development",
|
|
84
|
-
preventAssignment: true,
|
|
85
|
-
...context.config.build.define ?? {}
|
|
86
|
-
}),
|
|
87
|
-
context.config.build.inject && Object.keys(context.config.build.inject).length > 0 && inject({
|
|
88
|
-
sourceMap: context.config.mode === "development",
|
|
89
|
-
...context.config.build.inject
|
|
90
|
-
}),
|
|
91
|
-
alias({ entries: context.builtins.reduce((ret, id) => {
|
|
92
|
-
if (!ret.find((e) => e.find === id)) {
|
|
93
|
-
const path = context.fs.ids[id];
|
|
94
|
-
if (path) ret.push({
|
|
95
|
-
find: id,
|
|
96
|
-
replacement: path
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return ret;
|
|
100
|
-
}, context.config.build.alias ? Array.isArray(context.config.build.alias) ? context.config.build.alias : Object.entries(context.config.build.alias).reduce((ret, [id, path]) => {
|
|
101
|
-
if (!ret.find((e) => e.find === id)) ret.push({
|
|
102
|
-
find: id,
|
|
103
|
-
replacement: path
|
|
104
|
-
});
|
|
105
|
-
return ret;
|
|
106
|
-
}, []) : []) }),
|
|
107
|
-
getBabelInputPlugin(defu(context.config.transform.babel, {
|
|
108
|
-
caller: {
|
|
109
|
-
name: "powerlines",
|
|
110
|
-
supportsStaticESM: true
|
|
111
|
-
},
|
|
112
|
-
cwd: context.config.projectRoot,
|
|
113
|
-
babelrc: false,
|
|
114
|
-
extensions: [
|
|
115
|
-
".js",
|
|
116
|
-
".jsx",
|
|
117
|
-
".ts",
|
|
118
|
-
".tsx"
|
|
119
|
-
],
|
|
120
|
-
babelHelpers: "bundled",
|
|
121
|
-
skipPreflightCheck: true,
|
|
122
|
-
exclude: /node_modules/
|
|
123
|
-
})),
|
|
124
|
-
resolve({
|
|
125
|
-
moduleDirectories: ["node_modules"],
|
|
126
|
-
preferBuiltins: true
|
|
127
|
-
}),
|
|
128
|
-
dtsBundlePlugin
|
|
129
|
-
].filter(Boolean)
|
|
130
|
-
}, 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 : {}, {
|
|
131
|
-
cache: !context.config.skipCache ? joinPaths(context.cachePath, "rollup") : false,
|
|
132
|
-
logLevel: context.config.logLevel,
|
|
133
|
-
output: [{
|
|
134
|
-
dir: context.config.output.buildPath,
|
|
135
|
-
format: "es",
|
|
136
|
-
entryFileNames: "[name].js",
|
|
137
|
-
preserveModules: true,
|
|
138
|
-
sourcemap: context.config.mode === "development"
|
|
139
|
-
}, {
|
|
140
|
-
dir: context.config.output.buildPath,
|
|
141
|
-
format: "cjs",
|
|
142
|
-
entryFileNames: "[name].cjs",
|
|
143
|
-
preserveModules: true,
|
|
144
|
-
sourcemap: context.config.mode === "development"
|
|
145
|
-
}]
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
//#endregion
|
|
150
|
-
//#region ../powerlines/src/lib/build/unbuild.ts
|
|
151
|
-
const DEFAULT_UNBUILD_CONFIG = {
|
|
152
|
-
dts: true,
|
|
153
|
-
clean: false,
|
|
154
|
-
includeSrc: false,
|
|
155
|
-
treeShaking: true,
|
|
156
|
-
splitting: true,
|
|
157
|
-
stub: false,
|
|
158
|
-
watchOptions: {},
|
|
159
|
-
outputPath: "dist",
|
|
160
|
-
generatePackageJson: true,
|
|
161
|
-
banner: " ",
|
|
162
|
-
rollup: {
|
|
163
|
-
dts: {},
|
|
164
|
-
emitCJS: true,
|
|
165
|
-
replace: {},
|
|
166
|
-
resolve: {},
|
|
167
|
-
json: {},
|
|
168
|
-
esbuild: { target: "es2020" },
|
|
169
|
-
commonjs: {},
|
|
170
|
-
alias: {}
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
const unbuildLoader = (context) => {
|
|
174
|
-
return async (input, { options }) => {
|
|
175
|
-
if (!/\.(?:c|m)?[jt]sx?$/.test(input.path) || /\.d\.[cm]?ts$/.test(input.path)) return;
|
|
176
|
-
const output = [];
|
|
177
|
-
let contents = await input.getContents();
|
|
178
|
-
if (options.declaration && !input.srcPath?.match(/\.d\.[cm]?ts$/)) {
|
|
179
|
-
const extension$1 = `.d.${input.srcPath?.match(/(?<=\.)(?:c|m)(?=[jt]s$)/)?.[0] || ""}ts`;
|
|
180
|
-
output.push({
|
|
181
|
-
contents,
|
|
182
|
-
srcPath: input.srcPath,
|
|
183
|
-
path: input.path,
|
|
184
|
-
extension: extension$1,
|
|
185
|
-
declaration: true
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
let transformed = contents;
|
|
189
|
-
let result = await context.$$internal.callHook("transform", {
|
|
190
|
-
sequential: true,
|
|
191
|
-
order: "pre"
|
|
192
|
-
}, transformed, input.path);
|
|
193
|
-
if (result) transformed = result;
|
|
194
|
-
result = await context.$$internal.callHook("transform", {
|
|
195
|
-
sequential: true,
|
|
196
|
-
order: "normal"
|
|
197
|
-
}, getString(transformed), input.path);
|
|
198
|
-
if (result) transformed = result;
|
|
199
|
-
result = await context.$$internal.callHook("transform", {
|
|
200
|
-
sequential: true,
|
|
201
|
-
order: "post"
|
|
202
|
-
}, getString(transformed), input.path);
|
|
203
|
-
if (result) transformed = result;
|
|
204
|
-
if ([
|
|
205
|
-
".ts",
|
|
206
|
-
".mts",
|
|
207
|
-
".cts"
|
|
208
|
-
].includes(input.extension)) contents = await transform(getString(transformed), {
|
|
209
|
-
...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths")),
|
|
210
|
-
loader: "ts"
|
|
211
|
-
}).then((r) => r.code);
|
|
212
|
-
else if ([".tsx", ".jsx"].includes(input.extension)) contents = await transform(getString(transformed), {
|
|
213
|
-
loader: input.extension === ".tsx" ? "tsx" : "jsx",
|
|
214
|
-
...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths"))
|
|
215
|
-
}).then((r) => r.code);
|
|
216
|
-
const isCjs = options.format === "cjs";
|
|
217
|
-
if (isCjs) contents = context.resolver.transform({
|
|
218
|
-
source: contents,
|
|
219
|
-
retainLines: false
|
|
220
|
-
}).replace(/^exports.default = /gm, "module.exports = ").replace(/^var _default = exports.default = /gm, "module.exports = ").replace("module.exports = void 0;", "");
|
|
221
|
-
let extension = isCjs ? ".js" : ".mjs";
|
|
222
|
-
if (options.ext) extension = options.ext.startsWith(".") ? options.ext : `.${options.ext}`;
|
|
223
|
-
output.push({
|
|
224
|
-
contents,
|
|
225
|
-
path: input.path,
|
|
226
|
-
extension
|
|
227
|
-
});
|
|
228
|
-
return output;
|
|
229
|
-
};
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Extracts the unbuild configuration from the context.
|
|
233
|
-
*
|
|
234
|
-
* @param context - The build context.
|
|
235
|
-
* @returns The resolved unbuild configuration.
|
|
236
|
-
*/
|
|
237
|
-
function extractUnbuildConfig(context) {
|
|
238
|
-
return defu({ alias: context.builtins.reduce((ret, id) => {
|
|
239
|
-
if (!ret[id]) {
|
|
240
|
-
const path = context.fs.ids[id];
|
|
241
|
-
if (path) ret[id] = path;
|
|
242
|
-
}
|
|
243
|
-
return ret;
|
|
244
|
-
}, context.config.build.alias ? Array.isArray(context.config.build.alias) ? context.config.build.alias.reduce((ret, alias$1) => {
|
|
245
|
-
if (!ret[alias$1.find.toString()]) ret[alias$1.find.toString()] = alias$1.replacement;
|
|
246
|
-
return ret;
|
|
247
|
-
}, {}) : context.config.build.alias : {}) }, context.config.build.variant === "unbuild" ? context.config.build.override : {}, context.config.build.variant === "unbuild" ? omit(context.config.build, ["override", "variant"]) : {}, {
|
|
248
|
-
projectName: context.config.name,
|
|
249
|
-
name: context.config.name,
|
|
250
|
-
orgName: isObject(context.workspaceConfig.organization) ? context.workspaceConfig.organization.name : context.workspaceConfig.organization,
|
|
251
|
-
sourceRoot: context.config.sourceRoot,
|
|
252
|
-
projectRoot: context.config.projectRoot,
|
|
253
|
-
outputPath: context.config.output.buildPath || "dist",
|
|
254
|
-
platform: context.config.build.platform,
|
|
255
|
-
external: context.builtins.reduce((ret, id) => {
|
|
256
|
-
if (!ret.includes(id)) ret.push(id);
|
|
257
|
-
return ret;
|
|
258
|
-
}, context.config.build.external ?? []),
|
|
259
|
-
loaders: [unbuildLoader(context)],
|
|
260
|
-
jiti: {
|
|
261
|
-
interopDefault: true,
|
|
262
|
-
fsCache: joinPaths(context.envPaths.cache, "jiti"),
|
|
263
|
-
moduleCache: true
|
|
264
|
-
},
|
|
265
|
-
rollup: extractRollupConfig(context),
|
|
266
|
-
debug: context.config.mode === "development",
|
|
267
|
-
minify: context.config.mode !== "development",
|
|
268
|
-
sourcemap: context.config.mode === "development"
|
|
269
|
-
}, DEFAULT_UNBUILD_CONFIG);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
//#endregion
|
|
273
4
|
//#region src/index.ts
|
|
274
5
|
/**
|
|
275
6
|
* A Powerlines plugin to build projects using Unbuild.
|