Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to install current master modules while waiting for a release? #2229

Closed
ThomasG77 opened this issue Nov 27, 2021 · 3 comments
Closed
Labels

Comments

@ThomasG77
Copy link
Contributor

ThomasG77 commented Nov 27, 2021

Please provide the following when reporting an issue:

This question is related to the following issue

  • The version of Turf: v6.5.0
  • to reproduce

When I run

wget https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_rivers_lake_centerlines_scale_rank.geojson

and

ndjson-split 'd.features' < ne_50m_rivers_lake_centerlines_scale_rank.geojson | ndjson-map -r turf=@turf/turf 'turf.lineChunk(d, 50).features.map(el => {el.properties = d. properties; return el})'

It works. However, when I do,

ndjson-split 'd.features' < ne_50m_rivers_lake_centerlines_scale_rank.geojson | ndjson-map -r turf=@turf/turf 'turf.lineChunk(d, 50, {"units": "kilometers"}).features.map(el => {el.properties = d. properties; return el})'

It throws the following

/home/thomasg/.nvm/versions/node/v16.13.0/lib/node_modules/@turf/turf/node_modules/@turf/line-chunk/dist/js/index.js:39
  if (!helpers.isObject(options)) throw new Error("options is invalid");
                                  ^
Error: options is invalid
    at Object.lineChunk (/home/thomasg/.nvm/versions/node/v16.13.0/lib/node_modules/@turf/turf/node_modules/@turf/line-chunk/dist/js/index.js:39:41)
    at evalmachine.<anonymous>:1:7
    at Script.runInContext (node:vm:139:12)
    at Interface.<anonymous> (/home/thomasg/.nvm/versions/node/v16.13.0/lib/node_modules/ndjson-cli/ndjson-map:45:14)
    at Interface.emit (node:events:390:28)
    at Interface._onLine (node:readline:487:10)
    at Interface._normalWrite (node:readline:661:12)
    at Socket.ondata (node:readline:269:10)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)

The error is thrown due to line https://github.com/Turfjs/turf/blob/v6.5.0/packages/turf-line-chunk/index.js#L28 where we test helpers.isObject(options). While inspecting the isObject function e.g https://github.com/Turfjs/turf/blob/v6.5.0/packages/turf-helpers/index.ts#L765-L767 we see the following

export function isObject(input: any): boolean {
  return !!input && input.constructor === Object;
}

input.constructor === Object is false because input.constructor value is [Function: Object]

In master, e.g below code (visible also at https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/index.ts#L765-L767), we've seen the function has been changed and if changed manually in version 6.5 module (excepting the js/ts syntax differences), the previous failing command line works

export function isObject(input: any): boolean {
  return input !== null && typeof input === "object" && !Array.isArray(input);
}

Trying to install current Turf master version instead of v6.5.0 with

npm install Turfjs/turf#master -g

It failed. I also didn't see any prelease at https://www.npmjs.com/package/@turf/turf.

So, what did I miss to install locally all modules from master to a third party code repository that also use Node.js?

@ThomasG77
Copy link
Contributor Author

ThomasG77 commented Dec 11, 2021

Clearly annoying and did not find a simple solution. One approach below that works. Not closing as I would expect a simpler solution than my own solution if possible.

How to build local Turf packages from master

First console

Get code

git clone https://github.com/Turfjs/turf.git
cd turf

Create branch and switch to it (6.6.0 because at time of writing current version is 6.5.0)

git checkout -b v6.6.0

Follow partly release recipe (https://github.com/Turfjs/turf/blob/master/CONTRIBUTING.md#release)

yarn lerna version --no-push --no-commit-hooks 6.6.0

In a 2nd console

Install a local registry using verdaccio

npm i verdaccio -g
verdaccio

Do not kill the console as you need verdaccio running

In the first console

Create a new user (registry empty) with the following and type your username, password and mail

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

Login to local registry (type same info as the one you choose above)

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

Change registry url with the following (or edit lerna.json manually if no sed utility)

sed -i 's#https://registry.npmjs.org#http://localhost:4873#g' lerna.json
git add -u
git commit -m "Update registry for lerna local tests"

Publish to local registry

yarn lerna publish --ignore-scripts from-package

Install new version from your local registry and you're done

npm i @turf/turf --registry  http://localhost:4873

Confirm installed version is 6.6.0

  • If global install, head $(npm root -g)/@turf/turf/package.json
  • If local install, head $(npm root)/@turf/turf/package.json or node -e "const turf_package_json = require.resolve('@turf/turf/package.json');console.log(turf_package_json)"

To get tgz files list you usually get infos from packages in the registry, do

curl "http://localhost:4873/-/verdaccio/packages" >| packages.json

Retrieve the tgz files

mkdir turf-standalone
cd turf-standalone
wget -i <(jq -r '.[].dist.tarball' ../packages.json)

If you want to install from the tgz files from the local registry, do

npm install -g *.tgz

Reuse packages

For end-users (that do not have verdaccio installed), download the attached zip file that contains all tgz from last steps. Unzip the dir in your project

mkdir demo
cd demo
npm init -y
cp -r ../turf-standalone .
cd turf-standalone
npm install -g *.tgz
cd ..

Test it works

echo "const turf = require('@turf/turf');
var point = turf.point([-90.548630, 14.616599]);
var buffered = turf.buffer(point, 500, {units: 'miles'});
console.log(buffered);
" >| index.js
node index.js
@stebogit
Copy link
Collaborator

Ref #1720, just for the records

@smallsaucepan
Copy link
Member

@ThomasG77 doesn't seem like an simpler solution has appeared, so have promoted your instructions to a wiki page - https://github.com/Turfjs/turf/wiki/Contributing#deploy-to-a-local-node-registry

Thanks for putting them together. Will close this issue as understand the original problem was fixed in #1720

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 participants