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-06-28 12:55:26 +0100
commit6853b9b7d5f86c8080fe9a09811f57a411c74deb (patch)
treeb87cb3baac140c772215ae48318246a9d4f1839f /meta
parent08f020325ba173707f4493c19a789579ab14b65f (diff)
downloadpoky-6853b9b7d5f86c8080fe9a09811f57a411c74deb.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: 68b480d64ffb6750699cc8fa00d2ac0bc6a2e58a) Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de> 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 dbfc2e728e..492935a85e 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 """