@ttsc/unplugin 0.12.3 → 0.13.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/lib/api.d.ts CHANGED
@@ -1 +1,8 @@
1
+ /**
2
+ * Public API surface for `@ttsc/unplugin`.
3
+ *
4
+ * Re-exports everything from `core/index` so consumers can access the unified
5
+ * `unplugin` instance, the transform helpers, and the option types from the
6
+ * `@ttsc/unplugin/api` entry point without importing directly from `core/`.
7
+ */
1
8
  export * from "./core/index";
package/lib/api.js CHANGED
@@ -6,6 +6,7 @@ var options = require('./core/options.js');
6
6
 
7
7
 
8
8
 
9
+ exports.sourceFilePattern = index.sourceFilePattern;
9
10
  exports.unplugin = index.default;
10
11
  exports.createTtscTransformCache = transform.createTtscTransformCache;
11
12
  exports.transformTtsc = transform.transformTtsc;
package/lib/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
1
+ {"version":3,"file":"api.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
package/lib/api.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { default as unplugin } from './core/index.mjs';
1
+ export { sourceFilePattern, default as unplugin } from './core/index.mjs';
2
2
  export { createTtscTransformCache, transformTtsc } from './core/transform.mjs';
3
3
  export { resolveOptions } from './core/options.mjs';
4
4
  //# sourceMappingURL=api.mjs.map
package/lib/bun.d.ts CHANGED
@@ -1,9 +1,30 @@
1
1
  import type { TtscUnpluginOptions } from "./core/options";
2
+ /**
3
+ * Minimal subset of the Bun plugin API consumed by this adapter.
4
+ *
5
+ * Bun does not yet ship TypeScript types for its bundler plugin interface, so
6
+ * we define the subset we need here. This keeps the adapter free of a Bun
7
+ * runtime dependency while remaining type-safe.
8
+ */
2
9
  export interface BunLikePlugin {
10
+ /** Plugin identifier shown in Bun bundler output. */
3
11
  name: string;
12
+ /** Called by Bun when the plugin is registered. */
4
13
  setup(build: BunLikeBuild): void | Promise<void>;
5
14
  }
15
+ /**
16
+ * Minimal subset of the Bun `BuildConfig` plugin build object.
17
+ *
18
+ * Only the `onLoad` hook is used; other hooks are not needed for a
19
+ * source-to-source transform.
20
+ */
6
21
  export interface BunLikeBuild {
22
+ /**
23
+ * Register a loader callback for files matching `filter`.
24
+ *
25
+ * The callback receives the absolute file path and must return the
26
+ * transformed file contents.
27
+ */
7
28
  onLoad(options: {
8
29
  filter: RegExp;
9
30
  }, loader: (args: {
@@ -12,4 +33,13 @@ export interface BunLikeBuild {
12
33
  contents: string;
13
34
  }>): void;
14
35
  }
36
+ /**
37
+ * Create a ttsc plugin for Bun's bundler.
38
+ *
39
+ * Bun does not implement the unplugin protocol, so this adapter instantiates
40
+ * the raw unplugin transform and wires it to Bun's `onLoad` hook manually. The
41
+ * adapter reads each matching file from disk and forwards the content to the
42
+ * ttsc transform; if the transform returns no changes the original source is
43
+ * passed through unchanged.
44
+ */
15
45
  export default function bun(options?: TtscUnpluginOptions): BunLikePlugin;
package/lib/bun.js CHANGED
@@ -5,17 +5,26 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var fs = require('node:fs/promises');
6
6
  var index = require('./core/index.js');
7
7
 
8
- const sourceFilePattern = /\.[cm]?tsx?$/;
8
+ /**
9
+ * Create a ttsc plugin for Bun's bundler.
10
+ *
11
+ * Bun does not implement the unplugin protocol, so this adapter instantiates
12
+ * the raw unplugin transform and wires it to Bun's `onLoad` hook manually. The
13
+ * adapter reads each matching file from disk and forwards the content to the
14
+ * ttsc transform; if the transform returns no changes the original source is
15
+ * passed through unchanged.
16
+ */
9
17
  function bun(options) {
10
18
  return {
11
19
  name: "ttsc-unplugin",
12
20
  setup(build) {
13
21
  const raw = index.default.raw(options, {});
14
- build.onLoad({ filter: sourceFilePattern }, async (args) => {
22
+ build.onLoad({ filter: index.sourceFilePattern }, async (args) => {
15
23
  const source = await fs.readFile(args.path, "utf8");
16
24
  const result = typeof raw.transform === "function"
17
25
  ? await raw.transform.call({}, source, args.path)
18
26
  : undefined;
27
+ // Unpack both shorthand string and object result shapes.
19
28
  if (typeof result === "string") {
20
29
  return { contents: result };
21
30
  }
package/lib/bun.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bun.js","sources":["../src/bun.ts"],"sourcesContent":[null],"names":["unplugin"],"mappings":";;;;;;;AAkBA,MAAM,iBAAiB,GAAG,cAAc;AAE1B,SAAU,GAAG,CAAC,OAA6B,EAAA;IACvD,OAAO;AACL,QAAA,IAAI,EAAE,eAAe;AACrB,QAAA,KAAK,CAAC,KAAK,EAAA;YACT,MAAM,GAAG,GAAGA,aAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,EAAyB,CAAC;AAC5D,YAAA,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAAE,OAAO,IAAI,KAAI;AACzD,gBAAA,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC;AACnD,gBAAA,MAAM,MAAM,GACV,OAAO,GAAG,CAAC,SAAS,KAAK;AACvB,sBAAE,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAW,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI;sBACvD,SAAS;AACf,gBAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AAC9B,oBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;gBAC7B;gBACA,IACE,OAAO,MAAM,KAAK,QAAQ;AAC1B,oBAAA,MAAM,KAAK,IAAI;AACf,oBAAA,MAAM,IAAI,MAAM;AAChB,oBAAA,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAC/B;AACA,oBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE;gBAClC;AACA,gBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;AAC7B,YAAA,CAAC,CAAC;QACJ,CAAC;KACF;AACH;;;;"}
1
+ {"version":3,"file":"bun.js","sources":["../src/bun.ts"],"sourcesContent":[null],"names":["unplugin","sourceFilePattern"],"mappings":";;;;;;;AAwCA;;;;;;;;AAQG;AACW,SAAU,GAAG,CAAC,OAA6B,EAAA;IACvD,OAAO;AACL,QAAA,IAAI,EAAE,eAAe;AACrB,QAAA,KAAK,CAAC,KAAK,EAAA;YACT,MAAM,GAAG,GAAGA,aAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,EAAyB,CAAC;AAC5D,YAAA,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAEC,uBAAiB,EAAE,EAAE,OAAO,IAAI,KAAI;AACzD,gBAAA,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC;AACnD,gBAAA,MAAM,MAAM,GACV,OAAO,GAAG,CAAC,SAAS,KAAK;AACvB,sBAAE,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAW,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI;sBACvD,SAAS;;AAEf,gBAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AAC9B,oBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;gBAC7B;gBACA,IACE,OAAO,MAAM,KAAK,QAAQ;AAC1B,oBAAA,MAAM,KAAK,IAAI;AACf,oBAAA,MAAM,IAAI,MAAM;AAChB,oBAAA,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAC/B;AACA,oBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE;gBAClC;AACA,gBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;AAC7B,YAAA,CAAC,CAAC;QACJ,CAAC;KACF;AACH;;;;"}
package/lib/bun.mjs CHANGED
@@ -1,7 +1,15 @@
1
1
  import fs from 'node:fs/promises';
2
- import unplugin from './core/index.mjs';
2
+ import unplugin, { sourceFilePattern } from './core/index.mjs';
3
3
 
4
- const sourceFilePattern = /\.[cm]?tsx?$/;
4
+ /**
5
+ * Create a ttsc plugin for Bun's bundler.
6
+ *
7
+ * Bun does not implement the unplugin protocol, so this adapter instantiates
8
+ * the raw unplugin transform and wires it to Bun's `onLoad` hook manually. The
9
+ * adapter reads each matching file from disk and forwards the content to the
10
+ * ttsc transform; if the transform returns no changes the original source is
11
+ * passed through unchanged.
12
+ */
5
13
  function bun(options) {
6
14
  return {
7
15
  name: "ttsc-unplugin",
@@ -12,6 +20,7 @@ function bun(options) {
12
20
  const result = typeof raw.transform === "function"
13
21
  ? await raw.transform.call({}, source, args.path)
14
22
  : undefined;
23
+ // Unpack both shorthand string and object result shapes.
15
24
  if (typeof result === "string") {
16
25
  return { contents: result };
17
26
  }
package/lib/bun.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bun.mjs","sources":["../src/bun.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAkBA,MAAM,iBAAiB,GAAG,cAAc;AAE1B,SAAU,GAAG,CAAC,OAA6B,EAAA;IACvD,OAAO;AACL,QAAA,IAAI,EAAE,eAAe;AACrB,QAAA,KAAK,CAAC,KAAK,EAAA;YACT,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,EAAyB,CAAC;AAC5D,YAAA,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAAE,OAAO,IAAI,KAAI;AACzD,gBAAA,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC;AACnD,gBAAA,MAAM,MAAM,GACV,OAAO,GAAG,CAAC,SAAS,KAAK;AACvB,sBAAE,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAW,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI;sBACvD,SAAS;AACf,gBAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,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AM,IAAI,MAAM;AAChB,oBAAA,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAC/B;AACA,oBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE;gBAClC;AACA,gBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;AAC7B,YAAA,CAAC,CAAC;QACJ,CAAC;KACF;AACH;;;;"}
@@ -2,6 +2,12 @@ import type { UnpluginInstance } from "unplugin";
2
2
  import type { TtscUnpluginOptions } from "./options";
3
3
  import { resolveOptions } from "./options";
4
4
  import { createTtscTransformCache, transformTtsc } from "./transform";
5
+ /**
6
+ * Matches any TypeScript or JavaScript source extension (.ts, .tsx, .mts, .cts,
7
+ * etc.). Shared with the Bun adapter (`bun.ts`) so the filter is defined once
8
+ * and both adapters stay in sync.
9
+ */
10
+ export declare const sourceFilePattern: RegExp;
5
11
  declare const unplugin: UnpluginInstance<TtscUnpluginOptions | undefined, false>;
6
12
  export type { TtscUnpluginCompilerOptionsJson, TtscUnpluginOptions, } from "./options";
7
13
  export { createTtscTransformCache, resolveOptions, transformTtsc, unplugin };
package/lib/core/index.js CHANGED
@@ -7,9 +7,29 @@ var options = require('./options.js');
7
7
  var transform = require('./transform.js');
8
8
 
9
9
  const name = "ttsc-unplugin";
10
+ /**
11
+ * Matches any TypeScript or JavaScript source extension (.ts, .tsx, .mts, .cts,
12
+ * etc.). Shared with the Bun adapter (`bun.ts`) so the filter is defined once
13
+ * and both adapters stay in sync.
14
+ */
10
15
  const sourceFilePattern = /\.[cm]?tsx?$/;
16
+ /** Matches any path segment that is a `node_modules` directory (cross-platform). */
11
17
  const nodeModulesPattern = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
18
+ /**
19
+ * Matches virtual module ids — Rollup/Vite use a leading NUL byte (`\0`) as
20
+ * convention.
21
+ */
12
22
  const virtualModulePattern = /\0/;
23
+ /**
24
+ * Unplugin factory that wires the ttsc transform pipeline into any supported
25
+ * bundler (Vite, Rollup, Rolldown, webpack, Rspack, esbuild, Farm).
26
+ *
27
+ * The factory resolves raw options once, creates a per-build transform cache,
28
+ * and captures Vite alias configuration via the `vite.configResolved` hook so
29
+ * that path aliases are forwarded to the generated tsconfig overlay. The cache
30
+ * is cleared on every `buildStart` to avoid stale results across watch-mode
31
+ * rebuilds.
32
+ */
13
33
  const unpluginFactory = (rawOptions = {}) => {
14
34
  const options$1 = options.resolveOptions(rawOptions);
15
35
  const transformCache = transform.createTtscTransformCache();
@@ -39,6 +59,13 @@ const unpluginFactory = (rawOptions = {}) => {
39
59
  };
40
60
  };
41
61
  const unplugin = unplugin$1.createUnplugin(unpluginFactory);
62
+ /**
63
+ * Returns `true` when the module id refers to a real TypeScript/JavaScript
64
+ * source file that should be processed by the ttsc transform.
65
+ *
66
+ * Excluded ids: virtual modules (NUL prefix), `.d.ts` declaration files, and
67
+ * anything inside `node_modules`.
68
+ */
42
69
  function isTransformTarget(id) {
43
70
  return (sourceFilePattern.test(id) &&
44
71
  !virtualModulePattern.test(id) &&
@@ -50,5 +77,6 @@ exports.resolveOptions = options.resolveOptions;
50
77
  exports.createTtscTransformCache = transform.createTtscTransformCache;
51
78
  exports.transformTtsc = transform.transformTtsc;
52
79
  exports.default = unplugin;
80
+ exports.sourceFilePattern = sourceFilePattern;
53
81
  exports.unplugin = unplugin;
54
82
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/core/index.ts"],"sourcesContent":[null],"names":["options","resolveOptions","createTtscTransformCache","stripQuery","transformTtsc","createUnplugin","isDeclarationFile"],"mappings":";;;;;;;;AAYA,MAAM,IAAI,GAAG,eAAe;AAC5B,MAAM,iBAAiB,GAAG,cAAc;AACxC,MAAM,kBAAkB,GAAG,oCAAoC;AAC/D,MAAM,oBAAoB,GAAG,IAAI;AAEjC,MAAM,eAAe,GAGjB,CAAC,UAAU,GAAG,EAAE,KAAI;AACtB,IAAA,MAAMA,SAAO,GAAGC,sBAAc,CAAC,UAAU,CAAC;AAC1C,IAAA,MAAM,cAAc,GAAGC,kCAAwB,EAAE;AACjD,IAAA,IAAI,OAAgB;IAEpB,OAAO;QACL,IAAI;AACJ,QAAA,OAAO,EAAE,KAAK;AAEd,QAAA,IAAI,EAAE;AACJ,YAAA,cAAc,CAAC,MAAM,EAAA;AACnB,gBAAA,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK;YAChC,CAAC;AACF,SAAA;QAED,UAAU,GAAA;YACR,cAAc,CAAC,KAAK,EAAE;QACxB,CAAC;AAED,QAAA,gBAAgB,CAAC,EAAE,EAAA;AACjB,YAAA,MAAM,IAAI,GAAGC,oBAAU,CAAC,EAAE,CAAC;AAC3B,YAAA,OAAO,iBAAiB,CAAC,IAAI,CAAC;QAChC,CAAC;AAED,QAAA,MAAM,SAAS,CAAC,MAAM,EAAE,EAAE,EAAA;AACxB,YAAA,MAAM,IAAI,GAAGA,oBAAU,CAAC,EAAE,CAAC;AAC3B,YAAA,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE;AAC5B,gBAAA,OAAO,SAAS;YAClB;AACA,YAAA,OAAOC,uBAAa,CAAC,IAAI,EAAE,MAAM,EAAEJ,SAAO,EAAE,OAAO,EAAE,cAAc,CAAC;QACtE,CAAC;KACF;AACH,CAAC;AAED,MAAM,QAAQ,GACZK,yBAAc,CAAC,eAAe;AAUhC,SAAS,iBAAiB,CAAC,EAAU,EAAA;AACnC,IAAA,QACE,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;AAC1B,QAAA,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,CAACC,2BAAiB,CAAC,EAAE,CAAC;AACtB,QAAA,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;AAEhC;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/core/index.ts"],"sourcesContent":[null],"names":["options","resolveOptions","createTtscTransformCache","stripQuery","transformTtsc","createUnplugin","isDeclarationFile"],"m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IAAI,CAAC,EAAE,CAAC;AAC1B,QAAA,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,CAACC,2BAAiB,CAAC,EAAE,CAAC;AACtB,QAAA,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;AAEhC;;;;;;;;;"}
@@ -3,9 +3,29 @@ import { resolveOptions } from './options.mjs';
3
3
  import { stripQuery, transformTtsc, isDeclarationFile, createTtscTransformCache } from './transform.mjs';
4
4
 
5
5
  const name = "ttsc-unplugin";
6
+ /**
7
+ * Matches any TypeScript or JavaScript source extension (.ts, .tsx, .mts, .cts,
8
+ * etc.). Shared with the Bun adapter (`bun.ts`) so the filter is defined once
9
+ * and both adapters stay in sync.
10
+ */
6
11
  const sourceFilePattern = /\.[cm]?tsx?$/;
12
+ /** Matches any path segment that is a `node_modules` directory (cross-platform). */
7
13
  const nodeModulesPattern = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
14
+ /**
15
+ * Matches virtual module ids — Rollup/Vite use a leading NUL byte (`\0`) as
16
+ * convention.
17
+ */
8
18
  const virtualModulePattern = /\0/;
19
+ /**
20
+ * Unplugin factory that wires the ttsc transform pipeline into any supported
21
+ * bundler (Vite, Rollup, Rolldown, webpack, Rspack, esbuild, Farm).
22
+ *
23
+ * The factory resolves raw options once, creates a per-build transform cache,
24
+ * and captures Vite alias configuration via the `vite.configResolved` hook so
25
+ * that path aliases are forwarded to the generated tsconfig overlay. The cache
26
+ * is cleared on every `buildStart` to avoid stale results across watch-mode
27
+ * rebuilds.
28
+ */
9
29
  const unpluginFactory = (rawOptions = {}) => {
10
30
  const options = resolveOptions(rawOptions);
11
31
  const transformCache = createTtscTransformCache();
@@ -35,6 +55,13 @@ const unpluginFactory = (rawOptions = {}) => {
35
55
  };
36
56
  };
37
57
  const unplugin = createUnplugin(unpluginFactory);
58
+ /**
59
+ * Returns `true` when the module id refers to a real TypeScript/JavaScript
60
+ * source file that should be processed by the ttsc transform.
61
+ *
62
+ * Excluded ids: virtual modules (NUL prefix), `.d.ts` declaration files, and
63
+ * anything inside `node_modules`.
64
+ */
38
65
  function isTransformTarget(id) {
39
66
  return (sourceFilePattern.test(id) &&
40
67
  !virtualModulePattern.test(id) &&
@@ -42,5 +69,5 @@ function isTransformTarget(id) {
42
69
  !nodeModulesPattern.test(id));
43
70
  }
44
71
 
45
- export { createTtscTransformCache, unplugin as default, resolveOptions, transformTtsc, unplugin };
72
+ export { createTtscTransformCache, unplugin as default, resolveOptions, sourceFilePattern, transformTtsc, unplugin };
46
73
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../src/core/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAYA,MAAM,IAAI,GAAG,eAAe;AAC5B,MAAM,iBAAiB,GAAG,cAAc;AACxC,MAAM,kBAAkB,GAAG,oCAAoC;AAC/D,MAAM,oBAAoB,GAAG,IAAI;AAEjC,MAAM,eAAe,GAGjB,CAAC,UAAU,GAAG,EAAE,KAAI;AACtB,IAAA,MAAM,OAAO,GAAG,cAAc,CAAC,UAAU,CAAC;AAC1C,IAAA,MAAM,cAAc,GAAG,wBAAwB,EAAE;AACjD,IAAA,IAAI,OAAgB;IAEpB,OAAO;QACL,IAAI;AACJ,QAAA,OAAO,EAAE,KAAK;AAEd,QAAA,IAAI,EAAE;AACJ,YAAA,cAAc,CAAC,MAAM,EAAA;AACnB,gBAAA,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK;YAChC,CAAC;AACF,SAAA;QAED,UAAU,GAAA;YACR,cAAc,CAAC,KAAK,EAAE;QACxB,CAAC;AAED,QAAA,gBAAgB,CAAC,EAAE,EAAA;AACjB,YAAA,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC;AAC3B,YAAA,OAAO,iBAAiB,CAAC,IAAI,CAAC;QAChC,CAAC;AAED,QAAA,MAAM,SAAS,CAAC,MAAM,EAAE,EAAE,EAAA;AACxB,YAAA,MAA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C;AAED,QAAA,gBAAgB,CAAC,EAAE,EAAA;AACjB,YAAA,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC;AAC3B,YAAA,OAAO,iBAAiB,CAAC,IAAI,CAAC;QAChC,CAAC;AAED,QAAA,MAAM,SAAS,CAAC,MAAM,EAAE,EAAE,EAAA;AACxB,YAAA,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC;AAC3B,YAAA,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE;AAC5B,gBAAA,OAAO,SAAS;YAClB;AACA,YAAA,OAAO,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC;QACtE,CAAC;KACF;AACH,CAAC;AAED,MAAM,QAAQ,GACZ,cAAc,CAAC,eAAe;AAUhC;;;;;;AAMG;AACH,SAAS,iBAAiB,CAAC,EAAU,EAAA;AACnC,IAAA,QACE,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;AAC1B,QAAA,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,CAAC,iBAAiB,CAAC,EAAE,CAAC;AACtB,QAAA,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;AAEhC;;;;"}
@@ -1,5 +1,7 @@
1
1
  import type { ITtscProjectPluginConfig } from "ttsc";
2
+ /** Raw compiler-options overlay supplied by the caller as a plain JSON value. */
2
3
  export type TtscUnpluginCompilerOptionsJson = Record<string, unknown>;
4
+ /** Options accepted by the `@ttsc/unplugin` bundler adapter. */
3
5
  export interface TtscUnpluginOptions {
4
6
  /**
5
7
  * Project config used by the bundler adapter.
@@ -24,9 +26,29 @@ export interface TtscUnpluginOptions {
24
26
  */
25
27
  plugins?: readonly ITtscProjectPluginConfig[] | false;
26
28
  }
29
+ /**
30
+ * Fully-resolved plugin options with all defaults applied.
31
+ *
32
+ * Produced by {@link resolveOptions}; consumed internally by the transform
33
+ * pipeline. Every field is present and normalised — callers should not
34
+ * construct this type directly.
35
+ */
27
36
  export interface ResolvedTtscUnpluginOptions {
37
+ /** Compiler-options overlay applied on top of the discovered tsconfig. */
28
38
  compilerOptions: TtscUnpluginCompilerOptionsJson;
39
+ /**
40
+ * Resolved plugin list; mirrors the semantics of
41
+ * {@link TtscUnpluginOptions.plugins}.
42
+ */
29
43
  plugins?: readonly ITtscProjectPluginConfig[] | false;
44
+ /** Resolved path to the project tsconfig, or `undefined` to auto-discover. */
30
45
  project?: string;
31
46
  }
47
+ /**
48
+ * Normalise raw user-supplied options into {@link ResolvedTtscUnpluginOptions}.
49
+ *
50
+ * Merges provided values with defaults. The `plugins` field uses an explicit
51
+ * `"plugins" in options` presence check rather than a falsy guard so that
52
+ * `plugins: false` (disable all plugins) is preserved as-is.
53
+ */
32
54
  export declare function resolveOptions(options?: TtscUnpluginOptions): ResolvedTtscUnpluginOptions;
@@ -4,6 +4,13 @@ const defaultOptions = {
4
4
  plugins: undefined,
5
5
  project: undefined,
6
6
  };
7
+ /**
8
+ * Normalise raw user-supplied options into {@link ResolvedTtscUnpluginOptions}.
9
+ *
10
+ * Merges provided values with defaults. The `plugins` field uses an explicit
11
+ * `"plugins" in options` presence check rather than a falsy guard so that
12
+ * `plugins: false` (disable all plugins) is preserved as-is.
13
+ */
7
14
  function resolveOptions(options = {}) {
8
15
  return {
9
16
  compilerOptions: { ...(options.compilerOptions ?? {}) },
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sources":["../../src/core/options.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAqCA,MAAM,cAAc,GAAgC;AAClD,IACA,OAAO,EAAE,SAAS;AAClB,IAAA,OAAO,EAAE,SAAS;CACnB;AAEK,SAAU,cAAc,CAC5B,OAAA,GAA+B,EAAE,EAAA;IAEjC,OAAO;QACL,eAAe,EAAE,EAAE,IAAI,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,EAAE;AACvD,QAAA,OAAO,EAAE,SAAS,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO;AACxE,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO;KACnD;AACH;;;;"}
1
+ {"version":3,"file":"options.js","sources":["../../src/core/options.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAoDA,MAAM,cAAc,GAAgC;AAClD,IACA,OAAO,EAAE,SAAS;AAClB,IAAA,OAAO,EAAE,SAAS;CACnB;AAED;;;;;;AAMG;AACG,SAAU,cAAc,CAC5B,OAAA,GAA+B,EAAE,EAAA;IAEjC,OAAO;QACL,eAAe,EAAE,EAAE,IAAI,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,EAAE;AACvD,QAAA,OAAO,EAAE,SAAS,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO;AACxE,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO;KACnD;AACH;;;;"}
@@ -2,6 +2,13 @@ const defaultOptions = {
2
2
  plugins: undefined,
3
3
  project: undefined,
4
4
  };
5
+ /**
6
+ * Normalise raw user-supplied options into {@link ResolvedTtscUnpluginOptions}.
7
+ *
8
+ * Merges provided values with defaults. The `plugins` field uses an explicit
9
+ * `"plugins" in options` presence check rather than a falsy guard so that
10
+ * `plugins: false` (disable all plugins) is preserved as-is.
11
+ */
5
12
  function resolveOptions(options = {}) {
6
13
  return {
7
14
  compilerOptions: { ...(options.compilerOptions ?? {}) },
@@ -1 +1 @@
1
- {"version":3,"file":"options.mjs","sources":["../../src/core/options.ts"],"sourcesContent":[null],"names":[],"mappings":"AAqCA,MAAM,cAAc,GAAgC;AAClD,IACA,OAAO,EAAE,SAAS;AAClB,IAAA,OAAO,EAAE,SAAS;CACnB;AAEK,SAAU,cAAc,CAC5B,OAAA,GAA+B,EAAE,EAAA;IAEjC,OAAO;QACL,eAAe,EAAE,EAAE,IAAI,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,EAAE;AACvD,QAAA,OAAO,EAAE,SAAS,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO;AACxE,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO;KACnD;AACH;;;;"}
1
+ {"version":3,"file":"options.mjs","sources":["../../src/core/options.ts"],"sourcesContent":[null],"names":[],"mappings":"AAoDA,MAAM,cAAc,GAAgC;AAClD,IACA,OAAO,EAAE,SAAS;AAClB,IAAA,OAAO,EAAE,SAAS;CACnB;AAED;;;;;;AAMG;AACG,SAAU,cAAc,CAC5B,OAAA,GAA+B,EAAE,EAAA;IAEjC,OAAO;QACL,eAAe,EAAE,EAAE,IAAI,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,EAAE;AACvD,QAAA,OAAO,EAAE,SAAS,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO;AACxE,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO;KACnD;AACH;;;;"}
@@ -1,19 +1,92 @@
1
1
  import type { ITtscCompilerTransformation } from "ttsc";
2
2
  import type { TransformResult } from "unplugin";
3
3
  import type { ResolvedTtscUnpluginOptions } from "./options";
4
+ /**
5
+ * The normalised transform result type that this module produces.
6
+ *
7
+ * Excludes the shorthand `string`, `null`, and `undefined` variants of
8
+ * unplugin's `TransformResult` so callers always receive an object or
9
+ * `undefined`.
10
+ */
4
11
  export type TtscTransformResult = Exclude<TransformResult, string | null | undefined>;
12
+ /**
13
+ * Normalised alias entry used when building the `paths` overlay for the
14
+ * generated tsconfig. Derived from either a Vite array alias or a webpack/
15
+ * Rspack object alias.
16
+ */
5
17
  export interface TtscTransformAlias {
18
+ /** The alias key (module specifier prefix). */
6
19
  find: string;
20
+ /** Absolute or cwd-relative path that the alias points to. */
7
21
  replacement: string;
8
22
  }
23
+ /**
24
+ * A single entry in the per-build transform cache.
25
+ *
26
+ * Stores the full compiler result together with SHA-256 hashes of every input
27
+ * file. On subsequent transforms the cached entry is validated by comparing
28
+ * fresh hashes against {@link inputHashes}; a mismatch triggers a full
29
+ * re-transform of the project.
30
+ */
9
31
  export interface TtscCachedProjectTransform {
32
+ /**
33
+ * SHA-256 hash of each project-relative input path at the time of the
34
+ * transform.
35
+ */
10
36
  inputHashes: Record<string, string>;
37
+ /** Absolute path to the directory that owns the tsconfig. */
11
38
  projectRoot: string;
39
+ /** Raw compiler output returned by {@link TtscCompiler.transform}. */
12
40
  result: ITtscCompilerTransformation;
13
41
  }
42
+ /**
43
+ * Keyed by a stable JSON string that encodes the tsconfig path, compiler
44
+ * options overlay, plugin list, and alias paths. The value is a `Promise` so
45
+ * concurrent transforms for the same project share a single in-flight
46
+ * compilation rather than spawning multiple `TtscCompiler` instances.
47
+ */
14
48
  export type TtscTransformCache = Map<string, Promise<TtscCachedProjectTransform>>;
49
+ /** Create an empty transform cache for a single build session. */
15
50
  export declare function createTtscTransformCache(): TtscTransformCache;
51
+ /**
52
+ * Apply the ttsc plugin transform to a single source file.
53
+ *
54
+ * The function is intentionally project-scoped: it compiles the entire tsconfig
55
+ * project in one shot and extracts the result for `id`. Subsequent calls for
56
+ * sibling files in the same project reuse the cached result as long as none of
57
+ * the project's input files have changed (verified by comparing SHA-256
58
+ * hashes).
59
+ *
60
+ * Returns `undefined` when no transform is needed (declaration files, virtual
61
+ * modules, disabled plugins, or source unchanged after transform).
62
+ *
63
+ * @param id - Bundler module id (may carry a query string or virtual prefix).
64
+ * @param source - Current file content supplied by the bundler.
65
+ * @param options - Resolved plugin options.
66
+ * @param aliases - Raw bundler alias configuration (Vite array or webpack
67
+ * object).
68
+ * @param cache - Optional per-build cache; cleared by the caller on
69
+ * `buildStart`.
70
+ */
16
71
  export declare function transformTtsc(id: string, source: string, options: ResolvedTtscUnpluginOptions, aliases?: unknown, cache?: TtscTransformCache): Promise<TtscTransformResult | undefined>;
72
+ /**
73
+ * Strip a query string or hash fragment from a bundler module id.
74
+ *
75
+ * Vite appends query parameters (e.g. `?raw`, `?url`, `?inline`) to
76
+ * differentiate import variants of the same file. We must strip them before
77
+ * using the id as a file-system path.
78
+ */
17
79
  export declare function stripQuery(id: string): string;
80
+ /**
81
+ * Returns `true` for TypeScript declaration files (`.d.ts`, `.d.mts`,
82
+ * `.d.cts`).
83
+ */
18
84
  export declare function isDeclarationFile(id: string): boolean;
85
+ /**
86
+ * Build the unplugin transform result, or `undefined` when the transform
87
+ * produced no changes.
88
+ *
89
+ * Returning `undefined` instead of `{ code: source }` lets the bundler skip the
90
+ * unnecessary module update and preserves the original source map.
91
+ */
19
92
  export declare function createTransformResult(source: string, code: string): TtscTransformResult | undefined;