[PATCH] Add node-build-system.

  • Done
  • quality assurance status badge
Details
6 participants
  • goodoldpaul
  • Jelle Licht
  • Julien Lepiller
  • Ludovic Courtès
  • Robert Vollmert
  • swedebugia
Owner
unassigned
Submitted by
Julien Lepiller
Severity
normal
J
J
Julien Lepiller wrote on 11 Jul 2019 18:46
(address . guix-patches@gnu.org)
20190711184653.3f6956b8@sybil.lepiller.eu
Hi Guix!

This patch adds a node-build-system. I wasn't sure if it was ready yet,
but I think, since I didn't change it in the last months, that it might
actually be :)

The patch was initially made by Jelle Licht, and I improved a bit on
it. Note that packages built with this build system will embed symlinks
to their dependencies, but not devDependencies (build-only
dependencies) according to the information in the metadata. Each
package is installed in lib/node_modules/package-name and symlinks are
added to lib/node_modules/package-name/node_modules. This allows us to
use only inputs instead of propagated inputs. Executables are installed
in bin according to metadata, and they should work even if called
directly from their store path.
J
J
Jelle Licht wrote on 11 Jul 2019 20:25
87ef2wsa2l.fsf@jlicht.xyz
Hello Julien,

Julien Lepiller <julien@lepiller.eu> writes:

Toggle quote (16 lines)
> Hi Guix!
>
> This patch adds a node-build-system. I wasn't sure if it was ready yet,
> but I think, since I didn't change it in the last months, that it might
> actually be :)
>
> The patch was initially made by Jelle Licht, and I improved a bit on
> it. Note that packages built with this build system will embed symlinks
> to their dependencies, but not devDependencies (build-only
> dependencies) according to the information in the metadata. Each
> package is installed in lib/node_modules/package-name and symlinks are
> added to lib/node_modules/package-name/node_modules. This allows us to
> use only inputs instead of propagated inputs. Executables are installed
> in bin according to metadata, and they should work even if called
> directly from their store path.

I am probably a bit of a hypocrite for the following nitpicks, as I am
quite sure I was the one that introduced pretty much all of them them,
so I offer my apologies in advance :-).

Toggle quote (41 lines)
> From 38158940be0ef4780cdbb553cfa039d21fcdda9b Mon Sep 17 00:00:00 2001
> From: Jelle Licht <jlicht@fsfe.org>
> Date: Tue, 23 Aug 2016 05:23:55 +0200
> Subject: [PATCH] build: Add node-build-system.
>
> * guix/build/node-build-system.scm: New file.
> * guix/build-system/node.scm: New file.
> * guix/build/json.scm: New file.
> * doc/guix.texi: Document it.
> * Makefile.am: Added new files.
>
> Co-Authored-By: Julien Lepiller <julien@lepiller.eu>
> ---
> Makefile.am | 2 +
> doc/guix.texi | 11 +
> guix/build-system/node.scm | 139 +++++++++++
> guix/build/json.scm | 387 +++++++++++++++++++++++++++++++
> guix/build/node-build-system.scm | 159 +++++++++++++
> 5 files changed, 698 insertions(+)
> create mode 100644 guix/build-system/node.scm
> create mode 100644 guix/build/json.scm
> create mode 100644 guix/build/node-build-system.scm
>
> diff --git a/Makefile.am b/Makefile.am
> index 82eda6042a..38f2d7e690 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -125,6 +125,7 @@ MODULES = \
> guix/build-system/guile.scm \
> guix/build-system/haskell.scm \
> guix/build-system/linux-module.scm \
> + guix/build-system/node.scm \
> guix/build-system/perl.scm \
> guix/build-system/python.scm \
> guix/build-system/ocaml.scm \
> @@ -170,6 +171,7 @@ MODULES = \
> guix/build/gnu-build-system.scm \
> guix/build/gnu-dist.scm \
> guix/build/guile-build-system.scm \
> + guix/build/node-build-system.scm \

We are missing the `json.scm' file in this listing.

Toggle quote (6 lines)
> [snip]

> +(define* (node-build store name inputs
> + #:key
> + (npm-flags ''())
> + (global? #f)
I am not quite sure if this is needed. Put another way: would we not
want all package builds to have `global? #t' in Guix?

Toggle quote (1 lines)
> + (test-target "test")
This one is no longer in use.

Toggle quote (1 lines)
> + (tests? #f)
I know that for most modules we will not even be able to run tests, but
it seems silly to disable them by default, as that would hide the issue.

Toggle quote (16 lines)
> [snip]

> +(define* (install #:key outputs inputs global? #:allow-other-keys)
> + "Install the node module to the output store item. MODULENAME defines
> +under which name the module will be installed, GLOBAL? determines whether this
> +is an npm global install."
> + (let* ((out (assoc-ref outputs "out"))
> + (src-dir (getcwd))
> + (tgt-dir (string-append out "/lib"))
> + (bin-dir (string-append out "/bin"))
> + (modulename (string-append (assoc-ref (read-package-data) "name")))
> + (data (read-package-data))
> + (bin-conf (assoc-ref data "bin"))
> + (dependencies (match (assoc-ref data "dependencies")
> + ((@ deps ...) deps)
> + (#f #f))))
It might be better to write out most of these
names. I think we could also move `modulename' one line lower, so it can
become `(modulename (assoc-ref data "name"))'.

If you want me to tidy up these things, let me know; I can do it first
thing after the weekend.

Thanks

Jelle
L
L
Ludovic Courtès wrote on 13 Jul 2019 14:42
(name . Jelle Licht)(address . jlicht@fsfe.org)
87a7di9kch.fsf@gnu.org
Hello!

Nice work! I wonder if this could be used for the ‘node-semver’ package
that arrived at about the same time: https://issues.guix.gnu.org/issue/36599.

Jelle Licht <jlicht@fsfe.org> skribis:

Toggle quote (14 lines)
>> +(define* (install #:key outputs inputs global? #:allow-other-keys)
>> + "Install the node module to the output store item. MODULENAME defines
>> +under which name the module will be installed, GLOBAL? determines whether this
>> +is an npm global install."
>> + (let* ((out (assoc-ref outputs "out"))
>> + (src-dir (getcwd))
>> + (tgt-dir (string-append out "/lib"))
>> + (bin-dir (string-append out "/bin"))
>> + (modulename (string-append (assoc-ref (read-package-data) "name")))
>> + (data (read-package-data))
>> + (bin-conf (assoc-ref data "bin"))
>> + (dependencies (match (assoc-ref data "dependencies")
>> + ((@ deps ...) deps)

Note that ‘@’ here matches anything. Did you mean '@, which would match
the @ symbol?

Toggle quote (5 lines)
>> + (#f #f))))
> It might be better to write out most of these
> names. I think we could also move `modulename' one line lower, so it can
> become `(modulename (assoc-ref data "name"))'.

I’m gratuitously nitpicking as well :-), but I think we should spell out
names in general, so I’d propose s/src-dir/source/, s/tgt-dir/target/,
etc.


Anyway, thanks for working on it!

Ludo’.
G
G
goodoldpaul wrote on 13 Jul 2019 17:32
Re: [PATCH] Add node-build-system.
(address . 36602@debbugs.gnu.org)
4ea27e7ea72e7effbd3cb8e63a75e834@autistici.org
Hello!

I'm the author of: https://issues.guix.gnu.org/issue/36599. It should
be really easy to rewrite the package using this new build system.

I submitted the patch before asking in #guix if someone was already
working on node's ecosystem, but when I did Julien pointed me to his
development branch which contains a definition for node-semver using the
new node-build system:
.

If this is merged I can refactor my patch (which contains node-semver
6.2.0), based on Julien's package definition (which contains version
5.6.0), in no time!

Very cool work by the way,

Giacomo
J
J
Julien Lepiller wrote on 13 Jul 2019 22:20
Re: [bug#36602] [PATCH] Add node-build-system.
(name . Ludovic Courtès)(address . ludo@gnu.org)
20190713221952.0de23569@sybil.lepiller.eu
Le Sat, 13 Jul 2019 14:42:38 +0200,
Ludovic Courtès <ludo@gnu.org> a écrit :

Toggle quote (41 lines)
> Hello!
>
> Nice work! I wonder if this could be used for the ‘node-semver’
> package that arrived at about the same time:
> <https://issues.guix.gnu.org/issue/36599>.
>
> Jelle Licht <jlicht@fsfe.org> skribis:
>
> >> +(define* (install #:key outputs inputs global? #:allow-other-keys)
> >> + "Install the node module to the output store item. MODULENAME
> >> defines +under which name the module will be installed, GLOBAL?
> >> determines whether this +is an npm global install."
> >> + (let* ((out (assoc-ref outputs "out"))
> >> + (src-dir (getcwd))
> >> + (tgt-dir (string-append out "/lib"))
> >> + (bin-dir (string-append out "/bin"))
> >> + (modulename (string-append (assoc-ref
> >> (read-package-data) "name")))
> >> + (data (read-package-data))
> >> + (bin-conf (assoc-ref data "bin"))
> >> + (dependencies (match (assoc-ref data "dependencies")
> >> + ((@ deps ...) deps)
>
> Note that ‘@’ here matches anything. Did you mean '@, which would
> match the @ symbol?
>
> >> + (#f #f))))
> > It might be better to write out most of these
> > names. I think we could also move `modulename' one line lower, so
> > it can become `(modulename (assoc-ref data "name"))'.
>
> I’m gratuitously nitpicking as well :-), but I think we should spell
> out names in general, so I’d propose s/src-dir/source/,
> s/tgt-dir/target/, etc.
>
> https://www.gnu.org/software/guix/manual/en/html_node/Formatting-Code.html
>
> Anyway, thanks for working on it!
>
> Ludo’.

Hopefully, the attached patch fixes your (and Jelle's) points. I also
fixed the default node package (it was node-lts, but that doesn't exist
anymore), made the configure phase return #t and fixed the
binary-configuration. I tested again on a few packages and they built
without issue.
J
J
Jelle Licht wrote on 13 Jul 2019 23:30
(address . 36602@debbugs.gnu.org)
87a7dhsjvf.fsf@jlicht.xyz
Julien Lepiller <julien@lepiller.eu> writes:

Toggle quote (6 lines)
> [...]
> +(define* (install #:key outputs inputs #:allow-other-keys)
> + "Install the node module to the output store item. MODULENAME defines
> +under which name the module will be installed, GLOBAL? determines whether this
> +is an npm global install."

`global?' is no longer , so it could probably be removed from the
docstring as well. LGTM otherwise :-).
J
J
Julien Lepiller wrote on 14 Jul 2019 12:34
(name . Jelle Licht)(address . jlicht@fsfe.org)
20190714123453.55c6d1b1@sybil.lepiller.eu
Le Sat, 13 Jul 2019 23:30:12 +0200,
Jelle Licht <jlicht@fsfe.org> a écrit :

Toggle quote (11 lines)
> Julien Lepiller <julien@lepiller.eu> writes:
>
> > [...]
> > +(define* (install #:key outputs inputs #:allow-other-keys)
> > + "Install the node module to the output store item. MODULENAME
> > defines +under which name the module will be installed, GLOBAL?
> > determines whether this +is an npm global install."
>
> `global?' is no longer , so it could probably be removed from the
> docstring as well. LGTM otherwise :-).

I've reworked that docstring and pushed as
09a1f92f61d1ab11d2cf9f7a0983f4fc9f436f57, thank you!
Closed
R
R
Robert Vollmert wrote on 14 Jul 2019 13:09
guix/build/json.scm
(address . 36602@debbugs.gnu.org)
055006A2-DA0C-4570-A9D0-4A9FFD5A6037@vllmrt.net
Hi,

just had a look at 09a1f92f61d1ab11d2cf9f7a0983f4fc9f436f57, some questions:

is a 404, and I can’t find (ice-9 json) elsewhere (also, shouldn’t cwebber be listed in the
copyright line?)
- how does this embedded json parsing module differ from (json parser) as used by the cargo
build system? wouldn’t it be better to have both use the same json modules?

Cheers
Robert
S
S
swedebugia wrote on 14 Jul 2019 14:46
Re: bug#36602: [PATCH] Add node-build-system.
(address . guix-patches@gnu.org)
b9f60f61-ef4f-c099-53d1-e2b53ae7d521@riseup.net
On 2019-07-14 12:34, Julien Lepiller wrote:

Toggle quote (3 lines)
> I've reworked that docstring and pushed as
> 09a1f92f61d1ab11d2cf9f7a0983f4fc9f436f57, thank you!

Wohoo! First small step to working node applications.

--
Cheers
Swedebugia
J
J
Julien Lepiller wrote on 14 Jul 2019 14:59
Re: [bug#36602] guix/build/json.scm
(name . Robert Vollmert)(address . rob@vllmrt.net)(address . 36602@debbugs.gnu.org)
20190714145945.65841b36@sybil.lepiller.eu
Le Sun, 14 Jul 2019 13:09:18 +0200,
Robert Vollmert <rob@vllmrt.net> a écrit :

Toggle quote (17 lines)
> Hi,
>
> just had a look at 09a1f92f61d1ab11d2cf9f7a0983f4fc9f436f57, some
> questions:
>
> - the link to
> https://github.com/cwebber/activitystuff/blob/master/activitystuff/contrib/json.scm
> is a 404, and I can’t find (ice-9 json) elsewhere (also, shouldn’t
> cwebber be listed in the copyright line?)
> - how does this embedded json parsing module differ from (json
> parser) as used by the cargo build system? wouldn’t it be better to
> have both use the same json modules?
>
> Cheers
> Robert
>

You're right, I thought we didn't use guile-json, but since we already
use it in the cargo build system, I removed (guix build json) and fixed
the node-build-system to use (json parser) instead. I tested a few
packages, so it should be working. I pushed the changes in
8eb0ba532ebbebef23180e666e0607ea735f9c1a.
?