tsdown 0.9.4 → 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.
@@ -1,4 +1,4 @@
1
- import { UserConfig } from "./options.d-CRAKIn7H.js";
1
+ import { UserConfig } from "./options.d-v--gMr_a.js";
2
2
 
3
3
  //#region src/config.d.ts
4
4
  /**
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import "./options.d-CRAKIn7H.js";
2
- import { defineConfig$1 as defineConfig } from "./config.d-DHsClbv0.js";
1
+ import "./options.d-v--gMr_a.js";
2
+ import { defineConfig$1 as defineConfig } from "./config.d-_qPbb_88.js";
3
3
 
4
4
  export { defineConfig };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Options, ResolvedOptions, UserConfig } from "./options.d-CRAKIn7H.js";
2
- import { defineConfig$1 as defineConfig } from "./config.d-DHsClbv0.js";
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
@@ -11,6 +11,7 @@ import { exec } from "tinyexec";
11
11
  import { readdir, stat } from "node:fs/promises";
12
12
  import Debug from "debug";
13
13
  import { glob } from "tinyglobby";
14
+ import { createHooks } from "hookable";
14
15
  import { findUp } from "find-up-simple";
15
16
  import readline from "node:readline";
16
17
  import { loadConfig } from "unconfig";
@@ -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
- await build$1(await getBuildOptions(config, pkg, format));
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,6 +455,7 @@ 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
461
  logger.success(`${first ? "Build" : "Rebuild"} complete in ${green(`${Math.round(performance.now() - startTime)}ms`)}`);
@@ -1,4 +1,4 @@
1
- import { version } from "./package-BgsbkBlA.js";
1
+ import { version } from "./package-CIVaynpa.js";
2
2
  import process from "node:process";
3
3
  import { readFile, unlink, writeFile } from "node:fs/promises";
4
4
  import consola$1 from "consola";
@@ -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 };
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.9.5";
3
+
4
+ //#endregion
5
+ export { version };
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ResolvedOptions } from "./options.d-CRAKIn7H.js";
1
+ import { ResolvedOptions } from "./options.d-v--gMr_a.js";
2
2
  import { Plugin } from "rolldown";
3
3
  import { PackageJson } from "pkg-types";
4
4
 
package/dist/run.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { logger, setSilent } from "./logger-Dt3D6T-U.js";
3
- import { version } from "./package-BgsbkBlA.js";
3
+ import { version } from "./package-CIVaynpa.js";
4
4
  import process from "node:process";
5
5
  import { dim } from "ansis";
6
6
  import { VERSION } from "rolldown";
@@ -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-DRASxtab.js");
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.4",
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",
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.9.4";
3
-
4
- //#endregion
5
- export { version };