Last active
February 16, 2018 21:53
-
-
Save smoll/94365ce78873969e734adaef8dfc0325 to your computer and use it in GitHub Desktop.
Quick 'n Dirty hack to rewrite minify.js to make join-monster play nice with React Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const path = require('path') | |
const rewriteFile = (file, value, replacement) => { | |
const data = fs.readFileSync(file, 'utf-8') | |
const replaced = data.replace(value, replacement) | |
fs.writeFileSync(file, replaced, 'utf-8') | |
} | |
const rewriteMinifyJs = () => { | |
const file = path.join(__dirname, '..', 'node_modules', 'metro-bundler', 'src', 'JSTransformer', 'worker', 'minify.js') | |
// https://github.com/facebook/metro-bundler/compare/v0.10.0...master#diff-9dbbf11afb26941efbbef89e288b9c45L31 | |
const value = /mangle:.*\n/ // mangle: { toplevel: true }, | |
// const replacement = `mangle: false,\n` // DEBUG only | |
const replacement = `mangle: { reserved: ['GraphQLObjectType', 'GraphQLUnionType', 'GraphQLInterfaceType'] },\n` | |
rewriteFile(file, value, replacement) | |
} | |
// Mangling will prevent Javascript `constructor.name` from working | |
rewriteMinifyJs() | |
// Error: require() must have a single string literal argument [dynamic require fails...] | |
// because of https://github.com/facebook/metro-bundler/issues/65 | |
const joinMonsterFile = path.join(__dirname, '..', 'node_modules', 'join-monster', 'dist', 'stringifiers', 'dispatcher.js') | |
rewriteFile(joinMonsterFile, `require('./dialects/' + options.dialect)`, 'null') | |
console.log('rewrote code for all bad deps!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment