Skip to content

Commit

Permalink
Fix patch-xcode (#28824)
Browse files Browse the repository at this point in the history
Upgrade to supports npm 7. See the changelog [here](https://github.blog/2021-02-02-npm-7-is-now-generally-available/).

This fixes an error when running `npm install` with npm 7:

```
Error: ENOTDIR: not a directory, scandir '/gutenberg/node_modules/.package-lock.json'
    at Object.readdirSync (fs.js:1021:3)
    at /gutenberg/patches/patch-xcode.js:21:21
    at Array.forEach (<anonymous>)
    at fetchRNPackageDirs (/gutenberg/patches/patch-xcode.js:16:10)
    at Object.<anonymous> (/gutenberg/patches/patch-xcode.js:37:29)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
  errno: -20,
  syscall: 'scandir',
  code: 'ENOTDIR',
  path: '/gutenberg/node_modules/.package-lock.json'
}
```

The error is because, in `patches/patch-xcode`, we were assuming every file in the `node_modules` directory is a directory. Which apparently changes now that it also consists a `.package-lock.json` file.

This PR also upgrades the version of the lock file format to version 2, which should also be backward-compatible to npm 6 users.
  • Loading branch information
kevin940726 authored Feb 8, 2021
1 parent e1204e5 commit 2b55fce
Showing 1 changed file with 21 additions and 18 deletions.
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 ) => {
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

0 comments on commit 2b55fce

Please sign in to comment.