@zod-to-form/vite 0.3.1 → 0.4.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/query-mode/transform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/query-mode/transform.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAwC,MAAM,mBAAmB,CAAC;AAK7F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAejD,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,SAAS,EAAE,eAAe,CAAC;IAC3B,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,MAAM,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,eAAe,EAAE,MAAM,CAAC;IACxB,0EAA0E;IAC1E,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,2EAA2E;IAC3E,eAAe,EAAE,aAAa,CAAC;IAC/B,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,CA+E5E"}
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
* `plugin.ts` handles all of that.
|
|
10
10
|
*/
|
|
11
11
|
import path from 'node:path';
|
|
12
|
-
import { walkSchema } from '@zod-to-form/core';
|
|
12
|
+
import { registerFlat, registerSchemaConfigs, resolveFieldConfig, walkSchema } from '@zod-to-form/core';
|
|
13
13
|
import { generateFormComponent, generateSchemaLiteFile } from '@zod-to-form/codegen';
|
|
14
|
+
import { z } from 'zod';
|
|
14
15
|
import { buildEffectiveConfig, selectExport } from '../config/load.js';
|
|
15
16
|
/**
|
|
16
17
|
* Default `schemaImportPath` for query-mode targets when the user did not
|
|
@@ -37,6 +38,13 @@ export function compileTarget(input) {
|
|
|
37
38
|
const effectiveConfig = buildEffectiveConfig(config, variant);
|
|
38
39
|
const expectedName = effectiveConfig.exportName || undefined;
|
|
39
40
|
const { name, schema } = selectExport(namespace, schemaFile, expectedName);
|
|
41
|
+
const componentConfig = effectiveConfig.componentConfig;
|
|
42
|
+
const mergedFields = resolveFieldConfig(componentConfig?.fields, componentConfig?.schemas?.[name]?.fields);
|
|
43
|
+
const formRegistry = z.registry();
|
|
44
|
+
registerSchemaConfigs(formRegistry, namespace, componentConfig?.schemas);
|
|
45
|
+
if (Object.keys(mergedFields).length > 0) {
|
|
46
|
+
registerFlat(formRegistry, schema, mergedFields);
|
|
47
|
+
}
|
|
40
48
|
// Walk the schema, optionally with the optimization level the user
|
|
41
49
|
// configured. The result type depends on whether optimization is set.
|
|
42
50
|
const optimization = effectiveConfig.validationLevel
|
|
@@ -46,13 +54,13 @@ export function compileTarget(input) {
|
|
|
46
54
|
let schemaLite = null;
|
|
47
55
|
let schemaLiteInfo = null;
|
|
48
56
|
if (optimization) {
|
|
49
|
-
const result = walkSchema(schema, optimization);
|
|
57
|
+
const result = walkSchema(schema, { ...optimization, formRegistry });
|
|
50
58
|
fields = result.fields;
|
|
51
59
|
schemaLite = result.schemaLite;
|
|
52
60
|
schemaLiteInfo = result.schemaLiteInfo;
|
|
53
61
|
}
|
|
54
62
|
else {
|
|
55
|
-
fields = walkSchema(schema);
|
|
63
|
+
fields = walkSchema(schema, { formRegistry });
|
|
56
64
|
}
|
|
57
65
|
// Build the codegen-facing config: take the effective config but
|
|
58
66
|
// overwrite exportName with the actually-selected name (so auto-detect
|
|
@@ -69,6 +77,12 @@ export function compileTarget(input) {
|
|
|
69
77
|
const isGenerateVariant = /^__generate_\d+$/.test(variant);
|
|
70
78
|
const codegenConfig = {
|
|
71
79
|
...effectiveConfig,
|
|
80
|
+
componentConfig: componentConfig
|
|
81
|
+
? {
|
|
82
|
+
...componentConfig,
|
|
83
|
+
fields: Object.keys(mergedFields).length > 0 ? mergedFields : componentConfig.fields
|
|
84
|
+
}
|
|
85
|
+
: undefined,
|
|
72
86
|
exportName: name,
|
|
73
87
|
componentName: isGenerateVariant ? 'Form' : (effectiveConfig.componentName ?? 'Form'),
|
|
74
88
|
schemaImportPath: effectiveConfig.schemaImportPath ?? defaultSchemaImportPath(schemaFile),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/query-mode/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/query-mode/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,kBAAkB,EAClB,UAAU,EACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAErF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIvE;;;;;;;;GAQG;AACH,SAAS,uBAAuB,CAAC,UAAkB;IACjD,OAAO,KAAK,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;AAC1C,CAAC;AAwBD;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,CA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AAa;QAC9B,UAAU,EAAE,IAAI;KACjB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zod-to-form/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Vite plugin for zod-to-form — transforms ?z2f imports into generated form components and optionally replaces <ZodForm> JSX call sites with generated components at build time",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/pradeepmouli/zod-to-form#readme",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"@babel/types": "^7.29.0",
|
|
51
51
|
"magic-string": "^0.30.21",
|
|
52
52
|
"pathe": "^2.0.3",
|
|
53
|
-
"@zod-to-form/codegen": "0.
|
|
54
|
-
"@zod-to-form/core": "0.
|
|
53
|
+
"@zod-to-form/codegen": "0.9.0",
|
|
54
|
+
"@zod-to-form/core": "0.9.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/babel__traverse": "^7.28.0",
|