@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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @ttsc/unplugin: bundler-agnostic ttsc plugin adapter.
3
+ *
4
+ * Re-exports the unified `unplugin` instance that carries named bundler
5
+ * adapters (`.vite`, `.rollup`, `.rolldown`, `.webpack`, `.rspack`, `.esbuild`,
6
+ * `.farm`) as well as the raw factory for custom integrations. Per-bundler
7
+ * entry points (`@ttsc/unplugin/vite`, `/webpack`, …) each re-export the
8
+ * matching adapter directly to keep bundler-specific builds lean.
9
+ */
10
+ import unplugin from "./core/index.mjs";
11
+ export type { TtscUnpluginOptions } from "./core/options.mjs";
12
+ export default unplugin;
package/lib/next.d.cts ADDED
@@ -0,0 +1,37 @@
1
+ import type { TtscUnpluginOptions } from "./core/options.cjs";
2
+ /**
3
+ * Minimal structural type for a Next.js configuration object.
4
+ *
5
+ * Only the `webpack` field is used by this adapter; all other Next.js options
6
+ * are forwarded as-is through the spread operator.
7
+ */
8
+ export type NextLikeConfig = Record<string, unknown> & {
9
+ /**
10
+ * Optional existing webpack customisation hook. When the caller has already
11
+ * defined one, `next()` will chain through to it after injecting the ttsc
12
+ * webpack plugin.
13
+ */
14
+ webpack?: (config: WebpackLikeConfig, options: unknown) => WebpackLikeConfig;
15
+ };
16
+ /**
17
+ * Minimal structural type for a webpack configuration object as seen by the
18
+ * Next.js `webpack` hook callback.
19
+ */
20
+ export type WebpackLikeConfig = Record<string, unknown> & {
21
+ /** The webpack plugin array; initialised to `[]` by this adapter if absent. */
22
+ plugins?: unknown[];
23
+ };
24
+ /**
25
+ * Wrap a Next.js config object so that the ttsc webpack plugin is injected into
26
+ * every webpack build Next.js performs.
27
+ *
28
+ * The adapter uses `unshift` to ensure the ttsc plugin runs before any other
29
+ * plugins in the array (unplugin `enforce: "pre"` semantics). An existing
30
+ * `nextConfig.webpack` hook is preserved and called after the plugin is
31
+ * injected.
32
+ *
33
+ * @param nextConfig - The caller's existing Next.js config (spread into the
34
+ * returned object unchanged, except for `webpack`).
35
+ * @param options - Ttsc plugin options forwarded to the webpack adapter.
36
+ */
37
+ export default function next(nextConfig?: NextLikeConfig, options?: TtscUnpluginOptions): NextLikeConfig;
package/lib/next.d.mts ADDED
@@ -0,0 +1,37 @@
1
+ import type { TtscUnpluginOptions } from "./core/options.mjs";
2
+ /**
3
+ * Minimal structural type for a Next.js configuration object.
4
+ *
5
+ * Only the `webpack` field is used by this adapter; all other Next.js options
6
+ * are forwarded as-is through the spread operator.
7
+ */
8
+ export type NextLikeConfig = Record<string, unknown> & {
9
+ /**
10
+ * Optional existing webpack customisation hook. When the caller has already
11
+ * defined one, `next()` will chain through to it after injecting the ttsc
12
+ * webpack plugin.
13
+ */
14
+ webpack?: (config: WebpackLikeConfig, options: unknown) => WebpackLikeConfig;
15
+ };
16
+ /**
17
+ * Minimal structural type for a webpack configuration object as seen by the
18
+ * Next.js `webpack` hook callback.
19
+ */
20
+ export type WebpackLikeConfig = Record<string, unknown> & {
21
+ /** The webpack plugin array; initialised to `[]` by this adapter if absent. */
22
+ plugins?: unknown[];
23
+ };
24
+ /**
25
+ * Wrap a Next.js config object so that the ttsc webpack plugin is injected into
26
+ * every webpack build Next.js performs.
27
+ *
28
+ * The adapter uses `unshift` to ensure the ttsc plugin runs before any other
29
+ * plugins in the array (unplugin `enforce: "pre"` semantics). An existing
30
+ * `nextConfig.webpack` hook is preserved and called after the plugin is
31
+ * injected.
32
+ *
33
+ * @param nextConfig - The caller's existing Next.js config (spread into the
34
+ * returned object unchanged, except for `webpack`).
35
+ * @param options - Ttsc plugin options forwarded to the webpack adapter.
36
+ */
37
+ export default function next(nextConfig?: NextLikeConfig, options?: TtscUnpluginOptions): NextLikeConfig;
@@ -0,0 +1,3 @@
1
+ import unplugin from "./core/index.cjs";
2
+ declare const rolldown: typeof unplugin.rolldown;
3
+ export default rolldown;
@@ -0,0 +1,3 @@
1
+ import unplugin from "./core/index.mjs";
2
+ declare const rolldown: typeof unplugin.rolldown;
3
+ export default rolldown;
@@ -0,0 +1,3 @@
1
+ import unplugin from "./core/index.cjs";
2
+ declare const rollup: typeof unplugin.rollup;
3
+ export default rollup;
@@ -0,0 +1,3 @@
1
+ import unplugin from "./core/index.mjs";
2
+ declare const rollup: typeof unplugin.rollup;
3
+ export default rollup;
@@ -0,0 +1,3 @@
1
+ import unplugin from "./core/index.cjs";
2
+ declare const rspack: typeof unplugin.rspack;
3
+ export default rspack;
@@ -0,0 +1,3 @@
1
+ import unplugin from "./core/index.mjs";
2
+ declare const rspack: typeof unplugin.rspack;
3
+ export default rspack;
@@ -0,0 +1,58 @@
1
+ import type { TtscUnpluginOptions } from "./core/options.cjs";
2
+ /**
3
+ * Subset of the webpack loader context Turbopack provides to loaders wired
4
+ * through `turbopack.rules`. Turbopack has no JS plugin API, but it runs
5
+ * webpack-compatible loaders: source string in, source string out, with
6
+ * `async()` for asynchronous completion and `getOptions()` for the rule's
7
+ * `options` object.
8
+ */
9
+ export interface TtscTurbopackLoaderContext {
10
+ /** Marks the loader asynchronous and returns the completion callback. */
11
+ async(): (error?: unknown, content?: string) => void;
12
+ /** Absolute path of the module being loaded. */
13
+ resourcePath: string;
14
+ /** The rule's `options` object, when one was configured. */
15
+ getOptions?(): TtscUnpluginOptions | undefined;
16
+ /**
17
+ * Register an additional file the transformed module depends on. Part of the
18
+ * webpack loader context contract Turbopack implements; a registered file
19
+ * enters Turbopack's `fileDependencies` set so editing it re-runs this loader
20
+ * for the owning module. Optional so a minimal stub context (or a Turbopack
21
+ * build that predates the method) still loads.
22
+ */
23
+ addDependency?(file: string): void;
24
+ /**
25
+ * Toggle result cacheability. Part of the webpack loader context contract;
26
+ * called with `false` when the ttsc plugin declared the module volatile
27
+ * (output depends on non-file inputs), so the bundler never replays a cached
28
+ * result for it. Optional so a minimal stub context still loads.
29
+ */
30
+ cacheable?(flag: boolean): void;
31
+ }
32
+ /**
33
+ * Standalone webpack-loader entrypoint for Turbopack.
34
+ *
35
+ * Turbopack cannot load unplugin-based plugins (no JS plugin API), but its
36
+ * `turbopack.rules` accept webpack loaders, and a ttsc transform is exactly
37
+ * loader-shaped: pure TypeScript source in, transformed source out. Wire it per
38
+ * extension:
39
+ *
40
+ * ```js
41
+ * // next.config.mjs
42
+ * const nextConfig = {
43
+ * turbopack: {
44
+ * rules: {
45
+ * "*.ts": { loaders: ["@ttsc/unplugin/turbopack"] },
46
+ * "*.tsx": { loaders: ["@ttsc/unplugin/turbopack"] },
47
+ * },
48
+ * },
49
+ * };
50
+ * ```
51
+ *
52
+ * Pass {@link TtscUnpluginOptions} through the rule's `options` object. The
53
+ * loader returns the source unchanged for declaration files, `node_modules`
54
+ * paths, and transforms that produce no change, mirroring the unplugin
55
+ * adapters' `transformInclude` filter, since a broad rule glob routes
56
+ * everything matching the extension through the loader.
57
+ */
58
+ export default function turbopack(this: TtscTurbopackLoaderContext, source: string): void;
@@ -0,0 +1,58 @@
1
+ import type { TtscUnpluginOptions } from "./core/options.mjs";
2
+ /**
3
+ * Subset of the webpack loader context Turbopack provides to loaders wired
4
+ * through `turbopack.rules`. Turbopack has no JS plugin API, but it runs
5
+ * webpack-compatible loaders: source string in, source string out, with
6
+ * `async()` for asynchronous completion and `getOptions()` for the rule's
7
+ * `options` object.
8
+ */
9
+ export interface TtscTurbopackLoaderContext {
10
+ /** Marks the loader asynchronous and returns the completion callback. */
11
+ async(): (error?: unknown, content?: string) => void;
12
+ /** Absolute path of the module being loaded. */
13
+ resourcePath: string;
14
+ /** The rule's `options` object, when one was configured. */
15
+ getOptions?(): TtscUnpluginOptions | undefined;
16
+ /**
17
+ * Register an additional file the transformed module depends on. Part of the
18
+ * webpack loader context contract Turbopack implements; a registered file
19
+ * enters Turbopack's `fileDependencies` set so editing it re-runs this loader
20
+ * for the owning module. Optional so a minimal stub context (or a Turbopack
21
+ * build that predates the method) still loads.
22
+ */
23
+ addDependency?(file: string): void;
24
+ /**
25
+ * Toggle result cacheability. Part of the webpack loader context contract;
26
+ * called with `false` when the ttsc plugin declared the module volatile
27
+ * (output depends on non-file inputs), so the bundler never replays a cached
28
+ * result for it. Optional so a minimal stub context still loads.
29
+ */
30
+ cacheable?(flag: boolean): void;
31
+ }
32
+ /**
33
+ * Standalone webpack-loader entrypoint for Turbopack.
34
+ *
35
+ * Turbopack cannot load unplugin-based plugins (no JS plugin API), but its
36
+ * `turbopack.rules` accept webpack loaders, and a ttsc transform is exactly
37
+ * loader-shaped: pure TypeScript source in, transformed source out. Wire it per
38
+ * extension:
39
+ *
40
+ * ```js
41
+ * // next.config.mjs
42
+ * const nextConfig = {
43
+ * turbopack: {
44
+ * rules: {
45
+ * "*.ts": { loaders: ["@ttsc/unplugin/turbopack"] },
46
+ * "*.tsx": { loaders: ["@ttsc/unplugin/turbopack"] },
47
+ * },
48
+ * },
49
+ * };
50
+ * ```
51
+ *
52
+ * Pass {@link TtscUnpluginOptions} through the rule's `options` object. The
53
+ * loader returns the source unchanged for declaration files, `node_modules`
54
+ * paths, and transforms that produce no change, mirroring the unplugin
55
+ * adapters' `transformInclude` filter, since a broad rule glob routes
56
+ * everything matching the extension through the loader.
57
+ */
58
+ export default function turbopack(this: TtscTurbopackLoaderContext, source: string): void;
package/lib/vite.d.cts ADDED
@@ -0,0 +1,3 @@
1
+ import unplugin from "./core/index.cjs";
2
+ declare const vite: typeof unplugin.vite;
3
+ export default vite;
package/lib/vite.d.mts ADDED
@@ -0,0 +1,3 @@
1
+ import unplugin from "./core/index.mjs";
2
+ declare const vite: typeof unplugin.vite;
3
+ export default vite;
@@ -0,0 +1,3 @@
1
+ import unplugin from "./core/index.cjs";
2
+ declare const webpack: typeof unplugin.webpack;
3
+ export default webpack;
@@ -0,0 +1,3 @@
1
+ import unplugin from "./core/index.mjs";
2
+ declare const webpack: typeof unplugin.webpack;
3
+ export default webpack;
package/package.json CHANGED
@@ -1,74 +1,178 @@
1
1
  {
2
2
  "name": "@ttsc/unplugin",
3
- "version": "0.28.1",
3
+ "version": "0.28.2",
4
4
  "description": "Bundler adapters for ttsc plugins.",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
7
7
  "types": "lib/index.d.ts",
8
+ "typesVersions": {
9
+ "*": {
10
+ "lib/*": [
11
+ "lib/*"
12
+ ],
13
+ "package.json": [
14
+ "package.json"
15
+ ],
16
+ "*": [
17
+ "lib/*"
18
+ ]
19
+ }
20
+ },
8
21
  "exports": {
9
22
  ".": {
23
+ "import": {
24
+ "types": "./lib/index.d.mts",
25
+ "default": "./lib/index.mjs"
26
+ },
27
+ "require": {
28
+ "types": "./lib/index.d.cts",
29
+ "default": "./lib/index.js"
30
+ },
10
31
  "types": "./lib/index.d.ts",
11
- "import": "./lib/index.mjs",
12
32
  "default": "./lib/index.js"
13
33
  },
14
34
  "./api": {
35
+ "import": {
36
+ "types": "./lib/api.d.mts",
37
+ "default": "./lib/api.mjs"
38
+ },
39
+ "require": {
40
+ "types": "./lib/api.d.cts",
41
+ "default": "./lib/api.js"
42
+ },
15
43
  "types": "./lib/api.d.ts",
16
- "import": "./lib/api.mjs",
17
44
  "default": "./lib/api.js"
18
45
  },
19
46
  "./bun": {
47
+ "import": {
48
+ "types": "./lib/bun.d.mts",
49
+ "default": "./lib/bun.mjs"
50
+ },
51
+ "require": {
52
+ "types": "./lib/bun.d.cts",
53
+ "default": "./lib/bun.js"
54
+ },
20
55
  "types": "./lib/bun.d.ts",
21
- "import": "./lib/bun.mjs",
22
56
  "default": "./lib/bun.js"
23
57
  },
24
58
  "./bun-register": {
59
+ "import": {
60
+ "types": "./lib/bun-register.d.mts",
61
+ "default": "./lib/bun-register.mjs"
62
+ },
63
+ "require": {
64
+ "types": "./lib/bun-register.d.cts",
65
+ "default": "./lib/bun-register.js"
66
+ },
25
67
  "types": "./lib/bun-register.d.ts",
26
- "import": "./lib/bun-register.mjs",
27
68
  "default": "./lib/bun-register.js"
28
69
  },
29
70
  "./esbuild": {
71
+ "import": {
72
+ "types": "./lib/esbuild.d.mts",
73
+ "default": "./lib/esbuild.mjs"
74
+ },
75
+ "require": {
76
+ "types": "./lib/esbuild.d.cts",
77
+ "default": "./lib/esbuild.js"
78
+ },
30
79
  "types": "./lib/esbuild.d.ts",
31
- "import": "./lib/esbuild.mjs",
32
80
  "default": "./lib/esbuild.js"
33
81
  },
34
82
  "./farm": {
83
+ "import": {
84
+ "types": "./lib/farm.d.mts",
85
+ "default": "./lib/farm.mjs"
86
+ },
87
+ "require": {
88
+ "types": "./lib/farm.d.cts",
89
+ "default": "./lib/farm.js"
90
+ },
35
91
  "types": "./lib/farm.d.ts",
36
- "import": "./lib/farm.mjs",
37
92
  "default": "./lib/farm.js"
38
93
  },
39
94
  "./next": {
95
+ "import": {
96
+ "types": "./lib/next.d.mts",
97
+ "default": "./lib/next.mjs"
98
+ },
99
+ "require": {
100
+ "types": "./lib/next.d.cts",
101
+ "default": "./lib/next.js"
102
+ },
40
103
  "types": "./lib/next.d.ts",
41
- "import": "./lib/next.mjs",
42
104
  "default": "./lib/next.js"
43
105
  },
44
106
  "./rolldown": {
107
+ "import": {
108
+ "types": "./lib/rolldown.d.mts",
109
+ "default": "./lib/rolldown.mjs"
110
+ },
111
+ "require": {
112
+ "types": "./lib/rolldown.d.cts",
113
+ "default": "./lib/rolldown.js"
114
+ },
45
115
  "types": "./lib/rolldown.d.ts",
46
- "import": "./lib/rolldown.mjs",
47
116
  "default": "./lib/rolldown.js"
48
117
  },
49
118
  "./rollup": {
119
+ "import": {
120
+ "types": "./lib/rollup.d.mts",
121
+ "default": "./lib/rollup.mjs"
122
+ },
123
+ "require": {
124
+ "types": "./lib/rollup.d.cts",
125
+ "default": "./lib/rollup.js"
126
+ },
50
127
  "types": "./lib/rollup.d.ts",
51
- "import": "./lib/rollup.mjs",
52
128
  "default": "./lib/rollup.js"
53
129
  },
54
130
  "./rspack": {
131
+ "import": {
132
+ "types": "./lib/rspack.d.mts",
133
+ "default": "./lib/rspack.mjs"
134
+ },
135
+ "require": {
136
+ "types": "./lib/rspack.d.cts",
137
+ "default": "./lib/rspack.js"
138
+ },
55
139
  "types": "./lib/rspack.d.ts",
56
- "import": "./lib/rspack.mjs",
57
140
  "default": "./lib/rspack.js"
58
141
  },
59
142
  "./turbopack": {
143
+ "import": {
144
+ "types": "./lib/turbopack.d.mts",
145
+ "default": "./lib/turbopack.mjs"
146
+ },
147
+ "require": {
148
+ "types": "./lib/turbopack.d.cts",
149
+ "default": "./lib/turbopack.js"
150
+ },
60
151
  "types": "./lib/turbopack.d.ts",
61
- "import": "./lib/turbopack.mjs",
62
152
  "default": "./lib/turbopack.js"
63
153
  },
64
154
  "./vite": {
155
+ "import": {
156
+ "types": "./lib/vite.d.mts",
157
+ "default": "./lib/vite.mjs"
158
+ },
159
+ "require": {
160
+ "types": "./lib/vite.d.cts",
161
+ "default": "./lib/vite.js"
162
+ },
65
163
  "types": "./lib/vite.d.ts",
66
- "import": "./lib/vite.mjs",
67
164
  "default": "./lib/vite.js"
68
165
  },
69
166
  "./webpack": {
167
+ "import": {
168
+ "types": "./lib/webpack.d.mts",
169
+ "default": "./lib/webpack.mjs"
170
+ },
171
+ "require": {
172
+ "types": "./lib/webpack.d.cts",
173
+ "default": "./lib/webpack.js"
174
+ },
70
175
  "types": "./lib/webpack.d.ts",
71
- "import": "./lib/webpack.mjs",
72
176
  "default": "./lib/webpack.js"
73
177
  },
74
178
  "./package.json": "./package.json"
@@ -95,7 +199,7 @@
95
199
  "unplugin": "^2.3.11"
96
200
  },
97
201
  "peerDependencies": {
98
- "ttsc": "^0.28.1"
202
+ "ttsc": "^0.28.2"
99
203
  },
100
204
  "devDependencies": {
101
205
  "@rollup/plugin-commonjs": "^29.0.2",
@@ -105,10 +209,11 @@
105
209
  "rimraf": "^6.1.2",
106
210
  "rollup": "^4.60.3",
107
211
  "tinyglobby": "^0.2.16",
212
+ "ts-legacy": "npm:typescript@~6.0.3",
108
213
  "tslib": "^2.8.1",
109
214
  "typescript": "^7.0.2",
110
215
  "vite": "^7.3.5",
111
- "ttsc": "0.28.1"
216
+ "ttsc": "0.28.2"
112
217
  },
113
218
  "repository": {
114
219
  "type": "git",
@@ -122,6 +227,6 @@
122
227
  "homepage": "https://ttsc.dev",
123
228
  "sideEffects": false,
124
229
  "scripts": {
125
- "build": "rimraf lib && tsc --emitDeclarationOnly && rollup -c"
230
+ "build": "rimraf lib && tsc --emitDeclarationOnly && node scripts/emit-dual-declarations.mjs && rollup -c"
126
231
  }
127
232
  }