diff options
| author | BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com> | 2023-05-31 00:27:51 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-06-29 11:10:39 +0100 |
| commit | 17732f9cb4a4925d6e5419a0122d052ca1d5556a (patch) | |
| tree | 88dc49d93cfbf083cb68eaed05e9522a59171e52 | |
| parent | 2dacac93bccc5c50bde1749f9b3f86a3a953d760 (diff) | |
| download | poky-17732f9cb4a4925d6e5419a0122d052ca1d5556a.tar.gz | |
classes: npm: Add support for the new format of the shrinkwrap file
1 - Adapt do_configure to the new format of the shrinkwrap
2 - Remove useless function _npmsw_dependency_dict because the dictionnary
is already given by npmsw:foreach_dependencies
3 - Rename arguments of callback functions
(From OE-Core rev: 89e02fa47e8e4f77b7d7c552c07f8dc05f6e42ad)
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>
| -rw-r--r-- | meta/classes-recipe/npm.bbclass | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/meta/classes-recipe/npm.bbclass b/meta/classes-recipe/npm.bbclass index 92e59fefce..c1944ca14e 100644 --- a/meta/classes-recipe/npm.bbclass +++ b/meta/classes-recipe/npm.bbclass | |||
| @@ -130,22 +130,6 @@ python npm_do_configure() { | |||
| 130 | sha512 = bb.utils.sha512_file(tarball) | 130 | sha512 = bb.utils.sha512_file(tarball) |
| 131 | return "sha512-" + base64.b64encode(bytes.fromhex(sha512)).decode() | 131 | return "sha512-" + base64.b64encode(bytes.fromhex(sha512)).decode() |
| 132 | 132 | ||
| 133 | def _npmsw_dependency_dict(orig, deptree): | ||
| 134 | """ | ||
| 135 | Return the sub dictionary in the 'orig' dictionary corresponding to the | ||
| 136 | 'deptree' dependency tree. This function follows the shrinkwrap file | ||
| 137 | format. | ||
| 138 | """ | ||
| 139 | ptr = orig | ||
| 140 | for dep in deptree: | ||
| 141 | if "dependencies" not in ptr: | ||
| 142 | ptr["dependencies"] = {} | ||
| 143 | ptr = ptr["dependencies"] | ||
| 144 | if dep not in ptr: | ||
| 145 | ptr[dep] = {} | ||
| 146 | ptr = ptr[dep] | ||
| 147 | return ptr | ||
| 148 | |||
| 149 | # Manage the manifest file and shrinkwrap files | 133 | # Manage the manifest file and shrinkwrap files |
| 150 | orig_manifest_file = d.expand("${S}/package.json") | 134 | orig_manifest_file = d.expand("${S}/package.json") |
| 151 | orig_shrinkwrap_file = d.expand("${S}/npm-shrinkwrap.json") | 135 | orig_shrinkwrap_file = d.expand("${S}/npm-shrinkwrap.json") |
| @@ -177,24 +161,25 @@ python npm_do_configure() { | |||
| 177 | progress_total = 1 # also count the main package | 161 | progress_total = 1 # also count the main package |
| 178 | progress_done = 0 | 162 | progress_done = 0 |
| 179 | 163 | ||
| 180 | def _count_dependency(name, params, deptree): | 164 | def _count_dependency(name, params, destsuffix): |
| 181 | nonlocal progress_total | 165 | nonlocal progress_total |
| 182 | progress_total += 1 | 166 | progress_total += 1 |
| 183 | 167 | ||
| 184 | def _cache_dependency(name, params, deptree): | 168 | def _cache_dependency(name, params, destsuffix): |
| 185 | destsubdirs = [os.path.join("node_modules", dep) for dep in deptree] | ||
| 186 | destsuffix = os.path.join(*destsubdirs) | ||
| 187 | with tempfile.TemporaryDirectory() as tmpdir: | 169 | with tempfile.TemporaryDirectory() as tmpdir: |
| 188 | # Add the dependency to the npm cache | 170 | # Add the dependency to the npm cache |
| 189 | destdir = os.path.join(d.getVar("S"), destsuffix) | 171 | destdir = os.path.join(d.getVar("S"), destsuffix) |
| 190 | (tarball, pkg) = npm_pack(env, destdir, tmpdir) | 172 | (tarball, pkg) = npm_pack(env, destdir, tmpdir) |
| 191 | _npm_cache_add(tarball, pkg) | 173 | _npm_cache_add(tarball, pkg) |
| 192 | # Add its signature to the cached shrinkwrap | 174 | # Add its signature to the cached shrinkwrap |
| 193 | dep = _npmsw_dependency_dict(cached_shrinkwrap, deptree) | 175 | dep = params |
| 194 | dep["version"] = pkg['version'] | 176 | dep["version"] = pkg['version'] |
| 195 | dep["integrity"] = _npm_integrity(tarball) | 177 | dep["integrity"] = _npm_integrity(tarball) |
| 196 | if params.get("dev", False): | 178 | if params.get("dev", False): |
| 197 | dep["dev"] = True | 179 | dep["dev"] = True |
| 180 | if "dependencies" not in cached_shrinkwrap: | ||
| 181 | cached_shrinkwrap["dependencies"] = {} | ||
| 182 | cached_shrinkwrap["dependencies"][name] = dep | ||
| 198 | # Display progress | 183 | # Display progress |
| 199 | nonlocal progress_done | 184 | nonlocal progress_done |
| 200 | progress_done += 1 | 185 | progress_done += 1 |
