bunup 0.8.29 → 0.8.30
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/bin/bunup.mjs +1 -1
- package/dist/cli/index.cjs +2030 -0
- package/dist/cli/index.d.cts +360 -0
- package/dist/cli/index.d.ts +360 -0
- package/dist/cli/index.js +2027 -0
- package/dist/index.cjs +1168 -0
- package/dist/index.d.cts +362 -0
- package/dist/index.d.ts +24 -126
- package/dist/index.js +552 -199
- package/dist/plugins.cjs +866 -0
- package/dist/plugins.d.cts +385 -0
- package/dist/plugins.d.ts +385 -0
- package/dist/plugins.js +846 -0
- package/package.json +11 -6
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __getProtoOf = Object.getPrototypeOf;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -16,6 +16,17 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
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;
|
|
19
30
|
|
|
20
31
|
// node_modules/picocolors/picocolors.js
|
|
21
32
|
var require_picocolors = __commonJS((exports, module) => {
|
|
@@ -87,26 +98,7 @@ var require_picocolors = __commonJS((exports, module) => {
|
|
|
87
98
|
module.exports.createColors = createColors;
|
|
88
99
|
});
|
|
89
100
|
|
|
90
|
-
// src/define.ts
|
|
91
|
-
function defineConfig(options) {
|
|
92
|
-
return options;
|
|
93
|
-
}
|
|
94
|
-
function defineWorkspace(options) {
|
|
95
|
-
return options;
|
|
96
|
-
}
|
|
97
|
-
// src/build.ts
|
|
98
|
-
import path4 from "node:path";
|
|
99
|
-
import {
|
|
100
|
-
generateDts,
|
|
101
|
-
logIsolatedDeclarationErrors
|
|
102
|
-
} from "bun-dts";
|
|
103
|
-
|
|
104
|
-
// src/errors.ts
|
|
105
|
-
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
106
|
-
|
|
107
101
|
// src/logger.ts
|
|
108
|
-
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
109
|
-
var silent = false;
|
|
110
102
|
function setSilent(value) {
|
|
111
103
|
silent = value ?? false;
|
|
112
104
|
}
|
|
@@ -291,40 +283,140 @@ function logTable(columns, data, footer) {
|
|
|
291
283
|
console.log(footerRow);
|
|
292
284
|
}
|
|
293
285
|
}
|
|
294
|
-
var
|
|
286
|
+
var import_picocolors, silent = false, logger;
|
|
287
|
+
var init_logger = __esm(() => {
|
|
288
|
+
import_picocolors = __toESM(require_picocolors(), 1);
|
|
289
|
+
logger = Logger.getInstance();
|
|
290
|
+
});
|
|
295
291
|
|
|
296
292
|
// src/errors.ts
|
|
297
|
-
|
|
298
|
-
constructor(message) {
|
|
299
|
-
super(message);
|
|
300
|
-
this.name = "BunupError";
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
class BunupBuildError extends BunupError {
|
|
305
|
-
constructor(message) {
|
|
306
|
-
super(message);
|
|
307
|
-
this.name = "BunupBuildError";
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
class BunupDTSBuildError extends BunupError {
|
|
312
|
-
constructor(message) {
|
|
313
|
-
super(message);
|
|
314
|
-
this.name = "BunupDTSBuildError";
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
var parseErrorMessage = (error) => {
|
|
293
|
+
var import_picocolors2, BunupError, BunupBuildError, BunupDTSBuildError, BunupCLIError, BunupWatchError, BunupPluginError, parseErrorMessage = (error) => {
|
|
318
294
|
if (error instanceof Error) {
|
|
319
295
|
return error.message;
|
|
320
296
|
}
|
|
321
297
|
return String(error);
|
|
298
|
+
}, KNOWN_ERRORS, handleError = (error, context) => {
|
|
299
|
+
const errorMessage = parseErrorMessage(error);
|
|
300
|
+
const contextPrefix = context ? `[${context}] ` : "";
|
|
301
|
+
let errorType = "UNKNOWN ERROR";
|
|
302
|
+
if (error instanceof BunupBuildError) {
|
|
303
|
+
errorType = "BUILD ERROR";
|
|
304
|
+
} else if (error instanceof BunupDTSBuildError) {
|
|
305
|
+
errorType = "DTS ERROR";
|
|
306
|
+
} else if (error instanceof BunupCLIError) {
|
|
307
|
+
errorType = "CLI ERROR";
|
|
308
|
+
} else if (error instanceof BunupWatchError) {
|
|
309
|
+
errorType = "WATCH ERROR";
|
|
310
|
+
} else if (error instanceof BunupPluginError) {
|
|
311
|
+
errorType = "PLUGIN ERROR";
|
|
312
|
+
} else if (error instanceof BunupError) {
|
|
313
|
+
errorType = "BUNUP ERROR";
|
|
314
|
+
}
|
|
315
|
+
const knownError = KNOWN_ERRORS.find((error2) => error2.pattern.test(errorMessage) && (error2.errorType === errorType || !error2.errorType));
|
|
316
|
+
if (!knownError && errorType) {
|
|
317
|
+
console.error(`${import_picocolors2.default.red(errorType)} ${contextPrefix}${errorMessage}`);
|
|
318
|
+
}
|
|
319
|
+
if (knownError) {
|
|
320
|
+
console.log(`
|
|
321
|
+
`);
|
|
322
|
+
knownError.logSolution(errorMessage);
|
|
323
|
+
console.log(`
|
|
324
|
+
`);
|
|
325
|
+
} else {
|
|
326
|
+
console.error(import_picocolors2.default.dim(import_picocolors2.default.white("If you think this is a bug, please open an issue at: ") + import_picocolors2.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")));
|
|
327
|
+
}
|
|
328
|
+
}, handleErrorAndExit = (error, context) => {
|
|
329
|
+
handleError(error, context);
|
|
330
|
+
process.exit(1);
|
|
322
331
|
};
|
|
332
|
+
var init_errors = __esm(() => {
|
|
333
|
+
import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
334
|
+
init_logger();
|
|
335
|
+
BunupError = class BunupError extends Error {
|
|
336
|
+
constructor(message) {
|
|
337
|
+
super(message);
|
|
338
|
+
this.name = "BunupError";
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
BunupBuildError = class BunupBuildError extends BunupError {
|
|
342
|
+
constructor(message) {
|
|
343
|
+
super(message);
|
|
344
|
+
this.name = "BunupBuildError";
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
BunupDTSBuildError = class BunupDTSBuildError extends BunupError {
|
|
348
|
+
constructor(message) {
|
|
349
|
+
super(message);
|
|
350
|
+
this.name = "BunupDTSBuildError";
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
BunupCLIError = class BunupCLIError extends BunupError {
|
|
354
|
+
constructor(message) {
|
|
355
|
+
super(message);
|
|
356
|
+
this.name = "BunupCLIError";
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
BunupWatchError = class BunupWatchError extends BunupError {
|
|
360
|
+
constructor(message) {
|
|
361
|
+
super(message);
|
|
362
|
+
this.name = "BunupWatchError";
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
BunupPluginError = class BunupPluginError extends BunupError {
|
|
366
|
+
constructor(message) {
|
|
367
|
+
super(message);
|
|
368
|
+
this.name = "BunupPluginError";
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
KNOWN_ERRORS = [
|
|
372
|
+
{
|
|
373
|
+
pattern: /Could not resolve: "bun"/i,
|
|
374
|
+
errorType: "BUILD ERROR",
|
|
375
|
+
logSolution: () => {
|
|
376
|
+
logger.error(import_picocolors2.default.white("You're trying to build a project that uses Bun. ") + import_picocolors2.default.white("Please set the target option to ") + import_picocolors2.default.cyan("`bun`") + import_picocolors2.default.white(`.
|
|
377
|
+
`) + import_picocolors2.default.white("Example: ") + import_picocolors2.default.green("`bunup --target bun`") + import_picocolors2.default.white(" or in config: ") + import_picocolors2.default.green("{ target: 'bun' }"));
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
];
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// src/loaders.ts
|
|
384
|
+
import path from "path";
|
|
385
|
+
import { loadConfig } from "coffi";
|
|
386
|
+
async function processLoadedConfigs(config, cwd, filter) {
|
|
387
|
+
return Array.isArray(config) && "root" in config[0] ? config.filter((c) => filter ? filter.includes(c.name) : true).map((c) => ({
|
|
388
|
+
rootDir: path.resolve(cwd, c.root),
|
|
389
|
+
options: addField(c.config, "name", c.name)
|
|
390
|
+
})) : [
|
|
391
|
+
{
|
|
392
|
+
rootDir: cwd,
|
|
393
|
+
options: config
|
|
394
|
+
}
|
|
395
|
+
];
|
|
396
|
+
}
|
|
397
|
+
function addField(objectOrArray, field, value) {
|
|
398
|
+
return Array.isArray(objectOrArray) ? objectOrArray.map((o) => ({ ...o, [field]: value })) : { ...objectOrArray, [field]: value };
|
|
399
|
+
}
|
|
400
|
+
async function loadPackageJson(cwd = process.cwd()) {
|
|
401
|
+
const { config, filepath } = await loadConfig({
|
|
402
|
+
name: "package",
|
|
403
|
+
cwd,
|
|
404
|
+
extensions: [".json"]
|
|
405
|
+
});
|
|
406
|
+
return {
|
|
407
|
+
data: config,
|
|
408
|
+
path: filepath
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
var init_loaders = () => {};
|
|
323
412
|
|
|
324
413
|
// src/utils.ts
|
|
325
|
-
import fsSync from "
|
|
326
|
-
import fs from "
|
|
327
|
-
import
|
|
414
|
+
import fsSync from "fs";
|
|
415
|
+
import fs from "fs/promises";
|
|
416
|
+
import path2, { normalize } from "path";
|
|
417
|
+
function ensureArray(value) {
|
|
418
|
+
return Array.isArray(value) ? value : [value];
|
|
419
|
+
}
|
|
328
420
|
function getDefaultJsOutputExtension(format, packageType) {
|
|
329
421
|
switch (format) {
|
|
330
422
|
case "esm":
|
|
@@ -335,25 +427,22 @@ function getDefaultJsOutputExtension(format, packageType) {
|
|
|
335
427
|
return ".global.js";
|
|
336
428
|
}
|
|
337
429
|
}
|
|
338
|
-
function getDefaultDtsOutputExtension(format, packageType) {
|
|
339
|
-
switch (format) {
|
|
340
|
-
case "esm":
|
|
341
|
-
return isModulePackage(packageType) ? ".d.ts" : ".d.mts";
|
|
342
|
-
case "cjs":
|
|
343
|
-
return isModulePackage(packageType) ? ".d.cts" : ".d.ts";
|
|
344
|
-
case "iife":
|
|
345
|
-
return ".global.d.ts";
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
430
|
function removeExtension(filePath) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
431
|
+
const basename = path2.basename(filePath);
|
|
432
|
+
const firstDotIndex = basename.indexOf(".");
|
|
433
|
+
if (firstDotIndex === -1) {
|
|
434
|
+
return filePath;
|
|
435
|
+
}
|
|
436
|
+
const nameWithoutExtensions = basename.slice(0, firstDotIndex);
|
|
437
|
+
const directory = path2.dirname(filePath);
|
|
438
|
+
return directory === "." ? nameWithoutExtensions : path2.join(directory, nameWithoutExtensions);
|
|
353
439
|
}
|
|
354
440
|
function isModulePackage(packageType) {
|
|
355
441
|
return packageType === "module";
|
|
356
442
|
}
|
|
443
|
+
function formatTime(ms) {
|
|
444
|
+
return ms >= 1000 ? `${(ms / 1000).toFixed(2)}s` : `${Math.round(ms)}ms`;
|
|
445
|
+
}
|
|
357
446
|
function getPackageDeps(packageJson) {
|
|
358
447
|
if (!packageJson)
|
|
359
448
|
return [];
|
|
@@ -377,7 +466,7 @@ function getShortFilePath(filePath, maxLength = 3) {
|
|
|
377
466
|
return shortPath;
|
|
378
467
|
}
|
|
379
468
|
async function cleanOutDir(rootDir, outDir) {
|
|
380
|
-
const outDirPath =
|
|
469
|
+
const outDirPath = path2.join(rootDir, outDir);
|
|
381
470
|
try {
|
|
382
471
|
await fs.rm(outDirPath, { recursive: true, force: true });
|
|
383
472
|
} catch (error) {
|
|
@@ -385,54 +474,67 @@ async function cleanOutDir(rootDir, outDir) {
|
|
|
385
474
|
}
|
|
386
475
|
await fs.mkdir(outDirPath, { recursive: true });
|
|
387
476
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
477
|
+
function cleanPath(path3) {
|
|
478
|
+
let cleaned = normalize(path3).replace(/\\/g, "/");
|
|
479
|
+
cleaned = cleaned.replace(/^[a-zA-Z]:\//, "");
|
|
480
|
+
cleaned = cleaned.replace(/^\/+/, "");
|
|
481
|
+
cleaned = cleaned.replace(/\/+/g, "/");
|
|
482
|
+
return cleaned;
|
|
483
|
+
}
|
|
484
|
+
function isDirectoryPath(filePath) {
|
|
485
|
+
return path2.extname(filePath) === "";
|
|
486
|
+
}
|
|
487
|
+
function pathExistsSync(filePath) {
|
|
488
|
+
try {
|
|
489
|
+
fsSync.accessSync(filePath);
|
|
490
|
+
return true;
|
|
491
|
+
} catch (error) {
|
|
492
|
+
return false;
|
|
404
493
|
}
|
|
405
|
-
return entry.map((_entry) => ({
|
|
406
|
-
entry: _entry,
|
|
407
|
-
outputBasePath: getEntryOutputBasePath(_entry)
|
|
408
|
-
}));
|
|
409
494
|
}
|
|
410
|
-
function
|
|
411
|
-
|
|
412
|
-
|
|
495
|
+
function formatListWithAnd(arr) {
|
|
496
|
+
return new Intl.ListFormat("en", {
|
|
497
|
+
style: "long",
|
|
498
|
+
type: "conjunction"
|
|
499
|
+
}).format(arr);
|
|
413
500
|
}
|
|
414
|
-
function
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
501
|
+
async function getFilesFromGlobs(patterns, cwd) {
|
|
502
|
+
const includePatterns = patterns.filter((p) => !p.startsWith("!"));
|
|
503
|
+
const excludePatterns = patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
|
|
504
|
+
const includedFiles = new Set;
|
|
505
|
+
for (const pattern of includePatterns) {
|
|
506
|
+
const glob = new Bun.Glob(pattern);
|
|
507
|
+
for await (const file of glob.scan(cwd)) {
|
|
508
|
+
includedFiles.add(file);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (excludePatterns.length > 0) {
|
|
512
|
+
for (const pattern of excludePatterns) {
|
|
513
|
+
const glob = new Bun.Glob(pattern);
|
|
514
|
+
for await (const file of glob.scan(cwd)) {
|
|
515
|
+
includedFiles.delete(file);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return Array.from(includedFiles);
|
|
420
520
|
}
|
|
521
|
+
var init_utils = __esm(() => {
|
|
522
|
+
init_errors();
|
|
523
|
+
});
|
|
421
524
|
|
|
422
|
-
// src/
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
async function loadPackageJson(cwd = process.cwd()) {
|
|
426
|
-
const { config, filepath } = await loadConfig({
|
|
427
|
-
name: "package",
|
|
428
|
-
cwd,
|
|
429
|
-
extensions: [".json"]
|
|
430
|
-
});
|
|
431
|
-
return {
|
|
432
|
-
data: config,
|
|
433
|
-
path: filepath
|
|
434
|
-
};
|
|
525
|
+
// src/define.ts
|
|
526
|
+
function defineConfig(options) {
|
|
527
|
+
return options;
|
|
435
528
|
}
|
|
529
|
+
function defineWorkspace(options) {
|
|
530
|
+
return options;
|
|
531
|
+
}
|
|
532
|
+
// src/build.ts
|
|
533
|
+
init_errors();
|
|
534
|
+
init_loaders();
|
|
535
|
+
init_logger();
|
|
536
|
+
import path4 from "path";
|
|
537
|
+
import { dts } from "bun-dts";
|
|
436
538
|
|
|
437
539
|
// src/constants/re.ts
|
|
438
540
|
var JS_RE = /\.(js|jsx|cjs|mjs)$/;
|
|
@@ -440,11 +542,166 @@ var TS_RE = /\.(ts|tsx|mts|cts)$/;
|
|
|
440
542
|
var DTS_RE = /\.(d\.(ts|mts|cts))$/;
|
|
441
543
|
var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
|
|
442
544
|
var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
|
|
545
|
+
var CSS_RE = /\.(css)$/;
|
|
546
|
+
|
|
547
|
+
// src/plugins/built-in/node/shims.ts
|
|
548
|
+
function shims() {
|
|
549
|
+
return {
|
|
550
|
+
type: "bun",
|
|
551
|
+
name: "shims",
|
|
552
|
+
plugin: {
|
|
553
|
+
name: "bunup:shims",
|
|
554
|
+
setup(build) {
|
|
555
|
+
const isNodeCompatibleTarget = build.config.target === "node" || build.config.target === "bun";
|
|
556
|
+
const isEsm = build.config.format === "esm";
|
|
557
|
+
const isCjs = build.config.format === "cjs";
|
|
558
|
+
if (!isNodeCompatibleTarget || !isEsm && !isCjs) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
build.config.define = {
|
|
562
|
+
...build.config.define,
|
|
563
|
+
...isCjs && {
|
|
564
|
+
"import.meta.url": "importMetaUrl"
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
build.onLoad({ filter: JS_TS_RE }, async ({ path: path2 }) => {
|
|
568
|
+
const content = await Bun.file(path2).text();
|
|
569
|
+
let shimCode = "";
|
|
570
|
+
if (isEsm && (/\b__dirname\b/.test(content) || /\b__filename\b/.test(content))) {
|
|
571
|
+
shimCode = `import { fileURLToPath } from 'url';
|
|
572
|
+
import { dirname } from 'path';
|
|
573
|
+
|
|
574
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
575
|
+
const __dirname = dirname(__filename);
|
|
576
|
+
|
|
577
|
+
`;
|
|
578
|
+
}
|
|
579
|
+
if (isCjs && /\bimport\.meta\.url\b/.test(content)) {
|
|
580
|
+
shimCode = `import { pathToFileURL } from 'url';
|
|
581
|
+
|
|
582
|
+
const importMetaUrl = pathToFileURL(__filename).href;
|
|
583
|
+
|
|
584
|
+
`;
|
|
585
|
+
}
|
|
586
|
+
if (!shimCode)
|
|
587
|
+
return;
|
|
588
|
+
const lines = content.split(`
|
|
589
|
+
`);
|
|
590
|
+
const firstLine = lines[0];
|
|
591
|
+
const restLines = lines.slice(1);
|
|
592
|
+
return {
|
|
593
|
+
contents: [firstLine, shimCode, ...restLines].join(`
|
|
594
|
+
`)
|
|
595
|
+
};
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
// src/plugins/built-in/productivity/exports.ts
|
|
602
|
+
init_logger();
|
|
603
|
+
init_utils();
|
|
604
|
+
function exports(options = {}) {
|
|
605
|
+
return {
|
|
606
|
+
type: "bunup",
|
|
607
|
+
name: "exports",
|
|
608
|
+
hooks: {
|
|
609
|
+
onBuildDone: async ({ output, options: buildOptions, meta }) => {
|
|
610
|
+
if (!meta.packageJson.path || !meta.packageJson.data) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
try {
|
|
614
|
+
const { exportsField, entryPoints } = generateExportsFields(output.files);
|
|
615
|
+
const files = Array.isArray(meta.packageJson.data.files) ? [
|
|
616
|
+
...new Set([
|
|
617
|
+
...meta.packageJson.data.files,
|
|
618
|
+
buildOptions.outDir
|
|
619
|
+
])
|
|
620
|
+
] : [buildOptions.outDir];
|
|
621
|
+
const mergedExports = { ...exportsField };
|
|
622
|
+
if (options.extraExports) {
|
|
623
|
+
for (const [key, value] of Object.entries(options.extraExports)) {
|
|
624
|
+
if (typeof value === "string") {
|
|
625
|
+
mergedExports[key] = value;
|
|
626
|
+
} else {
|
|
627
|
+
const existingExport = mergedExports[key];
|
|
628
|
+
if (typeof existingExport === "object" && existingExport !== null) {
|
|
629
|
+
mergedExports[key] = {
|
|
630
|
+
...existingExport,
|
|
631
|
+
...value
|
|
632
|
+
};
|
|
633
|
+
} else {
|
|
634
|
+
mergedExports[key] = value;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
const newPackageJson = {
|
|
640
|
+
name: meta.packageJson.data.name,
|
|
641
|
+
description: meta.packageJson.data.description,
|
|
642
|
+
version: meta.packageJson.data.version,
|
|
643
|
+
type: meta.packageJson.data.type,
|
|
644
|
+
private: meta.packageJson.data.private,
|
|
645
|
+
files,
|
|
646
|
+
...entryPoints,
|
|
647
|
+
exports: mergedExports
|
|
648
|
+
};
|
|
649
|
+
for (const key in meta.packageJson.data) {
|
|
650
|
+
if (Object.prototype.hasOwnProperty.call(meta.packageJson.data, key) && !Object.prototype.hasOwnProperty.call(newPackageJson, key)) {
|
|
651
|
+
newPackageJson[key] = meta.packageJson.data[key];
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
await Bun.write(meta.packageJson.path, JSON.stringify(newPackageJson, null, 2));
|
|
655
|
+
logger.cli("Updated package.json with exports");
|
|
656
|
+
} catch {
|
|
657
|
+
logger.error("Failed to update package.json");
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
function generateExportsFields(files) {
|
|
664
|
+
const exportsField = {};
|
|
665
|
+
const entryPoints = {};
|
|
666
|
+
const filteredFiles = filterFiles(files);
|
|
667
|
+
for (const file of filteredFiles) {
|
|
668
|
+
const exportType = formatToExportField(file.format, file.dts);
|
|
669
|
+
const relativePath = `./${cleanPath(file.relativePathToRootDir)}`;
|
|
670
|
+
const exportKey = getExportKey(cleanPath(file.relativePathToOutputDir));
|
|
671
|
+
exportsField[exportKey] = {
|
|
672
|
+
...exportsField[exportKey],
|
|
673
|
+
[exportType]: relativePath
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
for (const field of Object.keys(exportsField["."] ?? {})) {
|
|
677
|
+
const entryPoint = exportFieldToEntryPoint(field);
|
|
678
|
+
entryPoints[entryPoint] = exportsField["."][field];
|
|
679
|
+
}
|
|
680
|
+
return { exportsField, entryPoints };
|
|
681
|
+
}
|
|
682
|
+
function filterFiles(files) {
|
|
683
|
+
return files.filter((file) => JS_DTS_RE.test(file.fullPath) && file.kind === "entry-point");
|
|
684
|
+
}
|
|
685
|
+
function getExportKey(relativePathToOutputDir) {
|
|
686
|
+
const pathSegments = cleanPath(removeExtension(relativePathToOutputDir)).split("/");
|
|
687
|
+
if (pathSegments.length === 1 && pathSegments[0].startsWith("index")) {
|
|
688
|
+
return ".";
|
|
689
|
+
}
|
|
690
|
+
return `./${pathSegments.filter((p) => !p.startsWith("index")).join("/")}`;
|
|
691
|
+
}
|
|
692
|
+
function exportFieldToEntryPoint(exportField) {
|
|
693
|
+
return exportField === "types" ? "types" : exportField === "require" ? "main" : "module";
|
|
694
|
+
}
|
|
695
|
+
function formatToExportField(format, dts) {
|
|
696
|
+
return dts ? "types" : format === "esm" ? "import" : "require";
|
|
697
|
+
}
|
|
443
698
|
// src/plugins/built-in/css/inject-styles.ts
|
|
444
|
-
import path3 from "
|
|
699
|
+
import path3 from "path";
|
|
700
|
+
init_logger();
|
|
445
701
|
|
|
446
702
|
// src/plugins/utils.ts
|
|
447
703
|
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
704
|
+
init_errors();
|
|
448
705
|
function filterBunupBunPlugins(plugins) {
|
|
449
706
|
if (!plugins)
|
|
450
707
|
return [];
|
|
@@ -473,11 +730,104 @@ async function runPluginBuildDoneHooks(bunupPlugins, options, output, meta) {
|
|
|
473
730
|
}
|
|
474
731
|
}
|
|
475
732
|
}
|
|
733
|
+
async function getPackageForPlugin(name, pluginName) {
|
|
734
|
+
let pkg;
|
|
735
|
+
try {
|
|
736
|
+
pkg = await import(name);
|
|
737
|
+
} catch {
|
|
738
|
+
throw new BunupPluginError(`[${import_picocolors3.default.cyan(name)}] is required for the ${pluginName} plugin. Please install it with: ${import_picocolors3.default.blue(`bun add ${name} --dev`)}`);
|
|
739
|
+
}
|
|
740
|
+
return pkg;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// src/plugins/built-in/css/inject-styles.ts
|
|
744
|
+
function injectStyles(options) {
|
|
745
|
+
const { inject, ...transformOptions } = options ?? {};
|
|
746
|
+
return {
|
|
747
|
+
type: "bun",
|
|
748
|
+
name: "inject-styles",
|
|
749
|
+
plugin: {
|
|
750
|
+
name: "bunup:inject-styles",
|
|
751
|
+
async setup(build) {
|
|
752
|
+
const lightningcss = await getPackageForPlugin("lightningcss", "inject-styles");
|
|
753
|
+
build.onResolve({ filter: /^__inject-style$/ }, () => {
|
|
754
|
+
return {
|
|
755
|
+
path: "__inject-style",
|
|
756
|
+
namespace: "__inject-style"
|
|
757
|
+
};
|
|
758
|
+
});
|
|
759
|
+
build.onLoad({ filter: /^__inject-style$/, namespace: "__inject-style" }, () => {
|
|
760
|
+
return {
|
|
761
|
+
contents: `
|
|
762
|
+
export default function injectStyle(css) {
|
|
763
|
+
if (!css || typeof document === 'undefined') return
|
|
764
|
+
|
|
765
|
+
const head = document.head || document.getElementsByTagName('head')[0]
|
|
766
|
+
const style = document.createElement('style')
|
|
767
|
+
head.appendChild(style)
|
|
768
|
+
|
|
769
|
+
if (style.styleSheet) {
|
|
770
|
+
style.styleSheet.cssText = css
|
|
771
|
+
} else {
|
|
772
|
+
style.appendChild(document.createTextNode(css))
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
`,
|
|
776
|
+
loader: "js"
|
|
777
|
+
};
|
|
778
|
+
});
|
|
779
|
+
build.onLoad({ filter: CSS_RE }, async (args) => {
|
|
780
|
+
const source = await Bun.file(args.path).text();
|
|
781
|
+
const { code, warnings } = lightningcss.transform({
|
|
782
|
+
...transformOptions,
|
|
783
|
+
filename: path3.basename(args.path),
|
|
784
|
+
code: Buffer.from(source),
|
|
785
|
+
minify: transformOptions.minify ?? (build.config.minify === true || typeof build.config.minify === "object" && build.config.minify.whitespace)
|
|
786
|
+
});
|
|
787
|
+
for (const warning of warnings) {
|
|
788
|
+
logger.warn(warning.message);
|
|
789
|
+
}
|
|
790
|
+
const stringifiedCode = JSON.stringify(code.toString());
|
|
791
|
+
const js = inject ? await inject(stringifiedCode, args.path) : `import injectStyle from '__inject-style';injectStyle(${stringifiedCode})`;
|
|
792
|
+
return {
|
|
793
|
+
contents: js,
|
|
794
|
+
loader: "js"
|
|
795
|
+
};
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
}
|
|
476
801
|
// src/plugins/built-in/productivity/copy.ts
|
|
477
|
-
|
|
478
|
-
import {
|
|
802
|
+
init_utils();
|
|
803
|
+
import { join } from "path";
|
|
804
|
+
import { basename } from "path";
|
|
805
|
+
function copy(patterns, outPath) {
|
|
806
|
+
return {
|
|
807
|
+
type: "bunup",
|
|
808
|
+
name: "copy",
|
|
809
|
+
hooks: {
|
|
810
|
+
onBuildDone: async ({ options, meta }) => {
|
|
811
|
+
const destinationPath = outPath || options.outDir;
|
|
812
|
+
for (const pattern of patterns) {
|
|
813
|
+
const glob = new Bun.Glob(pattern);
|
|
814
|
+
for await (const filePath of glob.scan({
|
|
815
|
+
cwd: meta.rootDir,
|
|
816
|
+
dot: true
|
|
817
|
+
})) {
|
|
818
|
+
const sourceFile = Bun.file(join(meta.rootDir, filePath));
|
|
819
|
+
await Bun.write(outPath && isDirectoryPath(outPath) ? join(destinationPath, basename(filePath)) : destinationPath, sourceFile);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
}
|
|
479
826
|
// src/plugins/internal/report.ts
|
|
480
827
|
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
828
|
+
init_logger();
|
|
829
|
+
init_logger();
|
|
830
|
+
init_utils();
|
|
481
831
|
function report() {
|
|
482
832
|
return {
|
|
483
833
|
type: "bunup",
|
|
@@ -555,6 +905,7 @@ ${text}`;
|
|
|
555
905
|
}
|
|
556
906
|
|
|
557
907
|
// src/options.ts
|
|
908
|
+
init_utils();
|
|
558
909
|
var DEFAULT_OPTIONS = {
|
|
559
910
|
entry: [],
|
|
560
911
|
format: ["cjs"],
|
|
@@ -608,11 +959,24 @@ function getResolvedDefine(define, env) {
|
|
|
608
959
|
function getResolvedSplitting(splitting, format) {
|
|
609
960
|
return splitting === undefined ? format === "esm" : splitting;
|
|
610
961
|
}
|
|
962
|
+
var DEFAULT_ENTRY_NAMING = "[dir]/[name].[ext]";
|
|
963
|
+
function getResolvedNaming(naming, fmt, packageType) {
|
|
964
|
+
const resolvedNaming = typeof naming === "object" ? { entry: DEFAULT_ENTRY_NAMING, ...naming } : naming ?? DEFAULT_ENTRY_NAMING;
|
|
965
|
+
const replaceExt = (pattern) => pattern.replace(".[ext]", getDefaultJsOutputExtension(fmt, packageType));
|
|
966
|
+
if (typeof resolvedNaming === "string") {
|
|
967
|
+
return replaceExt(resolvedNaming);
|
|
968
|
+
}
|
|
969
|
+
return {
|
|
970
|
+
...resolvedNaming,
|
|
971
|
+
entry: replaceExt(resolvedNaming.entry)
|
|
972
|
+
};
|
|
973
|
+
}
|
|
611
974
|
function getResolvedEnv(env) {
|
|
612
975
|
return typeof env === "string" ? env : undefined;
|
|
613
976
|
}
|
|
614
977
|
|
|
615
978
|
// src/helpers/external.ts
|
|
979
|
+
init_utils();
|
|
616
980
|
function getPackageDepsPatterns(packageJson) {
|
|
617
981
|
return getPackageDeps(packageJson).map((dep) => new RegExp(`^${dep}($|\\/|\\\\)`));
|
|
618
982
|
}
|
|
@@ -646,6 +1010,7 @@ function externalOptionPlugin(options, packageJson) {
|
|
|
646
1010
|
}
|
|
647
1011
|
|
|
648
1012
|
// src/build.ts
|
|
1013
|
+
init_utils();
|
|
649
1014
|
async function build(partialOptions, rootDir = process.cwd()) {
|
|
650
1015
|
const buildOutput = {
|
|
651
1016
|
files: []
|
|
@@ -668,113 +1033,98 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
668
1033
|
}
|
|
669
1034
|
const bunupPlugins = filterBunupPlugins(options.plugins);
|
|
670
1035
|
await runPluginBuildStartHooks(bunupPlugins, options);
|
|
671
|
-
const processableEntries = getProcessableEntries(options.entry);
|
|
672
1036
|
const packageType = packageJson.data?.type;
|
|
673
1037
|
const plugins = [
|
|
674
1038
|
externalOptionPlugin(options, packageJson.data),
|
|
675
1039
|
...filterBunupBunPlugins(options.plugins).map((p) => p.plugin)
|
|
676
1040
|
];
|
|
677
|
-
if (
|
|
678
|
-
const
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
sourcemap: getResolvedSourcemap(options.sourcemap),
|
|
696
|
-
loader: options.loader,
|
|
697
|
-
drop: options.drop,
|
|
698
|
-
banner: options.banner,
|
|
699
|
-
footer: options.footer,
|
|
700
|
-
publicPath: options.publicPath,
|
|
701
|
-
env: getResolvedEnv(options.env),
|
|
702
|
-
plugins,
|
|
703
|
-
throw: false
|
|
704
|
-
});
|
|
705
|
-
for (const log of result.logs) {
|
|
706
|
-
if (log.level === "error") {
|
|
707
|
-
throw new BunupBuildError(log.message);
|
|
708
|
-
}
|
|
709
|
-
if (log.level === "warning")
|
|
710
|
-
logger.warn(log.message);
|
|
711
|
-
else if (log.level === "info")
|
|
712
|
-
logger.info(log.message);
|
|
713
|
-
}
|
|
714
|
-
for (const file of result.outputs) {
|
|
715
|
-
const relativePathToRootDir = getRelativePathToRootDir(file.path, rootDir);
|
|
716
|
-
if (file.kind === "entry-point") {
|
|
717
|
-
logger.progress(fmt.toUpperCase(), relativePathToRootDir, {
|
|
1041
|
+
if (options.dts) {
|
|
1042
|
+
const { resolve, entry, splitting } = typeof options.dts === "object" ? options.dts : {};
|
|
1043
|
+
let entrypoints2;
|
|
1044
|
+
if (entry) {
|
|
1045
|
+
entrypoints2 = await getFilesFromGlobs(ensureArray(entry), rootDir);
|
|
1046
|
+
}
|
|
1047
|
+
if (Array.isArray(entrypoints2) && !entrypoints2.length) {
|
|
1048
|
+
throw new BunupDTSBuildError("The dts entrypoints you provided do not exist. Please make sure the entrypoints point to valid files.");
|
|
1049
|
+
}
|
|
1050
|
+
plugins.push(dts({
|
|
1051
|
+
resolve,
|
|
1052
|
+
preferredTsConfigPath: options.preferredTsconfigPath,
|
|
1053
|
+
entry: entrypoints2,
|
|
1054
|
+
cwd: rootDir,
|
|
1055
|
+
splitting,
|
|
1056
|
+
onDeclarationsGenerated({ results, buildConfig }) {
|
|
1057
|
+
for (const result of results) {
|
|
1058
|
+
logger.progress("DTS", `${options.outDir}/${result.outputPath}`, {
|
|
718
1059
|
identifier: options.name
|
|
719
1060
|
});
|
|
1061
|
+
const fullPath = path4.join(rootDir, options.outDir, result.outputPath);
|
|
1062
|
+
if (buildConfig.format) {
|
|
1063
|
+
buildOutput.files.push({
|
|
1064
|
+
fullPath,
|
|
1065
|
+
relativePathToRootDir: getRelativePathToRootDir(fullPath, rootDir),
|
|
1066
|
+
relativePathToOutputDir: result.outputPath,
|
|
1067
|
+
dts: true,
|
|
1068
|
+
format: buildConfig.format,
|
|
1069
|
+
kind: result.kind
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
720
1072
|
}
|
|
721
|
-
buildOutput.files.push({
|
|
722
|
-
fullPath: file.path,
|
|
723
|
-
relativePathToRootDir,
|
|
724
|
-
dts: false,
|
|
725
|
-
entry,
|
|
726
|
-
outputBasePath,
|
|
727
|
-
format: fmt
|
|
728
|
-
});
|
|
729
1073
|
}
|
|
730
1074
|
}));
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
if (
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
const
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
1075
|
+
}
|
|
1076
|
+
const entrypoints = await getFilesFromGlobs(ensureArray(options.entry), rootDir);
|
|
1077
|
+
if (!entrypoints.length) {
|
|
1078
|
+
throw new BunupBuildError("The entrypoints you provided do not exist. Please make sure the entrypoints point to valid files.");
|
|
1079
|
+
}
|
|
1080
|
+
const buildPromises = options.format.flatMap(async (fmt) => {
|
|
1081
|
+
const result = await Bun.build({
|
|
1082
|
+
entrypoints: entrypoints.map((file) => `${rootDir}/${file}`),
|
|
1083
|
+
format: fmt,
|
|
1084
|
+
naming: getResolvedNaming(options.naming, fmt, packageType),
|
|
1085
|
+
splitting: getResolvedSplitting(options.splitting, fmt),
|
|
1086
|
+
bytecode: getResolvedBytecode(options.bytecode, fmt),
|
|
1087
|
+
define: getResolvedDefine(options.define, options.env),
|
|
1088
|
+
minify: getResolvedMinify(options),
|
|
1089
|
+
outdir: `${rootDir}/${options.outDir}`,
|
|
1090
|
+
target: options.target,
|
|
1091
|
+
sourcemap: getResolvedSourcemap(options.sourcemap),
|
|
1092
|
+
loader: options.loader,
|
|
1093
|
+
drop: options.drop,
|
|
1094
|
+
banner: options.banner,
|
|
1095
|
+
footer: options.footer,
|
|
1096
|
+
publicPath: options.publicPath,
|
|
1097
|
+
env: getResolvedEnv(options.env),
|
|
1098
|
+
plugins,
|
|
1099
|
+
throw: false
|
|
1100
|
+
});
|
|
1101
|
+
for (const log of result.logs) {
|
|
1102
|
+
if (log.level === "error") {
|
|
1103
|
+
throw new BunupBuildError(log.message);
|
|
747
1104
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
buildOutput.files.push({
|
|
758
|
-
fullPath: filePath,
|
|
759
|
-
relativePathToRootDir,
|
|
760
|
-
dts: true,
|
|
761
|
-
entry,
|
|
762
|
-
outputBasePath,
|
|
763
|
-
format: fmt
|
|
764
|
-
});
|
|
765
|
-
if (result.errors.length > 0) {
|
|
766
|
-
logIsolatedDeclarationErrors(result.errors, {
|
|
767
|
-
shouldExit: true
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
await Bun.write(filePath, result.dts);
|
|
771
|
-
logger.progress("DTS", relativePathToRootDir, {
|
|
1105
|
+
if (log.level === "warning")
|
|
1106
|
+
logger.warn(log.message);
|
|
1107
|
+
else if (log.level === "info")
|
|
1108
|
+
logger.info(log.message);
|
|
1109
|
+
}
|
|
1110
|
+
for (const file of result.outputs) {
|
|
1111
|
+
const relativePathToRootDir = getRelativePathToRootDir(file.path, rootDir);
|
|
1112
|
+
if (file.kind === "entry-point") {
|
|
1113
|
+
logger.progress(fmt.toUpperCase(), relativePathToRootDir, {
|
|
772
1114
|
identifier: options.name
|
|
773
1115
|
});
|
|
774
1116
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
1117
|
+
buildOutput.files.push({
|
|
1118
|
+
fullPath: file.path,
|
|
1119
|
+
relativePathToRootDir,
|
|
1120
|
+
relativePathToOutputDir: getRelativePathToOutputDir(relativePathToRootDir, options.outDir),
|
|
1121
|
+
dts: false,
|
|
1122
|
+
format: fmt,
|
|
1123
|
+
kind: file.kind
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
await Promise.all(buildPromises);
|
|
778
1128
|
await runPluginBuildDoneHooks(bunupPlugins, options, buildOutput, {
|
|
779
1129
|
packageJson,
|
|
780
1130
|
rootDir
|
|
@@ -784,7 +1134,10 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
784
1134
|
}
|
|
785
1135
|
}
|
|
786
1136
|
function getRelativePathToRootDir(filePath, rootDir) {
|
|
787
|
-
return filePath.replace(`${rootDir}/`, "");
|
|
1137
|
+
return cleanPath(filePath).replace(`${cleanPath(rootDir)}/`, "");
|
|
1138
|
+
}
|
|
1139
|
+
function getRelativePathToOutputDir(relativePathToRootDir, outDir) {
|
|
1140
|
+
return cleanPath(relativePathToRootDir).replace(`${cleanPath(outDir)}/`, "");
|
|
788
1141
|
}
|
|
789
1142
|
export {
|
|
790
1143
|
defineWorkspace,
|