Skip to content

Instantly share code, notes, and snippets.

@HosseinRashno
Created December 9, 2020 14:22
Show Gist options
  • Save HosseinRashno/4786b289356ad9840b6c087ce8191fe4 to your computer and use it in GitHub Desktop.
Save HosseinRashno/4786b289356ad9840b6c087ce8191fe4 to your computer and use it in GitHub Desktop.
Fix node modules package for Xcode 12 by changing "dependency" from "React" to "React-Core" inside their podspec files.
/*
* You can add this to your package.json file to run
* after "yarn" or "npm install" like this:
* "scripts": {
* "postinstall": "node ./FixNodeModulesForXCode12.js",
* }
*/
const fs = require('fs');
const glob = require('glob');
console.log('\x1b[36m%s\x1b[0m', '\n\n\n\n\n\nPOST INSTALL IS RUNNING:');
const NODE_MODULES_DIR = 'node_modules';
// Fix node modules package for Xcode 12 by changing "dependency" from "React" to "React-Core" inside their podspec files
glob(NODE_MODULES_DIR + '/**/*.podspec', {}, function(err, files) {
if (err) {
return console.error('Error in post install');
}
console.info('Total detected podspec files: ', files.length);
files.forEach(file => {
fs.readFile(file, 'utf8', function(fileError, data) {
if (fileError) {
return console.error('File error: ', fileError);
}
const regex = /\.dependency\s*[",']React[",']/g;
if (regex.test(data)) {
console.log(
'\x1b[33m%s\x1b[0m',
`Detected podspec with wrong dependency ----> ${file}`,
);
const result = data.replace(regex, '.dependency "React-Core"');
fs.writeFile(file, result, 'utf8', function(writeErr) {
if (writeErr) {
return console.error('File write error: ', writeErr);
}
console.log(
'\x1b[32m%s\x1b[0m',
`Fixed podspec with wrong dependency ----> ${file}`,
);
});
}
});
});
});
@jmarek-sky
Copy link

Kudos
10 months later it is still proving useful 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment