@akanjs/language 3.2.0-rc.17 → 3.2.0-rc.19
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/guardResolver.d.ts +2 -6
- package/index.cjs +317 -146
- package/index.js +317 -146
- package/package.json +1 -1
- package/server.js +317 -146
package/server.js
CHANGED
|
@@ -5,6 +5,38 @@ import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "n
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
|
|
8
|
+
// pkgs/akanjs/common/facetBarrel.ts
|
|
9
|
+
var barrelFacetDirs = ["ui", "webkit", "srvkit", "common", "plugin"];
|
|
10
|
+
var sourceFilePattern = /\.(ts|tsx)$/;
|
|
11
|
+
var excludedFilePattern = /(^index\.tsx?$|\.d\.ts$|\.(test|spec)\.(ts|tsx)$|\.css$|\.scss$|\.sass$)/;
|
|
12
|
+
var pascalCasePattern = /^[A-Z][A-Za-z0-9]*$/;
|
|
13
|
+
var camelCasePattern = /^[a-z][A-Za-z0-9]*$/;
|
|
14
|
+
var letterRankOf = (char) => char.toLowerCase().charCodeAt(0) * 2 + (char === char.toLowerCase() ? 1 : 0);
|
|
15
|
+
var digitRunAt = (name, idx) => /^\d+/.exec(name.slice(idx))?.[0] ?? "";
|
|
16
|
+
var compareExportNames = (a, b) => {
|
|
17
|
+
for (let idx = 0;idx < a.length && idx < b.length; ) {
|
|
18
|
+
const [runA, runB] = [digitRunAt(a, idx), digitRunAt(b, idx)];
|
|
19
|
+
if (runA && runB && runA !== runB)
|
|
20
|
+
return runA.length - runB.length || (runA < runB ? -1 : 1);
|
|
21
|
+
if (runA && runB)
|
|
22
|
+
idx += runA.length;
|
|
23
|
+
else if (runA || runB)
|
|
24
|
+
return runA ? -1 : 1;
|
|
25
|
+
else if (a.charAt(idx) !== b.charAt(idx))
|
|
26
|
+
return letterRankOf(a.charAt(idx)) - letterRankOf(b.charAt(idx));
|
|
27
|
+
else
|
|
28
|
+
idx++;
|
|
29
|
+
}
|
|
30
|
+
return a.length - b.length;
|
|
31
|
+
};
|
|
32
|
+
var facetBarrelNamesOf = (facet, files, dirs) => {
|
|
33
|
+
const nameCasePattern = facet === "ui" ? pascalCasePattern : camelCasePattern;
|
|
34
|
+
return [
|
|
35
|
+
...files.filter((file) => sourceFilePattern.test(file) && !excludedFilePattern.test(file)).map((file) => file.replace(sourceFilePattern, "")),
|
|
36
|
+
...dirs.filter((dir) => !dir.startsWith("."))
|
|
37
|
+
].filter((name) => nameCasePattern.test(name)).sort(compareExportNames);
|
|
38
|
+
};
|
|
39
|
+
|
|
8
40
|
// pkgs/@akanjs/language/escapeRegExp.ts
|
|
9
41
|
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
10
42
|
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
@@ -286,7 +318,7 @@ var ownerOf = (relativePath) => {
|
|
|
286
318
|
const [root, name] = relativePath.split("/");
|
|
287
319
|
return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
|
|
288
320
|
};
|
|
289
|
-
var
|
|
321
|
+
var syntaxReaderOf = (ts, ast) => {
|
|
290
322
|
const spanOf = (source, node) => {
|
|
291
323
|
const start = node.getStart(source);
|
|
292
324
|
const end = node.getEnd();
|
|
@@ -344,6 +376,74 @@ var createFactReader = (ts, ast) => {
|
|
|
344
376
|
const node = keyName(property);
|
|
345
377
|
return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
|
|
346
378
|
});
|
|
379
|
+
const verbReaderOf = (parameter) => {
|
|
380
|
+
const verbs = new Map;
|
|
381
|
+
if (parameter && ts.isObjectBindingPattern(parameter.name))
|
|
382
|
+
for (const element of parameter.name.elements) {
|
|
383
|
+
const verb = element.propertyName ?? element.name;
|
|
384
|
+
if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
|
|
385
|
+
verbs.set(element.name.text, verb.text);
|
|
386
|
+
}
|
|
387
|
+
const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
|
|
388
|
+
return (callee) => {
|
|
389
|
+
if (callee && ts.isIdentifier(callee))
|
|
390
|
+
return verbs.get(callee.text) ?? null;
|
|
391
|
+
if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
|
|
392
|
+
return callee.name.text;
|
|
393
|
+
return null;
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
return {
|
|
397
|
+
spanOf,
|
|
398
|
+
extentOf,
|
|
399
|
+
unwrap,
|
|
400
|
+
moduleRefOf,
|
|
401
|
+
returnedObject,
|
|
402
|
+
builderOf,
|
|
403
|
+
guardNameOf,
|
|
404
|
+
optionObjectOf,
|
|
405
|
+
chainOf,
|
|
406
|
+
keyName,
|
|
407
|
+
objectKeys,
|
|
408
|
+
verbReaderOf
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
var sourceReaderOf = (ts) => {
|
|
412
|
+
const importsOf = (statement) => {
|
|
413
|
+
const { importClause, moduleSpecifier } = statement;
|
|
414
|
+
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
415
|
+
return [];
|
|
416
|
+
const from = moduleSpecifier.text;
|
|
417
|
+
const bindings = importClause.namedBindings;
|
|
418
|
+
return [
|
|
419
|
+
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
420
|
+
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
421
|
+
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
422
|
+
name: element.name.text,
|
|
423
|
+
imported: (element.propertyName ?? element.name).text,
|
|
424
|
+
from
|
|
425
|
+
})) : []
|
|
426
|
+
];
|
|
427
|
+
};
|
|
428
|
+
const docOf = (source, node) => {
|
|
429
|
+
const { text } = source;
|
|
430
|
+
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
431
|
+
const comments = [];
|
|
432
|
+
let end = node.getStart(source);
|
|
433
|
+
for (const range of [...ranges].reverse()) {
|
|
434
|
+
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
435
|
+
break;
|
|
436
|
+
comments.unshift(text.slice(range.pos, range.end));
|
|
437
|
+
end = range.pos;
|
|
438
|
+
}
|
|
439
|
+
const lines = comments.flatMap((comment) => comment.split(`
|
|
440
|
+
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
441
|
+
return lines.length ? lines.join(" ") : null;
|
|
442
|
+
};
|
|
443
|
+
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
444
|
+
return { docOf, importsIn };
|
|
445
|
+
};
|
|
446
|
+
var signalKeyReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, optionObjectOf, chainOf, verbReaderOf }, guardsIn) => {
|
|
347
447
|
const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
348
448
|
if (!ts.isPropertyAssignment(property))
|
|
349
449
|
return [];
|
|
@@ -362,23 +462,30 @@ var createFactReader = (ts, ast) => {
|
|
|
362
462
|
}
|
|
363
463
|
];
|
|
364
464
|
});
|
|
365
|
-
const
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
465
|
+
const endpointKeysOf = (source, builder, made, model) => {
|
|
466
|
+
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
467
|
+
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
468
|
+
if (!ts.isPropertyAssignment(property))
|
|
469
|
+
return [];
|
|
470
|
+
const name = ast.nodeName(property.name);
|
|
471
|
+
if (!name)
|
|
472
|
+
return [];
|
|
473
|
+
const { root, methods } = chainOf(property.initializer);
|
|
474
|
+
return [
|
|
475
|
+
{
|
|
476
|
+
name,
|
|
477
|
+
span: spanOf(source, property.name),
|
|
478
|
+
extent: extentOf(source, property),
|
|
479
|
+
verb: root ? verbOf(root.expression) : null,
|
|
480
|
+
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
481
|
+
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
482
|
+
}
|
|
483
|
+
];
|
|
484
|
+
});
|
|
381
485
|
};
|
|
486
|
+
return { sliceKeysOf, endpointKeysOf };
|
|
487
|
+
};
|
|
488
|
+
var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
|
|
382
489
|
const numberOf = (expression) => {
|
|
383
490
|
const value = unwrap(expression);
|
|
384
491
|
if (ts.isNumericLiteral(value))
|
|
@@ -451,6 +558,9 @@ var createFactReader = (ts, ast) => {
|
|
|
451
558
|
];
|
|
452
559
|
});
|
|
453
560
|
};
|
|
561
|
+
return { internalKeysOf };
|
|
562
|
+
};
|
|
563
|
+
var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
|
|
454
564
|
const plugsOf = (source, builder) => {
|
|
455
565
|
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
456
566
|
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
@@ -476,27 +586,17 @@ var createFactReader = (ts, ast) => {
|
|
|
476
586
|
visit(source);
|
|
477
587
|
return bindings;
|
|
478
588
|
};
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
name,
|
|
491
|
-
span: spanOf(source, property.name),
|
|
492
|
-
extent: extentOf(source, property),
|
|
493
|
-
verb: root ? verbOf(root.expression) : null,
|
|
494
|
-
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
495
|
-
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
496
|
-
}
|
|
497
|
-
];
|
|
498
|
-
});
|
|
499
|
-
};
|
|
589
|
+
const methodsOf = (source, statement) => statement.members.flatMap((member) => {
|
|
590
|
+
if (!ts.isMethodDeclaration(member) || !member.body)
|
|
591
|
+
return [];
|
|
592
|
+
const name = ast.nodeName(member.name);
|
|
593
|
+
if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
|
|
594
|
+
return [];
|
|
595
|
+
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
596
|
+
});
|
|
597
|
+
return { plugsOf, adaptorBindingsIn, methodsOf };
|
|
598
|
+
};
|
|
599
|
+
var constantReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, keyName, objectKeys }) => {
|
|
500
600
|
const filterQueriesOf = (source, builder) => {
|
|
501
601
|
const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
|
|
502
602
|
return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
|
|
@@ -534,48 +634,18 @@ var createFactReader = (ts, ast) => {
|
|
|
534
634
|
return [];
|
|
535
635
|
return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
|
|
536
636
|
};
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
544
|
-
});
|
|
545
|
-
const importsOf = (statement) => {
|
|
546
|
-
const { importClause, moduleSpecifier } = statement;
|
|
547
|
-
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
548
|
-
return [];
|
|
549
|
-
const from = moduleSpecifier.text;
|
|
550
|
-
const bindings = importClause.namedBindings;
|
|
551
|
-
return [
|
|
552
|
-
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
553
|
-
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
554
|
-
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
555
|
-
name: element.name.text,
|
|
556
|
-
imported: (element.propertyName ?? element.name).text,
|
|
557
|
-
from
|
|
558
|
-
})) : []
|
|
559
|
-
];
|
|
560
|
-
};
|
|
561
|
-
const docOf = (source, node) => {
|
|
562
|
-
const { text } = source;
|
|
563
|
-
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
564
|
-
const comments = [];
|
|
565
|
-
let end = node.getStart(source);
|
|
566
|
-
for (const range of [...ranges].reverse()) {
|
|
567
|
-
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
568
|
-
break;
|
|
569
|
-
comments.unshift(text.slice(range.pos, range.end));
|
|
570
|
-
end = range.pos;
|
|
571
|
-
}
|
|
572
|
-
const lines = comments.flatMap((comment) => comment.split(`
|
|
573
|
-
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
574
|
-
return lines.length ? lines.join(" ") : null;
|
|
575
|
-
};
|
|
637
|
+
return { constantOf, enumValuesOf, filterQueriesOf };
|
|
638
|
+
};
|
|
639
|
+
var createFactReader = (ts, ast) => {
|
|
640
|
+
const syntax = syntaxReaderOf(ts, ast);
|
|
641
|
+
const { spanOf, extentOf, unwrap, moduleRefOf, returnedObject, builderOf, chainOf, objectKeys } = syntax;
|
|
642
|
+
const { docOf, importsIn } = sourceReaderOf(ts);
|
|
576
643
|
const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
|
|
644
|
+
const { sliceKeysOf, endpointKeysOf } = signalKeyReaderOf(ts, ast, syntax, guardsIn);
|
|
645
|
+
const { internalKeysOf } = jobKeyReaderOf(ts, ast, syntax);
|
|
646
|
+
const { plugsOf, adaptorBindingsIn, methodsOf } = serviceReaderOf(ts, ast, syntax);
|
|
647
|
+
const { constantOf, enumValuesOf, filterQueriesOf } = constantReaderOf(ts, ast, syntax);
|
|
577
648
|
const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
578
|
-
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
579
649
|
const read = (source, owner) => {
|
|
580
650
|
const imports = importsIn(source);
|
|
581
651
|
const madeInPlace = [];
|
|
@@ -675,7 +745,9 @@ var aliasPattern = /^@(apps|libs)\/([^/]+)/;
|
|
|
675
745
|
var maxMapDepth = 4;
|
|
676
746
|
var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
|
|
677
747
|
var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
|
|
748
|
+
var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
|
|
678
749
|
var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
|
|
750
|
+
var exportMentioningPatternOf = (name) => new RegExp(`export\\s[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
|
|
679
751
|
var declaringPatternOf = (name, isAnyBinding) => {
|
|
680
752
|
const escaped = escapeRegExp(name);
|
|
681
753
|
const braced = "\\{(?:[^}]*?[\\s,])?";
|
|
@@ -698,8 +770,11 @@ class GuardResolver {
|
|
|
698
770
|
#declarations = new Map;
|
|
699
771
|
#starExports = new Map;
|
|
700
772
|
#moduleExports = new Map;
|
|
773
|
+
#fileStars = new Map;
|
|
774
|
+
#starReach = new Map;
|
|
701
775
|
#ownerFiles = null;
|
|
702
776
|
#modules = null;
|
|
777
|
+
#barrels = null;
|
|
703
778
|
constructor(source, routes) {
|
|
704
779
|
this.#source = source;
|
|
705
780
|
this.#routes = routes;
|
|
@@ -827,7 +902,7 @@ ${name}`, guard);
|
|
|
827
902
|
const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
|
|
828
903
|
if (own)
|
|
829
904
|
return own;
|
|
830
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
905
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
831
906
|
if (reexport)
|
|
832
907
|
return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
|
|
833
908
|
return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
|
|
@@ -865,13 +940,13 @@ ${name}`, guard);
|
|
|
865
940
|
const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
|
|
866
941
|
return visible ? { guard: visible } : { name, from };
|
|
867
942
|
}
|
|
868
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
943
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
869
944
|
if (reexport)
|
|
870
945
|
return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
|
|
871
946
|
const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
|
|
872
947
|
return reached ? { guard: reached } : { name, from };
|
|
873
948
|
}
|
|
874
|
-
reexportOf(owner, name, near) {
|
|
949
|
+
#reexportOf(owner, name, near) {
|
|
875
950
|
const key = `${owner}
|
|
876
951
|
${name}
|
|
877
952
|
${near ?? ""}`;
|
|
@@ -1028,20 +1103,24 @@ ${near}`;
|
|
|
1028
1103
|
return cached;
|
|
1029
1104
|
const found = { owners: [], packages: [], paths: [near], isOpaque: false };
|
|
1030
1105
|
this.#starExports.set(key, found);
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1106
|
+
const reach = (specifier, path, target) => {
|
|
1107
|
+
if (path === null && !found.packages.includes(specifier))
|
|
1108
|
+
found.packages.push(specifier);
|
|
1109
|
+
if (target === undefined || target === frameworkOwner || path === null)
|
|
1110
|
+
found.isOpaque = true;
|
|
1111
|
+
else if (!found.paths.includes(path))
|
|
1112
|
+
found.paths.push(path);
|
|
1113
|
+
if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
|
|
1114
|
+
found.owners.push(target);
|
|
1115
|
+
};
|
|
1116
|
+
for (let idx = 0;idx < found.paths.length; idx++) {
|
|
1117
|
+
const path = found.paths[idx] ?? "";
|
|
1118
|
+
for (const module of this.#barrelAt(path) ?? [])
|
|
1119
|
+
reach(module, module, ownerOf(module) ?? undefined);
|
|
1120
|
+
for (const fileName of this.#modulesAt(path))
|
|
1121
|
+
for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
|
|
1122
|
+
reach(specifier, this.pathOfSpecifier(fileName, specifier), this.ownerOfSpecifier(fileName, specifier));
|
|
1123
|
+
}
|
|
1045
1124
|
return found;
|
|
1046
1125
|
}
|
|
1047
1126
|
exportsAt(path, name) {
|
|
@@ -1050,27 +1129,78 @@ ${name}`;
|
|
|
1050
1129
|
const cached = this.#moduleExports.get(key);
|
|
1051
1130
|
if (cached)
|
|
1052
1131
|
return cached;
|
|
1053
|
-
const found = { named: null, stars: [] };
|
|
1054
|
-
const
|
|
1132
|
+
const found = { named: null, stars: [], isLocal: false };
|
|
1133
|
+
const stars = new Set(this.#barrelAt(path));
|
|
1055
1134
|
for (const fileName of this.#modulesAt(path)) {
|
|
1056
1135
|
const text = this.#source.readText(fileName);
|
|
1057
1136
|
if (text === undefined)
|
|
1058
1137
|
continue;
|
|
1059
|
-
const named = identifierPattern.test(name) &&
|
|
1138
|
+
const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name) : null;
|
|
1060
1139
|
if (named) {
|
|
1061
1140
|
found.named = { ...named, fileName };
|
|
1062
|
-
found.stars = [];
|
|
1063
1141
|
break;
|
|
1064
1142
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
found.stars.push(target);
|
|
1143
|
+
if (text.includes(name) && exportMentioningPatternOf(name).test(text) && this.#exportsLocally(this.#source.parse(fileName, text), name)) {
|
|
1144
|
+
found.isLocal = true;
|
|
1145
|
+
break;
|
|
1069
1146
|
}
|
|
1147
|
+
for (const target of this.#starsIn(fileName, text))
|
|
1148
|
+
stars.add(target);
|
|
1070
1149
|
}
|
|
1150
|
+
if (!found.named && !found.isLocal)
|
|
1151
|
+
found.stars = [...stars];
|
|
1071
1152
|
this.#moduleExports.set(key, found);
|
|
1072
1153
|
return found;
|
|
1073
1154
|
}
|
|
1155
|
+
#exportsLocally(source, name) {
|
|
1156
|
+
const { ts } = this.#source;
|
|
1157
|
+
const binds = (node) => ts.isIdentifier(node) ? node.text === name : node.elements.some((element) => !ts.isOmittedExpression(element) && binds(element.name));
|
|
1158
|
+
return source.statements.some((statement) => {
|
|
1159
|
+
if (ts.isExportDeclaration(statement))
|
|
1160
|
+
return !statement.moduleSpecifier && !statement.isTypeOnly && !!statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.some((element) => !element.isTypeOnly && element.name.text === name);
|
|
1161
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
|
|
1162
|
+
if (!modifiers.some(({ kind }) => kind === ts.SyntaxKind.ExportKeyword) || modifiers.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword))
|
|
1163
|
+
return false;
|
|
1164
|
+
if (ts.isVariableStatement(statement))
|
|
1165
|
+
return statement.declarationList.declarations.some((declaration) => binds(declaration.name));
|
|
1166
|
+
return (ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement) || ts.isEnumDeclaration(statement) || ts.isModuleDeclaration(statement) || ts.isImportEqualsDeclaration(statement)) && !!statement.name && ts.isIdentifier(statement.name) && statement.name.text === name;
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
mentionsAlong(path, name) {
|
|
1170
|
+
return this.#starReachOf(path).some((text) => text.includes(name));
|
|
1171
|
+
}
|
|
1172
|
+
#starReachOf(path) {
|
|
1173
|
+
const cached = this.#starReach.get(path);
|
|
1174
|
+
if (cached)
|
|
1175
|
+
return cached;
|
|
1176
|
+
const paths = new Set([path]);
|
|
1177
|
+
const texts = [];
|
|
1178
|
+
for (const at of paths) {
|
|
1179
|
+
for (const next of this.#barrelAt(at) ?? [])
|
|
1180
|
+
paths.add(next);
|
|
1181
|
+
for (const fileName of this.#modulesAt(at)) {
|
|
1182
|
+
const text = this.#source.readText(fileName) ?? "";
|
|
1183
|
+
texts.push(text);
|
|
1184
|
+
for (const next of this.#starsIn(fileName, text))
|
|
1185
|
+
paths.add(next);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
this.#starReach.set(path, texts);
|
|
1189
|
+
return texts;
|
|
1190
|
+
}
|
|
1191
|
+
#starsIn(fileName, text) {
|
|
1192
|
+
const cached = this.#fileStars.get(fileName);
|
|
1193
|
+
if (cached)
|
|
1194
|
+
return cached;
|
|
1195
|
+
const found = [];
|
|
1196
|
+
for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
|
|
1197
|
+
const target = this.pathOfSpecifier(fileName, specifier);
|
|
1198
|
+
if (target !== null)
|
|
1199
|
+
found.push(target);
|
|
1200
|
+
}
|
|
1201
|
+
this.#fileStars.set(fileName, found);
|
|
1202
|
+
return found;
|
|
1203
|
+
}
|
|
1074
1204
|
#modulesAt(path) {
|
|
1075
1205
|
if (!this.#modules) {
|
|
1076
1206
|
this.#modules = new Map;
|
|
@@ -1082,21 +1212,23 @@ ${name}`;
|
|
|
1082
1212
|
}
|
|
1083
1213
|
return this.#modules.get(path) ?? [];
|
|
1084
1214
|
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1215
|
+
#barrelAt(path) {
|
|
1216
|
+
if (!this.#barrels) {
|
|
1217
|
+
const entries = new Map;
|
|
1218
|
+
for (const [fileName] of this.#source.files) {
|
|
1219
|
+
const [, folder, facet, entry, nested] = this.#source.relative(fileName).match(facetEntryPattern) ?? [];
|
|
1220
|
+
if (!folder || !facet || !entry)
|
|
1221
|
+
continue;
|
|
1222
|
+
const found = entries.get(folder) ?? { facet, files: new Set, dirs: new Set };
|
|
1223
|
+
(nested ? found.dirs : found.files).add(entry);
|
|
1224
|
+
entries.set(folder, found);
|
|
1225
|
+
}
|
|
1226
|
+
this.#barrels = new Map([...entries].map(([folder, { facet, files, dirs }]) => [
|
|
1227
|
+
folder,
|
|
1228
|
+
facetBarrelNamesOf(facet, [...files], [...dirs]).map((name) => `${folder}/${name}`)
|
|
1229
|
+
]));
|
|
1098
1230
|
}
|
|
1099
|
-
return
|
|
1231
|
+
return this.#modulesAt(path).length ? undefined : this.#barrels.get(path);
|
|
1100
1232
|
}
|
|
1101
1233
|
declares(owner, name) {
|
|
1102
1234
|
const declaring = declaringPatternOf(name, true);
|
|
@@ -1157,7 +1289,12 @@ export
|
|
|
1157
1289
|
}
|
|
1158
1290
|
|
|
1159
1291
|
// pkgs/@akanjs/language/adaptorResolver.ts
|
|
1160
|
-
var
|
|
1292
|
+
var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1293
|
+
var packageKeyOf = ({ name, from }) => `${packageOf(from)}
|
|
1294
|
+
${name}`;
|
|
1295
|
+
var exportedKeyOf = (item) => ("fact" in item) ? item.id : ("local" in item) ? `${item.local}
|
|
1296
|
+
` : packageKeyOf(item);
|
|
1297
|
+
var isPackageExport = (item) => ("from" in item);
|
|
1161
1298
|
|
|
1162
1299
|
class AdaptorResolver {
|
|
1163
1300
|
#source;
|
|
@@ -1166,6 +1303,7 @@ class AdaptorResolver {
|
|
|
1166
1303
|
#adaptors = new Map;
|
|
1167
1304
|
#plugs = new Map;
|
|
1168
1305
|
#serviceFields = new Set;
|
|
1306
|
+
#exported = new Map;
|
|
1169
1307
|
constructor(source, resolver, sink) {
|
|
1170
1308
|
this.#source = source;
|
|
1171
1309
|
this.#resolver = resolver;
|
|
@@ -1248,52 +1386,85 @@ ${field}`))
|
|
|
1248
1386
|
return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
|
|
1249
1387
|
if (own.length === 1)
|
|
1250
1388
|
return first;
|
|
1251
|
-
|
|
1252
|
-
return own.find((adaptor) => this.#source.relative(adaptor.fileName).startsWith(`${path}/`)) ?? first;
|
|
1253
|
-
const exported = this.#exportedAt(name, path, new Set).filter((item) => first || ("fact" in item));
|
|
1389
|
+
const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
|
|
1254
1390
|
const [only] = exported;
|
|
1255
1391
|
if (only)
|
|
1256
|
-
return exported.length === 1 ? only : null;
|
|
1392
|
+
return exported.length === 1 && !("local" in only) ? only : null;
|
|
1257
1393
|
return first ? null : undefined;
|
|
1258
1394
|
}
|
|
1259
|
-
#exportedAt(name, path
|
|
1395
|
+
#exportedAt(name, path) {
|
|
1260
1396
|
const key = `${path}
|
|
1261
1397
|
${name}`;
|
|
1262
|
-
|
|
1398
|
+
const cached = this.#exported.get(key);
|
|
1399
|
+
if (cached)
|
|
1400
|
+
return cached;
|
|
1401
|
+
if (!this.#resolver.mentionsAlong(path, name)) {
|
|
1402
|
+
this.#exported.set(key, []);
|
|
1263
1403
|
return [];
|
|
1264
|
-
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1404
|
+
}
|
|
1405
|
+
const reached = new Map;
|
|
1406
|
+
const seen = new Set;
|
|
1407
|
+
const pending = [[name, path]];
|
|
1408
|
+
for (let next = pending.pop();next; next = pending.pop()) {
|
|
1409
|
+
const [wanted, at] = next;
|
|
1410
|
+
if (seen.has(`${at}
|
|
1411
|
+
${wanted}`))
|
|
1412
|
+
continue;
|
|
1413
|
+
seen.add(`${at}
|
|
1414
|
+
${wanted}`);
|
|
1415
|
+
for (const item of this.#bindingAt(wanted, at, pending))
|
|
1416
|
+
reached.set(exportedKeyOf(item), item);
|
|
1417
|
+
}
|
|
1418
|
+
const found = [...reached.values()];
|
|
1419
|
+
this.#exported.set(key, found);
|
|
1420
|
+
return found;
|
|
1421
|
+
}
|
|
1422
|
+
#bindingAt(name, path, pending) {
|
|
1423
|
+
const here = this.#declaredAt(name, path);
|
|
1269
1424
|
if (here.length)
|
|
1270
1425
|
return here;
|
|
1271
|
-
const { named, stars } = this.#resolver.exportsAt(path, name);
|
|
1272
|
-
if (
|
|
1273
|
-
return [{
|
|
1426
|
+
const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
|
|
1427
|
+
if (isLocal)
|
|
1428
|
+
return [{ local: path }];
|
|
1429
|
+
if (named?.from === null) {
|
|
1430
|
+
const local = this.#declaredAt(named.name, path);
|
|
1431
|
+
return local.length ? local : [{ local: path }];
|
|
1432
|
+
}
|
|
1274
1433
|
if (named) {
|
|
1275
|
-
const target =
|
|
1276
|
-
|
|
1434
|
+
const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
|
|
1435
|
+
if (target === null)
|
|
1436
|
+
return [{ name: named.name === "default" ? name : named.name, from: named.from }];
|
|
1437
|
+
pending.push([named.name, target]);
|
|
1438
|
+
return [];
|
|
1277
1439
|
}
|
|
1278
|
-
|
|
1440
|
+
for (const star of stars)
|
|
1441
|
+
pending.push([name, star]);
|
|
1442
|
+
return [];
|
|
1443
|
+
}
|
|
1444
|
+
#declaredAt(name, path) {
|
|
1445
|
+
return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
|
|
1446
|
+
const module = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
|
|
1447
|
+
return module === path || module === `${path}/index`;
|
|
1448
|
+
});
|
|
1279
1449
|
}
|
|
1280
1450
|
#packageAdaptorOf(name, specifier) {
|
|
1281
1451
|
if (frameworkPattern.test(specifier))
|
|
1282
1452
|
return this.#sink.addNode(this.#sink.key("adaptor", null, name), "adaptor", null, name, null, [frameworkOwner]).id;
|
|
1283
|
-
const pkg =
|
|
1453
|
+
const pkg = packageOf(specifier);
|
|
1284
1454
|
return this.#sink.addNode(this.#sink.key("adaptor", pkg, name), "adaptor", null, name, null, [pkg]).id;
|
|
1285
1455
|
}
|
|
1286
1456
|
#packageShimOf(owner, name, near) {
|
|
1287
|
-
|
|
1288
|
-
const [shim] = reexport?.site.imports ?? [];
|
|
1289
|
-
if (reexport && shim && this.#resolver.pathOfSpecifier(reexport.site.fileName, shim.from) === null)
|
|
1290
|
-
return { name: reexport.local === "default" ? name : reexport.local, from: shim.from };
|
|
1291
|
-
if (reexport || !near)
|
|
1457
|
+
if (!near)
|
|
1292
1458
|
return null;
|
|
1293
|
-
const
|
|
1459
|
+
const shims = this.#exportedAt(name, near).filter(isPackageExport);
|
|
1460
|
+
const [shim] = shims;
|
|
1461
|
+
if (shim)
|
|
1462
|
+
return shims.length === 1 ? shim : null;
|
|
1463
|
+
const { packages, paths } = this.#resolver.starExportsOf(owner, near);
|
|
1294
1464
|
const [only] = packages;
|
|
1295
|
-
|
|
1296
|
-
|
|
1465
|
+
if (!only || new Set(packages.map(packageOf)).size !== 1)
|
|
1466
|
+
return null;
|
|
1467
|
+
return paths.some((path) => this.#resolver.declaresAt(path, name)) ? null : { name, from: only };
|
|
1297
1468
|
}
|
|
1298
1469
|
#nodeOf({ fact, owner, fileName, id }) {
|
|
1299
1470
|
const detail = fact.refName ? [fact.refName] : [];
|
|
@@ -1328,6 +1499,7 @@ var PAGE_ROUTE_EXPORTS = new Set([
|
|
|
1328
1499
|
"guard"
|
|
1329
1500
|
]);
|
|
1330
1501
|
var LAYOUT_ROUTE_EXPORTS = new Set([...PAGE_ROUTE_EXPORTS, "NotFound", "Error"]);
|
|
1502
|
+
var GENERATED_ROOT_LAYOUT_EXPORTS = new Set(["McpAppRoot", "LevelBoundary"]);
|
|
1331
1503
|
var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
|
|
1332
1504
|
...LAYOUT_ROUTE_EXPORTS,
|
|
1333
1505
|
"fonts",
|
|
@@ -1337,8 +1509,7 @@ var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
|
|
|
1337
1509
|
"wsConnect",
|
|
1338
1510
|
"layoutStyle",
|
|
1339
1511
|
"viewport",
|
|
1340
|
-
|
|
1341
|
-
"LevelBoundary"
|
|
1512
|
+
...GENERATED_ROOT_LAYOUT_EXPORTS
|
|
1342
1513
|
]);
|
|
1343
1514
|
var RESERVED_ROUTE_CONFIG_EXPORTS = new Set([...ROOT_LAYOUT_ROUTE_EXPORTS].filter((name) => name !== "default" && !/^[A-Z]/.test(name)));
|
|
1344
1515
|
function parseRouteModuleKey(key) {
|