aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jansa <martin.jansa@gmail.com>2024-01-15 16:21:09 +0100
committerMartin Jansa <martin.jansa@gmail.com>2024-04-16 09:00:51 +0200
commit6361cbde7093eefe8d517d2c5f859a53e09035a3 (patch)
treed00c2cfbe0015ac326c2b0b67f022a281bcc2605
parentd05a6683ebf021232f9639f2c6c83dc6d85e7f7c (diff)
downloadbitbake-contrib-6361cbde7093eefe8d517d2c5f859a53e09035a3.tar.gz
fetch2: npmsw: add support for local link sources with relative path to parent directory
* parse only the packages starting with node_modules/ it was already stripping the 'node_modules/' prefix from package name and had exception for root package with empty name, but for other local sources like '..' it failed to parse the url and triggered ParamterError * also allow missing version in cases which are resolved and link, e.g.: "node_modules/@npm-local-link-sources/upper": { "resolved": "..", "link": true } * we need to use symlink instead of copy, because otherwise cp will fail when trying to copy parent directory from relative path over itself this seems much more fragile than I would prefer, but haven't found easier way yet Signed-off-by: Martin Jansa <martin.jansa@gmail.com>
-rw-r--r--lib/bb/fetch2/npmsw.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/bb/fetch2/npmsw.py b/lib/bb/fetch2/npmsw.py
index cdab56ea4..1a1e4f41b 100644
--- a/lib/bb/fetch2/npmsw.py
+++ b/lib/bb/fetch2/npmsw.py
@@ -61,7 +61,7 @@ def foreach_dependencies(shrinkwrap, callback=None, dev=False):
packages = shrinkwrap.get("packages", None)
if packages is not None:
for package in packages:
- if package != "":
+ if package.startswith('node_modules/'):
name = package.split('node_modules/')[-1]
package_infos = packages.get(package, {})
if dev == False and package_infos.get("dev", False):
@@ -99,9 +99,17 @@ class NpmShrinkWrap(FetchMethod):
resolved = params.get("resolved", None)
version = params.get("version", None)
depname = params.get("name", None)
+ link = params.get("link", None)
+
+ # Handle local link sources without version
+ if not version and resolved and link:
+ localpath = resolved
+ if not localpath.endswith(".tgz"):
+ unpack = False
# Handle registry sources
- if is_semver(version) and integrity:
+ elif is_semver(version) and integrity:
+
# Handle duplicate dependencies without url
if not resolved:
return
@@ -295,9 +303,15 @@ class NpmShrinkWrap(FetchMethod):
if dep["unpack"]:
npm_unpack(depsrcdir, depdestdir, d)
else:
- bb.utils.mkdirhier(depdestdir)
- cmd = 'cp -fpPRH "%s/." .' % (depsrcdir)
- runfetchcmd(cmd, d, workdir=depdestdir)
+ if os.path.commonpath([os.path.abspath(depsrcdir)]) == os.path.commonpath([os.path.abspath(depsrcdir), os.path.abspath(depdestdir)]):
+ # If the depsrcdir is some parent directory of depdestdir use symlink there, to avoid trying to copy itself
+ bb.utils.mkdirhier(os.path.dirname(depdestdir))
+ cmd = 'ln -snf "%s" "%s"' % (depsrcdir, depdestdir)
+ runfetchcmd(cmd, d)
+ else:
+ bb.utils.mkdirhier(depdestdir)
+ cmd = 'cp -fpPRH "%s/." .' % (depsrcdir)
+ runfetchcmd(cmd, d, workdir=depdestdir)
def clean(self, ud, d):
"""Clean any existing full or partial download"""