Subject: Re: [bug#49946] [PATCH 08/31] gnu: node: Patch /usr/bin/env in node-gyp.

From: Philip McGrath <[email-masked]>
Date: Thu, 23 Sep 2021 05:18:46 -0400

I'm interested in the node-gyp part of this, which has come up in some 
other software I'm trying to package. These comments come with the 
caveat that my experience with node.js and npm is fairly shallow.

On 8/10/21 2:28 PM, Maxime Devos wrote:
> Pierre Langlois schreef op ma 09-08-2021 om 00:33 [+0100]:
>> @@ -120,6 +120,10 @@
>>                  (("'/usr/bin/env'")
>>                   (string-append "'" (which "env") "'")))
>>
>> +             ;; Fix /usr/bin/env shebang in node-gyp.
>> +             (substitute* "deps/npm/node_modules/node-gyp/bin/node-gyp.js"
>> +               (("#!/usr/bin/env") (string-append "#!" (which "env"))))
> 
> For cross-compilation, this should most likely be
> (string-append (assoc-ref inputs "coreutils") "/bin/env")
> or something like that instead.  Likewise in other places.

Since the shebang line for node-gyp is specifically "#!/usr/bin/env 
node", I wonder if it should use the node built by this package, rather 
than a dynamic node.

More generally, I see that there are 355 directories installed under 
"lib/node_modules/npm/node_modules" (which corresponds to the "deps" 
path above). Most of them don't seem to be available as Guix packages 
that could be depended upon by other Guix node packages. I'd guess 
node-gyp may not be the only one with shebangs that ought to be patched.

On 8/8/21 6:29 PM, Pierre Langlois wrote:

 >    ... `node-gyp' needs

 >    node headers to compile against, packaged as a tarball, which it tries

 >    to download.  Instead, we can run a `node-gyp --tarball <> configure'

 >    step to manually provide the tarball, which we can package separately

 >    for any given node version.

There is also a --nodedir option, which I found could work with 
something like:

     (string-append "--nodedir=" (assoc-ref inputs "node"))

That seems like it might be better, though I don't know all the 
considerations for cross-compilation and such.

-Philip