zod-compiler 1.14.0 → 1.16.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 +81 -0
- package/dist/loader.d.ts +19 -4
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +83 -39
- package/dist/loader.js.map +1 -1
- package/dist/swc.d.ts +60 -0
- package/dist/swc.d.ts.map +1 -0
- package/dist/swc.js +98 -0
- package/dist/swc.js.map +1 -0
- package/dist/unplugin/dep-graph.js +17 -11
- package/dist/unplugin/dep-graph.js.map +1 -1
- package/dist/unplugin/rsbuild.d.ts +4 -0
- package/dist/unplugin/rsbuild.d.ts.map +1 -0
- package/dist/unplugin/rsbuild.js +13 -0
- package/dist/unplugin/rsbuild.js.map +1 -0
- package/package.json +25 -1
package/README.md
CHANGED
|
@@ -137,8 +137,10 @@ npx zod-compiler generate src/ --strip-unknown-keys
|
|
|
137
137
|
| Vite | `import zodCompiler from "zod-compiler/vite"` |
|
|
138
138
|
| webpack | `import zodCompiler from "zod-compiler/webpack"` |
|
|
139
139
|
| esbuild | `import zodCompiler from "zod-compiler/esbuild"` |
|
|
140
|
+
| SWC | `import zodCompiler from "zod-compiler/swc"` |
|
|
140
141
|
| Rollup | `import zodCompiler from "zod-compiler/rollup"` |
|
|
141
142
|
| Rolldown | `import zodCompiler from "zod-compiler/rolldown"` |
|
|
143
|
+
| Rsbuild | `import zodCompiler from "zod-compiler/rsbuild"` |
|
|
142
144
|
| rspack | `import zodCompiler from "zod-compiler/rspack"` |
|
|
143
145
|
| Bun | `import zodCompiler from "zod-compiler/bun"` |
|
|
144
146
|
| Farm | `import zodCompiler from "zod-compiler/farm"` |
|
|
@@ -165,6 +167,17 @@ zodCompiler({
|
|
|
165
167
|
});
|
|
166
168
|
```
|
|
167
169
|
|
|
170
|
+
**rsbuild.config.ts:**
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { defineConfig } from "@rsbuild/core";
|
|
174
|
+
import zodCompiler from "zod-compiler/rsbuild";
|
|
175
|
+
|
|
176
|
+
export default defineConfig({
|
|
177
|
+
plugins: [zodCompiler()],
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
168
181
|
> **Note:** Vitest is detected automatically (via the `VITEST` env var), so
|
|
169
182
|
> tests compile and exercise the same validators that ship to production —
|
|
170
183
|
> including their performance. Pass `apply: "build"` if you want tests to use
|
|
@@ -341,6 +354,74 @@ The result: a 5-file project with 10 schemas all using `z.email()` and
|
|
|
341
354
|
Set `output: "bag"` to additionally drop the original Zod schema reference
|
|
342
355
|
when you don't need `instanceof` / `.shape` access on the compiled output.
|
|
343
356
|
|
|
357
|
+
### SWC
|
|
358
|
+
|
|
359
|
+
`zod-compiler/swc` is a **programmatic `@swc/core` bridge**, not a native
|
|
360
|
+
`.swcrc` WASM plugin. Native SWC plugins run inside SWC's Rust/WASM plugin
|
|
361
|
+
runtime; zod-compiler needs Node.js at build time to execute schema modules
|
|
362
|
+
for discovery, so the SWC integration wraps `@swc/core.transform()` instead.
|
|
363
|
+
|
|
364
|
+
Install `@swc/core` in the consuming project:
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
pnpm add -D @swc/core
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Use the default factory when you want shared SWC/zod-compiler defaults:
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
import zodCompiler from "zod-compiler/swc";
|
|
374
|
+
|
|
375
|
+
const compiler = zodCompiler({
|
|
376
|
+
swc: {
|
|
377
|
+
jsc: {
|
|
378
|
+
parser: { syntax: "typescript", tsx: true },
|
|
379
|
+
},
|
|
380
|
+
sourceMaps: true,
|
|
381
|
+
},
|
|
382
|
+
zodCompiler: {
|
|
383
|
+
schemas: "auto",
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
const result = await compiler.transform(sourceCode, {
|
|
388
|
+
filename: "src/schemas.ts",
|
|
389
|
+
});
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
Or use the one-shot helper:
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
import { transform } from "zod-compiler/swc";
|
|
396
|
+
|
|
397
|
+
const result = await transform(sourceCode, {
|
|
398
|
+
filename: "src/schemas.ts",
|
|
399
|
+
swc: {
|
|
400
|
+
jsc: {
|
|
401
|
+
parser: { syntax: "typescript" },
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
The bridge defaults `codegenMode` to `"inline"` because SWC does not provide
|
|
408
|
+
Rollup-style virtual module hooks for `virtual:zod-compiler/runtime`. If your
|
|
409
|
+
pipeline runs another bundler after SWC and that bundler resolves the runtime
|
|
410
|
+
specifier, you can opt into smaller lean output:
|
|
411
|
+
|
|
412
|
+
```typescript
|
|
413
|
+
await transform(sourceCode, {
|
|
414
|
+
filename: "src/schemas.ts",
|
|
415
|
+
zodCompiler: { codegenMode: "lean" },
|
|
416
|
+
});
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
The bridge honors `include`/`exclude` globs (rejected files pass through to
|
|
420
|
+
SWC without the zod-compiler step) and re-runs schema discovery when a
|
|
421
|
+
file's content changes between calls, so watch-mode hosts pick up schema
|
|
422
|
+
edits. It keeps no persistent disk cache — long-running hosts that want one
|
|
423
|
+
should key cached transform results on file content.
|
|
424
|
+
|
|
344
425
|
**Structural dedup within a file.** Beyond the shared runtime layer, schemas in
|
|
345
426
|
the same file that contain a structurally identical sub-tree — a reused
|
|
346
427
|
`Address`, a `Money` pair, an exported schema also embedded in another — emit
|
package/dist/loader.d.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Candidate files for a specifier using the tsconfig path mappings visible
|
|
3
|
+
* from a directory. Used by the static dependency crawler so alias imports
|
|
4
|
+
* resolve the same way discovery resolves them.
|
|
5
|
+
*
|
|
6
|
+
* `authoritative` tells the caller how to treat a miss (no candidate exists
|
|
7
|
+
* on disk):
|
|
8
|
+
* - true — the tsconfig owns this specifier: an explicit `paths` pattern
|
|
9
|
+
* matched, or the paths config exists but cannot be interpreted
|
|
10
|
+
* (createPathsMatcher rejects what tsc rejects). Resolution must be
|
|
11
|
+
* treated as failed rather than falling back to node — which specifiers a
|
|
12
|
+
* broken config would have mapped is unknowable.
|
|
13
|
+
* - false — candidates came only from the implicit baseUrl lookup, which
|
|
14
|
+
* proposes `<baseDir>/<specifier>` for EVERY bare specifier (npm packages
|
|
15
|
+
* and `#` subpath imports included) and expects the caller to fall back
|
|
16
|
+
* to node resolution when the candidate does not exist.
|
|
5
17
|
*/
|
|
6
|
-
export declare function
|
|
18
|
+
export declare function resolveTsconfigPathCandidates(fromDir: string, specifier: string): {
|
|
19
|
+
candidates: string[];
|
|
20
|
+
authoritative: boolean;
|
|
21
|
+
};
|
|
7
22
|
/**
|
|
8
23
|
* Thrown in place of a `process.exit()` call made while a build-time module is
|
|
9
24
|
* executing (see {@link runGuarded}). Discovery already catches load failures
|
package/dist/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAoFA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB;IAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAoBlD;AAoCD;;;;;GAKG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;gBAEnC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;CAQnC;AA0DD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAS5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,EAAE,GAAG,IAAI,CAW1D;AAiBD;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAsBvF;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAkBlC"}
|
package/dist/loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
|
-
import { getTsconfig } from "get-tsconfig";
|
|
3
|
+
import { createPathsMatcher, getTsconfig, } from "get-tsconfig";
|
|
4
4
|
function detectRuntime() {
|
|
5
5
|
if ("Bun" in globalThis)
|
|
6
6
|
return "bun";
|
|
@@ -10,52 +10,96 @@ function detectRuntime() {
|
|
|
10
10
|
}
|
|
11
11
|
/** Cache: search dir → tsconfig lookup result (getTsconfig walks the fs otherwise). */
|
|
12
12
|
const tsconfigSearchCache = new Map();
|
|
13
|
-
/** Cache: tsconfig.json absolute path → resolved jiti alias map */
|
|
14
|
-
const aliasCache = new Map();
|
|
15
13
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
14
|
+
* Cache: tsconfig.json absolute path → paths matcher. `null`: config has no
|
|
15
|
+
* baseUrl/paths. `"unusable"`: createPathsMatcher rejected the config (the
|
|
16
|
+
* same validations tsc enforces — multi-star patterns, TS5090 non-relative
|
|
17
|
+
* substitutions without baseUrl).
|
|
18
|
+
*/
|
|
19
|
+
const pathsMatcherCache = new Map();
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the tsconfig.json visible from a source directory.
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
+
* jiti has first-class TypeScript paths support, so runtime discovery uses the
|
|
24
|
+
* tsconfig path directly instead of translating aliases into jiti's simpler
|
|
25
|
+
* prefix alias format. The static dependency crawler uses get-tsconfig's own
|
|
26
|
+
* matcher for the same reason: project aliases are arbitrary TypeScript
|
|
27
|
+
* `paths` patterns, not a fixed convention like "~" or "@".
|
|
23
28
|
*/
|
|
24
29
|
function resolveLoaderConfig(fromDir) {
|
|
25
30
|
const tsconfig = getTsconfig(fromDir, "tsconfig.json", tsconfigSearchCache);
|
|
26
31
|
if (!tsconfig)
|
|
27
|
-
return { key: "",
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
return { key: "", tsconfigPath: undefined };
|
|
33
|
+
return { key: tsconfig.path, tsconfigPath: tsconfig.path };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether an explicit `compilerOptions.paths` pattern matches the specifier.
|
|
37
|
+
* TS pattern grammar: an exact string, or a single `*` wildcard (prefix +
|
|
38
|
+
* suffix match). Needed because the matcher's output alone cannot tell an
|
|
39
|
+
* explicit alias apart from the implicit baseUrl lookup (see below).
|
|
40
|
+
*/
|
|
41
|
+
function specifierMatchesPathsPattern(tsconfig, specifier) {
|
|
32
42
|
const paths = tsconfig.config.compilerOptions?.paths;
|
|
33
|
-
if (paths
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const val = target.endsWith("/*") ? target.slice(0, -2) : target;
|
|
46
|
-
alias[key] = path.resolve(baseDir, val);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
aliasCache.set(tsconfig.path, alias);
|
|
50
|
-
return { key: tsconfig.path, alias };
|
|
43
|
+
if (!paths)
|
|
44
|
+
return false;
|
|
45
|
+
return Object.keys(paths).some((pattern) => {
|
|
46
|
+
const star = pattern.indexOf("*");
|
|
47
|
+
if (star === -1)
|
|
48
|
+
return pattern === specifier;
|
|
49
|
+
const prefix = pattern.slice(0, star);
|
|
50
|
+
const suffix = pattern.slice(star + 1);
|
|
51
|
+
return (specifier.length >= prefix.length + suffix.length &&
|
|
52
|
+
specifier.startsWith(prefix) &&
|
|
53
|
+
specifier.endsWith(suffix));
|
|
54
|
+
});
|
|
51
55
|
}
|
|
56
|
+
const NO_CANDIDATES = {
|
|
57
|
+
candidates: [],
|
|
58
|
+
authoritative: false,
|
|
59
|
+
};
|
|
60
|
+
const UNUSABLE_CONFIG = {
|
|
61
|
+
candidates: [],
|
|
62
|
+
authoritative: true,
|
|
63
|
+
};
|
|
52
64
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
65
|
+
* Candidate files for a specifier using the tsconfig path mappings visible
|
|
66
|
+
* from a directory. Used by the static dependency crawler so alias imports
|
|
67
|
+
* resolve the same way discovery resolves them.
|
|
68
|
+
*
|
|
69
|
+
* `authoritative` tells the caller how to treat a miss (no candidate exists
|
|
70
|
+
* on disk):
|
|
71
|
+
* - true — the tsconfig owns this specifier: an explicit `paths` pattern
|
|
72
|
+
* matched, or the paths config exists but cannot be interpreted
|
|
73
|
+
* (createPathsMatcher rejects what tsc rejects). Resolution must be
|
|
74
|
+
* treated as failed rather than falling back to node — which specifiers a
|
|
75
|
+
* broken config would have mapped is unknowable.
|
|
76
|
+
* - false — candidates came only from the implicit baseUrl lookup, which
|
|
77
|
+
* proposes `<baseDir>/<specifier>` for EVERY bare specifier (npm packages
|
|
78
|
+
* and `#` subpath imports included) and expects the caller to fall back
|
|
79
|
+
* to node resolution when the candidate does not exist.
|
|
56
80
|
*/
|
|
57
|
-
export function
|
|
58
|
-
|
|
81
|
+
export function resolveTsconfigPathCandidates(fromDir, specifier) {
|
|
82
|
+
const tsconfig = getTsconfig(fromDir, "tsconfig.json", tsconfigSearchCache);
|
|
83
|
+
if (!tsconfig)
|
|
84
|
+
return NO_CANDIDATES;
|
|
85
|
+
let matcher = pathsMatcherCache.get(tsconfig.path);
|
|
86
|
+
if (matcher === undefined) {
|
|
87
|
+
try {
|
|
88
|
+
matcher = createPathsMatcher(tsconfig);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Invalid-per-tsc paths config. A stray tsconfig anywhere in the
|
|
92
|
+
// crawled tree must degrade the graph, not crash the build.
|
|
93
|
+
matcher = "unusable";
|
|
94
|
+
}
|
|
95
|
+
pathsMatcherCache.set(tsconfig.path, matcher);
|
|
96
|
+
}
|
|
97
|
+
if (matcher === "unusable")
|
|
98
|
+
return UNUSABLE_CONFIG;
|
|
99
|
+
const candidates = matcher?.(specifier) ?? [];
|
|
100
|
+
if (candidates.length === 0)
|
|
101
|
+
return NO_CANDIDATES;
|
|
102
|
+
return { candidates, authoritative: specifierMatchesPathsPattern(tsconfig, specifier) };
|
|
59
103
|
}
|
|
60
104
|
/**
|
|
61
105
|
* Shared jiti instances, keyed by tsconfig identity (the alias config).
|
|
@@ -203,14 +247,14 @@ export function getFirstPartyModulePaths() {
|
|
|
203
247
|
return paths;
|
|
204
248
|
}
|
|
205
249
|
async function getJiti(absPath) {
|
|
206
|
-
const { key,
|
|
250
|
+
const { key, tsconfigPath } = resolveLoaderConfig(path.dirname(absPath));
|
|
207
251
|
const existing = jitiInstances.get(key);
|
|
208
252
|
if (existing)
|
|
209
253
|
return existing;
|
|
210
254
|
const { createJiti } = await import("jiti");
|
|
211
255
|
const created = createJiti(pathToFileURL(absPath).href, {
|
|
212
256
|
moduleCache: true,
|
|
213
|
-
|
|
257
|
+
...(tsconfigPath ? { tsconfigPaths: tsconfigPath } : {}),
|
|
214
258
|
jsx: true,
|
|
215
259
|
});
|
|
216
260
|
jitiInstances.set(key, created);
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACL,kBAAkB,EAElB,WAAW,GAGZ,MAAM,cAAc,CAAC;AAKtB,SAAS,aAAa;IACpB,IAAI,KAAK,IAAI,UAAU;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,MAAM,IAAI,UAAU;QAAE,OAAO,MAAM,CAAC;IACxC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,uFAAuF;AACvF,MAAM,mBAAmB,GAAU,IAAI,GAAG,EAAE,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAA4C,CAAC;AAQ9E;;;;;;;;GAQG;AACH,SAAS,mBAAmB,CAAC,OAAe;IAC1C,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,eAAe,EAAE,mBAAmB,CAAC,CAAC;IAC5E,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;IAE3D,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;AAC7D,CAAC;AAED;;;;;GAKG;AACH,SAAS,4BAA4B,CAAC,QAAwB,EAAE,SAAiB;IAC/E,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,KAAK,CAAC;IACrD,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB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,IAAI,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9D,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IACvF,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;IAChC,IAAI,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,MAAM,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAA4B,CAAC;IAChF,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC5E,SAAS,GAAG,IAAI,CAAC,IAAI,CACnB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;IACF,OAAO,CAAC,MAAM,IAAI,CAA4B,CAAC;AACjD,CAAC"}
|
package/dist/swc.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ZodCompilerPluginOptions } from "./unplugin/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal @swc/core option shape. zod-compiler keeps @swc/core optional so
|
|
4
|
+
* non-SWC users do not install a native dependency just by using the package.
|
|
5
|
+
* `inputSourceMap` matches @swc/core: a JSON string or a boolean — swc does
|
|
6
|
+
* not accept map objects.
|
|
7
|
+
*/
|
|
8
|
+
export interface SwcOptions {
|
|
9
|
+
filename?: string | undefined;
|
|
10
|
+
inputSourceMap?: boolean | string | undefined;
|
|
11
|
+
sourceMaps?: boolean | "inline" | undefined;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface SwcOutput {
|
|
15
|
+
code: string;
|
|
16
|
+
map?: string | undefined;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface SwcCoreLike {
|
|
20
|
+
transform(code: string, options?: SwcOptions): Promise<SwcOutput>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Plugin options that make sense for a transformer host. `apply` is Vite
|
|
24
|
+
* lifecycle and `cache` is the bundler disk cache — the bridge keeps no
|
|
25
|
+
* persistent cache, so hosts that need one must key transform results on
|
|
26
|
+
* content themselves. `include`/`exclude` are honored: files they reject
|
|
27
|
+
* pass through to SWC without the zod-compiler step.
|
|
28
|
+
*/
|
|
29
|
+
export type ZodCompilerSwcOptions = Omit<ZodCompilerPluginOptions, "apply" | "cache" | "codegenMode"> & {
|
|
30
|
+
/**
|
|
31
|
+
* SWC is a transformer, not a bundler plugin host, so inline is the safe
|
|
32
|
+
* default. Lean mode may emit virtual runtime imports that SWC cannot resolve
|
|
33
|
+
* unless another tool handles them after SWC.
|
|
34
|
+
*/
|
|
35
|
+
codegenMode?: "inline" | "lean" | undefined;
|
|
36
|
+
};
|
|
37
|
+
export interface SwcBridgeDefaults {
|
|
38
|
+
/** Options passed through to @swc/core.transform. */
|
|
39
|
+
swc?: SwcOptions | undefined;
|
|
40
|
+
/** zod-compiler options. Defaults match the build plugins except codegenMode is "inline". */
|
|
41
|
+
zodCompiler?: ZodCompilerSwcOptions | undefined;
|
|
42
|
+
}
|
|
43
|
+
export interface SwcBridgeTransformOptions extends SwcBridgeDefaults {
|
|
44
|
+
/** Absolute or project-relative filename for schema discovery and SWC config resolution. */
|
|
45
|
+
filename: string;
|
|
46
|
+
}
|
|
47
|
+
export interface SwcBridge {
|
|
48
|
+
transform(code: string, options: SwcBridgeTransformOptions): Promise<SwcOutput>;
|
|
49
|
+
transformFile(filename: string, options?: SwcBridgeDefaults): Promise<SwcOutput>;
|
|
50
|
+
}
|
|
51
|
+
export declare function transform(code: string, options: SwcBridgeTransformOptions): Promise<SwcOutput>;
|
|
52
|
+
export declare function transformFile(filename: string, options?: SwcBridgeDefaults): Promise<SwcOutput>;
|
|
53
|
+
export declare function createSwcCompiler(defaults?: SwcBridgeDefaults): SwcBridge;
|
|
54
|
+
/**
|
|
55
|
+
* Test seam for the SWC bridge. It is exported because it is also useful for
|
|
56
|
+
* custom hosts that already own a @swc/core-compatible transform function.
|
|
57
|
+
*/
|
|
58
|
+
export declare function transformWithSwc(swc: SwcCoreLike, code: string, options: SwcBridgeTransformOptions): Promise<SwcOutput>;
|
|
59
|
+
export default function zodCompiler(defaults?: SwcBridgeDefaults): SwcBridge;
|
|
60
|
+
//# sourceMappingURL=swc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swc.d.ts","sourceRoot":"","sources":["../src/swc.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoB,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEtF;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IAC9C,UAAU,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GA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AC,EAAE,iBAAiB,GAAG,SAAS,CAE3E"}
|
package/dist/swc.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { invalidateModuleCache } from "./loader.js";
|
|
4
|
+
import { shouldTransform, transformCodeWithMap } from "./unplugin/transform.js";
|
|
5
|
+
function toTransformOptions(options) {
|
|
6
|
+
const output = options?.output ?? "schema";
|
|
7
|
+
return {
|
|
8
|
+
mode: options?.codegenMode ?? "inline",
|
|
9
|
+
verbose: options?.verbose,
|
|
10
|
+
zodCompat: output === "schema" || output === "compact",
|
|
11
|
+
compact: output === "compact",
|
|
12
|
+
autoDiscover: (options?.schemas ?? "auto") === "auto",
|
|
13
|
+
stripUnknownKeys: options?.stripUnknownKeys,
|
|
14
|
+
hoist: options?.hoist,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Per-call options win key-by-key over factory defaults. The merge is
|
|
19
|
+
* shallow: a per-call `swc.jsc` replaces the default `jsc` wholesale rather
|
|
20
|
+
* than deep-merging parser/target settings.
|
|
21
|
+
*/
|
|
22
|
+
function mergeOptions(defaults, options) {
|
|
23
|
+
return {
|
|
24
|
+
filename: options.filename,
|
|
25
|
+
swc: { ...defaults?.swc, ...options.swc },
|
|
26
|
+
zodCompiler: { ...defaults?.zodCompiler, ...options.zodCompiler },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async function loadSwc() {
|
|
30
|
+
try {
|
|
31
|
+
return (await import("@swc/core"));
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const cause = error instanceof Error ? `: ${error.message}` : "";
|
|
35
|
+
throw new Error(`zod-compiler/swc requires @swc/core to be installed by the consuming project${cause}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Last content seen per filename. Discovery executes schema files from DISK
|
|
40
|
+
* through a module cache that outlives transform calls, so when a host (dev
|
|
41
|
+
* server, watch-mode test runner) re-transforms a file with new content, the
|
|
42
|
+
* stale executions must be dropped or the compiled validators keep
|
|
43
|
+
* reflecting the old schema. Same content-diff scheme as the unplugin
|
|
44
|
+
* transform hook; tracked for every file fed to the bridge — an excluded
|
|
45
|
+
* file can still be a dependency a schema file executed.
|
|
46
|
+
*/
|
|
47
|
+
const lastSeenCode = new Map();
|
|
48
|
+
function invalidateOnContentChange(filename, code) {
|
|
49
|
+
const key = path.resolve(filename);
|
|
50
|
+
const previous = lastSeenCode.get(key);
|
|
51
|
+
if (previous !== undefined && previous !== code) {
|
|
52
|
+
invalidateModuleCache();
|
|
53
|
+
}
|
|
54
|
+
lastSeenCode.set(key, code);
|
|
55
|
+
}
|
|
56
|
+
async function transformWith(swc, code, options) {
|
|
57
|
+
invalidateOnContentChange(options.filename, code);
|
|
58
|
+
const zodResult = shouldTransform(options.filename, options.zodCompiler)
|
|
59
|
+
? await transformCodeWithMap(code, options.filename, toTransformOptions(options.zodCompiler))
|
|
60
|
+
: null;
|
|
61
|
+
const swcOptions = {
|
|
62
|
+
...options.swc,
|
|
63
|
+
filename: options.swc?.filename ?? options.filename,
|
|
64
|
+
};
|
|
65
|
+
if (zodResult?.map && swcOptions.inputSourceMap === undefined) {
|
|
66
|
+
swcOptions.inputSourceMap = JSON.stringify(zodResult.map);
|
|
67
|
+
}
|
|
68
|
+
return swc.transform(zodResult?.code ?? code, swcOptions);
|
|
69
|
+
}
|
|
70
|
+
export async function transform(code, options) {
|
|
71
|
+
return transformWith(await loadSwc(), code, options);
|
|
72
|
+
}
|
|
73
|
+
export async function transformFile(filename, options) {
|
|
74
|
+
const code = await fs.readFile(filename, "utf8");
|
|
75
|
+
return transform(code, { ...options, filename });
|
|
76
|
+
}
|
|
77
|
+
export function createSwcCompiler(defaults) {
|
|
78
|
+
return {
|
|
79
|
+
transform(code, options) {
|
|
80
|
+
return transform(code, mergeOptions(defaults, options));
|
|
81
|
+
},
|
|
82
|
+
async transformFile(filename, options) {
|
|
83
|
+
const code = await fs.readFile(filename, "utf8");
|
|
84
|
+
return transform(code, mergeOptions(defaults, { ...options, filename }));
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Test seam for the SWC bridge. It is exported because it is also useful for
|
|
90
|
+
* custom hosts that already own a @swc/core-compatible transform function.
|
|
91
|
+
*/
|
|
92
|
+
export async function transformWithSwc(swc, code, options) {
|
|
93
|
+
return transformWith(swc, code, options);
|
|
94
|
+
}
|
|
95
|
+
export default function zodCompiler(defaults) {
|
|
96
|
+
return createSwcCompiler(defaults);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=swc.js.map
|
package/dist/swc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swc.js","sourceRoot":"","sources":["../src/swc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AA8DhF,SAAS,kBAAkB,CAAC,OAA+B;IACzD,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,QAAQ,CAAC;IAC3C,OAAO;QACL,IAAI,EAAE,OAAO,EAAE,WAAW,IAAI,QAAQ;QACtC,OAAO,EAAE,OAAO,EAAE,OAAO;QACzB,SAAS,EAAE,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,SAAS;QACtD,OAAO,EAAE,MAAM,KAAK,SAAS;QAC7B,YAAY,EAAE,CAAC,OAAO,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,MAAM;QACrD,gBAAgB,EAAE,OAAO,EAAE,gBAAgB;QAC3C,KAAK,EAAE,OAAO,EAAE,KAAK;KACtB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,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EAAE,OAAO;YACnC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACjD,OAAO,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,QAAQ,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAgB,EAChB,IAAY,EACZ,OAAkC;IAElC,OAAO,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,QAA4B;IAC9D,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
import * as fs from "node:fs";
|
|
40
40
|
import { createRequire } from "node:module";
|
|
41
41
|
import * as path from "node:path";
|
|
42
|
-
import {
|
|
42
|
+
import { resolveTsconfigPathCandidates } from "../loader.js";
|
|
43
43
|
const SOURCE_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
|
|
44
44
|
const NODE_MODULES_SEGMENT = `${path.sep}node_modules${path.sep}`;
|
|
45
45
|
/** Specifier schemes that never resolve to project files. */
|
|
@@ -154,18 +154,18 @@ function requireFor(dir) {
|
|
|
154
154
|
* - null when the dep is intentionally out of scope (node_modules, builtins)
|
|
155
155
|
* - UNRESOLVED when resolution failed and the graph cannot be trusted
|
|
156
156
|
*/
|
|
157
|
-
function resolveSpecifier(rawSpec, fromDir
|
|
157
|
+
function resolveSpecifier(rawSpec, fromDir) {
|
|
158
158
|
if (SKIP_SPECIFIER.test(rawSpec))
|
|
159
159
|
return null;
|
|
160
160
|
const memoKey = `${fromDir}\0${rawSpec}`;
|
|
161
161
|
const memoized = resolveMemo.get(memoKey);
|
|
162
162
|
if (memoized !== undefined)
|
|
163
163
|
return memoized;
|
|
164
|
-
const result = resolveSpecifierUncached(rawSpec, fromDir
|
|
164
|
+
const result = resolveSpecifierUncached(rawSpec, fromDir);
|
|
165
165
|
resolveMemo.set(memoKey, result);
|
|
166
166
|
return result;
|
|
167
167
|
}
|
|
168
|
-
function resolveSpecifierUncached(rawSpec, fromDir
|
|
168
|
+
function resolveSpecifierUncached(rawSpec, fromDir) {
|
|
169
169
|
// Vite-style resource queries (./logo.svg?url, ./shader.glsl?raw) resolve
|
|
170
170
|
// to the underlying file.
|
|
171
171
|
const q = rawSpec.indexOf("?");
|
|
@@ -176,13 +176,20 @@ function resolveSpecifierUncached(rawSpec, fromDir, aliases) {
|
|
|
176
176
|
const hit = probeFile(path.resolve(fromDir, spec));
|
|
177
177
|
return hit === null ? UNRESOLVED : firstPartyOrNull(hit);
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return
|
|
179
|
+
const { candidates, authoritative } = resolveTsconfigPathCandidates(fromDir, spec);
|
|
180
|
+
for (const candidate of candidates) {
|
|
181
|
+
const hit = probeFile(candidate);
|
|
182
|
+
if (hit !== null) {
|
|
183
|
+
return firstPartyOrNull(hit);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
+
// An authoritative miss (explicit `paths` pattern matched, or the paths
|
|
187
|
+
// config is present but uninterpretable) means the import cannot be
|
|
188
|
+
// trusted. Implicit baseUrl candidates are proposed for EVERY bare
|
|
189
|
+
// specifier (npm packages, `#` imports) and only mean "try baseDir
|
|
190
|
+
// first" — a miss falls through to node resolution below.
|
|
191
|
+
if (authoritative)
|
|
192
|
+
return UNRESOLVED;
|
|
186
193
|
// Bare specifier (package) or package.json "imports" (#...): node
|
|
187
194
|
// resolution from the importing directory. node_modules results are out of
|
|
188
195
|
// scope (zod's version is part of the cache key); symlinked workspace
|
|
@@ -233,12 +240,11 @@ function fileNode(filePath) {
|
|
|
233
240
|
const edges = [];
|
|
234
241
|
const seen = new Set();
|
|
235
242
|
const dir = path.dirname(filePath);
|
|
236
|
-
const aliases = resolveTsconfigAliases(dir);
|
|
237
243
|
for (const m of source.matchAll(STATIC_SPECIFIER)) {
|
|
238
244
|
const spec = m[1];
|
|
239
245
|
if (!spec)
|
|
240
246
|
continue;
|
|
241
|
-
const resolved = resolveSpecifier(spec, dir
|
|
247
|
+
const resolved = resolveSpecifier(spec, dir);
|
|
242
248
|
if (resolved === UNRESOLVED) {
|
|
243
249
|
incomplete = true;
|
|
244
250
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dep-graph.js","sourceRoot":"","sources":["../../src/unplugin/dep-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"dep-graph.js","sourceRoot":"","sources":["../../src/unplugin/dep-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAS7D,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACzF,MAAM,oBAAoB,GAAG,GAAG,IAAI,CAAC,GAAG,eAAe,IAAI,CAAC,GAAG,EAAE,CAAC;AAClE,6DA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AC;IAEhC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,IAAI,OAAO,CAAC,IAAI,GAAG,SAAS;YAAE,OAAO,UAAU,CAAC;QAChD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAY,CAAC;QACnC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5B,yEAAyE;QACzE,+DAA+D;QAC/D,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,UAAU;YAAE,OAAO,UAAU,CAAC;QACxD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACjB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rsbuild.d.ts","sourceRoot":"","sources":["../../src/unplugin/rsbuild.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAG3D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,aAAa,CAUrF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import zodCompilerRspack from "./rspack.js";
|
|
2
|
+
export default function zodCompiler(options) {
|
|
3
|
+
return {
|
|
4
|
+
name: "zod-compiler",
|
|
5
|
+
setup(api) {
|
|
6
|
+
api.modifyRspackConfig((config) => {
|
|
7
|
+
config.plugins ??= [];
|
|
8
|
+
config.plugins.push(zodCompilerRspack(options));
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=rsbuild.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rsbuild.js","sourceRoot":"","sources":["../../src/unplugin/rsbuild.ts"],"names":[],"mappings":"AAEA,OAAO,iBAAiB,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,OAAkC;IACpE,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,KAAK,CAAC,GAAG;YACP,GAAG,CAAC,kBAAkB,CAAC,CAAC,MAAM,EAAE,EAAE;gBAChC,MAAM,CAAC,OAAO,KAAK,EAAE,CAAC;gBACtB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-compiler",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "Compile Zod schemas into zero-overhead validation functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aot",
|
|
@@ -74,11 +74,23 @@
|
|
|
74
74
|
"import": "./dist/unplugin/rspack.js",
|
|
75
75
|
"default": "./dist/unplugin/rspack.js"
|
|
76
76
|
},
|
|
77
|
+
"./rsbuild": {
|
|
78
|
+
"types": "./dist/unplugin/rsbuild.d.ts",
|
|
79
|
+
"source": "./src/unplugin/rsbuild.ts",
|
|
80
|
+
"import": "./dist/unplugin/rsbuild.js",
|
|
81
|
+
"default": "./dist/unplugin/rsbuild.js"
|
|
82
|
+
},
|
|
77
83
|
"./farm": {
|
|
78
84
|
"types": "./dist/unplugin/farm.d.ts",
|
|
79
85
|
"source": "./src/unplugin/farm.ts",
|
|
80
86
|
"import": "./dist/unplugin/farm.js",
|
|
81
87
|
"default": "./dist/unplugin/farm.js"
|
|
88
|
+
},
|
|
89
|
+
"./swc": {
|
|
90
|
+
"types": "./dist/swc.d.ts",
|
|
91
|
+
"source": "./src/swc.ts",
|
|
92
|
+
"import": "./dist/swc.js",
|
|
93
|
+
"default": "./dist/swc.js"
|
|
82
94
|
}
|
|
83
95
|
},
|
|
84
96
|
"scripts": {
|
|
@@ -101,6 +113,8 @@
|
|
|
101
113
|
},
|
|
102
114
|
"devDependencies": {
|
|
103
115
|
"@jridgewell/trace-mapping": "^0.3.31",
|
|
116
|
+
"@rsbuild/core": "^2.1.7",
|
|
117
|
+
"@swc/core": "^1.15.43",
|
|
104
118
|
"@types/node": "catalog:",
|
|
105
119
|
"@types/picomatch": "^4.0.3",
|
|
106
120
|
"@vitest/coverage-v8": "4.1.4",
|
|
@@ -114,7 +128,17 @@
|
|
|
114
128
|
"zod": "catalog:"
|
|
115
129
|
},
|
|
116
130
|
"peerDependencies": {
|
|
131
|
+
"@rsbuild/core": "^1.0.0 || ^2.0.0",
|
|
132
|
+
"@swc/core": ">=1.3.0",
|
|
117
133
|
"zod": "^4.0.0"
|
|
118
134
|
},
|
|
135
|
+
"peerDependenciesMeta": {
|
|
136
|
+
"@rsbuild/core": {
|
|
137
|
+
"optional": true
|
|
138
|
+
},
|
|
139
|
+
"@swc/core": {
|
|
140
|
+
"optional": true
|
|
141
|
+
}
|
|
142
|
+
},
|
|
119
143
|
"packageManager": "pnpm@10.33.1"
|
|
120
144
|
}
|