@cosmicdrift/kumiko-feature-ast 0.391.0 → 0.391.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-feature-ast",
3
- "version": "0.391.0",
3
+ "version": "0.391.1",
4
4
  "description": "Feature-file AST for Kumiko: parse, patch and render feature definitions, the pattern library, and the codemods kumiko-upgrade runs.",
5
5
  "license": "MIT",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -22,8 +22,8 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@cosmicdrift/kumiko-framework": "0.391.0",
26
- "@cosmicdrift/kumiko-types": "0.391.0",
25
+ "@cosmicdrift/kumiko-framework": "0.391.1",
26
+ "@cosmicdrift/kumiko-types": "0.391.1",
27
27
  "ts-morph": "^28.0.0",
28
28
  "zod": "^4.6.7"
29
29
  },
package/src/changes.json CHANGED
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.391.1",
4
+ "type": "fix",
5
+ "title": "Type-aware codemods no longer exhaust memory when the app pins another zod",
6
+ "detail": "ctx-namespaces and remove-engine-payload-casts build their ts-morph project with a resolution host that resolves zod and its subpaths from the app root, so the program holds one zod copy even when bun nests a second version under each framework package. Without zod at the app root, resolution is unchanged. A small app with zod 4.6.6 next to framework packages on 4.6.7 went from 17 GB and 36 s to 1.1 GB and 3 s for ctx-namespaces, with the same rewrites."
7
+ },
2
8
  {
3
9
  "version": "0.391.0",
4
10
  "type": "fix",
@@ -1,9 +1,9 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join, relative, resolve } from "node:path";
3
- import { Project } from "ts-morph";
4
3
  import { type CodemodSite, formatWithBiome } from "./codemod-support.ts";
5
4
  import { collectSourceFiles } from "./collect-source-files.ts";
6
5
  import { transformCtxNamespaces } from "./ctx-namespaces-transform.ts";
6
+ import { createTypeAwareProject } from "./type-aware-project.ts";
7
7
 
8
8
  const NAME = "ctx-namespaces";
9
9
 
@@ -101,10 +101,7 @@ function runGroup(
101
101
  mode: Mode,
102
102
  totals: RunTotals,
103
103
  ): void {
104
- const project = new Project({
105
- ...(tsconfig === undefined ? {} : { tsConfigFilePath: tsconfig }),
106
- skipAddingFilesFromTsConfig: true,
107
- });
104
+ const project = createTypeAwareProject(tsconfig);
108
105
  totals.projects += 1;
109
106
  // Receivers are found through references: a structural helper is only recognised as taking a
110
107
  // handler context when its callers in other files are already part of the project.
@@ -13,8 +13,9 @@
13
13
  // program, so the framework version the app compiles against decides the row type.
14
14
 
15
15
  import { dirname, resolve } from "node:path";
16
- import { type AsExpression, Node, Project, type SourceFile, SyntaxKind, ts } from "ts-morph";
16
+ import { type AsExpression, Node, type Project, type SourceFile, SyntaxKind, ts } from "ts-morph";
17
17
  import { type CodemodResult, runCodemodCli } from "./codemod-support.ts";
18
+ import { createTypeAwareProject } from "./type-aware-project.ts";
18
19
 
19
20
  const CAST_MARKER = "@cast-boundary";
20
21
  const EXECUTOR_TYPES_FILE = "/event-store-executor-types.ts";
@@ -278,7 +279,7 @@ function projectFor(filePath: string): Project | undefined {
278
279
  if (tsconfig === undefined) return undefined;
279
280
  const cached = projectsByTsconfig.get(tsconfig);
280
281
  if (cached !== undefined) return cached;
281
- const project = new Project({ tsConfigFilePath: tsconfig, skipAddingFilesFromTsConfig: true });
282
+ const project = createTypeAwareProject(tsconfig);
282
283
  projectsByTsconfig.set(tsconfig, project);
283
284
  return project;
284
285
  }
@@ -0,0 +1,47 @@
1
+ import { dirname, join, resolve } from "node:path";
2
+ import { Project, type ResolutionHostFactory, ts } from "ts-morph";
3
+
4
+ function isZodSpecifier(moduleName: string): boolean {
5
+ return moduleName === "zod" || moduleName.startsWith("zod/");
6
+ }
7
+
8
+ // A second zod nested under a package makes the checker compare schemas structurally across both
9
+ // copies at every framework call, which exhausts memory; one copy keeps them nominal.
10
+ function appRootZodResolution(appRoot: string): ResolutionHostFactory {
11
+ const appRootAnchor = join(appRoot, "codemod-resolution-anchor.ts");
12
+ return (moduleResolutionHost, getCompilerOptions) => {
13
+ const cache = ts.createModuleResolutionCache(
14
+ appRoot,
15
+ (fileName) => fileName,
16
+ getCompilerOptions(),
17
+ );
18
+ const resolveFrom = (moduleName: string, containingFile: string, options: ts.CompilerOptions) =>
19
+ ts.resolveModuleName(moduleName, containingFile, options, moduleResolutionHost, cache)
20
+ .resolvedModule;
21
+ return {
22
+ resolveModuleNames: (
23
+ moduleNames,
24
+ containingFile,
25
+ _reusedNames,
26
+ _redirectedReference,
27
+ options,
28
+ ) =>
29
+ moduleNames.map(
30
+ (moduleName) =>
31
+ (isZodSpecifier(moduleName)
32
+ ? resolveFrom(moduleName, appRootAnchor, options)
33
+ : undefined) ?? resolveFrom(moduleName, containingFile, options),
34
+ ),
35
+ };
36
+ };
37
+ }
38
+
39
+ export function createTypeAwareProject(tsconfig: string | undefined): Project {
40
+ if (tsconfig === undefined) return new Project({ skipAddingFilesFromTsConfig: true });
41
+ const tsConfigFilePath = resolve(tsconfig);
42
+ return new Project({
43
+ tsConfigFilePath,
44
+ skipAddingFilesFromTsConfig: true,
45
+ resolutionHost: appRootZodResolution(dirname(tsConfigFilePath)),
46
+ });
47
+ }