zodvex 0.7.1-beta.2 → 0.7.1-beta.3

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":"codemod.d.ts","sourceRoot":"","sources":["../../src/cli/codemod.ts"],"names":[],"mappings":"AAaA,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,IAAI,CAAC,CA+Df"}
1
+ {"version":3,"file":"codemod.d.ts","sourceRoot":"","sources":["../../src/cli/codemod.ts"],"names":[],"mappings":"AAyBA,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,IAAI,CAAC,CA6Ef"}
package/dist/cli/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
- import fs2, { readFileSync, writeFileSync } from 'fs';
3
- import path3, { resolve, relative } from 'path';
2
+ import fs2, { readFileSync, writeFileSync, existsSync } from 'fs';
3
+ import path3, { resolve, relative, join } from 'path';
4
4
  import { Project, SyntaxKind } from 'ts-morph';
5
5
  import { globSync } from 'tinyglobby';
6
6
  import { $ZodCodec, $ZodNumber, $ZodCustom, $ZodOptional, $ZodNullable, $ZodObject, $ZodUnion, $ZodArray, $ZodRecord, $ZodTuple, $ZodString, $ZodBoolean, $ZodNull, $ZodUndefined, $ZodAny, $ZodEnum, $ZodLiteral } from 'zod/v4/core';
@@ -417,6 +417,16 @@ function transformClassRefs(file) {
417
417
  neededImports.add(replacement);
418
418
  count++;
419
419
  }
420
+ const qualNames = file.getDescendantsOfKind(SyntaxKind.QualifiedName);
421
+ for (const qn of qualNames) {
422
+ if (qn.wasForgotten()) continue;
423
+ const text = qn.getText();
424
+ const replacement = CLASS_RENAMES[text];
425
+ if (!replacement) continue;
426
+ qn.replaceWithText(replacement);
427
+ neededImports.add(replacement);
428
+ count++;
429
+ }
420
430
  if (neededImports.size > 0) {
421
431
  const existingCoreImport = file.getImportDeclaration(
422
432
  (d) => d.getModuleSpecifierValue() === "zod/v4/core"
@@ -569,6 +579,7 @@ var init_transforms = __esm({
569
579
  "z.ZodError": "$ZodError",
570
580
  "z.ZodType": "$ZodType",
571
581
  "z.ZodTypeAny": "$ZodType",
582
+ "z.ZodRawShape": "$ZodShape",
572
583
  "z.ZodObject": "$ZodObject",
573
584
  "z.ZodArray": "$ZodArray",
574
585
  "z.ZodString": "$ZodString",
@@ -583,7 +594,11 @@ var init_transforms = __esm({
583
594
  "z.ZodCustom": "$ZodCustom",
584
595
  "z.ZodDefault": "$ZodDefault",
585
596
  "z.ZodRecord": "$ZodRecord",
586
- "z.ZodTuple": "$ZodTuple"
597
+ "z.ZodTuple": "$ZodTuple",
598
+ "z.ZodDiscriminatedUnion": "$ZodDiscriminatedUnion",
599
+ "z.ZodLazy": "$ZodLazy",
600
+ "z.ZodPipe": "$ZodPipe",
601
+ "z.ZodTransform": "$ZodTransform"
587
602
  };
588
603
  }
589
604
  });
@@ -646,6 +661,16 @@ var codemod_exports = {};
646
661
  __export(codemod_exports, {
647
662
  runToMiniCodemod: () => runToMiniCodemod
648
663
  });
664
+ function findTsconfig(startDir) {
665
+ let dir = startDir;
666
+ while (true) {
667
+ const candidate = join(dir, "tsconfig.json");
668
+ if (existsSync(candidate)) return candidate;
669
+ const parent = resolve(dir, "..");
670
+ if (parent === dir) return void 0;
671
+ dir = parent;
672
+ }
673
+ }
649
674
  async function runToMiniCodemod(targetDir, options = {}) {
650
675
  const { transformCode: transformCode2, transformImports: transformImports2 } = await Promise.resolve().then(() => (init_src(), src_exports));
651
676
  const { Project: Project3 } = await import('ts-morph');
@@ -655,6 +680,15 @@ async function runToMiniCodemod(targetDir, options = {}) {
655
680
  ignore: ["_generated/**", "_zodvex/**", "**/*.d.ts", "node_modules/**"],
656
681
  absolute: true
657
682
  });
683
+ let typeProject;
684
+ const tsconfigPath = findTsconfig(dir);
685
+ if (tsconfigPath) {
686
+ typeProject = new Project3({
687
+ tsConfigFilePath: tsconfigPath,
688
+ skipAddingFilesFromTsConfig: true
689
+ });
690
+ console.log(`[zodvex codemod] Using type checker (${relative(process.cwd(), tsconfigPath)})`);
691
+ }
658
692
  console.log(
659
693
  `[zodvex codemod] ${options.dryRun ? "Dry run \u2014 " : ""}Processing ${files.length} files in ${targetDir}/`
660
694
  );
@@ -663,7 +697,10 @@ async function runToMiniCodemod(targetDir, options = {}) {
663
697
  for (const filePath of files) {
664
698
  const code = readFileSync(filePath, "utf-8");
665
699
  if (!code.includes("'zod'") && !code.includes('"zod"')) continue;
666
- const result = transformCode2(code);
700
+ const result = transformCode2(code, {
701
+ filename: filePath,
702
+ project: typeProject
703
+ });
667
704
  let output = result.code;
668
705
  const project = new Project3({ useInMemoryFileSystem: true });
669
706
  const sf = project.createSourceFile("tmp.ts", output);
@@ -1591,8 +1628,8 @@ Usage:
1591
1628
  zodvex init Set up zodvex in an existing Convex project
1592
1629
  zodvex migrate [dir] Migrate pre-0.6 APIs (renames + import fixes)
1593
1630
  zodvex migrate [dir] --dry-run Preview changes without writing
1594
- zodvex codemod --to-mini [dir] Convert full-zod code to zod/mini syntax
1595
- zodvex codemod --to-mini [dir] --dry-run Preview changes without writing
1631
+ zodvex codemod --to-mini [dir] Convert full-zod code to zod/mini syntax
1632
+ zodvex codemod --to-mini [dir] --dry-run Preview changes without writing
1596
1633
  zodvex help Show this help message
1597
1634
 
1598
1635
  Flags: