skip to Main Content

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


  1. Chosen as BEST ANSWER

    yarn link does the job!

    cd ..
    git clone https://github.com/opentripplanner/otp-ui
    cd otp-ui
    yarn
    cd 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.

    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:

    cd node_modules
    $ find -name geocoder -type d 
    ./trip-details/node_modules/@opentripplanner/geocoder
    ./vehicle-rental-overlay/node_modules/@opentripplanner/geocoder
    ./transitive-overlay/node_modules/@opentripplanner/geocoder
    ./endpoints-overlay/node_modules/@opentripplanner/geocoder
    ./zoom-based-markers/node_modules/@opentripplanner/geocoder
    ./trip-viewer-overlay/node_modules/@opentripplanner/geocoder
    ./trip-form/node_modules/@opentripplanner/geocoder
    ./transit-vehicle-overlay/node_modules/@opentripplanner/geocoder
    ./itinerary-body/node_modules/@opentripplanner/geocoder
    ./icons/node_modules/@opentripplanner/geocoder
    ./route-viewer-overlay/node_modules/@opentripplanner/geocoder
    ./printable-itinerary/node_modules/@opentripplanner/geocoder
    ./stop-viewer-overlay/node_modules/@opentripplanner/geocoder
    ./stops-overlay/node_modules/@opentripplanner/geocoder
    ./location-field/node_modules/@opentripplanner/geocoder
    ./park-and-ride-overlay/node_modules/@opentripplanner/geocoder
    
    cd trip-details
    yarn link "@opentripplanner/geocoder"
    

    repeat for each of them until they are all links:

    otp-react-redux$ find node_modules/ -name geocoder -type l 
    node_modules/@opentripplanner/trip-details/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/vehicle-rental-overlay/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/transitive-overlay/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/endpoints-overlay/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/zoom-based-markers/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/trip-viewer-overlay/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/trip-form/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/transit-vehicle-overlay/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/itinerary-body/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/icons/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/route-viewer-overlay/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/printable-itinerary/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/stop-viewer-overlay/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/stops-overlay/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/location-field/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/park-and-ride-overlay/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/base-map/node_modules/@opentripplanner/geocoder
    node_modules/@opentripplanner/geocoder
    

  2. yalc seems a good solution for this kind of problem

    cd ~/projects/otp-ui/packages/itinerary-body
    yarn tsc
    yalc publish
    
    cd ~/projects/otp-react-redux
    yalc link @opentripplanner/itinerary-body
    

    Now each time you change something in the package:

    cd ~/projects/otp-ui/packages/itinerary-body
    yarn tsc && yalc publish
    cd ~/projects/otp-react-redux
    yalc update
    yarn start
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search