@cosmicdrift/kumiko-feature-ast 0.390.1 → 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.390.1",
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.390.1",
26
- "@cosmicdrift/kumiko-types": "0.390.1",
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,16 @@
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
+ },
8
+ {
9
+ "version": "0.391.0",
10
+ "type": "fix",
11
+ "title": "Codemods no longer fail when git is not installed",
12
+ "detail": "collectSourceFiles asks git check-ignore which files the repository's .gitignore excludes. Without a git executable Bun.spawnSync threw ENOENT and kumiko-upgrade --apply aborted at the first codemod, for example ctx-namespaces in the customer-app builder image. A missing git is now treated like a directory outside a repository: no file is filtered."
13
+ },
2
14
  {
3
15
  "version": "0.390.1",
4
16
  "type": "fix",
@@ -1,5 +1,6 @@
1
1
  import { lstatSync, readdirSync, statSync } from "node:fs";
2
2
  import { dirname, join, resolve } from "node:path";
3
+ import { errorCodeOf } from "@cosmicdrift/kumiko-types/type-guards";
3
4
 
4
5
  export const BUILD_AND_VENDOR_DIR_NAMES: readonly string[] = [
5
6
  "node_modules",
@@ -68,15 +69,26 @@ export function envWithoutGitRepositoryOverrides(): Record<string, string> {
68
69
  // a codemod must not rewrite them.
69
70
  function withoutGitIgnored(cwd: string, files: readonly string[]): readonly string[] {
70
71
  if (files.length === 0) return files;
71
- const result = Bun.spawnSync({
72
- cmd: ["git", "check-ignore", "--stdin", "-z"],
73
- cwd,
74
- env: envWithoutGitRepositoryOverrides(),
75
- stdin: Buffer.from(`${files.join("\0")}\0`),
76
- stdout: "pipe",
77
- stderr: "pipe",
78
- });
79
- if (result.exitCode !== GIT_CHECK_IGNORE_SOME_IGNORED) return files;
72
+ const result = runGitCheckIgnore(cwd, files);
73
+ if (result === undefined || result.exitCode !== GIT_CHECK_IGNORE_SOME_IGNORED) return files;
80
74
  const ignored = new Set(result.stdout.toString().split("\0"));
81
75
  return files.filter((file) => !ignored.has(file));
82
76
  }
77
+
78
+ function runGitCheckIgnore(cwd: string, files: readonly string[]) {
79
+ try {
80
+ return Bun.spawnSync({
81
+ cmd: ["git", "check-ignore", "--stdin", "-z"],
82
+ cwd,
83
+ env: envWithoutGitRepositoryOverrides(),
84
+ stdin: Buffer.from(`${files.join("\0")}\0`),
85
+ stdout: "pipe",
86
+ stderr: "pipe",
87
+ });
88
+ } catch (error) {
89
+ // Build images such as the customer-app builder ship without git; like outside a repository,
90
+ // there is no .gitignore to honour then.
91
+ if (errorCodeOf(error) === "ENOENT") return undefined;
92
+ throw error;
93
+ }
94
+ }
@@ -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
+ }