Openembedded Core Discussions
 help / color / mirror / Atom feed
From: "Zoltan Boszormenyi" <zboszor@pr.hu>
To: enrico.scholz@sigma-chemnitz.de,
	openembedded-core@lists.openembedded.org
Subject: Re: [OE-core] [PATCH 1/6] npm: replace 'npm pack' call by 'tar czf'
Date: Thu, 19 May 2022 12:25:22 +0200	[thread overview]
Message-ID: <5d21c744-33c3-ae3e-c902-712be3918d4e@pr.hu> (raw)
In-Reply-To: <42a8c94825cdcee944a274210a78e9e9940e6b63.1652954597.git.enrico.scholz@sigma-chemnitz.de>

2022. 05. 19. 12:05 keltezéssel, Enrico Scholz via lists.openembedded.org írta:
> '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.

\o/ Hurray!

> 
> Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> ---
>   meta/classes/npm.bbclass | 35 +++++++++++++++++++++++++++++------
>   1 file 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):
>       configs.append(("cache", d.getVar("NPM_CACHE")))
>       return configs
>   
> +## 'npm pack' runs 'prepare' and 'prepack' scripts. Support for
> +## 'ignore-scripts' which prevents this behavior has been removed
> +## from nodejs 16.  Use simple 'tar' instead of.
>   def npm_pack(env, srcdir, workdir):
> -    """Run 'npm pack' on a specified directory"""
> -    import shlex
> -    cmd = "npm pack %s" % shlex.quote(srcdir)
> -    args = [("ignore-scripts", "true")]
> -    tarball = env.run(cmd, args=args, workdir=workdir).strip("\n")
> -    return os.path.join(workdir, tarball)
> +    """Emulate 'npm pack' on a specified directory"""
> +    import subprocess
> +    import os
> +    import json
> +
> +    src = os.path.join(srcdir, 'package.json')
> +    with open(src) as f:
> +        j = json.load(f)
> +
> +    # base does not really matter and is for documentation purposes
> +    # only.  But the 'version' part must exist because other parts of
> +    # the bbclass rely on it.
> +    base = j['name'].split('/')[-1]
> +    tarball = os.path.join(workdir, "%s-%s.tgz" % (base, j['version']));
> +
> +    # TODO: real 'npm pack' does not include directories while 'tar'
> +    # does.  But this does not seem to matter...
> +    subprocess.run(['tar', 'czf', tarball,
> +                    '--exclude', './node-modules',
> +                    '--exclude-vcs',
> +                    '--transform', 's,^\./,package/,',
> +                    '--mtime', '1985-10-26T08:15:00.000Z',
> +                    '.'],
> +                   check = True, cwd = srcdir)
> +
> +    return tarball
>   
>   python npm_do_configure() {
>       """
> 
> 
> 
> 
> 


  reply	other threads:[~2022-05-19 10:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-19 10:05 [PATCH 0/6] npm.bbclass: work with nodejs 16 Enrico Scholz
2022-05-19 10:05 ` [PATCH 1/6] npm: replace 'npm pack' call by 'tar czf' Enrico Scholz
2022-05-19 10:25   ` Zoltan Boszormenyi [this message]
2022-05-19 10:05 ` [PATCH 2/6] npm: return content of 'package.json' in 'npm_pack' Enrico Scholz
2022-05-19 10:05 ` [PATCH 3/6] npm: take 'version' directly from 'package.json' Enrico Scholz
2022-05-19 10:05 ` [PATCH 4/6] npm: disable 'audit' + 'fund' Enrico Scholz
2022-05-19 13:56   ` [OE-core] " Luca Ceresoli
2022-05-19 14:06   ` [PATCH 4/6, v2] " Enrico Scholz
2022-05-19 10:05 ` [PATCH 5/6] lib:npm_registry: initial checkin Enrico Scholz
2022-05-19 10:05 ` [PATCH 6/6] npm: use npm_registry to cache package Enrico Scholz
2022-05-19 10:38 ` [OE-core] [PATCH 0/6] npm.bbclass: work with nodejs 16 Enrico Scholz
2022-05-23  7:23 ` Christian Eggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5d21c744-33c3-ae3e-c902-712be3918d4e@pr.hu \
    --to=zboszor@pr.hu \
    --cc=enrico.scholz@sigma-chemnitz.de \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox