tsdown 0.9.3 → 0.9.5
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/{config.d-DHsClbv0.d.ts → config.d-_qPbb_88.d.ts} +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +30 -4
- package/dist/{migrate-BB2Nt65I.js → migrate-C2JwD44Q.js} +1 -1
- package/dist/{options.d-CRAKIn7H.d.ts → options.d-v--gMr_a.d.ts} +37 -3
- package/dist/package-CIVaynpa.js +5 -0
- package/dist/{plugins-BvgcOKes.js → plugins-x9xHcxDm.js} +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +1 -1
- package/dist/run.js +4 -4
- package/package.json +2 -1
- package/dist/package-C_4Rg-Ho.js +0 -5
package/dist/config.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Options, ResolvedOptions, UserConfig } from "./options.d-
|
|
2
|
-
import { defineConfig$1 as defineConfig } from "./config.d-
|
|
1
|
+
import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig } from "./options.d-v--gMr_a.js";
|
|
2
|
+
import { defineConfig$1 as defineConfig } from "./config.d-_qPbb_88.js";
|
|
3
3
|
import Debug from "debug";
|
|
4
4
|
import { ConsolaInstance } from "consola";
|
|
5
5
|
|
|
@@ -24,4 +24,4 @@ declare const pkgRoot: string;
|
|
|
24
24
|
declare function buildSingle(config: ResolvedOptions): Promise<(() => Promise<void>) | undefined>;
|
|
25
25
|
|
|
26
26
|
//#endregion
|
|
27
|
-
export { Options, UserConfig, build, buildSingle, defineConfig, logger, pkgRoot };
|
|
27
|
+
export { BuildContext, Options, TsdownHooks, UserConfig, build, buildSingle, defineConfig, logger, pkgRoot };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { defineConfig } from "./config-yiJy1jd0.js";
|
|
2
|
-
import { ExternalPlugin, ReportPlugin, ShebangPlugin, debounce, fsExists, fsRemove, getPackageType, lowestCommonAncestor, normalizeFormat, readPackageJson, toArray } from "./plugins-
|
|
2
|
+
import { ExternalPlugin, ReportPlugin, ShebangPlugin, debounce, fsExists, fsRemove, getPackageType, lowestCommonAncestor, normalizeFormat, readPackageJson, toArray } from "./plugins-x9xHcxDm.js";
|
|
3
3
|
import { debug, logger, setSilent } from "./logger-Dt3D6T-U.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
+
import { blue, bold, dim, green, underline } from "ansis";
|
|
7
8
|
import { build as build$1 } from "rolldown";
|
|
8
9
|
import { transformPlugin } from "rolldown/experimental";
|
|
9
10
|
import { exec } from "tinyexec";
|
|
10
11
|
import { readdir, stat } from "node:fs/promises";
|
|
11
12
|
import Debug from "debug";
|
|
12
13
|
import { glob } from "tinyglobby";
|
|
14
|
+
import { createHooks } from "hookable";
|
|
13
15
|
import { findUp } from "find-up-simple";
|
|
14
|
-
import { blue, bold, dim, underline } from "ansis";
|
|
15
16
|
import readline from "node:readline";
|
|
16
17
|
import { loadConfig } from "unconfig";
|
|
17
18
|
|
|
@@ -31,6 +32,23 @@ async function cleanOutDir(cwd, patterns) {
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/features/hooks.ts
|
|
37
|
+
async function createHooks$1(options, pkg) {
|
|
38
|
+
const hooks = createHooks();
|
|
39
|
+
if (typeof options.hooks === "object") hooks.addHooks(options.hooks);
|
|
40
|
+
else if (typeof options.hooks === "function") await options.hooks(hooks);
|
|
41
|
+
const context = {
|
|
42
|
+
options,
|
|
43
|
+
pkg,
|
|
44
|
+
hooks
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
hooks,
|
|
48
|
+
context
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
34
52
|
//#endregion
|
|
35
53
|
//#region src/features/output.ts
|
|
36
54
|
function resolveJsOutputExtension(packageType, format, fixedExtension) {
|
|
@@ -409,16 +427,23 @@ async function buildSingle(config) {
|
|
|
409
427
|
const { outDir, format: formats, clean, dts, watch, onSuccess } = config;
|
|
410
428
|
let onSuccessCleanup;
|
|
411
429
|
const pkg = await readPackageJson(process.cwd());
|
|
430
|
+
const { hooks, context } = await createHooks$1(config);
|
|
412
431
|
await rebuild(true);
|
|
413
432
|
if (watch) return () => rebuild();
|
|
414
433
|
async function rebuild(first) {
|
|
415
434
|
const startTime = performance.now();
|
|
435
|
+
await hooks.callHook("build:prepare", context);
|
|
416
436
|
onSuccessCleanup?.();
|
|
417
437
|
if (clean) await cleanOutDir(outDir, clean);
|
|
418
438
|
let hasErrors = false;
|
|
419
439
|
await Promise.all(formats.map(async (format) => {
|
|
420
440
|
try {
|
|
421
|
-
|
|
441
|
+
const buildOptions = await getBuildOptions(config, pkg, format);
|
|
442
|
+
await hooks.callHook("build:before", {
|
|
443
|
+
...context,
|
|
444
|
+
buildOptions
|
|
445
|
+
});
|
|
446
|
+
await build$1(buildOptions);
|
|
422
447
|
if (format === "cjs" && dts) await build$1(await getBuildOptions(config, pkg, format, true));
|
|
423
448
|
} catch (error) {
|
|
424
449
|
if (watch) {
|
|
@@ -430,9 +455,10 @@ async function buildSingle(config) {
|
|
|
430
455
|
}
|
|
431
456
|
}));
|
|
432
457
|
if (hasErrors) return;
|
|
458
|
+
await hooks.callHook("build:done", context);
|
|
433
459
|
if (config.publint) if (pkg) await publint(pkg);
|
|
434
460
|
else logger.warn("publint is enabled but package.json is not found");
|
|
435
|
-
logger.success(`${first ? "Build" : "Rebuild"} complete in ${Math.round(performance.now() - startTime)}ms`);
|
|
461
|
+
logger.success(`${first ? "Build" : "Rebuild"} complete in ${green(`${Math.round(performance.now() - startTime)}ms`)}`);
|
|
436
462
|
if (typeof onSuccess === "string") {
|
|
437
463
|
const p = exec(onSuccess, [], { nodeOptions: {
|
|
438
464
|
shell: true,
|
|
@@ -1,9 +1,42 @@
|
|
|
1
|
-
import { ExternalOption, InputOption, InputOptions, InternalModuleFormat, ModuleFormat, OutputOptions } from "rolldown";
|
|
1
|
+
import { BuildOptions, ExternalOption, InputOption, InputOptions, InternalModuleFormat, ModuleFormat, OutputOptions } from "rolldown";
|
|
2
|
+
import { Hookable } from "hookable";
|
|
2
3
|
import { Options } from "publint";
|
|
3
4
|
import { Options as Options$1 } from "rolldown-plugin-dts";
|
|
4
5
|
import { Options as Options$2 } from "unplugin-unused";
|
|
5
6
|
import { PackageJson } from "pkg-types";
|
|
6
7
|
|
|
8
|
+
//#region src/features/hooks.d.ts
|
|
9
|
+
interface BuildContext {
|
|
10
|
+
options: ResolvedOptions;
|
|
11
|
+
pkg?: PackageJson;
|
|
12
|
+
hooks: Hookable<TsdownHooks>;
|
|
13
|
+
}
|
|
14
|
+
interface RolldownContext {
|
|
15
|
+
buildOptions: BuildOptions;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Hooks for tsdown.
|
|
19
|
+
*/
|
|
20
|
+
interface TsdownHooks {
|
|
21
|
+
/**
|
|
22
|
+
* Invoked before each tsdown build starts.
|
|
23
|
+
* Use this hook to perform setup or preparation tasks.
|
|
24
|
+
*/
|
|
25
|
+
"build:prepare": (ctx: BuildContext) => void | Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Invoked before each Rolldown build.
|
|
28
|
+
* For dual-format builds, this hook is called for each format.
|
|
29
|
+
* Useful for configuring or modifying the build context before bundling.
|
|
30
|
+
*/
|
|
31
|
+
"build:before": (ctx: BuildContext & RolldownContext) => void | Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Invoked after each tsdown build completes.
|
|
34
|
+
* Use this hook for cleanup or post-processing tasks.
|
|
35
|
+
*/
|
|
36
|
+
"build:done": (ctx: BuildContext) => void | Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
7
40
|
//#region src/utils/package.d.ts
|
|
8
41
|
type PackageType = "module" | "commonjs" | undefined;
|
|
9
42
|
|
|
@@ -116,13 +149,14 @@ interface Options$3 {
|
|
|
116
149
|
* @default true
|
|
117
150
|
*/
|
|
118
151
|
report?: boolean;
|
|
152
|
+
hooks?: Partial<TsdownHooks> | ((hooks: Hookable<TsdownHooks>) => Awaitable<void>);
|
|
119
153
|
}
|
|
120
154
|
/**
|
|
121
155
|
* Options without specifying config file path.
|
|
122
156
|
*/
|
|
123
157
|
type UserConfig = Arrayable<Omit<Options$3, "config">>;
|
|
124
158
|
type NormalizedFormat = Exclude<InternalModuleFormat, "app"> | "experimental-app";
|
|
125
|
-
type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "dts" | "fixedExtension" | "outExtensions">, {
|
|
159
|
+
type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "dts" | "fixedExtension" | "outExtensions" | "hooks">, {
|
|
126
160
|
format: NormalizedFormat[]
|
|
127
161
|
clean: string[] | false
|
|
128
162
|
dts: false | Options$1
|
|
@@ -131,4 +165,4 @@ type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inp
|
|
|
131
165
|
}>, "config" | "fromVite">;
|
|
132
166
|
|
|
133
167
|
//#endregion
|
|
134
|
-
export { Options$3 as Options, ResolvedOptions, UserConfig };
|
|
168
|
+
export { BuildContext, Options$3 as Options, ResolvedOptions, TsdownHooks, UserConfig };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { debug, logger } from "./logger-Dt3D6T-U.js";
|
|
2
2
|
import path, { dirname, normalize, sep } from "node:path";
|
|
3
|
+
import { blue, bold, dim, green, underline, yellow } from "ansis";
|
|
3
4
|
import { access, chmod, readFile, rm } from "node:fs/promises";
|
|
4
5
|
import Debug from "debug";
|
|
5
6
|
import { findUp } from "find-up-simple";
|
|
6
7
|
import { Buffer } from "node:buffer";
|
|
7
8
|
import { promisify } from "node:util";
|
|
8
9
|
import { brotliCompress, gzip } from "node:zlib";
|
|
9
|
-
import { blue, bold, dim, green, underline, yellow } from "ansis";
|
|
10
10
|
|
|
11
11
|
//#region src/utils/fs.ts
|
|
12
12
|
function fsExists(path$1) {
|
package/dist/plugins.d.ts
CHANGED
package/dist/plugins.js
CHANGED
package/dist/run.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { logger, setSilent } from "./logger-Dt3D6T-U.js";
|
|
3
|
-
import { version } from "./package-
|
|
3
|
+
import { version } from "./package-CIVaynpa.js";
|
|
4
4
|
import process from "node:process";
|
|
5
|
-
import { VERSION } from "rolldown";
|
|
6
5
|
import { dim } from "ansis";
|
|
6
|
+
import { VERSION } from "rolldown";
|
|
7
7
|
import { cac } from "cac";
|
|
8
8
|
|
|
9
9
|
//#region src/cli.ts
|
|
10
10
|
const cli = cac("tsdown");
|
|
11
11
|
cli.help().version(version);
|
|
12
|
-
cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory").option("--minify", "Minify output").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("--silent", "Suppress non-error logs").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--dts", "Generate dts files", { default: false }).option("--publint", "Enable publint", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).action(async (input, flags) => {
|
|
12
|
+
cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("--silent", "Suppress non-error logs").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--dts", "Generate dts files", { default: false }).option("--publint", "Enable publint", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).action(async (input, flags) => {
|
|
13
13
|
setSilent(!!flags.silent);
|
|
14
14
|
logger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
|
|
15
15
|
const { build: build$1 } = await import("./index.js");
|
|
@@ -17,7 +17,7 @@ cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).op
|
|
|
17
17
|
await build$1(flags);
|
|
18
18
|
});
|
|
19
19
|
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
20
|
-
const { migrate } = await import("./migrate-
|
|
20
|
+
const { migrate } = await import("./migrate-C2JwD44Q.js");
|
|
21
21
|
await migrate(args);
|
|
22
22
|
});
|
|
23
23
|
async function runCLI() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "The Elegant Bundler for Libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"debug": "^4.4.0",
|
|
62
62
|
"diff": "^7.0.0",
|
|
63
63
|
"find-up-simple": "^1.0.1",
|
|
64
|
+
"hookable": "^5.5.3",
|
|
64
65
|
"rolldown": "1.0.0-beta.8-commit.d984417",
|
|
65
66
|
"rolldown-plugin-dts": "^0.8.3",
|
|
66
67
|
"tinyexec": "^1.0.1",
|