fix(architecture): refuse import.meta.glob in the import graph (12-06)
A glob loaded adapter modules without naming one, so the graph, ESLint and the type check all passed it. It is now a parse failure like a non-literal import(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
39b9fbffb7
commit
7bbe48277c
@@ -416,7 +416,7 @@ async function importSpecifiers(sourceFile: string): Promise<string[]> {
|
||||
visitSyntaxNode(syntaxTree, specifiers, nonLiteralModuleLoads);
|
||||
if (nonLiteralModuleLoads.size > 0) {
|
||||
throw new Error(
|
||||
`module loading must use string literals: ${[...nonLiteralModuleLoads].join(", ")}`,
|
||||
`module loading must name one module with a string literal: ${[...nonLiteralModuleLoads].join(", ")}`,
|
||||
);
|
||||
}
|
||||
for (const comment of syntaxTree.comments ?? []) {
|
||||
@@ -476,6 +476,17 @@ function visitSyntaxNode(
|
||||
if (!addStringLiteral(arguments_[0], specifiers)) {
|
||||
nonLiteralModuleLoads.add("require()");
|
||||
}
|
||||
} else if (
|
||||
nodeType === "CallExpression" &&
|
||||
syntaxNodeType(node.callee) === "MemberExpression" &&
|
||||
syntaxNodeType(syntaxNodeProperty(node.callee, "object")) === "MetaProperty" &&
|
||||
/^glob(?:Eager)?$/u.test(
|
||||
String(syntaxNodeProperty(syntaxNodeProperty(node.callee, "property"), "name")),
|
||||
)
|
||||
) {
|
||||
// 12-06: a glob pulls in every matching module without naming one, so no
|
||||
// edge rule can see it. Refuse it like a non-literal import().
|
||||
nonLiteralModuleLoads.add("import.meta.glob()");
|
||||
} else if (nodeType === "TSExternalModuleReference") {
|
||||
addStringLiteral(node.expression, specifiers);
|
||||
} else if (nodeType === "TSImportType") {
|
||||
@@ -989,6 +1000,14 @@ async function runGraphFixtureChecks(): Promise<GraphFixtureResult> {
|
||||
reason.includes("import()"),
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "import.meta.glob module loads are rejected",
|
||||
passed: unresolvedGraph.parseFailures.some(
|
||||
({ source, reason }) =>
|
||||
source === "src/application/glob-value.ts" &&
|
||||
reason.includes("import.meta.glob"),
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "non-literal CommonJS imports are rejected",
|
||||
passed: unresolvedGraph.parseFailures.some(
|
||||
|
||||
Reference in New Issue
Block a user