Skip to content

Commit 3832864

Browse files
committed
fix(typescript): normalize Windows drive roots in containment; exclude node_modules by default when auto‑including JS\n\n- Normalize drive‑letter case when comparing roots in outDir containment (win32)\n- When allowJs expands include and user did not set include/exclude, add '**/node_modules/**' to exclude to avoid transforming third‑party code\n\nRefs #1920
1 parent 3734281 commit 3832864

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/typescript/src/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
6666
// Build filter exclusions, ensuring we never re-process TypeScript emit outputs.
6767
// Always exclude the effective outDir (user-provided or the auto-created temp dir).
6868
const filterExclude = Array.isArray(exclude) ? [...exclude] : exclude ? [exclude] : [];
69+
// When auto-expanding to include JS (allowJs) and the user did not provide
70+
// custom include/exclude patterns, avoid transforming third-party code by
71+
// default by excluding node_modules.
72+
if (parsedOptions.options.allowJs && !include && !exclude) {
73+
filterExclude.push('**/node_modules/**');
74+
}
6975
const effectiveOutDir = parsedOptions.options.outDir
7076
? path.resolve(parsedOptions.options.outDir)
7177
: null;
@@ -86,8 +92,13 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
8692
// Use path.relative with root equality guard for cross-platform correctness.
8793
const baseForContainment = filterBaseAbs ?? process.cwd();
8894
const outDirContainsFilterBase = (() => {
89-
// Different roots (e.g., drive letters on Windows) cannot be in a parent/child relationship
90-
if (path.parse(effectiveOutDir).root !== path.parse(baseForContainment).root) return false;
95+
// Different roots (e.g., drive letters on Windows) cannot be in a parent/child relationship.
96+
// Normalize Windows drive-letter case before comparison to avoid false mismatches.
97+
const getRoot = (p: string) => {
98+
const r = path.parse(p).root;
99+
return process.platform === 'win32' ? r.toLowerCase() : r;
100+
};
101+
if (getRoot(effectiveOutDir) !== getRoot(baseForContainment)) return false;
91102
const rel = path.relative(effectiveOutDir, baseForContainment);
92103
// rel === '' -> same dir; absolute or '..' => outside
93104
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));

0 commit comments

Comments
 (0)