Repository navigation
Description
Summary
While testing the monorepo-doctor audit pipeline on TypeScript and React packages, I noticed that scan.mjs silently discards default runtime imports whenever they are imported alongside named type specifiers.
In TypeScript codebases, mixing default value imports with type imports on a single line is common:
import Button, { type ButtonProps } from '@acme/ui';
import React, { type FC, type ReactNode } from 'react';
import apiClient, { type RequestConfig } from '@acme/api';When scanning these statements, scan.mjs marks the entire import statement as type-only and skips it, losing the runtime dependency.
Root Cause
In skills/monorepo-doctor/references/scan.md (lines 114 to 139):
- The scanner regex matches the import statement and extracts the import clause into
m[3]("Button, { type ButtonProps } from "). - Line 138 calls
if (allNamedSpecifiersAreTypeOnly(m[3])) continue;. allNamedSpecifiersAreTypeOnlyisolates only the content within{ ... }:
function allNamedSpecifiersAreTypeOnly(clause = '') {
const m = clause.match(/\{([\s\S]*?)\}/);
if (!m) return false;
const specs = stripComments(m[1]).split(',').map((s) => s.trim()).filter(Boolean);
return specs.length > 0 && specs.every((s) => /^type\s+[$\w]+(?:\s+as\s+[$\w]+)?$/.test(s));
}Because every specifier inside the curly braces begins with type, specs.every(...) evaluates to true. The function does not check whether a default value identifier precedes the opening brace {. The scanner executes continue and discards the runtime value import (Button).
Reproduction
Run the following script with Node.js:
function allNamedSpecifiersAreTypeOnly(clause = '') {
const m = clause.match(/\{([\s\S]*?)\}/);
if (!m) return false;
const specs = m[1].split(',').map((s) => s.trim()).filter(Boolean);
return specs.length > 0 && specs.every((s) => /^type\s+[$\w]+(?:\s+as\s+[$\w]+)?$/.test(s));
}
const importLine = "import Button, { type ButtonProps } from '@acme/ui';";
const importRe = /^[ \t]*(import|export)\s+(type\s+)?((?:(?!\n[ \t]*(?:import|export)\b)[\w$*{},\s]|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)*?\bfrom\s*)?['"]([^'"\n]+)['"]/gm;
const match = [...importLine.matchAll(importRe)][0];
console.log("Clause:", JSON.stringify(match[3]));
console.log("Skipped as type-only:", allNamedSpecifiersAreTypeOnly(match[3]));Expected behavior: Button is recognized as a runtime value import and retained.
Actual behavior: allNamedSpecifiersAreTypeOnly returns true, and the import is dropped.
Impact
Because all checks depend on scan.json, dropping these imports creates false negatives:
ci-coverage/undeclared-workspace-dependency: Misses undeclared workspace packages imported as default values.boundaries/deep-import: Misses deep imports of default exports.circular-deps/file-cycle: Misses intra-package edges, failing to detect dependency cycles.
Proposed Fix
Inspect the substring preceding the opening brace in clause. If non-whitespace characters exist before {, treat the statement as containing a runtime default import:
function allNamedSpecifiersAreTypeOnly(clause = '') {
const m = clause.match(/\{([\s\S]*?)\}/);
if (!m) return false;
const beforeBrace = clause.slice(0, m.index).replace(/[\s,]/g, '');
if (beforeBrace.length > 0) return false;
const specs = stripComments(m[1]).split(',').map((s) => s.trim()).filter(Boolean);
return specs.length > 0 && specs.every((s) => /^type\s+[$\w]+(?:\s+as\s+[$\w]+)?$/.test(s));
}
Activity
Kaap10 commentedon Oct 12, 2026
This covers a parser edge-case in scan.mjs where mixed default and type imports silently drop runtime dependencies.
Happy to open a PR with the fix if this looks good @santoshyadavdev
santoshyadavdev commentedon Oct 12, 2026
Thank you 💙 go for it
fix(scanner): preserve default imports when mixed with type specifiers (
Merge pull request #4 from Kaap10/fix/preserve-default-imports