@ttsc/unplugin 0.8.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 +286 -0
- package/lib/api.d.ts +1 -0
- package/lib/api.js +18 -0
- package/lib/api.js.map +1 -0
- package/lib/bun.d.ts +15 -0
- package/lib/bun.js +34 -0
- package/lib/bun.js.map +1 -0
- package/lib/core/index.d.ts +8 -0
- package/lib/core/index.js +44 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/options.d.ts +32 -0
- package/lib/core/options.js +16 -0
- package/lib/core/options.js.map +1 -0
- package/lib/core/transform.d.ts +11 -0
- package/lib/core/transform.js +307 -0
- package/lib/core/transform.js.map +1 -0
- package/lib/esbuild.d.ts +3 -0
- package/lib/esbuild.js +9 -0
- package/lib/esbuild.js.map +1 -0
- package/lib/farm.d.ts +3 -0
- package/lib/farm.js +9 -0
- package/lib/farm.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/next.d.ts +8 -0
- package/lib/next.js +21 -0
- package/lib/next.js.map +1 -0
- package/lib/rolldown.d.ts +3 -0
- package/lib/rolldown.js +9 -0
- package/lib/rolldown.js.map +1 -0
- package/lib/rollup.d.ts +3 -0
- package/lib/rollup.js +9 -0
- package/lib/rollup.js.map +1 -0
- package/lib/rspack.d.ts +3 -0
- package/lib/rspack.js +9 -0
- package/lib/rspack.js.map +1 -0
- package/lib/vite.d.ts +3 -0
- package/lib/vite.js +9 -0
- package/lib/vite.js.map +1 -0
- package/lib/webpack.d.ts +3 -0
- package/lib/webpack.js +9 -0
- package/lib/webpack.js.map +1 -0
- package/package.json +106 -0
- package/src/api.ts +1 -0
- package/src/bun.ts +47 -0
- package/src/core/index.ts +61 -0
- package/src/core/options.ts +52 -0
- package/src/core/transform.ts +357 -0
- package/src/esbuild.ts +5 -0
- package/src/farm.ts +5 -0
- package/src/index.ts +5 -0
- package/src/next.ts +27 -0
- package/src/rolldown.ts +5 -0
- package/src/rollup.ts +5 -0
- package/src/rspack.ts +5 -0
- package/src/vite.ts +5 -0
- package/src/webpack.ts +5 -0
package/README.md
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# `@ttsc/unplugin`
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
[](https://github.com/samchon/ttsc/blob/master/LICENSE)
|
|
6
|
+
[](https://www.npmjs.com/package/@ttsc/unplugin)
|
|
7
|
+
[](https://www.npmjs.com/package/@ttsc/unplugin)
|
|
8
|
+
[](https://github.com/samchon/ttsc/actions?query=workflow%3Atest)
|
|
9
|
+
[](https://github.com/samchon/ttsc/tree/master/docs)
|
|
10
|
+
[](https://discord.gg/E94XhzrUCZ)
|
|
11
|
+
|
|
12
|
+
Bundler adapter for `ttsc` plugins.
|
|
13
|
+
|
|
14
|
+
Use it when Vite, Rollup, esbuild, Webpack, Rspack, Next.js, Farm, or Bun should run the same `compilerOptions.plugins` entries that `ttsc` and `ttsx` use.
|
|
15
|
+
|
|
16
|
+
## Setup
|
|
17
|
+
|
|
18
|
+
Install `ttsc` and TypeScript-Go first. Then install the bundler adapter:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -D ttsc @typescript/native-preview
|
|
22
|
+
npm install -D @ttsc/unplugin
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Choose your bundler and add the adapter.
|
|
26
|
+
|
|
27
|
+
### Vite
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
// vite.config.ts
|
|
31
|
+
import ttsc from "@ttsc/unplugin/vite";
|
|
32
|
+
import { defineConfig } from "vite";
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
plugins: [ttsc()],
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Rollup
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// rollup.config.ts
|
|
43
|
+
import ttsc from "@ttsc/unplugin/rollup";
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
input: "src/index.ts",
|
|
47
|
+
output: {
|
|
48
|
+
dir: "dist",
|
|
49
|
+
format: "esm",
|
|
50
|
+
},
|
|
51
|
+
plugins: [ttsc()],
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Rolldown
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// rolldown.config.ts
|
|
59
|
+
import ttsc from "@ttsc/unplugin/rolldown";
|
|
60
|
+
|
|
61
|
+
export default {
|
|
62
|
+
input: "src/index.ts",
|
|
63
|
+
output: {
|
|
64
|
+
dir: "dist",
|
|
65
|
+
format: "esm",
|
|
66
|
+
},
|
|
67
|
+
plugins: [ttsc()],
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### esbuild
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
// esbuild.config.ts
|
|
75
|
+
import { build } from "esbuild";
|
|
76
|
+
import ttsc from "@ttsc/unplugin/esbuild";
|
|
77
|
+
|
|
78
|
+
await build({
|
|
79
|
+
entryPoints: ["src/index.ts"],
|
|
80
|
+
outdir: "dist",
|
|
81
|
+
bundle: true,
|
|
82
|
+
plugins: [ttsc()],
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Webpack
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
// webpack.config.cjs
|
|
90
|
+
const ttsc = require("@ttsc/unplugin/webpack").default;
|
|
91
|
+
|
|
92
|
+
module.exports = {
|
|
93
|
+
entry: "./src/index.ts",
|
|
94
|
+
output: {
|
|
95
|
+
path: `${__dirname}/dist`,
|
|
96
|
+
},
|
|
97
|
+
plugins: [ttsc()],
|
|
98
|
+
};
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Rspack
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
// rspack.config.cjs
|
|
105
|
+
const ttsc = require("@ttsc/unplugin/rspack").default;
|
|
106
|
+
|
|
107
|
+
module.exports = {
|
|
108
|
+
entry: "./src/index.ts",
|
|
109
|
+
plugins: [ttsc()],
|
|
110
|
+
};
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Next.js
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
// next.config.mjs
|
|
117
|
+
import withTtsc from "@ttsc/unplugin/next";
|
|
118
|
+
|
|
119
|
+
/** @type {import("next").NextConfig} */
|
|
120
|
+
const nextConfig = {
|
|
121
|
+
reactStrictMode: true,
|
|
122
|
+
};
|
|
123
|
+
export default withTtsc(nextConfig);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Farm
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
// farm.config.ts
|
|
130
|
+
import ttsc from "@ttsc/unplugin/farm";
|
|
131
|
+
import { defineConfig } from "@farmfe/core";
|
|
132
|
+
|
|
133
|
+
export default defineConfig({
|
|
134
|
+
plugins: [ttsc()],
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Bun
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
// build.ts
|
|
142
|
+
import ttsc from "@ttsc/unplugin/bun";
|
|
143
|
+
|
|
144
|
+
await Bun.build({
|
|
145
|
+
entrypoints: ["src/index.ts"],
|
|
146
|
+
outdir: "dist",
|
|
147
|
+
plugins: [ttsc()],
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Configuration
|
|
152
|
+
|
|
153
|
+
By default, `@ttsc/unplugin` finds the nearest `tsconfig.json` from the file being transformed and reads its existing `compilerOptions.plugins`.
|
|
154
|
+
|
|
155
|
+
If that is already the config you want, `ttsc()` is enough.
|
|
156
|
+
|
|
157
|
+
### Project Selection
|
|
158
|
+
|
|
159
|
+
Use `project` when the bundler should read a different config file:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
import ttsc from "@ttsc/unplugin/vite";
|
|
163
|
+
|
|
164
|
+
export default {
|
|
165
|
+
plugins: [
|
|
166
|
+
ttsc({
|
|
167
|
+
project: "tsconfig.bundle.json",
|
|
168
|
+
}),
|
|
169
|
+
],
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The project path is resolved from `process.cwd()`.
|
|
174
|
+
|
|
175
|
+
### Inline Compiler Options
|
|
176
|
+
|
|
177
|
+
Use `compilerOptions` when the bundler needs a small override without another config file:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
import ttsc from "@ttsc/unplugin/vite";
|
|
181
|
+
|
|
182
|
+
export default {
|
|
183
|
+
plugins: [
|
|
184
|
+
ttsc({
|
|
185
|
+
compilerOptions: {
|
|
186
|
+
plugins: [
|
|
187
|
+
{
|
|
188
|
+
transform: "@ttsc/lint",
|
|
189
|
+
config: { "no-var": "error" },
|
|
190
|
+
},
|
|
191
|
+
{ transform: "typia/lib/transform" },
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
],
|
|
196
|
+
};
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
`compilerOptions` is layered on top of the selected project config. Existing settings stay in place, and only the fields you pass here are changed for the bundler build.
|
|
200
|
+
|
|
201
|
+
### Plugin Overrides
|
|
202
|
+
|
|
203
|
+
Use the top-level `plugins` option inside `ttsc(...)` when the bundler should ignore the plugin list from `tsconfig.json`:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
import ttsc from "@ttsc/unplugin/vite";
|
|
207
|
+
|
|
208
|
+
export default {
|
|
209
|
+
plugins: [
|
|
210
|
+
ttsc({
|
|
211
|
+
plugins: [
|
|
212
|
+
{ transform: "@ttsc/lint", config: { "no-var": "error" } },
|
|
213
|
+
{ transform: "typia/lib/transform" },
|
|
214
|
+
],
|
|
215
|
+
}),
|
|
216
|
+
],
|
|
217
|
+
};
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Plugin resolution order:
|
|
221
|
+
|
|
222
|
+
1. `plugins` option.
|
|
223
|
+
2. `compilerOptions.plugins` option.
|
|
224
|
+
3. `compilerOptions.plugins` from `project` / discovered `tsconfig.json`.
|
|
225
|
+
|
|
226
|
+
Set `plugins: false` to run the adapter without loading project plugins.
|
|
227
|
+
|
|
228
|
+
### Next.js Options
|
|
229
|
+
|
|
230
|
+
Pass adapter options as the second argument:
|
|
231
|
+
|
|
232
|
+
```js
|
|
233
|
+
// next.config.mjs
|
|
234
|
+
import withTtsc from "@ttsc/unplugin/next";
|
|
235
|
+
|
|
236
|
+
/** @type {import("next").NextConfig} */
|
|
237
|
+
const nextConfig = {
|
|
238
|
+
reactStrictMode: true,
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
export default withTtsc(nextConfig, {
|
|
242
|
+
project: "tsconfig.bundle.json",
|
|
243
|
+
});
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Adapter Entrypoints
|
|
247
|
+
|
|
248
|
+
Import the entrypoint that matches your bundler:
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
import ttsc from "@ttsc/unplugin/vite";
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Supported entrypoints are:
|
|
255
|
+
|
|
256
|
+
- `@ttsc/unplugin/vite`
|
|
257
|
+
- `@ttsc/unplugin/esbuild`
|
|
258
|
+
- `@ttsc/unplugin/rollup`
|
|
259
|
+
- `@ttsc/unplugin/rolldown`
|
|
260
|
+
- `@ttsc/unplugin/webpack`
|
|
261
|
+
- `@ttsc/unplugin/rspack`
|
|
262
|
+
- `@ttsc/unplugin/farm`
|
|
263
|
+
- `@ttsc/unplugin/next`
|
|
264
|
+
- `@ttsc/unplugin/bun`
|
|
265
|
+
|
|
266
|
+
### Options
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
import type { TtscUnpluginOptions } from "@ttsc/unplugin";
|
|
270
|
+
|
|
271
|
+
const options: TtscUnpluginOptions = {
|
|
272
|
+
project: "tsconfig.json",
|
|
273
|
+
compilerOptions: {
|
|
274
|
+
baseUrl: ".",
|
|
275
|
+
},
|
|
276
|
+
plugins: false,
|
|
277
|
+
};
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
- `project`: path to the `tsconfig.json` used by the bundler.
|
|
281
|
+
- `compilerOptions`: temporary override layered on the selected project config.
|
|
282
|
+
- `plugins`: direct `ttsc` plugin list override, or `false` to disable plugins.
|
|
283
|
+
|
|
284
|
+
## References
|
|
285
|
+
|
|
286
|
+
Inspired by [`@ryoppippi/unplugin-typia`](https://github.com/ryoppippi/unplugin-typia).
|
package/lib/api.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core/index";
|
package/lib/api.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./core/index"), exports);
|
|
18
|
+
//# sourceMappingURL=api.js.map
|
package/lib/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
|
package/lib/bun.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TtscUnpluginOptions } from "./core/options";
|
|
2
|
+
export interface BunLikePlugin {
|
|
3
|
+
name: string;
|
|
4
|
+
setup(build: BunLikeBuild): void | Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export interface BunLikeBuild {
|
|
7
|
+
onLoad(options: {
|
|
8
|
+
filter: RegExp;
|
|
9
|
+
}, loader: (args: {
|
|
10
|
+
path: string;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
contents: string;
|
|
13
|
+
}>): void;
|
|
14
|
+
}
|
|
15
|
+
export default function bun(options?: TtscUnpluginOptions): BunLikePlugin;
|
package/lib/bun.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = bun;
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const api_1 = require("./api");
|
|
9
|
+
const sourceFilePattern = /\.[cm]?[jt]sx?$/;
|
|
10
|
+
function bun(options) {
|
|
11
|
+
return {
|
|
12
|
+
name: "ttsc-unplugin",
|
|
13
|
+
setup(build) {
|
|
14
|
+
const raw = api_1.unplugin.raw(options, {});
|
|
15
|
+
build.onLoad({ filter: sourceFilePattern }, async (args) => {
|
|
16
|
+
const source = await promises_1.default.readFile(args.path, "utf8");
|
|
17
|
+
const result = typeof raw.transform === "function"
|
|
18
|
+
? await raw.transform.call({}, source, args.path)
|
|
19
|
+
: undefined;
|
|
20
|
+
if (typeof result === "string") {
|
|
21
|
+
return { contents: result };
|
|
22
|
+
}
|
|
23
|
+
if (typeof result === "object" &&
|
|
24
|
+
result !== null &&
|
|
25
|
+
"code" in result &&
|
|
26
|
+
typeof result.code === "string") {
|
|
27
|
+
return { contents: result.code };
|
|
28
|
+
}
|
|
29
|
+
return { contents: source };
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=bun.js.map
|
package/lib/bun.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.js","sourceRoot":"","sources":["../src/bun.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAkC;AAGlC,+BAAiC;AAejC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAE5C,aAA4B,OAA6B;IACvD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,KAAK,CAAC,KAAK;YACT,MAAM,GAAG,GAAG,cAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,EAAyB,CAAC,CAAC;YAC7D,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;gBACzD,MAAM,MAAM,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBACpD,MAAM,MAAM,GACV,OAAO,GAAG,CAAC,SAAS,KAAK,UAAU;oBACjC,CAAC,CAAC,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAW,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC;oBAC1D,CAAC,CAAC,SAAS,CAAC;gBAChB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;oBAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;gBAC9B,CAAC;gBACD,IACE,OAAO,MAAM,KAAK,QAAQ;oBAC1B,MAAM,KAAK,IAAI;oBACf,MAAM,IAAI,MAAM;oBAChB,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAC/B,CAAC;oBACD,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;gBACnC,CAAC;gBACD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UnpluginInstance } from "unplugin";
|
|
2
|
+
import type { TtscUnpluginOptions } from "./options";
|
|
3
|
+
import { resolveOptions } from "./options";
|
|
4
|
+
import { transformTtsc } from "./transform";
|
|
5
|
+
declare const unplugin: UnpluginInstance<TtscUnpluginOptions | undefined, false>;
|
|
6
|
+
export type { TtscUnpluginCompilerOptionsJson, TtscUnpluginOptions, } from "./options";
|
|
7
|
+
export { resolveOptions, transformTtsc, unplugin };
|
|
8
|
+
export default unplugin;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unplugin = exports.transformTtsc = exports.resolveOptions = void 0;
|
|
4
|
+
const unplugin_1 = require("unplugin");
|
|
5
|
+
const options_1 = require("./options");
|
|
6
|
+
Object.defineProperty(exports, "resolveOptions", { enumerable: true, get: function () { return options_1.resolveOptions; } });
|
|
7
|
+
const transform_1 = require("./transform");
|
|
8
|
+
Object.defineProperty(exports, "transformTtsc", { enumerable: true, get: function () { return transform_1.transformTtsc; } });
|
|
9
|
+
const name = "ttsc-unplugin";
|
|
10
|
+
const sourceFilePattern = /\.[cm]?[jt]sx?$/;
|
|
11
|
+
const nodeModulesPattern = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
|
|
12
|
+
const unpluginFactory = (rawOptions = {}) => {
|
|
13
|
+
const options = (0, options_1.resolveOptions)(rawOptions);
|
|
14
|
+
let aliases;
|
|
15
|
+
return {
|
|
16
|
+
name,
|
|
17
|
+
enforce: "pre",
|
|
18
|
+
vite: {
|
|
19
|
+
configResolved(config) {
|
|
20
|
+
aliases = config.resolve.alias;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
transformInclude(id) {
|
|
24
|
+
const file = (0, transform_1.stripQuery)(id);
|
|
25
|
+
return isTransformTarget(file);
|
|
26
|
+
},
|
|
27
|
+
async transform(source, id) {
|
|
28
|
+
const file = (0, transform_1.stripQuery)(id);
|
|
29
|
+
if (!isTransformTarget(file)) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return (0, transform_1.transformTtsc)(file, source, options, aliases);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const unplugin = (0, unplugin_1.createUnplugin)(unpluginFactory);
|
|
37
|
+
exports.unplugin = unplugin;
|
|
38
|
+
exports.default = unplugin;
|
|
39
|
+
function isTransformTarget(id) {
|
|
40
|
+
return (sourceFilePattern.test(id) &&
|
|
41
|
+
!(0, transform_1.isDeclarationFile)(id) &&
|
|
42
|
+
!nodeModulesPattern.test(id));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;AACA,uCAA0C;AAG1C,uCAA2C;+FAAlC,wBAAc;AACvB,2CAA2E;8FAAnC,yBAAa;AAErD,MAAM,IAAI,GAAG,eAAe,CAAC;AAC7B,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAC5C,MAAM,kBAAkB,GAAG,oCAAoC,CAAC;AAEhE,MAAM,eAAe,GAGjB,CAAC,UAAU,GAAG,EAAE,EAAE,EAAE;IACtB,MAAM,OAAO,GAAG,IAAA,wBAAc,EAAC,UAAU,CAAC,CAAC;IAC3C,IAAI,OAAgB,CAAC;IAErB,OAAO;QACL,IAAI;QACJ,OAAO,EAAE,KAAK;QAEd,IAAI,EAAE;YACJ,cAAc,CAAC,MAAM;gBACnB,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YACjC,CAAC;SACF;QAED,gBAAgB,CAAC,EAAE;YACjB,MAAM,IAAI,GAAG,IAAA,sBAAU,EAAC,EAAE,CAAC,CAAC;YAC5B,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QAED,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE;YACxB,MAAM,IAAI,GAAG,IAAA,sBAAU,EAAC,EAAE,CAAC,CAAC;YAC5B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7B,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAO,IAAA,yBAAa,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACvD,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,QAAQ,GACZ,IAAA,yBAAc,EAAC,eAAe,CAAC,CAAC;QAMM,QAAQ;kBAEjC,QAAQ;AAEvB,SAAS,iBAAiB,CAAC,EAAU;IACnC,OAAO,CACL,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,CAAC,IAAA,6BAAiB,EAAC,EAAE,CAAC;QACtB,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAC7B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ITtscProjectPluginConfig } from "ttsc";
|
|
2
|
+
export type TtscUnpluginCompilerOptionsJson = Record<string, unknown>;
|
|
3
|
+
export interface TtscUnpluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Project config used by the bundler adapter.
|
|
6
|
+
*
|
|
7
|
+
* Relative paths resolve from `process.cwd()`. When omitted, the nearest
|
|
8
|
+
* `tsconfig.json` is discovered from the transformed file.
|
|
9
|
+
*/
|
|
10
|
+
project?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Compiler options overlaid on top of the selected project config.
|
|
13
|
+
*
|
|
14
|
+
* This can include `plugins`; `plugins` passed at the top level still wins as
|
|
15
|
+
* the explicit plugin override.
|
|
16
|
+
*/
|
|
17
|
+
compilerOptions?: TtscUnpluginCompilerOptionsJson;
|
|
18
|
+
/**
|
|
19
|
+
* `ttsc` plugin entries.
|
|
20
|
+
*
|
|
21
|
+
* `undefined` reads `compilerOptions.plugins` from the project config,
|
|
22
|
+
* `false` disables project plugins, and an array overrides the project
|
|
23
|
+
* plugin list.
|
|
24
|
+
*/
|
|
25
|
+
plugins?: readonly ITtscProjectPluginConfig[] | false;
|
|
26
|
+
}
|
|
27
|
+
export interface ResolvedTtscUnpluginOptions {
|
|
28
|
+
compilerOptions: TtscUnpluginCompilerOptionsJson;
|
|
29
|
+
plugins?: readonly ITtscProjectPluginConfig[] | false;
|
|
30
|
+
project?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function resolveOptions(options?: TtscUnpluginOptions): ResolvedTtscUnpluginOptions;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveOptions = resolveOptions;
|
|
4
|
+
const defaultOptions = {
|
|
5
|
+
compilerOptions: {},
|
|
6
|
+
plugins: undefined,
|
|
7
|
+
project: undefined,
|
|
8
|
+
};
|
|
9
|
+
function resolveOptions(options = {}) {
|
|
10
|
+
return {
|
|
11
|
+
compilerOptions: { ...(options.compilerOptions ?? {}) },
|
|
12
|
+
plugins: "plugins" in options ? options.plugins : defaultOptions.plugins,
|
|
13
|
+
project: options.project ?? defaultOptions.project,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/core/options.ts"],"names":[],"mappings":";;;AAqCA,MAAM,cAAc,GAAgC;IAClD,eAAe,EAAE,EAAE;IACnB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;CACnB,CAAC;AAEF,wBACE,OAAO,GAAwB,EAAE;IAEjC,OAAO;QACL,eAAe,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,EAAE;QACvD,OAAO,EAAE,SAAS,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO;QACxE,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO;KACnD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TransformResult } from "unplugin";
|
|
2
|
+
import type { ResolvedTtscUnpluginOptions } from "./options";
|
|
3
|
+
export type TtscTransformResult = Exclude<TransformResult, string | null | undefined>;
|
|
4
|
+
export interface TtscTransformAlias {
|
|
5
|
+
find: string | RegExp;
|
|
6
|
+
replacement: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function transformTtsc(id: string, source: string, options: ResolvedTtscUnpluginOptions, aliases?: unknown): Promise<TtscTransformResult | undefined>;
|
|
9
|
+
export declare function stripQuery(id: string): string;
|
|
10
|
+
export declare function isDeclarationFile(id: string): boolean;
|
|
11
|
+
export declare function createTransformResult(source: string, code: string, id: string): TtscTransformResult | undefined;
|