Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbf84804

Browse files
committed
copy changes fromtypescript-eslint#9518
1 parentc0bf342 commitbf84804

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

‎packages/typescript-estree/src/parseSettings/resolveProjectList.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,23 @@ export function resolveProjectList(
9393
constnonGlobProjects=sanitizedProjects.filter(project=>!isGlob(project));
9494
constglobProjects=sanitizedProjects.filter(project=>isGlob(project));
9595

96+
letglobProjectPaths:string[]=[];
97+
98+
if(globProjects.length>0){
99+
// Although fast-glob supports multiple patterns, fast-glob returns arbitrary order of results
100+
// to improve performance. To ensure the order is correct, we need to call fast-glob for each pattern
101+
// separately and then concatenate the results in patterns' order.
102+
globProjectPaths=globProjects.flatMap(pattern=>
103+
globSync([pattern],{
104+
cwd:options.tsconfigRootDir,
105+
ignore:projectFolderIgnoreList,
106+
}),
107+
);
108+
}
109+
96110
constuniqueCanonicalProjectPaths=newMap(
97111
nonGlobProjects
98-
.concat(
99-
globProjects.length===0
100-
?[]
101-
:globSync([...globProjects, ...projectFolderIgnoreList],{
102-
cwd:options.tsconfigRootDir,
103-
dot:true,
104-
}),
105-
)
112+
.concat(globProjectPaths)
106113
.map(project=>[
107114
getCanonicalFileName(
108115
ensureAbsolutePath(project,options.tsconfigRootDir),

‎packages/typescript-estree/tests/lib/parse.test.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,9 @@ describe('parseAndGenerateServices', () => {
685685

686686
describe('cacheLifetime',()=>{
687687
describe('glob',()=>{
688+
constproject=['./**/tsconfig.json','./**/tsconfig.extra.json'];
689+
// `resolveProjectList()` runs a glob for each pattern
690+
constexpectedGlobCount=project.length;
688691
functiondoParse(lifetime:CacheDurationSeconds):void{
689692
parser.parseAndGenerateServices('const x = 1',{
690693
cacheLifetime:{
@@ -693,52 +696,52 @@ describe('parseAndGenerateServices', () => {
693696
disallowAutomaticSingleRunInference:true,
694697
filePath:join(FIXTURES_DIR,'file.ts'),
695698
tsconfigRootDir:FIXTURES_DIR,
696-
project:['./**/tsconfig.json','./**/tsconfig.extra.json'],
699+
project,
697700
});
698701
}
699702

700703
it('should cache globs if the lifetime is non-zero',()=>{
701704
doParse(30);
702-
expect(globbySyncMock).toHaveBeenCalledTimes(1);
705+
expect(globbySyncMock).toHaveBeenCalledTimes(expectedGlobCount);
703706
doParse(30);
704-
// shouldn'tcall globby again due to the caching
705-
expect(globbySyncMock).toHaveBeenCalledTimes(1);
707+
// shouldn'tglob again due to the caching
708+
expect(globbySyncMock).toHaveBeenCalledTimes(expectedGlobCount);
706709
});
707710

708711
it('should not cache globs if the lifetime is zero',()=>{
709712
doParse(0);
710-
expect(globbySyncMock).toHaveBeenCalledTimes(1);
713+
expect(globbySyncMock).toHaveBeenCalledTimes(expectedGlobCount);
711714
doParse(0);
712-
// shouldcall globby again because we specified immediate cache expiry
713-
expect(globbySyncMock).toHaveBeenCalledTimes(2);
715+
// shouldglob again because we specified immediate cache expiry
716+
expect(globbySyncMock).toHaveBeenCalledTimes(2*expectedGlobCount);
714717
});
715718

716719
it('should evict the cache if the entry expires',()=>{
717720
hrtimeSpy.mockReturnValueOnce([1,0]);
718721

719722
doParse(30);
720-
expect(globbySyncMock).toHaveBeenCalledTimes(1);
723+
expect(globbySyncMock).toHaveBeenCalledTimes(expectedGlobCount);
721724

722725
// wow so much time has passed
723726
hrtimeSpy.mockReturnValueOnce([Number.MAX_VALUE,0]);
724727

725728
doParse(30);
726-
// shouldn'tcall globby again due to the caching
727-
expect(globbySyncMock).toHaveBeenCalledTimes(2);
729+
// shouldn'tglob again due to the caching
730+
expect(globbySyncMock).toHaveBeenCalledTimes(2*expectedGlobCount);
728731
});
729732

730733
it('should infinitely cache if passed Infinity',()=>{
731734
hrtimeSpy.mockReturnValueOnce([1,0]);
732735

733736
doParse('Infinity');
734-
expect(globbySyncMock).toHaveBeenCalledTimes(1);
737+
expect(globbySyncMock).toHaveBeenCalledTimes(expectedGlobCount);
735738

736739
// wow so much time has passed
737740
hrtimeSpy.mockReturnValueOnce([Number.MAX_VALUE,0]);
738741

739742
doParse('Infinity');
740-
// shouldn'tcall globby again due to the caching
741-
expect(globbySyncMock).toHaveBeenCalledTimes(1);
743+
// shouldn'tglob again due to the caching
744+
expect(globbySyncMock).toHaveBeenCalledTimes(expectedGlobCount);
742745
});
743746
});
744747
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp