tsdown 0.5.0 → 0.5.2
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/index.d.ts +1 -1
- package/dist/index.js +66 -55
- package/dist/run.js +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ interface Options {
|
|
|
52
52
|
*/
|
|
53
53
|
unused?: boolean | Options$2;
|
|
54
54
|
watch?: boolean | string | string[];
|
|
55
|
-
inputOptions?: InputOptions;
|
|
55
|
+
inputOptions?: InputOptions | ((options: InputOptions, format: ModuleFormat) => MaybePromise<InputOptions | void | null>);
|
|
56
56
|
outputOptions?: OutputOptions | ((options: OutputOptions, format: ModuleFormat) => MaybePromise<OutputOptions | void | null>);
|
|
57
57
|
onSuccess?: () => void | Promise<void>;
|
|
58
58
|
/**
|
package/dist/index.js
CHANGED
|
@@ -58,12 +58,35 @@ async function cleanOutDir(cwd, patterns) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/utils/general.ts
|
|
63
|
+
function toArray(val, defaultValue) {
|
|
64
|
+
if (Array.isArray(val)) return val;
|
|
65
|
+
else if (val == null) {
|
|
66
|
+
if (defaultValue) return [defaultValue];
|
|
67
|
+
return [];
|
|
68
|
+
} else return [val];
|
|
69
|
+
}
|
|
70
|
+
function debounce(fn, wait) {
|
|
71
|
+
let timeout;
|
|
72
|
+
return function(...args) {
|
|
73
|
+
if (timeout) clearTimeout(timeout);
|
|
74
|
+
timeout = setTimeout(() => {
|
|
75
|
+
timeout = undefined;
|
|
76
|
+
fn.apply(this, args);
|
|
77
|
+
}, wait);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
61
81
|
//#endregion
|
|
62
82
|
//#region src/features/dts.ts
|
|
63
83
|
const TEMP_DTS_DIR = ".tsdown-types";
|
|
64
|
-
|
|
84
|
+
function getTempDtsDir(format) {
|
|
85
|
+
return `${TEMP_DTS_DIR}-${format}`;
|
|
86
|
+
}
|
|
87
|
+
async function bundleDts(options, jsExtension, format) {
|
|
65
88
|
const ext = jsExtension.replace("j", "t");
|
|
66
|
-
const dtsOutDir = path$5.resolve(options.outDir,
|
|
89
|
+
const dtsOutDir = path$5.resolve(options.outDir, getTempDtsDir(format));
|
|
67
90
|
const dtsEntry = Object.fromEntries(Object.keys(options.entry).map((key) => [key, path$5.resolve(dtsOutDir, `${key}.d.${ext}`)]));
|
|
68
91
|
const build$2 = await rollup({
|
|
69
92
|
input: dtsEntry,
|
|
@@ -80,7 +103,10 @@ async function bundleDts(options, jsExtension) {
|
|
|
80
103
|
format: "es",
|
|
81
104
|
entryFileNames: `[name].d.${ext}`
|
|
82
105
|
});
|
|
83
|
-
await rm(dtsOutDir, {
|
|
106
|
+
await rm(dtsOutDir, {
|
|
107
|
+
recursive: true,
|
|
108
|
+
force: true
|
|
109
|
+
}).catch(() => {});
|
|
84
110
|
}
|
|
85
111
|
|
|
86
112
|
//#endregion
|
|
@@ -174,33 +200,15 @@ function shortcuts(restart) {
|
|
|
174
200
|
rl.on("line", onInput);
|
|
175
201
|
}
|
|
176
202
|
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region src/utils/general.ts
|
|
179
|
-
function toArray(val, defaultValue) {
|
|
180
|
-
if (Array.isArray(val)) return val;
|
|
181
|
-
else if (val == null) {
|
|
182
|
-
if (defaultValue) return [defaultValue];
|
|
183
|
-
return [];
|
|
184
|
-
} else return [val];
|
|
185
|
-
}
|
|
186
|
-
function debounce(fn, wait) {
|
|
187
|
-
let timeout;
|
|
188
|
-
return function(...args) {
|
|
189
|
-
if (timeout) clearTimeout(timeout);
|
|
190
|
-
timeout = setTimeout(() => {
|
|
191
|
-
timeout = undefined;
|
|
192
|
-
fn.apply(this, args);
|
|
193
|
-
}, wait);
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
203
|
//#endregion
|
|
198
204
|
//#region src/features/watch.ts
|
|
199
|
-
|
|
205
|
+
const endsWithPackageJson = /[\\/]package\.json$/;
|
|
206
|
+
async function watchBuild(options, configFile, rebuild, restart) {
|
|
200
207
|
const { watch } = await import("chokidar");
|
|
201
208
|
const debouncedRebuild = debounce(rebuild, 100);
|
|
202
|
-
const files = typeof options.watch === "boolean" ? process$2.cwd() : options.watch;
|
|
203
|
-
logger.info(`Watching for changes in ${
|
|
209
|
+
const files = toArray(typeof options.watch === "boolean" ? process$2.cwd() : options.watch);
|
|
210
|
+
logger.info(`Watching for changes in ${files.join(", ")}`);
|
|
211
|
+
if (configFile) files.push(configFile);
|
|
204
212
|
const watcher = watch(files, {
|
|
205
213
|
ignoreInitial: true,
|
|
206
214
|
ignorePermissionErrors: true,
|
|
@@ -210,6 +218,11 @@ async function watchBuild(options, rebuild) {
|
|
|
210
218
|
}
|
|
211
219
|
});
|
|
212
220
|
watcher.on("all", (type, file) => {
|
|
221
|
+
if (endsWithPackageJson.test(file) || configFile === file) {
|
|
222
|
+
logger.info(`Reload config: ${file}`);
|
|
223
|
+
restart();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
213
226
|
logger.info(`Change detected: ${type} ${file}`);
|
|
214
227
|
debouncedRebuild();
|
|
215
228
|
});
|
|
@@ -325,6 +338,13 @@ async function loadConfigFile(options) {
|
|
|
325
338
|
const file = sources[0];
|
|
326
339
|
return [toArray(config), file];
|
|
327
340
|
}
|
|
341
|
+
async function mergeUserOptions(defaults, user, args) {
|
|
342
|
+
const userOutputOptions = typeof user === "function" ? await user(defaults, ...args) : user;
|
|
343
|
+
return {
|
|
344
|
+
...defaults,
|
|
345
|
+
...userOutputOptions
|
|
346
|
+
};
|
|
347
|
+
}
|
|
328
348
|
|
|
329
349
|
//#endregion
|
|
330
350
|
//#region src/index.ts
|
|
@@ -338,13 +358,14 @@ else debug("No config file found");
|
|
|
338
358
|
for (const [i, resolved] of resolveds.entries()) {
|
|
339
359
|
const rebuild = rebuilds[i];
|
|
340
360
|
if (!rebuild) continue;
|
|
341
|
-
const watcher = await watchBuild(resolved, rebuild);
|
|
361
|
+
const watcher = await watchBuild(resolved, configFile, rebuild, restart);
|
|
342
362
|
cleanCbs.push(() => watcher.close());
|
|
343
363
|
}
|
|
344
|
-
if (cleanCbs.length) shortcuts(
|
|
364
|
+
if (cleanCbs.length) shortcuts(restart);
|
|
365
|
+
async function restart() {
|
|
345
366
|
for (const clean of cleanCbs) await clean();
|
|
346
367
|
build(userOptions);
|
|
347
|
-
}
|
|
368
|
+
}
|
|
348
369
|
}
|
|
349
370
|
const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
350
371
|
const pkgRoot = path.resolve(dirname$1, "..");
|
|
@@ -356,33 +377,28 @@ async function buildSingle(resolved) {
|
|
|
356
377
|
if (watch) return () => rebuild();
|
|
357
378
|
async function rebuild(first) {
|
|
358
379
|
const startTime = performance.now();
|
|
359
|
-
const plugins = [
|
|
360
|
-
pkg && ExternalPlugin(pkg, resolved.skipNodeModulesBundle),
|
|
361
|
-
unused && Unused.rolldown(unused === true ? {} : unused),
|
|
362
|
-
dts && IsolatedDecl.rolldown({
|
|
363
|
-
...dts,
|
|
364
|
-
extraOutdir: resolved.bundleDts ? TEMP_DTS_DIR : dts.extraOutdir
|
|
365
|
-
}),
|
|
366
|
-
target && transformPlugin({ target: target && (typeof target === "string" ? target : target.join(",")) }),
|
|
367
|
-
userPlugins
|
|
368
|
-
].filter((plugin) => !!plugin);
|
|
369
380
|
await Promise.all(format.map(async (format$1) => {
|
|
370
|
-
const inputOptions = {
|
|
381
|
+
const inputOptions = await mergeUserOptions({
|
|
371
382
|
input: entry,
|
|
372
383
|
external,
|
|
373
384
|
resolve: { alias },
|
|
374
385
|
treeshake,
|
|
375
386
|
platform,
|
|
376
387
|
define,
|
|
377
|
-
plugins
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
388
|
+
plugins: [
|
|
389
|
+
pkg && ExternalPlugin(pkg, resolved.skipNodeModulesBundle),
|
|
390
|
+
unused && Unused.rolldown(unused === true ? {} : unused),
|
|
391
|
+
dts && IsolatedDecl.rolldown({
|
|
392
|
+
...dts,
|
|
393
|
+
extraOutdir: resolved.bundleDts ? getTempDtsDir(format$1) : dts.extraOutdir
|
|
394
|
+
}),
|
|
395
|
+
target && transformPlugin({ target: target && (typeof target === "string" ? target : target.join(",")) }),
|
|
396
|
+
userPlugins
|
|
397
|
+
].filter((plugin) => !!plugin),
|
|
398
|
+
inject: { ...shims && getShimsInject(format$1, platform) }
|
|
399
|
+
}, resolved.inputOptions, [format$1]);
|
|
384
400
|
const extension = resolveOutputExtension(pkg, format$1);
|
|
385
|
-
|
|
401
|
+
const outputOptions = await mergeUserOptions({
|
|
386
402
|
format: format$1,
|
|
387
403
|
name: resolved.globalName,
|
|
388
404
|
sourcemap,
|
|
@@ -390,17 +406,12 @@ async function buildSingle(resolved) {
|
|
|
390
406
|
minify,
|
|
391
407
|
entryFileNames: `[name].${extension}`,
|
|
392
408
|
chunkFileNames: `[name]-[hash].${extension}`
|
|
393
|
-
};
|
|
394
|
-
const userOutputOptions = typeof resolved.outputOptions === "function" ? await resolved.outputOptions(outputOptions, format$1) : resolved.outputOptions;
|
|
395
|
-
outputOptions = {
|
|
396
|
-
...outputOptions,
|
|
397
|
-
...userOutputOptions
|
|
398
|
-
};
|
|
409
|
+
}, resolved.outputOptions, [format$1]);
|
|
399
410
|
await build$1({
|
|
400
411
|
...inputOptions,
|
|
401
412
|
output: outputOptions
|
|
402
413
|
});
|
|
403
|
-
if (resolved.dts && resolved.bundleDts) await bundleDts(resolved, extension);
|
|
414
|
+
if (resolved.dts && resolved.bundleDts) await bundleDts(resolved, extension, format$1);
|
|
404
415
|
}));
|
|
405
416
|
logger.success(`${first ? "Build" : "Rebuild"} complete in ${Math.round(performance.now() - startTime)}ms`);
|
|
406
417
|
await onSuccess?.();
|
package/dist/run.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "An even faster bundler powered by Rolldown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"tsup": "^8.3.5",
|
|
69
69
|
"tsx": "^4.19.2",
|
|
70
70
|
"typescript": "~5.7.2",
|
|
71
|
+
"unplugin-ast": "^0.13.1",
|
|
71
72
|
"vitest": "^2.2.0-beta.2"
|
|
72
73
|
},
|
|
73
74
|
"engines": {
|