I want to add a feature to https://github.com/opentripplanner/otp-react-redux/ which is pulled in from the https://github.com/opentripplanner/otp-ui/tree/master/packages/geocoder package (add another geocoder).
Coming from the PHP world and composer, I normally do in such cases
composer install
rm -r vendor/foo/bar
composer install --prefer-source
cd vendor/foo/bar
git remote set-url origin <myforkURL>
git checkout main
Now I can easily edit that package in-place and make a pull request.
My question is: Is there a similar work-flow possible for node packages using yarn?
I already tried
yarn add "@opentripplanner/geocoder#master"
but no .git
folder appeared in otp-react-redux/node_modules/@opentripplanner
or otp-react-redux/node_modules/@opentripplanner/geocoder
Also it looks like that multiple packages are created from the @opentripplanner
repo, which might complicate things.
I could try to simply edit the files in node_modules
and then copy them to the a manually checked-out git repository, but when running yarn start
everything is also overwritten.
EDIT: As the packages come from a monorepo I tried to delete all the @opentripplanner
lines from packages.json
and added:
yarn add opentripplanner/otp-ui#main
This now causes the build to fail.
I noticed, that the base package.json requires different package versions from the monorepo, so it will not work to require the complete the full main branch.
EDIT2: I found some clue here:
https://github.com/opentripplanner/otp-ui#development
but that also caused dependencies to not resolve properly.
EDIT3: yarn link
actually looked promissing:
cd ..
git clone https://github.com/opentripplanner/otp-ui
cd otp-ui/packages/geocoder
yarn link
Now in the main project code (otp-react-redux)
yarn link "@opentripplanner/geocoder"
This creates a symlink in the node_modules folder to the specific folder in the monorepo I have cloned.
Unfortunately the build does not work:
Module not found: Can't resolve '@opentripplanner/geocoder' in 'otp-react-redux/lib/actions'
I even tried to match the version which is used in the main project by checking out the revision of 1.2.1
2
Answers
yarn link
does the job!Now in the main project code (otp-react-redux)
This creates a symlink in the node_modules folder to the specific folder in the monorepo I have cloned.
To make the build work, the important part is that we run
yarn
in the monorepo before!EDIT: Unfortunately the link process needs to be repeated for each of the
@opentripplanner
modules which require geocoder:repeat for each of them until they are all links:
yalc seems a good solution for this kind of problem
Now each time you change something in the package: