summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorEnrico Scholz <enrico.scholz@sigma-chemnitz.de>2022-05-19 12:05:51 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-09-12 08:41:48 +0100
commitc5feaa512036a4c855547c5261c68b0828cf9e16 (patch)
treeeef2c26b6e7e80ccbfa5b04c92b41c9d4664c2c4 /meta
parentb7d5addf56c7f9d1b7d733cf5c907b0c45be63e5 (diff)
downloadpoky-c5feaa512036a4c855547c5261c68b0828cf9e16.tar.gz
npm: replace 'npm pack' call by 'tar czf'
'npm pack' is a maintainer tool which tries to execute 'prepare' and similar scripts. This fails usually in OE because it requires completely installed 'node_modules'. Earlier nodejs versions supported an undocumented 'ignore-scripts' option. This has been removed in nodejs 16. We could patch 'package.json' and remove the unwanted scripts. But this might complicate local workflows (applying patches) and installed packages will contain the modified 'package.json'. Instead of, package it manually by 'tar czf'. As a sideeffect, 'do_configure' is running much faster now. (From OE-Core rev: 8a83fbca45a74c30265168767a716e1a272df89b) Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 68b480d64ffb6750699cc8fa00d2ac0bc6a2e58a) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/npm.bbclass35
1 files changed, 29 insertions, 6 deletions
diff --git a/meta/classes/npm.bbclass b/meta/classes/npm.bbclass
index ba50fcac20..91f8f36b0d 100644
--- a/meta/classes/npm.bbclass
+++ b/meta/classes/npm.bbclass
@@ -57,13 +57,36 @@ def npm_global_configs(d):
57 configs.append(("cache", d.getVar("NPM_CACHE"))) 57 configs.append(("cache", d.getVar("NPM_CACHE")))
58 return configs 58 return configs
59 59
60## 'npm pack' runs 'prepare' and 'prepack' scripts. Support for
61## 'ignore-scripts' which prevents this behavior has been removed
62## from nodejs 16. Use simple 'tar' instead of.
60def npm_pack(env, srcdir, workdir): 63def npm_pack(env, srcdir, workdir):
61 """Run 'npm pack' on a specified directory""" 64 """Emulate 'npm pack' on a specified directory"""
62 import shlex 65 import subprocess
63 cmd = "npm pack %s" % shlex.quote(srcdir) 66 import os
64 args = [("ignore-scripts", "true")] 67 import json
65 tarball = env.run(cmd, args=args, workdir=workdir).strip("\n") 68
66 return os.path.join(workdir, tarball) 69 src = os.path.join(srcdir, 'package.json')
70 with open(src) as f:
71 j = json.load(f)
72
73 # base does not really matter and is for documentation purposes
74 # only. But the 'version' part must exist because other parts of
75 # the bbclass rely on it.
76 base = j['name'].split('/')[-1]
77 tarball = os.path.join(workdir, "%s-%s.tgz" % (base, j['version']));
78
79 # TODO: real 'npm pack' does not include directories while 'tar'
80 # does. But this does not seem to matter...
81 subprocess.run(['tar', 'czf', tarball,
82 '--exclude', './node-modules',
83 '--exclude-vcs',
84 '--transform', 's,^\./,package/,',
85 '--mtime', '1985-10-26T08:15:00.000Z',
86 '.'],
87 check = True, cwd = srcdir)
88
89 return tarball
67 90
68python npm_do_configure() { 91python npm_do_configure() {
69 """ 92 """