@d1g1tal/tsbuild 1.4.1 → 1.6.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/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  [![Node.js](https://img.shields.io/node/v/@d1g1tal/tsbuild)](https://nodejs.org)
9
9
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
10
10
 
11
- A TypeScript build tool that combines three tools into one workflow: **TypeScript's type system** for correctness, **esbuild** for speed, and **SWC** for legacy decorator metadata (optional, not installed by default). Built for modern ESM-only projects on Node.js 20.16.0+.
11
+ A TypeScript build tool that combines three tools into one workflow: **TypeScript's type system** for correctness, **esbuild** for speed, and **SWC** for legacy decorator metadata (optional, not installed by default). Built for modern ESM-only projects on Node.js 22+.
12
12
 
13
13
  TC39 standard decorators are supported natively — no additional dependencies needed. SWC is only required if you are still using `experimentalDecorators` with `emitDecoratorMetadata`.
14
14
 
@@ -42,6 +42,46 @@ The build runs in two phases:
42
42
 
43
43
  If `declaration` is not enabled, phase 2 is just the esbuild step.
44
44
 
45
+ ## Installation
46
+
47
+ ### Global Installation (Recommended for CLI usage)
48
+
49
+ Installing globally makes the `tsbuild` command available in your terminal across all projects:
50
+
51
+ ```bash
52
+ # pnpm
53
+ pnpm add -g @d1g1tal/tsbuild
54
+
55
+ # npm
56
+ npm install -g @d1g1tal/tsbuild
57
+ ```
58
+
59
+ With a global install, your projects can use `tsbuild` in `package.json` scripts without adding it as a dependency.
60
+
61
+ ### Local Installation (Per-project)
62
+
63
+ Install as a dev dependency for per-project version pinning (recommended for CI/CD environments):
64
+
65
+ ```bash
66
+ # pnpm
67
+ pnpm add -D @d1g1tal/tsbuild
68
+
69
+ # npm
70
+ npm install -D @d1g1tal/tsbuild
71
+
72
+ # yarn
73
+ yarn add -D @d1g1tal/tsbuild
74
+ ```
75
+
76
+ `@swc/core` is **not a dependency** and will never be installed automatically. It is only needed if you use `experimentalDecorators` with `emitDecoratorMetadata` — see [Decorator Metadata](#decorator-metadata) for details.
77
+
78
+ > **Note:** When installed only as a local dev dependency, the `tsbuild` command is not available directly in your terminal. Use it through `package.json` scripts (e.g., `pnpm build`) or invoke it explicitly with `pnpm exec tsbuild` / `npx tsbuild`.
79
+
80
+ ### Requirements
81
+
82
+ - **Node.js**: >=22.0.0
83
+ - **pnpm**: >=10.13.0 (if using corepack)
84
+
45
85
  ## Quick Start
46
86
 
47
87
  The only thing tsbuild requires in `tsconfig.json` is an `outDir`. Everything else carries over from your existing config.
@@ -141,47 +181,7 @@ Or if installed locally as a dev dependency, add a script to `package.json` and
141
181
  pnpm build
142
182
  ```
143
183
 
144
- That's it. tsbuild reads your `compilerOptions`, infers entry points from your `package.json`, and builds. See [Configuration Options](#configuration-options) for everything you can customise.
145
-
146
- ## Installation
147
-
148
- ### Global Installation (Recommended for CLI usage)
149
-
150
- Installing globally makes the `tsbuild` command available in your terminal across all projects:
151
-
152
- ```bash
153
- # pnpm
154
- pnpm add -g @d1g1tal/tsbuild
155
-
156
- # npm
157
- npm install -g @d1g1tal/tsbuild
158
- ```
159
-
160
- With a global install, your projects can use `tsbuild` in `package.json` scripts without adding it as a dependency.
161
-
162
- ### Local Installation (Per-project)
163
-
164
- Install as a dev dependency for per-project version pinning (recommended for CI/CD environments):
165
-
166
- ```bash
167
- # pnpm
168
- pnpm add -D @d1g1tal/tsbuild
169
-
170
- # npm
171
- npm install -D @d1g1tal/tsbuild
172
-
173
- # yarn
174
- yarn add -D @d1g1tal/tsbuild
175
- ```
176
-
177
- `@swc/core` is **not a dependency** and will never be installed automatically. It is only needed if you use `experimentalDecorators` with `emitDecoratorMetadata` — see [Decorator Metadata](#decorator-metadata) for details.
178
-
179
- > **Note:** When installed only as a local dev dependency, the `tsbuild` command is not available directly in your terminal. Use it through `package.json` scripts (e.g., `pnpm build`) or invoke it explicitly with `pnpm exec tsbuild` / `npx tsbuild`.
180
-
181
- ### Requirements
182
-
183
- - **Node.js**: >=20.16.0
184
- - **pnpm**: >=9.0.0
184
+ That's it. tsbuild reads your `compilerOptions`, infers entry points from your `package.json`, and builds. See [Configuration Options](#configuration-options) for everything you can customize.
185
185
 
186
186
  ## Usage
187
187
 
@@ -191,7 +191,7 @@ yarn add -D @d1g1tal/tsbuild
191
191
 
192
192
  Because tsbuild uses the TypeScript compiler API directly, it reads your `compilerOptions` automatically. There is no need to re-declare `target`, `module`, `lib`, `strict`, `paths`, `moduleResolution`, `baseUrl`, or any other TypeScript settings in a separate config — they are already in your `tsconfig.json`, and tsbuild honours them as-is.
193
193
 
194
- The `tsbuild` section only covers options that don't belong in `compilerOptions`: bundling behaviour, entry points, watch mode, output formatting, and similar build-specific settings.
194
+ The `tsbuild` section only covers options that don't belong in `compilerOptions`: bundling behavior, entry points, watch mode, output formatting, and similar build-specific settings.
195
195
 
196
196
  This means your type-checker and your build always use the exact same TypeScript configuration — no drift, no duplication.
197
197
 
@@ -202,7 +202,7 @@ Declaration generation is **not required**. If `declaration: true` is already se
202
202
 
203
203
  Everything else carries over automatically.
204
204
 
205
- Add a `tsbuild` property to your `tsconfig.json` with only the options you need to customise:
205
+ Add a `tsbuild` property to your `tsconfig.json` with only the options you need to customize:
206
206
 
207
207
  ```jsonc
208
208
  {
@@ -284,17 +284,17 @@ tsbuild uses two separate caches to speed up repeated builds, and two flags to c
284
284
 
285
285
  ### How it works
286
286
 
287
- Enable incremental compilation in `tsconfig.json`:
287
+ Incremental compilation is **enabled by default** — no configuration needed. To opt out, explicitly set `incremental: false` in `tsconfig.json`:
288
288
 
289
289
  ```jsonc
290
290
  {
291
291
  "compilerOptions": {
292
- "incremental": true
292
+ "incremental": false // disables TypeScript's .tsbuildinfo cache and tsbuild's DTS cache
293
293
  }
294
294
  }
295
295
  ```
296
296
 
297
- With this set, each build maintains two caches inside a `.tsbuild/` directory:
297
+ With incremental enabled, each build maintains two caches inside a `.tsbuild/` directory:
298
298
 
299
299
  | Cache | File | What it stores |
300
300
  |-------|------|----------------|
@@ -303,6 +303,20 @@ With this set, each build maintains two caches inside a `.tsbuild/` directory:
303
303
 
304
304
  On each build, TypeScript reads `.tsbuildinfo` to determine what changed and only re-emits those files. Changed `.d.ts` files overwrite their entries in the DTS cache; unchanged entries remain valid. If nothing changed, TypeScript skips emission entirely and the output phase is skipped too — this is why incremental rebuilds with no changes take ~5ms.
305
305
 
306
+ ### Ignoring the cache directory
307
+
308
+ The `.tsbuild/` directory contains build artifacts that should not be committed to source control. Add it to your `.gitignore`:
309
+
310
+ ```bash
311
+ echo '.tsbuild/' >> .gitignore
312
+ ```
313
+
314
+ Or add the entry manually:
315
+
316
+ ```gitignore
317
+ .tsbuild/
318
+ ```
319
+
306
320
  ### Flags
307
321
 
308
322
  **`--force` (`-f`)** — Runs the output phase (esbuild + DTS bundling) even when TypeScript detects no changes. Useful when something outside the source files changed (e.g. an environment variable or esbuild config) and you need to regenerate output without touching the caches.
@@ -336,7 +350,7 @@ If a directory is provided, all files within will be used as entry points.
336
350
 
337
351
  When `entryPoints` is omitted entirely, tsbuild automatically infers entry points from `package.json` by reverse-mapping output paths back to their source files. Resolution order:
338
352
 
339
- 1. **`exports`** - Subpath export map (wildcard patterns are skipped; `import`/`default` conditions are tried in order)
353
+ 1. **`exports`** - Subpath export map (wildcard patterns are skipped; `import`, `node`, `module`, and `default` conditions are tried in order)
340
354
  2. **`bin`** - Binary entry points
341
355
  3. **`main`** / **`module`** - Legacy fallback (only used when `exports` and `bin` produce no results)
342
356
 
@@ -510,7 +524,7 @@ When a circular dependency is detected between declaration files, tsbuild emits
510
524
 
511
525
  tsbuild is designed for speed:
512
526
 
513
- - **Incremental builds** - Only recompiles changed files
527
+ - **Incremental builds** - Only recompile changed files
514
528
  - **In-memory declarations** - No intermediate disk I/O for `.d.ts` files
515
529
  - **Parallel processing** - Declaration bundling and transpilation run in parallel after type checking completes
516
530
  - **Smart caching** - Leverages `.tsbuildinfo` for TypeScript incremental compilation
@@ -535,12 +549,12 @@ The TypeScript declaration bundling system was originally inspired by rollup-plu
535
549
  - **[TypeScript](https://www.typescriptlang.org/)** - Type checking, declaration generation, and module resolution
536
550
  - **[SWC](https://swc.rs/)** - Optional decorator metadata transformation
537
551
  - **[magic-string](https://github.com/Rich-Harris/magic-string)** - Efficient source code transformation with sourcemap support
538
- - **[watchr](https://github.com/bevry/watchr)** - File watching for watch mode
552
+ - **[watchr](https://github.com/D1g1talEntr0py/watchr)** - File watching for watch mode
539
553
 
540
554
  ## Limitations
541
555
 
542
556
  - **ESM Only** - No CommonJS support by design
543
- - **Node.js 20.16.0+** - Requires a modern Node.js version
557
+ - **Node.js 22+** - Requires a modern Node.js version
544
558
  - **Personal project** - Works well for my use cases, but hasn't been tested across every environment or edge case
545
559
  - **Plugins are programmatic only** - Custom esbuild plugins can't be declared in `tsconfig.json`; they require using the `TypeScriptProject` API directly
546
560
  - **tsBuildInfoFile Path Changes** - When changing the `tsBuildInfoFile` path in `tsconfig.json`, the old `.tsbuildinfo` file at the previous location will not be automatically cleaned up and must be manually removed
@@ -318,10 +318,12 @@ var Logger = class _Logger {
318
318
  }
319
319
  /**
320
320
  * Logs a header box with a message.
321
+ * The header is styled with a cyan border and the message is centered inside. ANSI escape codes are stripped from the message when calculating the width to ensure proper formatting.
322
+ * This ensures the header box is sized correctly even when the message contains color codes or other formatting.
321
323
  * @param message The message to display in the header.
322
324
  */
323
325
  static header(message) {
324
- const innerWidth = message.length + 2;
326
+ const innerWidth = message.replace(new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g"), "").length + 2;
325
327
  console.log(TextFormat.cyan(`\u256D${"\u2500".repeat(innerWidth)}\u256E${newLine}\u2502 ${message} \u2502${newLine}\u2570${"\u2500".repeat(innerWidth)}\u256F`));
326
328
  }
327
329
  /**
@@ -345,10 +347,14 @@ var Logger = class _Logger {
345
347
  * @param steps The sub-steps to log.
346
348
  */
347
349
  static subSteps(steps) {
348
- const maxNameLength = steps.reduce((max, { name }) => Math.max(max, name.length), 0);
349
- const maxDurationLength = steps.reduce((max, { duration }) => Math.max(max, duration.length), 0);
350
- for (let i = 0, length = steps.length; i < length; i++) {
351
- const { name, duration } = steps[i];
350
+ const visible = steps.filter(({ ms }) => ms >= 5);
351
+ if (visible.length === 0) {
352
+ return;
353
+ }
354
+ const maxNameLength = visible.reduce((max, { name }) => Math.max(max, name.length), 0);
355
+ const maxDurationLength = visible.reduce((max, { duration }) => Math.max(max, duration.length), 0);
356
+ for (let i = 0, length = visible.length; i < length; i++) {
357
+ const { name, duration } = visible[i];
352
358
  const prefix = i === length - 1 ? " \u2514\u2500" : " \u251C\u2500";
353
359
  console.log(`${TextFormat.dim(prefix)} ${TextFormat.bold(name.padEnd(maxNameLength))} ${TextFormat.cyan(duration.padStart(maxDurationLength))}`);
354
360
  }
@@ -1595,8 +1601,8 @@ _PerformanceLogger = __decorateElement(_init, 0, "PerformanceLogger", _Performan
1595
1601
  __runInitializers(_init, 1, _PerformanceLogger);
1596
1602
  var PerformanceLogger = _PerformanceLogger;
1597
1603
  var measure = new PerformanceLogger().measure;
1598
- function addPerformanceStep(name, duration) {
1599
- pendingSteps.push({ name, duration });
1604
+ function addPerformanceStep(name, ms) {
1605
+ pendingSteps.push({ name, duration: `${ms}ms`, ms });
1600
1606
  }
1601
1607
 
1602
1608
  // src/decorators/debounce.ts
@@ -1831,9 +1837,9 @@ var FileManager = class {
1831
1837
  this.pendingBuildInfo = { path: filePath, text };
1832
1838
  } else {
1833
1839
  this.pendingFiles.push({ path: filePath, text });
1834
- }
1835
- if (!this.hasEmittedFiles) {
1836
- this.hasEmittedFiles = true;
1840
+ if (!this.hasEmittedFiles) {
1841
+ this.hasEmittedFiles = true;
1842
+ }
1837
1843
  }
1838
1844
  };
1839
1845
  /**
@@ -2059,7 +2065,7 @@ var globCharacters = /[*?\\[\]!].*$/;
2059
2065
  var domPredicate = (lib) => lib.toUpperCase() === "DOM";
2060
2066
  var diagnosticsHost = { getNewLine: () => sys2.newLine, getCurrentDirectory: sys2.getCurrentDirectory, getCanonicalFileName: (fileName) => fileName };
2061
2067
  var _triggerRebuild_dec, _processDeclarations_dec, _transpile_dec, _typeCheck_dec, _build_dec, _TypeScriptProject_decorators, _init3;
2062
- _TypeScriptProject_decorators = [closeOnExit], _build_dec = [measure("Build")], _typeCheck_dec = [measure("Type-checking")], _transpile_dec = [measure("Transpile", true)], _processDeclarations_dec = [measure("Process Declarations", true)], _triggerRebuild_dec = [debounce(100)];
2068
+ _TypeScriptProject_decorators = [closeOnExit], _build_dec = [measure("Build")], _typeCheck_dec = [measure("Type-checking")], _transpile_dec = [measure("Transpile", true)], _processDeclarations_dec = [measure("Bundle Declarations", true)], _triggerRebuild_dec = [debounce(100)];
2063
2069
  var _TypeScriptProject = class _TypeScriptProject {
2064
2070
  /**
2065
2071
  * Creates a TypeScript project and prepares it for building/bundling.
@@ -2098,7 +2104,8 @@ var _TypeScriptProject = class _TypeScriptProject {
2098
2104
  return Files.empty(this.buildConfiguration.outDir);
2099
2105
  }
2100
2106
  async build() {
2101
- Logger.header(`\u{1F680} tsbuild v${"1.4.1"}${this.configuration.compilerOptions.incremental && this.configuration.buildCache?.isValid() ? " [incremental]" : ""}`);
2107
+ const tsLogo = TextFormat.bgBlue(TextFormat.bold(TextFormat.whiteBright(" TS ")));
2108
+ Logger.header(`${tsLogo} tsbuild v${"1.6.0"}${this.configuration.compilerOptions.incremental && this.configuration.buildCache?.isValid() ? " [incremental]" : ""}`);
2102
2109
  try {
2103
2110
  const processes = [];
2104
2111
  const filesWereEmitted = await this.typeCheck();
@@ -2148,7 +2155,7 @@ var _TypeScriptProject = class _TypeScriptProject {
2148
2155
  performance2.mark("finalize:start");
2149
2156
  const result = this.fileManager.finalize();
2150
2157
  addPerformanceStep("Finalize", _TypeScriptProject.elapsed("finalize:start"));
2151
- return result;
2158
+ return result || !this.configuration.compilerOptions.declaration;
2152
2159
  }
2153
2160
  async transpile() {
2154
2161
  const plugins = [outputPlugin()];
@@ -2364,7 +2371,9 @@ var _TypeScriptProject = class _TypeScriptProject {
2364
2371
  compilerOptions: {
2365
2372
  ...{ outDir: defaultOutDirectory, noEmit: false, sourceMap: false, incremental: true, tsBuildInfoFile: Paths.join(cacheDirectory, buildInfoFile), lib: [] },
2366
2373
  ...configResult.config.compilerOptions,
2367
- ...typeScriptOptions.compilerOptions
2374
+ ...typeScriptOptions.compilerOptions,
2375
+ // Always include 'node' and merge with any user-specified types
2376
+ types: [.../* @__PURE__ */ new Set(["node", ...configResult.config.compilerOptions?.types ?? [], ...typeScriptOptions.compilerOptions?.types ?? []])]
2368
2377
  }
2369
2378
  };
2370
2379
  const { options, fileNames, errors } = parseJsonConfigFileContent(baseConfig, sys2, directory);
@@ -2482,14 +2491,14 @@ var _TypeScriptProject = class _TypeScriptProject {
2482
2491
  /**
2483
2492
  * Calculates elapsed time since a performance mark and clears the mark.
2484
2493
  * @param markName - The name of the performance mark to measure from
2485
- * @returns Formatted elapsed time string (e.g., '42ms')
2494
+ * @returns Elapsed time in milliseconds
2486
2495
  */
2487
2496
  static elapsed(markName) {
2488
2497
  const endMark = performance2.mark(`${markName}:end`);
2489
- const duration = endMark.startTime - performance2.getEntriesByName(markName, "mark")[0].startTime;
2498
+ const ms = ~~(endMark.startTime - performance2.getEntriesByName(markName, "mark")[0].startTime);
2490
2499
  performance2.clearMarks(markName);
2491
2500
  performance2.clearMarks(endMark.name);
2492
- return `${~~duration}ms`;
2501
+ return ms;
2493
2502
  }
2494
2503
  };
2495
2504
  _init3 = __decoratorStart(null);
package/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ type ClosableConstructor = Constructor<any[], Closable>;
44
44
  type PerformanceSubStep = {
45
45
  name: string;
46
46
  duration: string;
47
+ ms: number;
47
48
  };
48
49
  type PerformanceEntryDetail<T = unknown[]> = {
49
50
  message: string;
@@ -351,7 +352,7 @@ declare class TypeScriptProject implements Closable {
351
352
  /**
352
353
  * Calculates elapsed time since a performance mark and clears the mark.
353
354
  * @param markName - The name of the performance mark to measure from
354
- * @returns Formatted elapsed time string (e.g., '42ms')
355
+ * @returns Elapsed time in milliseconds
355
356
  */
356
357
  private static elapsed;
357
358
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TypeScriptProject
3
- } from "./TY4W6KLM.js";
3
+ } from "./Q7VGDC7X.js";
4
4
  import "./7FPDHUPW.js";
5
5
  export {
6
6
  TypeScriptProject
package/dist/tsbuild.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  BuildError,
4
4
  TypeScriptProject
5
- } from "./TY4W6KLM.js";
5
+ } from "./Q7VGDC7X.js";
6
6
  import "./7FPDHUPW.js";
7
7
 
8
8
  // src/tsbuild.ts
@@ -30,7 +30,7 @@ if (help) {
30
30
  process.exit(0);
31
31
  }
32
32
  if (version) {
33
- console.log("1.4.1");
33
+ console.log("1.6.0");
34
34
  process.exit(0);
35
35
  }
36
36
  var typeScriptOptions = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@d1g1tal/tsbuild",
3
3
  "author": "D1g1talEntr0py",
4
- "version": "1.4.1",
4
+ "version": "1.6.0",
5
5
  "license": "MIT",
6
6
  "description": "A fast, ESM-only TypeScript build tool combining the TypeScript API for type checking and declaration generation, esbuild for bundling, and SWC for decorator metadata.",
7
7
  "homepage": "https://github.com/D1g1talEntr0py/tsbuild#readme",
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "engines": {
22
- "node": ">=20.16.0"
22
+ "node": ">=22.0.0"
23
23
  },
24
24
  "publishConfig": {
25
25
  "registry": "https://registry.npmjs.org",
@@ -42,24 +42,24 @@
42
42
  "tsbuild": "./dist/tsbuild.js"
43
43
  },
44
44
  "dependencies": {
45
- "@d1g1tal/watchr": "1.0.0",
46
- "esbuild": "^0.27.3",
45
+ "@d1g1tal/watchr": "^1.0.3",
46
+ "esbuild": "^0.27.4",
47
47
  "magic-string": "^0.30.21"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@eslint/js": "^10.0.1",
51
- "@types/node": "^25.3.5",
52
- "@typescript-eslint/eslint-plugin": "^8.56.1",
53
- "@typescript-eslint/parser": "^8.56.1",
54
- "@vitest/coverage-v8": "4.0.18",
51
+ "@types/node": "^25.4.0",
52
+ "@typescript-eslint/eslint-plugin": "^8.57.0",
53
+ "@typescript-eslint/parser": "^8.57.0",
54
+ "@vitest/coverage-v8": "^4.1.0",
55
55
  "eslint": "^10.0.3",
56
- "eslint-plugin-jsdoc": "^62.7.1",
56
+ "eslint-plugin-jsdoc": "^62.8.0",
57
57
  "fs-monkey": "^1.1.0",
58
58
  "memfs": "^4.56.11",
59
59
  "tsx": "^4.21.0",
60
- "typescript": "5.9.3",
61
- "typescript-eslint": "^8.56.1",
62
- "vitest": "^4.0.18"
60
+ "typescript": "^5.9.3",
61
+ "typescript-eslint": "^8.57.0",
62
+ "vitest": "^4.1.0"
63
63
  },
64
64
  "keywords": [
65
65
  "typescript",