Skip to content

Commit 9bfee86

Browse files
authored
perf: replace glob with fast-glob (#2280)
* perf: replace glob with fast-glob * chore: fix tests * Use regular glob for build/link scripts
1 parent 7c05c1d commit 9bfee86

File tree

17 files changed

+141
-104
lines changed

17 files changed

+141
-104
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
},
2424
"devDependencies": {
2525
"@babel/core": "^7.0.0",
26+
"@babel/eslint-parser": "^7.12.0",
2627
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
2728
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
2829
"@babel/plugin-transform-runtime": "^7.6.2",
2930
"@babel/preset-env": "^7.0.0",
3031
"@babel/preset-typescript": "^7.3.3",
31-
"@babel/eslint-parser": "^7.12.0",
3232
"@react-native-community/eslint-config": "^3.2.0",
3333
"@types/glob": "^7.1.1",
3434
"@types/jest": "^26.0.15",
@@ -44,6 +44,7 @@
4444
"eslint-plugin-ft-flow": "^2.0.1",
4545
"eslint-plugin-import": "^2.25.3",
4646
"execa": "^5.0.0",
47+
"fast-glob": "^3.3.2",
4748
"glob": "^7.1.3",
4849
"husky": "^8.0.2",
4950
"jest": "^26.6.2",

packages/cli-clean/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@react-native-community/cli-tools": "13.5.1",
1212
"chalk": "^4.1.2",
1313
"execa": "^5.0.0",
14-
"glob": "^7.1.3"
14+
"fast-glob": "^3.3.2"
1515
},
1616
"files": [
1717
"build",
@@ -20,7 +20,6 @@
2020
],
2121
"devDependencies": {
2222
"@react-native-community/cli-types": "13.5.1",
23-
"@types/glob": "^7.1.1",
2423
"@types/prompts": "^2.4.4"
2524
},
2625
"homepage": "https://github.com/react-native-community/cli/tree/main/packages/cli-clean",

packages/cli-clean/src/clean.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {existsSync as fileExists, rm} from 'fs';
66
import os from 'os';
77
import path from 'path';
88
import {promisify} from 'util';
9-
import glob from 'glob';
9+
import glob from 'fast-glob';
1010

1111
type Args = {
1212
include?: string;
@@ -38,15 +38,7 @@ function isDirectoryPattern(directory: string): boolean {
3838
export async function cleanDir(directory: string): Promise<void> {
3939
try {
4040
if (isDirectoryPattern(directory)) {
41-
const directories = await new Promise<string[]>((resolve, reject) => {
42-
glob(directory, {}, (err, foundDirectories) => {
43-
if (err) {
44-
reject(err);
45-
} else {
46-
resolve(foundDirectories);
47-
}
48-
});
49-
});
41+
const directories = await glob.async(directory, {onlyFiles: false});
5042

5143
for (const dir of directories) {
5244
await rmAsync(dir, rmAsyncOptions);

packages/cli-config/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"chalk": "^4.1.2",
1313
"cosmiconfig": "^5.1.0",
1414
"deepmerge": "^4.3.0",
15-
"glob": "^7.1.3",
15+
"fast-glob": "^3.3.2",
1616
"joi": "^17.2.1"
1717
},
1818
"files": [
@@ -22,8 +22,7 @@
2222
],
2323
"devDependencies": {
2424
"@react-native-community/cli-types": "13.5.1",
25-
"@types/cosmiconfig": "^5.0.3",
26-
"@types/glob": "^7.1.1"
25+
"@types/cosmiconfig": "^5.0.3"
2726
},
2827
"homepage": "https://github.com/react-native-community/cli/tree/main/packages/cli-config",
2928
"repository": {

packages/cli-platform-android/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"@react-native-community/cli-tools": "13.5.1",
1111
"chalk": "^4.1.2",
1212
"execa": "^5.0.0",
13+
"fast-glob": "^3.3.2",
1314
"fast-xml-parser": "^4.2.4",
14-
"glob": "^7.1.3",
1515
"logkitty": "^0.7.1"
1616
},
1717
"files": [
@@ -22,8 +22,7 @@
2222
],
2323
"devDependencies": {
2424
"@react-native-community/cli-types": "13.5.1",
25-
"@types/fs-extra": "^8.1.0",
26-
"@types/glob": "^7.1.1"
25+
"@types/fs-extra": "^8.1.0"
2726
},
2827
"homepage": "https://github.com/react-native-community/cli/tree/main/packages/cli-platform-android",
2928
"repository": {

packages/cli-platform-android/src/config/findComponentDescriptors.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import glob from 'glob';
3+
import glob from 'fast-glob';
44
import {extractComponentDescriptors} from './extractComponentDescriptors';
5+
import {unixifyPaths} from '@react-native-community/cli-tools';
56

67
export function findComponentDescriptors(packageRoot: string) {
78
const files = glob.sync('**/+(*.js|*.jsx|*.ts|*.tsx)', {
8-
cwd: packageRoot,
9-
nodir: true,
10-
ignore: '**/node_modules/**',
9+
cwd: unixifyPaths(packageRoot),
10+
onlyFiles: true,
11+
ignore: ['**/node_modules/**'],
1112
});
1213
const codegenComponent = files
1314
.map((filePath) =>

packages/cli-platform-android/src/config/findManifest.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
*
77
*/
88

9-
import glob from 'glob';
9+
import glob from 'fast-glob';
1010
import path from 'path';
11+
import {unixifyPaths} from '@react-native-community/cli-tools';
1112

1213
export default function findManifest(folder: string) {
1314
let manifestPaths = glob.sync(path.join('**', 'AndroidManifest.xml'), {
14-
cwd: folder,
15+
cwd: unixifyPaths(folder),
1516
ignore: [
1617
'node_modules/**',
1718
'**/build/**',

packages/cli-platform-android/src/config/findPackageClassName.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
*/
88

99
import fs from 'fs';
10-
import glob from 'glob';
10+
import glob from 'fast-glob';
1111
import path from 'path';
12+
import {unixifyPaths} from '@react-native-community/cli-tools';
1213

1314
export default function getPackageClassName(folder: string) {
14-
const files = glob.sync('**/+(*.java|*.kt)', {cwd: folder});
15+
const files = glob.sync('**/+(*.java|*.kt)', {cwd: unixifyPaths(folder)});
1516

1617
const packages = files
1718
.map((filePath) => fs.readFileSync(path.join(folder, filePath), 'utf8'))

packages/cli-platform-apple/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
"@react-native-community/cli-tools": "13.5.1",
1111
"chalk": "^4.1.2",
1212
"execa": "^5.0.0",
13+
"fast-glob": "^3.3.2",
1314
"fast-xml-parser": "^4.0.12",
14-
"glob": "^7.1.3",
1515
"ora": "^5.4.1"
1616
},
1717
"devDependencies": {
1818
"@react-native-community/cli-types": "13.5.1",
19-
"@types/glob": "^7.1.1",
2019
"@types/lodash": "^4.14.149",
2120
"hasbin": "^1.2.3"
2221
},

packages/cli-platform-apple/src/config/__tests__/findPodfilePath.test.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,39 @@ jest.mock('fs');
77

88
const fs = require('fs');
99

10-
afterEach(() => {
11-
jest.resetAllMocks();
12-
});
13-
1410
describe('ios::findPodfilePath', () => {
11+
beforeAll(() => {
12+
fs.__setMockFilesystem({
13+
empty: {},
14+
flat: {
15+
...projects.project,
16+
},
17+
multiple: {
18+
bar: {
19+
...projects.project,
20+
},
21+
foo: {
22+
...projects.project,
23+
},
24+
},
25+
});
26+
});
27+
1528
it('returns null if there is no Podfile', () => {
16-
fs.__setMockFilesystem({});
17-
expect(findPodfilePath('/', 'ios')).toBeNull();
29+
expect(findPodfilePath('/empty', 'ios')).toBeNull();
1830
});
1931

2032
it('returns Podfile path if it exists', () => {
21-
fs.__setMockFilesystem(projects.project);
22-
expect(findPodfilePath('/', 'ios')).toContain('ios/Podfile');
33+
expect(findPodfilePath('/flat', 'ios')).toContain('ios/Podfile');
2334
});
2435

2536
it('prints a warning when multile Podfiles are found', () => {
2637
const warn = jest.spyOn(logger, 'warn').mockImplementation();
27-
fs.__setMockFilesystem({
28-
foo: projects.project,
29-
bar: projects.project,
30-
});
31-
expect(findPodfilePath('/', 'ios')).toContain('bar/ios/Podfile');
38+
expect(findPodfilePath('/multiple', 'ios')).toContain(
39+
'/multiple/bar/ios/Podfile',
40+
);
3241
expect(warn.mock.calls).toMatchSnapshot();
3342
});
3443

35-
it('igores Podfiles in Example folder', () => {});
44+
it('ignores Podfiles in Example folder', () => {});
3645
});

0 commit comments

Comments
 (0)