bunup 0.8.35 → 0.8.36
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-vfvfb7pv.js → chunk-4y0hvzcd.js} +17 -14
- package/dist/{chunk-8sqm3fje.d.ts → chunk-589998ak.d.ts} +10 -44
- package/dist/{chunk-gdnf8ebe.js → chunk-ct0a7gyb.js} +2 -2
- package/dist/{chunk-h9jzw5qq.js → chunk-g3b9h2ys.js} +9 -9
- package/dist/{chunk-8z361mhm.js → chunk-ka4kbkdd.js} +64 -109
- package/dist/{chunk-by2b1r3m.js → chunk-vh9fpy39.js} +49 -59
- package/dist/{chunk-0r7kktgh.js → chunk-w13gdbvp.js} +15 -6
- package/dist/cli/index.js +345 -166
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +2 -2
- package/package.json +102 -92
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
displayBunupGradientArt
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ct0a7gyb.js";
|
|
5
5
|
import {
|
|
6
6
|
pathExistsSync
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-ka4kbkdd.js";
|
|
8
8
|
|
|
9
9
|
// src/cli/new.ts
|
|
10
10
|
import { renameSync } from "fs";
|
|
@@ -29,12 +29,14 @@ var MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER = "package-1";
|
|
|
29
29
|
var MONOREPO_PACKAGES_DIR = "packages";
|
|
30
30
|
var TEMPLATES = [
|
|
31
31
|
{
|
|
32
|
+
type: "typescript",
|
|
32
33
|
defaultName: "my-ts-lib",
|
|
33
34
|
name: "Typescript Library",
|
|
34
35
|
dir: "ts-lib",
|
|
35
36
|
monorepoDir: "ts-lib-monorepo"
|
|
36
37
|
},
|
|
37
38
|
{
|
|
39
|
+
type: "react",
|
|
38
40
|
defaultName: "my-react-lib",
|
|
39
41
|
name: "React Library",
|
|
40
42
|
dir: "react-lib"
|
|
@@ -96,7 +98,7 @@ async function newProject() {
|
|
|
96
98
|
const [githubUsername, githubRepoName] = githubRepoInfo.split("/");
|
|
97
99
|
await tasks([
|
|
98
100
|
{
|
|
99
|
-
title: "
|
|
101
|
+
title: "Downloading template",
|
|
100
102
|
task: async () => {
|
|
101
103
|
const templatePath = useMonorepo ? template.monorepoDir : template.dir;
|
|
102
104
|
await downloadTemplate(`github:${TEMPLATE_OWNER}/${TEMPLATE_REPO}/${templatePath}`, {
|
|
@@ -131,17 +133,18 @@ async function newProject() {
|
|
|
131
133
|
}
|
|
132
134
|
]);
|
|
133
135
|
outro(`
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
136
|
+
${pc.green("\u2728 Project scaffolded successfully! \u2728")}
|
|
137
|
+
|
|
138
|
+
${pc.bold("Ready to launch your awesome new project?")}
|
|
139
|
+
|
|
140
|
+
${pc.cyan("cd")} ${projectName}
|
|
141
|
+
${pc.cyan("bun install")}
|
|
142
|
+
${pc.cyan("bun run dev")}${pc.dim(" (watch mode for development)")}${template.type === "react" ? `
|
|
143
|
+
${pc.cyan("bun run dev:test")} ${pc.dim("(preview components in a test Next.js app)")} ` : ""}
|
|
144
|
+
|
|
145
|
+
${pc.dim("Learn more:")} ${pc.underline("https://bunup.dev/docs")}
|
|
146
|
+
|
|
147
|
+
${pc.yellow("Happy coding!")} \uD83D\uDE80
|
|
145
148
|
`);
|
|
146
149
|
}
|
|
147
150
|
function getProjectPath(projectName) {
|
|
@@ -1,43 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
type
|
|
1
|
+
import { BunPlugin } from "bun";
|
|
2
|
+
import { BuildConfig } from "bun";
|
|
3
|
+
import { DtsPluginOptions } from "bun-dts";
|
|
4
|
+
type Loader = NonNullable<BuildConfig["loader"]>[string];
|
|
5
|
+
type Define = BuildConfig["define"];
|
|
6
|
+
type Sourcemap = BuildConfig["sourcemap"];
|
|
7
|
+
type Format = Exclude<BuildConfig["format"], undefined>;
|
|
8
|
+
type Target = BuildConfig["target"];
|
|
7
9
|
type External = (string | RegExp)[];
|
|
8
|
-
type Env =
|
|
9
|
-
type DtsResolve = boolean | (string | RegExp)[];
|
|
10
|
-
type Naming = string | {
|
|
11
|
-
entry?: string
|
|
12
|
-
chunk?: string
|
|
13
|
-
asset?: string
|
|
14
|
-
};
|
|
15
|
-
type DtsOptions = {
|
|
16
|
-
/**
|
|
17
|
-
* Entry point files for TypeScript declaration file generation
|
|
18
|
-
*
|
|
19
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
20
|
-
*
|
|
21
|
-
* @see https://bunup.dev/docs/guide/typescript-declarations#custom-entry-points
|
|
22
|
-
* @see https://bunup.dev/docs/guide/typescript-declarations#named-entries
|
|
23
|
-
*/
|
|
24
|
-
entry?: string | string[]
|
|
25
|
-
/**
|
|
26
|
-
* Resolve external types used in dts files from node_modules
|
|
27
|
-
*/
|
|
28
|
-
resolve?: DtsResolve
|
|
29
|
-
/**
|
|
30
|
-
* Whether to split declaration files when multiple entrypoints import the same files,
|
|
31
|
-
* modules, or share types. When enabled, shared types will be extracted to separate
|
|
32
|
-
* .d.ts files, and other declaration files will import these shared files.
|
|
33
|
-
*
|
|
34
|
-
* This helps reduce bundle size by preventing duplication of type definitions
|
|
35
|
-
* across multiple entrypoints.
|
|
36
|
-
*
|
|
37
|
-
* This option is enabled by default if splitting is enabled in the Bun build config or format is esm.
|
|
38
|
-
*/
|
|
39
|
-
splitting?: boolean
|
|
40
|
-
};
|
|
10
|
+
type Env = BuildConfig["env"] | Record<string, string>;
|
|
41
11
|
interface BuildOptions {
|
|
42
12
|
/**
|
|
43
13
|
* Name of the build configuration
|
|
@@ -75,7 +45,6 @@ interface BuildOptions {
|
|
|
75
45
|
* Defaults to true for ESM format, false for CJS format
|
|
76
46
|
*/
|
|
77
47
|
splitting?: boolean;
|
|
78
|
-
naming?: Naming;
|
|
79
48
|
/**
|
|
80
49
|
* Whether to minify whitespace in the output
|
|
81
50
|
* Removes unnecessary whitespace to reduce file size
|
|
@@ -100,7 +69,7 @@ interface BuildOptions {
|
|
|
100
69
|
* When set to true, generates declaration files for all entry points
|
|
101
70
|
* Can also be configured with DtsOptions for more control
|
|
102
71
|
*/
|
|
103
|
-
dts?: boolean |
|
|
72
|
+
dts?: boolean | Pick<DtsPluginOptions, "entry" | "resolve" | "splitting" | "minify">;
|
|
104
73
|
/**
|
|
105
74
|
* Path to a preferred tsconfig.json file to use for declaration generation
|
|
106
75
|
*
|
|
@@ -259,9 +228,6 @@ type WithOptional<
|
|
|
259
228
|
K extends keyof T
|
|
260
229
|
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
261
230
|
type Arrayable<T> = T | T[];
|
|
262
|
-
type Bun = typeof _Bun;
|
|
263
|
-
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
264
|
-
type BunPlugin = Exclude<BunBuildOptions["plugins"], undefined>[number];
|
|
265
231
|
type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
|
|
266
232
|
type DefineWorkspaceItem = {
|
|
267
233
|
name: string
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
logger
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ka4kbkdd.js";
|
|
4
4
|
|
|
5
5
|
// src/cli/utils.ts
|
|
6
6
|
import pc from "picocolors";
|
|
@@ -17,7 +17,7 @@ function displayBunupGradientArt() {
|
|
|
17
17
|
`);
|
|
18
18
|
logger.space();
|
|
19
19
|
for (const line of lines) {
|
|
20
|
-
|
|
20
|
+
console.log(pc.cyan(line));
|
|
21
21
|
}
|
|
22
22
|
logger.space();
|
|
23
23
|
}
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
} from "./chunk-gh7z7s46.js";
|
|
5
5
|
import {
|
|
6
6
|
displayBunupGradientArt
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-ct0a7gyb.js";
|
|
8
8
|
import {
|
|
9
9
|
formatListWithAnd
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ka4kbkdd.js";
|
|
11
11
|
|
|
12
12
|
// src/cli/init.ts
|
|
13
13
|
import fs from "fs";
|
|
@@ -334,15 +334,15 @@ function showSuccessOutro(isWorkspace) {
|
|
|
334
334
|
const devCommand = isWorkspace ? `${pc.cyan("bun run dev")} - Start development mode (watches all packages)` : `${pc.cyan("bun run dev")} - Start development mode`;
|
|
335
335
|
const filterCommand = isWorkspace ? `${pc.cyan("bunup --filter core,utils")} - Build specific packages` : "";
|
|
336
336
|
outro(`
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
337
|
+
${pc.green("\u2728 Bunup initialized successfully! \u2728")}
|
|
338
|
+
|
|
339
|
+
${buildCommand}
|
|
340
|
+
${devCommand}${isWorkspace ? `
|
|
341
|
+
${filterCommand}` : ""}
|
|
342
342
|
|
|
343
|
-
|
|
343
|
+
${pc.dim("Learn more:")} ${pc.underline("https://bunup.dev/docs")}
|
|
344
344
|
|
|
345
|
-
|
|
345
|
+
${pc.yellow("Happy building!")} \uD83D\uDE80
|
|
346
346
|
`);
|
|
347
347
|
}
|
|
348
348
|
async function installBunup() {
|
|
@@ -26,31 +26,6 @@ function setSilent(value) {
|
|
|
26
26
|
class Logger {
|
|
27
27
|
static instance;
|
|
28
28
|
loggedOnceMessages = new Set;
|
|
29
|
-
MAX_LABEL_LENGTH = 3;
|
|
30
|
-
cliColor = pc.blue;
|
|
31
|
-
mutedColor = pc.dim;
|
|
32
|
-
infoColor = pc.cyan;
|
|
33
|
-
warnColor = pc.yellow;
|
|
34
|
-
errorColor = pc.red;
|
|
35
|
-
defaultColor = pc.white;
|
|
36
|
-
progressFgColorMap = {
|
|
37
|
-
ESM: pc.yellow,
|
|
38
|
-
CJS: pc.green,
|
|
39
|
-
IIFE: pc.magenta,
|
|
40
|
-
DTS: pc.blue
|
|
41
|
-
};
|
|
42
|
-
progressIdentifierBgColorMap = {
|
|
43
|
-
ESM: pc.bgYellow,
|
|
44
|
-
CJS: pc.bgGreen,
|
|
45
|
-
IIFE: pc.bgMagenta,
|
|
46
|
-
DTS: pc.bgBlue
|
|
47
|
-
};
|
|
48
|
-
labels = {
|
|
49
|
-
cli: "CLI",
|
|
50
|
-
info: "INFO",
|
|
51
|
-
warn: "WARN",
|
|
52
|
-
error: "ERROR"
|
|
53
|
-
};
|
|
54
29
|
constructor() {}
|
|
55
30
|
static getInstance() {
|
|
56
31
|
if (!Logger.instance) {
|
|
@@ -62,111 +37,91 @@ class Logger {
|
|
|
62
37
|
this.loggedOnceMessages.clear();
|
|
63
38
|
}
|
|
64
39
|
shouldLog(options) {
|
|
65
|
-
if (!options?.once)
|
|
40
|
+
if (!options?.once) {
|
|
66
41
|
return true;
|
|
67
|
-
|
|
42
|
+
}
|
|
43
|
+
if (this.loggedOnceMessages.has(options.once)) {
|
|
68
44
|
return false;
|
|
45
|
+
}
|
|
69
46
|
this.loggedOnceMessages.add(options.once);
|
|
70
47
|
return true;
|
|
71
48
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
49
|
+
getIcon(type, tick) {
|
|
50
|
+
if (tick) {
|
|
51
|
+
return pc.green("\u2713");
|
|
52
|
+
}
|
|
53
|
+
const iconMap = {
|
|
54
|
+
info: pc.blue("i"),
|
|
55
|
+
warn: pc.yellow("!"),
|
|
56
|
+
error: pc.red("\u2715")
|
|
57
|
+
};
|
|
58
|
+
return iconMap[type];
|
|
59
|
+
}
|
|
60
|
+
formatIdentifier(identifier) {
|
|
61
|
+
return identifier ? ` ${pc.bgBlue(pc.black(` ${identifier} `))}` : "";
|
|
62
|
+
}
|
|
63
|
+
formatMessage(options) {
|
|
64
|
+
const {
|
|
65
|
+
message,
|
|
66
|
+
identifier,
|
|
67
|
+
muted = false,
|
|
68
|
+
tick = false,
|
|
69
|
+
type = "info"
|
|
70
|
+
} = options;
|
|
71
|
+
const icon = this.getIcon(type, tick);
|
|
72
|
+
const styledMessage = muted ? pc.dim(message) : message;
|
|
73
|
+
const identifierPart = this.formatIdentifier(identifier);
|
|
74
|
+
return `${icon} ${styledMessage}${identifierPart}`;
|
|
84
75
|
}
|
|
85
76
|
output(message, options = {}, logFn = console.log) {
|
|
86
|
-
if (silent || !this.shouldLog(options))
|
|
77
|
+
if (silent || !this.shouldLog(options)) {
|
|
87
78
|
return;
|
|
88
|
-
|
|
79
|
+
}
|
|
80
|
+
if (options.verticalSpace) {
|
|
89
81
|
logFn("");
|
|
82
|
+
}
|
|
90
83
|
logFn(message);
|
|
91
|
-
if (options.verticalSpace)
|
|
84
|
+
if (options.verticalSpace) {
|
|
92
85
|
logFn("");
|
|
93
|
-
|
|
94
|
-
cli(message, options = {}) {
|
|
95
|
-
const formattedMessage = this.formatMessage({
|
|
96
|
-
fgColor: this.cliColor,
|
|
97
|
-
bgColor: pc.bgBlue,
|
|
98
|
-
label: this.labels.cli,
|
|
99
|
-
message,
|
|
100
|
-
identifier: options.identifier,
|
|
101
|
-
muted: options.muted
|
|
102
|
-
});
|
|
103
|
-
this.output(formattedMessage, options);
|
|
86
|
+
}
|
|
104
87
|
}
|
|
105
88
|
info(message, options = {}) {
|
|
106
89
|
const formattedMessage = this.formatMessage({
|
|
107
|
-
|
|
108
|
-
bgColor: pc.bgCyan,
|
|
109
|
-
label: this.labels.info,
|
|
90
|
+
...options,
|
|
110
91
|
message,
|
|
111
|
-
|
|
112
|
-
muted: options.muted
|
|
92
|
+
type: "info"
|
|
113
93
|
});
|
|
114
94
|
this.output(formattedMessage, options);
|
|
115
95
|
}
|
|
116
96
|
warn(message, options = {}) {
|
|
117
97
|
const formattedMessage = this.formatMessage({
|
|
118
|
-
|
|
119
|
-
bgColor: pc.bgYellow,
|
|
120
|
-
label: this.labels.warn,
|
|
98
|
+
...options,
|
|
121
99
|
message,
|
|
122
|
-
|
|
123
|
-
muted: options.muted
|
|
100
|
+
type: "warn"
|
|
124
101
|
});
|
|
125
|
-
this.output(formattedMessage, options
|
|
102
|
+
this.output(formattedMessage, options);
|
|
126
103
|
}
|
|
127
104
|
error(message, options = {}) {
|
|
128
105
|
const formattedMessage = this.formatMessage({
|
|
129
|
-
|
|
130
|
-
bgColor: pc.bgRed,
|
|
131
|
-
label: this.labels.error,
|
|
106
|
+
...options,
|
|
132
107
|
message,
|
|
133
|
-
|
|
134
|
-
muted: options.muted
|
|
108
|
+
type: "error"
|
|
135
109
|
});
|
|
136
|
-
this.output(formattedMessage, options
|
|
137
|
-
}
|
|
138
|
-
space() {
|
|
139
|
-
if (silent)
|
|
140
|
-
return;
|
|
141
|
-
console.log("");
|
|
142
|
-
}
|
|
143
|
-
getProgressFgColor(label) {
|
|
144
|
-
for (const [key, colorFn] of Object.entries(this.progressFgColorMap)) {
|
|
145
|
-
if (label.includes(key))
|
|
146
|
-
return colorFn;
|
|
147
|
-
}
|
|
148
|
-
return this.defaultColor;
|
|
149
|
-
}
|
|
150
|
-
getProgressBgColor(label) {
|
|
151
|
-
for (const [key, colorFn] of Object.entries(this.progressIdentifierBgColorMap)) {
|
|
152
|
-
if (label.includes(key))
|
|
153
|
-
return colorFn;
|
|
154
|
-
}
|
|
155
|
-
return pc.bgWhite;
|
|
110
|
+
this.output(formattedMessage, options);
|
|
156
111
|
}
|
|
157
|
-
|
|
158
|
-
const fgColor = this.getProgressFgColor(label);
|
|
159
|
-
const bgColor = this.getProgressBgColor(label);
|
|
112
|
+
success(message, options = {}) {
|
|
160
113
|
const formattedMessage = this.formatMessage({
|
|
161
|
-
|
|
162
|
-
bgColor,
|
|
163
|
-
label,
|
|
114
|
+
...options,
|
|
164
115
|
message,
|
|
165
|
-
|
|
166
|
-
muted: options.muted
|
|
116
|
+
tick: true
|
|
167
117
|
});
|
|
168
118
|
this.output(formattedMessage, options);
|
|
169
119
|
}
|
|
120
|
+
space() {
|
|
121
|
+
if (!silent) {
|
|
122
|
+
console.log("");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
170
125
|
}
|
|
171
126
|
function logTable(columns, data, footer) {
|
|
172
127
|
if (silent)
|
|
@@ -259,7 +214,7 @@ var KNOWN_ERRORS = [
|
|
|
259
214
|
pattern: /Could not resolve: "bun"/i,
|
|
260
215
|
errorType: "BUILD ERROR",
|
|
261
216
|
logSolution: () => {
|
|
262
|
-
logger.
|
|
217
|
+
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(`.
|
|
263
218
|
`) + pc2.white("Example: ") + pc2.green("`bunup --target bun`") + pc2.white(" or in config: ") + pc2.green("{ target: 'bun' }"));
|
|
264
219
|
}
|
|
265
220
|
}
|
|
@@ -307,7 +262,7 @@ import path, { normalize } from "path";
|
|
|
307
262
|
function ensureArray(value) {
|
|
308
263
|
return Array.isArray(value) ? value : [value];
|
|
309
264
|
}
|
|
310
|
-
function
|
|
265
|
+
function getDefaultOutputExtension(format, packageType) {
|
|
311
266
|
switch (format) {
|
|
312
267
|
case "esm":
|
|
313
268
|
return isModulePackage(packageType) ? ".js" : ".mjs";
|
|
@@ -317,15 +272,15 @@ function getDefaultJsOutputExtension(format, packageType) {
|
|
|
317
272
|
return ".global.js";
|
|
318
273
|
}
|
|
319
274
|
}
|
|
320
|
-
function
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
275
|
+
function getDefaultDtsExtention(format, packageType) {
|
|
276
|
+
switch (format) {
|
|
277
|
+
case "esm":
|
|
278
|
+
return isModulePackage(packageType) ? ".d.ts" : ".d.mts";
|
|
279
|
+
case "cjs":
|
|
280
|
+
return isModulePackage(packageType) ? ".d.cts" : ".d.ts";
|
|
281
|
+
case "iife":
|
|
282
|
+
return ".global.d.ts";
|
|
283
|
+
}
|
|
329
284
|
}
|
|
330
285
|
function isModulePackage(packageType) {
|
|
331
286
|
return packageType === "module";
|
|
@@ -409,4 +364,4 @@ async function getFilesFromGlobs(patterns, cwd) {
|
|
|
409
364
|
return Array.from(includedFiles);
|
|
410
365
|
}
|
|
411
366
|
|
|
412
|
-
export { __toESM, __require, setSilent, logTable, logger, BunupBuildError,
|
|
367
|
+
export { __toESM, __require, setSilent, logTable, logger, BunupBuildError, BunupCLIError, BunupWatchError, BunupPluginError, parseErrorMessage, handleError, handleErrorAndExit, ensureArray, getDefaultOutputExtension, getDefaultDtsExtention, formatTime, getPackageDeps, formatFileSize, getShortFilePath, cleanOutDir, cleanPath, isDirectoryPath, pathExistsSync, formatListWithAnd, getFilesFromGlobs };
|
|
@@ -4,27 +4,28 @@ import {
|
|
|
4
4
|
report,
|
|
5
5
|
runPluginBuildDoneHooks,
|
|
6
6
|
runPluginBuildStartHooks
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-w13gdbvp.js";
|
|
8
8
|
import {
|
|
9
9
|
loadPackageJson
|
|
10
10
|
} from "./chunk-gh7z7s46.js";
|
|
11
11
|
import {
|
|
12
12
|
BunupBuildError,
|
|
13
|
-
BunupDTSBuildError,
|
|
14
13
|
cleanOutDir,
|
|
15
14
|
cleanPath,
|
|
16
15
|
ensureArray,
|
|
17
|
-
|
|
16
|
+
getDefaultDtsExtention,
|
|
17
|
+
getDefaultOutputExtension,
|
|
18
18
|
getFilesFromGlobs,
|
|
19
19
|
getPackageDeps,
|
|
20
20
|
getShortFilePath,
|
|
21
21
|
logger,
|
|
22
22
|
setSilent
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-ka4kbkdd.js";
|
|
24
24
|
|
|
25
25
|
// src/build.ts
|
|
26
26
|
import path from "path";
|
|
27
|
-
import {
|
|
27
|
+
import { generateDts, logIsolatedDeclarationErrors } from "bun-dts";
|
|
28
|
+
import pc from "picocolors";
|
|
28
29
|
|
|
29
30
|
// src/plugins/internal/use-client.ts
|
|
30
31
|
function useClient() {
|
|
@@ -104,16 +105,9 @@ function getResolvedSplitting(splitting, format) {
|
|
|
104
105
|
return splitting === undefined ? format === "esm" : splitting;
|
|
105
106
|
}
|
|
106
107
|
var DEFAULT_ENTRY_NAMING = "[dir]/[name].[ext]";
|
|
107
|
-
function getResolvedNaming(
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
if (typeof resolvedNaming === "string") {
|
|
111
|
-
return replaceExt(resolvedNaming);
|
|
112
|
-
}
|
|
113
|
-
return {
|
|
114
|
-
...resolvedNaming,
|
|
115
|
-
entry: replaceExt(resolvedNaming.entry)
|
|
116
|
-
};
|
|
108
|
+
function getResolvedNaming(fmt, packageType) {
|
|
109
|
+
const replaceExt = (pattern) => pattern.replace(".[ext]", getDefaultOutputExtension(fmt, packageType));
|
|
110
|
+
return replaceExt(DEFAULT_ENTRY_NAMING);
|
|
117
111
|
}
|
|
118
112
|
function getResolvedEnv(env) {
|
|
119
113
|
return typeof env === "string" ? env : undefined;
|
|
@@ -167,7 +161,7 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
167
161
|
setSilent(options.silent);
|
|
168
162
|
const packageJson = await loadPackageJson(rootDir);
|
|
169
163
|
if (packageJson.data && packageJson.path) {
|
|
170
|
-
logger.
|
|
164
|
+
logger.info(`Using ${getShortFilePath(packageJson.path, 2)}`, {
|
|
171
165
|
muted: true,
|
|
172
166
|
identifier: options.name,
|
|
173
167
|
once: `${packageJson.path}:${options.name}`
|
|
@@ -180,43 +174,6 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
180
174
|
externalOptionPlugin(options, packageJson.data),
|
|
181
175
|
...filterBunupBunPlugins(options.plugins).map((p) => p.plugin)
|
|
182
176
|
];
|
|
183
|
-
let hasBuiltAnyFormat = false;
|
|
184
|
-
if (options.dts) {
|
|
185
|
-
const { resolve, entry, splitting } = typeof options.dts === "object" ? options.dts : {};
|
|
186
|
-
let entrypoints2;
|
|
187
|
-
if (entry) {
|
|
188
|
-
entrypoints2 = await getFilesFromGlobs(ensureArray(entry), rootDir);
|
|
189
|
-
}
|
|
190
|
-
if (Array.isArray(entrypoints2) && !entrypoints2.length) {
|
|
191
|
-
throw new BunupDTSBuildError("The dts entrypoints you provided do not exist. Please make sure the entrypoints point to valid files.");
|
|
192
|
-
}
|
|
193
|
-
plugins.push(dts({
|
|
194
|
-
resolve,
|
|
195
|
-
preferredTsConfigPath: options.preferredTsconfigPath,
|
|
196
|
-
entry: entrypoints2,
|
|
197
|
-
cwd: rootDir,
|
|
198
|
-
splitting,
|
|
199
|
-
silent: () => !hasBuiltAnyFormat,
|
|
200
|
-
onDeclarationsGenerated({ result, buildConfig }) {
|
|
201
|
-
for (const file of result.files) {
|
|
202
|
-
logger.progress("DTS", `${options.outDir}/${file.outputPath}`, {
|
|
203
|
-
identifier: options.name
|
|
204
|
-
});
|
|
205
|
-
const fullPath = path.join(rootDir, options.outDir, file.outputPath);
|
|
206
|
-
if (buildConfig.format) {
|
|
207
|
-
buildOutput.files.push({
|
|
208
|
-
fullPath,
|
|
209
|
-
relativePathToRootDir: getRelativePathToRootDir(fullPath, rootDir),
|
|
210
|
-
relativePathToOutputDir: file.outputPath,
|
|
211
|
-
dts: true,
|
|
212
|
-
format: buildConfig.format,
|
|
213
|
-
kind: file.kind
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}));
|
|
219
|
-
}
|
|
220
177
|
const entrypoints = await getFilesFromGlobs(ensureArray(options.entry), rootDir);
|
|
221
178
|
if (!entrypoints.length) {
|
|
222
179
|
throw new BunupBuildError("The entrypoints you provided do not exist. Please make sure the entrypoints point to valid files.");
|
|
@@ -225,7 +182,7 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
225
182
|
const result = await Bun.build({
|
|
226
183
|
entrypoints: entrypoints.map((file) => `${rootDir}/${file}`),
|
|
227
184
|
format: fmt,
|
|
228
|
-
naming: getResolvedNaming(
|
|
185
|
+
naming: getResolvedNaming(fmt, packageType),
|
|
229
186
|
splitting: getResolvedSplitting(options.splitting, fmt),
|
|
230
187
|
bytecode: getResolvedBytecode(options.bytecode, fmt),
|
|
231
188
|
define: getResolvedDefine(options.define, options.env),
|
|
@@ -239,10 +196,9 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
239
196
|
footer: options.footer,
|
|
240
197
|
publicPath: options.publicPath,
|
|
241
198
|
env: getResolvedEnv(options.env),
|
|
242
|
-
|
|
243
|
-
|
|
199
|
+
throw: false,
|
|
200
|
+
plugins
|
|
244
201
|
});
|
|
245
|
-
hasBuiltAnyFormat = true;
|
|
246
202
|
for (const log of result.logs) {
|
|
247
203
|
if (log.level === "error") {
|
|
248
204
|
throw new BunupBuildError(log.message);
|
|
@@ -254,15 +210,16 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
254
210
|
}
|
|
255
211
|
for (const file of result.outputs) {
|
|
256
212
|
const relativePathToRootDir = getRelativePathToRootDir(file.path, rootDir);
|
|
213
|
+
const relativePathToOutputDir = getRelativePathToOutputDir(relativePathToRootDir, options.outDir);
|
|
257
214
|
if (file.kind === "entry-point") {
|
|
258
|
-
logger.
|
|
215
|
+
logger.success(`${pc.dim(options.outDir)}/${relativePathToOutputDir}`, {
|
|
259
216
|
identifier: options.name
|
|
260
217
|
});
|
|
261
218
|
}
|
|
262
219
|
buildOutput.files.push({
|
|
263
220
|
fullPath: file.path,
|
|
264
221
|
relativePathToRootDir,
|
|
265
|
-
relativePathToOutputDir
|
|
222
|
+
relativePathToOutputDir,
|
|
266
223
|
dts: false,
|
|
267
224
|
format: fmt,
|
|
268
225
|
kind: file.kind
|
|
@@ -270,6 +227,39 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
270
227
|
}
|
|
271
228
|
});
|
|
272
229
|
await Promise.all(buildPromises);
|
|
230
|
+
if (options.dts) {
|
|
231
|
+
const { entry, ...dtsOptions } = typeof options.dts === "object" ? options.dts : {};
|
|
232
|
+
const dtsResult = await generateDts(ensureArray(entry ?? entrypoints), {
|
|
233
|
+
cwd: rootDir,
|
|
234
|
+
preferredTsConfigPath: options.preferredTsconfigPath,
|
|
235
|
+
...dtsOptions
|
|
236
|
+
});
|
|
237
|
+
if (dtsResult.errors.length) {
|
|
238
|
+
logIsolatedDeclarationErrors(dtsResult.errors, {
|
|
239
|
+
shouldExit: true
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
for (const fmt of options.format) {
|
|
243
|
+
for (const file of dtsResult.files) {
|
|
244
|
+
const dtsExtension = getDefaultDtsExtention(fmt, packageType);
|
|
245
|
+
const relativePathToOutputDir = cleanPath(`${file.pathInfo.outputPathWithoutExtension}${dtsExtension}`);
|
|
246
|
+
const relativePathToRootDir = cleanPath(`${options.outDir}/${relativePathToOutputDir}`);
|
|
247
|
+
logger.success(`${pc.dim(options.outDir)}/${relativePathToOutputDir}`, {
|
|
248
|
+
identifier: options.name
|
|
249
|
+
});
|
|
250
|
+
const fullPath = path.join(rootDir, relativePathToRootDir);
|
|
251
|
+
await Bun.write(fullPath, file.dts);
|
|
252
|
+
buildOutput.files.push({
|
|
253
|
+
fullPath,
|
|
254
|
+
relativePathToRootDir,
|
|
255
|
+
relativePathToOutputDir,
|
|
256
|
+
dts: true,
|
|
257
|
+
format: fmt,
|
|
258
|
+
kind: file.kind
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
273
263
|
await runPluginBuildDoneHooks(bunupPlugins, options, buildOutput, {
|
|
274
264
|
packageJson,
|
|
275
265
|
rootDir
|