-
Notifications
You must be signed in to change notification settings - Fork 192
JS-769 Restrict nested node_modules lookups and remove ruling node_modules cleanup #6636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
ccf82d3
24d5a91
9c429fb
b1831fd
544de1e
e9478b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ import { | |
| clearSourceFileContentCache, | ||
| getCachedSourceFile, | ||
| } from '../../src/program/cache/sourceFileCache.js'; | ||
| import { normalizeToAbsolutePath } from '../../src/rules/helpers/files.js'; | ||
| import { joinPaths, normalizeToAbsolutePath } from '../../src/rules/helpers/files.js'; | ||
|
|
||
| describe('IncrementalCompilerHost', () => { | ||
| const baseDir = normalizeToAbsolutePath('/project'); | ||
|
|
@@ -170,6 +170,17 @@ describe('IncrementalCompilerHost', () => { | |
|
|
||
| expect(cache.get(normalizeToAbsolutePath('/project/src/index.ts'))).toBe(content); | ||
| }); | ||
|
|
||
| it('should not skip node_modules reads nested under baseDir', () => { | ||
|
||
| const host = new IncrementalCompilerHost(compilerOptions, baseDir); | ||
| const nestedNodeModulesFile = joinPaths(baseDir, 'src', 'node_modules', 'pkg', 'index.d.ts'); | ||
|
|
||
| host.readFile(nestedNodeModulesFile); | ||
|
|
||
| const calls = host.getTrackedFsCalls(); | ||
| expect(calls.some(c => c.op === 'readFile-node_modules-skip')).toBe(false); | ||
| expect(calls.some(c => c.op === 'readFile-disk')).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('fileExists', () => { | ||
|
|
@@ -197,6 +208,73 @@ describe('IncrementalCompilerHost', () => { | |
| const calls = host.getTrackedFsCalls(); | ||
| expect(calls.some(c => c.op === 'fileExists-context')).toBe(true); | ||
| }); | ||
|
|
||
| it('should not skip node_modules lookups nested under baseDir', () => { | ||
| const host = new IncrementalCompilerHost(compilerOptions, baseDir); | ||
| const nestedNodeModulesFile = joinPaths(baseDir, 'src', 'node_modules', 'pkg', 'index.d.ts'); | ||
|
|
||
| host.fileExists(nestedNodeModulesFile); | ||
|
|
||
| const calls = host.getTrackedFsCalls(); | ||
| expect(calls.some(c => c.op === 'fileExists-node_modules-skip')).toBe(false); | ||
| expect(calls.some(c => c.op === 'fileExists-disk')).toBe(true); | ||
| }); | ||
|
|
||
| it('should not skip node_modules lookups under baseDir', () => { | ||
| const host = new IncrementalCompilerHost(compilerOptions, baseDir); | ||
| const fileInsideBaseNodeModules = joinPaths(baseDir, 'node_modules', 'pkg', 'index.d.ts'); | ||
|
|
||
| host.fileExists(fileInsideBaseNodeModules); | ||
|
|
||
| const calls = host.getTrackedFsCalls(); | ||
| expect(calls.some(c => c.op === 'fileExists-node_modules-skip')).toBe(false); | ||
| expect(calls.some(c => c.op === 'fileExists-disk')).toBe(true); | ||
| }); | ||
|
|
||
| it('should skip node_modules lookups outside baseDir', () => { | ||
| const host = new IncrementalCompilerHost(compilerOptions, baseDir); | ||
| const outsideNodeModulesFile = normalizeToAbsolutePath( | ||
| '/external/node_modules/pkg/index.d.ts', | ||
| ); | ||
|
|
||
| expect(host.fileExists(outsideNodeModulesFile)).toBe(false); | ||
|
|
||
| const calls = host.getTrackedFsCalls(); | ||
| expect(calls.some(c => c.op === 'fileExists-node_modules-skip')).toBe(true); | ||
| expect(calls.some(c => c.op === 'fileExists-disk')).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('readDirectory', () => { | ||
| const extensions = ['.ts', '.d.ts']; | ||
| const includes = ['**/*']; | ||
|
|
||
| it('should skip node_modules lookups outside baseDir', () => { | ||
| const host = new IncrementalCompilerHost(compilerOptions, baseDir); | ||
|
|
||
| const files = host.readDirectory( | ||
| '/external/node_modules/pkg', | ||
| extensions, | ||
| undefined, | ||
| includes, | ||
| ); | ||
|
|
||
| expect(files).toEqual([]); | ||
| const calls = host.getTrackedFsCalls(); | ||
| expect(calls.some(c => c.op === 'readDirectory-node_modules-skip')).toBe(true); | ||
| expect(calls.some(c => c.op === 'readDirectory-disk')).toBe(false); | ||
| }); | ||
|
|
||
| it('should not skip node_modules lookups under baseDir', () => { | ||
| const host = new IncrementalCompilerHost(compilerOptions, baseDir); | ||
| const nodeModulesUnderBaseDir = joinPaths(baseDir, 'node_modules'); | ||
|
|
||
| host.readDirectory(nodeModulesUnderBaseDir, extensions, undefined, includes); | ||
|
|
||
| const calls = host.getTrackedFsCalls(); | ||
| expect(calls.some(c => c.op === 'readDirectory-node_modules-skip')).toBe(false); | ||
| expect(calls.some(c => c.op === 'readDirectory-disk')).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getSourceFile', () => { | ||
|
|
@@ -264,6 +342,19 @@ describe('IncrementalCompilerHost', () => { | |
|
|
||
| expect(sf?.languageVersion).toBe(ts.ScriptTarget.ES2020); | ||
| }); | ||
|
|
||
| it('should not skip source files from nested node_modules under baseDir', () => { | ||
| const host = new IncrementalCompilerHost(compilerOptions, baseDir); | ||
| const nestedNodeModulesFile = joinPaths(baseDir, 'src', 'node_modules', 'pkg', 'index.d.ts'); | ||
|
|
||
| const sf = host.getSourceFile(nestedNodeModulesFile, ts.ScriptTarget.ESNext); | ||
|
|
||
| expect(sf).toBeUndefined(); | ||
|
|
||
| const calls = host.getTrackedFsCalls(); | ||
| expect(calls.some(c => c.op === 'getSourceFile-node_modules-skip')).toBe(false); | ||
| expect(calls.some(c => c.op === 'getSourceFile-disk-fallback')).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getSourceFileByPath', () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.