@akanjs/cli 3.1.1-rc.0 → 3.1.1-rc.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.
@@ -20,7 +20,7 @@ import { readdir, readFile, stat } from "fs/promises";
20
20
  import path2 from "path";
21
21
  import { RESERVED_ROUTE_CONFIG_EXPORTS } from "akanjs/common";
22
22
  import ignore from "ignore";
23
- import ts3 from "typescript";
23
+ import ts5 from "typescript";
24
24
 
25
25
  // pkgs/@akanjs/devkit/abstractDoc.ts
26
26
  import path from "path";
@@ -156,7 +156,313 @@ class FormSetterScanner {
156
156
  }
157
157
 
158
158
  // pkgs/@akanjs/devkit/ssrScanner.ts
159
+ import ts4 from "typescript";
160
+
161
+ // pkgs/@akanjs/devkit/renderMutationScanner.ts
159
162
  import ts2 from "typescript";
163
+
164
+ class RenderMutationScanner {
165
+ static rule = "akan.ssr.render-mutation";
166
+ static fix = "Send the write from an explicit user action, such as a button that calls a store action. Only a write that is harmless to repeat and safe for anyone to trigger may stay in the render, with `{ duringRender: true }` as the call's option.";
167
+ static #builders = new Set(["page", "layout", "rootLayout"]);
168
+ static #stages = new Set(["render", "guard", "head", "loading", "notFound", "error"]);
169
+ #mutations;
170
+ constructor(mutations) {
171
+ this.#mutations = mutations;
172
+ }
173
+ scan(sourceFiles) {
174
+ return sourceFiles.filter(({ file }) => /^(apps|libs)\/[^/]+\/page\/.+(?<!\.test|\.spec)\.tsx$/.test(file)).flatMap((sourceFile) => this.#scanRoute(sourceFile));
175
+ }
176
+ #scanRoute({ file, sourceFile }) {
177
+ const fetchNames = RenderMutationScanner.#fetchBindingsOf(sourceFile);
178
+ if (!fetchNames.size)
179
+ return [];
180
+ const functions = RenderMutationScanner.#functionsOf(sourceFile);
181
+ const calls = new Set;
182
+ const helpers = new Set;
183
+ const visit = (node, follow) => {
184
+ if (RenderMutationScanner.#isEventHandler(node))
185
+ return;
186
+ if (this.#isRenderMutation(file, node, fetchNames))
187
+ calls.add(node);
188
+ const helper = follow ? RenderMutationScanner.#helperOf(node, functions) : undefined;
189
+ if (helper)
190
+ helpers.add(helper);
191
+ ts2.forEachChild(node, (child) => visit(child, follow));
192
+ };
193
+ for (const body of RenderMutationScanner.#renderBodiesOf(sourceFile, functions))
194
+ visit(body, true);
195
+ for (const helper of helpers)
196
+ visit(helper, false);
197
+ return [...calls].sort((a, b) => a.getStart(sourceFile) - b.getStart(sourceFile)).map((call) => ({
198
+ rule: RenderMutationScanner.rule,
199
+ scope: "ssr",
200
+ severity: "warning",
201
+ file,
202
+ line: sourceFile.getLineAndCharacterOfPosition(call.getStart(sourceFile)).line + 1,
203
+ message: `${call.expression.getText(sourceFile)}() is a mutation sent while the route renders: anyone who opens a link to this page would perform it, and the call is refused unless it passes { duringRender: true }.`,
204
+ fix: RenderMutationScanner.fix
205
+ }));
206
+ }
207
+ #isRenderMutation(file, node, fetchNames) {
208
+ if (!ts2.isCallExpression(node))
209
+ return false;
210
+ const name = RenderMutationScanner.#endpointOf(node.expression, fetchNames);
211
+ if (!name || !this.#mutations.isMutation(file, name))
212
+ return false;
213
+ return !RenderMutationScanner.#optsIn(node, this.#mutations.policyIndexOf(file, name));
214
+ }
215
+ static #isEventHandler(node) {
216
+ return ts2.isJsxAttribute(node) && ts2.isIdentifier(node.name) && /^on[A-Z]/.test(node.name.text);
217
+ }
218
+ static #endpointOf(callee, fetchNames) {
219
+ if (ts2.isPropertyAccessExpression(callee))
220
+ return RenderMutationScanner.#isFetch(callee.expression, fetchNames) ? callee.name.text : null;
221
+ if (ts2.isElementAccessExpression(callee) && ts2.isStringLiteralLike(callee.argumentExpression))
222
+ return RenderMutationScanner.#isFetch(callee.expression, fetchNames) ? callee.argumentExpression.text : null;
223
+ return null;
224
+ }
225
+ static #isFetch(expression, fetchNames) {
226
+ return ts2.isIdentifier(expression) && fetchNames.has(expression.text);
227
+ }
228
+ static #optsIn(call, policyIndex) {
229
+ if (policyIndex === null)
230
+ return false;
231
+ const leading = call.arguments.slice(0, policyIndex + 1);
232
+ if (leading.some((argument) => ts2.isSpreadElement(argument)))
233
+ return true;
234
+ const policy = leading[policyIndex];
235
+ return policy ? RenderMutationScanner.#policyOptsIn(policy) : false;
236
+ }
237
+ static #policyOptsIn(argument) {
238
+ const policy = RenderMutationScanner.#unwrap(argument);
239
+ if (!ts2.isObjectLiteralExpression(policy))
240
+ return !RenderMutationScanner.#cannotBePolicy(policy);
241
+ return policy.properties.some((property) => {
242
+ if (ts2.isSpreadAssignment(property))
243
+ return true;
244
+ if (!ts2.isPropertyAssignment(property) && !ts2.isShorthandPropertyAssignment(property))
245
+ return false;
246
+ if (!(ts2.isIdentifier(property.name) || ts2.isStringLiteral(property.name)))
247
+ return false;
248
+ if (property.name.text !== "duringRender")
249
+ return false;
250
+ if (ts2.isShorthandPropertyAssignment(property))
251
+ return true;
252
+ const value = RenderMutationScanner.#unwrap(property.initializer);
253
+ return value.kind !== ts2.SyntaxKind.FalseKeyword && !(ts2.isIdentifier(value) && value.text === "undefined");
254
+ });
255
+ }
256
+ static #unwrap(expression) {
257
+ let current = expression;
258
+ while (ts2.isParenthesizedExpression(current) || ts2.isAsExpression(current) || ts2.isSatisfiesExpression(current) || ts2.isNonNullExpression(current) || ts2.isTypeAssertionExpression(current))
259
+ current = current.expression;
260
+ return current;
261
+ }
262
+ static #cannotBePolicy(expression) {
263
+ if (ts2.isIdentifier(expression))
264
+ return expression.text === "undefined";
265
+ return ts2.isLiteralExpression(expression) || ts2.isNoSubstitutionTemplateLiteral(expression) || ts2.isTemplateExpression(expression) || ts2.isArrayLiteralExpression(expression) || ts2.isArrowFunction(expression) || ts2.isFunctionExpression(expression) || ts2.isVoidExpression(expression) || ts2.isPrefixUnaryExpression(expression) || [ts2.SyntaxKind.NullKeyword, ts2.SyntaxKind.TrueKeyword, ts2.SyntaxKind.FalseKeyword].includes(expression.kind);
266
+ }
267
+ static #fetchBindingsOf(sourceFile) {
268
+ const names = new Set;
269
+ for (const statement of sourceFile.statements) {
270
+ if (!ts2.isImportDeclaration(statement) || statement.importClause?.isTypeOnly)
271
+ continue;
272
+ const bindings = statement.importClause?.namedBindings;
273
+ if (!bindings || !ts2.isNamedImports(bindings))
274
+ continue;
275
+ for (const element of bindings.elements)
276
+ if (!element.isTypeOnly && (element.propertyName ?? element.name).text === "fetch")
277
+ names.add(element.name.text);
278
+ }
279
+ return names;
280
+ }
281
+ static #functionsOf(sourceFile) {
282
+ const functions = new Map;
283
+ for (const statement of sourceFile.statements) {
284
+ if (ts2.isFunctionDeclaration(statement) && statement.name && statement.body)
285
+ functions.set(statement.name.text, statement.body);
286
+ if (!ts2.isVariableStatement(statement))
287
+ continue;
288
+ for (const declaration of statement.declarationList.declarations) {
289
+ const initializer = declaration.initializer && RenderMutationScanner.#unwrap(declaration.initializer);
290
+ if (!ts2.isIdentifier(declaration.name) || !initializer)
291
+ continue;
292
+ if (ts2.isArrowFunction(initializer) || ts2.isFunctionExpression(initializer))
293
+ functions.set(declaration.name.text, initializer.body);
294
+ }
295
+ }
296
+ return functions;
297
+ }
298
+ static #helperOf(node, functions) {
299
+ const callee = ts2.isCallExpression(node) ? node.expression : ts2.isJsxSelfClosingElement(node) || ts2.isJsxOpeningElement(node) ? node.tagName : undefined;
300
+ return callee && ts2.isIdentifier(callee) ? functions.get(callee.text) : undefined;
301
+ }
302
+ static #renderBodiesOf(sourceFile, functions) {
303
+ const bodies = [];
304
+ const bodyOf = (node) => ts2.isIdentifier(node) ? functions.get(node.text) : node;
305
+ const visit = (node) => {
306
+ if (ts2.isCallExpression(node) && ts2.isPropertyAccessExpression(node.expression) && RenderMutationScanner.#stages.has(node.expression.name.text) && RenderMutationScanner.#isRouteChain(node.expression.expression))
307
+ for (const argument of node.arguments) {
308
+ const body = bodyOf(argument);
309
+ if (body)
310
+ bodies.push(body);
311
+ }
312
+ ts2.forEachChild(node, visit);
313
+ };
314
+ visit(sourceFile);
315
+ for (const statement of sourceFile.statements) {
316
+ const legacy = RenderMutationScanner.#legacyPageOf(statement, functions);
317
+ if (legacy)
318
+ bodies.push(legacy);
319
+ }
320
+ return bodies;
321
+ }
322
+ static #isRouteChain(expression) {
323
+ let current = expression;
324
+ while (ts2.isCallExpression(current)) {
325
+ if (ts2.isIdentifier(current.expression))
326
+ return RenderMutationScanner.#builders.has(current.expression.text);
327
+ if (!ts2.isPropertyAccessExpression(current.expression))
328
+ return false;
329
+ current = current.expression.expression;
330
+ }
331
+ return false;
332
+ }
333
+ static #legacyPageOf(statement, functions) {
334
+ if (ts2.isFunctionDeclaration(statement))
335
+ return statement.modifiers?.some((modifier) => modifier.kind === ts2.SyntaxKind.DefaultKeyword) ? statement.body : undefined;
336
+ if (!ts2.isExportAssignment(statement))
337
+ return;
338
+ const expression = RenderMutationScanner.#unwrap(statement.expression);
339
+ if (ts2.isIdentifier(expression))
340
+ return functions.get(expression.text);
341
+ return ts2.isArrowFunction(expression) || ts2.isFunctionExpression(expression) ? expression.body : undefined;
342
+ }
343
+ }
344
+
345
+ // pkgs/@akanjs/devkit/signalMutationIndex.ts
346
+ import ts3 from "typescript";
347
+
348
+ class SignalMutationIndex {
349
+ static #generatedArgCounts = { create: 1, update: 2, remove: 1, merge: 2 };
350
+ static #argMethods = new Set(["param", "body", "search", "room", "msg"]);
351
+ #shapesByOwner = new Map;
352
+ constructor(sourceFiles) {
353
+ for (const { file, sourceFile } of sourceFiles) {
354
+ if (!/^(apps|libs)\/[^/]+\/lib\/.+\.signal\.ts$/.test(file))
355
+ continue;
356
+ const owner = file.split("/").slice(0, 2).join("/");
357
+ const shapes = this.#shapesByOwner.get(owner) ?? new Map;
358
+ SignalMutationIndex.#collect(sourceFile, shapes);
359
+ this.#shapesByOwner.set(owner, shapes);
360
+ }
361
+ }
362
+ isMutation(consumerFile, name) {
363
+ return this.#shapeOf(consumerFile, name)?.kind === "mutation";
364
+ }
365
+ policyIndexOf(consumerFile, name) {
366
+ const shape = this.#shapeOf(consumerFile, name);
367
+ return shape?.kind === "mutation" ? shape.argCount : null;
368
+ }
369
+ #shapeOf(consumerFile, name) {
370
+ const [root, owner] = consumerFile.split("/");
371
+ const own = root === "apps" ? this.#shapesByOwner.get(`apps/${owner}`)?.get(name) : undefined;
372
+ if (own)
373
+ return own;
374
+ for (const [key, shapes] of this.#shapesByOwner) {
375
+ const shape = shapes.get(name);
376
+ if (key.startsWith("libs/") && shape?.kind === "mutation")
377
+ return shape;
378
+ }
379
+ return;
380
+ }
381
+ static #collect(sourceFile, kinds) {
382
+ const visit = (node) => {
383
+ if (ts3.isCallExpression(node) && ts3.isIdentifier(node.expression)) {
384
+ if (node.expression.text === "slice")
385
+ SignalMutationIndex.#collectGenerated(node, kinds);
386
+ else if (node.expression.text === "endpoint")
387
+ SignalMutationIndex.#collectEndpoints(node, kinds);
388
+ }
389
+ ts3.forEachChild(node, visit);
390
+ };
391
+ visit(sourceFile);
392
+ }
393
+ static #collectGenerated(slice, kinds) {
394
+ let service = slice.arguments[0];
395
+ while (service && ts3.isCallExpression(service) && ts3.isPropertyAccessExpression(service.expression))
396
+ service = service.expression.expression;
397
+ if (!service || !ts3.isPropertyAccessExpression(service) || !SignalMutationIndex.#isNamed(service.expression, "srv"))
398
+ return;
399
+ const model = service.name.text;
400
+ const capModel = `${model.charAt(0).toUpperCase()}${model.slice(1)}`;
401
+ for (const [verb, argCount] of Object.entries(SignalMutationIndex.#generatedArgCounts))
402
+ kinds.set(`${verb}${capModel}`, { kind: "mutation", argCount });
403
+ kinds.set(`add${capModel}Files`, { kind: "mutation", argCount: 2 });
404
+ }
405
+ static #collectEndpoints(endpoint, kinds) {
406
+ const builder = endpoint.arguments[1];
407
+ if (!builder || !ts3.isArrowFunction(builder) && !ts3.isFunctionExpression(builder))
408
+ return;
409
+ const map = SignalMutationIndex.#returnedObjectOf(builder);
410
+ if (!map)
411
+ return;
412
+ const verbOf = SignalMutationIndex.#verbReaderOf(builder.parameters[0]);
413
+ for (const property of map.properties) {
414
+ if (!ts3.isPropertyAssignment(property))
415
+ continue;
416
+ if (!ts3.isIdentifier(property.name) && !ts3.isStringLiteral(property.name))
417
+ continue;
418
+ const { root, argCount } = SignalMutationIndex.#chainOf(property.initializer);
419
+ const verb = verbOf(root);
420
+ const kind = verb === "message" ? "mutation" : verb;
421
+ if (kind === "query" || kind === "mutation")
422
+ kinds.set(property.name.text, { kind, argCount });
423
+ }
424
+ }
425
+ static #returnedObjectOf(builder) {
426
+ let body = builder.body;
427
+ if (ts3.isBlock(body))
428
+ body = body.statements.find(ts3.isReturnStatement)?.expression;
429
+ while (body && ts3.isParenthesizedExpression(body))
430
+ body = body.expression;
431
+ return body && ts3.isObjectLiteralExpression(body) ? body : null;
432
+ }
433
+ static #verbReaderOf(parameter) {
434
+ const verbs = new Map;
435
+ if (parameter && ts3.isObjectBindingPattern(parameter.name))
436
+ for (const element of parameter.name.elements) {
437
+ const verb = element.propertyName ?? element.name;
438
+ if (ts3.isIdentifier(verb) && ts3.isIdentifier(element.name))
439
+ verbs.set(element.name.text, verb.text);
440
+ }
441
+ const holder = parameter && ts3.isIdentifier(parameter.name) ? parameter.name.text : null;
442
+ return (callee) => {
443
+ if (callee && ts3.isIdentifier(callee))
444
+ return verbs.get(callee.text);
445
+ if (callee && ts3.isPropertyAccessExpression(callee) && SignalMutationIndex.#isNamed(callee.expression, holder))
446
+ return callee.name.text;
447
+ return;
448
+ };
449
+ }
450
+ static #isNamed(expression, name) {
451
+ return ts3.isIdentifier(expression) && expression.text === name;
452
+ }
453
+ static #chainOf(initializer) {
454
+ let root = initializer;
455
+ let argCount = 0;
456
+ while (ts3.isCallExpression(root) && ts3.isPropertyAccessExpression(root.expression) && ts3.isCallExpression(root.expression.expression)) {
457
+ if (SignalMutationIndex.#argMethods.has(root.expression.name.text))
458
+ argCount += 1;
459
+ root = root.expression.expression;
460
+ }
461
+ return { root: ts3.isCallExpression(root) ? root.expression : undefined, argCount };
462
+ }
463
+ }
464
+
465
+ // pkgs/@akanjs/devkit/ssrScanner.ts
160
466
  var STATIC_COMPONENT_MIN_MASS = 4;
161
467
  var MIXED_COMPONENT_MIN_MASS = 10;
162
468
  var MIXED_COMPONENT_MAX_TOUCHES = 2;
@@ -167,17 +473,20 @@ class SsrScanner {
167
473
  static #serverSafeCalls = new Set(["usePage", "getSelf", "useServer"]);
168
474
  static #clientGlobals = new Set("window document navigator localStorage sessionStorage location history screen matchMedia IntersectionObserver".split(" ").concat("ResizeObserver MutationObserver requestAnimationFrame WebSocket".split(" ")));
169
475
  static #clientRuntimeImports = new Set(["st", "fetch"]);
476
+ static #mountWriteFix = "Send the write from an explicit user action, such as a button that calls a store action. Do not move it into the route: a write there runs for anyone who opens a link to the page.";
170
477
  scan(sourceFiles) {
478
+ const mutations = new SignalMutationIndex(sourceFiles);
171
479
  const componentFiles = sourceFiles.filter((sourceFile) => this.#isBalancedFile(sourceFile.file));
172
480
  return {
173
481
  warnings: [
174
- ...componentFiles.flatMap((sourceFile) => this.#scanFile(sourceFile)),
175
- ...this.#scanModules(componentFiles)
482
+ ...componentFiles.flatMap((sourceFile) => this.#scanFile(sourceFile, mutations)),
483
+ ...this.#scanModules(componentFiles),
484
+ ...new RenderMutationScanner(mutations).scan(sourceFiles)
176
485
  ],
177
486
  balance: this.#measureBalance(componentFiles)
178
487
  };
179
488
  }
180
- #scanFile(sourceFile) {
489
+ #scanFile(sourceFile, mutations) {
181
490
  if (!this.#hasUseClient(sourceFile.sourceFile))
182
491
  return [];
183
492
  const vendorNames = this.#getVendorNames(sourceFile.sourceFile);
@@ -199,7 +508,7 @@ class SsrScanner {
199
508
  warnings.push(fileWarning("akan.ssr.client-static-markup", "ssr", sourceFile.file, `Client component "${component.name}" renders ${component.mass} JSX elements around only ${component.touches.length} client-only touch (${[...new Set(component.touches)].join(", ")}). Most of this subtree does not need the client bundle.`, component.line));
200
509
  }
201
510
  }
202
- warnings.push(...this.#getMountLoadWarnings(sourceFile));
511
+ warnings.push(...this.#getMountLoadWarnings(sourceFile, mutations));
203
512
  warnings.push(...this.#getTemplateStateWarnings(sourceFile));
204
513
  return warnings;
205
514
  }
@@ -218,29 +527,34 @@ class SsrScanner {
218
527
  }
219
528
  return [...modules].filter(([, entry]) => entry.serverFiles === 0 && entry.clientMass >= MODULE_SERVER_VIEW_MIN_CLIENT_MASS).map(([moduleDir, entry]) => fileWarning("akan.ssr.module-missing-server-view", "ssr", entry.line, `Module "${moduleDir}" renders ${entry.clientMass} JSX elements from client files only; it declares no Unit or View server component.`));
220
529
  }
221
- #getMountLoadWarnings(sourceFile) {
530
+ #getMountLoadWarnings(sourceFile, mutations) {
222
531
  const warnings = [];
223
532
  SsrScanner.#walk(sourceFile.sourceFile, (node) => {
224
533
  if (!this.#isMountEffect(sourceFile.sourceFile, node))
225
534
  return;
226
- for (const load of this.#getLoadCalls(sourceFile.sourceFile, node))
227
- warnings.push(fileWarning("akan.ssr.client-mount-load", "ssr", sourceFile.file, `Mount-only effect loads server data with ${load.callee}(). The route can fetch this before the first byte instead.`, this.#getLine(sourceFile.sourceFile, load.node)));
535
+ for (const load of this.#getLoadCalls(sourceFile.sourceFile, node)) {
536
+ const line = this.#getLine(sourceFile.sourceFile, load.node);
537
+ warnings.push(load.callee.startsWith("fetch.") && mutations.isMutation(sourceFile.file, load.callee.slice("fetch.".length)) ? {
538
+ ...fileWarning("akan.ssr.client-mount-load", "ssr", sourceFile.file, `Mount-only effect sends the mutation ${load.callee}() each time the component mounts. A write is not data the route can load.`, line),
539
+ fix: SsrScanner.#mountWriteFix
540
+ } : fileWarning("akan.ssr.client-mount-load", "ssr", sourceFile.file, `Mount-only effect loads server data with ${load.callee}(). The route can fetch this before the first byte instead.`, line));
541
+ }
228
542
  });
229
543
  return warnings;
230
544
  }
231
545
  #isMountEffect(sourceFile, node) {
232
- if (!ts2.isCallExpression(node))
546
+ if (!ts4.isCallExpression(node))
233
547
  return false;
234
548
  const callee = node.expression.getText(sourceFile);
235
549
  if (callee !== "useEffect" && callee !== "useLayoutEffect")
236
550
  return false;
237
551
  const deps = node.arguments[1];
238
- return !!deps && ts2.isArrayLiteralExpression(deps) && deps.elements.length === 0;
552
+ return !!deps && ts4.isArrayLiteralExpression(deps) && deps.elements.length === 0;
239
553
  }
240
554
  #getLoadCalls(sourceFile, node) {
241
555
  const calls = [];
242
556
  SsrScanner.#walk(node, (child) => {
243
- if (!ts2.isCallExpression(child))
557
+ if (!ts4.isCallExpression(child))
244
558
  return;
245
559
  const callee = child.expression.getText(sourceFile);
246
560
  if (/^fetch\.[a-z]/.test(callee) || /^st\.do\.(init|get|view|load|list|count|insight)[A-Z]/.test(callee))
@@ -253,7 +567,7 @@ class SsrScanner {
253
567
  return [];
254
568
  const warnings = [];
255
569
  SsrScanner.#walk(sourceFile.sourceFile, (node) => {
256
- if (ts2.isCallExpression(node) && node.expression.getText(sourceFile.sourceFile) === "useState")
570
+ if (ts4.isCallExpression(node) && node.expression.getText(sourceFile.sourceFile) === "useState")
257
571
  warnings.push(fileWarning("akan.ssr.template-client-state", "ssr", sourceFile.file, "Template holds form state in useState. Templates are store-driven and carry no local state.", this.#getLine(sourceFile.sourceFile, node)));
258
572
  });
259
573
  return warnings;
@@ -296,14 +610,14 @@ class SsrScanner {
296
610
  return components;
297
611
  }
298
612
  #getComponentNodes(statement) {
299
- if (ts2.isFunctionDeclaration(statement) && statement.body)
613
+ if (ts4.isFunctionDeclaration(statement) && statement.body)
300
614
  return [{ name: statement.name?.text ?? "default", node: statement.body }];
301
- if (!ts2.isVariableStatement(statement))
615
+ if (!ts4.isVariableStatement(statement))
302
616
  return [];
303
617
  return statement.declarationList.declarations.flatMap((declaration) => {
304
- if (!ts2.isIdentifier(declaration.name) || !declaration.initializer)
618
+ if (!ts4.isIdentifier(declaration.name) || !declaration.initializer)
305
619
  return [];
306
- if (!ts2.isArrowFunction(declaration.initializer) && !ts2.isFunctionExpression(declaration.initializer))
620
+ if (!ts4.isArrowFunction(declaration.initializer) && !ts4.isFunctionExpression(declaration.initializer))
307
621
  return [];
308
622
  return [{ name: declaration.name.text, node: declaration.initializer }];
309
623
  });
@@ -311,7 +625,7 @@ class SsrScanner {
311
625
  #getTouches(sourceFile, node) {
312
626
  const touches = [];
313
627
  SsrScanner.#walk(node, (child) => {
314
- if (ts2.isCallExpression(child)) {
628
+ if (ts4.isCallExpression(child)) {
315
629
  const callee = child.expression.getText(sourceFile);
316
630
  const bareName = callee.split(".").pop() ?? callee;
317
631
  if (callee === "createContext" || callee === "lazy")
@@ -319,9 +633,9 @@ class SsrScanner {
319
633
  else if (/^use[A-Z]/.test(bareName) && !SsrScanner.#serverSafeCalls.has(bareName))
320
634
  touches.push(bareName);
321
635
  }
322
- if (ts2.isJsxAttribute(child) && /^on[A-Z]/.test(child.name.getText(sourceFile)))
636
+ if (ts4.isJsxAttribute(child) && /^on[A-Z]/.test(child.name.getText(sourceFile)))
323
637
  touches.push(child.name.getText(sourceFile));
324
- if (ts2.isPropertyAccessExpression(child)) {
638
+ if (ts4.isPropertyAccessExpression(child)) {
325
639
  const root = getAccessRoot(child);
326
640
  if (root === "st")
327
641
  touches.push("st");
@@ -334,7 +648,7 @@ class SsrScanner {
334
648
  #getTagNames(sourceFile, node) {
335
649
  const tags = new Set;
336
650
  SsrScanner.#walk(node, (child) => {
337
- if (ts2.isJsxOpeningElement(child) || ts2.isJsxSelfClosingElement(child))
651
+ if (ts4.isJsxOpeningElement(child) || ts4.isJsxSelfClosingElement(child))
338
652
  tags.add(child.tagName.getText(sourceFile).split(".")[0]);
339
653
  });
340
654
  return tags;
@@ -342,7 +656,7 @@ class SsrScanner {
342
656
  #getMass(node) {
343
657
  let mass = 0;
344
658
  SsrScanner.#walk(node, (child) => {
345
- if (ts2.isJsxOpeningElement(child) || ts2.isJsxSelfClosingElement(child))
659
+ if (ts4.isJsxOpeningElement(child) || ts4.isJsxSelfClosingElement(child))
346
660
  mass += 1;
347
661
  });
348
662
  return mass;
@@ -350,30 +664,30 @@ class SsrScanner {
350
664
  static #walk(node, visit) {
351
665
  const walk = (child) => {
352
666
  visit(child);
353
- ts2.forEachChild(child, walk);
667
+ ts4.forEachChild(child, walk);
354
668
  };
355
- ts2.forEachChild(node, walk);
669
+ ts4.forEachChild(node, walk);
356
670
  }
357
671
  #hasUseClient(sourceFile) {
358
672
  const first = sourceFile.statements[0];
359
- if (!first || !ts2.isExpressionStatement(first) || !ts2.isStringLiteral(first.expression))
673
+ if (!first || !ts4.isExpressionStatement(first) || !ts4.isStringLiteral(first.expression))
360
674
  return false;
361
675
  return first.expression.text === "use client";
362
676
  }
363
677
  #hasVendorImport(sourceFile) {
364
- return sourceFile.statements.some((statement) => ts2.isImportDeclaration(statement) && isVendorSpecifier(getSpecifier(statement)));
678
+ return sourceFile.statements.some((statement) => ts4.isImportDeclaration(statement) && isVendorSpecifier(getSpecifier(statement)));
365
679
  }
366
680
  #getVendorNames(sourceFile) {
367
681
  const names = new Set;
368
682
  for (const statement of sourceFile.statements) {
369
- if (!ts2.isImportDeclaration(statement) || !isVendorSpecifier(getSpecifier(statement)))
683
+ if (!ts4.isImportDeclaration(statement) || !isVendorSpecifier(getSpecifier(statement)))
370
684
  continue;
371
685
  const clause = statement.importClause;
372
686
  if (clause?.name)
373
687
  names.add(clause.name.text);
374
- if (clause?.namedBindings && ts2.isNamespaceImport(clause.namedBindings))
688
+ if (clause?.namedBindings && ts4.isNamespaceImport(clause.namedBindings))
375
689
  names.add(clause.namedBindings.name.text);
376
- if (clause?.namedBindings && ts2.isNamedImports(clause.namedBindings))
690
+ if (clause?.namedBindings && ts4.isNamedImports(clause.namedBindings))
377
691
  for (const element of clause.namedBindings.elements)
378
692
  names.add(element.name.text);
379
693
  }
@@ -381,10 +695,10 @@ class SsrScanner {
381
695
  }
382
696
  #importsClientRuntime(sourceFile) {
383
697
  for (const statement of sourceFile.statements) {
384
- if (!ts2.isImportDeclaration(statement))
698
+ if (!ts4.isImportDeclaration(statement))
385
699
  continue;
386
700
  const bindings = statement.importClause?.namedBindings;
387
- if (!bindings || !ts2.isNamedImports(bindings))
701
+ if (!bindings || !ts4.isNamedImports(bindings))
388
702
  continue;
389
703
  if (bindings.elements.some((element) => SsrScanner.#clientRuntimeImports.has(element.name.text)))
390
704
  return true;
@@ -435,7 +749,7 @@ function getShare(serverMass, clientMass) {
435
749
  return total === 0 ? 1 : serverMass / total;
436
750
  }
437
751
  function getSpecifier(statement) {
438
- return ts2.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : "";
752
+ return ts4.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : "";
439
753
  }
440
754
  function isVendorSpecifier(specifier) {
441
755
  if (specifier === "" || specifier.startsWith(".") || specifier.startsWith("/"))
@@ -448,9 +762,9 @@ function isVendorSpecifier(specifier) {
448
762
  }
449
763
  function getAccessRoot(node) {
450
764
  let current = node;
451
- while (ts2.isPropertyAccessExpression(current))
765
+ while (ts4.isPropertyAccessExpression(current))
452
766
  current = current.expression;
453
- return ts2.isIdentifier(current) ? current.text : "";
767
+ return ts4.isIdentifier(current) ? current.text : "";
454
768
  }
455
769
 
456
770
  // pkgs/@akanjs/devkit/qualityScanner.ts
@@ -588,7 +902,7 @@ class AkanQualityScanner {
588
902
  file,
589
903
  absolutePath,
590
904
  content,
591
- sourceFile: ts3.createSourceFile(file, content, ts3.ScriptTarget.Latest, true, getScriptKind(file))
905
+ sourceFile: ts5.createSourceFile(file, content, ts5.ScriptTarget.Latest, true, getScriptKind(file))
592
906
  };
593
907
  }
594
908
  async#readTextFile(workspaceRoot, file) {
@@ -785,13 +1099,13 @@ function getExportedFunctionLikes(sourceFile) {
785
1099
  duplicateNameExempt: nameExempt || isConventionDuplicateNameExempt(sourceFile.file, isEnumClass)
786
1100
  });
787
1101
  for (const statement of sourceFile.sourceFile.statements) {
788
- if (ts3.isFunctionDeclaration(statement) && statement.name && isExported(statement))
1102
+ if (ts5.isFunctionDeclaration(statement) && statement.name && isExported(statement))
789
1103
  add(statement.name.text, "function", statement, statement.body);
790
- if (ts3.isClassDeclaration(statement) && statement.name && isExported(statement))
1104
+ if (ts5.isClassDeclaration(statement) && statement.name && isExported(statement))
791
1105
  add(statement.name.text, "class", statement, statement, isEnumClassStatement(sourceFile.sourceFile, statement));
792
- if (ts3.isVariableStatement(statement) && isExported(statement)) {
1106
+ if (ts5.isVariableStatement(statement) && isExported(statement)) {
793
1107
  for (const declaration of statement.declarationList.declarations) {
794
- if (!ts3.isIdentifier(declaration.name) || !isFunctionLikeInitializer(declaration.initializer))
1108
+ if (!ts5.isIdentifier(declaration.name) || !isFunctionLikeInitializer(declaration.initializer))
795
1109
  continue;
796
1110
  add(declaration.name.text, "function-variable", declaration, declaration.initializer);
797
1111
  }
@@ -819,14 +1133,14 @@ function isConventionDuplicateNameExempt(file, isEnumClass) {
819
1133
  return false;
820
1134
  }
821
1135
  function isEnumClassStatement(sourceFile, statement) {
822
- if (!ts3.isClassDeclaration(statement))
1136
+ if (!ts5.isClassDeclaration(statement))
823
1137
  return false;
824
- const heritageClause = statement.heritageClauses?.find((clause) => clause.token === ts3.SyntaxKind.ExtendsKeyword);
1138
+ const heritageClause = statement.heritageClauses?.find((clause) => clause.token === ts5.SyntaxKind.ExtendsKeyword);
825
1139
  const expression = heritageClause?.types[0]?.expression;
826
1140
  return !!expression && expression.getText(sourceFile).startsWith("enumOf(");
827
1141
  }
828
1142
  function getExportedClassNames(sourceFile) {
829
- return sourceFile.statements.filter((statement) => ts3.isClassDeclaration(statement)).filter((statement) => isExported(statement)).map((statement) => statement.name?.text).filter((name) => !!name);
1143
+ return sourceFile.statements.filter((statement) => ts5.isClassDeclaration(statement)).filter((statement) => isExported(statement)).map((statement) => statement.name?.text).filter((name) => !!name);
830
1144
  }
831
1145
  function isComponentDeclarationFile(file) {
832
1146
  if (!file.endsWith(".tsx"))
@@ -842,7 +1156,7 @@ function isComponentDeclarationFile(file) {
842
1156
  function getComponentFileDeclarations(sourceFile) {
843
1157
  const reExportedNames = new Set;
844
1158
  for (const statement of sourceFile.statements) {
845
- if (ts3.isExportDeclaration(statement) && statement.exportClause && ts3.isNamedExports(statement.exportClause)) {
1159
+ if (ts5.isExportDeclaration(statement) && statement.exportClause && ts5.isNamedExports(statement.exportClause)) {
846
1160
  for (const element of statement.exportClause.elements)
847
1161
  reExportedNames.add((element.propertyName ?? element.name).text);
848
1162
  }
@@ -852,19 +1166,19 @@ function getComponentFileDeclarations(sourceFile) {
852
1166
  const isDefaultExport = isDefaultExportStatement(statement);
853
1167
  const inlineExported = isExported(statement);
854
1168
  const add = (name, kind, line) => declarations.push({ name, kind, line, exported: inlineExported || reExportedNames.has(name), isDefaultExport });
855
- if (ts3.isInterfaceDeclaration(statement))
1169
+ if (ts5.isInterfaceDeclaration(statement))
856
1170
  add(statement.name.text, "interface", getLine(sourceFile, statement));
857
- else if (ts3.isTypeAliasDeclaration(statement))
1171
+ else if (ts5.isTypeAliasDeclaration(statement))
858
1172
  add(statement.name.text, "type", getLine(sourceFile, statement));
859
- else if (ts3.isEnumDeclaration(statement))
1173
+ else if (ts5.isEnumDeclaration(statement))
860
1174
  add(statement.name.text, "enum", getLine(sourceFile, statement));
861
- else if (ts3.isFunctionDeclaration(statement) && statement.name)
1175
+ else if (ts5.isFunctionDeclaration(statement) && statement.name)
862
1176
  add(statement.name.text, "function", getLine(sourceFile, statement));
863
- else if (ts3.isClassDeclaration(statement) && statement.name)
1177
+ else if (ts5.isClassDeclaration(statement) && statement.name)
864
1178
  add(statement.name.text, "class", getLine(sourceFile, statement));
865
- else if (ts3.isVariableStatement(statement)) {
1179
+ else if (ts5.isVariableStatement(statement)) {
866
1180
  for (const declaration of statement.declarationList.declarations) {
867
- if (!ts3.isIdentifier(declaration.name))
1181
+ if (!ts5.isIdentifier(declaration.name))
868
1182
  continue;
869
1183
  const kind = isFunctionLikeInitializer(declaration.initializer) ? "function" : "variable";
870
1184
  add(declaration.name.text, kind, getLine(sourceFile, declaration));
@@ -876,15 +1190,15 @@ function getComponentFileDeclarations(sourceFile) {
876
1190
  function getCompoundComponentNames(sourceFile) {
877
1191
  const names = new Set;
878
1192
  for (const statement of sourceFile.statements) {
879
- if (!ts3.isExpressionStatement(statement))
1193
+ if (!ts5.isExpressionStatement(statement))
880
1194
  continue;
881
1195
  const { expression } = statement;
882
- if (!ts3.isBinaryExpression(expression) || expression.operatorToken.kind !== ts3.SyntaxKind.EqualsToken)
1196
+ if (!ts5.isBinaryExpression(expression) || expression.operatorToken.kind !== ts5.SyntaxKind.EqualsToken)
883
1197
  continue;
884
- if (!ts3.isPropertyAccessExpression(expression.left) || !isPascalCaseName(expression.left.name.text))
1198
+ if (!ts5.isPropertyAccessExpression(expression.left) || !isPascalCaseName(expression.left.name.text))
885
1199
  continue;
886
1200
  names.add(expression.left.name.text);
887
- if (ts3.isIdentifier(expression.right) && isPascalCaseName(expression.right.text))
1201
+ if (ts5.isIdentifier(expression.right) && isPascalCaseName(expression.right.text))
888
1202
  names.add(expression.right.text);
889
1203
  }
890
1204
  return names;
@@ -904,11 +1218,11 @@ function isPascalCaseName(name) {
904
1218
  return /^[A-Z]/.test(name) && !/^[A-Z0-9_]+$/.test(name);
905
1219
  }
906
1220
  function isDefaultExportStatement(statement) {
907
- if (ts3.isExportAssignment(statement))
1221
+ if (ts5.isExportAssignment(statement))
908
1222
  return !statement.isExportEquals;
909
- if (!ts3.canHaveModifiers(statement))
1223
+ if (!ts5.canHaveModifiers(statement))
910
1224
  return false;
911
- return !!ts3.getModifiers(statement)?.some((modifier) => modifier.kind === ts3.SyntaxKind.DefaultKeyword);
1225
+ return !!ts5.getModifiers(statement)?.some((modifier) => modifier.kind === ts5.SyntaxKind.DefaultKeyword);
912
1226
  }
913
1227
  function getBangCommentWarnings(sourceFile) {
914
1228
  if (!isClientReachableFile(sourceFile.file))
@@ -944,11 +1258,11 @@ function getGlobalMutationWarnings(sourceFile) {
944
1258
  const warnings = [];
945
1259
  for (const statement of sourceFile.sourceFile.statements) {
946
1260
  const warn = (rule, message) => warnings.push(fileWarning(rule, "file", sourceFile.file, message, getLine(sourceFile.sourceFile, statement)));
947
- if (ts3.isModuleDeclaration(statement) && statement.name.getText(sourceFile.sourceFile) === "global")
1261
+ if (ts5.isModuleDeclaration(statement) && statement.name.getText(sourceFile.sourceFile) === "global")
948
1262
  warn("akan.file.global-declaration", "Global declarations require an explicit low-level integration allowlist.");
949
- if (ts3.isInterfaceDeclaration(statement) && statement.name.text === "Window")
1263
+ if (ts5.isInterfaceDeclaration(statement) && statement.name.text === "Window")
950
1264
  warn("akan.file.window-augmentation", "Window augmentation should be isolated to approved browser integration files.");
951
- if (ts3.isExpressionStatement(statement) && statement.expression.getText(sourceFile.sourceFile).includes(".prototype."))
1265
+ if (ts5.isExpressionStatement(statement) && statement.expression.getText(sourceFile.sourceFile).includes(".prototype."))
952
1266
  warn("akan.file.prototype-mutation", "Prototype mutation should be avoided or isolated to approved low-level integration files.");
953
1267
  }
954
1268
  return warnings;
@@ -965,19 +1279,19 @@ function getTopLevelDeclaration(sourceFile, statement) {
965
1279
  exported: isExported(statement),
966
1280
  node: statement
967
1281
  });
968
- if (ts3.isClassDeclaration(statement) && statement.name)
1282
+ if (ts5.isClassDeclaration(statement) && statement.name)
969
1283
  return [declared(statement.name.text, "class")];
970
- if (ts3.isFunctionDeclaration(statement) && statement.name)
1284
+ if (ts5.isFunctionDeclaration(statement) && statement.name)
971
1285
  return [declared(statement.name.text, "function")];
972
- if (ts3.isInterfaceDeclaration(statement))
1286
+ if (ts5.isInterfaceDeclaration(statement))
973
1287
  return [declared(statement.name.text, "interface")];
974
- if (ts3.isTypeAliasDeclaration(statement))
1288
+ if (ts5.isTypeAliasDeclaration(statement))
975
1289
  return [declared(statement.name.text, "type")];
976
- if (ts3.isEnumDeclaration(statement))
1290
+ if (ts5.isEnumDeclaration(statement))
977
1291
  return [declared(statement.name.text, "enum")];
978
- if (ts3.isVariableStatement(statement))
979
- return statement.declarationList.declarations.filter((declaration) => ts3.isIdentifier(declaration.name)).map((declaration) => declared(declaration.name.text, "variable", getLine(sourceFile, declaration)));
980
- if (ts3.isExportDeclaration(statement))
1292
+ if (ts5.isVariableStatement(statement))
1293
+ return statement.declarationList.declarations.filter((declaration) => ts5.isIdentifier(declaration.name)).map((declaration) => declared(declaration.name.text, "variable", getLine(sourceFile, declaration)));
1294
+ if (ts5.isExportDeclaration(statement))
981
1295
  return [{ name: "export declaration", kind: "export", line, exported: true, node: statement }];
982
1296
  return [];
983
1297
  }
@@ -1065,13 +1379,13 @@ function getModuleInfo(file) {
1065
1379
  return { moduleName, fileName, kind: "database" };
1066
1380
  }
1067
1381
  function isExportedConst(declaration) {
1068
- return declaration.exported && ts3.isVariableStatement(declaration.node) && (declaration.node.declarationList.flags & ts3.NodeFlags.Const) !== 0;
1382
+ return declaration.exported && ts5.isVariableStatement(declaration.node) && (declaration.node.declarationList.flags & ts5.NodeFlags.Const) !== 0;
1069
1383
  }
1070
1384
  function isExported(node) {
1071
- return !!(ts3.getCombinedModifierFlags(node) & ts3.ModifierFlags.Export);
1385
+ return !!(ts5.getCombinedModifierFlags(node) & ts5.ModifierFlags.Export);
1072
1386
  }
1073
1387
  function isFunctionLikeInitializer(node) {
1074
- return !!node && (ts3.isArrowFunction(node) || ts3.isFunctionExpression(node));
1388
+ return !!node && (ts5.isArrowFunction(node) || ts5.isFunctionExpression(node));
1075
1389
  }
1076
1390
  function getBodyFingerprint(sourceFile, node) {
1077
1391
  if (!node)
@@ -1093,7 +1407,7 @@ async function isDirectory(absolutePath) {
1093
1407
  }
1094
1408
  }
1095
1409
  function getScriptKind(file) {
1096
- return file.endsWith(".tsx") ? ts3.ScriptKind.TSX : ts3.ScriptKind.TS;
1410
+ return file.endsWith(".tsx") ? ts5.ScriptKind.TSX : ts5.ScriptKind.TS;
1097
1411
  }
1098
1412
  function getLine(sourceFile, node) {
1099
1413
  return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;