Skip to content

Commit 41eace0

Browse files
kittenmeta-codesync[bot]
authored andcommitted
Replace glob@^7.0.0 with tinyglobby@^0.2.15 (#54737)
Summary: This replaces `glob@^7.0.0` with `tinyglobby@^0.2.15`. `glob@7` has been deprecated for a while and some versions after had security notices released for them. The plan is to backport this PR to `0.81.x` and onwards. > [!NOTE] > This is a stopgap solution until `fs.glob` becomes generally available with the EOL of Node v20 Succeeds: - #54669 - #48875 ## Changelog: [GENERAL] [SECURITY] - Replace `glob@^7.0.0` with `tinyglobby@^0.2.15` Pull Request resolved: #54737 Test Plan: - Ran all modified commands manually and `pod install in `rn-tester` - NOTE: `ios-prebuild`-related scripts haven't been run manually yet Reviewed By: robhogan Differential Revision: D88069145 Pulled By: huntie fbshipit-source-id: 0c455342a4c6d1d6605fd09fe47b418e5d751491
1 parent b447d26 commit 41eace0

File tree

17 files changed

+159
-160
lines changed

17 files changed

+159
-160
lines changed

flow-typed/npm/glob_v7.x.x.js

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
declare module 'tinyglobby' {
2+
import typeof FSModule from 'fs';
3+
4+
declare type FileSystemAdapter = Partial<FSModule>;
5+
6+
declare type GlobOptions = {
7+
absolute?: boolean,
8+
braceExpansion?: boolean,
9+
caseSensitiveMatch?: boolean,
10+
cwd?: string | URL,
11+
debug?: boolean,
12+
deep?: number,
13+
dot?: boolean,
14+
expandDirectories?: boolean,
15+
extglob?: boolean,
16+
followSymbolicLinks?: boolean,
17+
fs?: FileSystemAdapter,
18+
globstar?: boolean,
19+
ignore?: string | $ReadOnlyArray<string>,
20+
onlyDirectories?: boolean,
21+
onlyFiles?: boolean,
22+
signal?: AbortSignal,
23+
};
24+
25+
declare type GlobModule = {
26+
convertPathToPattern(path: string): string;
27+
escapePath(path: string): string;
28+
isDynamicPattern(pattern: string, options?: { caseSensitiveMatch: boolean }): boolean;
29+
glob(patterns: string | $ReadOnlyArray<string>, options?: GlobOptions): Promise<string[]>;
30+
globSync(patterns: string | $ReadOnlyArray<string>, options?: GlobOptions): string[];
31+
};
32+
33+
declare module.exports: GlobModule;
34+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
"fb-dotslash": "0.5.8",
8888
"flow-api-translator": "0.32.0",
8989
"flow-bin": "^0.291.0",
90-
"glob": "^7.1.1",
9190
"hermes-eslint": "0.32.0",
9291
"hermes-transform": "0.32.0",
9392
"ini": "^5.0.0",
@@ -116,6 +115,7 @@
116115
"supports-color": "^7.1.0",
117116
"temp-dir": "^2.0.0",
118117
"tinybench": "^4.1.0",
118+
"tinyglobby": "^0.2.15",
119119
"typescript": "5.8.3",
120120
"ws": "^7.5.10"
121121
},

packages/react-native-codegen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
"dependencies": {
3232
"@babel/core": "^7.25.2",
3333
"@babel/parser": "^7.25.3",
34-
"glob": "^7.1.1",
3534
"hermes-parser": "0.32.0",
3635
"invariant": "^2.2.4",
3736
"nullthrows": "^1.1.1",
37+
"tinyglobby": "^0.2.15",
3838
"yargs": "^17.6.2"
3939
},
4040
"devDependencies": {

packages/react-native-codegen/scripts/build.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
const babel = require('@babel/core');
2727
const fs = require('fs');
28-
const glob = require('glob');
2928
const micromatch = require('micromatch');
3029
const path = require('path');
3130
const prettier = require('prettier');
31+
const {globSync} = require('tinyglobby');
3232
const {styleText} = require('util');
3333

3434
const prettierConfig = JSON.parse(
@@ -106,8 +106,11 @@ async function buildFile(file, silent) {
106106
}
107107

108108
const srcDir = path.resolve(__dirname, '..', SRC_DIR);
109-
const pattern = path.resolve(srcDir, '**/*');
110-
const files = glob.sync(pattern, {nodir: true});
109+
const files = globSync('**/*', {
110+
cwd: srcDir,
111+
absolute: true,
112+
onlyFiles: true,
113+
});
111114

112115
process.stdout.write(fixedWidth(`${path.basename(PACKAGE_DIR)}\n`));
113116

packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const {FlowParser} = require('../../parsers/flow/parser');
1515
const {TypeScriptParser} = require('../../parsers/typescript/parser');
1616
const {filterJSFile} = require('./combine-utils');
1717
const fs = require('fs');
18-
const glob = require('glob');
1918
const path = require('path');
19+
const {globSync} = require('tinyglobby');
2020

2121
const flowParser = new FlowParser();
2222
const typescriptParser = new TypeScriptParser();
@@ -66,13 +66,11 @@ function expandDirectoriesIntoFiles(
6666
if (!fs.lstatSync(file).isDirectory()) {
6767
return [file];
6868
}
69-
const filePattern = path.sep === '\\' ? file.replace(/\\/g, '/') : file;
70-
return glob.sync(`${filePattern}/**/*{,.fb}.{js,ts,tsx}`, {
71-
nodir: true,
72-
// TODO: This will remove the need of slash substitution above for Windows,
73-
// but it requires glob@v9+; with the package currenlty relying on
74-
// [email protected]; and flow-typed repo not having definitions for glob@9+.
75-
// windowsPathsNoEscape: true,
69+
return globSync('**/*{,.fb}.{js,ts,tsx}', {
70+
expandDirectories: false,
71+
onlyFiles: true,
72+
absolute: true,
73+
cwd: file,
7674
});
7775
})
7876
.filter(element => filterJSFile(element, platform, exclude));

packages/react-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@
175175
"base64-js": "^1.5.1",
176176
"commander": "^12.0.0",
177177
"flow-enums-runtime": "^0.0.6",
178-
"glob": "^7.1.1",
179178
"hermes-compiler": "0.0.0",
180179
"invariant": "^2.2.4",
181180
"jest-environment-node": "^29.7.0",
@@ -191,6 +190,7 @@
191190
"scheduler": "0.27.0",
192191
"semver": "^7.1.3",
193192
"stacktrace-parser": "^0.1.10",
193+
"tinyglobby": "^0.2.15",
194194
"whatwg-fetch": "^3.0.0",
195195
"ws": "^7.5.10",
196196
"yargs": "^17.6.2"

packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
const CodegenUtils = require('../codegen-utils');
1414
const {codegenLog} = require('./utils');
1515
const fs = require('fs');
16-
const glob = require('glob');
1716
const path = require('path');
17+
const {globSync} = require('tinyglobby');
1818

1919
function generateSchemaInfos(
2020
libraries /*: $ReadOnlyArray<$FlowFixMe> */,
@@ -57,17 +57,18 @@ function extractSupportedApplePlatforms(
5757
dependencyPath /*: string */,
5858
) /*: ?{[string]: boolean} */ {
5959
codegenLog('Searching for podspec in the project dependencies.', true);
60-
const podspecs = glob.sync('*.podspec', {cwd: dependencyPath});
60+
const podspecs = globSync('*.podspec', {
61+
cwd: dependencyPath,
62+
onlyFiles: true,
63+
absolute: true,
64+
});
6165

6266
if (podspecs.length === 0) {
6367
return;
6468
}
6569

6670
// Take the first podspec found
67-
const podspec = fs.readFileSync(
68-
path.join(dependencyPath, podspecs[0]),
69-
'utf8',
70-
);
71+
const podspec = fs.readFileSync(podspecs[0], 'utf8');
7172

7273
/**
7374
* Podspec can have platforms defined in two ways:

packages/react-native/scripts/ios-prebuild/build.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import type {BuildFlavor, Destination} from './types';
1515
const {createLogger} = require('./utils');
1616
const {execSync} = require('child_process');
1717
const fs = require('fs');
18-
const glob = require('glob');
1918
const path = require('path');
19+
const {globSync} = require('tinyglobby');
2020

2121
const buildLog = createLogger('SPM');
2222

@@ -28,9 +28,16 @@ function computeFrameworkPaths(
2828
productsFolder /*: string */,
2929
) /*: Array<string> */ {
3030
// The frameworks are in the products folder under a platform/buildType folder and are directories ending with .framework
31-
const frameworks = glob.sync('**/*.framework', {
31+
const frameworks = globSync('**/*.framework', {
3232
cwd: productsFolder,
33+
expandDirectories: false,
34+
onlyDirectories: true,
3335
absolute: true,
36+
}).map(framework => {
37+
// NOTE: tinyglobby outputs a trailing slash for directories
38+
return framework[framework.length - 1] === '/'
39+
? framework.slice(0, -1)
40+
: framework;
3441
});
3542

3643
if (frameworks.length === 0) {

packages/react-native/scripts/ios-prebuild/headers.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010

1111
const fs = require('fs');
12-
const glob = require('glob');
1312
const path = require('path');
13+
const {globSync} = require('tinyglobby');
1414

1515
/**
1616
* This regular expression is designed to match function calls to `podspec_sources` within a podspec file.
@@ -32,9 +32,10 @@ function getHeaderFilesFromPodspecs(
3232
rootFolder /*:string*/,
3333
) /*: { [key: string]: string[] }*/ {
3434
// Find podspec files
35-
const podSpecFiles = glob.sync('**/*.podspec', {
35+
const podSpecFiles = globSync('**/*.podspec', {
3636
cwd: rootFolder,
3737
absolute: true,
38+
onlyFiles: true,
3839
});
3940

4041
const headers /*: { [key: string]: string[] }*/ = {};
@@ -66,9 +67,10 @@ function getHeaderFilesFromPodspecs(
6667
const p = path.resolve(process.cwd(), path.dirname(podspec));
6768
const results = globPatterns
6869
.map(g => {
69-
return glob.sync(g.replace('{h}', 'h'), {
70+
return globSync(g.replace('{h}', 'h'), {
7071
cwd: p,
7172
absolute: true,
73+
expandDirectories: false,
7274
});
7375
})
7476
.flat();

0 commit comments

Comments
 (0)