@vitus-labs/tools-rolldown 2.3.0 → 2.4.0
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/lib/scripts/build.js +155 -47
- package/lib/scripts/build.js.map +1 -1
- package/lib/types/scripts/build.d.ts.map +1 -1
- package/package.json +6 -7
package/lib/scripts/build.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { cpSync, mkdirSync, readdirSync, renameSync, statSync } from 'node:fs';
|
|
1
|
+
import { cpSync, mkdirSync, readdirSync, renameSync, rmSync, statSync, } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
-
import { rimraf } from 'rimraf';
|
|
5
4
|
import { rolldown } from 'rolldown';
|
|
6
5
|
import { CONFIG, PKG } from "../config/index.js";
|
|
7
6
|
import { buildAllDts, createBuildPipeline, config as rolldownConfig, } from "../rolldown/index.js";
|
|
@@ -22,27 +21,128 @@ async function build({ inputOptions, outputOptions, }) {
|
|
|
22
21
|
await bundle.write(outputOptions);
|
|
23
22
|
await bundle.close();
|
|
24
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Longest common parent directory of a list of file paths.
|
|
26
|
+
* '/lib/index.js' + '/lib/component.js' -> '/lib'
|
|
27
|
+
* '/lib/index.js' + '/lib/sub/foo.js' -> '/lib'
|
|
28
|
+
*/
|
|
29
|
+
const commonParent = (files) => {
|
|
30
|
+
if (files.length === 0)
|
|
31
|
+
return '.';
|
|
32
|
+
const split = files.map((f) => {
|
|
33
|
+
const i = f.lastIndexOf('/');
|
|
34
|
+
return i >= 0 ? f.substring(0, i).split('/') : ['.'];
|
|
35
|
+
});
|
|
36
|
+
const head = split[0];
|
|
37
|
+
let common = head;
|
|
38
|
+
for (const s of split.slice(1)) {
|
|
39
|
+
const next = [];
|
|
40
|
+
for (let i = 0; i < Math.min(common.length, s.length); i++) {
|
|
41
|
+
if (common[i] === s[i])
|
|
42
|
+
next.push(common[i]);
|
|
43
|
+
else
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
common = next;
|
|
47
|
+
}
|
|
48
|
+
return common.length === 0 ? '.' : common.join('/');
|
|
49
|
+
};
|
|
50
|
+
const stripJsExt = (s) => s.replace(/\.(m?js|cjs)$/, '');
|
|
51
|
+
/**
|
|
52
|
+
* Partition variants into groups eligible for multi-entry shared-chunk
|
|
53
|
+
* builds, and singletons that keep the per-entry path.
|
|
54
|
+
*
|
|
55
|
+
* Eligible: same (format, env, platform), explicit `input` set, and a
|
|
56
|
+
* format that supports code-splitting (i.e. not umd/iife — those are
|
|
57
|
+
* inherently standalone bundles).
|
|
58
|
+
*/
|
|
59
|
+
const partitionForSharedChunks = (variants) => {
|
|
60
|
+
const buckets = new Map();
|
|
61
|
+
const singles = [];
|
|
62
|
+
for (const v of variants) {
|
|
63
|
+
if (!v.input || ['umd', 'iife'].includes(v.format)) {
|
|
64
|
+
singles.push(v);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const key = `${v.format}|${v.env}|${v.platform}`;
|
|
68
|
+
const bucket = buckets.get(key) ?? [];
|
|
69
|
+
bucket.push(v);
|
|
70
|
+
buckets.set(key, bucket);
|
|
71
|
+
}
|
|
72
|
+
const groups = [];
|
|
73
|
+
for (const bucket of buckets.values()) {
|
|
74
|
+
if (bucket.length <= 1)
|
|
75
|
+
singles.push(...bucket);
|
|
76
|
+
else
|
|
77
|
+
groups.push(bucket);
|
|
78
|
+
}
|
|
79
|
+
return { groups, singles };
|
|
80
|
+
};
|
|
81
|
+
/** Build one group of multi-entry variants as a single rolldown invocation. */
|
|
82
|
+
const buildGroup = async (group) => {
|
|
83
|
+
// Use the first variant as the representative for format/env/platform —
|
|
84
|
+
// they're identical across the group by construction.
|
|
85
|
+
const head = group[0];
|
|
86
|
+
const dir = commonParent(group.map((v) => v.file));
|
|
87
|
+
// Entry name = file relative to common parent, with .js/.cjs/.mjs stripped.
|
|
88
|
+
// rolldown preserves '/' in input keys, so nested entries map cleanly to
|
|
89
|
+
// nested output paths via [name] in entryFileNames.
|
|
90
|
+
const inputMap = {};
|
|
91
|
+
for (const v of group) {
|
|
92
|
+
const rel = v.file.startsWith(`${dir}/`)
|
|
93
|
+
? v.file.substring(dir.length + 1)
|
|
94
|
+
: v.file;
|
|
95
|
+
inputMap[stripJsExt(rel)] = v.input;
|
|
96
|
+
}
|
|
97
|
+
// Build via the per-variant config to inherit plugins/externals/etc.,
|
|
98
|
+
// then override input + output for the group.
|
|
99
|
+
const { output, ...inputOptions } = rolldownConfig(head);
|
|
100
|
+
inputOptions.input = inputMap;
|
|
101
|
+
const outputOptions = {
|
|
102
|
+
...output,
|
|
103
|
+
dir,
|
|
104
|
+
entryFileNames: '[name].js',
|
|
105
|
+
chunkFileNames: '_chunks/[name]-[hash].js',
|
|
106
|
+
};
|
|
107
|
+
const format = FORMAT_LABEL[head.format] || head.format;
|
|
108
|
+
const start = performance.now();
|
|
109
|
+
try {
|
|
110
|
+
await build({ inputOptions, outputOptions });
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
log(`\n${chalk.bold.red('Build failed')}`);
|
|
114
|
+
log(chalk.gray(` Format: ${format}`));
|
|
115
|
+
log(chalk.gray(` Entries: ${Object.keys(inputMap).join(', ')}`));
|
|
116
|
+
log(e);
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
119
|
+
const duration = Math.round(performance.now() - start);
|
|
120
|
+
log(` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(`${dir}/{${Object.keys(inputMap).join(',')}}.js`)} ${dim(`(${duration}ms, shared chunks)`)}`);
|
|
121
|
+
};
|
|
122
|
+
const buildSingle = async (item) => {
|
|
123
|
+
const { output, ...inputOptions } = rolldownConfig(item);
|
|
124
|
+
const format = FORMAT_LABEL[output.format] || output.format;
|
|
125
|
+
const start = performance.now();
|
|
126
|
+
try {
|
|
127
|
+
await build({ inputOptions, outputOptions: output });
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
log(`\n${chalk.bold.red('Build failed')}`);
|
|
131
|
+
log(chalk.gray(` Format: ${format}`));
|
|
132
|
+
log(chalk.gray(` File: ${output.dir}/${output.entryFileNames}`));
|
|
133
|
+
log(e);
|
|
134
|
+
throw e;
|
|
135
|
+
}
|
|
136
|
+
const duration = Math.round(performance.now() - start);
|
|
137
|
+
log(` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(`${output.dir}/${output.entryFileNames}`)} ${dim(`(${duration}ms)`)}`);
|
|
138
|
+
};
|
|
25
139
|
const createBuilds = async () => {
|
|
140
|
+
const { groups, singles } = partitionForSharedChunks(allBuilds);
|
|
26
141
|
let p = Promise.resolve();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
p = p.then(() =>
|
|
31
|
-
const start = performance.now();
|
|
32
|
-
return build({ inputOptions: input, outputOptions: output })
|
|
33
|
-
.then(() => {
|
|
34
|
-
const duration = Math.round(performance.now() - start);
|
|
35
|
-
log(` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(`${output.dir}/${output.entryFileNames}`)} ${dim(`(${duration}ms)`)}`);
|
|
36
|
-
})
|
|
37
|
-
.catch((e) => {
|
|
38
|
-
log(`\n${chalk.bold.red('Build failed')}`);
|
|
39
|
-
log(chalk.gray(` Format: ${format}`));
|
|
40
|
-
log(chalk.gray(` File: ${output.dir}/${output.entryFileNames}`));
|
|
41
|
-
log(e);
|
|
42
|
-
throw e;
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
});
|
|
142
|
+
for (const item of singles)
|
|
143
|
+
p = p.then(() => buildSingle(item));
|
|
144
|
+
for (const group of groups)
|
|
145
|
+
p = p.then(() => buildGroup(group));
|
|
46
146
|
return p;
|
|
47
147
|
};
|
|
48
148
|
const copyStaticFiles = () => {
|
|
@@ -67,35 +167,40 @@ const buildDtsIsolated = async (dtsConfig) => {
|
|
|
67
167
|
const finalDir = output.dir;
|
|
68
168
|
const entryName = output.entryFileNames;
|
|
69
169
|
const tempDir = join(finalDir, `__dts_tmp_${entryName.replace(/\W/g, '_')}`);
|
|
70
|
-
// Build into isolated temp directory
|
|
71
|
-
const tempOutput = { ...output, dir: tempDir };
|
|
72
|
-
await build({ inputOptions: input, outputOptions: tempOutput });
|
|
73
|
-
// Find the largest .d.ts file — that's the real declarations
|
|
74
170
|
const absTempDir = join(process.cwd(), tempDir);
|
|
75
|
-
const dtsFiles = readdirSync(absTempDir).filter((f) => f.endsWith('.d.ts'));
|
|
76
|
-
let bestFile = dtsFiles[0] || entryName;
|
|
77
|
-
let bestSize = 0;
|
|
78
|
-
for (const f of dtsFiles) {
|
|
79
|
-
const size = statSync(join(absTempDir, f)).size;
|
|
80
|
-
if (size > bestSize) {
|
|
81
|
-
bestSize = size;
|
|
82
|
-
bestFile = f;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Move the best file to the final location
|
|
86
|
-
const absFinalDir = join(process.cwd(), finalDir);
|
|
87
|
-
mkdirSync(absFinalDir, { recursive: true });
|
|
88
|
-
renameSync(join(absTempDir, bestFile), join(absFinalDir, entryName));
|
|
89
|
-
// Move sourcemap if it exists
|
|
90
|
-
const mapName = `${bestFile}.map`;
|
|
91
171
|
try {
|
|
92
|
-
|
|
172
|
+
// Build into isolated temp directory
|
|
173
|
+
const tempOutput = { ...output, dir: tempDir };
|
|
174
|
+
await build({ inputOptions: input, outputOptions: tempOutput });
|
|
175
|
+
// Find the largest .d.ts file — that's the real declarations
|
|
176
|
+
const dtsFiles = readdirSync(absTempDir).filter((f) => f.endsWith('.d.ts'));
|
|
177
|
+
let bestFile = dtsFiles[0] || entryName;
|
|
178
|
+
let bestSize = 0;
|
|
179
|
+
for (const f of dtsFiles) {
|
|
180
|
+
const size = statSync(join(absTempDir, f)).size;
|
|
181
|
+
if (size > bestSize) {
|
|
182
|
+
bestSize = size;
|
|
183
|
+
bestFile = f;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Move the best file to the final location
|
|
187
|
+
const absFinalDir = join(process.cwd(), finalDir);
|
|
188
|
+
mkdirSync(absFinalDir, { recursive: true });
|
|
189
|
+
renameSync(join(absTempDir, bestFile), join(absFinalDir, entryName));
|
|
190
|
+
// Move sourcemap if it exists
|
|
191
|
+
const mapName = `${bestFile}.map`;
|
|
192
|
+
try {
|
|
193
|
+
renameSync(join(absTempDir, mapName), join(absFinalDir, `${entryName}.map`));
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// sourcemap may not exist
|
|
197
|
+
}
|
|
93
198
|
}
|
|
94
|
-
|
|
95
|
-
//
|
|
199
|
+
finally {
|
|
200
|
+
// Always remove the temp dir — even if the build or a post-step
|
|
201
|
+
// throws — so a partial failure can't leak __dts_tmp_* into lib/.
|
|
202
|
+
rmSync(absTempDir, { recursive: true, force: true });
|
|
96
203
|
}
|
|
97
|
-
// Clean up temp directory
|
|
98
|
-
rimraf.sync(absTempDir);
|
|
99
204
|
};
|
|
100
205
|
const generateDeclarations = async () => {
|
|
101
206
|
const dtsConfigs = buildAllDts();
|
|
@@ -113,7 +218,10 @@ const runBuild = async () => {
|
|
|
113
218
|
const start = performance.now();
|
|
114
219
|
log(`\n${label('rolldown')} ${bold(PKG.name || '')} ${dim(`v${PKG.version || '0.0.0'}`)}\n`);
|
|
115
220
|
log(`${dim('Cleaning')} ${CONFIG.outputDir}/`);
|
|
116
|
-
|
|
221
|
+
rmSync(`${process.cwd()}/${CONFIG.outputDir}`, {
|
|
222
|
+
recursive: true,
|
|
223
|
+
force: true,
|
|
224
|
+
});
|
|
117
225
|
log(`${dim('Building')} ${bold(String(allBuildsCount))} bundle${allBuildsCount > 1 ? 's' : ''}...\n`);
|
|
118
226
|
await createBuilds();
|
|
119
227
|
copyStaticFiles();
|
package/lib/scripts/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/scripts/build.ts"],"names":[],"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AAM,CAAC,SAAS,EAAE,CAAC,CAAA;IAEnD,GAAG,CACD,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,UAAU,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,CACjG,CAAA;IAED,MAAM,YAAY,EAAE,CAAA;IACpB,eAAe,EAAE,CAAA;IACjB,MAAM,oBAAoB,EAAE,CAAA;IAE5B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAA;IACnD,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,CAAA;AAC3D,CAAC,CAAA;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA","sourcesContent":["import { cpSync, mkdirSync, readdirSync, renameSync, statSync } from 'node:fs'\nimport { join } from 'node:path'\nimport chalk from 'chalk'\nimport { rimraf } from 'rimraf'\nimport { rolldown } from 'rolldown'\nimport { CONFIG, PKG } from '../config/index.ts'\nimport {\n buildAllDts,\n createBuildPipeline,\n config as rolldownConfig,\n} from '../rolldown/index.ts'\n\nconst { log } = console\nconst allBuilds = createBuildPipeline()\nconst allBuildsCount = allBuilds.length\n\nconst FORMAT_LABEL: Record<string, string> = {\n cjs: 'CJS',\n es: 'ESM',\n umd: 'UMD',\n iife: 'IIFE',\n}\n\nconst label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)\nconst dim = chalk.dim\nconst bold = chalk.bold\n\nasync function build({\n inputOptions,\n outputOptions,\n}: {\n inputOptions: any\n outputOptions: any\n}) {\n const bundle = await rolldown(inputOptions)\n await bundle.write(outputOptions)\n await bundle.close()\n}\n\nconst createBuilds = async () => {\n let p = Promise.resolve()\n\n allBuilds.forEach((item: Record<string, any>) => {\n const { output, ...input } = rolldownConfig(item)\n const format = FORMAT_LABEL[output.format] || output.format\n p = p.then(() => {\n const start = performance.now()\n\n return build({ inputOptions: input, outputOptions: output })\n .then(() => {\n const duration = Math.round(performance.now() - start)\n log(\n ` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(`${output.dir}/${output.entryFileNames}`)} ${dim(`(${duration}ms)`)}`,\n )\n })\n .catch((e) => {\n log(`\\n${chalk.bold.red('Build failed')}`)\n log(chalk.gray(` Format: ${format}`))\n log(chalk.gray(` File: ${output.dir}/${output.entryFileNames}`))\n log(e)\n throw e\n })\n })\n })\n\n return p\n}\n\nconst copyStaticFiles = () => {\n if (!Array.isArray(CONFIG.copyFiles) || CONFIG.copyFiles.length === 0) return\n\n log(`\\n${dim('Copying')} static files...\\n`)\n for (const { from, to } of CONFIG.copyFiles as {\n from: string\n to: string\n }[]) {\n cpSync(from, to, { recursive: true })\n log(` ${chalk.green('+')} ${dim(from)} ${dim('->')} ${dim(to)}`)\n }\n}\n\n/**\n * Build a single DTS entry in an isolated temp directory, then move the\n * largest .d.ts file (the real declarations) to the final output path.\n *\n * Rolldown code-splits DTS output: the entry file is a tiny re-export stub,\n * and the actual types go into a chunk. Building into a temp dir avoids\n * collisions when multiple DTS entries share the same output directory.\n */\nconst buildDtsIsolated = async (\n dtsConfig: ReturnType<typeof buildAllDts>[number],\n) => {\n const { output, file, ...input } = dtsConfig\n const finalDir = output.dir as string\n const entryName = output.entryFileNames as string\n const tempDir = join(finalDir, `__dts_tmp_${entryName.replace(/\\W/g, '_')}`)\n\n // Build into isolated temp directory\n const tempOutput = { ...output, dir: tempDir }\n await build({ inputOptions: input, outputOptions: tempOutput })\n\n // Find the largest .d.ts file — that's the real declarations\n const absTempDir = join(process.cwd(), tempDir)\n const dtsFiles = readdirSync(absTempDir).filter((f) => f.endsWith('.d.ts'))\n\n let bestFile = dtsFiles[0] || entryName\n let bestSize = 0\n for (const f of dtsFiles) {\n const size = statSync(join(absTempDir, f)).size\n if (size > bestSize) {\n bestSize = size\n bestFile = f\n }\n }\n\n // Move the best file to the final location\n const absFinalDir = join(process.cwd(), finalDir)\n mkdirSync(absFinalDir, { recursive: true })\n renameSync(join(absTempDir, bestFile), join(absFinalDir, entryName))\n\n // Move sourcemap if it exists\n const mapName = `${bestFile}.map`\n try {\n renameSync(join(absTempDir, mapName), join(absFinalDir, `${entryName}.map`))\n } catch {\n // sourcemap may not exist\n }\n\n // Clean up temp directory\n rimraf.sync(absTempDir)\n}\n\nconst generateDeclarations = async () => {\n const dtsConfigs = buildAllDts()\n if (dtsConfigs.length === 0) return\n\n log(`\\n${dim('Generating')} declarations...`)\n\n for (const dtsFile of dtsConfigs) {\n const tscStart = performance.now()\n await buildDtsIsolated(dtsFile)\n\n const tscDuration = Math.round(performance.now() - tscStart)\n log(\n ` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(dtsFile.file)} ${dim(`(${tscDuration}ms)`)}`,\n )\n }\n}\n\nconst runBuild = async () => {\n const start = performance.now()\n\n log(\n `\\n${label('rolldown')} ${bold(PKG.name || '')} ${dim(`v${PKG.version || '0.0.0'}`)}\\n`,\n )\n\n log(`${dim('Cleaning')} ${CONFIG.outputDir}/`)\n rimraf.sync(`${process.cwd()}/${CONFIG.outputDir}`)\n\n log(\n `${dim('Building')} ${bold(String(allBuildsCount))} bundle${allBuildsCount > 1 ? 's' : ''}...\\n`,\n )\n\n await createBuilds()\n copyStaticFiles()\n await generateDeclarations()\n\n const total = Math.round(performance.now() - start)\n log(`\\n${chalk.green('Done')} ${dim(`in ${total}ms`)}\\n`)\n}\n\nexport { runBuild }\n"]}
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/scripts/build.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,SAAS,EACT,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,GACT,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,KAAK,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GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,CAAA;AAC3D,CAAC,CAAA;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA","sourcesContent":["import {\n cpSync,\n mkdirSync,\n readdirSync,\n renameSync,\n rmSync,\n statSync,\n} from 'node:fs'\nimport { join } from 'node:path'\nimport chalk from 'chalk'\nimport { rolldown } from 'rolldown'\nimport { CONFIG, PKG } from '../config/index.ts'\nimport {\n buildAllDts,\n createBuildPipeline,\n config as rolldownConfig,\n} from '../rolldown/index.ts'\n\nconst { log } = console\nconst allBuilds = createBuildPipeline()\nconst allBuildsCount = allBuilds.length\n\nconst FORMAT_LABEL: Record<string, string> = {\n cjs: 'CJS',\n es: 'ESM',\n umd: 'UMD',\n iife: 'IIFE',\n}\n\nconst label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)\nconst dim = chalk.dim\nconst bold = chalk.bold\n\nasync function build({\n inputOptions,\n outputOptions,\n}: {\n inputOptions: any\n outputOptions: any\n}) {\n const bundle = await rolldown(inputOptions)\n await bundle.write(outputOptions)\n await bundle.close()\n}\n\n/**\n * Longest common parent directory of a list of file paths.\n * '/lib/index.js' + '/lib/component.js' -> '/lib'\n * '/lib/index.js' + '/lib/sub/foo.js' -> '/lib'\n */\nconst commonParent = (files: string[]): string => {\n if (files.length === 0) return '.'\n const split = files.map((f) => {\n const i = f.lastIndexOf('/')\n return i >= 0 ? f.substring(0, i).split('/') : ['.']\n })\n const head = split[0] as string[]\n let common: string[] = head\n for (const s of split.slice(1)) {\n const next: string[] = []\n for (let i = 0; i < Math.min(common.length, s.length); i++) {\n if (common[i] === s[i]) next.push(common[i] as string)\n else break\n }\n common = next\n }\n return common.length === 0 ? '.' : common.join('/')\n}\n\nconst stripJsExt = (s: string): string => s.replace(/\\.(m?js|cjs)$/, '')\n\n/**\n * Partition variants into groups eligible for multi-entry shared-chunk\n * builds, and singletons that keep the per-entry path.\n *\n * Eligible: same (format, env, platform), explicit `input` set, and a\n * format that supports code-splitting (i.e. not umd/iife — those are\n * inherently standalone bundles).\n */\nconst partitionForSharedChunks = (variants: Record<string, any>[]) => {\n const buckets = new Map<string, Record<string, any>[]>()\n const singles: Record<string, any>[] = []\n for (const v of variants) {\n if (!v.input || ['umd', 'iife'].includes(v.format)) {\n singles.push(v)\n continue\n }\n const key = `${v.format}|${v.env}|${v.platform}`\n const bucket = buckets.get(key) ?? []\n bucket.push(v)\n buckets.set(key, bucket)\n }\n const groups: Record<string, any>[][] = []\n for (const bucket of buckets.values()) {\n if (bucket.length <= 1) singles.push(...bucket)\n else groups.push(bucket)\n }\n return { groups, singles }\n}\n\n/** Build one group of multi-entry variants as a single rolldown invocation. */\nconst buildGroup = async (group: Record<string, any>[]) => {\n // Use the first variant as the representative for format/env/platform —\n // they're identical across the group by construction.\n const head = group[0] as Record<string, any>\n const dir = commonParent(group.map((v) => v.file as string))\n // Entry name = file relative to common parent, with .js/.cjs/.mjs stripped.\n // rolldown preserves '/' in input keys, so nested entries map cleanly to\n // nested output paths via [name] in entryFileNames.\n const inputMap: Record<string, string> = {}\n for (const v of group) {\n const rel = (v.file as string).startsWith(`${dir}/`)\n ? (v.file as string).substring(dir.length + 1)\n : (v.file as string)\n inputMap[stripJsExt(rel)] = v.input as string\n }\n\n // Build via the per-variant config to inherit plugins/externals/etc.,\n // then override input + output for the group.\n const { output, ...inputOptions } = rolldownConfig(head)\n inputOptions.input = inputMap\n const outputOptions = {\n ...output,\n dir,\n entryFileNames: '[name].js',\n chunkFileNames: '_chunks/[name]-[hash].js',\n }\n\n const format = FORMAT_LABEL[head.format] || head.format\n const start = performance.now()\n try {\n await build({ inputOptions, outputOptions })\n } catch (e) {\n log(`\\n${chalk.bold.red('Build failed')}`)\n log(chalk.gray(` Format: ${format}`))\n log(chalk.gray(` Entries: ${Object.keys(inputMap).join(', ')}`))\n log(e)\n throw e\n }\n const duration = Math.round(performance.now() - start)\n log(\n ` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(`${dir}/{${Object.keys(inputMap).join(',')}}.js`)} ${dim(`(${duration}ms, shared chunks)`)}`,\n )\n}\n\nconst buildSingle = async (item: Record<string, any>) => {\n const { output, ...inputOptions } = rolldownConfig(item)\n const format = FORMAT_LABEL[output.format] || output.format\n const start = performance.now()\n try {\n await build({ inputOptions, outputOptions: output })\n } catch (e) {\n log(`\\n${chalk.bold.red('Build failed')}`)\n log(chalk.gray(` Format: ${format}`))\n log(chalk.gray(` File: ${output.dir}/${output.entryFileNames}`))\n log(e)\n throw e\n }\n const duration = Math.round(performance.now() - start)\n log(\n ` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(`${output.dir}/${output.entryFileNames}`)} ${dim(`(${duration}ms)`)}`,\n )\n}\n\nconst createBuilds = async () => {\n const { groups, singles } = partitionForSharedChunks(allBuilds)\n let p = Promise.resolve()\n for (const item of singles) p = p.then(() => buildSingle(item))\n for (const group of groups) p = p.then(() => buildGroup(group))\n return p\n}\n\nconst copyStaticFiles = () => {\n if (!Array.isArray(CONFIG.copyFiles) || CONFIG.copyFiles.length === 0) return\n\n log(`\\n${dim('Copying')} static files...\\n`)\n for (const { from, to } of CONFIG.copyFiles as {\n from: string\n to: string\n }[]) {\n cpSync(from, to, { recursive: true })\n log(` ${chalk.green('+')} ${dim(from)} ${dim('->')} ${dim(to)}`)\n }\n}\n\n/**\n * Build a single DTS entry in an isolated temp directory, then move the\n * largest .d.ts file (the real declarations) to the final output path.\n *\n * Rolldown code-splits DTS output: the entry file is a tiny re-export stub,\n * and the actual types go into a chunk. Building into a temp dir avoids\n * collisions when multiple DTS entries share the same output directory.\n */\nconst buildDtsIsolated = async (\n dtsConfig: ReturnType<typeof buildAllDts>[number],\n) => {\n const { output, file, ...input } = dtsConfig\n const finalDir = output.dir as string\n const entryName = output.entryFileNames as string\n const tempDir = join(finalDir, `__dts_tmp_${entryName.replace(/\\W/g, '_')}`)\n const absTempDir = join(process.cwd(), tempDir)\n\n try {\n // Build into isolated temp directory\n const tempOutput = { ...output, dir: tempDir }\n await build({ inputOptions: input, outputOptions: tempOutput })\n\n // Find the largest .d.ts file — that's the real declarations\n const dtsFiles = readdirSync(absTempDir).filter((f) => f.endsWith('.d.ts'))\n\n let bestFile = dtsFiles[0] || entryName\n let bestSize = 0\n for (const f of dtsFiles) {\n const size = statSync(join(absTempDir, f)).size\n if (size > bestSize) {\n bestSize = size\n bestFile = f\n }\n }\n\n // Move the best file to the final location\n const absFinalDir = join(process.cwd(), finalDir)\n mkdirSync(absFinalDir, { recursive: true })\n renameSync(join(absTempDir, bestFile), join(absFinalDir, entryName))\n\n // Move sourcemap if it exists\n const mapName = `${bestFile}.map`\n try {\n renameSync(\n join(absTempDir, mapName),\n join(absFinalDir, `${entryName}.map`),\n )\n } catch {\n // sourcemap may not exist\n }\n } finally {\n // Always remove the temp dir — even if the build or a post-step\n // throws — so a partial failure can't leak __dts_tmp_* into lib/.\n rmSync(absTempDir, { recursive: true, force: true })\n }\n}\n\nconst generateDeclarations = async () => {\n const dtsConfigs = buildAllDts()\n if (dtsConfigs.length === 0) return\n\n log(`\\n${dim('Generating')} declarations...`)\n\n for (const dtsFile of dtsConfigs) {\n const tscStart = performance.now()\n await buildDtsIsolated(dtsFile)\n\n const tscDuration = Math.round(performance.now() - tscStart)\n log(\n ` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(dtsFile.file)} ${dim(`(${tscDuration}ms)`)}`,\n )\n }\n}\n\nconst runBuild = async () => {\n const start = performance.now()\n\n log(\n `\\n${label('rolldown')} ${bold(PKG.name || '')} ${dim(`v${PKG.version || '0.0.0'}`)}\\n`,\n )\n\n log(`${dim('Cleaning')} ${CONFIG.outputDir}/`)\n rmSync(`${process.cwd()}/${CONFIG.outputDir}`, {\n recursive: true,\n force: true,\n })\n\n log(\n `${dim('Building')} ${bold(String(allBuildsCount))} bundle${allBuildsCount > 1 ? 's' : ''}...\\n`,\n )\n\n await createBuilds()\n copyStaticFiles()\n await generateDeclarations()\n\n const total = Math.round(performance.now() - start)\n log(`\\n${chalk.green('Done')} ${dim(`in ${total}ms`)}\\n`)\n}\n\nexport { runBuild }\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AAmQA,QAAA,MAAM,QAAQ,qBAuBb,CAAA;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/tools-rolldown",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -41,17 +41,16 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@vitus-labs/tools-core": "^2.
|
|
44
|
+
"@vitus-labs/tools-core": "^2.3.0",
|
|
45
45
|
"chalk": "^5.6.2",
|
|
46
|
-
"
|
|
47
|
-
"rolldown": "^
|
|
48
|
-
"rolldown-plugin-dts": "^0.23.2",
|
|
46
|
+
"rolldown": "^1.0.1",
|
|
47
|
+
"rolldown-plugin-dts": "^0.25.1",
|
|
49
48
|
"rollup-plugin-filesize": "^10.0.0",
|
|
50
49
|
"rollup-plugin-visualizer": "^7.0.1"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^25.
|
|
54
|
-
"@vitus-labs/tools-typescript": "^2.
|
|
52
|
+
"@types/node": "^25.8.0",
|
|
53
|
+
"@vitus-labs/tools-typescript": "^2.3.0",
|
|
55
54
|
"typescript": "^6.0.3"
|
|
56
55
|
}
|
|
57
56
|
}
|