poetapp / poet-js

Po.et JS is an small library that provides methods to easily create and sign Po.et Claims.
https://www.npmjs.com/package/@po.et/poet-js
MIT License
52 stars 4 forks source link

Research how to avoid node-gyp native build #250

Open krobi64 opened 6 years ago

krobi64 commented 6 years ago

Dependency https://github.com/digitalbazaar/jsonld.js has a dependency on https://github.com/digitalbazaar/rdf-canonize (a feature we use to build claims)

https://github.com/digitalbazaar/rdf-canonize#nodejs--npm states:

NOTE: This package has an optional dependency on rdf-canonize-native. If native build tools are not available then the native bindings will fail to build and only the JavaScript implementation will be used. If you wish to ensure you get the higher performance of the native code, and want to ensure build failures will not be ignored, then you should also add a dependency on rdf-canonize-native to your project.

If the native bindings fail to build, npm exits with a non-zero status, which breaks our CI. For libraries not performing canonization, possibly using npm --no-optional would resolve this, but apparently npm has had issues with that flag that they've fixed at least twice.

Research required.

wzalazar commented 6 years ago

we have set the option --no-optional with false in all repositories in the file .npmrc

for example: https://github.com/poetapp/poet-js/blob/master/.npmrc

lautarodragan commented 5 years ago

Thinking a bit more about this... I think native dependencies are only available in the context of Node JS. When running in the browser, we probably don't want to build using native dependencies.

So even if we somehow got around the Netlify / whatever limitation... it's possible that then the application would fail at run time, since the browser allows no access to native libraries.

In other words: how do we use JSON-LD in the browser?

@geoffturk I'd like to come back to this asap, because if we find out we can't use JSON-LD in the browser at all... that's a limitation better known sooner rather than later.

geoffturk commented 5 years ago

It's in the current milestone, so feel free to get to the bottom of it as soon as you can.

wzalazar commented 5 years ago

more in depth, I did this research about the behavior of --no-optional

First I created a project npm

mkdir test-native
cd test-native
npm init --yes

after that I installed the pakcages rdf-canonize and jsonld but one at a time

Fist with rdf-canonize

npm i --no-optional rdf-canonize

screen shot 2018-12-06 at 21 28 46

in this case the optional packages was omitted, that's fine

after I tried the same with npm i rdf-canonize

screen shot 2018-12-06 at 21 29 15

in this case the optional packages was installed, that's fine

now, I did the same with jsonld, previous I deleted the node_modules and the package-lock

npm i --no-optional jsonld

screen shot 2018-12-06 at 21 30 07

in this case the optional packages was installed, that's wrong, I was waiting that omit the optional package.

The expected behavior is that NPM has to omit optional packages with the deep packages also.

krobi64 commented 5 years ago

Why would the browser require jsonld or jsonld-signatures?

On another note, I played around with making jsonld-signatures optional in the poet-js library. Running npm -i --no-optional still build the optional package. I'll try to make both jsonld and jsonld-signatures optional.

lautarodragan commented 5 years ago

Why would the browser require jsonld or jsonld-signatures?

We could sign claims right there in the browser with metamask in the future. Not in the roadmap, but I do want to know if it's at all possible or straight off the table.

Also: we keep some things in Po.et JS that are shared by different projects and could be used in both browserland and nodejs. It may make sense to move this stuff out of Po.et JS, but I'd rather know sooner rather than later whether we need to limit Po.et JS to JSON-LD related stuff only and keep anything else in another package.

IMO the conclusion of this research should be one of: