Skip to content

Commit

Permalink
fix(typescript-estree): Replace fast-glob with built-in node:fs `…
Browse files Browse the repository at this point in the history
…globSync`
  • Loading branch information
james-pre committed Dec 23, 2024
1 parent 4747299 commit d555589
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@types/jest-specific-snapshot": "^0.5.9",
"@types/natural-compare": "^1.4.3",
"@types/ncp": "^2.0.8",
"@types/node": "^20.12.5",
"@types/node": "^22.5.0",
"@types/semver": "^7.5.8",
"@types/tmp": "^0.2.6",
"@types/yargs": "^17.0.32",
Expand Down Expand Up @@ -131,7 +131,7 @@
"@types/eslint-scope": "link:./tools/dummypkg",
"@types/eslint": "link:./tools/dummypkg",
"@types/estree": "link:./tools/dummypkg",
"@types/node": "^20.0.0",
"@types/node": "^22.5.0",
"@types/react": "^18.2.14",
"eslint-plugin-eslint-plugin@^5.5.0": "patch:eslint-plugin-eslint-plugin@npm%3A5.5.1#./.yarn/patches/eslint-plugin-eslint-plugin-npm-5.5.1-4206c2506d.patch",
"eslint-visitor-keys": "^4.2.0",
Expand Down
1 change: 0 additions & 1 deletion packages/typescript-estree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"@typescript-eslint/types": "8.18.1",
"@typescript-eslint/visitor-keys": "8.18.1",
"debug": "^4.3.4",
"fast-glob": "^3.3.2",
"is-glob": "^4.0.3",
"minimatch": "^9.0.4",
"semver": "^7.6.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import debug from 'debug';
import { sync as globSync } from 'fast-glob';
import isGlob from 'is-glob';
import { globSync } from 'node:fs';
import { matchesGlob } from 'node:path';

import type { CanonicalPath } from '../create-program/shared';
import type { TSESTreeOptions } from '../parser-options';
Expand Down Expand Up @@ -92,13 +93,11 @@ export function resolveProjectList(
let globProjectPaths: string[] = [];

if (globProjects.length > 0) {
// Although fast-glob supports multiple patterns, fast-glob returns arbitrary order of results
// to improve performance. To ensure the order is correct, we need to call fast-glob for each pattern
// separately and then concatenate the results in patterns' order.
globProjectPaths = globProjects.flatMap(pattern =>
globSync(pattern, {
cwd: options.tsconfigRootDir,
ignore: projectFolderIgnoreList,
exclude: (fileName: string) =>
projectFolderIgnoreList.some(ignore => matchesGlob(fileName, ignore)),
}),
);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/typescript-estree/tests/lib/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CacheDurationSeconds } from '@typescript-eslint/types';
import type * as typescriptModule from 'typescript';

import debug from 'debug';
import * as fastGlobModule from 'fast-glob';
import * as fs from 'node:fs';
import { join, resolve } from 'node:path';

import type { TSESTreeOptions } from '../../src/parser-options';
Expand Down Expand Up @@ -40,11 +40,11 @@ jest.mock('typescript', () => {
};
});

jest.mock('fast-glob', () => {
const fastGlob = jest.requireActual<typeof fastGlobModule>('fast-glob');
jest.mock('node:fs', () => {
const node_fs = jest.requireActual<typeof fs>('node:fs');
return {
...fastGlob,
sync: jest.fn(fastGlob.sync),
...node_fs,
globSync: jest.fn(fs.globSync),
};
});

Expand All @@ -53,7 +53,7 @@ const hrtimeSpy = jest.spyOn(process, 'hrtime');
const createDefaultCompilerOptionsFromExtra = jest.mocked(
sharedParserUtilsModule.createDefaultCompilerOptionsFromExtra,
);
const fastGlobSyncMock = jest.mocked(fastGlobModule.sync);
const fastGlobSyncMock = jest.mocked(fs.globSync);

/**
* Aligns paths between environments, node for windows uses `\`, for linux and mac uses `/`
Expand Down
21 changes: 10 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5370,12 +5370,12 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^20.0.0":
version: 20.17.5
resolution: "@types/node@npm:20.17.5"
"@types/node@npm:^22.5.0":
version: 22.10.2
resolution: "@types/node@npm:22.10.2"
dependencies:
undici-types: ~6.19.2
checksum: ca78990c16762f644ee802a93765e78e0c3c695c58b685196fb0ba37356b1380ab9591e60fd03c1bd0e3f4ec92305c9302f518f830f0e63f29dc32e5e7666802
undici-types: ~6.20.0
checksum: b22401e6e7d1484e437d802c72f5560e18100b1257b9ad0574d6fe05bebe4dbcb620ea68627d1f1406775070d29ace8b6b51f57e7b1c7b8bafafe6da7f29c843
languageName: node
linkType: hard

Expand Down Expand Up @@ -5821,7 +5821,7 @@ __metadata:
"@types/jest-specific-snapshot": ^0.5.9
"@types/natural-compare": ^1.4.3
"@types/ncp": ^2.0.8
"@types/node": ^20.12.5
"@types/node": ^22.5.0
"@types/semver": ^7.5.8
"@types/tmp": ^0.2.6
"@types/yargs": ^17.0.32
Expand Down Expand Up @@ -5879,7 +5879,6 @@ __metadata:
"@typescript-eslint/types": 8.18.1
"@typescript-eslint/visitor-keys": 8.18.1
debug: ^4.3.4
fast-glob: ^3.3.2
glob: "*"
is-glob: ^4.0.3
jest: 29.7.0
Expand Down Expand Up @@ -19362,10 +19361,10 @@ __metadata:
languageName: node
linkType: hard

"undici-types@npm:~6.19.2":
version: 6.19.8
resolution: "undici-types@npm:6.19.8"
checksum: de51f1b447d22571cf155dfe14ff6d12c5bdaec237c765085b439c38ca8518fc360e88c70f99469162bf2e14188a7b0bcb06e1ed2dc031042b984b0bb9544017
"undici-types@npm:~6.20.0":
version: 6.20.0
resolution: "undici-types@npm:6.20.0"
checksum: b7bc50f012dc6afbcce56c9fd62d7e86b20a62ff21f12b7b5cbf1973b9578d90f22a9c7fe50e638e96905d33893bf2f9f16d98929c4673c2480de05c6c96ea8b
languageName: node
linkType: hard

Expand Down

0 comments on commit d555589

Please sign in to comment.