Skip to content

Commit

Permalink
perf: replace glob with fast-glob
Browse files Browse the repository at this point in the history
  • Loading branch information
abejfehr committed Jan 29, 2024
1 parent 7c05c1d commit c72f1d6
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 55 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/eslint-parser": "^7.12.0",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/preset-env": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@babel/eslint-parser": "^7.12.0",
"@react-native-community/eslint-config": "^3.2.0",
"@types/glob": "^7.1.1",
"@types/jest": "^26.0.15",
"@types/node": "^18.0.0",
"@types/node-fetch": "^2.3.7",
Expand All @@ -44,7 +43,7 @@
"eslint-plugin-ft-flow": "^2.0.1",
"eslint-plugin-import": "^2.25.3",
"execa": "^5.0.0",
"glob": "^7.1.3",
"fast-glob": "^3.3.2",
"husky": "^8.0.2",
"jest": "^26.6.2",
"jest-circus": "^26.6.2",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-clean/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@react-native-community/cli-tools": "13.5.1",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"glob": "^7.1.3"
"fast-glob": "^3.3.2"
},
"files": [
"build",
Expand All @@ -20,7 +20,6 @@
],
"devDependencies": {
"@react-native-community/cli-types": "13.5.1",
"@types/glob": "^7.1.1",
"@types/prompts": "^2.4.4"
},
"homepage": "https://github.com/react-native-community/cli/tree/main/packages/cli-clean",
Expand Down
12 changes: 2 additions & 10 deletions packages/cli-clean/src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {existsSync as fileExists, rm} from 'fs';
import os from 'os';
import path from 'path';
import {promisify} from 'util';
import glob from 'glob';
import fg from 'fast-glob';

type Args = {
include?: string;
Expand Down Expand Up @@ -38,15 +38,7 @@ function isDirectoryPattern(directory: string): boolean {
export async function cleanDir(directory: string): Promise<void> {
try {
if (isDirectoryPattern(directory)) {
const directories = await new Promise<string[]>((resolve, reject) => {
glob(directory, {}, (err, foundDirectories) => {
if (err) {
reject(err);
} else {
resolve(foundDirectories);
}
});
});
const directories = await fg.async(directory, {onlyFiles: false});

for (const dir of directories) {
await rmAsync(dir, rmAsyncOptions);
Expand Down
5 changes: 2 additions & 3 deletions packages/cli-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"chalk": "^4.1.2",
"cosmiconfig": "^5.1.0",
"deepmerge": "^4.3.0",
"glob": "^7.1.3",
"fast-glob": "^3.3.2",
"joi": "^17.2.1"
},
"files": [
Expand All @@ -22,8 +22,7 @@
],
"devDependencies": {
"@react-native-community/cli-types": "13.5.1",
"@types/cosmiconfig": "^5.0.3",
"@types/glob": "^7.1.1"
"@types/cosmiconfig": "^5.0.3"
},
"homepage": "https://github.com/react-native-community/cli/tree/main/packages/cli-config",
"repository": {
Expand Down
5 changes: 2 additions & 3 deletions packages/cli-platform-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@react-native-community/cli-tools": "13.5.1",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"fast-glob": "^3.3.2",
"fast-xml-parser": "^4.2.4",
"glob": "^7.1.3",
"logkitty": "^0.7.1"
},
"files": [
Expand All @@ -22,8 +22,7 @@
],
"devDependencies": {
"@react-native-community/cli-types": "13.5.1",
"@types/fs-extra": "^8.1.0",
"@types/glob": "^7.1.1"
"@types/fs-extra": "^8.1.0"
},
"homepage": "https://github.com/react-native-community/cli/tree/main/packages/cli-platform-android",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fs from 'fs';
import path from 'path';
import glob from 'glob';
import fg from 'fast-glob';
import {extractComponentDescriptors} from './extractComponentDescriptors';

export function findComponentDescriptors(packageRoot: string) {
const files = glob.sync('**/+(*.js|*.jsx|*.ts|*.tsx)', {
const files = fg.sync('**/+(*.js|*.jsx|*.ts|*.tsx)', {
cwd: packageRoot,
nodir: true,
ignore: '**/node_modules/**',
onlyFiles: true,
ignore: ['**/node_modules/**'],
});
const codegenComponent = files
.map((filePath) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-platform-android/src/config/findManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*
*/

import glob from 'glob';
import fg from 'fast-glob';
import path from 'path';

export default function findManifest(folder: string) {
let manifestPaths = glob.sync(path.join('**', 'AndroidManifest.xml'), {
let manifestPaths = fg.sync(path.join('**', 'AndroidManifest.xml'), {
cwd: folder,
ignore: [
'node_modules/**',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/

import fs from 'fs';
import glob from 'glob';
import fg from 'fast-glob';
import path from 'path';

export default function getPackageClassName(folder: string) {
const files = glob.sync('**/+(*.java|*.kt)', {cwd: folder});
const files = fg.sync('**/+(*.java|*.kt)', {cwd: folder});

const packages = files
.map((filePath) => fs.readFileSync(path.join(folder, filePath), 'utf8'))
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-platform-apple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
"@react-native-community/cli-tools": "13.5.1",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"fast-glob": "^3.3.2",
"fast-xml-parser": "^4.0.12",
"glob": "^7.1.3",
"ora": "^5.4.1"
},
"devDependencies": {
"@react-native-community/cli-types": "13.5.1",
"@types/glob": "^7.1.1",
"@types/lodash": "^4.14.149",
"hasbin": "^1.2.3"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-platform-apple/src/config/findAllPodfilePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* LICENSE file in the root directory of this source tree.
*
*/
import glob from 'glob';
import fg from 'fast-glob';

// These folders will be excluded from search to speed it up
const GLOB_EXCLUDE_PATTERN = ['**/@(Pods|node_modules|Carthage|vendor)/**'];

export default function findAllPodfilePaths(cwd: string) {
return glob.sync('**/Podfile', {
return fg.sync('**/Podfile', {
cwd,
ignore: GLOB_EXCLUDE_PATTERN,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-platform-apple/src/config/findPodspec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import glob from 'glob';
import fg from 'fast-glob';
import path from 'path';

export default function findPodspec(folder: string): string | null {
const podspecs = glob.sync('*.podspec', {cwd: folder});
const podspecs = fg.sync('*.podspec', {cwd: folder});

if (podspecs.length === 0) {
return null;
Expand Down
6 changes: 3 additions & 3 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

const fs = require('fs');
const path = require('path');
const glob = require('glob');
const fg = require('fast-glob');
const babel = require('@babel/core');
const chalk = require('chalk');
const micromatch = require('micromatch');
Expand Down Expand Up @@ -55,8 +55,8 @@ function getBuildPath(file, buildFolder) {
function buildNodePackage(p) {
const srcDir = path.resolve(p, SRC_DIR);
const pattern = path.resolve(srcDir, '**/*');
const files = glob.sync(pattern, {
nodir: true,
const files = fg.sync(pattern, {
onlyFiles: true,
});

process.stdout.write(adjustToTerminalWidth(`${path.basename(p)}\n`));
Expand Down
4 changes: 2 additions & 2 deletions scripts/linkPackages.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const execa = require('execa');
const chalk = require('chalk');
const path = require('path');
const glob = require('glob');
const fg = require('fast-glob');

const projects = glob.sync('packages/*/package.json');
const projects = fg.sync('packages/*/package.json');

projects.forEach((project) => {
const cwd = path.dirname(project);
Expand Down
27 changes: 12 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2212,11 +2212,6 @@
dependencies:
"@types/express" "*"

"@types/events@*":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==

"@types/express-serve-static-core@^4.17.33":
version "4.17.33"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz#de35d30a9d637dc1450ad18dd583d75d5733d543"
Expand All @@ -2243,15 +2238,6 @@
dependencies:
"@types/node" "*"

"@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==
dependencies:
"@types/events" "*"
"@types/minimatch" "*"
"@types/node" "*"

"@types/graceful-fs@^4.1.2", "@types/graceful-fs@^4.1.3":
version "4.1.3"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.3.tgz#039af35fe26bec35003e8d86d2ee9c586354348f"
Expand Down Expand Up @@ -2331,7 +2317,7 @@
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.1.tgz#dc488842312a7f075149312905b5e3c0b054c79d"
integrity sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==

"@types/minimatch@*", "@types/minimatch@^3.0.3":
"@types/minimatch@^3.0.3":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
integrity sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==
Expand Down Expand Up @@ -5620,6 +5606,17 @@ fast-glob@^3.2.9, fast-glob@^3.3.1:
merge2 "^1.3.0"
micromatch "^4.0.4"

fast-glob@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.2.tgz#a904501e57cfdd2ffcded45e99a54fef55e46129"
integrity sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==
dependencies:
"@nodelib/fs.stat" "^2.0.2"
"@nodelib/fs.walk" "^1.2.3"
glob-parent "^5.1.2"
merge2 "^1.3.0"
micromatch "^4.0.4"

fast-json-stable-stringify@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
Expand Down

0 comments on commit c72f1d6

Please sign in to comment.