How do you modify other's library/ module?

后端 未结 1 1436
走了就别回头了
走了就别回头了 2021-01-03 04:45

I want to add a Card component to this module: https://snack.expo.io/@xcarpentier/gifted-chat (demo)

For example, if using onLongPress() on the Bubble M

1条回答
  •  别那么骄傲
    2021-01-03 05:06

    Although you are able to edit the file in your node_modules folder, it is not a great long-term solution. Why not?

    • The process is not consistent with using other modules
    • Another npm install will overwrite your changes
    • Your solution won't be available to someone else wanting to implement that feature

    Bad Solution

    If you would still like to go this route, the quickest way to go about it would be by linking it via npm. In the event this link is not available anymore, you can link a module following these steps:

    1. In your terminal, navigate to the node module you have modified
    2. Create a global symlink with npm link
    3. Navigate to your app's root directory
    4. Reference that symlink with npm link name-of-module

    Again, this is not a permanent solution and should only be used for quickly testing modifications to a module.

    Better Solution

    Forking the repo is a good way to maintain the commits specific to that module, and you can share your modifications to the open-source community. Some reasons to fork are explained in the Github help wiki, but doing it is pretty straight-forward.

    1. Navigate to the Github repo of the package you are wanting to change
    2. Press the Fork button in the top right corner
    3. npm install git+your-forked-repo-url in your project's root directory (don't forget to npm uninstall the old one)

    Now, you can follow the process mentioned in the Bad Solution to locally test out changes to that package. After you're satisfied with them, you can copy those changes over to your forked repo and push them to Github (you'll want bump your version, but you may have some merge conflicts to resolve if you ever want to merge changes with the upstream repo). Then do another npm install of your repo make those changes more permanent in your node_modules folder.

    If you would like to stay up-to-date with the repo you forked from, Github explains the process here.

    TL;DR

    Choose the Better Solution.

    0 讨论(0)
提交回复
热议问题