javascript-obfuscator / react-native-obfuscating-transformer

Obfuscation for React Native bundles
MIT License
196 stars 100 forks source link

Support for react native 0.59^ #10

Open azi1 opened 5 years ago

azi1 commented 5 years ago

are there same configuration for react native 0.59 version. if it is it's not working at all. even if my trace option is true. i cannot see anything in my console when making the build. any advice?

chrisbobbe commented 5 years ago

I'm getting this, with React Native 0.59.1 and react-native-obfuscating-transformer 1.0.0:

info { Error: Cannot find module 'metro/src/reactNativeTransformer'
info     at Function.Module._resolveFilename (module.js:548:15)
info     at Function.Module._load (module.js:475:25)
info     at Module.require (module.js:597:17)
info     at require (internal/module.js:11:18)
info     at Object.getMetroTransformer (/Users/sgidev-005/dev/pregis2/iOsMaxwellMedia/node_modules/react-native-obfuscating-transformer/dist/getMetroTransformer.js:19:16)

info     at obfuscatingTransformer (/Users/sgidev-005/dev/pregis2/iOsMaxwellMedia/node_modules/react-native-obfuscating-transformer/dist/obfuscatingTransformer.js:38:208)
info     at Object.<anonymous> (/Users/sgidev-005/dev/pregis2/iOsMaxwellMedia/transformer.js:6:22)
info     at Module._compile (module.js:653:30)
info     at Object.Module._extensions..js (module.js:664:10)
info     at Module.load (module.js:566:32) code: 'MODULE_NOT_FOUND' }
info error Cannot read property 'transformFile' of undefined

The file metro/src/reactNativeTransformer does not exist in version 0.51.1 of Metro, which is what RN 0.59.1 uses. In fact, I'm having a lot of difficulty finding any version of Metro that has the file metro/src/reactNativeTransformer... does anyone know if it was replaced by the contents of JSTransformer?

chrisbobbe commented 5 years ago

The only place I can find metro/src/reactNativeTransformer is on a fork of Metro by Invertase: https://github.com/invertase/metro/blob/81762b72e4cd3950171b4d90906740007736f6d6/packages/metro/src/reactNativeTransformer.js

kida7 commented 5 years ago

Just add this line to ./transformer.js

 module.exports = obfuscatingTransformer({
     /* Insert here any required configuration */
+    upstreamTransformer: require("metro-react-native-babel-transformer"),
me21 commented 5 years ago

Seems I'm missing something...

Here's my rn-cli.config.js file:

module.exports = {
 getTransformModulePath() {
   return require.resolve("./transformer")
 },
}

Here's my transformer.js file:

const obfuscatingTransformer = require("react-native-obfuscating-transformer");

module.exports = obfuscatingTransformer({
    /* Insert here any required configuration */
    emitObfuscatedFiles: true,
    upstreamTransformer: require("metro-react-native-babel-transformer"),
    trace: true,
    enableInDevelopment: true
});

There is App.js file in src subfolder of the project.

I call react-native run-android but no obfuscated files appear inside my src subfoler. And no trace related to obfuscation. How can I check that obfuscator has been executed?

I suspect that in RN 0.59 metro.config.js file should be edited instead.