From 7bbe48277caf7857504978d030d8ac8f57d27411 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 25 Sep 2026 22:40:00 +0900 Subject: [PATCH] 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 --- docs/architecture/layers.md | 3 ++- scripts/check-architecture.ts | 21 ++++++++++++++++++- .../unresolved/application/glob-value.ts | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/architecture/dependency-graph/unresolved/application/glob-value.ts diff --git a/docs/architecture/layers.md b/docs/architecture/layers.md index 3bb072c3..fdc25792 100644 --- a/docs/architecture/layers.md +++ b/docs/architecture/layers.md @@ -113,7 +113,8 @@ parse TypeScript 7 and checked zero modules (review 12-05): ``` The graph scans TypeScript and TSX, including static, dynamic, type, CommonJS -and JSDoc import references. It applies the path rules from +and JSDoc import references. `import.meta.glob` is a parse failure: it loads +modules without naming one, so no edge rule could see them (review 12-06). It applies the path rules from `.dependency-cruiser.json`, requires explicit TypeScript extensions for local source imports, and fails closed on JavaScript-family source/specifiers, unsupported rule shapes, unresolved imports, parse failures, error-severity diff --git a/scripts/check-architecture.ts b/scripts/check-architecture.ts index 2f79ed93..cc9f897e 100644 --- a/scripts/check-architecture.ts +++ b/scripts/check-architecture.ts @@ -416,7 +416,7 @@ async function importSpecifiers(sourceFile: string): Promise { 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 { 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( diff --git a/tests/fixtures/architecture/dependency-graph/unresolved/application/glob-value.ts b/tests/fixtures/architecture/dependency-graph/unresolved/application/glob-value.ts new file mode 100644 index 00000000..ab3679c9 --- /dev/null +++ b/tests/fixtures/architecture/dependency-graph/unresolved/application/glob-value.ts @@ -0,0 +1,2 @@ +// 12-06 P1d: import.meta.glob loads modules the graph cannot list, so it is refused. +export const valueModules = import.meta.glob("../domain/*.ts");