@cosmicdrift/kumiko-feature-ast 0.414.0 → 0.416.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,3 +1,5 @@
1
+ import { IRREVERSIBLE_WITHOUT_ENTRY_HANDLER_CASES, } from "@cosmicdrift/kumiko-types/config";
2
+ import { isOneOf } from "@cosmicdrift/kumiko-types/type-guards";
1
3
  import { SyntaxKind } from "ts-morph";
2
4
  import { SCREEN_OPAQUE_MARKER } from "../patterns.js";
3
5
  import { sourceLocationFromNode } from "../source-location.js";
@@ -102,6 +104,15 @@ export function extractMultiStreamProjection(call, sourceFile) {
102
104
  const delivery = deliveryLit
103
105
  ? deliveryLit.getLiteralValue()
104
106
  : undefined;
107
+ const irreversibleLit = arg
108
+ .getProperty("irreversibleWithoutEntryHandler")
109
+ ?.asKind(SyntaxKind.PropertyAssignment)
110
+ ?.getInitializer()
111
+ ?.asKind(SyntaxKind.StringLiteral);
112
+ const irreversibleValue = irreversibleLit?.getLiteralValue();
113
+ const irreversibleWithoutEntryHandler = isOneOf(IRREVERSIBLE_WITHOUT_ENTRY_HANDLER_CASES, irreversibleValue)
114
+ ? irreversibleValue
115
+ : undefined;
105
116
  return ok({
106
117
  kind: "multiStreamProjection",
107
118
  source: sourceLocationFromNode(call, sourceFile),
@@ -110,6 +121,7 @@ export function extractMultiStreamProjection(call, sourceFile) {
110
121
  ...(isPlainObject(errorMode) && { errorMode: errorMode }),
111
122
  ...(runIn !== undefined && { runIn }),
112
123
  ...(delivery !== undefined && { delivery }),
124
+ ...(irreversibleWithoutEntryHandler !== undefined && { irreversibleWithoutEntryHandler }),
113
125
  });
114
126
  }
115
127
  export function collectScreenOpaqueProps(node, path, sourceFile, out) {
@@ -1,5 +1,5 @@
1
1
  import type { AccessRule, AgentHandlerHints, ClaimKeyType, ConfigKeyDefinition, ConfigKeyType, EntityDefinition, EscapeHatchDeclaration, JobDefinition, LifecycleHookType, MspErrorMode, NavDefinition, ReferenceDataDef, RelationDefinition, ScreenDefinition, SecretNamespaceOptions, TranslationKeys, TreeActionDef, WorkspaceDefinition } from "@cosmicdrift/kumiko-framework/engine";
2
- import type { RunIn } from "@cosmicdrift/kumiko-types/config";
2
+ import type { IrreversibleWithoutEntryHandler, RunIn } from "@cosmicdrift/kumiko-types/config";
3
3
  import type { MetricOptions, SecretOptions } from "@cosmicdrift/kumiko-types/feature";
4
4
  import type { PayloadRateLimitOption, RateLimitDeclaration } from "@cosmicdrift/kumiko-types/handlers";
5
5
  import type { HookPhase } from "@cosmicdrift/kumiko-types/hook-phase";
@@ -223,6 +223,7 @@ export type MultiStreamProjectionPattern = {
223
223
  readonly errorMode?: MspErrorMode;
224
224
  readonly runIn?: RunIn;
225
225
  readonly delivery?: "shared" | "per-instance";
226
+ readonly irreversibleWithoutEntryHandler?: IrreversibleWithoutEntryHandler;
226
227
  };
227
228
  export type DefineEventPattern = {
228
229
  readonly kind: "defineEvent";
package/dist/render.js CHANGED
@@ -527,6 +527,9 @@ function renderMultiStreamProjection(p) {
527
527
  lines.push(` runIn: ${renderValue(p.runIn)},`);
528
528
  if (p.delivery !== undefined)
529
529
  lines.push(` delivery: ${JSON.stringify(p.delivery)},`);
530
+ if (p.irreversibleWithoutEntryHandler !== undefined) {
531
+ lines.push(` irreversibleWithoutEntryHandler: ${JSON.stringify(p.irreversibleWithoutEntryHandler)},`);
532
+ }
530
533
  lines.push("});");
531
534
  return lines.join("\n");
532
535
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-feature-ast",
3
- "version": "0.414.0",
3
+ "version": "0.416.0",
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.414.0",
26
- "@cosmicdrift/kumiko-types": "0.414.0",
25
+ "@cosmicdrift/kumiko-framework": "0.416.0",
26
+ "@cosmicdrift/kumiko-types": "0.416.0",
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.415.0",
4
+ "type": "fix",
5
+ "title": "lint-ignore-to-biome skips no-raw-hooks markers outside the plugin scope",
6
+ "detail": "The no-raw-hooks Biome plugin only scans .tsx files under web/ and public/, without tests, renderer, document-designer and samples. Converting a marker elsewhere produced a `biome-ignore` that suppresses nothing. The codemod now keeps such markers as they are."
7
+ },
2
8
  {
3
9
  "version": "0.414.0",
4
10
  "type": "fix",
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
1
+ import { existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join, relative, resolve } from "node:path";
3
3
  import {
4
4
  type ImportDeclaration,
@@ -278,7 +278,8 @@ function displayPath(file: string): string {
278
278
 
279
279
  export interface CodemodCliConfig {
280
280
  readonly name: string;
281
- readonly transform: (source: string, filePath: string) => CodemodResult;
281
+ // projectRoot: nearest ancestor of the target with a Biome config, else the target itself.
282
+ readonly transform: (source: string, filePath: string, projectRoot: string) => CodemodResult;
282
283
  readonly isSkippedPath: (file: string) => boolean;
283
284
  // Exact file names (e.g. package.json) handed to transform next to the .ts/.tsx sources.
284
285
  readonly extraFileNames?: readonly string[];
@@ -301,17 +302,29 @@ function parseArgsOrUsageError(
301
302
  }
302
303
  }
303
304
 
305
+ function findProjectRoot(target: string): string {
306
+ const start = resolve(target);
307
+ let dir = statSync(start).isDirectory() ? start : dirname(start);
308
+ for (;;) {
309
+ if (existsSync(join(dir, "biome.json")) || existsSync(join(dir, "biome.jsonc"))) return dir;
310
+ const parent = dirname(dir);
311
+ if (parent === dir) return statSync(start).isDirectory() ? start : dirname(start);
312
+ dir = parent;
313
+ }
314
+ }
315
+
304
316
  function transformFiles(
305
317
  config: CodemodCliConfig,
306
318
  files: readonly string[],
307
319
  mode: Mode,
320
+ projectRoot: string,
308
321
  ): { rewrites: CodemodSite[]; manual: CodemodSite[]; changedFiles: string[] } {
309
322
  const rewrites: CodemodSite[] = [];
310
323
  const manual: CodemodSite[] = [];
311
324
  const changedFiles: string[] = [];
312
325
  for (const file of files) {
313
326
  const before = readFileSync(file, "utf8");
314
- const result = config.transform(before, file);
327
+ const result = config.transform(before, file, projectRoot);
315
328
  const shown = displayPath(file);
316
329
  for (const site of result.rewrites)
317
330
  console.log(`${shown}:${site.line} rewritten ${site.description}`);
@@ -349,7 +362,12 @@ export async function runCodemod(
349
362
  (config.extraFileNames?.includes(name) ?? false) ||
350
363
  (config.extraExtensions?.some((extension) => name.endsWith(extension)) ?? false),
351
364
  }).filter((file) => !(file.includes("/__tests__/fixtures/") || config.isSkippedPath(file)));
352
- const { rewrites, manual, changedFiles } = transformFiles(config, files, options.mode);
365
+ const { rewrites, manual, changedFiles } = transformFiles(
366
+ config,
367
+ files,
368
+ options.mode,
369
+ findProjectRoot(options.paths[0] ?? "."),
370
+ );
353
371
  console.log(
354
372
  `\n[${config.name}] ${options.mode === "write" ? "rewritten" : "rewritable"}: ${rewrites.length} site(s) in ${new Set(rewrites.map((site) => site.file)).size} file(s); manual: ${manual.length}`,
355
373
  );
@@ -8,7 +8,10 @@
8
8
  //
9
9
  // Usage: bun scripts/codemod/lint-ignore-to-biome.ts <targetDir> [--check | --dry-run]
10
10
 
11
+ import { relative } from "node:path";
12
+ import preset from "@cosmicdrift/kumiko-framework/biome-rules" with { type: "json" };
11
13
  import { ts } from "ts-morph";
14
+ import * as z from "zod";
12
15
  import {
13
16
  type CodemodCliConfig,
14
17
  type CodemodResult,
@@ -20,21 +23,62 @@ const MIN_REASON_WORDS = 3;
20
23
 
21
24
  const PLUGIN_RULE = "lint/plugin";
22
25
  const INLINE_STYLES_RULE = "lint/style/noInlineStyles";
26
+ const PROCESS_ENV_RULE = "lint/style/noProcessEnv";
27
+ const RESTRICTED_IMPORTS_RULE = "lint/style/noRestrictedImports";
23
28
 
24
29
  // Slugs of the guards deleted in the guards-to-biome move; each maps to the rule that replaces it.
25
30
  const DELETED_GUARD_SLUG_RULES: ReadonlyMap<string, string> = new Map([
31
+ ["admin-api", PLUGIN_RULE],
26
32
  ["direct-fetch", PLUGIN_RULE],
27
33
  ["direct-fs", PLUGIN_RULE],
34
+ ["error-reasons", PLUGIN_RULE],
35
+ ["es-literal-writes", PLUGIN_RULE],
36
+ ["event-store-writes", PLUGIN_RULE],
28
37
  ["i18n-locale-terminology", PLUGIN_RULE],
29
38
  ["no-custom-primitives", PLUGIN_RULE],
39
+ ["no-date-api", PLUGIN_RULE],
40
+ ["no-direct-process-env", PROCESS_ENV_RULE],
30
41
  ["no-inline-styles", INLINE_STYLES_RULE],
31
42
  ["no-raw-hooks", PLUGIN_RULE],
43
+ ["no-temporal-polyfill-import", RESTRICTED_IMPORTS_RULE],
32
44
  ["primitives-discipline", PLUGIN_RULE],
33
45
  ["raw-classname", PLUGIN_RULE],
34
46
  ["raw-interactive-elements", PLUGIN_RULE],
47
+ ["restricted-symbols", PLUGIN_RULE],
48
+ ["test-es-fixtures", PLUGIN_RULE],
35
49
  ["test-title", PLUGIN_RULE],
50
+ ["unsafe-json-parse", PLUGIN_RULE],
36
51
  ]);
37
52
 
53
+ const presetPluginsSchema = z.object({
54
+ plugins: z.array(z.object({ path: z.string(), includes: z.array(z.string()).optional() })),
55
+ });
56
+
57
+ // Outside the plugin's includes a converted marker would be a `biome-ignore` that suppresses
58
+ // nothing, which Biome reports as unused. The includes come from the preset itself.
59
+ function noRawHooksIncludes(): { positive: Bun.Glob[]; negative: Bun.Glob[] } {
60
+ const plugin = presetPluginsSchema
61
+ .parse(preset)
62
+ .plugins.find((candidate) => candidate.path.endsWith("/no-raw-hooks.grit"));
63
+ const includes = plugin?.includes ?? [];
64
+ const toGlobs = (patterns: string[]): Bun.Glob[] =>
65
+ patterns.map((pattern) => new Bun.Glob(pattern));
66
+ return {
67
+ positive: toGlobs(includes.filter((pattern) => !pattern.startsWith("!"))),
68
+ negative: toGlobs(includes.filter((pattern) => pattern.startsWith("!")).map((p) => p.slice(1))),
69
+ };
70
+ }
71
+
72
+ const NO_RAW_HOOKS_INCLUDES = noRawHooksIncludes();
73
+
74
+ function isPluginScopeOfSlug(slug: string, relativePath: string): boolean {
75
+ if (slug !== "no-raw-hooks") return true;
76
+ return (
77
+ NO_RAW_HOOKS_INCLUDES.positive.some((glob) => glob.match(relativePath)) &&
78
+ !NO_RAW_HOOKS_INCLUDES.negative.some((glob) => glob.match(relativePath))
79
+ );
80
+ }
81
+
38
82
  const MARKER_RE = /^\s*\**\s*kumiko-lint-ignore\s+([\w-]+(?:,[\w-]+)*)(?:\s+([\s\S]*))?$/;
39
83
 
40
84
  type CommentRange = { readonly pos: number; readonly end: number; readonly line: number };
@@ -71,7 +115,7 @@ type Rewrite =
71
115
  | { readonly kind: "unconverted"; readonly note: string }
72
116
  | { readonly kind: "untouched" };
73
117
 
74
- function rewriteComment(commentText: string): Rewrite {
118
+ function rewriteComment(commentText: string, relativePath: string): Rewrite {
75
119
  const isBlock = commentText.startsWith("/*");
76
120
  const body = isBlock ? commentText.slice(2, -2) : commentText.slice(2);
77
121
  const match = MARKER_RE.exec(body);
@@ -84,7 +128,9 @@ function rewriteComment(commentText: string): Rewrite {
84
128
  : { kind: "untouched" };
85
129
  }
86
130
  const slugs = (match[1] ?? "").split(",");
87
- const deleted = slugs.filter((slug) => DELETED_GUARD_SLUG_RULES.has(slug));
131
+ const deleted = slugs.filter(
132
+ (slug) => DELETED_GUARD_SLUG_RULES.has(slug) && isPluginScopeOfSlug(slug, relativePath),
133
+ );
88
134
  if (deleted.length === 0) return { kind: "untouched" };
89
135
 
90
136
  const rules = new Set(deleted.map((slug) => DELETED_GUARD_SLUG_RULES.get(slug)));
@@ -113,7 +159,15 @@ function mentionsDeletedSlug(body: string): boolean {
113
159
  return [...DELETED_GUARD_SLUG_RULES.keys()].some((slug) => body.includes(slug));
114
160
  }
115
161
 
116
- function migrateLintIgnoreMarkers(text: string, file: string): CodemodResult {
162
+ // Biome does not honour a trailing suppression; only a lone `{` (JSX comment container) may precede.
163
+ function isTrailingComment(text: string, commentPos: number): boolean {
164
+ const lineStart = text.lastIndexOf("\n", commentPos - 1) + 1;
165
+ const before = text.slice(lineStart, commentPos).trim();
166
+ return before !== "" && before !== "{";
167
+ }
168
+
169
+ function migrateLintIgnoreMarkers(text: string, file: string, projectRoot: string): CodemodResult {
170
+ const relativePath = relative(projectRoot, file).split("\\").join("/");
117
171
  const rewrites: CodemodSite[] = [];
118
172
  const manual: CodemodSite[] = [];
119
173
  if (!text.includes("kumiko-lint-ignore")) return { output: text, rewrites, manual };
@@ -126,8 +180,16 @@ function migrateLintIgnoreMarkers(text: string, file: string): CodemodResult {
126
180
  );
127
181
  let output = text;
128
182
  for (const comment of collectComments(sourceFile).reverse()) {
129
- const rewrite = rewriteComment(text.slice(comment.pos, comment.end));
183
+ const rewrite = rewriteComment(text.slice(comment.pos, comment.end), relativePath);
130
184
  if (rewrite.kind === "untouched") continue;
185
+ if (rewrite.kind === "converted" && isTrailingComment(text, comment.pos)) {
186
+ manual.push({
187
+ file,
188
+ line: comment.line,
189
+ description: "trailing marker, move it above the hit as `// biome-ignore ...`",
190
+ });
191
+ continue;
192
+ }
131
193
  if (rewrite.kind === "unconverted") {
132
194
  manual.push({ file, line: comment.line, description: rewrite.note });
133
195
  continue;