Skip to contentSkip to conversation

Status of the NPM refactoring

DISCUSSION Jean-Marie LEMETAYER 2 participants 4 messages Dec 12, 2019 – Dec 19, 2019

lore
Share & tools
lore
#0 lore raw

Hi folks,

I am currently trying to update/refactor the handling of the NPM packages.

Here is the history of my patchset:

V1:
http://lists.openembedded.org/pipermail/openembedded-core/2019-October/288179.html
http://lists.openembedded.org/pipermail/bitbake-devel/2019-October/020435.html

V2:
http://lists.openembedded.org/pipermail/openembedded-core/2019-October/288352.html
http://lists.openembedded.org/pipermail/bitbake-devel/2019-October/020449.html

V3:
http://lists.openembedded.org/pipermail/openembedded-core/2019-November/289431.html
http://lists.openembedded.org/pipermail/bitbake-devel/2019-November/020532.html

----

I first tried to separate the fetching of a single npm package (with a "npm://" fetcher) and the fetching of its dependencies (managed in the npm.bbclass class). The good thing is that the initial package could be fetched by another fetcher ("git://", "http://" ...) and still get the dependencies by inheriting the npm class based on a npm-shrinkwrap.json file [1].

1: https://docs.npmjs.com/files/shrinkwrap.json

In the latest version, Richard suggest to create another "npmsw://" fetcher to get the dependencies. The fetching of the package and its dependencies is still divided AND the npm class no longer fetches anything, which is much cleaner.

Here is a visual example of what a recipe could be:

    SRC_URI = "npm://registry.npmjs.org;name=my-package;version=${PV} \
               npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json"

    S = "${WORKDIR}/npm"

    inherit npm

----

Thinking about these fetchers I realized that they are in fact "proxy fetchers" as they just generate new URIs that are already handled by bitbake (mainly "http://" but also "git://" and "file://").

The first fetcher "npm://" runs the "npm view" command [2] to get the tarball URI. There is only one URI for this one. The second fetcher have to manage multiple URIs which are already resolved in the npm-shrinkwrap.json file.

2: https://docs.npmjs.com/cli/view.html

To achieve this I have to correctly configure the localfile / localpath of the fetch files and manage the donestamp file and the lockfile. I may need to tweak a little these parts.

----

Another part is about the checksums. To be able to fetch something using "http://" a checksum must be set (md5 or sha256). On its side NPM provides shasum (sha1) or integrity (sha256, sha384 or sha512) [3].

3: https://docs.npmjs.com/files/package-lock.json#integrity

For this to work, I intend to add sha1, sha384 and sha512 support for fetchers. I would like to post these patches before the others because they are not directly related to NPM.

----

Is it OK ? Any thought ? Any advice ?

Best Regards,

Jean-Marie LEMETAYER
Enthusiast embedded systems engineer
Savoir-faire Linux

#1 lore raw

Hi,

Quoted 5 lines · Jean-Marie LEMETAYER

Hi folks,

I am currently trying to update/refactor the handling of the NPM packages. [...]
Is it OK ? Any thought ? Any advice ?

Three questions occurred to me on that whole subject... Mostly based on the understanding that there are no recipes for
the dependencies, only for the
main package.

Firstly:
With your approach, can I force a different version of a dependency to be fetched? I.e. a versions different from what npm would do?

Use case:
Let's say an npm package A somewhere down in the chain of my own (recursive) dependencies pulls in version 1.2 of package B, but version 1.2 is unsuitable for use, e.g. licensing issue. An updated, compatible, but yet unreleased on npmjs.org version of package B exists (e.g. in github), with the licensing fixed.

Can I pull in that alternative version using your approach, as I believe there is no recipe for package C if I understand right, i.e. no place to put the alternative URL.

Secondly:
Say I need to patch an npm package C somewhere down in the chain of my own (recursive) dependencies to fix an issue with package C. Can I do that, as again, I believe there is no recipe for package C where I could update SRC_URI to include my patch.

Thirdly:
Will it be possible to handle projects that use angular natively in yocto using your approach. E.g. have an angular-native recipe that will allow running ng build on the code I'm interested in?

Cheers,
Andre'

PS: Points one and two work with my (updated) script that I had posted some weeks ago here.

#2 lore raw

Hi Andre,

Quoted 25 lines · On Dec 12, 2019, at 9:17 PM, André Draszik [email protected] wrote:

Hi,

Quoted 5 lines · Jean-Marie LEMETAYER

Hi folks,

I am currently trying to update/refactor the handling of the NPM packages. [...]
Is it OK ? Any thought ? Any advice ?

Three questions occurred to me on that whole subject... Mostly based on the understanding that there are no recipes for
the dependencies, only for the
main package.

Firstly:
With your approach, can I force a different version of a dependency to be fetched? I.e. a versions different from what npm would do?

Use case:
Let's say an npm package A somewhere down in the chain of my own (recursive) dependencies pulls in version 1.2 of package B, but version 1.2 is unsuitable for use, e.g. licensing issue. An updated, compatible, but yet unreleased on npmjs.org version of package B exists (e.g. in github), with the licensing fixed.

Quoted 3 lines

Can I pull in that alternative version using your approach, as I believe there is no recipe for package C if I understand right, i.e. no place to put the alternative URL.

Yes you can ! Just update manually the shrinkwrap file and use the npm formatting [1].

1: https://docs.npmjs.com/files/package-lock.json#dependencies

For example you will be able to replace this entry:

    "array-flatten": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
      "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
    }

By this one:

    "array-flatten": {
      "version": "git+https://github.com/blakeembrey/array-flatten.git#66299a02d2ce6a9b6998be333581a87affbb8631"
    }

Note that the first case will use the wget fether and the second case will use the git fetcher.

Quoted 5 lines

Secondly:
Say I need to patch an npm package C somewhere down in the chain of my own (recursive) dependencies to fix an issue with package C. Can I do that, as again, I believe there is no recipe for package C where I could update SRC_URI to include my patch.

Yes you can ! After the fetch tasks the dependencies will be available in the ${S} directory (this is mandatory for the license management). The dependencies can be patched as usual. Note that you have to use the full path of the dependency ("/node_modules/array-flatten/...").

For example your patch could look like this:

    diff --git a/node_modules/array-flatten/array-flatten.js b/node_modules/array-flatten/array-flatten.js
    index 089117b..1b83b82 100644
    --- a/node_modules/array-flatten/array-flatten.js
    +++ b/node_modules/array-flatten/array-flatten.js
    @@ -60,5 +60,6 @@ function arrayFlatten (array, depth) {
         return flattenForever(array, [])
       }
     
    +  console.log("Hello World");
       return flattenWithDepth(array, [], depth)
     }
    --
Quoted 4 lines

Thirdly:
Will it be possible to handle projects that use angular natively in yocto using your approach. E.g. have an angular-native recipe that will allow running ng build on the code I'm interested in?

Yes, the ultimate goal of this update / refactoring is to add an angular support in Yocto. I have already done this work for my project.

The final recipe could look like this:

    SRC_URI = "npm://registry.npmjs.org;name=my-package;version=${PV} \
               npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json"

    S = "${WORKDIR}/npm"

    inherit angular

Kind regards,
Jean-Marie

#3 lore raw

Hi Jean-Marie,

Quoted 8 lines · Jean-Marie LEMETAYER

Hi Andre,

Quoted 5 lines · On Dec 12, 2019, at 9:17 PM, André Draszik [email protected] wrote:

Hi,

Quoted 2 lines · Jean-Marie LEMETAYER

Hi folks,

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

I am currently trying to update/refactor the handling of the NPM packages. [...]
Is it OK ? Any thought ? Any advice ?

Three questions occurred to me on that whole subject... Mostly based on the

[...]

Thanks for taking the time to answer my questions - sounds fantastic.

I'll give it a try sometime soon.

Cheers,
Andre'