Commit Graph

18 Commits

Author SHA1 Message Date
Stefan Herbrechtsmeier
eb0c87fa4c bitbake: fetch2: npmsw: remove old lockfile format support
Remove support for the old lockfile format. The old lockfile format is
required by npm 6 / Node.js 14 which is out of maintenance [2].

[1] https://docs.npmjs.com/cli/v6/configuring-npm/package-lock-json
[2] https://nodejs.org/en/about/previous-releases

(Bitbake rev: 7824e19483d9b60a259d6e3a4c7068fade94f2bf)

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2025-01-08 11:34:04 +00:00
Stefan Herbrechtsmeier
02f8ea6865 bitbake: fetch2: npmsw: ignore bundled dependencies in packages
The npm package lock and shrinkwrap file list bundled dependencies which
are supplied together with the parent dependency. The flag depends on
the lock file version. Add the missing `inBundle` flag to packages list
processing.

(Bitbake rev: 042d7121ddc93c18306bf03d26ea774f66379a90)

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2024-12-20 16:18:59 +00:00
Enguerrand de Ribaucourt
ec86853a26 bitbake: fetch2/npmsw: allow packages not declaring a registry version
We fetch npm dependencies from the npm-shrinkwrap.json file. They can
point to a package on the NPM registry with a version field, or to a
git/http/file URL with the resolved field. Such packages are allowed not
to declare a registry version field because they may not have been
published to the NPM registry. The previous implementation refuses to
fetch such packages and throws an error.

The resolved field contains the exact source, including the revision,
wich we can use to pass as SRC_URI to the git/http/file fetcher. The
integrity field is also mandatory for HTTP tarballs which will ensure
reproducibility. So even if the version field is not present, we are
still fetching a precise revision of the package.

Another commit published along this stack is also required in the npm
class to support these packages.

v5:
 - improve commit message
v3:
 - Split bitbake npmsw.py modification in another commit

Co-authored-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
(Bitbake rev: 209982b5a3efc8081e65b4326bf9b64eef7f0ba0)

Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
Signed-off-by: Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2024-08-23 09:48:48 +01:00
Enguerrand de Ribaucourt
524e6b65a6 bitbake: fetch2/npmsw: fix fetching git revisions not on master
The NPM package.json documentation[1] states that git URLs may contain
a commit-ish suffix to specify a specific revision. When running
`npm install`, this revision will be looked for on any branch of the
repository.

The bitbake implementation however translates the URL stored in
package.json into a git URL to be fetch by the bitbake git fetcher. The
bitbake fetcher git.py, enforces the branch to be master by default. If
the revision specified in the package.json is not on the master branch,
the fetch will fail while the package.json is valid.

To fix this, append the ";nobranch=1" suffix to the revision in the git
URL to be fetched. This will make the bitbake git fetcher ignore the
branch and respect the behavior of `npm install``.

This can be tested with the following command:
 $ devtool add --npm-dev https://github.com/seapath/cockpit-cluster-dashboard.git -B version
Which points to a project which has a package.json with a git URL:
```json
  "devDependencies": {
    "cockpit-repo": "git+https://github.com/cockpit-project/cockpit.git#d34cabacb8e5e1e028c7eea3d6e3b606d862b8ac"
  }
```
In this repo, the specified revision is on the "main" branch, which
would fail without this fix.

[1] https://docs.npmjs.com/cli/v10/configuring-npm/package-json#git-urls-as-dependencies

Co-authored-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
(Bitbake rev: 37a35adf7882f231c13643dbf9168497c6a242a1)

Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
Signed-off-by: Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2024-08-23 09:48:48 +01:00
Richard Purdie
7812f104db bitbake: fetch/npmsw: The fetcher shouldn't have any knowledge of S
I don't know why there is hardcoded knowledge of S in the fetcher but there
shouldn't be and the OE unpack changes highlight this doing things it
shouldn't.

Drop the S reference and use rootdir which is the only place it should
be touching.

(Bitbake rev: 84f102954e10a3390fca9c26d5c3c639e952a2c9)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2024-05-23 11:27:08 +01:00
Alberto Pianon
ef3e46afd9 bitbake: fetch2: Add API for upstream source tracing
This patch adds an API to bb.fetch2 to enable users to plug in an unpack
tracer that can trace each source file back to its corresponding
upstream source url, even when multiple upstream sources are combined
together in the same unpack directory. This may be required for software
composition analysis, license compliance, and detailed SBoM generation.

This patch provides only the needed hooks in bb.fetch2 code and a dummy
abstract class defining the API; users may load their own unpack tracer
class by setting the BB_UNPACK_TRACER_CLASS config parameter.

(Bitbake rev: 05051152cc42acc52bcf9af9a696f632fac4307f)

Signed-off-by: Alberto Pianon <alberto@pianon.eu>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-10-15 09:12:43 +01:00
BELOUARGA Mohamed
1f92db2d2c bitbake: bitbake: fetch2/npmsw: Check if there are dependencies before trying to fetch them
When there are no dependencies, _foreach_proxy_method does not verify that there are
dependencies to fetch before fetching them.

(Bitbake rev: 48a102e49448656ef25fb689af7b0971fde523e3)

Signed-off-by: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-08-04 11:48:26 +01:00
Richard Purdie
8ee607b972 bitbake: fetch2/npmsw: Support old and new shrinkwrap formats
"fetch2/npmsw: Add support for the new format of the shrinkwrap file"
added support for the new format shrinkwrap files but this regressed
our tests which still use the old format.

Similar to how npm handles this, support both for now until we can
migrate our tests.

(Bitbake rev: 9941b480a0e2a8b57f2ed069cd583f2784394a2b)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-06-30 09:50:46 +01:00
BELOUARGA Mohamed
d3642c2d10 bitbake: fetch2/npmsw: Don't fetch dev dependencies when they are not demanded
Dev dependencies should not be fetched only if it is specified in the
recipe.

(Bitbake rev: 224c2bb1fd3f16ac4063dc0eb8ba43eee34ba782)

Signed-off-by: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-06-29 11:10:39 +01:00
BELOUARGA Mohamed
d988d31578 bitbake: fetch2/npmsw: Add support for the new format of the shrinkwrap file
Npm is a package manager that has its own manner to handle installation of packages.
But it is not yocto friendly, for instance NPM fetch dependencies in the middle of compilation.

The shrinkwrap file changed its format over npm versions, but npm does not version
this file, so we can use it properly.
The actual changes make NPM depencies work with the actual shrinkwrap format.

(Bitbake rev: 19b9f7f0f451a636f3fdcdc1bb283ab431ede612)

Signed-off-by: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-06-29 11:10:39 +01:00
Svend Meyland Nicolaisen
1a1025658c bitbake: npmsw fetcher: Avoid instantiating Fetch class if url list is empty
Recipes containing both git and npmsw sources in the SRC_URI fail
during fetch from the shrinkwrap. It seems that when the fetcher is
fetching from the shrinkwrap, the SRCREV variable has been deleted but it
till ends up fetching from the git source resulting in an error because
SRCREV is undefined. The root cause of this is that the Fetch class defaults
to urls from the SRC_URI when the urls parameter contains an empty list. This
patch will ensure that Fetch is not instantiated if the urls list is empty.

(Bitbake rev: e602963dfd505eef08702366383358d29ee20c4d)

Signed-off-by: Svend Meyland Nicolaisen <public@smn.dk>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-04-20 11:59:14 +01:00
Mark Asselstine
67d5541f65 bitbake: fetch/npmsw: add more short forms for git operations
>From the npm-install documentation [1] the CLI provides a set of
short forms when the install fetches from git. These include

"github:"
example: npm install github:mygithubuser/myproject

"gist:"
example: npm install gist:101a11beef

"gitlab:"
example: npm install gitlab:mygitlabuser/myproject

"bitbucket:"
example: npm install bitbucket:mybitbucketuser/myproject

Commit 1d8af6aed0a9 [fetch2: npmsw: Add support for github prefix in
npm shrinkwrap version] by Stefan Herbrechtsmeier added support for
the "github:" but the others would marked as 'Unsupported dependency'.

The other prefixes are added in this commit, along with extending the
tests to cover some of these.

However, there is one more short form for github which npm-install
allows which forgoes the prefix altogether.

example: npm install mygithubuser/myproject

Unfortunately this format is a bit problematic as it lacks any easily
identifiable 'marker' to match against, and it could be either the
github short form or install from folder format. Experimentation shows
that the folder format requires a leading './' or '/', so we use this
to rule out the ambiguity.

If this approach to folder and github formats disambiguation is
incorrect it won't matter anyways as the folder format is unrecognized
by the code as-is and thus with this change or without, things would
fail.

Since we have to be less strict in the check for git operations we
move it to be the last install format which we check, such that the
less ambiguous formats can be sorted out first.

[1] https://docs.npmjs.com/cli/v9/commands/npm-install

[Yocto #14236]

(Bitbake rev: 0ac6f6cb5d807919ed13a8b7bb3fb551b79c5a71)

Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-02-26 11:49:41 +00:00
Peter Kjellerstedt
bef3fe4969 bitbake: fetch2: npm: Put all downloaded files in the npm2 directory
Previously npm files that specify downloadfilename= in the SRC_URI
would be downloaded to the root of ${DL_DIR} rather than in the
${DL_DIR}/npm2 directory where all other npm files are downloaded.
This should make it simpler when setting up and configuring a
premirror with the downloaded npm packages.

(Bitbake rev: 73fa376d6502ab6f2cccfb25a1193d9b1c3c3bc8)

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2022-02-05 17:46:44 +00:00
Stefan Herbrechtsmeier
e17d4895ca bitbake: fetch2: npmsw: Add support for github prefix in npm shrinkwrap version
(Bitbake rev: 1d8af6aed0a929f493d2c3e31b8d3ee3a70beb43)

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2021-11-01 11:12:16 +00:00
Stefan Herbrechtsmeier
a3a26e500a bitbake: fetch2: npmsw: Add support for duplicate dependencies without url
(Bitbake rev: 9dcd9a3c671b24982aff9a994e31cb9f491471f5)

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2021-11-01 11:12:16 +00:00
Caner Altinbasak
8e6aaed8ff bitbake: npmsw: Avoid race condition with multiple npm fetchers
If multiple npmsw fetchers are trying to download the same npm file, one of them
can try to download the file while other is calling verify. npmsw methods gets
called without holding the lock, which causes race conditions in fetching and
verification etc. Lock the lockfile before calling proxy fetcher methods.

(Bitbake rev: fa39e6689d0f0fff772e1c81682698f4b1587b8a)

Signed-off-by: Caner Altinbasak <cal@brightsign.biz>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2021-10-14 22:37:43 +01:00
Stefan Herbrechtsmeier
fb437d6db1 bitbake: fetch2: npmsw: Add support for local tarball and link sources
(Bitbake rev: 4f983dc419a1a6f635a5d333f253d49244cec374)

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2021-10-08 16:45:06 +01:00
Jean-Marie LEMETAYER
e0bd972ba7 bitbake: fetch2: add the npmsw fetcher
This commit adds a new npmsw fetcher that fetches every npm dependencies
described in a npm shrinkwrap file:

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

The main package must be fetched separately:

  SRC_URI = "npm://registry.url;package=foobar;version=1.0.0 \
             npmsw://${THISDIR}/npm-shrinkwrap.json"

Since a separation has been created between the package and its
dependencies, the package can also be fetched with a non npm fetcher
without impacting the general behavior:

  SRC_URI = "git://github.com/foo/bar.git;protocol=https \
             npmsw://${THISDIR}/npm-shrinkwrap.json"

(Bitbake rev: f5223be54450bf20e0bfbd53b372a7748a44b475)

Signed-off-by: Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2020-01-27 16:48:10 +00:00