2

I have changed a react-native package src component as per my requirement. How can I add that in my app?

(i.e) I have added react-native-floating-action and changed some styles in FloatingActionItem.js and FloatingAction.js file. How can I add the changes inside in my app.

Because If I remove the node module all the changes are gone after installing it again.

3
  • Just keep copy of your current copy safe, remove currently installed one. npm/yarn install <path to your current change> Commented Mar 12, 2020 at 6:18
  • As per your suggestion, I think i need to make a copy inside any one of my project folder and then need to remove the node_modules and then need to add that path <component/react-native-floating-action> and then yarn install. Then all the changes in that package will reflect for me. Commented Mar 12, 2020 at 6:27
  • Is this option is a good practise? Commented Mar 12, 2020 at 6:28

3 Answers 3

7

In your case, once you have modified npm package once you have to reinstall all packages and your changes are not be saved because you are installing dependency from GitHub repository. So anyway you have two options to edit npm package and save it.

  1. Copy code from the original repository and make your own component inside your re-usable components folder. ( Before copy whole code read the license of selected package )
  2. Simply you can fork the original repository to your github account and after that you can make changes to forked repository.

Personally I choose Second (2) option instead of First one

STEPS

  • Fork from the original repositoryenter image description here

  • After that make clone of this forked repo to your machine and change whatever you need (Here styles).

  • After changing push the changes and commit into your forked repo

  • After that you need to remove old original package from your dependency

npm uninstall --save react-native-floating-action

  • After that install forked repo by this command

npm install git+https://[email protected]/myRepo/angular-translate.git

Sign up to request clarification or add additional context in comments.

7 Comments

How to delete a forked package
npm uninstall --save git+https://[email protected]/myRepo/angular-translate.git
While pushing the changes I got permission denied error
You need to push with your personal access token. If you have not generate token, then you need to generate and add it to your github
|
1

You can write a custom script using JavaScript which capable of replace, delete and add lines.

NPM automaticly execute postinstall after npm install command. You need to put your custom script in postinstall within package.json. For an example:

package.json:

{
    "name": "my_package",
    "description": "",
    "version": "1.0.0",
    "main": "index.js",
    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "fix:issue": "node ./scripts/issue.js",
      "postinstall": "npm run fix:issue"
    },
    "repository": {
      "type": "git",
      "url": "https://github.com/ashleygwilliams/my_package.git"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "bugs": {
      "url": "https://github.com/ashleygwilliams/my_package/issues"
    },
    "homepage": "https://github.com/ashleygwilliams/my_package"
  }

Comments

0
  1. Keep your copy on root project folder or anywhere you prefer.
  2. yarn remove <current package name in package.json>.
  3. If this is native library, run pod install again for iOS.
  4. yarn add file:/path-to-local-edited-package-folder
  5. Rest of the steps will work same (pod install, etc)

Another approach as you mentioned (I don't suggest it as native libraries might not be removed completely)

  1. Remove package from package.json.
  2. On package.json file "library name same as current": "./<path to your folder>" or any other location.
  3. yarn install

3 Comments

In [1] I need to make the entire copy of that package in my root folder?
yes the entire folder of that exact package. The root folder name
Okay, But this is a good approach or not? (i.e) this folder has the all changes and all files from that package. But I have only simple changes in two files alone

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.