Skip to content

Contributing

James Beard edited this page Dec 16, 2023 · 5 revisions

Helpful guides

Deploy to a local Node registry

Very useful to confirm your changes will release to NPM ok. This is necessary if your PR adds or removes dependencies. It's common for a package to work ok in a local monorepo, but then be missing a dependency if it's installed standalone.

Thank you to @ThomasG77 for the original instructions

In one console

In a new directory initialise and start a local registry using verdaccio. This is similar to publishing the package to NPM, except it only occurs on your local machine.

npx verdaccio

Do not kill the console as you need to leave the verdaccio server running.

In a second console

Create verdaccio user You only need to do this when you're setting up verdaccio afresh

Create a new user in the empty verdaccio registry, and log in. Enter your username, password and email. The user and password can be made up - you're only using them on your local machine.

Note for this to work I had to use node v18+. Node 16 would bomb out with ECONNREFUSED message.

npm adduser --registry http://localhost:4873

npm login --registry http://localhost:4873

Get your working copy ready

git clone https://github.com/Turfjs/turf.git <-- or whatever branch you're testing

cd turf

Create a local branch and switch to it. Call the branch something meaningful to your test e.g. v7.0.0-pr1234

git checkout -b v7.0.0-pr1234

Instruct lerna to update all the packages in the monorepo for a new release.

yarn lerna version --no-push --no-commit-hooks v7.0.0-pr1234

Change the registry url in lerna.json from https://registry.npmjs.org to http://localhost:4873. Commit this change to your local branch, otherwise lerna will grumble that you have uncommitted changes.

git add -u

git commit -m "Update registry for lerna local tests"

Publish to your local registry

Publish to the local registry running in the other console.

yarn lerna publish --ignore-scripts from-package

In a third console

Create a simple test app to import the module you're testing, and install the new version from your local registry. For the example below, we're testing a change to turf-clusters-dbscan. Replace with whichever module you're testing.

yarn add @turf/clusters-dbscan --registry http://localhost:4873

Confirm installed version is v7.0.0-pr1234

head node_modules/@turf/clusters-dbscan/package.json

If your simple test app can be run with no "Cannot find module" errors, that's a good sign the standalone package installs all the dependencies it needs.