bunup 0.8.2 → 0.8.4
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/cli.js +1295 -18
- package/dist/index.cjs +683 -5
- package/dist/index.js +654 -5
- package/dist/plugins.cjs +606 -7
- package/dist/plugins.d.cts +12 -1
- package/dist/plugins.d.ts +12 -1
- package/dist/plugins.js +579 -7
- package/package.json +9 -4
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,684 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
// @bun @bun-cjs
|
|
3
|
-
(function(exports, require, module, __filename, __dirname) {var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
+
for (let key of __getOwnPropNames(mod))
|
|
12
|
+
if (!__hasOwnProp.call(to, key))
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => mod[key],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
20
|
+
var __toCommonJS = (from) => {
|
|
21
|
+
var entry = __moduleCache.get(from), desc;
|
|
22
|
+
if (entry)
|
|
23
|
+
return entry;
|
|
24
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
26
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
27
|
+
get: () => from[key],
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
}));
|
|
30
|
+
__moduleCache.set(from, entry);
|
|
31
|
+
return entry;
|
|
32
|
+
};
|
|
33
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
34
|
+
var __export = (target, all) => {
|
|
35
|
+
for (var name in all)
|
|
36
|
+
__defProp(target, name, {
|
|
37
|
+
get: all[name],
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
set: (newValue) => all[name] = () => newValue
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// node_modules/picocolors/picocolors.js
|
|
45
|
+
var require_picocolors = __commonJS((exports2, module2) => {
|
|
46
|
+
var p = process || {};
|
|
47
|
+
var argv = p.argv || [];
|
|
48
|
+
var env = p.env || {};
|
|
49
|
+
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
50
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
51
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
52
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
53
|
+
};
|
|
54
|
+
var replaceClose = (string, close, replace, index) => {
|
|
55
|
+
let result = "", cursor = 0;
|
|
56
|
+
do {
|
|
57
|
+
result += string.substring(cursor, index) + replace;
|
|
58
|
+
cursor = index + close.length;
|
|
59
|
+
index = string.indexOf(close, cursor);
|
|
60
|
+
} while (~index);
|
|
61
|
+
return result + string.substring(cursor);
|
|
62
|
+
};
|
|
63
|
+
var createColors = (enabled = isColorSupported) => {
|
|
64
|
+
let f = enabled ? formatter : () => String;
|
|
65
|
+
return {
|
|
66
|
+
isColorSupported: enabled,
|
|
67
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
68
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
69
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
70
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
71
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
72
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
73
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
74
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
75
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
76
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
77
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
78
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
79
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
80
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
81
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
82
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
83
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
84
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
85
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
86
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
87
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
88
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
89
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
90
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
91
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
92
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
93
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
94
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
95
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
96
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
97
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
98
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
99
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
100
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
101
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
102
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
103
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
104
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
105
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
106
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
107
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
module2.exports = createColors();
|
|
111
|
+
module2.exports.createColors = createColors;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// src/index.ts
|
|
115
|
+
var exports_src = {};
|
|
116
|
+
__export(exports_src, {
|
|
117
|
+
defineWorkspace: () => defineWorkspace,
|
|
118
|
+
defineConfig: () => defineConfig,
|
|
119
|
+
build: () => build
|
|
120
|
+
});
|
|
121
|
+
module.exports = __toCommonJS(exports_src);
|
|
122
|
+
|
|
123
|
+
// src/define.ts
|
|
124
|
+
function defineConfig(options) {
|
|
125
|
+
return options;
|
|
126
|
+
}
|
|
127
|
+
function defineWorkspace(options) {
|
|
128
|
+
return options;
|
|
129
|
+
}
|
|
130
|
+
// src/build.ts
|
|
131
|
+
var import_node_path2 = __toESM(require("path"));
|
|
132
|
+
var import_bun_dts = require("bun-dts");
|
|
133
|
+
|
|
134
|
+
// src/errors.ts
|
|
135
|
+
var import_picocolors2 = __toESM(require_picocolors());
|
|
136
|
+
|
|
137
|
+
// src/logger.ts
|
|
138
|
+
var import_picocolors = __toESM(require_picocolors());
|
|
139
|
+
var silent = false;
|
|
140
|
+
function setSilent(value) {
|
|
141
|
+
silent = value ?? false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
class Logger {
|
|
145
|
+
static instance;
|
|
146
|
+
loggedOnceMessages = new Set;
|
|
147
|
+
MAX_LABEL_LENGTH = 3;
|
|
148
|
+
cliColor = import_picocolors.default.blue;
|
|
149
|
+
mutedColor = import_picocolors.default.dim;
|
|
150
|
+
infoColor = import_picocolors.default.cyan;
|
|
151
|
+
warnColor = import_picocolors.default.yellow;
|
|
152
|
+
errorColor = import_picocolors.default.red;
|
|
153
|
+
defaultColor = import_picocolors.default.white;
|
|
154
|
+
progressFgColorMap = {
|
|
155
|
+
ESM: import_picocolors.default.yellow,
|
|
156
|
+
CJS: import_picocolors.default.green,
|
|
157
|
+
IIFE: import_picocolors.default.magenta,
|
|
158
|
+
DTS: import_picocolors.default.blue
|
|
159
|
+
};
|
|
160
|
+
progressIdentifierBgColorMap = {
|
|
161
|
+
ESM: import_picocolors.default.bgYellow,
|
|
162
|
+
CJS: import_picocolors.default.bgGreen,
|
|
163
|
+
IIFE: import_picocolors.default.bgMagenta,
|
|
164
|
+
DTS: import_picocolors.default.bgBlue
|
|
165
|
+
};
|
|
166
|
+
labels = {
|
|
167
|
+
cli: "CLI",
|
|
168
|
+
info: "INFO",
|
|
169
|
+
warn: "WARN",
|
|
170
|
+
error: "ERROR"
|
|
171
|
+
};
|
|
172
|
+
constructor() {}
|
|
173
|
+
static getInstance() {
|
|
174
|
+
if (!Logger.instance) {
|
|
175
|
+
Logger.instance = new Logger;
|
|
176
|
+
}
|
|
177
|
+
return Logger.instance;
|
|
178
|
+
}
|
|
179
|
+
dispose() {
|
|
180
|
+
this.loggedOnceMessages.clear();
|
|
181
|
+
}
|
|
182
|
+
shouldLog(options) {
|
|
183
|
+
if (!options?.once)
|
|
184
|
+
return true;
|
|
185
|
+
if (this.loggedOnceMessages.has(options.once))
|
|
186
|
+
return false;
|
|
187
|
+
this.loggedOnceMessages.add(options.once);
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
formatMessage({
|
|
191
|
+
fgColor,
|
|
192
|
+
bgColor,
|
|
193
|
+
label,
|
|
194
|
+
message,
|
|
195
|
+
identifier,
|
|
196
|
+
muted
|
|
197
|
+
}) {
|
|
198
|
+
const padding = " ".repeat(Math.max(0, this.MAX_LABEL_LENGTH - label.length));
|
|
199
|
+
const formattedMessage = muted ? this.mutedColor(message) : message;
|
|
200
|
+
const identifierPart = identifier ? ` ${bgColor(import_picocolors.default.black(` ${identifier} `))}` : "";
|
|
201
|
+
return `${fgColor(label)} ${padding}${formattedMessage}${identifierPart}`;
|
|
202
|
+
}
|
|
203
|
+
output(message, options = {}, logFn = console.log) {
|
|
204
|
+
if (silent || !this.shouldLog(options))
|
|
205
|
+
return;
|
|
206
|
+
if (options.verticalSpace)
|
|
207
|
+
logFn("");
|
|
208
|
+
logFn(message);
|
|
209
|
+
if (options.verticalSpace)
|
|
210
|
+
logFn("");
|
|
211
|
+
}
|
|
212
|
+
cli(message, options = {}) {
|
|
213
|
+
const formattedMessage = this.formatMessage({
|
|
214
|
+
fgColor: this.cliColor,
|
|
215
|
+
bgColor: import_picocolors.default.bgBlue,
|
|
216
|
+
label: this.labels.cli,
|
|
217
|
+
message,
|
|
218
|
+
identifier: options.identifier,
|
|
219
|
+
muted: options.muted
|
|
220
|
+
});
|
|
221
|
+
this.output(formattedMessage, options);
|
|
222
|
+
}
|
|
223
|
+
info(message, options = {}) {
|
|
224
|
+
const formattedMessage = this.formatMessage({
|
|
225
|
+
fgColor: this.infoColor,
|
|
226
|
+
bgColor: import_picocolors.default.bgCyan,
|
|
227
|
+
label: this.labels.info,
|
|
228
|
+
message,
|
|
229
|
+
identifier: options.identifier,
|
|
230
|
+
muted: options.muted
|
|
231
|
+
});
|
|
232
|
+
this.output(formattedMessage, options);
|
|
233
|
+
}
|
|
234
|
+
warn(message, options = {}) {
|
|
235
|
+
const formattedMessage = this.formatMessage({
|
|
236
|
+
fgColor: this.warnColor,
|
|
237
|
+
bgColor: import_picocolors.default.bgYellow,
|
|
238
|
+
label: this.labels.warn,
|
|
239
|
+
message,
|
|
240
|
+
identifier: options.identifier,
|
|
241
|
+
muted: options.muted
|
|
242
|
+
});
|
|
243
|
+
this.output(formattedMessage, options, console.warn);
|
|
244
|
+
}
|
|
245
|
+
error(message, options = {}) {
|
|
246
|
+
const formattedMessage = this.formatMessage({
|
|
247
|
+
fgColor: this.errorColor,
|
|
248
|
+
bgColor: import_picocolors.default.bgRed,
|
|
249
|
+
label: this.labels.error,
|
|
250
|
+
message,
|
|
251
|
+
identifier: options.identifier,
|
|
252
|
+
muted: options.muted
|
|
253
|
+
});
|
|
254
|
+
this.output(formattedMessage, options, console.error);
|
|
255
|
+
}
|
|
256
|
+
getProgressFgColor(label) {
|
|
257
|
+
for (const [key, colorFn] of Object.entries(this.progressFgColorMap)) {
|
|
258
|
+
if (label.includes(key))
|
|
259
|
+
return colorFn;
|
|
260
|
+
}
|
|
261
|
+
return this.defaultColor;
|
|
262
|
+
}
|
|
263
|
+
getProgressBgColor(label) {
|
|
264
|
+
for (const [key, colorFn] of Object.entries(this.progressIdentifierBgColorMap)) {
|
|
265
|
+
if (label.includes(key))
|
|
266
|
+
return colorFn;
|
|
267
|
+
}
|
|
268
|
+
return import_picocolors.default.bgWhite;
|
|
269
|
+
}
|
|
270
|
+
progress(label, message, options = {}) {
|
|
271
|
+
const fgColor = this.getProgressFgColor(label);
|
|
272
|
+
const bgColor = this.getProgressBgColor(label);
|
|
273
|
+
const formattedMessage = this.formatMessage({
|
|
274
|
+
fgColor,
|
|
275
|
+
bgColor,
|
|
276
|
+
label,
|
|
277
|
+
message,
|
|
278
|
+
identifier: options.identifier,
|
|
279
|
+
muted: options.muted
|
|
280
|
+
});
|
|
281
|
+
this.output(formattedMessage, options);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
var logger = Logger.getInstance();
|
|
285
|
+
|
|
286
|
+
// src/errors.ts
|
|
287
|
+
class BunupError extends Error {
|
|
288
|
+
constructor(message) {
|
|
289
|
+
super(message);
|
|
290
|
+
this.name = "BunupError";
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
class BunupBuildError extends BunupError {
|
|
295
|
+
constructor(message) {
|
|
296
|
+
super(message);
|
|
297
|
+
this.name = "BunupBuildError";
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// src/utils.ts
|
|
302
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
303
|
+
var import_node_path = __toESM(require("path"));
|
|
304
|
+
function getDefaultJsOutputExtension(format, packageType) {
|
|
305
|
+
switch (format) {
|
|
306
|
+
case "esm":
|
|
307
|
+
return isModulePackage(packageType) ? ".js" : ".mjs";
|
|
308
|
+
case "cjs":
|
|
309
|
+
return isModulePackage(packageType) ? ".cjs" : ".js";
|
|
310
|
+
case "iife":
|
|
311
|
+
return ".global.js";
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function getDefaultDtsOutputExtension(format, packageType) {
|
|
315
|
+
switch (format) {
|
|
316
|
+
case "esm":
|
|
317
|
+
return isModulePackage(packageType) ? ".d.ts" : ".d.mts";
|
|
318
|
+
case "cjs":
|
|
319
|
+
return isModulePackage(packageType) ? ".d.cts" : ".d.ts";
|
|
320
|
+
case "iife":
|
|
321
|
+
return ".global.d.ts";
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function removeExtension(filePath) {
|
|
325
|
+
return filePath.replace(import_node_path.default.extname(filePath), "");
|
|
326
|
+
}
|
|
327
|
+
function cleanPath(filePath) {
|
|
328
|
+
return filePath.replace(/\\/g, "/");
|
|
329
|
+
}
|
|
330
|
+
function isModulePackage(packageType) {
|
|
331
|
+
return packageType === "module";
|
|
332
|
+
}
|
|
333
|
+
function getPackageDeps(packageJson) {
|
|
334
|
+
if (!packageJson)
|
|
335
|
+
return [];
|
|
336
|
+
return Array.from(new Set([
|
|
337
|
+
...Object.keys(packageJson.dependencies || {}),
|
|
338
|
+
...Object.keys(packageJson.peerDependencies || {})
|
|
339
|
+
]));
|
|
340
|
+
}
|
|
341
|
+
function getShortFilePath(filePath, maxLength = 3) {
|
|
342
|
+
const fileParts = filePath.split("/");
|
|
343
|
+
const shortPath = fileParts.slice(-maxLength).join("/");
|
|
344
|
+
return shortPath;
|
|
345
|
+
}
|
|
346
|
+
async function cleanOutDir(rootDir, outDir) {
|
|
347
|
+
const outDirPath = import_node_path.default.join(rootDir, outDir);
|
|
348
|
+
try {
|
|
349
|
+
await import_promises.default.rm(outDirPath, { recursive: true, force: true });
|
|
350
|
+
} catch (error) {
|
|
351
|
+
throw new BunupBuildError(`Failed to clean output directory: ${error}`);
|
|
352
|
+
}
|
|
353
|
+
await import_promises.default.mkdir(outDirPath, { recursive: true });
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/helpers/entry.ts
|
|
357
|
+
function getProcessableEntries(entry) {
|
|
358
|
+
if (typeof entry === "string") {
|
|
359
|
+
return [
|
|
360
|
+
{
|
|
361
|
+
entry,
|
|
362
|
+
outputBasePath: getEntryOutputBasePath(entry)
|
|
363
|
+
}
|
|
364
|
+
];
|
|
365
|
+
}
|
|
366
|
+
if (typeof entry === "object" && !Array.isArray(entry)) {
|
|
367
|
+
return Object.entries(entry).map(([name, path2]) => ({
|
|
368
|
+
entry: path2,
|
|
369
|
+
outputBasePath: name
|
|
370
|
+
}));
|
|
371
|
+
}
|
|
372
|
+
return entry.map((_entry) => ({
|
|
373
|
+
entry: _entry,
|
|
374
|
+
outputBasePath: getEntryOutputBasePath(_entry)
|
|
375
|
+
}));
|
|
376
|
+
}
|
|
377
|
+
function getEntryOutputBasePath(entry) {
|
|
378
|
+
const pathSegments = cleanPath(removeExtension(entry)).split("/");
|
|
379
|
+
return pathSegments.length > 1 ? pathSegments.slice(1).join("/") : pathSegments.join("/");
|
|
380
|
+
}
|
|
381
|
+
function getResolvedNaming(outputBasePath, extension) {
|
|
382
|
+
return {
|
|
383
|
+
entry: `[dir]/${outputBasePath}${extension}`,
|
|
384
|
+
chunk: `${outputBasePath}-[hash].[ext]`,
|
|
385
|
+
asset: `${outputBasePath}-[name]-[hash].[ext]`
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// src/loaders.ts
|
|
390
|
+
var import_coffi = require("coffi");
|
|
391
|
+
async function loadPackageJson(cwd) {
|
|
392
|
+
const { config, filepath } = await import_coffi.loadConfig({
|
|
393
|
+
name: "package",
|
|
394
|
+
cwd,
|
|
395
|
+
extensions: [".json"]
|
|
396
|
+
});
|
|
397
|
+
return {
|
|
398
|
+
data: config,
|
|
399
|
+
path: filepath
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/plugins/internal/use-client.ts
|
|
404
|
+
function useClient() {
|
|
405
|
+
return {
|
|
406
|
+
type: "bunup",
|
|
407
|
+
name: "use-client",
|
|
408
|
+
hooks: {
|
|
409
|
+
onBuildDone: async ({ output }) => {
|
|
410
|
+
for (const file of output.files) {
|
|
411
|
+
let text = await Bun.file(file.fullPath).text();
|
|
412
|
+
const hasUseClient = text.split(`
|
|
413
|
+
`).some((line) => line.trim().startsWith(`"use client";`));
|
|
414
|
+
if (hasUseClient) {
|
|
415
|
+
text = text.replaceAll(`"use client";`, "");
|
|
416
|
+
text = `"use client";
|
|
417
|
+
${text}`;
|
|
418
|
+
}
|
|
419
|
+
await Bun.write(file.fullPath, text);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// src/options.ts
|
|
427
|
+
var DEFAULT_OPTIONS = {
|
|
428
|
+
entry: [],
|
|
429
|
+
format: ["cjs"],
|
|
430
|
+
outDir: "dist",
|
|
431
|
+
target: "node",
|
|
432
|
+
clean: true
|
|
433
|
+
};
|
|
434
|
+
function createBuildOptions(partialOptions) {
|
|
435
|
+
const options = {
|
|
436
|
+
...DEFAULT_OPTIONS,
|
|
437
|
+
...partialOptions
|
|
438
|
+
};
|
|
439
|
+
return {
|
|
440
|
+
...options,
|
|
441
|
+
plugins: [...options.plugins ?? [], useClient()]
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function getResolvedMinify(options) {
|
|
445
|
+
const { minify, minifyWhitespace, minifyIdentifiers, minifySyntax } = options;
|
|
446
|
+
const defaultValue = minify === true;
|
|
447
|
+
return {
|
|
448
|
+
whitespace: minifyWhitespace ?? defaultValue,
|
|
449
|
+
identifiers: minifyIdentifiers ?? defaultValue,
|
|
450
|
+
syntax: minifySyntax ?? defaultValue
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
function getResolvedBytecode(bytecode, format) {
|
|
454
|
+
return format === "cjs" ? bytecode : undefined;
|
|
455
|
+
}
|
|
456
|
+
function getResolvedSourcemap(sourcemap) {
|
|
457
|
+
if (sourcemap === true) {
|
|
458
|
+
return "inline";
|
|
459
|
+
}
|
|
460
|
+
return typeof sourcemap === "string" ? sourcemap : undefined;
|
|
461
|
+
}
|
|
462
|
+
function getResolvedDefine(define, env) {
|
|
463
|
+
return {
|
|
464
|
+
...typeof env === "object" && Object.keys(env).reduce((acc, key) => {
|
|
465
|
+
const value = JSON.stringify(env[key]);
|
|
466
|
+
acc[`process.env.${key}`] = value;
|
|
467
|
+
acc[`import.meta.env.${key}`] = value;
|
|
468
|
+
return acc;
|
|
469
|
+
}, {}),
|
|
470
|
+
...define
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
function getResolvedSplitting(splitting, format) {
|
|
474
|
+
return splitting === undefined ? format === "esm" : splitting;
|
|
475
|
+
}
|
|
476
|
+
function getResolvedEnv(env) {
|
|
477
|
+
return typeof env === "string" ? env : undefined;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// src/helpers/external.ts
|
|
481
|
+
function getPackageDepsPatterns(packageJson) {
|
|
482
|
+
return getPackageDeps(packageJson).map((dep) => new RegExp(`^${dep}($|\\/|\\\\)`));
|
|
483
|
+
}
|
|
484
|
+
function matchesPattern(path2, pattern) {
|
|
485
|
+
return typeof pattern === "string" ? pattern === path2 : pattern.test(path2);
|
|
486
|
+
}
|
|
487
|
+
function isExternal(path2, options, packageJson) {
|
|
488
|
+
const packageDepsPatterns = getPackageDepsPatterns(packageJson);
|
|
489
|
+
const matchesExternalPattern = packageDepsPatterns.some((pattern) => pattern.test(path2)) || options.external?.some((pattern) => matchesPattern(path2, pattern));
|
|
490
|
+
const isExcludedFromExternal = options.noExternal?.some((pattern) => matchesPattern(path2, pattern));
|
|
491
|
+
return matchesExternalPattern && !isExcludedFromExternal;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/plugins/internal/external-option.ts
|
|
495
|
+
function externalOptionPlugin(options, packageJson) {
|
|
496
|
+
return {
|
|
497
|
+
name: "bunup:external-option-plugin",
|
|
498
|
+
setup(build) {
|
|
499
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
500
|
+
const importPath = args.path;
|
|
501
|
+
if (isExternal(importPath, options, packageJson)) {
|
|
502
|
+
return {
|
|
503
|
+
path: importPath,
|
|
504
|
+
external: true
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
return null;
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// src/plugins/utils.ts
|
|
514
|
+
function filterBunupBunPlugins(plugins) {
|
|
515
|
+
if (!plugins)
|
|
516
|
+
return [];
|
|
517
|
+
return plugins.filter((p) => p.type === "bun");
|
|
518
|
+
}
|
|
519
|
+
function filterBunupPlugins(plugins) {
|
|
520
|
+
if (!plugins)
|
|
521
|
+
return [];
|
|
522
|
+
return plugins.filter((p) => p.type === "bunup");
|
|
523
|
+
}
|
|
524
|
+
async function runPluginBuildStartHooks(bunupPlugins, options) {
|
|
525
|
+
if (!bunupPlugins)
|
|
526
|
+
return;
|
|
527
|
+
for (const plugin of bunupPlugins) {
|
|
528
|
+
if (plugin.hooks.onBuildStart) {
|
|
529
|
+
await plugin.hooks.onBuildStart(options);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
async function runPluginBuildDoneHooks(bunupPlugins, options, output, meta) {
|
|
534
|
+
if (!bunupPlugins)
|
|
535
|
+
return;
|
|
536
|
+
for (const plugin of bunupPlugins) {
|
|
537
|
+
if (plugin.hooks.onBuildDone) {
|
|
538
|
+
await plugin.hooks.onBuildDone({ options, output, meta });
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// src/build.ts
|
|
544
|
+
async function build(partialOptions, rootDir = process.cwd()) {
|
|
545
|
+
const buildOutput = {
|
|
546
|
+
files: []
|
|
547
|
+
};
|
|
548
|
+
const options = createBuildOptions(partialOptions);
|
|
549
|
+
if (!options.entry || options.entry.length === 0 || !options.outDir) {
|
|
550
|
+
throw new BunupBuildError("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");
|
|
551
|
+
}
|
|
552
|
+
if (options.clean) {
|
|
553
|
+
cleanOutDir(rootDir, options.outDir);
|
|
554
|
+
}
|
|
555
|
+
setSilent(options.silent);
|
|
556
|
+
const packageJson = await loadPackageJson(rootDir);
|
|
557
|
+
if (packageJson.data && packageJson.path) {
|
|
558
|
+
logger.cli(`Using ${getShortFilePath(packageJson.path, 2)}`, {
|
|
559
|
+
muted: true,
|
|
560
|
+
identifier: options.name,
|
|
561
|
+
once: `${packageJson.path}:${options.name}`
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
const bunupPlugins = filterBunupPlugins(options.plugins);
|
|
565
|
+
await runPluginBuildStartHooks(bunupPlugins, options);
|
|
566
|
+
const processableEntries = getProcessableEntries(options.entry);
|
|
567
|
+
const packageType = packageJson.data?.type;
|
|
568
|
+
const plugins = [
|
|
569
|
+
externalOptionPlugin(options, packageJson.data),
|
|
570
|
+
...filterBunupBunPlugins(options.plugins).map((p) => p.plugin)
|
|
571
|
+
];
|
|
572
|
+
if (!options.dtsOnly) {
|
|
573
|
+
const buildPromises = options.format.flatMap((fmt) => processableEntries.map(async ({ entry, outputBasePath }) => {
|
|
574
|
+
const extension = options.outputExtension?.({
|
|
575
|
+
format: fmt,
|
|
576
|
+
packageType,
|
|
577
|
+
options,
|
|
578
|
+
entry
|
|
579
|
+
}).js ?? getDefaultJsOutputExtension(fmt, packageType);
|
|
580
|
+
const result = await Bun.build({
|
|
581
|
+
entrypoints: [`${rootDir}/${entry}`],
|
|
582
|
+
format: fmt,
|
|
583
|
+
naming: getResolvedNaming(outputBasePath, extension),
|
|
584
|
+
splitting: getResolvedSplitting(options.splitting, fmt),
|
|
585
|
+
bytecode: getResolvedBytecode(options.bytecode, fmt),
|
|
586
|
+
define: getResolvedDefine(options.define, options.env),
|
|
587
|
+
minify: getResolvedMinify(options),
|
|
588
|
+
outdir: `${rootDir}/${options.outDir}`,
|
|
589
|
+
target: options.target,
|
|
590
|
+
sourcemap: getResolvedSourcemap(options.sourcemap),
|
|
591
|
+
loader: options.loader,
|
|
592
|
+
drop: options.drop,
|
|
593
|
+
banner: options.banner,
|
|
594
|
+
footer: options.footer,
|
|
595
|
+
publicPath: options.publicPath,
|
|
596
|
+
env: getResolvedEnv(options.env),
|
|
597
|
+
plugins,
|
|
598
|
+
throw: false
|
|
599
|
+
});
|
|
600
|
+
for (const log of result.logs) {
|
|
601
|
+
if (log.level === "error") {
|
|
602
|
+
console.log(`
|
|
603
|
+
`);
|
|
604
|
+
console.log(log);
|
|
605
|
+
console.log(`
|
|
606
|
+
`);
|
|
607
|
+
throw new Error;
|
|
608
|
+
}
|
|
609
|
+
if (log.level === "warning")
|
|
610
|
+
logger.warn(log.message);
|
|
611
|
+
else if (log.level === "info")
|
|
612
|
+
logger.info(log.message);
|
|
613
|
+
}
|
|
614
|
+
for (const file of result.outputs) {
|
|
615
|
+
const relativePathToRootDir = getRelativePathToRootDir(file.path, rootDir);
|
|
616
|
+
if (file.kind === "entry-point") {
|
|
617
|
+
logger.progress(fmt.toUpperCase(), relativePathToRootDir, {
|
|
618
|
+
identifier: options.name
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
buildOutput.files.push({
|
|
622
|
+
fullPath: file.path,
|
|
623
|
+
relativePathToRootDir,
|
|
624
|
+
dts: false,
|
|
625
|
+
entry,
|
|
626
|
+
outputBasePath,
|
|
627
|
+
format: fmt
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
}));
|
|
631
|
+
await Promise.all(buildPromises);
|
|
632
|
+
}
|
|
633
|
+
if (options.dts === true || typeof options.dts === "object" || options.dtsOnly) {
|
|
634
|
+
const dtsResolve = typeof options.dts === "object" && "resolve" in options.dts ? options.dts.resolve : undefined;
|
|
635
|
+
const dtsEntry = typeof options.dts === "object" && "entry" in options.dts ? options.dts.entry : undefined;
|
|
636
|
+
const processableDtsEntries = dtsEntry ? getProcessableEntries(dtsEntry) : processableEntries;
|
|
637
|
+
const dtsPromises = processableDtsEntries.map(async ({ entry, outputBasePath }) => {
|
|
638
|
+
const result = await import_bun_dts.generateDts(entry, {
|
|
639
|
+
cwd: rootDir,
|
|
640
|
+
preferredTsConfigPath: options.preferredTsconfigPath,
|
|
641
|
+
resolve: dtsResolve
|
|
642
|
+
});
|
|
643
|
+
for (const fmt of options.format) {
|
|
644
|
+
const extension = options.outputExtension?.({
|
|
645
|
+
format: fmt,
|
|
646
|
+
packageType,
|
|
647
|
+
options,
|
|
648
|
+
entry
|
|
649
|
+
}).dts ?? getDefaultDtsOutputExtension(fmt, packageType);
|
|
650
|
+
const filePath = import_node_path2.default.join(rootDir, options.outDir, `${outputBasePath}${extension}`);
|
|
651
|
+
const relativePathToRootDir = getRelativePathToRootDir(filePath, rootDir);
|
|
652
|
+
buildOutput.files.push({
|
|
653
|
+
fullPath: filePath,
|
|
654
|
+
relativePathToRootDir,
|
|
655
|
+
dts: true,
|
|
656
|
+
entry,
|
|
657
|
+
outputBasePath,
|
|
658
|
+
format: fmt
|
|
659
|
+
});
|
|
660
|
+
if (result.errors.length > 0) {
|
|
661
|
+
import_bun_dts.logIsolatedDeclarationErrors(result.errors, {
|
|
662
|
+
warnInsteadOfError: options.watch,
|
|
663
|
+
shouldExit: true
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
await Bun.write(filePath, result.dts);
|
|
667
|
+
logger.progress("DTS", relativePathToRootDir, {
|
|
668
|
+
identifier: options.name
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
await Promise.all(dtsPromises);
|
|
673
|
+
}
|
|
674
|
+
await runPluginBuildDoneHooks(bunupPlugins, options, buildOutput, {
|
|
675
|
+
packageJson
|
|
676
|
+
});
|
|
677
|
+
if (options.onSuccess) {
|
|
678
|
+
await options.onSuccess(options);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
function getRelativePathToRootDir(filePath, rootDir) {
|
|
682
|
+
return filePath.replace(`${rootDir}/`, "");
|
|
683
|
+
}
|
|
684
|
+
})
|