A noob method of playing with Node modules
Steps to follow to update code from a node_module like d3-force directly !!
So what we get in a node_modules are the build folder that dont support HRM (hot reload module) so we have to make changes and then build that folder using the rollup module ( maybe we can use other libs also !!)
Steps:
- Make that change in the file that you want !!(be it debugging statements or logic change )
- Install the required files, using
npm installand if required change the package manager from yarn to npm - Then lookup to package.json and you might find a function named “prepublishOnly”
- Run the command
npm run prepublishOnly, If the command requires the some folder , build those or remove those folders from the npm command !! - Then once you fix the errors , got the errors solved , then we build this file using
npm run prepublishOnly - Then run the development server using the
npm run dev -- --cache
This is how to rebuild a node-module !!
Github commands
or,
to check the remote of branch we get,
git status -sb : helps to find the remote branch
git config pull.rebase false: makes the default git behaviour as pull and merge (your commit history is not maintained in this)
git config pull.rebase true : pulls the latest commits to the branch and add your commits on top of that
Rebase false
Rebase True
in one branch , we have config.json(dev) files and in another branch we have another config.json(prod), so while merging this raises merge conflict that can be easily sorted , but in PR this gets reflected so a better way to do this is for dev , use dev config , then when merging from prod use prod config,
Problem when working in a large team where many are working on same features
Problems:
- many people working on same file, potential conflict
- you working on a seperate feature , others working on other features
- you deployed branch on prod and then rebased the branch, that leads to fast-forward errors cause remote feat branch doesnt know about these rebased commits
Best way to merge branches together
Rebase :
Lifts your local commits off the branch and puts them in a temporary “holding area.”
Resets your branch to match the latest commit on the origin (origin/main).
Replays your commits one by one on top of that new base.
Industry standard is to first do rebase, fix errors that come in between and jsut stage those dont commit , and continue your replay using this command : git rebase --continue that and then do squash and merge, else if no conflict comes then change this part
Rebase , Squash and Merge and then Rebase : deadly , first you rebased (nice) , then did squash and merge ( nice , and now a new commit was created that your feature branch has no idea of and then you try to do rebase ( git tries to rerun your commits over top of the new commit and results in massive conflicts ) so you start getting merge conflicts in that part.
Once a branch is squashed , retire that branch dont use that same branch again
Merge :
Keeps the commits seperately so that everything can be known like when was this started , its first commit and helps in keeping all the history
--no-commit : stages all the commit but doesnt create that final merge commit.simple merge : merges the branch and adds that final merge commit as well to it.
BEST METHOD :
To solve problem 3, we need to push but with lease so use : git push --force-with-lease , this makes sure to push changes only if no one else has pushed in your branch in that time
Stashing
Using stash you save your current changes and then go back to some other branch and pop those changes there
stash push : git stash push -m '<message>' , pushes into stash
stash pop : git stash pop , removes it from stash
stash apply : git stash apply stash@{0/1/2/..} , does not remove the stash
stash list : git stash list
stash drop : git stash drop stash@{0/1/2/..} , deletes a stash manually
stash clear : git stash clear , deletes everything
stash untracked files as well : git stash -u
stash parts of a file : git stash -p , not useful