[bitbake-devel,v2] bitbake: fetch2/npm: allow to build npm package with no dependency
Submitted by Sandra Tobajas on Aug. 28, 2020, 7:06 p.m.
|
Patch ID: 175788
Details
Commit Message
@@ -177,17 +177,21 @@ class NpmShrinkWrap(FetchMethod):
# This fetcher resolves multiple URIs from a shrinkwrap file and then
# forwards it to a proxy fetcher. The management of the donestamp file,
# the lockfile and the checksums are forwarded to the proxy fetcher.
- ud.proxy = Fetch([dep["url"] for dep in ud.deps], data)
+ if ud.deps:
+ ud.proxy = Fetch([dep["url"] for dep in ud.deps], data)
+ else:
+ ud.proxy = None
ud.needdonestamp = False
@staticmethod
def _foreach_proxy_method(ud, handle):
returns = []
- for proxy_url in ud.proxy.urls:
- proxy_ud = ud.proxy.ud[proxy_url]
- proxy_d = ud.proxy.d
- proxy_ud.setup_localpath(proxy_d)
- returns.append(handle(proxy_ud.method, proxy_ud, proxy_d))
+ if ud and ud.proxy:
+ for proxy_url in ud.proxy.urls:
+ proxy_ud = ud.proxy.ud[proxy_url]
+ proxy_d = ud.proxy.d
+ proxy_ud.setup_localpath(proxy_d)
+ returns.append(handle(proxy_ud.method, proxy_ud, proxy_d))
return returns
def verify_donestamp(self, ud, d):
@@ -2308,6 +2308,26 @@ class NPMTest(FetcherTest):
self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'package.json')))
self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'node_modules', 'cookie', 'package.json')))
+ @skipIfNoNpm()
+ @skipIfNoNetwork()
+ def test_npmsw_nodeps(self):
+ swfile = self.create_shrinkwrap_file({
+ 'dependencies': {
+ 'content-type': {
+ 'version': '1.0.4',
+ 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
+ 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
+ 'dev': True
+ }
+ }
+ })
+ # Fetch with dev disabled
+ fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+ fetcher.download()
+ self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
+ fetcher.unpack(self.unpackdir)
+ self.assertTrue(os.path.exists(os.path.join(self.sdir, 'npm-shrinkwrap.json')))
+
@skipIfNoNpm()
@skipIfNoNetwork()
def test_npmsw_dev(self):
In the case of an empty npm-shrinkwrap.json file (with no dependency), the npmsw fetcher was causing a RecursionError reported in [1]. It also happened if the package has only "dev" dependencies and was built without --npm-dev option. Add sanity checks to ensure that the dependency list is not empty and set the urldata proxy attribute to None if no dependency is found. Add bb.tests.fetch.NPMTest.test_npmsw_nodeps unit test to ensure that a npm package without dependency can be built. [1] https://bugzilla.yoctoproject.org/show_bug.cgi?id=13901. Signed-off-by: Sandra Tobajas <sandra.tobajas@savoirfairelinux.com> --- bitbake/lib/bb/fetch2/npmsw.py | 16 ++++++++++------ bitbake/lib/bb/tests/fetch.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-)