@ttsc/unplugin 0.28.1 → 0.28.2

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.cts ADDED
@@ -0,0 +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
+ */
8
+ export * from "./core/index.cjs";
package/lib/api.d.mts ADDED
@@ -0,0 +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
+ */
8
+ export * from "./core/index.mjs";
@@ -0,0 +1,25 @@
1
+ import type { TtscUnpluginOptions } from "./core/options.cjs";
2
+ /**
3
+ * Register the ttsc transform as a Bun **runtime** plugin.
4
+ *
5
+ * The other `@ttsc/unplugin/*` adapters cover bundlers (`Bun.build`, Vite,
6
+ * Webpack, …). This entry is the runtime counterpart: loading it registers the
7
+ * same transform on Bun's module loader, so `bun run` / `bun test` apply ttsc
8
+ * plugins (e.g. typia's `typia/lib/transform`) as files are imported, with no
9
+ * bundling step. Wire it up once via a `bunfig.toml` preload entry — `preload =
10
+ * ["@ttsc/unplugin/bun-register"]` — or imperatively with `import
11
+ * "@ttsc/unplugin/bun-register"`. Options are read from the nearest
12
+ * `tsconfig.json`, identical to the bundler adapters.
13
+ *
14
+ * Registration is idempotent: the first call (implicit on import, or explicit)
15
+ * registers the one loader with Bun; later calls only update the effective
16
+ * options, so accessing the explicit API cannot install a second default loader
17
+ * that shadows the caller's configuration. Repeated explicit calls are
18
+ * last-write-wins for the effective options.
19
+ *
20
+ * @throws When called explicitly off the Bun runtime (`globalThis.Bun.plugin`
21
+ * is unavailable). The auto-registration below stays silent off Bun so the
22
+ * module is harmless to import from Node (tests, tooling).
23
+ */
24
+ export declare function register(options?: TtscUnpluginOptions): void;
25
+ export default register;
@@ -0,0 +1,25 @@
1
+ import type { TtscUnpluginOptions } from "./core/options.mjs";
2
+ /**
3
+ * Register the ttsc transform as a Bun **runtime** plugin.
4
+ *
5
+ * The other `@ttsc/unplugin/*` adapters cover bundlers (`Bun.build`, Vite,
6
+ * Webpack, …). This entry is the runtime counterpart: loading it registers the
7
+ * same transform on Bun's module loader, so `bun run` / `bun test` apply ttsc
8
+ * plugins (e.g. typia's `typia/lib/transform`) as files are imported, with no
9
+ * bundling step. Wire it up once via a `bunfig.toml` preload entry — `preload =
10
+ * ["@ttsc/unplugin/bun-register"]` — or imperatively with `import
11
+ * "@ttsc/unplugin/bun-register"`. Options are read from the nearest
12
+ * `tsconfig.json`, identical to the bundler adapters.
13
+ *
14
+ * Registration is idempotent: the first call (implicit on import, or explicit)
15
+ * registers the one loader with Bun; later calls only update the effective
16
+ * options, so accessing the explicit API cannot install a second default loader
17
+ * that shadows the caller's configuration. Repeated explicit calls are
18
+ * last-write-wins for the effective options.
19
+ *
20
+ * @throws When called explicitly off the Bun runtime (`globalThis.Bun.plugin`
21
+ * is unavailable). The auto-registration below stays silent off Bun so the
22
+ * module is harmless to import from Node (tests, tooling).
23
+ */
24
+ export declare function register(options?: TtscUnpluginOptions): void;
25
+ export default register;
package/lib/bun.d.cts ADDED
@@ -0,0 +1,95 @@
1
+ import type { TtscUnpluginOptions } from "./core/options.cjs";
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
+ */
9
+ export interface BunLikePlugin {
10
+ /** Plugin identifier shown in Bun bundler output. */
11
+ name: string;
12
+ /** Called by Bun when the plugin is registered. */
13
+ setup(build: BunLikeBuild): void | Promise<void>;
14
+ }
15
+ /** Bun loader identifiers this adapter can emit (only TypeScript is matched). */
16
+ export type BunLoader = "ts" | "tsx";
17
+ /**
18
+ * Options accepted by {@link bun}, either resolved eagerly or supplied through a
19
+ * provider evaluated lazily on the first `onLoad` call.
20
+ *
21
+ * The provider form exists for the runtime registration path (`bun-register`),
22
+ * where a single Bun plugin is registered on import but its effective options
23
+ * may be overridden by an explicit `register(options)` call made in the same
24
+ * synchronous tick. Resolving through the provider on first load, rather than
25
+ * at registration, lets that later call win without Bun ever seeing a second
26
+ * shadowing loader.
27
+ */
28
+ export type TtscBunOptions = TtscUnpluginOptions | (() => TtscUnpluginOptions | undefined);
29
+ /**
30
+ * Minimal subset of the Bun `BuildConfig` plugin build object.
31
+ *
32
+ * `onLoad` drives the source transform. Bun's bundler also exposes `onStart`,
33
+ * which is used when available to forward the shared plugin's build lifecycle
34
+ * and clear its per-build cache. The runtime plugin API omits that hook, so
35
+ * plugin setup itself starts its one process-scoped module-loading session.
36
+ */
37
+ export interface BunLikeBuild {
38
+ /**
39
+ * Build configuration exposed unchanged by Bun's bundler plugin builder.
40
+ *
41
+ * Runtime plugin builders do not supply `files`. Bun's bundler accepts an
42
+ * in-memory file map whose values deliberately remain `unknown` here because
43
+ * this adapter only needs to preserve ownership, not consume their contents.
44
+ */
45
+ config?: {
46
+ files?: Readonly<Record<string, unknown>>;
47
+ };
48
+ /**
49
+ * Register a callback for the start of a bundler build.
50
+ *
51
+ * Optional because `Bun.plugin()` runtime builders do not expose this hook.
52
+ */
53
+ onStart?(callback: () => void | Promise<void>): void;
54
+ /**
55
+ * Register a loader callback for files matching `filter`.
56
+ *
57
+ * The callback receives the file path and must return the transformed file
58
+ * contents plus the `loader` Bun should apply next. Configured in-memory
59
+ * files retain relative key spellings; ordinary disk files are normally
60
+ * absolute. The `loader` matters most for the runtime path (`Bun.plugin`),
61
+ * where Bun must be told the returned contents are still TypeScript so it
62
+ * keeps transpiling them before execution.
63
+ */
64
+ onLoad(options: {
65
+ filter: RegExp;
66
+ }, loader: (args: {
67
+ path: string;
68
+ }) => Promise<{
69
+ contents: string;
70
+ loader: BunLoader;
71
+ } | undefined>): void;
72
+ }
73
+ /**
74
+ * Create a ttsc plugin for Bun's bundler AND runtime.
75
+ *
76
+ * Bun does not implement the unplugin protocol, so this adapter wires the
77
+ * shared ttsc transform core to Bun's `onLoad` hook directly. It reads each
78
+ * included file from disk and forwards the content to the transform. Under
79
+ * `Bun.build`, excluded files and no-op transforms return `undefined` so the
80
+ * next loader retains ownership. Entries supplied through `BuildConfig.files`
81
+ * also stay with Bun's in-memory loader: they are not filesystem project inputs
82
+ * and reading the same path from disk would either fail or silently replace the
83
+ * configured contents. The runtime `Bun.plugin()` API rejects an undefined
84
+ * `onLoad` result, so that path explicitly returns the original source and
85
+ * loader instead.
86
+ *
87
+ * The same object works for `Bun.build({ plugins: [ttsc()] })` (bundler) and
88
+ * for `Bun.plugin(ttsc())` / a `bunfig.toml` preload (runtime) — see
89
+ * `bun-register`. Every result carries an explicit `loader` so Bun keeps
90
+ * transpiling the emitted TypeScript at runtime; `bunSourceFilePattern` only
91
+ * matches TypeScript, so the loader is always `ts`/`tsx`. A runtime plugin
92
+ * instance is one immutable load session, like Bun's own module cache; restart
93
+ * the process after changing compiler inputs.
94
+ */
95
+ export default function bun(options?: TtscBunOptions): BunLikePlugin;
package/lib/bun.d.mts ADDED
@@ -0,0 +1,95 @@
1
+ import type { TtscUnpluginOptions } from "./core/options.mjs";
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
+ */
9
+ export interface BunLikePlugin {
10
+ /** Plugin identifier shown in Bun bundler output. */
11
+ name: string;
12
+ /** Called by Bun when the plugin is registered. */
13
+ setup(build: BunLikeBuild): void | Promise<void>;
14
+ }
15
+ /** Bun loader identifiers this adapter can emit (only TypeScript is matched). */
16
+ export type BunLoader = "ts" | "tsx";
17
+ /**
18
+ * Options accepted by {@link bun}, either resolved eagerly or supplied through a
19
+ * provider evaluated lazily on the first `onLoad` call.
20
+ *
21
+ * The provider form exists for the runtime registration path (`bun-register`),
22
+ * where a single Bun plugin is registered on import but its effective options
23
+ * may be overridden by an explicit `register(options)` call made in the same
24
+ * synchronous tick. Resolving through the provider on first load, rather than
25
+ * at registration, lets that later call win without Bun ever seeing a second
26
+ * shadowing loader.
27
+ */
28
+ export type TtscBunOptions = TtscUnpluginOptions | (() => TtscUnpluginOptions | undefined);
29
+ /**
30
+ * Minimal subset of the Bun `BuildConfig` plugin build object.
31
+ *
32
+ * `onLoad` drives the source transform. Bun's bundler also exposes `onStart`,
33
+ * which is used when available to forward the shared plugin's build lifecycle
34
+ * and clear its per-build cache. The runtime plugin API omits that hook, so
35
+ * plugin setup itself starts its one process-scoped module-loading session.
36
+ */
37
+ export interface BunLikeBuild {
38
+ /**
39
+ * Build configuration exposed unchanged by Bun's bundler plugin builder.
40
+ *
41
+ * Runtime plugin builders do not supply `files`. Bun's bundler accepts an
42
+ * in-memory file map whose values deliberately remain `unknown` here because
43
+ * this adapter only needs to preserve ownership, not consume their contents.
44
+ */
45
+ config?: {
46
+ files?: Readonly<Record<string, unknown>>;
47
+ };
48
+ /**
49
+ * Register a callback for the start of a bundler build.
50
+ *
51
+ * Optional because `Bun.plugin()` runtime builders do not expose this hook.
52
+ */
53
+ onStart?(callback: () => void | Promise<void>): void;
54
+ /**
55
+ * Register a loader callback for files matching `filter`.
56
+ *
57
+ * The callback receives the file path and must return the transformed file
58
+ * contents plus the `loader` Bun should apply next. Configured in-memory
59
+ * files retain relative key spellings; ordinary disk files are normally
60
+ * absolute. The `loader` matters most for the runtime path (`Bun.plugin`),
61
+ * where Bun must be told the returned contents are still TypeScript so it
62
+ * keeps transpiling them before execution.
63
+ */
64
+ onLoad(options: {
65
+ filter: RegExp;
66
+ }, loader: (args: {
67
+ path: string;
68
+ }) => Promise<{
69
+ contents: string;
70
+ loader: BunLoader;
71
+ } | undefined>): void;
72
+ }
73
+ /**
74
+ * Create a ttsc plugin for Bun's bundler AND runtime.
75
+ *
76
+ * Bun does not implement the unplugin protocol, so this adapter wires the
77
+ * shared ttsc transform core to Bun's `onLoad` hook directly. It reads each
78
+ * included file from disk and forwards the content to the transform. Under
79
+ * `Bun.build`, excluded files and no-op transforms return `undefined` so the
80
+ * next loader retains ownership. Entries supplied through `BuildConfig.files`
81
+ * also stay with Bun's in-memory loader: they are not filesystem project inputs
82
+ * and reading the same path from disk would either fail or silently replace the
83
+ * configured contents. The runtime `Bun.plugin()` API rejects an undefined
84
+ * `onLoad` result, so that path explicitly returns the original source and
85
+ * loader instead.
86
+ *
87
+ * The same object works for `Bun.build({ plugins: [ttsc()] })` (bundler) and
88
+ * for `Bun.plugin(ttsc())` / a `bunfig.toml` preload (runtime) — see
89
+ * `bun-register`. Every result carries an explicit `loader` so Bun keeps
90
+ * transpiling the emitted TypeScript at runtime; `bunSourceFilePattern` only
91
+ * matches TypeScript, so the loader is always `ts`/`tsx`. A runtime plugin
92
+ * instance is one immutable load session, like Bun's own module cache; restart
93
+ * the process after changing compiler inputs.
94
+ */
95
+ export default function bun(options?: TtscBunOptions): BunLikePlugin;
@@ -0,0 +1,23 @@
1
+ import type { UnpluginInstance } from "unplugin";
2
+ import type { TtscUnpluginOptions } from "./options.cjs";
3
+ import { resolveOptions } from "./options.cjs";
4
+ import { beginTtscTransformBuild, collectExternalInputHashes, collectProjectInputHashes, createTtscTransformCache, isProjectWalkPath, resetTtscTransformCache, transformTtsc } from "./transform.cjs";
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;
11
+ declare const unplugin: UnpluginInstance<TtscUnpluginOptions | undefined, false>;
12
+ export type { TtscUnpluginCompilerOptionsJson, TtscUnpluginOptions, } from "./options.cjs";
13
+ export type { TtscTransformFilesystemOperations, TtscTransformHooks, TtscWatchInputEvidence, } from "./transform.cjs";
14
+ export { beginTtscTransformBuild, collectExternalInputHashes, collectProjectInputHashes, createTtscTransformCache, isProjectWalkPath, resetTtscTransformCache, resolveOptions, transformTtsc, unplugin, };
15
+ export default unplugin;
16
+ /**
17
+ * Returns `true` when the module id refers to a real TypeScript/JavaScript
18
+ * source file that should be processed by the ttsc transform.
19
+ *
20
+ * Excluded ids: virtual modules (NUL prefix), `.d.ts` declaration files, and
21
+ * anything inside `node_modules`.
22
+ */
23
+ export declare function isTransformTarget(id: string): boolean;
@@ -0,0 +1,23 @@
1
+ import type { UnpluginInstance } from "unplugin";
2
+ import type { TtscUnpluginOptions } from "./options.mjs";
3
+ import { resolveOptions } from "./options.mjs";
4
+ import { beginTtscTransformBuild, collectExternalInputHashes, collectProjectInputHashes, createTtscTransformCache, isProjectWalkPath, resetTtscTransformCache, transformTtsc } from "./transform.mjs";
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;
11
+ declare const unplugin: UnpluginInstance<TtscUnpluginOptions | undefined, false>;
12
+ export type { TtscUnpluginCompilerOptionsJson, TtscUnpluginOptions, } from "./options.mjs";
13
+ export type { TtscTransformFilesystemOperations, TtscTransformHooks, TtscWatchInputEvidence, } from "./transform.mjs";
14
+ export { beginTtscTransformBuild, collectExternalInputHashes, collectProjectInputHashes, createTtscTransformCache, isProjectWalkPath, resetTtscTransformCache, resolveOptions, transformTtsc, unplugin, };
15
+ export default unplugin;
16
+ /**
17
+ * Returns `true` when the module id refers to a real TypeScript/JavaScript
18
+ * source file that should be processed by the ttsc transform.
19
+ *
20
+ * Excluded ids: virtual modules (NUL prefix), `.d.ts` declaration files, and
21
+ * anything inside `node_modules`.
22
+ */
23
+ export declare function isTransformTarget(id: string): boolean;
@@ -0,0 +1,54 @@
1
+ import type { ITtscProjectPluginConfig } from "ttsc";
2
+ /** Raw compiler-options overlay supplied by the caller as a plain JSON value. */
3
+ export type TtscUnpluginCompilerOptionsJson = Record<string, unknown>;
4
+ /** Options accepted by the `@ttsc/unplugin` bundler adapter. */
5
+ export interface TtscUnpluginOptions {
6
+ /**
7
+ * Project config used by the bundler adapter.
8
+ *
9
+ * Relative paths resolve from `process.cwd()`. When omitted, the nearest
10
+ * `tsconfig.json` is discovered from the transformed file.
11
+ */
12
+ project?: string;
13
+ /**
14
+ * Compiler options overlaid on top of the selected project config.
15
+ *
16
+ * This can include `plugins`; `plugins` passed at the top level still wins as
17
+ * the explicit plugin override.
18
+ */
19
+ compilerOptions?: TtscUnpluginCompilerOptionsJson;
20
+ /**
21
+ * `ttsc` plugin entries.
22
+ *
23
+ * `undefined` reads project plugins from `compilerOptions.plugins` and
24
+ * directly installed package markers, `false` disables project plugins, and
25
+ * an array overrides the project plugin list.
26
+ */
27
+ plugins?: readonly ITtscProjectPluginConfig[] | false;
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 construct
34
+ * this type directly.
35
+ */
36
+ export interface ResolvedTtscUnpluginOptions {
37
+ /** Compiler-options overlay applied on top of the discovered tsconfig. */
38
+ compilerOptions: TtscUnpluginCompilerOptionsJson;
39
+ /**
40
+ * Resolved plugin list; mirrors the semantics of
41
+ * {@link TtscUnpluginOptions.plugins}.
42
+ */
43
+ plugins?: readonly ITtscProjectPluginConfig[] | false;
44
+ /** Resolved path to the project tsconfig, or `undefined` to auto-discover. */
45
+ project?: string;
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
+ */
54
+ export declare function resolveOptions(options?: TtscUnpluginOptions): ResolvedTtscUnpluginOptions;
@@ -0,0 +1,54 @@
1
+ import type { ITtscProjectPluginConfig } from "ttsc";
2
+ /** Raw compiler-options overlay supplied by the caller as a plain JSON value. */
3
+ export type TtscUnpluginCompilerOptionsJson = Record<string, unknown>;
4
+ /** Options accepted by the `@ttsc/unplugin` bundler adapter. */
5
+ export interface TtscUnpluginOptions {
6
+ /**
7
+ * Project config used by the bundler adapter.
8
+ *
9
+ * Relative paths resolve from `process.cwd()`. When omitted, the nearest
10
+ * `tsconfig.json` is discovered from the transformed file.
11
+ */
12
+ project?: string;
13
+ /**
14
+ * Compiler options overlaid on top of the selected project config.
15
+ *
16
+ * This can include `plugins`; `plugins` passed at the top level still wins as
17
+ * the explicit plugin override.
18
+ */
19
+ compilerOptions?: TtscUnpluginCompilerOptionsJson;
20
+ /**
21
+ * `ttsc` plugin entries.
22
+ *
23
+ * `undefined` reads project plugins from `compilerOptions.plugins` and
24
+ * directly installed package markers, `false` disables project plugins, and
25
+ * an array overrides the project plugin list.
26
+ */
27
+ plugins?: readonly ITtscProjectPluginConfig[] | false;
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 construct
34
+ * this type directly.
35
+ */
36
+ export interface ResolvedTtscUnpluginOptions {
37
+ /** Compiler-options overlay applied on top of the discovered tsconfig. */
38
+ compilerOptions: TtscUnpluginCompilerOptionsJson;
39
+ /**
40
+ * Resolved plugin list; mirrors the semantics of
41
+ * {@link TtscUnpluginOptions.plugins}.
42
+ */
43
+ plugins?: readonly ITtscProjectPluginConfig[] | false;
44
+ /** Resolved path to the project tsconfig, or `undefined` to auto-discover. */
45
+ project?: string;
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
+ */
54
+ export declare function resolveOptions(options?: TtscUnpluginOptions): ResolvedTtscUnpluginOptions;