@ttsc/unplugin 0.8.0 → 0.9.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/LICENSE +21 -0
- package/README.md +17 -16
- package/lib/api.js +13 -18
- package/lib/api.js.map +1 -1
- package/lib/api.mjs +4 -0
- package/lib/api.mjs.map +1 -0
- package/lib/bun.js +13 -12
- package/lib/bun.js.map +1 -1
- package/lib/bun.mjs +31 -0
- package/lib/bun.mjs.map +1 -0
- package/lib/core/index.d.ts +2 -2
- package/lib/core/index.js +28 -18
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +46 -0
- package/lib/core/index.mjs.map +1 -0
- package/lib/core/options.d.ts +3 -3
- package/lib/core/options.js +5 -5
- package/lib/core/options.js.map +1 -1
- package/lib/core/options.mjs +14 -0
- package/lib/core/options.mjs.map +1 -0
- package/lib/core/transform.d.ts +10 -2
- package/lib/core/transform.js +264 -119
- package/lib/core/transform.js.map +1 -1
- package/lib/core/transform.mjs +446 -0
- package/lib/core/transform.mjs.map +1 -0
- package/lib/esbuild.js +9 -8
- package/lib/esbuild.js.map +1 -1
- package/lib/esbuild.mjs +6 -0
- package/lib/esbuild.mjs.map +1 -0
- package/lib/farm.js +9 -8
- package/lib/farm.js.map +1 -1
- package/lib/farm.mjs +6 -0
- package/lib/farm.mjs.map +1 -0
- package/lib/index.js +10 -8
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +6 -0
- package/lib/index.mjs.map +1 -0
- package/lib/next.js +10 -9
- package/lib/next.js.map +1 -1
- package/lib/next.mjs +18 -0
- package/lib/next.mjs.map +1 -0
- package/lib/rolldown.js +9 -8
- package/lib/rolldown.js.map +1 -1
- package/lib/rolldown.mjs +6 -0
- package/lib/rolldown.mjs.map +1 -0
- package/lib/rollup.js +9 -8
- package/lib/rollup.js.map +1 -1
- package/lib/rollup.mjs +6 -0
- package/lib/rollup.mjs.map +1 -0
- package/lib/rspack.js +9 -8
- package/lib/rspack.js.map +1 -1
- package/lib/rspack.mjs +6 -0
- package/lib/rspack.mjs.map +1 -0
- package/lib/vite.js +9 -8
- package/lib/vite.js.map +1 -1
- package/lib/vite.mjs +6 -0
- package/lib/vite.mjs.map +1 -0
- package/lib/webpack.js +9 -8
- package/lib/webpack.js.map +1 -1
- package/lib/webpack.mjs +6 -0
- package/lib/webpack.mjs.map +1 -0
- package/package.json +30 -18
- package/src/bun.ts +1 -1
- package/src/core/index.ts +16 -4
- package/src/core/options.ts +3 -3
- package/src/core/transform.ts +306 -61
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jeongho Nam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
Bundler adapter for `ttsc` plugins.
|
|
13
13
|
|
|
14
|
-
Use it when Vite, Rollup, esbuild, Webpack, Rspack, Next.js, Farm, or Bun
|
|
14
|
+
Use it when Vite, Rollup, esbuild, Webpack, Rspack, Next.js, Farm, or Bun owns the build but the project still needs `ttsc` plugins.
|
|
15
15
|
|
|
16
16
|
## Setup
|
|
17
17
|
|
|
@@ -86,13 +86,13 @@ await build({
|
|
|
86
86
|
### Webpack
|
|
87
87
|
|
|
88
88
|
```js
|
|
89
|
-
// webpack.config.
|
|
90
|
-
|
|
89
|
+
// webpack.config.mjs
|
|
90
|
+
import ttsc from "@ttsc/unplugin/webpack";
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
export default {
|
|
93
93
|
entry: "./src/index.ts",
|
|
94
94
|
output: {
|
|
95
|
-
path:
|
|
95
|
+
path: new URL("./dist", import.meta.url).pathname,
|
|
96
96
|
},
|
|
97
97
|
plugins: [ttsc()],
|
|
98
98
|
};
|
|
@@ -101,10 +101,10 @@ module.exports = {
|
|
|
101
101
|
### Rspack
|
|
102
102
|
|
|
103
103
|
```js
|
|
104
|
-
// rspack.config.
|
|
105
|
-
|
|
104
|
+
// rspack.config.mjs
|
|
105
|
+
import ttsc from "@ttsc/unplugin/rspack";
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
export default {
|
|
108
108
|
entry: "./src/index.ts",
|
|
109
109
|
plugins: [ttsc()],
|
|
110
110
|
};
|
|
@@ -150,7 +150,7 @@ await Bun.build({
|
|
|
150
150
|
|
|
151
151
|
## Configuration
|
|
152
152
|
|
|
153
|
-
By default, `@ttsc/unplugin` finds the nearest `tsconfig.json` from the file being transformed and
|
|
153
|
+
By default, `@ttsc/unplugin` finds the nearest `tsconfig.json` from the file being transformed and uses that project's plugin settings, including directly installed plugin packages.
|
|
154
154
|
|
|
155
155
|
If that is already the config you want, `ttsc()` is enough.
|
|
156
156
|
|
|
@@ -188,7 +188,10 @@ export default {
|
|
|
188
188
|
transform: "@ttsc/lint",
|
|
189
189
|
config: { "no-var": "error" },
|
|
190
190
|
},
|
|
191
|
-
{
|
|
191
|
+
{
|
|
192
|
+
transform: "typia/lib/transform",
|
|
193
|
+
finite: true,
|
|
194
|
+
},
|
|
192
195
|
],
|
|
193
196
|
},
|
|
194
197
|
}),
|
|
@@ -200,7 +203,7 @@ export default {
|
|
|
200
203
|
|
|
201
204
|
### Plugin Overrides
|
|
202
205
|
|
|
203
|
-
Use the top-level `plugins` option inside `ttsc(...)` when the bundler should
|
|
206
|
+
Use the top-level `plugins` option inside `ttsc(...)` when the bundler should use a different plugin list from `tsconfig.json`:
|
|
204
207
|
|
|
205
208
|
```ts
|
|
206
209
|
import ttsc from "@ttsc/unplugin/vite";
|
|
@@ -217,11 +220,7 @@ export default {
|
|
|
217
220
|
};
|
|
218
221
|
```
|
|
219
222
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
1. `plugins` option.
|
|
223
|
-
2. `compilerOptions.plugins` option.
|
|
224
|
-
3. `compilerOptions.plugins` from `project` / discovered `tsconfig.json`.
|
|
223
|
+
Explicit adapter options override the plugin list read from the selected project config.
|
|
225
224
|
|
|
226
225
|
Set `plugins: false` to run the adapter without loading project plugins.
|
|
227
226
|
|
|
@@ -263,6 +262,8 @@ Supported entrypoints are:
|
|
|
263
262
|
- `@ttsc/unplugin/next`
|
|
264
263
|
- `@ttsc/unplugin/bun`
|
|
265
264
|
|
|
265
|
+
Each entrypoint supports ESM import and CJS require. In CommonJS configs, read the default export from `require("@ttsc/unplugin/vite").default`.
|
|
266
|
+
|
|
266
267
|
### Options
|
|
267
268
|
|
|
268
269
|
```ts
|
package/lib/api.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./core/index.js');
|
|
4
|
+
var transform = require('./core/transform.js');
|
|
5
|
+
var options = require('./core/options.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.unplugin = index.default;
|
|
10
|
+
exports.createTtscTransformCache = transform.createTtscTransformCache;
|
|
11
|
+
exports.transformTtsc = transform.transformTtsc;
|
|
12
|
+
exports.resolveOptions = options.resolveOptions;
|
|
13
|
+
//# sourceMappingURL=api.js.map
|
package/lib/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","
|
|
1
|
+
{"version":3,"file":"api.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
package/lib/api.mjs
ADDED
package/lib/api.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/lib/bun.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const sourceFilePattern = /\.[cm]?[jt]sx?$/;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fs = require('node:fs/promises');
|
|
6
|
+
var index = require('./core/index.js');
|
|
7
|
+
|
|
8
|
+
const sourceFilePattern = /\.[cm]?tsx?$/;
|
|
10
9
|
function bun(options) {
|
|
11
10
|
return {
|
|
12
11
|
name: "ttsc-unplugin",
|
|
13
12
|
setup(build) {
|
|
14
|
-
const raw =
|
|
13
|
+
const raw = index.default.raw(options, {});
|
|
15
14
|
build.onLoad({ filter: sourceFilePattern }, async (args) => {
|
|
16
|
-
const source = await
|
|
15
|
+
const source = await fs.readFile(args.path, "utf8");
|
|
17
16
|
const result = typeof raw.transform === "function"
|
|
18
17
|
? await raw.transform.call({}, source, args.path)
|
|
19
18
|
: undefined;
|
|
@@ -31,4 +30,6 @@ function bun(options) {
|
|
|
31
30
|
},
|
|
32
31
|
};
|
|
33
32
|
}
|
|
34
|
-
|
|
33
|
+
|
|
34
|
+
exports.default = bun;
|
|
35
|
+
//# sourceMappingURL=bun.js.map
|
package/lib/bun.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun.js","
|
|
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;;;;"}
|
package/lib/bun.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import unplugin from './core/index.mjs';
|
|
3
|
+
|
|
4
|
+
const sourceFilePattern = /\.[cm]?tsx?$/;
|
|
5
|
+
function bun(options) {
|
|
6
|
+
return {
|
|
7
|
+
name: "ttsc-unplugin",
|
|
8
|
+
setup(build) {
|
|
9
|
+
const raw = unplugin.raw(options, {});
|
|
10
|
+
build.onLoad({ filter: sourceFilePattern }, async (args) => {
|
|
11
|
+
const source = await fs.readFile(args.path, "utf8");
|
|
12
|
+
const result = typeof raw.transform === "function"
|
|
13
|
+
? await raw.transform.call({}, source, args.path)
|
|
14
|
+
: undefined;
|
|
15
|
+
if (typeof result === "string") {
|
|
16
|
+
return { contents: result };
|
|
17
|
+
}
|
|
18
|
+
if (typeof result === "object" &&
|
|
19
|
+
result !== null &&
|
|
20
|
+
"code" in result &&
|
|
21
|
+
typeof result.code === "string") {
|
|
22
|
+
return { contents: result.code };
|
|
23
|
+
}
|
|
24
|
+
return { contents: source };
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { bun as default };
|
|
31
|
+
//# sourceMappingURL=bun.mjs.map
|
package/lib/bun.mjs.map
ADDED
|
@@ -0,0 +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,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/core/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { UnpluginInstance } from "unplugin";
|
|
2
2
|
import type { TtscUnpluginOptions } from "./options";
|
|
3
3
|
import { resolveOptions } from "./options";
|
|
4
|
-
import { transformTtsc } from "./transform";
|
|
4
|
+
import { createTtscTransformCache, transformTtsc } from "./transform";
|
|
5
5
|
declare const unplugin: UnpluginInstance<TtscUnpluginOptions | undefined, false>;
|
|
6
6
|
export type { TtscUnpluginCompilerOptionsJson, TtscUnpluginOptions, } from "./options";
|
|
7
|
-
export { resolveOptions, transformTtsc, unplugin };
|
|
7
|
+
export { createTtscTransformCache, resolveOptions, transformTtsc, unplugin };
|
|
8
8
|
export default unplugin;
|
package/lib/core/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var unplugin$1 = require('unplugin');
|
|
6
|
+
var options = require('./options.js');
|
|
7
|
+
var transform = require('./transform.js');
|
|
8
|
+
|
|
9
9
|
const name = "ttsc-unplugin";
|
|
10
|
-
const sourceFilePattern = /\.[cm]?
|
|
10
|
+
const sourceFilePattern = /\.[cm]?tsx?$/;
|
|
11
11
|
const nodeModulesPattern = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
|
|
12
|
+
const virtualModulePattern = /\0/;
|
|
12
13
|
const unpluginFactory = (rawOptions = {}) => {
|
|
13
|
-
const options =
|
|
14
|
+
const options$1 = options.resolveOptions(rawOptions);
|
|
15
|
+
const transformCache = transform.createTtscTransformCache();
|
|
14
16
|
let aliases;
|
|
15
17
|
return {
|
|
16
18
|
name,
|
|
@@ -20,25 +22,33 @@ const unpluginFactory = (rawOptions = {}) => {
|
|
|
20
22
|
aliases = config.resolve.alias;
|
|
21
23
|
},
|
|
22
24
|
},
|
|
25
|
+
buildStart() {
|
|
26
|
+
transformCache.clear();
|
|
27
|
+
},
|
|
23
28
|
transformInclude(id) {
|
|
24
|
-
const file =
|
|
29
|
+
const file = transform.stripQuery(id);
|
|
25
30
|
return isTransformTarget(file);
|
|
26
31
|
},
|
|
27
32
|
async transform(source, id) {
|
|
28
|
-
const file =
|
|
33
|
+
const file = transform.stripQuery(id);
|
|
29
34
|
if (!isTransformTarget(file)) {
|
|
30
35
|
return undefined;
|
|
31
36
|
}
|
|
32
|
-
return
|
|
37
|
+
return transform.transformTtsc(file, source, options$1, aliases, transformCache);
|
|
33
38
|
},
|
|
34
39
|
};
|
|
35
40
|
};
|
|
36
|
-
const unplugin =
|
|
37
|
-
exports.unplugin = unplugin;
|
|
38
|
-
exports.default = unplugin;
|
|
41
|
+
const unplugin = unplugin$1.createUnplugin(unpluginFactory);
|
|
39
42
|
function isTransformTarget(id) {
|
|
40
43
|
return (sourceFilePattern.test(id) &&
|
|
41
|
-
!
|
|
44
|
+
!virtualModulePattern.test(id) &&
|
|
45
|
+
!transform.isDeclarationFile(id) &&
|
|
42
46
|
!nodeModulesPattern.test(id));
|
|
43
47
|
}
|
|
44
|
-
|
|
48
|
+
|
|
49
|
+
exports.resolveOptions = options.resolveOptions;
|
|
50
|
+
exports.createTtscTransformCache = transform.createTtscTransformCache;
|
|
51
|
+
exports.transformTtsc = transform.transformTtsc;
|
|
52
|
+
exports.default = unplugin;
|
|
53
|
+
exports.unplugin = unplugin;
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
package/lib/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
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;;;;;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createUnplugin } from 'unplugin';
|
|
2
|
+
import { resolveOptions } from './options.mjs';
|
|
3
|
+
import { stripQuery, transformTtsc, isDeclarationFile, createTtscTransformCache } from './transform.mjs';
|
|
4
|
+
|
|
5
|
+
const name = "ttsc-unplugin";
|
|
6
|
+
const sourceFilePattern = /\.[cm]?tsx?$/;
|
|
7
|
+
const nodeModulesPattern = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
|
|
8
|
+
const virtualModulePattern = /\0/;
|
|
9
|
+
const unpluginFactory = (rawOptions = {}) => {
|
|
10
|
+
const options = resolveOptions(rawOptions);
|
|
11
|
+
const transformCache = createTtscTransformCache();
|
|
12
|
+
let aliases;
|
|
13
|
+
return {
|
|
14
|
+
name,
|
|
15
|
+
enforce: "pre",
|
|
16
|
+
vite: {
|
|
17
|
+
configResolved(config) {
|
|
18
|
+
aliases = config.resolve.alias;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
buildStart() {
|
|
22
|
+
transformCache.clear();
|
|
23
|
+
},
|
|
24
|
+
transformInclude(id) {
|
|
25
|
+
const file = stripQuery(id);
|
|
26
|
+
return isTransformTarget(file);
|
|
27
|
+
},
|
|
28
|
+
async transform(source, id) {
|
|
29
|
+
const file = stripQuery(id);
|
|
30
|
+
if (!isTransformTarget(file)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return transformTtsc(file, source, options, aliases, transformCache);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const unplugin = createUnplugin(unpluginFactory);
|
|
38
|
+
function isTransformTarget(id) {
|
|
39
|
+
return (sourceFilePattern.test(id) &&
|
|
40
|
+
!virtualModulePattern.test(id) &&
|
|
41
|
+
!isDeclarationFile(id) &&
|
|
42
|
+
!nodeModulesPattern.test(id));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { createTtscTransformCache, unplugin as default, resolveOptions, transformTtsc, unplugin };
|
|
46
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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,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,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;;;;"}
|
package/lib/core/options.d.ts
CHANGED
|
@@ -18,9 +18,9 @@ export interface TtscUnpluginOptions {
|
|
|
18
18
|
/**
|
|
19
19
|
* `ttsc` plugin entries.
|
|
20
20
|
*
|
|
21
|
-
* `undefined` reads `compilerOptions.plugins`
|
|
22
|
-
* `false` disables project plugins, and
|
|
23
|
-
* plugin list.
|
|
21
|
+
* `undefined` reads project plugins from `compilerOptions.plugins` and
|
|
22
|
+
* directly installed package markers, `false` disables project plugins, and
|
|
23
|
+
* an array overrides the project plugin list.
|
|
24
24
|
*/
|
|
25
25
|
plugins?: readonly ITtscProjectPluginConfig[] | false;
|
|
26
26
|
}
|
package/lib/core/options.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.resolveOptions = resolveOptions;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
4
3
|
const defaultOptions = {
|
|
5
|
-
compilerOptions: {},
|
|
6
4
|
plugins: undefined,
|
|
7
5
|
project: undefined,
|
|
8
6
|
};
|
|
@@ -13,4 +11,6 @@ function resolveOptions(options = {}) {
|
|
|
13
11
|
project: options.project ?? defaultOptions.project,
|
|
14
12
|
};
|
|
15
13
|
}
|
|
16
|
-
|
|
14
|
+
|
|
15
|
+
exports.resolveOptions = resolveOptions;
|
|
16
|
+
//# sourceMappingURL=options.js.map
|
package/lib/core/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","
|
|
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;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const defaultOptions = {
|
|
2
|
+
plugins: undefined,
|
|
3
|
+
project: undefined,
|
|
4
|
+
};
|
|
5
|
+
function resolveOptions(options = {}) {
|
|
6
|
+
return {
|
|
7
|
+
compilerOptions: { ...(options.compilerOptions ?? {}) },
|
|
8
|
+
plugins: "plugins" in options ? options.plugins : defaultOptions.plugins,
|
|
9
|
+
project: options.project ?? defaultOptions.project,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { resolveOptions };
|
|
14
|
+
//# sourceMappingURL=options.mjs.map
|
|
@@ -0,0 +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;;;;"}
|
package/lib/core/transform.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ITtscCompilerTransformation } from "ttsc";
|
|
1
2
|
import type { TransformResult } from "unplugin";
|
|
2
3
|
import type { ResolvedTtscUnpluginOptions } from "./options";
|
|
3
4
|
export type TtscTransformResult = Exclude<TransformResult, string | null | undefined>;
|
|
@@ -5,7 +6,14 @@ export interface TtscTransformAlias {
|
|
|
5
6
|
find: string | RegExp;
|
|
6
7
|
replacement: string;
|
|
7
8
|
}
|
|
8
|
-
export
|
|
9
|
+
export interface TtscCachedProjectTransform {
|
|
10
|
+
inputHashes: Record<string, string>;
|
|
11
|
+
projectRoot: string;
|
|
12
|
+
result: ITtscCompilerTransformation;
|
|
13
|
+
}
|
|
14
|
+
export type TtscTransformCache = Map<string, Promise<TtscCachedProjectTransform>>;
|
|
15
|
+
export declare function createTtscTransformCache(): TtscTransformCache;
|
|
16
|
+
export declare function transformTtsc(id: string, source: string, options: ResolvedTtscUnpluginOptions, aliases?: unknown, cache?: TtscTransformCache): Promise<TtscTransformResult | undefined>;
|
|
9
17
|
export declare function stripQuery(id: string): string;
|
|
10
18
|
export declare function isDeclarationFile(id: string): boolean;
|
|
11
|
-
export declare function createTransformResult(source: string, code: string
|
|
19
|
+
export declare function createTransformResult(source: string, code: string): TtscTransformResult | undefined;
|