Skip to content

Instantly share code, notes, and snippets.

@smoll
Last active February 16, 2018 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smoll/94365ce78873969e734adaef8dfc0325 to your computer and use it in GitHub Desktop.
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
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