diff options
author | Martin Jansa <martin.jansa@gmail.com> | 2024-01-15 15:16:31 +0100 |
---|---|---|
committer | Martin Jansa <martin.jansa@gmail.com> | 2024-04-16 09:00:51 +0200 |
commit | da8ade3c7f6fbcb9c9dc843daddb2b7912ba4242 (patch) | |
tree | b13f14630a81045b7dabbafc985b573ee3a06c46 | |
parent | 6361cbde7093eefe8d517d2c5f859a53e09035a3 (diff) | |
download | bitbake-contrib-da8ade3c7f6fbcb9c9dc843daddb2b7912ba4242.tar.gz |
tests: fetch2: npm-local-link-sources: add a test for npmsw fetcher with local link sources
* https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json
shows 3 examples:
http tarball sources: This is the URL of the tarball. (eg, https://example.com/example-1.3.0.tgz)
local tarball sources: This is the file URL of the tarball. (eg file:///opt/storage/example-1.3.0.tgz)
local link sources: This is the file URL of the link. (eg file:libs/our-module)
it's not clear if the last one should start with file://, but in:
https://git.openembedded.org/bitbake/commit/lib/bb/fetch2/npmsw.py?id=4f983dc419a1a6f635a5d333f253d49244cec374
we strip 5 chars in:
localpath = version[5:]
so file:// wouldn't work in such case.
It works well when parsing the dependency in:
"@npm-local-link-sources/upper": "file:../"
but then when parsing the npm-shrinkwrap.json package like:
"..": {
"name": "@local-link-sources/upper",
"version": "1.0.0"
},
"node_modules/@local-link-sources/upper": {
"resolved": "..",
"link": true
}
it fails with:
bb.data_smart.ExpansionError: Failure expanding variable fetcher_hashes_dummyfunc[vardepvalue], expression was ${@bb.fetch.get_hashvalue(d)} which triggered exception ParameterError: URL: 'npmsw://npm-shrinkwrap.json' has invalid parameters. Unsupported dependency: ..
because it no longer has the "file:" prefix in the version to recognize local link.
https://git.openembedded.org/bitbake/commit/lib/bb/fetch2/npmsw.py?id=19b9f7f0f451a636f3fdcdc1bb283ab431ede612
switched to walk "packages" instead of "dependencies" to support
lockfileVersion 2 (and 3) as in:
No version provided: an "ancient" shrinkwrap file from a version of npm prior to npm v5.
1: The lockfile version used by npm v5 and v6.
2: The lockfile version used by npm v7 and v8. Backwards compatible to v1 lockfiles.
3: The lockfile version used by npm v9 and above. Backwards compatible to npm v7.
Add the npm source with npm-shrinkwrap files generated for all 3
versions to better document the differences in this case and also
easily compare what might change in some future npm with another
lockfileVersion:
npm-shrinkwrap-v1.json generated with npm-6.14.18
npm-shrinkwrap-v2.json generated with npm-8.19.4
npm-shrinkwrap-v3.json generated with npm-10.1.0
There is only exception for "" package name used for root package
and for all other packages it expects "node_modules/" prefix, which
is stripped from the name
* I don't know how common this case is in npm ecosystem, but this is what
we have in some component and what was failing with current npmsw://
implementation, the SRC_URI is git repository with some libraries
and a "sampler", S points to the "sampler" directory and npmsw:// uses
the shrinkwrap file from this "sampler" which refers to the libraries
to test in the directories above (so that it tests the libraries from
the same checkout, not some other released version from npm registry)
Signed-off-by: Martin Jansa <martin.jansa@gmail.com>
6 files changed, 93 insertions, 0 deletions
diff --git a/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/npm-shrinkwrap-v1.json b/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/npm-shrinkwrap-v1.json new file mode 100644 index 000000000..bcdca7de9 --- /dev/null +++ b/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/npm-shrinkwrap-v1.json @@ -0,0 +1,11 @@ +{ + "name": "@npm-local-link-sources/inner", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@npm-local-link-sources/upper": { + "version": "file:.." + } + } +} diff --git a/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/npm-shrinkwrap-v2.json b/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/npm-shrinkwrap-v2.json new file mode 100644 index 000000000..2427acf2d --- /dev/null +++ b/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/npm-shrinkwrap-v2.json @@ -0,0 +1,28 @@ +{ + "name": "@npm-local-link-sources/inner", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "@npm-local-link-sources/inner", + "version": "1.0.0", + "dependencies": { + "@npm-local-link-sources/upper": "file:../" + } + }, + "..": { + "name": "@npm-local-link-sources/upper", + "version": "1.0.0" + }, + "node_modules/@npm-local-link-sources/upper": { + "resolved": "..", + "link": true + } + }, + "dependencies": { + "@npm-local-link-sources/upper": { + "version": "file:.." + } + } +} diff --git a/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/npm-shrinkwrap-v3.json b/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/npm-shrinkwrap-v3.json new file mode 100644 index 000000000..99e0e8f6b --- /dev/null +++ b/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/npm-shrinkwrap-v3.json @@ -0,0 +1,23 @@ +{ + "name": "@npm-local-link-sources/inner", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@npm-local-link-sources/inner", + "version": "1.0.0", + "dependencies": { + "@npm-local-link-sources/upper": "file:../" + } + }, + "..": { + "name": "@npm-local-link-sources/upper", + "version": "1.0.0" + }, + "node_modules/@npm-local-link-sources/upper": { + "resolved": "..", + "link": true + } + } +} diff --git a/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/package.json b/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/package.json new file mode 100644 index 000000000..a578771b9 --- /dev/null +++ b/lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/package.json @@ -0,0 +1,8 @@ +{ + "name": "@npm-local-link-sources/inner", + "version": "1.0.0", + "description": "Inner project in npm-local-link-sources example", + "dependencies": { + "@npm-local-link-sources/upper": "file:../" + } +} diff --git a/lib/bb/tests/fetch-testdata/npm-local-link-sources/package.json b/lib/bb/tests/fetch-testdata/npm-local-link-sources/package.json new file mode 100644 index 000000000..42176c3ed --- /dev/null +++ b/lib/bb/tests/fetch-testdata/npm-local-link-sources/package.json @@ -0,0 +1,5 @@ +{ + "name": "@npm-local-link-sources/upper", + "version": "1.0.0", + "description": "Upper project in npm-local-link-sources example" +} diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py index 85c1f79ff..5233ab5c8 100644 --- a/lib/bb/tests/fetch.py +++ b/lib/bb/tests/fetch.py @@ -2891,6 +2891,24 @@ class NPMTest(FetcherTest): self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'gitlab.com.gitlab-examples.nodejs.git'))) @skipIfNoNpm() + def test_npmsw_local_link_sources(self): + # generated with npm-10 in: + # lib/bb/tests/fetch-testdata/npm-local-link-sources/inner/ + testdata = os.path.dirname(os.path.abspath(__file__)) + "/fetch-testdata" + testdir = os.path.join(testdata, 'npm-local-link-sources') + + self.sdir = os.path.join(self.unpackdir, testdata[1:], 'npm-local-link-sources', 'inner') + self.d.setVar('S', os.path.join(self.sdir)) + + fetcher = bb.fetch.Fetch(['file://%s/' % testdir, 'npmsw://%s/inner/npm-shrinkwrap-v3.json' % testdir], self.d) + fetcher.download() + fetcher.unpack(self.unpackdir) + + swf = os.path.join(self.sdir, 'npm-shrinkwrap-v3.json') + pkgf = os.path.join(self.sdir, 'node_modules', '@npm-local-link-sources/upper', 'package.json') + self.assertTrue(os.path.exists(swf), msg="%s doesn't exist" % swf) + self.assertTrue(os.path.exists(pkgf), msg="%s doesn't exist" % pkgf) + @skipIfNoNetwork() def test_npmsw_dev(self): swfile = self.create_shrinkwrap_file({ |