tsdown 0.5.0 → 0.5.1
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 +30 -21
- package/dist/run.js +1 -1
- package/package.json +1 -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
|
@@ -80,7 +80,10 @@ async function bundleDts(options, jsExtension) {
|
|
|
80
80
|
format: "es",
|
|
81
81
|
entryFileNames: `[name].d.${ext}`
|
|
82
82
|
});
|
|
83
|
-
await rm(dtsOutDir, {
|
|
83
|
+
await rm(dtsOutDir, {
|
|
84
|
+
recursive: true,
|
|
85
|
+
force: true
|
|
86
|
+
});
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
//#endregion
|
|
@@ -196,11 +199,13 @@ function debounce(fn, wait) {
|
|
|
196
199
|
|
|
197
200
|
//#endregion
|
|
198
201
|
//#region src/features/watch.ts
|
|
199
|
-
|
|
202
|
+
const endsWithPackageJson = /[\\/]package\.json$/;
|
|
203
|
+
async function watchBuild(options, configFile, rebuild, restart) {
|
|
200
204
|
const { watch } = await import("chokidar");
|
|
201
205
|
const debouncedRebuild = debounce(rebuild, 100);
|
|
202
|
-
const files = typeof options.watch === "boolean" ? process$2.cwd() : options.watch;
|
|
203
|
-
logger.info(`Watching for changes in ${
|
|
206
|
+
const files = toArray(typeof options.watch === "boolean" ? process$2.cwd() : options.watch);
|
|
207
|
+
logger.info(`Watching for changes in ${files.join(", ")}`);
|
|
208
|
+
if (configFile) files.push(configFile);
|
|
204
209
|
const watcher = watch(files, {
|
|
205
210
|
ignoreInitial: true,
|
|
206
211
|
ignorePermissionErrors: true,
|
|
@@ -210,6 +215,11 @@ async function watchBuild(options, rebuild) {
|
|
|
210
215
|
}
|
|
211
216
|
});
|
|
212
217
|
watcher.on("all", (type, file) => {
|
|
218
|
+
if (endsWithPackageJson.test(file) || configFile === file) {
|
|
219
|
+
logger.info(`Reload config: ${file}`);
|
|
220
|
+
restart();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
213
223
|
logger.info(`Change detected: ${type} ${file}`);
|
|
214
224
|
debouncedRebuild();
|
|
215
225
|
});
|
|
@@ -325,6 +335,13 @@ async function loadConfigFile(options) {
|
|
|
325
335
|
const file = sources[0];
|
|
326
336
|
return [toArray(config), file];
|
|
327
337
|
}
|
|
338
|
+
async function mergeUserOptions(defaults, user, args) {
|
|
339
|
+
const userOutputOptions = typeof user === "function" ? await user(defaults, ...args) : user;
|
|
340
|
+
return {
|
|
341
|
+
...defaults,
|
|
342
|
+
...userOutputOptions
|
|
343
|
+
};
|
|
344
|
+
}
|
|
328
345
|
|
|
329
346
|
//#endregion
|
|
330
347
|
//#region src/index.ts
|
|
@@ -338,13 +355,14 @@ else debug("No config file found");
|
|
|
338
355
|
for (const [i, resolved] of resolveds.entries()) {
|
|
339
356
|
const rebuild = rebuilds[i];
|
|
340
357
|
if (!rebuild) continue;
|
|
341
|
-
const watcher = await watchBuild(resolved, rebuild);
|
|
358
|
+
const watcher = await watchBuild(resolved, configFile, rebuild, restart);
|
|
342
359
|
cleanCbs.push(() => watcher.close());
|
|
343
360
|
}
|
|
344
|
-
if (cleanCbs.length) shortcuts(
|
|
361
|
+
if (cleanCbs.length) shortcuts(restart);
|
|
362
|
+
async function restart() {
|
|
345
363
|
for (const clean of cleanCbs) await clean();
|
|
346
364
|
build(userOptions);
|
|
347
|
-
}
|
|
365
|
+
}
|
|
348
366
|
}
|
|
349
367
|
const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
350
368
|
const pkgRoot = path.resolve(dirname$1, "..");
|
|
@@ -367,7 +385,7 @@ async function buildSingle(resolved) {
|
|
|
367
385
|
userPlugins
|
|
368
386
|
].filter((plugin) => !!plugin);
|
|
369
387
|
await Promise.all(format.map(async (format$1) => {
|
|
370
|
-
const inputOptions = {
|
|
388
|
+
const inputOptions = await mergeUserOptions({
|
|
371
389
|
input: entry,
|
|
372
390
|
external,
|
|
373
391
|
resolve: { alias },
|
|
@@ -375,14 +393,10 @@ async function buildSingle(resolved) {
|
|
|
375
393
|
platform,
|
|
376
394
|
define,
|
|
377
395
|
plugins,
|
|
378
|
-
...
|
|
379
|
-
|
|
380
|
-
...shims && getShimsInject(format$1, platform),
|
|
381
|
-
...resolved.inputOptions?.inject
|
|
382
|
-
}
|
|
383
|
-
};
|
|
396
|
+
inject: { ...shims && getShimsInject(format$1, platform) }
|
|
397
|
+
}, resolved.inputOptions, [format$1]);
|
|
384
398
|
const extension = resolveOutputExtension(pkg, format$1);
|
|
385
|
-
|
|
399
|
+
const outputOptions = await mergeUserOptions({
|
|
386
400
|
format: format$1,
|
|
387
401
|
name: resolved.globalName,
|
|
388
402
|
sourcemap,
|
|
@@ -390,12 +404,7 @@ async function buildSingle(resolved) {
|
|
|
390
404
|
minify,
|
|
391
405
|
entryFileNames: `[name].${extension}`,
|
|
392
406
|
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
|
-
};
|
|
407
|
+
}, resolved.outputOptions, [format$1]);
|
|
399
408
|
await build$1({
|
|
400
409
|
...inputOptions,
|
|
401
410
|
output: outputOptions
|
package/dist/run.js
CHANGED