bunup 0.8.48 → 0.8.49
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/{chunk-gh7z7s46.js → chunk-5v78yfze.js} +10 -1
- package/dist/{chunk-xebwdvyv.js → chunk-63s8ht8p.js} +2 -2
- package/dist/chunk-b38k5sg1.js +949 -0
- package/dist/{chunk-rnbj1nec.js → chunk-htbpffg4.js} +3 -3
- package/dist/{chunk-djb64jje.d.ts → chunk-nsmdhpdd.d.ts} +11 -2
- package/dist/{chunk-e7gp8gbh.js → chunk-qy8akfev.js} +1 -1
- package/dist/{chunk-snvybwa2.js → chunk-t9xma3m6.js} +1 -1
- package/dist/{chunk-a76fsvj7.js → chunk-y0jgbvca.js} +53 -1
- package/dist/cli/index.js +8 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +5 -12
- package/package.json +8 -3
- package/dist/chunk-kpthwads.js +0 -378
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
loadPackageJson
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5v78yfze.js";
|
|
5
5
|
import {
|
|
6
6
|
displayBunupGradientArt
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-qy8akfev.js";
|
|
8
8
|
import {
|
|
9
9
|
formatListWithAnd,
|
|
10
10
|
link
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-y0jgbvca.js";
|
|
12
12
|
|
|
13
13
|
// src/cli/init.ts
|
|
14
14
|
import fs from "fs";
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
type Resolve = boolean | (string | RegExp)[];
|
|
2
|
+
type GenerateDtsOptions = {
|
|
3
|
+
preferredTsConfigPath?: string
|
|
4
|
+
resolve?: Resolve
|
|
5
|
+
cwd?: string
|
|
6
|
+
splitting?: boolean
|
|
7
|
+
minify?: boolean
|
|
8
|
+
};
|
|
2
9
|
import { BunPlugin } from "bun";
|
|
3
10
|
type PackageJson = {
|
|
4
11
|
/** The parsed content of the package.json file */
|
|
@@ -162,7 +169,9 @@ interface BuildOptions {
|
|
|
162
169
|
* When set to true, generates declaration files for all entry points
|
|
163
170
|
* Can also be configured with DtsOptions for more control
|
|
164
171
|
*/
|
|
165
|
-
dts?: boolean | Pick<
|
|
172
|
+
dts?: boolean | (Pick<GenerateDtsOptions, "resolve" | "splitting" | "minify"> & {
|
|
173
|
+
entry?: string | string[]
|
|
174
|
+
});
|
|
166
175
|
/**
|
|
167
176
|
* Path to a preferred tsconfig.json file to use for declaration generation
|
|
168
177
|
*
|
|
@@ -269,6 +269,18 @@ var handleErrorAndExit = (error, context) => {
|
|
|
269
269
|
import fsSync from "fs";
|
|
270
270
|
import fs from "fs/promises";
|
|
271
271
|
import path, { normalize } from "path";
|
|
272
|
+
import { isCI, isDevelopment } from "std-env";
|
|
273
|
+
|
|
274
|
+
// src/constants/re.ts
|
|
275
|
+
var JS_RE = /\.(js|jsx|cjs|mjs)$/;
|
|
276
|
+
var TS_RE = /\.(ts|tsx|mts|cts)$/;
|
|
277
|
+
var DTS_RE = /\.(d\.(ts|mts|cts))$/;
|
|
278
|
+
var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
|
|
279
|
+
var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
|
|
280
|
+
var CSS_RE = /\.(css)$/;
|
|
281
|
+
var EXTENSION_REGEX = /\.(d\.(ts|cts|mts)|[cm]?[jt]s)$/;
|
|
282
|
+
|
|
283
|
+
// src/utils.ts
|
|
272
284
|
function ensureArray(value) {
|
|
273
285
|
return Array.isArray(value) ? value : [value];
|
|
274
286
|
}
|
|
@@ -292,6 +304,13 @@ function getDefaultDtsExtention(format, packageType) {
|
|
|
292
304
|
return ".global.d.ts";
|
|
293
305
|
}
|
|
294
306
|
}
|
|
307
|
+
function getDeclarationExtensionFromJsExtension(ext) {
|
|
308
|
+
if (ext === ".mjs")
|
|
309
|
+
return ".d.mts";
|
|
310
|
+
if (ext === ".cjs")
|
|
311
|
+
return ".d.cts";
|
|
312
|
+
return ".d.ts";
|
|
313
|
+
}
|
|
295
314
|
function isModulePackage(packageType) {
|
|
296
315
|
return packageType === "module";
|
|
297
316
|
}
|
|
@@ -373,5 +392,38 @@ async function getFilesFromGlobs(patterns, cwd) {
|
|
|
373
392
|
}
|
|
374
393
|
return Array.from(includedFiles);
|
|
375
394
|
}
|
|
395
|
+
function isDev() {
|
|
396
|
+
return isDevelopment || !isCI;
|
|
397
|
+
}
|
|
398
|
+
function generateRandomString(length = 10) {
|
|
399
|
+
return Array.from({ length }, () => String.fromCharCode(97 + Math.floor(Math.random() * 26))).join("");
|
|
400
|
+
}
|
|
401
|
+
function isNullOrUndefined(value) {
|
|
402
|
+
return value === null || value === undefined;
|
|
403
|
+
}
|
|
404
|
+
function isTypeScriptFile(path2) {
|
|
405
|
+
if (!path2)
|
|
406
|
+
return false;
|
|
407
|
+
return TS_RE.test(path2);
|
|
408
|
+
}
|
|
409
|
+
function getExtension(filename) {
|
|
410
|
+
const match = filename.match(EXTENSION_REGEX);
|
|
411
|
+
if (!match)
|
|
412
|
+
return "";
|
|
413
|
+
const ext = match[0];
|
|
414
|
+
return ext;
|
|
415
|
+
}
|
|
416
|
+
function replaceExtension(filename, newExt) {
|
|
417
|
+
if (EXTENSION_REGEX.test(filename)) {
|
|
418
|
+
return filename.replace(EXTENSION_REGEX, newExt);
|
|
419
|
+
}
|
|
420
|
+
return filename + newExt;
|
|
421
|
+
}
|
|
422
|
+
function deleteExtension(filename) {
|
|
423
|
+
return filename.replace(EXTENSION_REGEX, "");
|
|
424
|
+
}
|
|
425
|
+
function returnPathIfExists(path2) {
|
|
426
|
+
return pathExistsSync(path2) ? path2 : null;
|
|
427
|
+
}
|
|
376
428
|
|
|
377
|
-
export { __toESM, __require, setSilent, logTable, link, logger, BunupBuildError, BunupCLIError, BunupWatchError, BunupPluginError, parseErrorMessage, handleError, handleErrorAndExit, ensureArray, getDefaultOutputExtension, getDefaultDtsExtention, formatTime, getPackageDeps, formatFileSize, getShortFilePath, cleanOutDir, cleanPath, isDirectoryPath, pathExistsSync, formatListWithAnd, getFilesFromGlobs };
|
|
429
|
+
export { __toESM, __require, JS_RE, JS_TS_RE, JS_DTS_RE, CSS_RE, setSilent, logTable, link, logger, BunupBuildError, BunupCLIError, BunupWatchError, BunupPluginError, parseErrorMessage, handleError, handleErrorAndExit, ensureArray, getDefaultOutputExtension, getDefaultDtsExtention, getDeclarationExtensionFromJsExtension, formatTime, getPackageDeps, formatFileSize, getShortFilePath, cleanOutDir, cleanPath, isDirectoryPath, pathExistsSync, formatListWithAnd, getFilesFromGlobs, isDev, generateRandomString, isNullOrUndefined, isTypeScriptFile, getExtension, replaceExtension, deleteExtension, returnPathIfExists };
|
package/dist/cli/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
3
|
import {
|
|
4
|
+
BUNUP_DOCS_URL,
|
|
4
5
|
build,
|
|
5
6
|
createBuildOptions
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import"../chunk-
|
|
7
|
+
} from "../chunk-b38k5sg1.js";
|
|
8
|
+
import"../chunk-t9xma3m6.js";
|
|
8
9
|
import {
|
|
9
10
|
processLoadedConfigs
|
|
10
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-5v78yfze.js";
|
|
11
12
|
import {
|
|
12
13
|
BunupCLIError,
|
|
13
14
|
BunupWatchError,
|
|
@@ -21,14 +22,14 @@ import {
|
|
|
21
22
|
logger,
|
|
22
23
|
parseErrorMessage,
|
|
23
24
|
setSilent
|
|
24
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-y0jgbvca.js";
|
|
25
26
|
|
|
26
27
|
// src/cli/index.ts
|
|
27
28
|
import { loadConfig } from "coffi";
|
|
28
29
|
import pc3 from "picocolors";
|
|
29
30
|
import { exec } from "tinyexec";
|
|
30
31
|
// package.json
|
|
31
|
-
var version = "0.8.
|
|
32
|
+
var version = "0.8.49";
|
|
32
33
|
|
|
33
34
|
// src/watch.ts
|
|
34
35
|
import path from "path";
|
|
@@ -87,11 +88,6 @@ async function watch(partialOptions, rootDir) {
|
|
|
87
88
|
|
|
88
89
|
// src/cli/options.ts
|
|
89
90
|
import pc2 from "picocolors";
|
|
90
|
-
|
|
91
|
-
// src/constants/index.ts
|
|
92
|
-
var BUNUP_DOCS_URL = "https://bunup.dev/docs";
|
|
93
|
-
|
|
94
|
-
// src/cli/options.ts
|
|
95
91
|
var createHandlers = () => ({
|
|
96
92
|
boolean: (key) => (value, options) => {
|
|
97
93
|
options[key] = value === true || value === "true";
|
|
@@ -485,12 +481,12 @@ var parseCliOptions = (argv) => {
|
|
|
485
481
|
async function main(args = Bun.argv.slice(2)) {
|
|
486
482
|
const cliOptions = parseCliOptions(args);
|
|
487
483
|
if (cliOptions.new) {
|
|
488
|
-
const { newProject } = await import("../chunk-
|
|
484
|
+
const { newProject } = await import("../chunk-63s8ht8p.js");
|
|
489
485
|
await newProject();
|
|
490
486
|
return;
|
|
491
487
|
}
|
|
492
488
|
if (cliOptions.init) {
|
|
493
|
-
const { init } = await import("../chunk-
|
|
489
|
+
const { init } = await import("../chunk-htbpffg4.js");
|
|
494
490
|
await init();
|
|
495
491
|
return;
|
|
496
492
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Arrayable, BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin } from "./chunk-
|
|
1
|
+
import { Arrayable, BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin } from "./chunk-nsmdhpdd";
|
|
2
2
|
declare function build(partialOptions: Partial<BuildOptions>, rootDir?: string): Promise<void>;
|
|
3
3
|
declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
|
|
4
4
|
declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
build
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import"./chunk-
|
|
6
|
-
import"./chunk-
|
|
7
|
-
import"./chunk-
|
|
4
|
+
} from "./chunk-b38k5sg1.js";
|
|
5
|
+
import"./chunk-t9xma3m6.js";
|
|
6
|
+
import"./chunk-5v78yfze.js";
|
|
7
|
+
import"./chunk-y0jgbvca.js";
|
|
8
8
|
// src/define.ts
|
|
9
9
|
function defineConfig(options) {
|
|
10
10
|
return options;
|
package/dist/plugins.d.ts
CHANGED
package/dist/plugins.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
getPackageForPlugin
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-t9xma3m6.js";
|
|
5
5
|
import {
|
|
6
|
+
CSS_RE,
|
|
7
|
+
JS_DTS_RE,
|
|
8
|
+
JS_TS_RE,
|
|
6
9
|
cleanPath,
|
|
7
10
|
isDirectoryPath,
|
|
8
11
|
logger
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-y0jgbvca.js";
|
|
10
13
|
|
|
11
14
|
// src/plugins/built-in/copy.ts
|
|
12
15
|
import { basename, join } from "path";
|
|
@@ -33,16 +36,6 @@ function copy(patterns, outPath) {
|
|
|
33
36
|
}
|
|
34
37
|
// src/plugins/built-in/exports.ts
|
|
35
38
|
import path from "path";
|
|
36
|
-
|
|
37
|
-
// src/constants/re.ts
|
|
38
|
-
var JS_RE = /\.(js|jsx|cjs|mjs)$/;
|
|
39
|
-
var TS_RE = /\.(ts|tsx|mts|cts)$/;
|
|
40
|
-
var DTS_RE = /\.(d\.(ts|mts|cts))$/;
|
|
41
|
-
var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
|
|
42
|
-
var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
|
|
43
|
-
var CSS_RE = /\.(css)$/;
|
|
44
|
-
|
|
45
|
-
// src/plugins/built-in/exports.ts
|
|
46
39
|
function exports(options = {}) {
|
|
47
40
|
return {
|
|
48
41
|
type: "bunup",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
3
|
"description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.49",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -46,16 +46,21 @@
|
|
|
46
46
|
"bunup": "dist/cli/index.js"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
+
"@babel/parser": "^7.27.7",
|
|
49
50
|
"@clack/prompts": "^0.10.1",
|
|
50
|
-
"bun-dts": "^0.1.70",
|
|
51
51
|
"chokidar": "^4.0.3",
|
|
52
52
|
"coffi": "^0.1.31",
|
|
53
53
|
"giget": "^2.0.0",
|
|
54
|
+
"oxc-resolver": "^11.3.0",
|
|
55
|
+
"oxc-transform": "^0.75.0",
|
|
54
56
|
"picocolors": "^1.1.1",
|
|
55
57
|
"replace-in-file": "^8.3.0",
|
|
56
|
-
"
|
|
58
|
+
"std-env": "^3.9.0",
|
|
59
|
+
"tinyexec": "^1.0.1",
|
|
60
|
+
"ts-import-resolver": "^0.1.22"
|
|
57
61
|
},
|
|
58
62
|
"devDependencies": {
|
|
63
|
+
"@babel/types": "^7.27.7",
|
|
59
64
|
"@biomejs/biome": "2.0.0",
|
|
60
65
|
"@types/bun": "^1.2.5",
|
|
61
66
|
"bumpp": "^10.1.0",
|
package/dist/chunk-kpthwads.js
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
filterBunupBunPlugins,
|
|
3
|
-
filterBunupPlugins,
|
|
4
|
-
runPluginBuildDoneHooks,
|
|
5
|
-
runPluginBuildStartHooks
|
|
6
|
-
} from "./chunk-snvybwa2.js";
|
|
7
|
-
import {
|
|
8
|
-
loadPackageJson
|
|
9
|
-
} from "./chunk-gh7z7s46.js";
|
|
10
|
-
import {
|
|
11
|
-
BunupBuildError,
|
|
12
|
-
cleanOutDir,
|
|
13
|
-
cleanPath,
|
|
14
|
-
ensureArray,
|
|
15
|
-
formatFileSize,
|
|
16
|
-
getDefaultDtsExtention,
|
|
17
|
-
getDefaultOutputExtension,
|
|
18
|
-
getFilesFromGlobs,
|
|
19
|
-
getPackageDeps,
|
|
20
|
-
getShortFilePath,
|
|
21
|
-
link,
|
|
22
|
-
logTable,
|
|
23
|
-
logger,
|
|
24
|
-
setSilent
|
|
25
|
-
} from "./chunk-a76fsvj7.js";
|
|
26
|
-
|
|
27
|
-
// src/build.ts
|
|
28
|
-
import path from "path";
|
|
29
|
-
import { generateDts, logIsolatedDeclarationErrors } from "bun-dts";
|
|
30
|
-
import pc2 from "picocolors";
|
|
31
|
-
|
|
32
|
-
// src/plugins/internal/linter.ts
|
|
33
|
-
var rules = [
|
|
34
|
-
{
|
|
35
|
-
check: (ctx) => {
|
|
36
|
-
const hasMinification = !!(ctx.options.minify || ctx.options.minifyWhitespace || ctx.options.minifyIdentifiers || ctx.options.minifySyntax);
|
|
37
|
-
return hasMinification && !ctx.options.sourcemap;
|
|
38
|
-
},
|
|
39
|
-
message: `You are using minification without source maps. Consider enabling source maps to help with debugging minified code. Learn more: ${link("https://bunup.dev/docs/guide/options#source-maps")}`,
|
|
40
|
-
logLevel: "recommended"
|
|
41
|
-
}
|
|
42
|
-
];
|
|
43
|
-
function linter() {
|
|
44
|
-
return {
|
|
45
|
-
type: "bunup",
|
|
46
|
-
name: "linter",
|
|
47
|
-
hooks: {
|
|
48
|
-
onBuildDone: (ctx) => {
|
|
49
|
-
let hasWarnings = false;
|
|
50
|
-
for (const rule of rules) {
|
|
51
|
-
if (rule.check(ctx)) {
|
|
52
|
-
if (!hasWarnings) {
|
|
53
|
-
logger.space();
|
|
54
|
-
}
|
|
55
|
-
logger[rule.logLevel ?? "warn"](rule.message);
|
|
56
|
-
hasWarnings = true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// src/plugins/internal/report.ts
|
|
65
|
-
import pc from "picocolors";
|
|
66
|
-
function report() {
|
|
67
|
-
return {
|
|
68
|
-
type: "bunup",
|
|
69
|
-
name: "report",
|
|
70
|
-
hooks: {
|
|
71
|
-
onBuildDone: async ({ options, output }) => {
|
|
72
|
-
if (options.watch)
|
|
73
|
-
return;
|
|
74
|
-
const files = await Promise.all(output.files.map(async (file) => {
|
|
75
|
-
const name = file.relativePathToRootDir;
|
|
76
|
-
const size = Bun.file(file.fullPath).size;
|
|
77
|
-
const gzipSize = Bun.gzipSync(new Uint8Array(await Bun.file(file.fullPath).arrayBuffer())).length;
|
|
78
|
-
const formattedGzipSize = formatFileSize(gzipSize);
|
|
79
|
-
return {
|
|
80
|
-
name,
|
|
81
|
-
size,
|
|
82
|
-
formattedSize: formatFileSize(size),
|
|
83
|
-
gzipSize,
|
|
84
|
-
formattedGzipSize
|
|
85
|
-
};
|
|
86
|
-
}));
|
|
87
|
-
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
88
|
-
const formattedTotalSize = formatFileSize(totalSize);
|
|
89
|
-
const totalGzipSize = files.reduce((sum, file) => sum + (file.gzipSize || 0), 0);
|
|
90
|
-
const formattedTotalGzipSize = formatFileSize(totalGzipSize);
|
|
91
|
-
const columns = [
|
|
92
|
-
{ header: "File", align: "left", color: pc.blue },
|
|
93
|
-
{ header: "Size", align: "right", color: pc.green },
|
|
94
|
-
{
|
|
95
|
-
header: "Gzip",
|
|
96
|
-
align: "right",
|
|
97
|
-
color: pc.magenta
|
|
98
|
-
}
|
|
99
|
-
];
|
|
100
|
-
const data = files.map((file) => {
|
|
101
|
-
return {
|
|
102
|
-
File: file.name,
|
|
103
|
-
Size: file.formattedSize,
|
|
104
|
-
Gzip: file.formattedGzipSize
|
|
105
|
-
};
|
|
106
|
-
});
|
|
107
|
-
const footer = {
|
|
108
|
-
File: "Total",
|
|
109
|
-
Size: formattedTotalSize,
|
|
110
|
-
Gzip: formattedTotalGzipSize
|
|
111
|
-
};
|
|
112
|
-
logger.space();
|
|
113
|
-
logTable(columns, data, footer);
|
|
114
|
-
logger.space();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// src/plugins/internal/use-client.ts
|
|
121
|
-
function useClient() {
|
|
122
|
-
return {
|
|
123
|
-
type: "bunup",
|
|
124
|
-
name: "use-client",
|
|
125
|
-
hooks: {
|
|
126
|
-
onBuildDone: async ({ output }) => {
|
|
127
|
-
for (const file of output.files) {
|
|
128
|
-
let text = await Bun.file(file.fullPath).text();
|
|
129
|
-
const hasUseClient = text.split(`
|
|
130
|
-
`).some((line) => line.trim().startsWith(`"use client";`));
|
|
131
|
-
if (hasUseClient) {
|
|
132
|
-
text = text.replaceAll(`"use client";`, "");
|
|
133
|
-
text = `"use client";
|
|
134
|
-
${text}`;
|
|
135
|
-
}
|
|
136
|
-
await Bun.write(file.fullPath, text);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// src/options.ts
|
|
144
|
-
var DEFAULT_OPTIONS = {
|
|
145
|
-
entry: ["src/index.ts"],
|
|
146
|
-
format: ["cjs"],
|
|
147
|
-
outDir: "dist",
|
|
148
|
-
target: "node",
|
|
149
|
-
clean: true
|
|
150
|
-
};
|
|
151
|
-
function createBuildOptions(partialOptions) {
|
|
152
|
-
const options = {
|
|
153
|
-
...DEFAULT_OPTIONS,
|
|
154
|
-
...partialOptions
|
|
155
|
-
};
|
|
156
|
-
return {
|
|
157
|
-
...options,
|
|
158
|
-
plugins: [...options.plugins ?? [], useClient(), linter(), report()]
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function getResolvedMinify(options) {
|
|
162
|
-
const { minify, minifyWhitespace, minifyIdentifiers, minifySyntax } = options;
|
|
163
|
-
const defaultValue = minify === true;
|
|
164
|
-
return {
|
|
165
|
-
whitespace: minifyWhitespace ?? defaultValue,
|
|
166
|
-
identifiers: minifyIdentifiers ?? defaultValue,
|
|
167
|
-
syntax: minifySyntax ?? defaultValue
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
function getResolvedBytecode(bytecode, format) {
|
|
171
|
-
return format === "cjs" ? bytecode : undefined;
|
|
172
|
-
}
|
|
173
|
-
function getResolvedSourcemap(sourcemap) {
|
|
174
|
-
if (sourcemap === true) {
|
|
175
|
-
return "inline";
|
|
176
|
-
}
|
|
177
|
-
return typeof sourcemap === "string" ? sourcemap : undefined;
|
|
178
|
-
}
|
|
179
|
-
function getResolvedDefine(define, env) {
|
|
180
|
-
return {
|
|
181
|
-
...typeof env === "object" && Object.keys(env).reduce((acc, key) => {
|
|
182
|
-
const value = JSON.stringify(env[key]);
|
|
183
|
-
acc[`process.env.${key}`] = value;
|
|
184
|
-
acc[`import.meta.env.${key}`] = value;
|
|
185
|
-
return acc;
|
|
186
|
-
}, {}),
|
|
187
|
-
...define
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
function getResolvedSplitting(splitting, format) {
|
|
191
|
-
return splitting === undefined ? format === "esm" : splitting;
|
|
192
|
-
}
|
|
193
|
-
function getResolvedDtsSplitting(splitting) {
|
|
194
|
-
return splitting ?? true;
|
|
195
|
-
}
|
|
196
|
-
var DEFAULT_ENTRY_NAMING = "[dir]/[name].[ext]";
|
|
197
|
-
function getResolvedNaming(fmt, packageType) {
|
|
198
|
-
const replaceExt = (pattern) => pattern.replace(".[ext]", getDefaultOutputExtension(fmt, packageType));
|
|
199
|
-
return replaceExt(DEFAULT_ENTRY_NAMING);
|
|
200
|
-
}
|
|
201
|
-
function getResolvedEnv(env) {
|
|
202
|
-
return typeof env === "string" ? env : undefined;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// src/helpers/external.ts
|
|
206
|
-
function getPackageDepsPatterns(packageJson) {
|
|
207
|
-
return getPackageDeps(packageJson).map((dep) => new RegExp(`^${dep}($|\\/|\\\\)`));
|
|
208
|
-
}
|
|
209
|
-
function matchesPattern(path, pattern) {
|
|
210
|
-
return typeof pattern === "string" ? pattern === path : pattern.test(path);
|
|
211
|
-
}
|
|
212
|
-
function isExternal(path, options, packageJson) {
|
|
213
|
-
const packageDepsPatterns = getPackageDepsPatterns(packageJson);
|
|
214
|
-
const matchesExternalPattern = packageDepsPatterns.some((pattern) => pattern.test(path)) || options.external?.some((pattern) => matchesPattern(path, pattern));
|
|
215
|
-
const isExcludedFromExternal = options.noExternal?.some((pattern) => matchesPattern(path, pattern));
|
|
216
|
-
return matchesExternalPattern && !isExcludedFromExternal;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/plugins/internal/external-option.ts
|
|
220
|
-
function externalOptionPlugin(options, packageJson) {
|
|
221
|
-
return {
|
|
222
|
-
name: "bunup:external-option-plugin",
|
|
223
|
-
setup(build) {
|
|
224
|
-
build.onResolve({ filter: /.*/ }, (args) => {
|
|
225
|
-
const importPath = args.path;
|
|
226
|
-
if (isExternal(importPath, options, packageJson)) {
|
|
227
|
-
return {
|
|
228
|
-
path: importPath,
|
|
229
|
-
external: true
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
return null;
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// src/build.ts
|
|
239
|
-
async function build(partialOptions, rootDir = process.cwd()) {
|
|
240
|
-
const buildOutput = {
|
|
241
|
-
files: []
|
|
242
|
-
};
|
|
243
|
-
const options = createBuildOptions(partialOptions);
|
|
244
|
-
if (!options.entry || options.entry.length === 0 || !options.outDir) {
|
|
245
|
-
throw new BunupBuildError("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");
|
|
246
|
-
}
|
|
247
|
-
if (options.clean) {
|
|
248
|
-
cleanOutDir(rootDir, options.outDir);
|
|
249
|
-
}
|
|
250
|
-
setSilent(options.silent);
|
|
251
|
-
const packageJson = await loadPackageJson(rootDir);
|
|
252
|
-
if (packageJson.data && packageJson.path) {
|
|
253
|
-
logger.info(`Using ${getShortFilePath(packageJson.path, 2)}`, {
|
|
254
|
-
muted: true,
|
|
255
|
-
identifier: options.name,
|
|
256
|
-
once: `${packageJson.path}:${options.name}`
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
const bunupPlugins = filterBunupPlugins(options.plugins);
|
|
260
|
-
await runPluginBuildStartHooks(bunupPlugins, options);
|
|
261
|
-
const packageType = packageJson.data?.type;
|
|
262
|
-
const plugins = [
|
|
263
|
-
externalOptionPlugin(options, packageJson.data),
|
|
264
|
-
...filterBunupBunPlugins(options.plugins).map((p) => p.plugin)
|
|
265
|
-
];
|
|
266
|
-
const entrypoints = await getFilesFromGlobs(ensureArray(options.entry), rootDir);
|
|
267
|
-
if (!entrypoints.length) {
|
|
268
|
-
throw new BunupBuildError("The entrypoints you provided do not exist. Please make sure the entrypoints point to valid files.");
|
|
269
|
-
}
|
|
270
|
-
const buildPromises = options.format.flatMap(async (fmt) => {
|
|
271
|
-
const result = await Bun.build({
|
|
272
|
-
entrypoints: entrypoints.map((file) => `${rootDir}/${file}`),
|
|
273
|
-
format: fmt,
|
|
274
|
-
naming: getResolvedNaming(fmt, packageType),
|
|
275
|
-
splitting: getResolvedSplitting(options.splitting, fmt),
|
|
276
|
-
bytecode: getResolvedBytecode(options.bytecode, fmt),
|
|
277
|
-
define: getResolvedDefine(options.define, options.env),
|
|
278
|
-
minify: getResolvedMinify(options),
|
|
279
|
-
outdir: `${rootDir}/${options.outDir}`,
|
|
280
|
-
target: options.target,
|
|
281
|
-
sourcemap: getResolvedSourcemap(options.sourcemap),
|
|
282
|
-
loader: options.loader,
|
|
283
|
-
drop: options.drop,
|
|
284
|
-
banner: options.banner,
|
|
285
|
-
footer: options.footer,
|
|
286
|
-
publicPath: options.publicPath,
|
|
287
|
-
env: getResolvedEnv(options.env),
|
|
288
|
-
ignoreDCEAnnotations: options.ignoreDCEAnnotations,
|
|
289
|
-
emitDCEAnnotations: options.emitDCEAnnotations,
|
|
290
|
-
throw: false,
|
|
291
|
-
plugins
|
|
292
|
-
});
|
|
293
|
-
for (const log of result.logs) {
|
|
294
|
-
if (log.level === "error") {
|
|
295
|
-
throw new BunupBuildError(log.message);
|
|
296
|
-
}
|
|
297
|
-
if (log.level === "warning")
|
|
298
|
-
logger.warn(log.message);
|
|
299
|
-
else if (log.level === "info")
|
|
300
|
-
logger.info(log.message);
|
|
301
|
-
}
|
|
302
|
-
let entrypointIndex = 0;
|
|
303
|
-
for (const file of result.outputs) {
|
|
304
|
-
const relativePathToRootDir = getRelativePathToRootDir(file.path, rootDir);
|
|
305
|
-
const relativePathToOutputDir = getRelativePathToOutputDir(relativePathToRootDir, options.outDir);
|
|
306
|
-
if (file.kind === "entry-point") {
|
|
307
|
-
logger.success(`${pc2.dim(`${options.outDir}/`)}${relativePathToOutputDir}`, {
|
|
308
|
-
identifier: options.name
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
buildOutput.files.push({
|
|
312
|
-
fullPath: file.path,
|
|
313
|
-
relativePathToRootDir,
|
|
314
|
-
relativePathToOutputDir,
|
|
315
|
-
dts: false,
|
|
316
|
-
format: fmt,
|
|
317
|
-
kind: file.kind,
|
|
318
|
-
entrypoint: file.kind === "entry-point" ? cleanPath(entrypoints[entrypointIndex]) : undefined
|
|
319
|
-
});
|
|
320
|
-
if (file.kind === "entry-point") {
|
|
321
|
-
entrypointIndex++;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
await Promise.all(buildPromises);
|
|
326
|
-
if (options.dts) {
|
|
327
|
-
const { entry, splitting, ...dtsOptions } = typeof options.dts === "object" ? options.dts : {};
|
|
328
|
-
const dtsResult = await generateDts(ensureArray(entry ?? entrypoints), {
|
|
329
|
-
cwd: rootDir,
|
|
330
|
-
preferredTsConfigPath: options.preferredTsconfigPath,
|
|
331
|
-
splitting: getResolvedDtsSplitting(splitting),
|
|
332
|
-
...dtsOptions
|
|
333
|
-
});
|
|
334
|
-
if (dtsResult.errors.length) {
|
|
335
|
-
logIsolatedDeclarationErrors(dtsResult.errors, {
|
|
336
|
-
shouldExit: true
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
for (const fmt of options.format) {
|
|
340
|
-
for (const file of dtsResult.files) {
|
|
341
|
-
const dtsExtension = getDefaultDtsExtention(fmt, packageType);
|
|
342
|
-
const relativePathToOutputDir = cleanPath(`${file.pathInfo.outputPathWithoutExtension}${dtsExtension}`);
|
|
343
|
-
const relativePathToRootDir = cleanPath(`${options.outDir}/${relativePathToOutputDir}`);
|
|
344
|
-
if (file.kind === "entry-point") {
|
|
345
|
-
logger.success(`${pc2.dim(`${options.outDir}/`)}${relativePathToOutputDir}`, {
|
|
346
|
-
identifier: options.name
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
const fullPath = path.join(rootDir, relativePathToRootDir);
|
|
350
|
-
await Bun.write(fullPath, file.dts);
|
|
351
|
-
buildOutput.files.push({
|
|
352
|
-
fullPath,
|
|
353
|
-
relativePathToRootDir,
|
|
354
|
-
relativePathToOutputDir,
|
|
355
|
-
dts: true,
|
|
356
|
-
format: fmt,
|
|
357
|
-
kind: file.kind,
|
|
358
|
-
entrypoint: file.entrypoint ? cleanPath(file.entrypoint) : undefined
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
await runPluginBuildDoneHooks(bunupPlugins, options, buildOutput, {
|
|
364
|
-
packageJson,
|
|
365
|
-
rootDir
|
|
366
|
-
});
|
|
367
|
-
if (options.onSuccess) {
|
|
368
|
-
await options.onSuccess(options);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
function getRelativePathToRootDir(filePath, rootDir) {
|
|
372
|
-
return cleanPath(filePath).replace(`${cleanPath(rootDir)}/`, "");
|
|
373
|
-
}
|
|
374
|
-
function getRelativePathToOutputDir(relativePathToRootDir, outDir) {
|
|
375
|
-
return cleanPath(relativePathToRootDir).replace(`${cleanPath(outDir)}/`, "");
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
export { createBuildOptions, build };
|