@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.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -16
  3. package/lib/api.js +13 -18
  4. package/lib/api.js.map +1 -1
  5. package/lib/api.mjs +4 -0
  6. package/lib/api.mjs.map +1 -0
  7. package/lib/bun.js +13 -12
  8. package/lib/bun.js.map +1 -1
  9. package/lib/bun.mjs +31 -0
  10. package/lib/bun.mjs.map +1 -0
  11. package/lib/core/index.d.ts +2 -2
  12. package/lib/core/index.js +28 -18
  13. package/lib/core/index.js.map +1 -1
  14. package/lib/core/index.mjs +46 -0
  15. package/lib/core/index.mjs.map +1 -0
  16. package/lib/core/options.d.ts +3 -3
  17. package/lib/core/options.js +5 -5
  18. package/lib/core/options.js.map +1 -1
  19. package/lib/core/options.mjs +14 -0
  20. package/lib/core/options.mjs.map +1 -0
  21. package/lib/core/transform.d.ts +10 -2
  22. package/lib/core/transform.js +264 -119
  23. package/lib/core/transform.js.map +1 -1
  24. package/lib/core/transform.mjs +446 -0
  25. package/lib/core/transform.mjs.map +1 -0
  26. package/lib/esbuild.js +9 -8
  27. package/lib/esbuild.js.map +1 -1
  28. package/lib/esbuild.mjs +6 -0
  29. package/lib/esbuild.mjs.map +1 -0
  30. package/lib/farm.js +9 -8
  31. package/lib/farm.js.map +1 -1
  32. package/lib/farm.mjs +6 -0
  33. package/lib/farm.mjs.map +1 -0
  34. package/lib/index.js +10 -8
  35. package/lib/index.js.map +1 -1
  36. package/lib/index.mjs +6 -0
  37. package/lib/index.mjs.map +1 -0
  38. package/lib/next.js +10 -9
  39. package/lib/next.js.map +1 -1
  40. package/lib/next.mjs +18 -0
  41. package/lib/next.mjs.map +1 -0
  42. package/lib/rolldown.js +9 -8
  43. package/lib/rolldown.js.map +1 -1
  44. package/lib/rolldown.mjs +6 -0
  45. package/lib/rolldown.mjs.map +1 -0
  46. package/lib/rollup.js +9 -8
  47. package/lib/rollup.js.map +1 -1
  48. package/lib/rollup.mjs +6 -0
  49. package/lib/rollup.mjs.map +1 -0
  50. package/lib/rspack.js +9 -8
  51. package/lib/rspack.js.map +1 -1
  52. package/lib/rspack.mjs +6 -0
  53. package/lib/rspack.mjs.map +1 -0
  54. package/lib/vite.js +9 -8
  55. package/lib/vite.js.map +1 -1
  56. package/lib/vite.mjs +6 -0
  57. package/lib/vite.mjs.map +1 -0
  58. package/lib/webpack.js +9 -8
  59. package/lib/webpack.js.map +1 -1
  60. package/lib/webpack.mjs +6 -0
  61. package/lib/webpack.mjs.map +1 -0
  62. package/package.json +30 -18
  63. package/src/bun.ts +1 -1
  64. package/src/core/index.ts +16 -4
  65. package/src/core/options.ts +3 -3
  66. 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 should run the same `compilerOptions.plugins` entries that `ttsc` and `ttsx` use.
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.cjs
90
- const ttsc = require("@ttsc/unplugin/webpack").default;
89
+ // webpack.config.mjs
90
+ import ttsc from "@ttsc/unplugin/webpack";
91
91
 
92
- module.exports = {
92
+ export default {
93
93
  entry: "./src/index.ts",
94
94
  output: {
95
- path: `${__dirname}/dist`,
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.cjs
105
- const ttsc = require("@ttsc/unplugin/rspack").default;
104
+ // rspack.config.mjs
105
+ import ttsc from "@ttsc/unplugin/rspack";
106
106
 
107
- module.exports = {
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 reads its existing `compilerOptions.plugins`.
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
- { transform: "typia/lib/transform" },
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 ignore the plugin list from `tsconfig.json`:
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
- Plugin resolution order:
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
- "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
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","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
1
+ {"version":3,"file":"api.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
package/lib/api.mjs ADDED
@@ -0,0 +1,4 @@
1
+ export { default as unplugin } from './core/index.mjs';
2
+ export { createTtscTransformCache, transformTtsc } from './core/transform.mjs';
3
+ export { resolveOptions } from './core/options.mjs';
4
+ //# sourceMappingURL=api.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
package/lib/bun.js CHANGED
@@ -1,19 +1,18 @@
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?$/;
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 = api_1.unplugin.raw(options, {});
13
+ const raw = index.default.raw(options, {});
15
14
  build.onLoad({ filter: sourceFilePattern }, async (args) => {
16
- const source = await promises_1.default.readFile(args.path, "utf8");
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
- //# sourceMappingURL=bun.js.map
33
+
34
+ exports.default = bun;
35
+ //# sourceMappingURL=bun.js.map
package/lib/bun.js.map CHANGED
@@ -1 +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"}
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
@@ -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;;;;"}
@@ -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
- "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; } });
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]?[jt]sx?$/;
10
+ const sourceFilePattern = /\.[cm]?tsx?$/;
11
11
  const nodeModulesPattern = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
12
+ const virtualModulePattern = /\0/;
12
13
  const unpluginFactory = (rawOptions = {}) => {
13
- const options = (0, options_1.resolveOptions)(rawOptions);
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 = (0, transform_1.stripQuery)(id);
29
+ const file = transform.stripQuery(id);
25
30
  return isTransformTarget(file);
26
31
  },
27
32
  async transform(source, id) {
28
- const file = (0, transform_1.stripQuery)(id);
33
+ const file = transform.stripQuery(id);
29
34
  if (!isTransformTarget(file)) {
30
35
  return undefined;
31
36
  }
32
- return (0, transform_1.transformTtsc)(file, source, options, aliases);
37
+ return transform.transformTtsc(file, source, options$1, aliases, transformCache);
33
38
  },
34
39
  };
35
40
  };
36
- const unplugin = (0, unplugin_1.createUnplugin)(unpluginFactory);
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
- !(0, transform_1.isDeclarationFile)(id) &&
44
+ !virtualModulePattern.test(id) &&
45
+ !transform.isDeclarationFile(id) &&
42
46
  !nodeModulesPattern.test(id));
43
47
  }
44
- //# sourceMappingURL=index.js.map
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
@@ -1 +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"}
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;;;;"}
@@ -18,9 +18,9 @@ export interface TtscUnpluginOptions {
18
18
  /**
19
19
  * `ttsc` plugin entries.
20
20
  *
21
- * `undefined` reads `compilerOptions.plugins` from the project config,
22
- * `false` disables project plugins, and an array overrides the project
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
  }
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- //# sourceMappingURL=options.js.map
14
+
15
+ exports.resolveOptions = resolveOptions;
16
+ //# sourceMappingURL=options.js.map
@@ -1 +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"}
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;;;;"}
@@ -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 declare function transformTtsc(id: string, source: string, options: ResolvedTtscUnpluginOptions, aliases?: unknown): Promise<TtscTransformResult | undefined>;
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, id: string): TtscTransformResult | undefined;
19
+ export declare function createTransformResult(source: string, code: string): TtscTransformResult | undefined;