Skip to content

Commit 62929f3

Browse files
committed
chore: update build
1 parent 887320c commit 62929f3

File tree

2 files changed

+38
-48
lines changed

2 files changed

+38
-48
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"LICENSE"
2020
],
2121
"scripts": {
22-
"build": "bun run build:types && bun scripts/build.ts lib && bun scripts/build.ts umd",
22+
"build": "bun run build:types && bun scripts/build.ts lib umd",
2323
"build:types": "tsc -p tsconfig.build.json",
2424
"build:lib": "bun scripts/build.ts lib",
2525
"build:umd": "bun scripts/build.ts umd",

scripts/build.ts

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
#!/usr/bin/env bun
22

3-
import type { BuildConfig } from "bun";
3+
import type { BuildConfig, BuildOutput } from "bun";
44
import { build } from "bun";
55

6-
const target = process.argv[2] || "lib";
76
const isDev = process.argv.includes("--dev");
87
const isProduction = !isDev;
98

10-
async function buildLib() {
11-
const config: BuildConfig = {
12-
entrypoints: ["./src/index.ts"],
13-
outdir: "./dist",
14-
target: "node",
15-
format: "esm",
16-
external: ["@opentelemetry/*"],
17-
minify: isProduction,
18-
sourcemap: isProduction ? "linked" : "inline",
19-
naming: { entry: "index.mjs" },
20-
};
21-
22-
const result = await build(config);
23-
9+
function handleBuildResult(result: BuildOutput, target: string) {
2410
if (!result.success) {
2511
console.error(`Build failed for target '${target}':`);
2612
result.logs.forEach((log) => {
@@ -36,10 +22,26 @@ async function buildLib() {
3622
}
3723

3824
console.log(
39-
`✓ Built lib bundle: ${result.outputs.map((o) => o.path).join(", ")}`
25+
`✓ Built ${target} bundle: ${result.outputs.map((o) => o.path).join(", ")}`
4026
);
4127
}
4228

29+
async function buildLib() {
30+
const config: BuildConfig = {
31+
entrypoints: ["./src/index.ts"],
32+
outdir: "./dist",
33+
target: "node",
34+
format: "esm",
35+
external: ["@opentelemetry/*"],
36+
minify: isProduction,
37+
sourcemap: isProduction ? "linked" : "inline",
38+
naming: { entry: "index.mjs" },
39+
};
40+
41+
const result = await build(config);
42+
handleBuildResult(result, "lib");
43+
}
44+
4345
async function buildUmd() {
4446
const config: BuildConfig = {
4547
entrypoints: ["./src/umd.ts"],
@@ -53,39 +55,27 @@ async function buildUmd() {
5355
};
5456

5557
const result = await build(config);
56-
57-
if (!result.success) {
58-
console.error(`Build failed for target '${target}':`);
59-
result.logs.forEach((log) => {
60-
const level = log.level === "error" ? "ERROR" : log.level.toUpperCase();
61-
console.error(` [${level}] ${log.message}`);
62-
if (log.position) {
63-
console.error(
64-
` at ${log.position.file}:${log.position.line}:${log.position.column}`
65-
);
66-
}
67-
});
68-
process.exit(1);
69-
}
70-
71-
console.log(
72-
`✓ Built UMD bundle: ${result.outputs.map((o) => o.path).join(", ")}`
73-
);
58+
handleBuildResult(result, "umd");
7459
}
7560

7661
async function main() {
77-
switch (target) {
78-
case "lib":
79-
await buildLib();
80-
break;
81-
case "umd":
82-
await buildUmd();
83-
break;
84-
default:
85-
console.error(`Unknown target: ${target}`);
86-
console.error("Available targets: lib, umd");
87-
process.exit(1);
88-
}
62+
const args = process.argv.slice(2).filter((arg) => !arg.startsWith("--"));
63+
const targetsToBuild = args.length > 0 ? args : ["lib", "umd"];
64+
65+
const buildPromises = targetsToBuild.map((target) => {
66+
switch (target) {
67+
case "lib":
68+
return buildLib();
69+
case "umd":
70+
return buildUmd();
71+
default:
72+
console.error(`Unknown target: ${target}`);
73+
console.error("Available targets: lib, umd");
74+
process.exit(1);
75+
}
76+
});
77+
78+
await Promise.all(buildPromises);
8979
}
9080

9181
main().catch(console.error);

0 commit comments

Comments
 (0)