Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix npm 7 compatability #28824

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 21 additions & 18 deletions patches/patch-xcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,29 @@ const path = require( 'path' );
const nodeModulesDir = path.join( __dirname, '../', 'node_modules' );

const fetchRNPackageDirs = ( dir ) => {
const dirList = fs.readdirSync( dir );
const dirList = fs.readdirSync( dir, { withFileTypes: true } );
const packageDirs = [];
dirList.forEach( ( packageName ) => {
const packageDir = path.join( dir, packageName );
if ( packageName.startsWith( '@' ) ) {
packageDirs.push( ...fetchRNPackageDirs( packageDir ) );
} else {
const files = fs.readdirSync( packageDir );
const podSpecs = files.filter( ( file ) =>
file.toLowerCase().endsWith( '.podspec' )
);
if ( podSpecs.length > 0 ) {
packageDirs.push( {
dir: packageDir,
files: podSpecs,
package: packageName,
} );
dirList
.filter( ( file ) => file.isDirectory() )
.map( ( file ) => file.name )
.forEach( ( packageName ) => {
Comment on lines +14 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could omit { withFileTypes: true } and check for a leading dot . instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's error prone as it would break if npm decides to change that by adding another directory without a leading dot. This patch file is already a hack and we should prevent it from breaking our build again 😅 .

const packageDir = path.join( dir, packageName );
if ( packageName.startsWith( '@' ) ) {
packageDirs.push( ...fetchRNPackageDirs( packageDir ) );
} else {
const files = fs.readdirSync( packageDir );
const podSpecs = files.filter( ( file ) =>
file.toLowerCase().endsWith( '.podspec' )
);
if ( podSpecs.length > 0 ) {
packageDirs.push( {
dir: packageDir,
files: podSpecs,
package: packageName,
} );
}
}
}
} );
} );
return packageDirs;
};

Expand Down