bunup 0.8.41 → 0.8.42
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/index.js +1335 -49
- package/dist/index.js +772 -6
- package/dist/plugins/index.d.ts +1 -7
- package/dist/plugins/index.js +389 -73
- package/package.json +4 -4
- package/dist/chunk-5ng6vk19.js +0 -284
- package/dist/chunk-5s4mpe5d.js +0 -355
- package/dist/chunk-a7j07gk7.js +0 -25
- package/dist/chunk-c1eyecm3.js +0 -367
- package/dist/chunk-gh7z7s46.js +0 -30
- package/dist/chunk-q3kvndyh.js +0 -155
package/dist/cli/index.js
CHANGED
|
@@ -1,40 +1,952 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
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 __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
29
|
+
var __require = import.meta.require;
|
|
30
|
+
|
|
31
|
+
// src/logger.ts
|
|
32
|
+
import pc from "picocolors";
|
|
33
|
+
function setSilent(value) {
|
|
34
|
+
silent = value ?? false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class Logger {
|
|
38
|
+
static instance;
|
|
39
|
+
loggedOnceMessages = new Set;
|
|
40
|
+
constructor() {}
|
|
41
|
+
static getInstance() {
|
|
42
|
+
if (!Logger.instance) {
|
|
43
|
+
Logger.instance = new Logger;
|
|
44
|
+
}
|
|
45
|
+
return Logger.instance;
|
|
46
|
+
}
|
|
47
|
+
dispose() {
|
|
48
|
+
this.loggedOnceMessages.clear();
|
|
49
|
+
}
|
|
50
|
+
shouldLog(options) {
|
|
51
|
+
if (!options?.once) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (this.loggedOnceMessages.has(options.once)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
this.loggedOnceMessages.add(options.once);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
getIcon(type, tick) {
|
|
61
|
+
if (tick) {
|
|
62
|
+
return pc.green("\u2713");
|
|
63
|
+
}
|
|
64
|
+
const iconMap = {
|
|
65
|
+
info: pc.blue("i"),
|
|
66
|
+
warn: pc.yellow("!"),
|
|
67
|
+
error: pc.red("\u2715")
|
|
68
|
+
};
|
|
69
|
+
return iconMap[type];
|
|
70
|
+
}
|
|
71
|
+
formatIdentifier(identifier) {
|
|
72
|
+
return identifier ? ` ${pc.bgBlue(pc.black(` ${identifier} `))}` : "";
|
|
73
|
+
}
|
|
74
|
+
formatMessage(options) {
|
|
75
|
+
const {
|
|
76
|
+
message,
|
|
77
|
+
identifier,
|
|
78
|
+
muted = false,
|
|
79
|
+
tick = false,
|
|
80
|
+
type = "info"
|
|
81
|
+
} = options;
|
|
82
|
+
const icon = this.getIcon(type, tick);
|
|
83
|
+
const styledMessage = muted ? pc.dim(message) : type === "error" ? pc.red(message) : type === "warn" ? pc.yellow(message) : message;
|
|
84
|
+
const identifierPart = this.formatIdentifier(identifier);
|
|
85
|
+
return `${icon} ${styledMessage}${identifierPart}`;
|
|
86
|
+
}
|
|
87
|
+
output(message, options = {}, logFn = console.log) {
|
|
88
|
+
if (silent || !this.shouldLog(options)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (options.verticalSpace) {
|
|
92
|
+
logFn("");
|
|
93
|
+
}
|
|
94
|
+
logFn(message);
|
|
95
|
+
if (options.verticalSpace) {
|
|
96
|
+
logFn("");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
info(message, options = {}) {
|
|
100
|
+
const formattedMessage = this.formatMessage({
|
|
101
|
+
...options,
|
|
102
|
+
message,
|
|
103
|
+
type: "info"
|
|
104
|
+
});
|
|
105
|
+
this.output(formattedMessage, options);
|
|
106
|
+
}
|
|
107
|
+
warn(message, options = {}) {
|
|
108
|
+
const formattedMessage = this.formatMessage({
|
|
109
|
+
...options,
|
|
110
|
+
message,
|
|
111
|
+
type: "warn"
|
|
112
|
+
});
|
|
113
|
+
this.output(formattedMessage, options);
|
|
114
|
+
}
|
|
115
|
+
error(message, options = {}) {
|
|
116
|
+
const formattedMessage = this.formatMessage({
|
|
117
|
+
...options,
|
|
118
|
+
message,
|
|
119
|
+
type: "error"
|
|
120
|
+
});
|
|
121
|
+
this.output(formattedMessage, options);
|
|
122
|
+
}
|
|
123
|
+
success(message, options = {}) {
|
|
124
|
+
const formattedMessage = this.formatMessage({
|
|
125
|
+
...options,
|
|
126
|
+
message,
|
|
127
|
+
tick: true
|
|
128
|
+
});
|
|
129
|
+
this.output(formattedMessage, options);
|
|
130
|
+
}
|
|
131
|
+
space() {
|
|
132
|
+
if (!silent) {
|
|
133
|
+
console.log("");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function logTable(columns, data, footer) {
|
|
138
|
+
if (silent)
|
|
139
|
+
return;
|
|
140
|
+
const widths = {};
|
|
141
|
+
for (const col of columns) {
|
|
142
|
+
const headerLength = col.header.length;
|
|
143
|
+
const dataLengths = data.map((row) => row[col.header]?.length || 0);
|
|
144
|
+
const footerLength = footer ? footer[col.header]?.length || 0 : 0;
|
|
145
|
+
widths[col.header] = Math.max(headerLength, ...dataLengths, footerLength);
|
|
146
|
+
}
|
|
147
|
+
const pad = (str, width, align) => {
|
|
148
|
+
return align === "left" ? str.padEnd(width) : str.padStart(width);
|
|
149
|
+
};
|
|
150
|
+
const headerRow = columns.map((col) => pad(col.header, widths[col.header], col.align)).join(pc.gray(" | "));
|
|
151
|
+
console.log(pc.gray(headerRow));
|
|
152
|
+
const separator = columns.map((col) => "-".repeat(widths[col.header])).join(" | ");
|
|
153
|
+
console.log(pc.gray(separator));
|
|
154
|
+
for (const row of data) {
|
|
155
|
+
const rowStr = columns.map((col) => {
|
|
156
|
+
const value = row[col.header] || "";
|
|
157
|
+
const padded = pad(value, widths[col.header], col.align);
|
|
158
|
+
return col.color ? col.color(padded) : padded;
|
|
159
|
+
}).join(pc.gray(" | "));
|
|
160
|
+
console.log(rowStr);
|
|
161
|
+
}
|
|
162
|
+
console.log(pc.gray(separator));
|
|
163
|
+
if (footer) {
|
|
164
|
+
const footerRow = columns.map((col) => {
|
|
165
|
+
const value = footer[col.header] || "";
|
|
166
|
+
const padded = pad(value, widths[col.header], col.align);
|
|
167
|
+
return padded;
|
|
168
|
+
}).join(pc.gray(" | "));
|
|
169
|
+
console.log(footerRow);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
var silent = false, logger;
|
|
173
|
+
var init_logger = __esm(() => {
|
|
174
|
+
logger = Logger.getInstance();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// src/errors.ts
|
|
178
|
+
import pc2 from "picocolors";
|
|
179
|
+
var BunupError, BunupBuildError, BunupDTSBuildError, BunupCLIError, BunupWatchError, BunupPluginError, parseErrorMessage = (error) => {
|
|
180
|
+
if (error instanceof Error) {
|
|
181
|
+
return error.message;
|
|
182
|
+
}
|
|
183
|
+
return String(error);
|
|
184
|
+
}, KNOWN_ERRORS, handleError = (error, context) => {
|
|
185
|
+
const errorMessage = parseErrorMessage(error);
|
|
186
|
+
const contextPrefix = context ? `[${context}] ` : "";
|
|
187
|
+
let errorType = "UNKNOWN ERROR";
|
|
188
|
+
if (error instanceof BunupBuildError) {
|
|
189
|
+
errorType = "BUILD ERROR";
|
|
190
|
+
} else if (error instanceof BunupDTSBuildError) {
|
|
191
|
+
errorType = "DTS ERROR";
|
|
192
|
+
} else if (error instanceof BunupCLIError) {
|
|
193
|
+
errorType = "CLI ERROR";
|
|
194
|
+
} else if (error instanceof BunupWatchError) {
|
|
195
|
+
errorType = "WATCH ERROR";
|
|
196
|
+
} else if (error instanceof BunupPluginError) {
|
|
197
|
+
errorType = "PLUGIN ERROR";
|
|
198
|
+
} else if (error instanceof BunupError) {
|
|
199
|
+
errorType = "BUNUP ERROR";
|
|
200
|
+
}
|
|
201
|
+
const knownError = KNOWN_ERRORS.find((error2) => error2.pattern.test(errorMessage) && (error2.errorType === errorType || !error2.errorType));
|
|
202
|
+
if (!knownError && errorType) {
|
|
203
|
+
console.error(`${pc2.red(errorType)} ${contextPrefix}${errorMessage}`);
|
|
204
|
+
}
|
|
205
|
+
if (knownError) {
|
|
206
|
+
console.log(`
|
|
207
|
+
`);
|
|
208
|
+
knownError.logSolution(errorMessage);
|
|
209
|
+
console.log(`
|
|
210
|
+
`);
|
|
211
|
+
} else {
|
|
212
|
+
console.error(pc2.dim(pc2.white("If you think this is a bug, please open an issue at: ") + pc2.cyan("https://github.com/arshad-yaseen/bunup/issues/new")));
|
|
213
|
+
}
|
|
214
|
+
}, handleErrorAndExit = (error, context) => {
|
|
215
|
+
handleError(error, context);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
};
|
|
218
|
+
var init_errors = __esm(() => {
|
|
219
|
+
init_logger();
|
|
220
|
+
BunupError = class BunupError extends Error {
|
|
221
|
+
constructor(message) {
|
|
222
|
+
super(message);
|
|
223
|
+
this.name = "BunupError";
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
BunupBuildError = class BunupBuildError extends BunupError {
|
|
227
|
+
constructor(message) {
|
|
228
|
+
super(message);
|
|
229
|
+
this.name = "BunupBuildError";
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
BunupDTSBuildError = class BunupDTSBuildError extends BunupError {
|
|
233
|
+
constructor(message) {
|
|
234
|
+
super(message);
|
|
235
|
+
this.name = "BunupDTSBuildError";
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
BunupCLIError = class BunupCLIError extends BunupError {
|
|
239
|
+
constructor(message) {
|
|
240
|
+
super(message);
|
|
241
|
+
this.name = "BunupCLIError";
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
BunupWatchError = class BunupWatchError extends BunupError {
|
|
245
|
+
constructor(message) {
|
|
246
|
+
super(message);
|
|
247
|
+
this.name = "BunupWatchError";
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
BunupPluginError = class BunupPluginError extends BunupError {
|
|
251
|
+
constructor(message) {
|
|
252
|
+
super(message);
|
|
253
|
+
this.name = "BunupPluginError";
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
KNOWN_ERRORS = [
|
|
257
|
+
{
|
|
258
|
+
pattern: /Could not resolve: "bun"/i,
|
|
259
|
+
errorType: "BUILD ERROR",
|
|
260
|
+
logSolution: () => {
|
|
261
|
+
logger.info(pc2.white("You're trying to build a project that uses Bun. ") + pc2.white("Please set the target option to ") + pc2.cyan("`bun`") + pc2.white(`.
|
|
262
|
+
`) + pc2.white("Example: ") + pc2.green("`bunup --target bun`") + pc2.white(" or in config: ") + pc2.green("{ target: 'bun' }"));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
];
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// src/loaders.ts
|
|
269
|
+
import path from "path";
|
|
270
|
+
import { loadConfig } from "coffi";
|
|
271
|
+
async function processLoadedConfigs(config, cwd, filter) {
|
|
272
|
+
return Array.isArray(config) && "root" in config[0] ? config.filter((c) => filter ? filter.includes(c.name) : true).map((c) => ({
|
|
273
|
+
rootDir: path.resolve(cwd, c.root),
|
|
274
|
+
options: addField(c.config, "name", c.name)
|
|
275
|
+
})) : [
|
|
276
|
+
{
|
|
277
|
+
rootDir: cwd,
|
|
278
|
+
options: config
|
|
279
|
+
}
|
|
280
|
+
];
|
|
281
|
+
}
|
|
282
|
+
function addField(objectOrArray, field, value) {
|
|
283
|
+
return Array.isArray(objectOrArray) ? objectOrArray.map((o) => ({ ...o, [field]: value })) : { ...objectOrArray, [field]: value };
|
|
284
|
+
}
|
|
285
|
+
async function loadPackageJson(cwd = process.cwd()) {
|
|
286
|
+
const { config, filepath } = await loadConfig({
|
|
287
|
+
name: "package",
|
|
288
|
+
cwd,
|
|
289
|
+
extensions: [".json"]
|
|
290
|
+
});
|
|
291
|
+
return {
|
|
292
|
+
data: config,
|
|
293
|
+
path: filepath
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
var init_loaders = () => {};
|
|
297
|
+
|
|
298
|
+
// src/utils.ts
|
|
299
|
+
import fsSync from "fs";
|
|
300
|
+
import fs from "fs/promises";
|
|
301
|
+
import path2, { normalize } from "path";
|
|
302
|
+
function ensureArray(value) {
|
|
303
|
+
return Array.isArray(value) ? value : [value];
|
|
304
|
+
}
|
|
305
|
+
function getDefaultOutputExtension(format, packageType) {
|
|
306
|
+
switch (format) {
|
|
307
|
+
case "esm":
|
|
308
|
+
return isModulePackage(packageType) ? ".js" : ".mjs";
|
|
309
|
+
case "cjs":
|
|
310
|
+
return isModulePackage(packageType) ? ".cjs" : ".js";
|
|
311
|
+
case "iife":
|
|
312
|
+
return ".global.js";
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function getDefaultDtsExtention(format, packageType) {
|
|
316
|
+
switch (format) {
|
|
317
|
+
case "esm":
|
|
318
|
+
return isModulePackage(packageType) ? ".d.ts" : ".d.mts";
|
|
319
|
+
case "cjs":
|
|
320
|
+
return isModulePackage(packageType) ? ".d.cts" : ".d.ts";
|
|
321
|
+
case "iife":
|
|
322
|
+
return ".global.d.ts";
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function isModulePackage(packageType) {
|
|
326
|
+
return packageType === "module";
|
|
327
|
+
}
|
|
328
|
+
function formatTime(ms) {
|
|
329
|
+
return ms >= 1000 ? `${(ms / 1000).toFixed(2)}s` : `${Math.round(ms)}ms`;
|
|
330
|
+
}
|
|
331
|
+
function getPackageDeps(packageJson) {
|
|
332
|
+
if (!packageJson)
|
|
333
|
+
return [];
|
|
334
|
+
return Array.from(new Set([
|
|
335
|
+
...Object.keys(packageJson.dependencies || {}),
|
|
336
|
+
...Object.keys(packageJson.peerDependencies || {})
|
|
337
|
+
]));
|
|
338
|
+
}
|
|
339
|
+
function formatFileSize(bytes) {
|
|
340
|
+
if (bytes === 0)
|
|
341
|
+
return "0 B";
|
|
342
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
343
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
344
|
+
if (i === 0)
|
|
345
|
+
return `${bytes} ${units[i]}`;
|
|
346
|
+
return `${(bytes / 1024 ** i).toFixed(2)} ${units[i]}`;
|
|
347
|
+
}
|
|
348
|
+
function getShortFilePath(filePath, maxLength = 3) {
|
|
349
|
+
const fileParts = filePath.split("/");
|
|
350
|
+
const shortPath = fileParts.slice(-maxLength).join("/");
|
|
351
|
+
return shortPath;
|
|
352
|
+
}
|
|
353
|
+
async function cleanOutDir(rootDir, outDir) {
|
|
354
|
+
const outDirPath = path2.join(rootDir, outDir);
|
|
355
|
+
try {
|
|
356
|
+
await fs.rm(outDirPath, { recursive: true, force: true });
|
|
357
|
+
} catch (error) {
|
|
358
|
+
throw new BunupBuildError(`Failed to clean output directory: ${error}`);
|
|
359
|
+
}
|
|
360
|
+
await fs.mkdir(outDirPath, { recursive: true });
|
|
361
|
+
}
|
|
362
|
+
function cleanPath(path3) {
|
|
363
|
+
let cleaned = normalize(path3).replace(/\\/g, "/");
|
|
364
|
+
cleaned = cleaned.replace(/^[a-zA-Z]:\//, "");
|
|
365
|
+
cleaned = cleaned.replace(/^\/+/, "");
|
|
366
|
+
cleaned = cleaned.replace(/\/+/g, "/");
|
|
367
|
+
return cleaned;
|
|
368
|
+
}
|
|
369
|
+
function isDirectoryPath(filePath) {
|
|
370
|
+
return path2.extname(filePath) === "";
|
|
371
|
+
}
|
|
372
|
+
function pathExistsSync(filePath) {
|
|
373
|
+
try {
|
|
374
|
+
fsSync.accessSync(filePath);
|
|
375
|
+
return true;
|
|
376
|
+
} catch (error) {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function formatListWithAnd(arr) {
|
|
381
|
+
return new Intl.ListFormat("en", {
|
|
382
|
+
style: "long",
|
|
383
|
+
type: "conjunction"
|
|
384
|
+
}).format(arr);
|
|
385
|
+
}
|
|
386
|
+
async function getFilesFromGlobs(patterns, cwd) {
|
|
387
|
+
const includePatterns = patterns.filter((p) => !p.startsWith("!"));
|
|
388
|
+
const excludePatterns = patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
|
|
389
|
+
const includedFiles = new Set;
|
|
390
|
+
for (const pattern of includePatterns) {
|
|
391
|
+
const glob = new Bun.Glob(pattern);
|
|
392
|
+
for await (const file of glob.scan(cwd)) {
|
|
393
|
+
includedFiles.add(file);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (excludePatterns.length > 0) {
|
|
397
|
+
for (const pattern of excludePatterns) {
|
|
398
|
+
const glob = new Bun.Glob(pattern);
|
|
399
|
+
for await (const file of glob.scan(cwd)) {
|
|
400
|
+
includedFiles.delete(file);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return Array.from(includedFiles);
|
|
405
|
+
}
|
|
406
|
+
var init_utils = __esm(() => {
|
|
407
|
+
init_errors();
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// src/cli/utils.ts
|
|
411
|
+
import pc8 from "picocolors";
|
|
412
|
+
function displayBunupGradientArt() {
|
|
413
|
+
const art = `
|
|
414
|
+
\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557
|
|
415
|
+
\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
|
|
416
|
+
\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D
|
|
417
|
+
\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u255D
|
|
418
|
+
\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551
|
|
419
|
+
\u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D
|
|
420
|
+
`.trim();
|
|
421
|
+
const lines = art.split(`
|
|
422
|
+
`);
|
|
423
|
+
logger.space();
|
|
424
|
+
for (const line of lines) {
|
|
425
|
+
console.log(pc8.cyan(line));
|
|
426
|
+
}
|
|
427
|
+
logger.space();
|
|
428
|
+
}
|
|
429
|
+
var init_utils2 = __esm(() => {
|
|
430
|
+
init_logger();
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// src/cli/new.ts
|
|
434
|
+
var exports_new = {};
|
|
435
|
+
__export(exports_new, {
|
|
436
|
+
newProject: () => newProject
|
|
437
|
+
});
|
|
438
|
+
import { renameSync } from "fs";
|
|
439
|
+
import path5 from "path";
|
|
3
440
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
441
|
+
cancel,
|
|
442
|
+
confirm,
|
|
443
|
+
intro,
|
|
444
|
+
outro,
|
|
445
|
+
select,
|
|
446
|
+
tasks,
|
|
447
|
+
text
|
|
448
|
+
} from "@clack/prompts";
|
|
449
|
+
import { downloadTemplate } from "giget";
|
|
450
|
+
import pc9 from "picocolors";
|
|
451
|
+
import { replaceInFile } from "replace-in-file";
|
|
452
|
+
async function newProject() {
|
|
453
|
+
displayBunupGradientArt();
|
|
454
|
+
intro(pc9.bgCyan(pc9.black(" Scaffold a new project with Bunup ")));
|
|
455
|
+
const selectedTemplateDir = await select({
|
|
456
|
+
message: "Select a template",
|
|
457
|
+
options: TEMPLATES.map((template2) => ({
|
|
458
|
+
value: template2.dir,
|
|
459
|
+
label: pc9.blue(template2.name)
|
|
460
|
+
}))
|
|
461
|
+
});
|
|
462
|
+
const template = TEMPLATES.find((t) => t.dir === selectedTemplateDir);
|
|
463
|
+
if (!template) {
|
|
464
|
+
cancel("Invalid template");
|
|
465
|
+
process.exit(1);
|
|
466
|
+
}
|
|
467
|
+
const hasMonorepo = template.monorepoDir !== undefined;
|
|
468
|
+
const projectName = await text({
|
|
469
|
+
message: "Enter the project name",
|
|
470
|
+
placeholder: template.defaultName,
|
|
471
|
+
defaultValue: template.defaultName,
|
|
472
|
+
validate: (value) => {
|
|
473
|
+
if (!value) {
|
|
474
|
+
return "Project name is required";
|
|
475
|
+
}
|
|
476
|
+
if (value.includes(" ")) {
|
|
477
|
+
return "Project name cannot contain spaces";
|
|
478
|
+
}
|
|
479
|
+
if (pathExistsSync(getProjectPath(value))) {
|
|
480
|
+
return "Project already exists";
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
const projectPath = getProjectPath(projectName);
|
|
485
|
+
let useMonorepo = false;
|
|
486
|
+
let monorepoFirstPackageName;
|
|
487
|
+
if (hasMonorepo) {
|
|
488
|
+
useMonorepo = await confirm({
|
|
489
|
+
message: "Do you want to create a monorepo?",
|
|
490
|
+
initialValue: false
|
|
491
|
+
});
|
|
492
|
+
if (useMonorepo) {
|
|
493
|
+
monorepoFirstPackageName = await text({
|
|
494
|
+
message: "Enter the name of the first package",
|
|
495
|
+
placeholder: MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER,
|
|
496
|
+
defaultValue: MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const githubRepoInfo = await text({
|
|
501
|
+
message: "GitHub username and repo name (username/repo):",
|
|
502
|
+
placeholder: `${GITHUB_USERNAME_PLACEHOLDER}/${GITHUB_REPO_PLACEHOLDER}`,
|
|
503
|
+
defaultValue: `${GITHUB_USERNAME_PLACEHOLDER}/${GITHUB_REPO_PLACEHOLDER}`
|
|
504
|
+
});
|
|
505
|
+
const [githubUsername, githubRepoName] = githubRepoInfo.split("/");
|
|
506
|
+
await tasks([
|
|
507
|
+
{
|
|
508
|
+
title: "Downloading template",
|
|
509
|
+
task: async () => {
|
|
510
|
+
const templatePath = useMonorepo ? template.monorepoDir : template.dir;
|
|
511
|
+
await downloadTemplate(`github:${TEMPLATE_OWNER}/${TEMPLATE_REPO}/${templatePath}`, {
|
|
512
|
+
dir: projectPath
|
|
513
|
+
});
|
|
514
|
+
return "Template downloaded";
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
title: "Making the project yours",
|
|
519
|
+
task: async () => {
|
|
520
|
+
await replaceInFile({
|
|
521
|
+
files: path5.join(projectPath, "**/*"),
|
|
522
|
+
from: [
|
|
523
|
+
new RegExp(GITHUB_REPO_PLACEHOLDER, "g"),
|
|
524
|
+
new RegExp(GITHUB_USERNAME_PLACEHOLDER, "g"),
|
|
525
|
+
new RegExp(template.defaultName, "g")
|
|
526
|
+
],
|
|
527
|
+
to: [githubRepoName, githubUsername, projectName],
|
|
528
|
+
ignore: ["node_modules", "dist", "bun.lock"]
|
|
529
|
+
});
|
|
530
|
+
if (useMonorepo && monorepoFirstPackageName) {
|
|
531
|
+
await replaceInFile({
|
|
532
|
+
files: path5.join(projectPath, "**/*"),
|
|
533
|
+
from: [new RegExp(MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER, "g")],
|
|
534
|
+
to: [monorepoFirstPackageName],
|
|
535
|
+
ignore: ["node_modules", "dist", "bun.lock"]
|
|
536
|
+
});
|
|
537
|
+
renameSync(path5.join(projectPath, MONOREPO_PACKAGES_DIR, MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER), path5.join(projectPath, MONOREPO_PACKAGES_DIR, monorepoFirstPackageName));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
]);
|
|
542
|
+
outro(`
|
|
543
|
+
${pc9.green("\u2728 Project scaffolded successfully! \u2728")}
|
|
544
|
+
|
|
545
|
+
${pc9.bold("Ready to launch your awesome new project?")}
|
|
546
|
+
|
|
547
|
+
${pc9.cyan("cd")} ${projectName}
|
|
548
|
+
${pc9.cyan("bun install")}
|
|
549
|
+
${pc9.cyan("bun run dev")}${pc9.dim(" (watch mode for development)")}${template.type === "react" ? `
|
|
550
|
+
${pc9.cyan("bun run dev:test")} ${pc9.dim("(preview components in a test Next.js app)")} ` : ""}
|
|
551
|
+
|
|
552
|
+
${pc9.dim("Learn more:")} ${pc9.underline("https://bunup.dev/docs")}
|
|
553
|
+
|
|
554
|
+
${pc9.yellow("Happy coding!")} \uD83D\uDE80
|
|
555
|
+
`);
|
|
556
|
+
}
|
|
557
|
+
function getProjectPath(projectName) {
|
|
558
|
+
return path5.join(process.cwd(), projectName);
|
|
559
|
+
}
|
|
560
|
+
var TEMPLATE_OWNER = "arshad-yaseen", TEMPLATE_REPO = "bunup-new", GITHUB_USERNAME_PLACEHOLDER = "username", GITHUB_REPO_PLACEHOLDER = "repo-name", MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER = "package-1", MONOREPO_PACKAGES_DIR = "packages", TEMPLATES;
|
|
561
|
+
var init_new = __esm(() => {
|
|
562
|
+
init_utils();
|
|
563
|
+
init_utils2();
|
|
564
|
+
TEMPLATES = [
|
|
565
|
+
{
|
|
566
|
+
type: "typescript",
|
|
567
|
+
defaultName: "my-ts-lib",
|
|
568
|
+
name: "Typescript Library",
|
|
569
|
+
dir: "ts-lib",
|
|
570
|
+
monorepoDir: "ts-lib-monorepo"
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
type: "react",
|
|
574
|
+
defaultName: "my-react-lib",
|
|
575
|
+
name: "React Library",
|
|
576
|
+
dir: "react-lib"
|
|
577
|
+
}
|
|
578
|
+
];
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
// src/cli/init.ts
|
|
582
|
+
var exports_init = {};
|
|
583
|
+
__export(exports_init, {
|
|
584
|
+
init: () => init
|
|
585
|
+
});
|
|
586
|
+
import fs2 from "fs";
|
|
587
|
+
import path6 from "path";
|
|
11
588
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
589
|
+
confirm as confirm2,
|
|
590
|
+
intro as intro2,
|
|
591
|
+
log,
|
|
592
|
+
multiselect,
|
|
593
|
+
outro as outro2,
|
|
594
|
+
select as select2,
|
|
595
|
+
tasks as tasks2,
|
|
596
|
+
text as text2
|
|
597
|
+
} from "@clack/prompts";
|
|
598
|
+
import pc10 from "picocolors";
|
|
599
|
+
import { exec } from "tinyexec";
|
|
600
|
+
async function init() {
|
|
601
|
+
displayBunupGradientArt();
|
|
602
|
+
intro2(pc10.bgCyan(pc10.black(" Initialize bunup in an existing project ")));
|
|
603
|
+
const { path: packageJsonPath } = await loadPackageJson();
|
|
604
|
+
if (!packageJsonPath) {
|
|
605
|
+
log.error("package.json not found");
|
|
606
|
+
process.exit(1);
|
|
607
|
+
}
|
|
608
|
+
const shouldSetupWorkspace = await promptForWorkspace();
|
|
609
|
+
if (shouldSetupWorkspace) {
|
|
610
|
+
await initializeWorkspace(packageJsonPath);
|
|
611
|
+
} else {
|
|
612
|
+
await initializeSinglePackage(packageJsonPath);
|
|
613
|
+
}
|
|
614
|
+
await tasks2([
|
|
615
|
+
{
|
|
616
|
+
title: "Installing bunup",
|
|
617
|
+
task: async () => {
|
|
618
|
+
await installBunup();
|
|
619
|
+
return "Bunup installed";
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
]);
|
|
623
|
+
showSuccessOutro(shouldSetupWorkspace);
|
|
624
|
+
}
|
|
625
|
+
async function promptForWorkspace() {
|
|
626
|
+
return await confirm2({
|
|
627
|
+
message: "Do you want to setup a Bunup workspace? (for building multiple packages with one command)",
|
|
628
|
+
initialValue: false
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
async function initializeWorkspace(packageJsonPath) {
|
|
632
|
+
const workspacePackages = await collectWorkspacePackages();
|
|
633
|
+
const configMethod = await selectWorkspaceConfigurationMethod();
|
|
634
|
+
await generateWorkspaceConfiguration(configMethod, workspacePackages);
|
|
635
|
+
await handleWorkspaceBuildScripts(packageJsonPath);
|
|
636
|
+
}
|
|
637
|
+
async function initializeSinglePackage(packageJsonPath) {
|
|
638
|
+
const entryFiles = await collectEntryFiles();
|
|
639
|
+
const outputFormats = await selectOutputFormats();
|
|
640
|
+
const shouldGenerateDts = await promptForTypeScriptDeclarations(entryFiles);
|
|
641
|
+
const configMethod = await selectConfigurationMethod();
|
|
642
|
+
await generateConfiguration(configMethod, entryFiles, outputFormats, shouldGenerateDts, packageJsonPath);
|
|
643
|
+
await handleBuildScripts(packageJsonPath, entryFiles, outputFormats, shouldGenerateDts, configMethod);
|
|
644
|
+
}
|
|
645
|
+
async function collectWorkspacePackages() {
|
|
646
|
+
const packages = [];
|
|
647
|
+
while (true) {
|
|
648
|
+
const packageName = await text2({
|
|
649
|
+
message: packages.length > 0 ? "Enter the next package name:" : "Enter the first package name:",
|
|
650
|
+
placeholder: "core",
|
|
651
|
+
validate: (value) => {
|
|
652
|
+
if (!value)
|
|
653
|
+
return "Package name is required";
|
|
654
|
+
if (packages.some((pkg) => pkg.name === value))
|
|
655
|
+
return "Package name already exists";
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
const packageRoot = await text2({
|
|
659
|
+
message: `Enter the root directory for "${packageName}":`,
|
|
660
|
+
placeholder: `packages/${packageName}`,
|
|
661
|
+
defaultValue: `packages/${packageName}`,
|
|
662
|
+
validate: (value) => {
|
|
663
|
+
if (!value)
|
|
664
|
+
return "Package root is required";
|
|
665
|
+
if (!fs2.existsSync(value))
|
|
666
|
+
return "Package root directory does not exist";
|
|
667
|
+
if (!fs2.statSync(value).isDirectory())
|
|
668
|
+
return "Package root must be a directory";
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
const entryFiles = await collectEntryFilesForPackage(packageRoot, packageName);
|
|
672
|
+
const outputFormats = await selectOutputFormats();
|
|
673
|
+
const shouldGenerateDts = await promptForTypeScriptDeclarations(entryFiles);
|
|
674
|
+
packages.push({
|
|
675
|
+
name: packageName,
|
|
676
|
+
root: packageRoot,
|
|
677
|
+
entryFiles,
|
|
678
|
+
outputFormats,
|
|
679
|
+
shouldGenerateDts
|
|
680
|
+
});
|
|
681
|
+
const shouldAddMore = await confirm2({
|
|
682
|
+
message: "Do you want to add another package?",
|
|
683
|
+
initialValue: true
|
|
684
|
+
});
|
|
685
|
+
if (!shouldAddMore)
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
return packages;
|
|
689
|
+
}
|
|
690
|
+
async function collectEntryFilesForPackage(packageRoot, packageName) {
|
|
691
|
+
const entryFiles = [];
|
|
692
|
+
while (true) {
|
|
693
|
+
const entryFile = await text2({
|
|
694
|
+
message: entryFiles.length > 0 ? `Where is the next entry file for "${packageName}"? (relative to ${packageRoot})` : `Where is the entry file for "${packageName}"? (relative to ${packageRoot})`,
|
|
695
|
+
placeholder: "src/index.ts",
|
|
696
|
+
defaultValue: "src/index.ts",
|
|
697
|
+
validate: (value) => {
|
|
698
|
+
if (!value)
|
|
699
|
+
return "Entry file is required";
|
|
700
|
+
const fullPath = path6.join(packageRoot, value);
|
|
701
|
+
if (!fs2.existsSync(fullPath))
|
|
702
|
+
return `Entry file does not exist at ${fullPath}`;
|
|
703
|
+
if (!fs2.statSync(fullPath).isFile())
|
|
704
|
+
return "Entry file must be a file";
|
|
705
|
+
if (entryFiles.includes(value))
|
|
706
|
+
return "You have already added this entry file";
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
entryFiles.push(entryFile);
|
|
710
|
+
const shouldAddMore = await confirm2({
|
|
711
|
+
message: "Do you want to add another entry file for this package?",
|
|
712
|
+
initialValue: false
|
|
713
|
+
});
|
|
714
|
+
if (!shouldAddMore)
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
return entryFiles;
|
|
718
|
+
}
|
|
719
|
+
async function collectEntryFiles() {
|
|
720
|
+
const entryFiles = [];
|
|
721
|
+
while (true) {
|
|
722
|
+
const entryFile = await text2({
|
|
723
|
+
message: entryFiles.length > 0 ? "Where is your next entry file?" : "Where is your entry file?",
|
|
724
|
+
placeholder: "src/index.ts",
|
|
725
|
+
defaultValue: "src/index.ts",
|
|
726
|
+
validate: (value) => {
|
|
727
|
+
if (!value)
|
|
728
|
+
return "Entry file is required";
|
|
729
|
+
if (!fs2.existsSync(value))
|
|
730
|
+
return "Entry file does not exist";
|
|
731
|
+
if (!fs2.statSync(value).isFile())
|
|
732
|
+
return "Entry file must be a file";
|
|
733
|
+
if (entryFiles.includes(value))
|
|
734
|
+
return "You have already added this entry file";
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
entryFiles.push(entryFile);
|
|
738
|
+
const shouldAddMore = await confirm2({
|
|
739
|
+
message: "Do you want to add another entry file?",
|
|
740
|
+
initialValue: false
|
|
741
|
+
});
|
|
742
|
+
if (!shouldAddMore)
|
|
743
|
+
break;
|
|
744
|
+
}
|
|
745
|
+
return entryFiles;
|
|
746
|
+
}
|
|
747
|
+
async function selectOutputFormats() {
|
|
748
|
+
return await multiselect({
|
|
749
|
+
message: "Select the output formats",
|
|
750
|
+
options: [
|
|
751
|
+
{ value: "esm", label: "ESM (.mjs)" },
|
|
752
|
+
{ value: "cjs", label: "CommonJS (.cjs)" },
|
|
753
|
+
{ value: "iife", label: "IIFE (.global.js)" }
|
|
754
|
+
],
|
|
755
|
+
initialValues: ["esm", "cjs"]
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
async function promptForTypeScriptDeclarations(entryFiles) {
|
|
759
|
+
const hasTypeScriptFiles = entryFiles.some((file) => file.endsWith(".ts") || file.endsWith(".tsx"));
|
|
760
|
+
if (!hasTypeScriptFiles)
|
|
761
|
+
return false;
|
|
762
|
+
return await confirm2({
|
|
763
|
+
message: "Generate TypeScript declarations?",
|
|
764
|
+
initialValue: true
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
async function selectWorkspaceConfigurationMethod() {
|
|
768
|
+
return await select2({
|
|
769
|
+
message: "How would you like to configure your workspace?",
|
|
770
|
+
options: [
|
|
771
|
+
{ value: "ts", label: "bunup.config.ts", hint: "Recommended" },
|
|
772
|
+
{ value: "js", label: "bunup.config.js" }
|
|
773
|
+
],
|
|
774
|
+
initialValue: "ts"
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
async function selectConfigurationMethod() {
|
|
778
|
+
return await select2({
|
|
779
|
+
message: "How would you like to configure Bunup?",
|
|
780
|
+
options: [
|
|
781
|
+
{ value: "ts", label: "bunup.config.ts", hint: "Recommended" },
|
|
782
|
+
{ value: "js", label: "bunup.config.js" },
|
|
783
|
+
{ value: "json", label: 'package.json "bunup" property' },
|
|
784
|
+
{
|
|
785
|
+
value: "none",
|
|
786
|
+
label: "No config file",
|
|
787
|
+
hint: "Configure via CLI only"
|
|
788
|
+
}
|
|
789
|
+
],
|
|
790
|
+
initialValue: "ts"
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
async function generateWorkspaceConfiguration(configMethod, workspacePackages) {
|
|
794
|
+
const configContent = createWorkspaceConfigFileContent(workspacePackages);
|
|
795
|
+
await Bun.write(`bunup.config.${configMethod}`, configContent);
|
|
796
|
+
}
|
|
797
|
+
async function generateConfiguration(configMethod, entryFiles, outputFormats, shouldGenerateDts, packageJsonPath) {
|
|
798
|
+
if (configMethod === "none") {
|
|
799
|
+
log.info("If you need more control (such as adding plugins or customizing output), you can always create a config file later.");
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
if (configMethod === "ts" || configMethod === "js") {
|
|
803
|
+
await Bun.write(`bunup.config.${configMethod}`, createConfigFileContent(entryFiles, outputFormats, shouldGenerateDts));
|
|
804
|
+
} else if (configMethod === "json") {
|
|
805
|
+
const { data: packageJsonConfig } = await loadPackageJson();
|
|
806
|
+
const updatedConfig = {
|
|
807
|
+
...packageJsonConfig,
|
|
808
|
+
bunup: createPackageJsonConfig(entryFiles, outputFormats, shouldGenerateDts)
|
|
809
|
+
};
|
|
810
|
+
await Bun.write(packageJsonPath, JSON.stringify(updatedConfig, null, 2));
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
async function handleWorkspaceBuildScripts(packageJsonPath) {
|
|
814
|
+
const { data: packageJsonConfig } = await loadPackageJson();
|
|
815
|
+
const existingScripts = packageJsonConfig?.scripts ?? {};
|
|
816
|
+
const newScripts = createWorkspaceBuildScripts();
|
|
817
|
+
const conflictingScripts = Object.keys(newScripts).filter((script) => existingScripts[script]);
|
|
818
|
+
if (conflictingScripts.length > 0) {
|
|
819
|
+
const shouldOverride = await confirm2({
|
|
820
|
+
message: `The ${formatListWithAnd(conflictingScripts)} ${conflictingScripts.length > 1 ? "scripts already exist" : "script already exists"} in package.json. Override ${conflictingScripts.length > 1 ? "them" : "it"}?`,
|
|
821
|
+
initialValue: true
|
|
822
|
+
});
|
|
823
|
+
if (!shouldOverride) {
|
|
824
|
+
log.info("Skipped adding build scripts to avoid conflicts.");
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
const updatedConfig = {
|
|
829
|
+
...packageJsonConfig,
|
|
830
|
+
scripts: { ...existingScripts, ...newScripts }
|
|
831
|
+
};
|
|
832
|
+
await Bun.write(packageJsonPath, JSON.stringify(updatedConfig, null, 2));
|
|
833
|
+
}
|
|
834
|
+
async function handleBuildScripts(packageJsonPath, entryFiles, outputFormats, shouldGenerateDts, configMethod) {
|
|
835
|
+
const { data: packageJsonConfig } = await loadPackageJson();
|
|
836
|
+
const existingScripts = packageJsonConfig?.scripts ?? {};
|
|
837
|
+
const newScripts = createBuildScripts(entryFiles, outputFormats, shouldGenerateDts, configMethod);
|
|
838
|
+
const conflictingScripts = Object.keys(newScripts).filter((script) => existingScripts[script]);
|
|
839
|
+
if (conflictingScripts.length > 0) {
|
|
840
|
+
const shouldOverride = await confirm2({
|
|
841
|
+
message: `The ${formatListWithAnd(conflictingScripts)} ${conflictingScripts.length > 1 ? "scripts already exist" : "script already exists"} in package.json. Override ${conflictingScripts.length > 1 ? "them" : "it"}?`,
|
|
842
|
+
initialValue: true
|
|
843
|
+
});
|
|
844
|
+
if (!shouldOverride) {
|
|
845
|
+
log.info("Skipped adding build scripts to avoid conflicts.");
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
const updatedConfig = {
|
|
850
|
+
...packageJsonConfig,
|
|
851
|
+
scripts: { ...existingScripts, ...newScripts }
|
|
852
|
+
};
|
|
853
|
+
await Bun.write(packageJsonPath, JSON.stringify(updatedConfig, null, 2));
|
|
854
|
+
}
|
|
855
|
+
function createWorkspaceConfigFileContent(workspacePackages) {
|
|
856
|
+
const packagesConfig = workspacePackages.map((pkg) => {
|
|
857
|
+
return ` {
|
|
858
|
+
name: '${pkg.name}',
|
|
859
|
+
root: '${pkg.root}',
|
|
860
|
+
config: {
|
|
861
|
+
entry: [${pkg.entryFiles.map((file) => `'${file}'`).join(", ")}],
|
|
862
|
+
format: [${pkg.outputFormats.map((format) => `'${format}'`).join(", ")}],${pkg.shouldGenerateDts ? `
|
|
863
|
+
dts: true,` : ""}
|
|
864
|
+
},
|
|
865
|
+
}`;
|
|
866
|
+
}).join(`,
|
|
867
|
+
`);
|
|
868
|
+
return `import { defineWorkspace } from 'bunup'
|
|
869
|
+
|
|
870
|
+
export default defineWorkspace([
|
|
871
|
+
${packagesConfig}
|
|
872
|
+
])
|
|
873
|
+
`;
|
|
874
|
+
}
|
|
875
|
+
function createConfigFileContent(entryFiles, outputFormats, shouldGenerateDts) {
|
|
876
|
+
return `import { defineConfig } from 'bunup'
|
|
877
|
+
|
|
878
|
+
export default defineConfig({
|
|
879
|
+
entry: [${entryFiles.map((file) => `'${file}'`).join(", ")}],
|
|
880
|
+
format: [${outputFormats.map((format) => `'${format}'`).join(", ")}],${shouldGenerateDts ? `
|
|
881
|
+
dts: true,` : ""}
|
|
882
|
+
})
|
|
883
|
+
`;
|
|
884
|
+
}
|
|
885
|
+
function createPackageJsonConfig(entryFiles, outputFormats, shouldGenerateDts) {
|
|
886
|
+
return {
|
|
887
|
+
entry: entryFiles,
|
|
888
|
+
format: outputFormats,
|
|
889
|
+
...shouldGenerateDts && { dts: true }
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
function createWorkspaceBuildScripts() {
|
|
893
|
+
return {
|
|
894
|
+
build: "bunup",
|
|
895
|
+
dev: "bunup --watch"
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
function createBuildScripts(entryFiles, outputFormats, shouldGenerateDts, configMethod) {
|
|
899
|
+
const cliOptions = configMethod === "none" ? ` ${entryFiles.join(" ")} --format ${outputFormats.join(",")}${shouldGenerateDts ? " --dts" : ""}` : "";
|
|
900
|
+
return {
|
|
901
|
+
build: `bunup${cliOptions}`,
|
|
902
|
+
dev: `bunup${cliOptions} --watch`
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
function showSuccessOutro(isWorkspace) {
|
|
906
|
+
const buildCommand = isWorkspace ? `${pc10.cyan("bun run build")} - Build all packages in your workspace` : `${pc10.cyan("bun run build")} - Build your library`;
|
|
907
|
+
const devCommand = isWorkspace ? `${pc10.cyan("bun run dev")} - Start development mode (watches all packages)` : `${pc10.cyan("bun run dev")} - Start development mode`;
|
|
908
|
+
const filterCommand = isWorkspace ? `${pc10.cyan("bunup --filter core,utils")} - Build specific packages` : "";
|
|
909
|
+
outro2(`
|
|
910
|
+
${pc10.green("\u2728 Bunup initialized successfully! \u2728")}
|
|
911
|
+
|
|
912
|
+
${buildCommand}
|
|
913
|
+
${devCommand}${isWorkspace ? `
|
|
914
|
+
${filterCommand}` : ""}
|
|
915
|
+
|
|
916
|
+
${pc10.dim("Learn more:")} ${pc10.underline("https://bunup.dev/docs")}
|
|
917
|
+
|
|
918
|
+
${pc10.yellow("Happy building!")} \uD83D\uDE80
|
|
919
|
+
`);
|
|
920
|
+
}
|
|
921
|
+
async function installBunup() {
|
|
922
|
+
await exec("bun add -d bunup", [], {
|
|
923
|
+
nodeOptions: { shell: true, stdio: "pipe" }
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
var init_init = __esm(() => {
|
|
927
|
+
init_loaders();
|
|
928
|
+
init_utils();
|
|
929
|
+
init_utils2();
|
|
930
|
+
});
|
|
25
931
|
|
|
26
932
|
// src/cli/index.ts
|
|
27
|
-
import { exec } from "tinyexec";
|
|
933
|
+
import { exec as exec2 } from "tinyexec";
|
|
28
934
|
// package.json
|
|
29
|
-
var version = "0.8.
|
|
935
|
+
var version = "0.8.41";
|
|
936
|
+
|
|
937
|
+
// src/cli/index.ts
|
|
938
|
+
init_errors();
|
|
939
|
+
init_logger();
|
|
30
940
|
|
|
31
941
|
// src/cli/options.ts
|
|
32
|
-
import
|
|
942
|
+
import pc3 from "picocolors";
|
|
33
943
|
|
|
34
944
|
// src/constants/index.ts
|
|
35
945
|
var BUNUP_DOCS_URL = "https://bunup.dev/docs";
|
|
36
946
|
|
|
37
947
|
// src/cli/options.ts
|
|
948
|
+
init_errors();
|
|
949
|
+
init_logger();
|
|
38
950
|
var createHandlers = () => ({
|
|
39
951
|
boolean: (key) => (value, options) => {
|
|
40
952
|
options[key] = value === true || value === "true";
|
|
@@ -348,11 +1260,11 @@ var displayHelp = () => {
|
|
|
348
1260
|
utility: "Utility Options"
|
|
349
1261
|
};
|
|
350
1262
|
console.log();
|
|
351
|
-
console.log(
|
|
1263
|
+
console.log(pc3.cyan(pc3.bold("bunup")));
|
|
352
1264
|
console.log();
|
|
353
1265
|
console.log("\u26A1\uFE0F A blazing-fast build tool for your libraries built with Bun");
|
|
354
1266
|
console.log();
|
|
355
|
-
console.log(
|
|
1267
|
+
console.log(pc3.cyan("Usage:"));
|
|
356
1268
|
console.log(" bunup [entry...] [options]");
|
|
357
1269
|
console.log(" bunup --init");
|
|
358
1270
|
console.log(" bunup --new");
|
|
@@ -361,24 +1273,24 @@ var displayHelp = () => {
|
|
|
361
1273
|
const categoryOptions = Object.values(OPTION_DEFINITIONS).filter((option) => option.category === categoryKey);
|
|
362
1274
|
if (categoryOptions.length === 0)
|
|
363
1275
|
return;
|
|
364
|
-
console.log(
|
|
1276
|
+
console.log(pc3.cyan(`${categoryName}:`));
|
|
365
1277
|
for (const option of categoryOptions) {
|
|
366
1278
|
const flags = option.flags.map((flag) => flag.length === 1 ? `-${flag}` : `--${flag}`).join(", ");
|
|
367
|
-
const flagsDisplay =
|
|
368
|
-
const typeDisplay =
|
|
369
|
-
const defaultDisplay = option.default ?
|
|
1279
|
+
const flagsDisplay = pc3.green(flags);
|
|
1280
|
+
const typeDisplay = pc3.dim(`<${option.type}>`);
|
|
1281
|
+
const defaultDisplay = option.default ? pc3.yellow(`(default: ${option.default})`) : "";
|
|
370
1282
|
console.log(` ${flagsDisplay} ${typeDisplay}`);
|
|
371
|
-
console.log(` ${
|
|
1283
|
+
console.log(` ${pc3.dim(option.description)} ${defaultDisplay}`);
|
|
372
1284
|
console.log();
|
|
373
1285
|
}
|
|
374
1286
|
}
|
|
375
|
-
console.log(
|
|
1287
|
+
console.log(pc3.cyan("Examples:"));
|
|
376
1288
|
console.log(" bunup src/**/*.ts");
|
|
377
1289
|
console.log(" bunup src/index.ts src/cli.ts --format esm,cjs");
|
|
378
1290
|
console.log(" bunup src/index.ts --watch --dts");
|
|
379
1291
|
console.log();
|
|
380
|
-
console.log(
|
|
381
|
-
console.log(` ${
|
|
1292
|
+
console.log(pc3.dim("For more information:"));
|
|
1293
|
+
console.log(` ${pc3.cyan(pc3.underline(BUNUP_DOCS_URL))}`);
|
|
382
1294
|
console.log();
|
|
383
1295
|
};
|
|
384
1296
|
var parseArgument = (arg, nextArg) => {
|
|
@@ -425,19 +1337,393 @@ var parseCliOptions = (argv) => {
|
|
|
425
1337
|
};
|
|
426
1338
|
|
|
427
1339
|
// src/cli/index.ts
|
|
428
|
-
import { loadConfig } from "coffi";
|
|
429
|
-
import
|
|
1340
|
+
import { loadConfig as loadConfig2 } from "coffi";
|
|
1341
|
+
import pc11 from "picocolors";
|
|
1342
|
+
|
|
1343
|
+
// src/build.ts
|
|
1344
|
+
init_errors();
|
|
1345
|
+
init_loaders();
|
|
1346
|
+
init_logger();
|
|
1347
|
+
import path3 from "path";
|
|
1348
|
+
import { generateDts, logIsolatedDeclarationErrors } from "bun-dts";
|
|
1349
|
+
import pc6 from "picocolors";
|
|
1350
|
+
|
|
1351
|
+
// src/plugins/internal/report.ts
|
|
1352
|
+
init_logger();
|
|
1353
|
+
init_logger();
|
|
1354
|
+
init_utils();
|
|
1355
|
+
import pc4 from "picocolors";
|
|
1356
|
+
function report() {
|
|
1357
|
+
return {
|
|
1358
|
+
type: "bunup",
|
|
1359
|
+
name: "report",
|
|
1360
|
+
hooks: {
|
|
1361
|
+
onBuildDone: async ({ options, output }) => {
|
|
1362
|
+
if (options.watch)
|
|
1363
|
+
return;
|
|
1364
|
+
const files = await Promise.all(output.files.map(async (file) => {
|
|
1365
|
+
const name = file.relativePathToRootDir;
|
|
1366
|
+
const size = Bun.file(file.fullPath).size;
|
|
1367
|
+
const gzipSize = Bun.gzipSync(new Uint8Array(await Bun.file(file.fullPath).arrayBuffer())).length;
|
|
1368
|
+
const formattedGzipSize = formatFileSize(gzipSize);
|
|
1369
|
+
return {
|
|
1370
|
+
name,
|
|
1371
|
+
size,
|
|
1372
|
+
formattedSize: formatFileSize(size),
|
|
1373
|
+
gzipSize,
|
|
1374
|
+
formattedGzipSize
|
|
1375
|
+
};
|
|
1376
|
+
}));
|
|
1377
|
+
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
1378
|
+
const formattedTotalSize = formatFileSize(totalSize);
|
|
1379
|
+
const totalGzipSize = files.reduce((sum, file) => sum + (file.gzipSize || 0), 0);
|
|
1380
|
+
const formattedTotalGzipSize = formatFileSize(totalGzipSize);
|
|
1381
|
+
const columns = [
|
|
1382
|
+
{ header: "File", align: "left", color: pc4.blue },
|
|
1383
|
+
{ header: "Size", align: "right", color: pc4.green },
|
|
1384
|
+
{
|
|
1385
|
+
header: "Gzip",
|
|
1386
|
+
align: "right",
|
|
1387
|
+
color: pc4.magenta
|
|
1388
|
+
}
|
|
1389
|
+
];
|
|
1390
|
+
const data = files.map((file) => {
|
|
1391
|
+
return {
|
|
1392
|
+
File: file.name,
|
|
1393
|
+
Size: file.formattedSize,
|
|
1394
|
+
Gzip: file.formattedGzipSize
|
|
1395
|
+
};
|
|
1396
|
+
});
|
|
1397
|
+
const footer = {
|
|
1398
|
+
File: "Total",
|
|
1399
|
+
Size: formattedTotalSize,
|
|
1400
|
+
Gzip: formattedTotalGzipSize
|
|
1401
|
+
};
|
|
1402
|
+
logger.space();
|
|
1403
|
+
logTable(columns, data, footer);
|
|
1404
|
+
logger.space();
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
// src/plugins/internal/use-client.ts
|
|
1411
|
+
function useClient() {
|
|
1412
|
+
return {
|
|
1413
|
+
type: "bunup",
|
|
1414
|
+
name: "use-client",
|
|
1415
|
+
hooks: {
|
|
1416
|
+
onBuildDone: async ({ output }) => {
|
|
1417
|
+
for (const file of output.files) {
|
|
1418
|
+
let text = await Bun.file(file.fullPath).text();
|
|
1419
|
+
const hasUseClient = text.split(`
|
|
1420
|
+
`).some((line) => line.trim().startsWith(`"use client";`));
|
|
1421
|
+
if (hasUseClient) {
|
|
1422
|
+
text = text.replaceAll(`"use client";`, "");
|
|
1423
|
+
text = `"use client";
|
|
1424
|
+
${text}`;
|
|
1425
|
+
}
|
|
1426
|
+
await Bun.write(file.fullPath, text);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
// src/options.ts
|
|
1434
|
+
init_utils();
|
|
1435
|
+
var DEFAULT_OPTIONS = {
|
|
1436
|
+
entry: [],
|
|
1437
|
+
format: ["cjs"],
|
|
1438
|
+
outDir: "dist",
|
|
1439
|
+
target: "node",
|
|
1440
|
+
clean: true
|
|
1441
|
+
};
|
|
1442
|
+
function createBuildOptions(partialOptions) {
|
|
1443
|
+
const options = {
|
|
1444
|
+
...DEFAULT_OPTIONS,
|
|
1445
|
+
...partialOptions
|
|
1446
|
+
};
|
|
1447
|
+
return {
|
|
1448
|
+
...options,
|
|
1449
|
+
plugins: [
|
|
1450
|
+
...options.plugins?.filter((p) => p.name !== "report") ?? [],
|
|
1451
|
+
useClient(),
|
|
1452
|
+
report()
|
|
1453
|
+
]
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
function getResolvedMinify(options) {
|
|
1457
|
+
const { minify, minifyWhitespace, minifyIdentifiers, minifySyntax } = options;
|
|
1458
|
+
const defaultValue = minify === true;
|
|
1459
|
+
return {
|
|
1460
|
+
whitespace: minifyWhitespace ?? defaultValue,
|
|
1461
|
+
identifiers: minifyIdentifiers ?? defaultValue,
|
|
1462
|
+
syntax: minifySyntax ?? defaultValue
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
function getResolvedBytecode(bytecode, format) {
|
|
1466
|
+
return format === "cjs" ? bytecode : undefined;
|
|
1467
|
+
}
|
|
1468
|
+
function getResolvedSourcemap(sourcemap) {
|
|
1469
|
+
if (sourcemap === true) {
|
|
1470
|
+
return "inline";
|
|
1471
|
+
}
|
|
1472
|
+
return typeof sourcemap === "string" ? sourcemap : undefined;
|
|
1473
|
+
}
|
|
1474
|
+
function getResolvedDefine(define, env) {
|
|
1475
|
+
return {
|
|
1476
|
+
...typeof env === "object" && Object.keys(env).reduce((acc, key) => {
|
|
1477
|
+
const value = JSON.stringify(env[key]);
|
|
1478
|
+
acc[`process.env.${key}`] = value;
|
|
1479
|
+
acc[`import.meta.env.${key}`] = value;
|
|
1480
|
+
return acc;
|
|
1481
|
+
}, {}),
|
|
1482
|
+
...define
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
function getResolvedSplitting(splitting, format) {
|
|
1486
|
+
return splitting === undefined ? format === "esm" : splitting;
|
|
1487
|
+
}
|
|
1488
|
+
function getResolvedDtsSplitting(splitting) {
|
|
1489
|
+
return splitting ?? true;
|
|
1490
|
+
}
|
|
1491
|
+
var DEFAULT_ENTRY_NAMING = "[dir]/[name].[ext]";
|
|
1492
|
+
function getResolvedNaming(fmt, packageType) {
|
|
1493
|
+
const replaceExt = (pattern) => pattern.replace(".[ext]", getDefaultOutputExtension(fmt, packageType));
|
|
1494
|
+
return replaceExt(DEFAULT_ENTRY_NAMING);
|
|
1495
|
+
}
|
|
1496
|
+
function getResolvedEnv(env) {
|
|
1497
|
+
return typeof env === "string" ? env : undefined;
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
// src/helpers/external.ts
|
|
1501
|
+
init_utils();
|
|
1502
|
+
function getPackageDepsPatterns(packageJson) {
|
|
1503
|
+
return getPackageDeps(packageJson).map((dep) => new RegExp(`^${dep}($|\\/|\\\\)`));
|
|
1504
|
+
}
|
|
1505
|
+
function matchesPattern(path3, pattern) {
|
|
1506
|
+
return typeof pattern === "string" ? pattern === path3 : pattern.test(path3);
|
|
1507
|
+
}
|
|
1508
|
+
function isExternal(path3, options, packageJson) {
|
|
1509
|
+
const packageDepsPatterns = getPackageDepsPatterns(packageJson);
|
|
1510
|
+
const matchesExternalPattern = packageDepsPatterns.some((pattern) => pattern.test(path3)) || options.external?.some((pattern) => matchesPattern(path3, pattern));
|
|
1511
|
+
const isExcludedFromExternal = options.noExternal?.some((pattern) => matchesPattern(path3, pattern));
|
|
1512
|
+
return matchesExternalPattern && !isExcludedFromExternal;
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
// src/plugins/internal/external-option.ts
|
|
1516
|
+
function externalOptionPlugin(options, packageJson) {
|
|
1517
|
+
return {
|
|
1518
|
+
name: "bunup:external-option-plugin",
|
|
1519
|
+
setup(build) {
|
|
1520
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
1521
|
+
const importPath = args.path;
|
|
1522
|
+
if (isExternal(importPath, options, packageJson)) {
|
|
1523
|
+
return {
|
|
1524
|
+
path: importPath,
|
|
1525
|
+
external: true
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
return null;
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
};
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
// src/plugins/utils.ts
|
|
1535
|
+
init_errors();
|
|
1536
|
+
import pc5 from "picocolors";
|
|
1537
|
+
function filterBunupBunPlugins(plugins) {
|
|
1538
|
+
if (!plugins)
|
|
1539
|
+
return [];
|
|
1540
|
+
return plugins.filter((p) => p.type === "bun");
|
|
1541
|
+
}
|
|
1542
|
+
function filterBunupPlugins(plugins) {
|
|
1543
|
+
if (!plugins)
|
|
1544
|
+
return [];
|
|
1545
|
+
return plugins.filter((p) => p.type === "bunup");
|
|
1546
|
+
}
|
|
1547
|
+
async function runPluginBuildStartHooks(bunupPlugins, options) {
|
|
1548
|
+
if (!bunupPlugins)
|
|
1549
|
+
return;
|
|
1550
|
+
for (const plugin of bunupPlugins) {
|
|
1551
|
+
if (plugin.hooks.onBuildStart) {
|
|
1552
|
+
await plugin.hooks.onBuildStart(options);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
async function runPluginBuildDoneHooks(bunupPlugins, options, output, meta) {
|
|
1557
|
+
if (!bunupPlugins)
|
|
1558
|
+
return;
|
|
1559
|
+
for (const plugin of bunupPlugins) {
|
|
1560
|
+
if (plugin.hooks.onBuildDone) {
|
|
1561
|
+
await plugin.hooks.onBuildDone({ options, output, meta });
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
async function getPackageForPlugin(name, pluginName) {
|
|
1566
|
+
let pkg;
|
|
1567
|
+
try {
|
|
1568
|
+
pkg = await import(name);
|
|
1569
|
+
} catch {
|
|
1570
|
+
throw new BunupPluginError(`[${pc5.cyan(name)}] is required for the ${pluginName} plugin. Please install it with: ${pc5.blue(`bun add ${name} --dev`)}`);
|
|
1571
|
+
}
|
|
1572
|
+
return pkg;
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
// src/build.ts
|
|
1576
|
+
init_utils();
|
|
1577
|
+
async function build(partialOptions, rootDir = process.cwd()) {
|
|
1578
|
+
const buildOutput = {
|
|
1579
|
+
files: []
|
|
1580
|
+
};
|
|
1581
|
+
const options = createBuildOptions(partialOptions);
|
|
1582
|
+
if (!options.entry || options.entry.length === 0 || !options.outDir) {
|
|
1583
|
+
throw new BunupBuildError("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");
|
|
1584
|
+
}
|
|
1585
|
+
if (options.clean) {
|
|
1586
|
+
cleanOutDir(rootDir, options.outDir);
|
|
1587
|
+
}
|
|
1588
|
+
setSilent(options.silent);
|
|
1589
|
+
const packageJson = await loadPackageJson(rootDir);
|
|
1590
|
+
if (packageJson.data && packageJson.path) {
|
|
1591
|
+
logger.info(`Using ${getShortFilePath(packageJson.path, 2)}`, {
|
|
1592
|
+
muted: true,
|
|
1593
|
+
identifier: options.name,
|
|
1594
|
+
once: `${packageJson.path}:${options.name}`
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
const bunupPlugins = filterBunupPlugins(options.plugins);
|
|
1598
|
+
await runPluginBuildStartHooks(bunupPlugins, options);
|
|
1599
|
+
const packageType = packageJson.data?.type;
|
|
1600
|
+
const plugins = [
|
|
1601
|
+
externalOptionPlugin(options, packageJson.data),
|
|
1602
|
+
...filterBunupBunPlugins(options.plugins).map((p) => p.plugin)
|
|
1603
|
+
];
|
|
1604
|
+
const entrypoints = await getFilesFromGlobs(ensureArray(options.entry), rootDir);
|
|
1605
|
+
if (!entrypoints.length) {
|
|
1606
|
+
throw new BunupBuildError("The entrypoints you provided do not exist. Please make sure the entrypoints point to valid files.");
|
|
1607
|
+
}
|
|
1608
|
+
const buildPromises = options.format.flatMap(async (fmt) => {
|
|
1609
|
+
const result = await Bun.build({
|
|
1610
|
+
entrypoints: entrypoints.map((file) => `${rootDir}/${file}`),
|
|
1611
|
+
format: fmt,
|
|
1612
|
+
naming: getResolvedNaming(fmt, packageType),
|
|
1613
|
+
splitting: getResolvedSplitting(options.splitting, fmt),
|
|
1614
|
+
bytecode: getResolvedBytecode(options.bytecode, fmt),
|
|
1615
|
+
define: getResolvedDefine(options.define, options.env),
|
|
1616
|
+
minify: getResolvedMinify(options),
|
|
1617
|
+
outdir: `${rootDir}/${options.outDir}`,
|
|
1618
|
+
target: options.target,
|
|
1619
|
+
sourcemap: getResolvedSourcemap(options.sourcemap),
|
|
1620
|
+
loader: options.loader,
|
|
1621
|
+
drop: options.drop,
|
|
1622
|
+
banner: options.banner,
|
|
1623
|
+
footer: options.footer,
|
|
1624
|
+
publicPath: options.publicPath,
|
|
1625
|
+
env: getResolvedEnv(options.env),
|
|
1626
|
+
ignoreDCEAnnotations: options.ignoreDCEAnnotations,
|
|
1627
|
+
emitDCEAnnotations: options.emitDCEAnnotations,
|
|
1628
|
+
throw: false,
|
|
1629
|
+
plugins
|
|
1630
|
+
});
|
|
1631
|
+
for (const log of result.logs) {
|
|
1632
|
+
if (log.level === "error") {
|
|
1633
|
+
throw new BunupBuildError(log.message);
|
|
1634
|
+
}
|
|
1635
|
+
if (log.level === "warning")
|
|
1636
|
+
logger.warn(log.message);
|
|
1637
|
+
else if (log.level === "info")
|
|
1638
|
+
logger.info(log.message);
|
|
1639
|
+
}
|
|
1640
|
+
for (const file of result.outputs) {
|
|
1641
|
+
const relativePathToRootDir = getRelativePathToRootDir(file.path, rootDir);
|
|
1642
|
+
const relativePathToOutputDir = getRelativePathToOutputDir(relativePathToRootDir, options.outDir);
|
|
1643
|
+
if (file.kind === "entry-point") {
|
|
1644
|
+
logger.success(`${pc6.dim(options.outDir)}/${relativePathToOutputDir}`, {
|
|
1645
|
+
identifier: options.name
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
buildOutput.files.push({
|
|
1649
|
+
fullPath: file.path,
|
|
1650
|
+
relativePathToRootDir,
|
|
1651
|
+
relativePathToOutputDir,
|
|
1652
|
+
dts: false,
|
|
1653
|
+
format: fmt,
|
|
1654
|
+
kind: file.kind
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
});
|
|
1658
|
+
await Promise.all(buildPromises);
|
|
1659
|
+
if (options.dts) {
|
|
1660
|
+
const { entry, splitting, ...dtsOptions } = typeof options.dts === "object" ? options.dts : {};
|
|
1661
|
+
const dtsResult = await generateDts(ensureArray(entry ?? entrypoints), {
|
|
1662
|
+
cwd: rootDir,
|
|
1663
|
+
preferredTsConfigPath: options.preferredTsconfigPath,
|
|
1664
|
+
splitting: getResolvedDtsSplitting(splitting),
|
|
1665
|
+
...dtsOptions
|
|
1666
|
+
});
|
|
1667
|
+
if (dtsResult.errors.length) {
|
|
1668
|
+
logIsolatedDeclarationErrors(dtsResult.errors, {
|
|
1669
|
+
shouldExit: true
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
for (const fmt of options.format) {
|
|
1673
|
+
for (const file of dtsResult.files) {
|
|
1674
|
+
const dtsExtension = getDefaultDtsExtention(fmt, packageType);
|
|
1675
|
+
const relativePathToOutputDir = cleanPath(`${file.pathInfo.outputPathWithoutExtension}${dtsExtension}`);
|
|
1676
|
+
const relativePathToRootDir = cleanPath(`${options.outDir}/${relativePathToOutputDir}`);
|
|
1677
|
+
if (file.kind === "entry-point") {
|
|
1678
|
+
logger.success(`${pc6.dim(options.outDir)}/${relativePathToOutputDir}`, {
|
|
1679
|
+
identifier: options.name
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
const fullPath = path3.join(rootDir, relativePathToRootDir);
|
|
1683
|
+
await Bun.write(fullPath, file.dts);
|
|
1684
|
+
buildOutput.files.push({
|
|
1685
|
+
fullPath,
|
|
1686
|
+
relativePathToRootDir,
|
|
1687
|
+
relativePathToOutputDir,
|
|
1688
|
+
dts: true,
|
|
1689
|
+
format: fmt,
|
|
1690
|
+
kind: file.kind
|
|
1691
|
+
});
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
await runPluginBuildDoneHooks(bunupPlugins, options, buildOutput, {
|
|
1696
|
+
packageJson,
|
|
1697
|
+
rootDir
|
|
1698
|
+
});
|
|
1699
|
+
if (options.onSuccess) {
|
|
1700
|
+
await options.onSuccess(options);
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
function getRelativePathToRootDir(filePath, rootDir) {
|
|
1704
|
+
return cleanPath(filePath).replace(`${cleanPath(rootDir)}/`, "");
|
|
1705
|
+
}
|
|
1706
|
+
function getRelativePathToOutputDir(relativePathToRootDir, outDir) {
|
|
1707
|
+
return cleanPath(relativePathToRootDir).replace(`${cleanPath(outDir)}/`, "");
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
// src/cli/index.ts
|
|
1711
|
+
init_loaders();
|
|
1712
|
+
init_utils();
|
|
430
1713
|
|
|
431
1714
|
// src/watch.ts
|
|
432
|
-
import
|
|
433
|
-
import
|
|
1715
|
+
import path4 from "path";
|
|
1716
|
+
import pc7 from "picocolors";
|
|
1717
|
+
init_errors();
|
|
1718
|
+
init_logger();
|
|
1719
|
+
init_utils();
|
|
434
1720
|
async function watch(partialOptions, rootDir) {
|
|
435
1721
|
const watchPaths = new Set;
|
|
436
1722
|
const options = createBuildOptions(partialOptions);
|
|
437
1723
|
const uniqueEntries = new Set(options.entry);
|
|
438
1724
|
for (const entry of uniqueEntries) {
|
|
439
|
-
const entryPath =
|
|
440
|
-
const parentDir =
|
|
1725
|
+
const entryPath = path4.resolve(rootDir, entry);
|
|
1726
|
+
const parentDir = path4.dirname(entryPath);
|
|
441
1727
|
watchPaths.add(parentDir);
|
|
442
1728
|
}
|
|
443
1729
|
const chokidar = await import("chokidar");
|
|
@@ -447,7 +1733,7 @@ async function watch(partialOptions, rootDir) {
|
|
|
447
1733
|
ignored: [
|
|
448
1734
|
/[\\/]\.git[\\/]/,
|
|
449
1735
|
/[\\/]node_modules[\\/]/,
|
|
450
|
-
|
|
1736
|
+
path4.join(rootDir, options.outDir)
|
|
451
1737
|
]
|
|
452
1738
|
});
|
|
453
1739
|
let isRebuilding = false;
|
|
@@ -461,7 +1747,7 @@ async function watch(partialOptions, rootDir) {
|
|
|
461
1747
|
const start = performance.now();
|
|
462
1748
|
await build(options, rootDir);
|
|
463
1749
|
if (!initial) {
|
|
464
|
-
logger.success(`\uD83D\uDCE6 Rebuild finished in ${
|
|
1750
|
+
logger.success(`\uD83D\uDCE6 Rebuild finished in ${pc7.green(formatTime(performance.now() - start))}`);
|
|
465
1751
|
}
|
|
466
1752
|
} catch (error) {
|
|
467
1753
|
handleError(error);
|
|
@@ -470,7 +1756,7 @@ async function watch(partialOptions, rootDir) {
|
|
|
470
1756
|
}
|
|
471
1757
|
};
|
|
472
1758
|
watcher.on("change", (filePath) => {
|
|
473
|
-
const changedFile =
|
|
1759
|
+
const changedFile = path4.relative(rootDir, filePath);
|
|
474
1760
|
logger.info(`File changed: ${changedFile}`, {
|
|
475
1761
|
muted: true,
|
|
476
1762
|
once: changedFile
|
|
@@ -487,18 +1773,18 @@ async function watch(partialOptions, rootDir) {
|
|
|
487
1773
|
async function main(args = Bun.argv.slice(2)) {
|
|
488
1774
|
const cliOptions = parseCliOptions(args);
|
|
489
1775
|
if (cliOptions.new) {
|
|
490
|
-
const { newProject } = await
|
|
491
|
-
await
|
|
1776
|
+
const { newProject: newProject2 } = await Promise.resolve().then(() => (init_new(), exports_new));
|
|
1777
|
+
await newProject2();
|
|
492
1778
|
return;
|
|
493
1779
|
}
|
|
494
1780
|
if (cliOptions.init) {
|
|
495
|
-
const { init } = await
|
|
496
|
-
await
|
|
1781
|
+
const { init: init2 } = await Promise.resolve().then(() => (init_init(), exports_init));
|
|
1782
|
+
await init2();
|
|
497
1783
|
return;
|
|
498
1784
|
}
|
|
499
1785
|
setSilent(cliOptions.silent);
|
|
500
1786
|
const cwd = process.cwd();
|
|
501
|
-
const { config, filepath } = await
|
|
1787
|
+
const { config, filepath } = await loadConfig2({
|
|
502
1788
|
name: "bunup.config",
|
|
503
1789
|
extensions: [".ts", ".js", ".mjs", ".cjs"],
|
|
504
1790
|
maxDepth: 1,
|
|
@@ -532,7 +1818,7 @@ async function main(args = Bun.argv.slice(2)) {
|
|
|
532
1818
|
}));
|
|
533
1819
|
const buildTimeMs = performance.now() - startTime;
|
|
534
1820
|
const timeDisplay = formatTime(buildTimeMs);
|
|
535
|
-
logger.success(`Build completed in ${
|
|
1821
|
+
logger.success(`Build completed in ${pc11.green(timeDisplay)}`);
|
|
536
1822
|
if (cliOptions.watch) {
|
|
537
1823
|
logger.info("\uD83D\uDC40 Watching for file changes");
|
|
538
1824
|
}
|
|
@@ -540,7 +1826,7 @@ async function main(args = Bun.argv.slice(2)) {
|
|
|
540
1826
|
logger.info(`Running command: ${cliOptions.onSuccess}`, {
|
|
541
1827
|
muted: true
|
|
542
1828
|
});
|
|
543
|
-
await
|
|
1829
|
+
await exec2(cliOptions.onSuccess, [], {
|
|
544
1830
|
nodeOptions: { shell: true, stdio: "inherit" }
|
|
545
1831
|
});
|
|
546
1832
|
}
|