New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-repackager

Package Overview
Dependencies
Maintainers
4
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-repackager - npm Package Compare versions

Comparing version 0.44.0 to 0.51.0

repackagerRN51Setup.patch

4

package.json
{
"name": "react-native-repackager",
"version": "0.44.0",
"description": "Custom extension for react-native packager",
"version": "0.51.0",
"description": "Custom extensions support for react-native",
"license": "MIT",

@@ -6,0 +6,0 @@ "publishConfig": {

@@ -1,10 +0,9 @@

# react-native-repackager
Adding support for custom extension files for react-native packager
# Repackager
Adding support for custom file extensions for react-native.
### This packager is a workaround (read: giant hack) until [this PR is merged](https://github.com/facebook/react-native/pull/16948).
`react-native-repackager` is a [React Native](https://facebook.github.io/react-native/) packager extension which provide you an easy way to add files with custom extensions and to use them to override the original file while running RN packager with a special parameter.
## Why
## why-do-we-need-this-package
One of the biggest challenges when writing e2e tests with react environment is easy mocking.
One of the biggest challenges when writing e2e tests with react-native environment is easy mocking.
Another case, is running your app with different behavior in different environments or debug\release.

@@ -17,9 +16,9 @@

In order to make it super easy to mock stuff for tests, this package approach it like we handle imports in JavaScript code that is different between iOS and Android.
So in order to replace SomeFile.js, we will also create SomeFile.mock.js in the same directory.
When the packager will run for the e2e tests, it will pick up this file instead of the original. This way, the mocks files will not find themselves in our production code.
So in order to replace SomeFile.js, we will also create SomeFile.e2e.js in the same directory.
When the packager will run for the e2e tests, it will pick up this file instead of the original. This way, the mock files will not find themselves in our production code.
## Installation
**Currently supports only RN 0.44**
**Currently supports only RN 0.51**
> `react-native-repackager@0.44.x` is for react-native 44.

@@ -32,3 +31,3 @@ * Install the package from npm

add `repackager setup` to your postinstall script, this will patch the packager, adding `--customExtensions` feature to its cli.
add `repackager setup` to your postinstall script, this will patch react-native, allowing it to respect custom `sourceExt`.

@@ -41,9 +40,6 @@ ```json

## API
* `repackager setup`: apply the code changes to the react-native packager
* `repackager injectReleaseSourceMap`: apply injection of sourcemap to release builds
* `repackager injectReleaseMockedE2E`: apply injection of `--customExtensions=e2e` to release builds
* `repackager <command> --reverse`: reverses the command, applies the reverse changes
* `repackager <command> --reverse`: reverses the command, removes the changes

@@ -61,18 +57,34 @@ ## Usage

* run react-packager with --customExtension parameter
```
node node_modules/react-native/local-cli/cli.js start --customExtensions=foo
```
<img src="http://i.imgur.com/NEIDDgH.png"/>
### Two ways to trigger 'repackager' on React Native 0.51.x
* for more then one file extension type
Let's say we want to load files with custom extension like `e2e.js`. We have two options:
#### Method 1: CLI args on the packager (Debug only!).
Run the packager with this argument:
`react-native start —sourceExts=e2e.js`
It will load files that match `*.e2e.js` instead of regular ones.
#### Method 2: Config file (Debug or Release builds)
Create a file called `rn-cli.config.js` in your module’s main dir (the one with package.json).
Put this inside :
```js
module.exports = {
getSourceExts: () => ['e2e.js']
}
```
node node_modules/react-native/local-cli/cli.js start --customExtensions='foo, bar'
`getSourceExts` is a function that returns an array containing a list of custom source extensions. The array can contain multiple custom extensions, if you'd like.
It is recommended to turn the custom extensions on and off using an environment variable, like so :
```js
module.exports = {
getSourceExts: () => process.env.RN_FLAVOR === 'E2E' ? ['e2e.js'] : []
}
```
Where env variable RN_FLAVOR controls which files we load.
Method 2 works for release builds as well.
## Implementation Details
* This package injects code into the RN packager implementation (!)
* This package injects code into the local react-native installation under `./node_modules` (!)

@@ -79,0 +91,0 @@ ## License

@@ -12,5 +12,2 @@ #!/usr/bin/env node

const shouldSetup = _.includes(process.argv, 'setup');
const shouldInjectSourceMap = _.includes(process.argv, 'injectReleaseSourceMap');
const shouldInjectMockedE2E = _.includes(process.argv, 'injectReleaseMockedE2E');
const shouldReverse = _.includes(process.argv, '--reverse');

@@ -21,12 +18,6 @@

function run() {
assertRN44();
assertRN51();
if (shouldSetup) {
setup();
}
if (shouldInjectSourceMap) {
injectSourceMap();
}
if (shouldInjectMockedE2E) {
injectMockedE2E();
}
}

@@ -39,17 +30,7 @@

}
console.log(`injecting support for --customExtensions`);
patch('rn44PackagerCustomExtensions');
console.log(`injecting support for custom sourceExts`);
patch('repackagerRN51Setup');
}
function injectSourceMap() {
console.log(`${shouldReverse ? 'reversing' : 'injecting'} bundle sourcemap arg to release builds`);
patch('rn44PackagerReleaseSourceMap');
}
function injectMockedE2E() {
console.log(`${shouldReverse ? 'reversing' : 'injecting'} bundle customExtensions=e2e to release builds`);
patch('rn44PackagerReleaseMockedE2E');
}
function assertRN44() {
function assertRN51() {
const rnPackageFile = `${reactNativeDir}/package.json`;

@@ -60,4 +41,4 @@ if (!fs.existsSync(rnPackageFile)) {

const rnPackageJson = JSON.parse(fs.readFileSync(rnPackageFile));
if (!_.startsWith(rnPackageJson.version, '0.44')) {
throw new Error(`Only react-native 0.44.x is supported currently`);
if (!_.startsWith(rnPackageJson.version, '0.51')) {
throw new Error(`Only react-native 0.51.x is supported`);
}

@@ -64,0 +45,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc