@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/guardResolver.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ interface ModuleExports {
|
|
|
40
40
|
fileName: string;
|
|
41
41
|
}) | null;
|
|
42
42
|
stars: string[];
|
|
43
|
+
isLocal: boolean;
|
|
43
44
|
}
|
|
44
45
|
interface Declaration {
|
|
45
46
|
source: TS.SourceFile;
|
|
@@ -56,15 +57,10 @@ export declare class GuardResolver {
|
|
|
56
57
|
find(local: string, site: GuardSite): GuardLookup;
|
|
57
58
|
madeInPlace(fileName: string, name: string): DeclaredGuard | undefined;
|
|
58
59
|
declare(facts: FileFacts[]): DeclaredGuard[];
|
|
59
|
-
reexportOf(owner: string, name: string, near: string | null): {
|
|
60
|
-
local: string;
|
|
61
|
-
site: GuardSite;
|
|
62
|
-
} | null;
|
|
63
60
|
declarationOf(owner: string, name: string, near: string | null, depth?: number): Declaration | null;
|
|
64
61
|
starExportsOf(owner: string, near: string): StarExports;
|
|
65
62
|
exportsAt(path: string, name: string): ModuleExports;
|
|
66
|
-
|
|
67
|
-
packagesUnder(owner: string, folder: string): string[];
|
|
63
|
+
mentionsAlong(path: string, name: string): boolean;
|
|
68
64
|
declares(owner: string, name: string): boolean;
|
|
69
65
|
declaresAt(path: string, name: string): boolean;
|
|
70
66
|
inOwner(fileName: string, owner: string | null): string;
|
package/index.cjs
CHANGED
|
@@ -161,6 +161,38 @@ ${at.file}` : null;
|
|
|
161
161
|
return node.fields ? { ...node, fields: node.fields.map(({ digest: _field, ...field }) => field) } : node;
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
+
// pkgs/akanjs/common/facetBarrel.ts
|
|
165
|
+
var barrelFacetDirs = ["ui", "webkit", "srvkit", "common", "plugin"];
|
|
166
|
+
var sourceFilePattern = /\.(ts|tsx)$/;
|
|
167
|
+
var excludedFilePattern = /(^index\.tsx?$|\.d\.ts$|\.(test|spec)\.(ts|tsx)$|\.css$|\.scss$|\.sass$)/;
|
|
168
|
+
var pascalCasePattern = /^[A-Z][A-Za-z0-9]*$/;
|
|
169
|
+
var camelCasePattern = /^[a-z][A-Za-z0-9]*$/;
|
|
170
|
+
var letterRankOf = (char) => char.toLowerCase().charCodeAt(0) * 2 + (char === char.toLowerCase() ? 1 : 0);
|
|
171
|
+
var digitRunAt = (name, idx) => /^\d+/.exec(name.slice(idx))?.[0] ?? "";
|
|
172
|
+
var compareExportNames = (a, b) => {
|
|
173
|
+
for (let idx = 0;idx < a.length && idx < b.length; ) {
|
|
174
|
+
const [runA, runB] = [digitRunAt(a, idx), digitRunAt(b, idx)];
|
|
175
|
+
if (runA && runB && runA !== runB)
|
|
176
|
+
return runA.length - runB.length || (runA < runB ? -1 : 1);
|
|
177
|
+
if (runA && runB)
|
|
178
|
+
idx += runA.length;
|
|
179
|
+
else if (runA || runB)
|
|
180
|
+
return runA ? -1 : 1;
|
|
181
|
+
else if (a.charAt(idx) !== b.charAt(idx))
|
|
182
|
+
return letterRankOf(a.charAt(idx)) - letterRankOf(b.charAt(idx));
|
|
183
|
+
else
|
|
184
|
+
idx++;
|
|
185
|
+
}
|
|
186
|
+
return a.length - b.length;
|
|
187
|
+
};
|
|
188
|
+
var facetBarrelNamesOf = (facet, files, dirs) => {
|
|
189
|
+
const nameCasePattern = facet === "ui" ? pascalCasePattern : camelCasePattern;
|
|
190
|
+
return [
|
|
191
|
+
...files.filter((file) => sourceFilePattern.test(file) && !excludedFilePattern.test(file)).map((file) => file.replace(sourceFilePattern, "")),
|
|
192
|
+
...dirs.filter((dir) => !dir.startsWith("."))
|
|
193
|
+
].filter((name) => nameCasePattern.test(name)).sort(compareExportNames);
|
|
194
|
+
};
|
|
195
|
+
|
|
164
196
|
// pkgs/@akanjs/language/escapeRegExp.ts
|
|
165
197
|
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
166
198
|
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
@@ -442,7 +474,7 @@ var ownerOf = (relativePath) => {
|
|
|
442
474
|
const [root, name] = relativePath.split("/");
|
|
443
475
|
return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
|
|
444
476
|
};
|
|
445
|
-
var
|
|
477
|
+
var syntaxReaderOf = (ts, ast) => {
|
|
446
478
|
const spanOf = (source, node) => {
|
|
447
479
|
const start = node.getStart(source);
|
|
448
480
|
const end = node.getEnd();
|
|
@@ -500,6 +532,74 @@ var createFactReader = (ts, ast) => {
|
|
|
500
532
|
const node = keyName(property);
|
|
501
533
|
return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
|
|
502
534
|
});
|
|
535
|
+
const verbReaderOf = (parameter) => {
|
|
536
|
+
const verbs = new Map;
|
|
537
|
+
if (parameter && ts.isObjectBindingPattern(parameter.name))
|
|
538
|
+
for (const element of parameter.name.elements) {
|
|
539
|
+
const verb = element.propertyName ?? element.name;
|
|
540
|
+
if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
|
|
541
|
+
verbs.set(element.name.text, verb.text);
|
|
542
|
+
}
|
|
543
|
+
const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
|
|
544
|
+
return (callee) => {
|
|
545
|
+
if (callee && ts.isIdentifier(callee))
|
|
546
|
+
return verbs.get(callee.text) ?? null;
|
|
547
|
+
if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
|
|
548
|
+
return callee.name.text;
|
|
549
|
+
return null;
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
return {
|
|
553
|
+
spanOf,
|
|
554
|
+
extentOf,
|
|
555
|
+
unwrap,
|
|
556
|
+
moduleRefOf,
|
|
557
|
+
returnedObject,
|
|
558
|
+
builderOf,
|
|
559
|
+
guardNameOf,
|
|
560
|
+
optionObjectOf,
|
|
561
|
+
chainOf,
|
|
562
|
+
keyName,
|
|
563
|
+
objectKeys,
|
|
564
|
+
verbReaderOf
|
|
565
|
+
};
|
|
566
|
+
};
|
|
567
|
+
var sourceReaderOf = (ts) => {
|
|
568
|
+
const importsOf = (statement) => {
|
|
569
|
+
const { importClause, moduleSpecifier } = statement;
|
|
570
|
+
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
571
|
+
return [];
|
|
572
|
+
const from = moduleSpecifier.text;
|
|
573
|
+
const bindings = importClause.namedBindings;
|
|
574
|
+
return [
|
|
575
|
+
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
576
|
+
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
577
|
+
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
578
|
+
name: element.name.text,
|
|
579
|
+
imported: (element.propertyName ?? element.name).text,
|
|
580
|
+
from
|
|
581
|
+
})) : []
|
|
582
|
+
];
|
|
583
|
+
};
|
|
584
|
+
const docOf = (source, node) => {
|
|
585
|
+
const { text } = source;
|
|
586
|
+
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
587
|
+
const comments = [];
|
|
588
|
+
let end = node.getStart(source);
|
|
589
|
+
for (const range of [...ranges].reverse()) {
|
|
590
|
+
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
591
|
+
break;
|
|
592
|
+
comments.unshift(text.slice(range.pos, range.end));
|
|
593
|
+
end = range.pos;
|
|
594
|
+
}
|
|
595
|
+
const lines = comments.flatMap((comment) => comment.split(`
|
|
596
|
+
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
597
|
+
return lines.length ? lines.join(" ") : null;
|
|
598
|
+
};
|
|
599
|
+
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
600
|
+
return { docOf, importsIn };
|
|
601
|
+
};
|
|
602
|
+
var signalKeyReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, optionObjectOf, chainOf, verbReaderOf }, guardsIn) => {
|
|
503
603
|
const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
504
604
|
if (!ts.isPropertyAssignment(property))
|
|
505
605
|
return [];
|
|
@@ -518,23 +618,30 @@ var createFactReader = (ts, ast) => {
|
|
|
518
618
|
}
|
|
519
619
|
];
|
|
520
620
|
});
|
|
521
|
-
const
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
621
|
+
const endpointKeysOf = (source, builder, made, model) => {
|
|
622
|
+
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
623
|
+
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
624
|
+
if (!ts.isPropertyAssignment(property))
|
|
625
|
+
return [];
|
|
626
|
+
const name = ast.nodeName(property.name);
|
|
627
|
+
if (!name)
|
|
628
|
+
return [];
|
|
629
|
+
const { root, methods } = chainOf(property.initializer);
|
|
630
|
+
return [
|
|
631
|
+
{
|
|
632
|
+
name,
|
|
633
|
+
span: spanOf(source, property.name),
|
|
634
|
+
extent: extentOf(source, property),
|
|
635
|
+
verb: root ? verbOf(root.expression) : null,
|
|
636
|
+
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
637
|
+
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
638
|
+
}
|
|
639
|
+
];
|
|
640
|
+
});
|
|
537
641
|
};
|
|
642
|
+
return { sliceKeysOf, endpointKeysOf };
|
|
643
|
+
};
|
|
644
|
+
var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
|
|
538
645
|
const numberOf = (expression) => {
|
|
539
646
|
const value = unwrap(expression);
|
|
540
647
|
if (ts.isNumericLiteral(value))
|
|
@@ -607,6 +714,9 @@ var createFactReader = (ts, ast) => {
|
|
|
607
714
|
];
|
|
608
715
|
});
|
|
609
716
|
};
|
|
717
|
+
return { internalKeysOf };
|
|
718
|
+
};
|
|
719
|
+
var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
|
|
610
720
|
const plugsOf = (source, builder) => {
|
|
611
721
|
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
612
722
|
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
@@ -632,27 +742,17 @@ var createFactReader = (ts, ast) => {
|
|
|
632
742
|
visit(source);
|
|
633
743
|
return bindings;
|
|
634
744
|
};
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
name,
|
|
647
|
-
span: spanOf(source, property.name),
|
|
648
|
-
extent: extentOf(source, property),
|
|
649
|
-
verb: root ? verbOf(root.expression) : null,
|
|
650
|
-
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
651
|
-
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
652
|
-
}
|
|
653
|
-
];
|
|
654
|
-
});
|
|
655
|
-
};
|
|
745
|
+
const methodsOf = (source, statement) => statement.members.flatMap((member) => {
|
|
746
|
+
if (!ts.isMethodDeclaration(member) || !member.body)
|
|
747
|
+
return [];
|
|
748
|
+
const name = ast.nodeName(member.name);
|
|
749
|
+
if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
|
|
750
|
+
return [];
|
|
751
|
+
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
752
|
+
});
|
|
753
|
+
return { plugsOf, adaptorBindingsIn, methodsOf };
|
|
754
|
+
};
|
|
755
|
+
var constantReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, keyName, objectKeys }) => {
|
|
656
756
|
const filterQueriesOf = (source, builder) => {
|
|
657
757
|
const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
|
|
658
758
|
return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
|
|
@@ -690,48 +790,18 @@ var createFactReader = (ts, ast) => {
|
|
|
690
790
|
return [];
|
|
691
791
|
return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
|
|
692
792
|
};
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
700
|
-
});
|
|
701
|
-
const importsOf = (statement) => {
|
|
702
|
-
const { importClause, moduleSpecifier } = statement;
|
|
703
|
-
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
704
|
-
return [];
|
|
705
|
-
const from = moduleSpecifier.text;
|
|
706
|
-
const bindings = importClause.namedBindings;
|
|
707
|
-
return [
|
|
708
|
-
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
709
|
-
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
710
|
-
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
711
|
-
name: element.name.text,
|
|
712
|
-
imported: (element.propertyName ?? element.name).text,
|
|
713
|
-
from
|
|
714
|
-
})) : []
|
|
715
|
-
];
|
|
716
|
-
};
|
|
717
|
-
const docOf = (source, node) => {
|
|
718
|
-
const { text } = source;
|
|
719
|
-
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
720
|
-
const comments = [];
|
|
721
|
-
let end = node.getStart(source);
|
|
722
|
-
for (const range of [...ranges].reverse()) {
|
|
723
|
-
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
724
|
-
break;
|
|
725
|
-
comments.unshift(text.slice(range.pos, range.end));
|
|
726
|
-
end = range.pos;
|
|
727
|
-
}
|
|
728
|
-
const lines = comments.flatMap((comment) => comment.split(`
|
|
729
|
-
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
730
|
-
return lines.length ? lines.join(" ") : null;
|
|
731
|
-
};
|
|
793
|
+
return { constantOf, enumValuesOf, filterQueriesOf };
|
|
794
|
+
};
|
|
795
|
+
var createFactReader = (ts, ast) => {
|
|
796
|
+
const syntax = syntaxReaderOf(ts, ast);
|
|
797
|
+
const { spanOf, extentOf, unwrap, moduleRefOf, returnedObject, builderOf, chainOf, objectKeys } = syntax;
|
|
798
|
+
const { docOf, importsIn } = sourceReaderOf(ts);
|
|
732
799
|
const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
|
|
800
|
+
const { sliceKeysOf, endpointKeysOf } = signalKeyReaderOf(ts, ast, syntax, guardsIn);
|
|
801
|
+
const { internalKeysOf } = jobKeyReaderOf(ts, ast, syntax);
|
|
802
|
+
const { plugsOf, adaptorBindingsIn, methodsOf } = serviceReaderOf(ts, ast, syntax);
|
|
803
|
+
const { constantOf, enumValuesOf, filterQueriesOf } = constantReaderOf(ts, ast, syntax);
|
|
733
804
|
const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
734
|
-
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
735
805
|
const read = (source, owner) => {
|
|
736
806
|
const imports = importsIn(source);
|
|
737
807
|
const madeInPlace = [];
|
|
@@ -831,7 +901,9 @@ var aliasPattern = /^@(apps|libs)\/([^/]+)/;
|
|
|
831
901
|
var maxMapDepth = 4;
|
|
832
902
|
var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
|
|
833
903
|
var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
|
|
904
|
+
var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
|
|
834
905
|
var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
|
|
906
|
+
var exportMentioningPatternOf = (name) => new RegExp(`export\\s[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
|
|
835
907
|
var declaringPatternOf = (name, isAnyBinding) => {
|
|
836
908
|
const escaped = escapeRegExp(name);
|
|
837
909
|
const braced = "\\{(?:[^}]*?[\\s,])?";
|
|
@@ -854,8 +926,11 @@ class GuardResolver {
|
|
|
854
926
|
#declarations = new Map;
|
|
855
927
|
#starExports = new Map;
|
|
856
928
|
#moduleExports = new Map;
|
|
929
|
+
#fileStars = new Map;
|
|
930
|
+
#starReach = new Map;
|
|
857
931
|
#ownerFiles = null;
|
|
858
932
|
#modules = null;
|
|
933
|
+
#barrels = null;
|
|
859
934
|
constructor(source, routes) {
|
|
860
935
|
this.#source = source;
|
|
861
936
|
this.#routes = routes;
|
|
@@ -983,7 +1058,7 @@ ${name}`, guard);
|
|
|
983
1058
|
const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
|
|
984
1059
|
if (own)
|
|
985
1060
|
return own;
|
|
986
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
1061
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
987
1062
|
if (reexport)
|
|
988
1063
|
return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
|
|
989
1064
|
return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
|
|
@@ -1021,13 +1096,13 @@ ${name}`, guard);
|
|
|
1021
1096
|
const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
|
|
1022
1097
|
return visible ? { guard: visible } : { name, from };
|
|
1023
1098
|
}
|
|
1024
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
1099
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
1025
1100
|
if (reexport)
|
|
1026
1101
|
return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
|
|
1027
1102
|
const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
|
|
1028
1103
|
return reached ? { guard: reached } : { name, from };
|
|
1029
1104
|
}
|
|
1030
|
-
reexportOf(owner, name, near) {
|
|
1105
|
+
#reexportOf(owner, name, near) {
|
|
1031
1106
|
const key = `${owner}
|
|
1032
1107
|
${name}
|
|
1033
1108
|
${near ?? ""}`;
|
|
@@ -1184,20 +1259,24 @@ ${near}`;
|
|
|
1184
1259
|
return cached;
|
|
1185
1260
|
const found = { owners: [], packages: [], paths: [near], isOpaque: false };
|
|
1186
1261
|
this.#starExports.set(key, found);
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1262
|
+
const reach = (specifier, path, target) => {
|
|
1263
|
+
if (path === null && !found.packages.includes(specifier))
|
|
1264
|
+
found.packages.push(specifier);
|
|
1265
|
+
if (target === undefined || target === frameworkOwner || path === null)
|
|
1266
|
+
found.isOpaque = true;
|
|
1267
|
+
else if (!found.paths.includes(path))
|
|
1268
|
+
found.paths.push(path);
|
|
1269
|
+
if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
|
|
1270
|
+
found.owners.push(target);
|
|
1271
|
+
};
|
|
1272
|
+
for (let idx = 0;idx < found.paths.length; idx++) {
|
|
1273
|
+
const path = found.paths[idx] ?? "";
|
|
1274
|
+
for (const module2 of this.#barrelAt(path) ?? [])
|
|
1275
|
+
reach(module2, module2, ownerOf(module2) ?? undefined);
|
|
1276
|
+
for (const fileName of this.#modulesAt(path))
|
|
1277
|
+
for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
|
|
1278
|
+
reach(specifier, this.pathOfSpecifier(fileName, specifier), this.ownerOfSpecifier(fileName, specifier));
|
|
1279
|
+
}
|
|
1201
1280
|
return found;
|
|
1202
1281
|
}
|
|
1203
1282
|
exportsAt(path, name) {
|
|
@@ -1206,27 +1285,78 @@ ${name}`;
|
|
|
1206
1285
|
const cached = this.#moduleExports.get(key);
|
|
1207
1286
|
if (cached)
|
|
1208
1287
|
return cached;
|
|
1209
|
-
const found = { named: null, stars: [] };
|
|
1210
|
-
const
|
|
1288
|
+
const found = { named: null, stars: [], isLocal: false };
|
|
1289
|
+
const stars = new Set(this.#barrelAt(path));
|
|
1211
1290
|
for (const fileName of this.#modulesAt(path)) {
|
|
1212
1291
|
const text = this.#source.readText(fileName);
|
|
1213
1292
|
if (text === undefined)
|
|
1214
1293
|
continue;
|
|
1215
|
-
const named = identifierPattern.test(name) &&
|
|
1294
|
+
const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name) : null;
|
|
1216
1295
|
if (named) {
|
|
1217
1296
|
found.named = { ...named, fileName };
|
|
1218
|
-
found.stars = [];
|
|
1219
1297
|
break;
|
|
1220
1298
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
found.stars.push(target);
|
|
1299
|
+
if (text.includes(name) && exportMentioningPatternOf(name).test(text) && this.#exportsLocally(this.#source.parse(fileName, text), name)) {
|
|
1300
|
+
found.isLocal = true;
|
|
1301
|
+
break;
|
|
1225
1302
|
}
|
|
1303
|
+
for (const target of this.#starsIn(fileName, text))
|
|
1304
|
+
stars.add(target);
|
|
1226
1305
|
}
|
|
1306
|
+
if (!found.named && !found.isLocal)
|
|
1307
|
+
found.stars = [...stars];
|
|
1227
1308
|
this.#moduleExports.set(key, found);
|
|
1228
1309
|
return found;
|
|
1229
1310
|
}
|
|
1311
|
+
#exportsLocally(source, name) {
|
|
1312
|
+
const { ts } = this.#source;
|
|
1313
|
+
const binds = (node) => ts.isIdentifier(node) ? node.text === name : node.elements.some((element) => !ts.isOmittedExpression(element) && binds(element.name));
|
|
1314
|
+
return source.statements.some((statement) => {
|
|
1315
|
+
if (ts.isExportDeclaration(statement))
|
|
1316
|
+
return !statement.moduleSpecifier && !statement.isTypeOnly && !!statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.some((element) => !element.isTypeOnly && element.name.text === name);
|
|
1317
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
|
|
1318
|
+
if (!modifiers.some(({ kind }) => kind === ts.SyntaxKind.ExportKeyword) || modifiers.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword))
|
|
1319
|
+
return false;
|
|
1320
|
+
if (ts.isVariableStatement(statement))
|
|
1321
|
+
return statement.declarationList.declarations.some((declaration) => binds(declaration.name));
|
|
1322
|
+
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;
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
mentionsAlong(path, name) {
|
|
1326
|
+
return this.#starReachOf(path).some((text) => text.includes(name));
|
|
1327
|
+
}
|
|
1328
|
+
#starReachOf(path) {
|
|
1329
|
+
const cached = this.#starReach.get(path);
|
|
1330
|
+
if (cached)
|
|
1331
|
+
return cached;
|
|
1332
|
+
const paths = new Set([path]);
|
|
1333
|
+
const texts = [];
|
|
1334
|
+
for (const at of paths) {
|
|
1335
|
+
for (const next of this.#barrelAt(at) ?? [])
|
|
1336
|
+
paths.add(next);
|
|
1337
|
+
for (const fileName of this.#modulesAt(at)) {
|
|
1338
|
+
const text = this.#source.readText(fileName) ?? "";
|
|
1339
|
+
texts.push(text);
|
|
1340
|
+
for (const next of this.#starsIn(fileName, text))
|
|
1341
|
+
paths.add(next);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
this.#starReach.set(path, texts);
|
|
1345
|
+
return texts;
|
|
1346
|
+
}
|
|
1347
|
+
#starsIn(fileName, text) {
|
|
1348
|
+
const cached = this.#fileStars.get(fileName);
|
|
1349
|
+
if (cached)
|
|
1350
|
+
return cached;
|
|
1351
|
+
const found = [];
|
|
1352
|
+
for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
|
|
1353
|
+
const target = this.pathOfSpecifier(fileName, specifier);
|
|
1354
|
+
if (target !== null)
|
|
1355
|
+
found.push(target);
|
|
1356
|
+
}
|
|
1357
|
+
this.#fileStars.set(fileName, found);
|
|
1358
|
+
return found;
|
|
1359
|
+
}
|
|
1230
1360
|
#modulesAt(path) {
|
|
1231
1361
|
if (!this.#modules) {
|
|
1232
1362
|
this.#modules = new Map;
|
|
@@ -1238,21 +1368,23 @@ ${name}`;
|
|
|
1238
1368
|
}
|
|
1239
1369
|
return this.#modules.get(path) ?? [];
|
|
1240
1370
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1371
|
+
#barrelAt(path) {
|
|
1372
|
+
if (!this.#barrels) {
|
|
1373
|
+
const entries = new Map;
|
|
1374
|
+
for (const [fileName] of this.#source.files) {
|
|
1375
|
+
const [, folder, facet, entry, nested] = this.#source.relative(fileName).match(facetEntryPattern) ?? [];
|
|
1376
|
+
if (!folder || !facet || !entry)
|
|
1377
|
+
continue;
|
|
1378
|
+
const found = entries.get(folder) ?? { facet, files: new Set, dirs: new Set };
|
|
1379
|
+
(nested ? found.dirs : found.files).add(entry);
|
|
1380
|
+
entries.set(folder, found);
|
|
1381
|
+
}
|
|
1382
|
+
this.#barrels = new Map([...entries].map(([folder, { facet, files, dirs }]) => [
|
|
1383
|
+
folder,
|
|
1384
|
+
facetBarrelNamesOf(facet, [...files], [...dirs]).map((name) => `${folder}/${name}`)
|
|
1385
|
+
]));
|
|
1254
1386
|
}
|
|
1255
|
-
return
|
|
1387
|
+
return this.#modulesAt(path).length ? undefined : this.#barrels.get(path);
|
|
1256
1388
|
}
|
|
1257
1389
|
declares(owner, name) {
|
|
1258
1390
|
const declaring = declaringPatternOf(name, true);
|
|
@@ -1313,7 +1445,12 @@ export
|
|
|
1313
1445
|
}
|
|
1314
1446
|
|
|
1315
1447
|
// pkgs/@akanjs/language/adaptorResolver.ts
|
|
1316
|
-
var
|
|
1448
|
+
var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1449
|
+
var packageKeyOf = ({ name, from }) => `${packageOf(from)}
|
|
1450
|
+
${name}`;
|
|
1451
|
+
var exportedKeyOf = (item) => ("fact" in item) ? item.id : ("local" in item) ? `${item.local}
|
|
1452
|
+
` : packageKeyOf(item);
|
|
1453
|
+
var isPackageExport = (item) => ("from" in item);
|
|
1317
1454
|
|
|
1318
1455
|
class AdaptorResolver {
|
|
1319
1456
|
#source;
|
|
@@ -1322,6 +1459,7 @@ class AdaptorResolver {
|
|
|
1322
1459
|
#adaptors = new Map;
|
|
1323
1460
|
#plugs = new Map;
|
|
1324
1461
|
#serviceFields = new Set;
|
|
1462
|
+
#exported = new Map;
|
|
1325
1463
|
constructor(source, resolver, sink) {
|
|
1326
1464
|
this.#source = source;
|
|
1327
1465
|
this.#resolver = resolver;
|
|
@@ -1404,52 +1542,85 @@ ${field}`))
|
|
|
1404
1542
|
return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
|
|
1405
1543
|
if (own.length === 1)
|
|
1406
1544
|
return first;
|
|
1407
|
-
|
|
1408
|
-
return own.find((adaptor) => this.#source.relative(adaptor.fileName).startsWith(`${path}/`)) ?? first;
|
|
1409
|
-
const exported = this.#exportedAt(name, path, new Set).filter((item) => first || ("fact" in item));
|
|
1545
|
+
const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
|
|
1410
1546
|
const [only] = exported;
|
|
1411
1547
|
if (only)
|
|
1412
|
-
return exported.length === 1 ? only : null;
|
|
1548
|
+
return exported.length === 1 && !("local" in only) ? only : null;
|
|
1413
1549
|
return first ? null : undefined;
|
|
1414
1550
|
}
|
|
1415
|
-
#exportedAt(name, path
|
|
1551
|
+
#exportedAt(name, path) {
|
|
1416
1552
|
const key = `${path}
|
|
1417
1553
|
${name}`;
|
|
1418
|
-
|
|
1554
|
+
const cached = this.#exported.get(key);
|
|
1555
|
+
if (cached)
|
|
1556
|
+
return cached;
|
|
1557
|
+
if (!this.#resolver.mentionsAlong(path, name)) {
|
|
1558
|
+
this.#exported.set(key, []);
|
|
1419
1559
|
return [];
|
|
1420
|
-
|
|
1421
|
-
const
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1560
|
+
}
|
|
1561
|
+
const reached = new Map;
|
|
1562
|
+
const seen = new Set;
|
|
1563
|
+
const pending = [[name, path]];
|
|
1564
|
+
for (let next = pending.pop();next; next = pending.pop()) {
|
|
1565
|
+
const [wanted, at] = next;
|
|
1566
|
+
if (seen.has(`${at}
|
|
1567
|
+
${wanted}`))
|
|
1568
|
+
continue;
|
|
1569
|
+
seen.add(`${at}
|
|
1570
|
+
${wanted}`);
|
|
1571
|
+
for (const item of this.#bindingAt(wanted, at, pending))
|
|
1572
|
+
reached.set(exportedKeyOf(item), item);
|
|
1573
|
+
}
|
|
1574
|
+
const found = [...reached.values()];
|
|
1575
|
+
this.#exported.set(key, found);
|
|
1576
|
+
return found;
|
|
1577
|
+
}
|
|
1578
|
+
#bindingAt(name, path, pending) {
|
|
1579
|
+
const here = this.#declaredAt(name, path);
|
|
1425
1580
|
if (here.length)
|
|
1426
1581
|
return here;
|
|
1427
|
-
const { named, stars } = this.#resolver.exportsAt(path, name);
|
|
1428
|
-
if (
|
|
1429
|
-
return [{
|
|
1582
|
+
const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
|
|
1583
|
+
if (isLocal)
|
|
1584
|
+
return [{ local: path }];
|
|
1585
|
+
if (named?.from === null) {
|
|
1586
|
+
const local = this.#declaredAt(named.name, path);
|
|
1587
|
+
return local.length ? local : [{ local: path }];
|
|
1588
|
+
}
|
|
1430
1589
|
if (named) {
|
|
1431
|
-
const target =
|
|
1432
|
-
|
|
1590
|
+
const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
|
|
1591
|
+
if (target === null)
|
|
1592
|
+
return [{ name: named.name === "default" ? name : named.name, from: named.from }];
|
|
1593
|
+
pending.push([named.name, target]);
|
|
1594
|
+
return [];
|
|
1433
1595
|
}
|
|
1434
|
-
|
|
1596
|
+
for (const star of stars)
|
|
1597
|
+
pending.push([name, star]);
|
|
1598
|
+
return [];
|
|
1599
|
+
}
|
|
1600
|
+
#declaredAt(name, path) {
|
|
1601
|
+
return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
|
|
1602
|
+
const module2 = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
|
|
1603
|
+
return module2 === path || module2 === `${path}/index`;
|
|
1604
|
+
});
|
|
1435
1605
|
}
|
|
1436
1606
|
#packageAdaptorOf(name, specifier) {
|
|
1437
1607
|
if (frameworkPattern.test(specifier))
|
|
1438
1608
|
return this.#sink.addNode(this.#sink.key("adaptor", null, name), "adaptor", null, name, null, [frameworkOwner]).id;
|
|
1439
|
-
const pkg =
|
|
1609
|
+
const pkg = packageOf(specifier);
|
|
1440
1610
|
return this.#sink.addNode(this.#sink.key("adaptor", pkg, name), "adaptor", null, name, null, [pkg]).id;
|
|
1441
1611
|
}
|
|
1442
1612
|
#packageShimOf(owner, name, near) {
|
|
1443
|
-
|
|
1444
|
-
const [shim] = reexport?.site.imports ?? [];
|
|
1445
|
-
if (reexport && shim && this.#resolver.pathOfSpecifier(reexport.site.fileName, shim.from) === null)
|
|
1446
|
-
return { name: reexport.local === "default" ? name : reexport.local, from: shim.from };
|
|
1447
|
-
if (reexport || !near)
|
|
1613
|
+
if (!near)
|
|
1448
1614
|
return null;
|
|
1449
|
-
const
|
|
1615
|
+
const shims = this.#exportedAt(name, near).filter(isPackageExport);
|
|
1616
|
+
const [shim] = shims;
|
|
1617
|
+
if (shim)
|
|
1618
|
+
return shims.length === 1 ? shim : null;
|
|
1619
|
+
const { packages, paths } = this.#resolver.starExportsOf(owner, near);
|
|
1450
1620
|
const [only] = packages;
|
|
1451
|
-
|
|
1452
|
-
|
|
1621
|
+
if (!only || new Set(packages.map(packageOf)).size !== 1)
|
|
1622
|
+
return null;
|
|
1623
|
+
return paths.some((path) => this.#resolver.declaresAt(path, name)) ? null : { name, from: only };
|
|
1453
1624
|
}
|
|
1454
1625
|
#nodeOf({ fact, owner, fileName, id }) {
|
|
1455
1626
|
const detail = fact.refName ? [fact.refName] : [];
|
|
@@ -1484,6 +1655,7 @@ var PAGE_ROUTE_EXPORTS = new Set([
|
|
|
1484
1655
|
"guard"
|
|
1485
1656
|
]);
|
|
1486
1657
|
var LAYOUT_ROUTE_EXPORTS = new Set([...PAGE_ROUTE_EXPORTS, "NotFound", "Error"]);
|
|
1658
|
+
var GENERATED_ROOT_LAYOUT_EXPORTS = new Set(["McpAppRoot", "LevelBoundary"]);
|
|
1487
1659
|
var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
|
|
1488
1660
|
...LAYOUT_ROUTE_EXPORTS,
|
|
1489
1661
|
"fonts",
|
|
@@ -1493,8 +1665,7 @@ var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
|
|
|
1493
1665
|
"wsConnect",
|
|
1494
1666
|
"layoutStyle",
|
|
1495
1667
|
"viewport",
|
|
1496
|
-
|
|
1497
|
-
"LevelBoundary"
|
|
1668
|
+
...GENERATED_ROOT_LAYOUT_EXPORTS
|
|
1498
1669
|
]);
|
|
1499
1670
|
var RESERVED_ROUTE_CONFIG_EXPORTS = new Set([...ROOT_LAYOUT_ROUTE_EXPORTS].filter((name) => name !== "default" && !/^[A-Z]/.test(name)));
|
|
1500
1671
|
function parseRouteModuleKey(key) {
|