Skip to content
This repository was archived by the owner on Sep 2, 2026. It is now read-only.

Commit 64fa947

Browse files
committed
feat(monobundle): migrate to rolldown
1 parent da94060 commit 64fa947

13 files changed

Lines changed: 192 additions & 438 deletions

File tree

bun.lock

Lines changed: 92 additions & 166 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodedevpkg/monobundle/package.json

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@innoai-tech/monobundle",
3-
"version": "0.15.5",
3+
"version": "0.16.0",
44
"monobundle": {
55
"exports": {
66
".": "./src/index.ts",
@@ -14,20 +14,14 @@
1414
"@innoai-tech/lodash": "workspace:^",
1515
"@innoai-tech/purebundle": "workspace:^",
1616
"@innoai-tech/vuecomponentcompleter": "workspace:^",
17-
"@rollup/plugin-commonjs": "^28.0.6",
18-
"@rollup/plugin-node-resolve": "^16.0.1",
19-
"browserslist": "^4.26.2",
2017
"chalk": "^5.6.2",
21-
"esbuild": "^0.25.10",
22-
"globby": "^14.1.0",
18+
"globby": "^15.0.0",
2319
"js-yaml": "^4.1.0",
2420
"minimatch": "^10.0.3",
25-
"rollup": "^4.52.2",
21+
"rolldown": "^1.0.0-beta.40",
2622
"yargs": "^18.0.0"
2723
},
28-
"peerDependencies": {
29-
"typescript": "^5.0.x"
30-
},
24+
"peerDependencies": {},
3125
"devDependencies": {
3226
"@types/js-yaml": "^4.0.9",
3327
"@types/yargs": "^17.0.33"

nodedevpkg/monobundle/src/autoExternal.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { join } from "path";
22
import { readFile } from "fs/promises";
33
import { globby } from "globby";
44
import { minimatch } from "minimatch";
5-
import { type InputOptions } from "rollup";
5+
import { type InputOptions, type Plugin } from "rolldown";
66
import type { Project } from "./pm";
77
// @ts-ignore
88
const builtIns = process.binding("natives");
@@ -48,13 +48,13 @@ export const collectDeps = async (project: Project, localPkg: Package) => {
4848
const packageJSONs = await globby(
4949
workspaces.map((b) => `${b}/package.json`),
5050
{
51-
cwd: project.root,
52-
},
51+
cwd: project.root
52+
}
5353
);
5454

5555
for (const f of packageJSONs) {
5656
let pkg = JSON.parse(
57-
String(await readFile(join(`${project.root}`, f))),
57+
String(await readFile(join(`${project.root}`, f)))
5858
) as Package;
5959

6060
// localPkg may be changed
@@ -80,7 +80,7 @@ export const createAutoExternal = async (
8080
opts: {
8181
logger?: ReturnType<typeof import("./log").createLogger>;
8282
sideDeps?: string[];
83-
},
83+
}
8484
) => {
8585
const logger = opts.logger;
8686
const sideDeps = opts.sideDeps || [];
@@ -90,7 +90,7 @@ export const createAutoExternal = async (
9090
return false;
9191
}
9292
return sideDeps.some(
93-
(glob) => pkgName === glob || minimatch(pkgName, glob),
93+
(glob) => pkgName === glob || minimatch(pkgName, glob)
9494
);
9595
};
9696

@@ -123,7 +123,7 @@ export const createAutoExternal = async (
123123

124124
const unused = {
125125
deps: {} as { [k: string]: boolean },
126-
peerDeps: {} as { [k: string]: boolean },
126+
peerDeps: {} as { [k: string]: boolean }
127127
};
128128

129129
for (const d of dep) {
@@ -142,7 +142,7 @@ export const createAutoExternal = async (
142142

143143
const collector = new Set<string>();
144144

145-
const autoExternal = (validate = true) => {
145+
const autoExternal = (validate = true): Plugin => {
146146
return {
147147
name: "auto-external",
148148

@@ -152,7 +152,7 @@ export const createAutoExternal = async (
152152
external(
153153
id: string,
154154
importer: string | undefined,
155-
isResolved: boolean,
155+
isResolved: boolean
156156
) {
157157
if (
158158
typeof opts.external === "function" &&
@@ -165,6 +165,10 @@ export const createAutoExternal = async (
165165
return true;
166166
}
167167

168+
if (id.startsWith("node:")) {
169+
return true;
170+
}
171+
168172
if (!(id.startsWith(".") || id.startsWith("/"))) {
169173
const isDep = [...dep.keys()].some((d) => id.startsWith(d));
170174
const isBuiltIn =
@@ -184,7 +188,7 @@ export const createAutoExternal = async (
184188
collector.add(id);
185189

186190
logger?.danger(
187-
`"${id}" is not in dependencies or peerDependencies, and will be bundled.`,
191+
`"${id}" is not in dependencies or peerDependencies, and will be bundled.`
188192
);
189193
}
190194
}
@@ -193,9 +197,9 @@ export const createAutoExternal = async (
193197
}
194198

195199
return false;
196-
},
200+
}
197201
};
198-
},
202+
}
199203
};
200204
};
201205

nodedevpkg/monobundle/src/bundle.ts

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
11
import { basename, extname, join, relative } from "path";
2-
import {
3-
has,
4-
isEmpty,
5-
keys,
6-
map,
7-
mapKeys,
8-
mapValues
9-
} from "@innoai-tech/lodash";
10-
import commonjs from "@rollup/plugin-commonjs";
11-
import { nodeResolve } from "@rollup/plugin-node-resolve";
2+
import { forEach, has, isEmpty, keys, mapKeys, mapValues, set, startsWith } from "@innoai-tech/lodash";
123
import { readFile, unlink } from "fs/promises";
134
import { globby } from "globby";
14-
import { type OutputOptions, rollup } from "rollup";
5+
import { type OutputOptions, rolldown } from "rolldown";
156
import { createAutoExternal } from "./autoExternal";
167
import { bootstrap } from "./bootstrap";
17-
import { esbuild } from "./esbuild";
18-
import { getBuildTargets } from "./getTarget";
198
import { createLogger } from "./log";
209
import { patchShebang } from "./patchShebang";
2110
import { resolveProjectRoot } from "./pm";
22-
import {
23-
type MonoBundleOptions,
24-
entryAlias,
25-
writeFormattedJsonFile
26-
} from "./util";
27-
import { forEach, set, startsWith } from "@innoai-tech/lodash";
11+
import { entryAlias, type MonoBundleOptions, writeFormattedJsonFile } from "./util";
2812
import { chunkCleanup } from "./chunkCleanup.ts";
2913
import { vueComponentComplete } from "./vueComponentComplete.ts";
3014

@@ -85,11 +69,7 @@ export const bundle = async ({
8569
sideDeps: options["sideDeps"] as any
8670
});
8771

88-
const buildTargets = getBuildTargets(
89-
(pkg as any).browserslist ?? ["defaults"]
90-
);
91-
92-
const rollupOptions = [
72+
const rolldownOptions = [
9373
{
9474
input: inputs,
9575
output: {
@@ -98,17 +78,13 @@ export const bundle = async ({
9878
entryFileNames: "[name].mjs",
9979
chunkFileNames: "[name]-[hash].mjs"
10080
},
81+
resolve: {
82+
extensions: [".ts", ".tsx", ".mjs", "", ".js", ".jsx"]
83+
},
84+
tsconfig: tsconfigFile,
10185
plugins: [
10286
autoExternal(),
103-
nodeResolve({
104-
extensions: [".ts", ".tsx", ".mjs", "", ".js", ".jsx"]
105-
}),
106-
commonjs(),
10787
vueComponentComplete({}),
108-
esbuild({
109-
tsconfig: tsconfigFile,
110-
target: map(buildTargets, (v, k) => `${k}${v}`)
111-
}),
11288
patchShebang((chunkName) => {
11389
return !!options.exports?.[
11490
`bin:${basename(chunkName, extname(chunkName))}`
@@ -125,15 +101,15 @@ export const bundle = async ({
125101
await unlink(join(cwd, f));
126102
}
127103

128-
logger.warning(`bundling (target: ${JSON.stringify(buildTargets)})`);
104+
logger.warning(`bundling`);
129105

130106
const outputFiles: { [k: string]: boolean } = {};
131107

132-
for (const rollupOption of rollupOptions) {
133-
const files = await rollup(rollupOption).then((bundle) => {
108+
for (const rolldownOption of rolldownOptions) {
109+
const files = await rolldown(rolldownOption).then((bundle) => {
134110
return Promise.all(
135111
([] as OutputOptions[])
136-
.concat(rollupOption.output ?? [])
112+
.concat(rolldownOption.output ?? [])
137113
.map((output) => {
138114
if (dryRun) {
139115
return [];

nodedevpkg/monobundle/src/chunkCleanup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { transform, usePlugin } from "@innoai-tech/purebundle";
2-
import { type Plugin } from "rollup";
2+
import { type Plugin } from "rolldown";
33

44
export const chunkCleanup = (
55
opt: {

nodedevpkg/monobundle/src/esbuild.ts

Lines changed: 0 additions & 101 deletions
This file was deleted.

nodedevpkg/monobundle/src/getTarget.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

nodedevpkg/monobundle/src/patchShebang.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Plugin } from "rollup";
1+
import type { Plugin } from "rolldown";
22

33
export const patchShebang = (
44
isBin: (fileName: string) => boolean,

nodedevpkg/monobundle/src/vueComponentComplete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { extname } from "path";
2-
import type { Plugin } from "rollup";
2+
import type { Plugin } from "rolldown";
33
import { transform, usePlugin } from "@innoai-tech/vuecomponentcompleter";
44

55
export const vueComponentComplete = ({}): Plugin => {

nodepkg/config/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@innoai-tech/config",
3-
"version": "0.5.8",
3+
"version": "0.6.1",
44
"monobundle": {
55
"exports": {
66
".": "./src/index.ts",
@@ -9,10 +9,11 @@
99
}
1010
},
1111
"dependencies": {
12-
"@innoai-tech/lodash": "workspace:^",
13-
"esbuild": "^0.25.10"
12+
"@innoai-tech/lodash": "workspace:^"
13+
},
14+
"peerDependencies": {
15+
"rolldown": "*"
1416
},
15-
"peerDependencies": {},
1617
"browserslist": [
1718
"defaults"
1819
],

0 commit comments

Comments
 (0)