npm: Add latest version, update build (#34947)
* npm: Add latest version, update build The `npm` package had gotten a bit long in the tooth and only suported the last version for which running `configure` / `make` / `make install` actually worked. - [x] Update the package to support npm@9, in which `npm install .` works properly and installation is easier. - [x] Update the package so that `npm@6:8` also install successfullly. The incantation that is *supposed* to work on these versions is `node bin/npm-cli.js install $(node bin/npm-cli.js pack . | tail -1)`, but depending on the version one of `npm install` or `npm pack` will fail when run straight from the install directory. So now we just manually copies things over. This seems to make the `npm` install much more reliable for all of `npm@6:9` (at least for me). udpates the `npm` build to support versions 6-9 and fixes the install for all of them on macos. * update for review
This commit is contained in:
parent
8eb803ab4c
commit
c9e85ada15
1 changed files with 77 additions and 19 deletions
|
@ -9,20 +9,50 @@
|
||||||
from spack.package import *
|
from spack.package import *
|
||||||
|
|
||||||
|
|
||||||
# NOTE: not actually an Autotools package
|
|
||||||
class Npm(Package):
|
class Npm(Package):
|
||||||
"""npm: A package manager for javascript."""
|
"""npm: A package manager for javascript."""
|
||||||
|
|
||||||
homepage = "https://github.com/npm/cli"
|
homepage = "https://github.com/npm/cli"
|
||||||
# base https://www.npmjs.com/
|
# base https://www.npmjs.com/
|
||||||
url = "https://registry.npmjs.org/npm/-/npm-6.13.4.tgz"
|
|
||||||
|
|
||||||
version("6.14.9", sha256="1e0e880ce0d5adf0120fb3f92fc8e5ea5bac73681d37282615d074ff670f7703")
|
git = "https://github.com/npm/cli.git"
|
||||||
version("6.14.8", sha256="fe8e873cb606c06f67f666b4725eb9122c8927f677c8c0baf1477f0ff81f5a2c")
|
url = "https://registry.npmjs.org/npm/-/npm-9.3.1.tgz"
|
||||||
version("6.13.7", sha256="6adf71c198d61a5790cf0e057f4ab72c6ef6c345d72bed8bb7212cb9db969494")
|
|
||||||
version("6.13.4", sha256="a063290bd5fa06a8753de14169b7b243750432f42d01213fbd699e6b85916de7")
|
version("9.3.1", sha256="41caa26a340b0562bc5429d28792049c980fe3e872b42b82cad94e8f70e37f40")
|
||||||
version("3.10.9", sha256="fb0871b1aebf4b74717a72289fade356aedca83ee54e7386e38cb51874501dd6")
|
version("8.19.3", sha256="634bf4e0dc87be771ebf48a058629960e979a209c20a51ebdbc4897ca6a25260")
|
||||||
version("3.10.5", sha256="ff019769e186152098841c1fa6325e5a79f7903a45f13bd0046a4dc8e63f845f")
|
version("7.24.2", sha256="5b9eeea011f8bc3b76e55cc33339e87213800677f37e0756ad13ef0e9eaccd64")
|
||||||
|
version("6.14.18", sha256="c9b15f277e2a0b1b57e05bad04504296a27024555d56c2aa967f862e957ad2ed")
|
||||||
|
|
||||||
|
version(
|
||||||
|
"6.14.9",
|
||||||
|
sha256="1e0e880ce0d5adf0120fb3f92fc8e5ea5bac73681d37282615d074ff670f7703",
|
||||||
|
deprecated=True,
|
||||||
|
)
|
||||||
|
version(
|
||||||
|
"6.14.8",
|
||||||
|
sha256="fe8e873cb606c06f67f666b4725eb9122c8927f677c8c0baf1477f0ff81f5a2c",
|
||||||
|
deprecated=True,
|
||||||
|
)
|
||||||
|
version(
|
||||||
|
"6.13.7",
|
||||||
|
sha256="6adf71c198d61a5790cf0e057f4ab72c6ef6c345d72bed8bb7212cb9db969494",
|
||||||
|
deprecated=True,
|
||||||
|
)
|
||||||
|
version(
|
||||||
|
"6.13.4",
|
||||||
|
sha256="a063290bd5fa06a8753de14169b7b243750432f42d01213fbd699e6b85916de7",
|
||||||
|
deprecated=True,
|
||||||
|
)
|
||||||
|
version(
|
||||||
|
"3.10.9",
|
||||||
|
sha256="fb0871b1aebf4b74717a72289fade356aedca83ee54e7386e38cb51874501dd6",
|
||||||
|
deprecated=True,
|
||||||
|
)
|
||||||
|
version(
|
||||||
|
"3.10.5",
|
||||||
|
sha256="ff019769e186152098841c1fa6325e5a79f7903a45f13bd0046a4dc8e63f845f",
|
||||||
|
deprecated=True,
|
||||||
|
)
|
||||||
|
|
||||||
depends_on("node-js", type=("build", "run"))
|
depends_on("node-js", type=("build", "run"))
|
||||||
depends_on("libvips")
|
depends_on("libvips")
|
||||||
|
@ -35,30 +65,60 @@ class Npm(Package):
|
||||||
destination="node-gyp",
|
destination="node-gyp",
|
||||||
url="https://registry.npmjs.org/node-gyp/-/node-gyp-6.0.1.tgz",
|
url="https://registry.npmjs.org/node-gyp/-/node-gyp-6.0.1.tgz",
|
||||||
sha256="bbc0e137e17a63676efc97a0e3b1fcf101498a1c2c01c3341cd9491f248711b8",
|
sha256="bbc0e137e17a63676efc97a0e3b1fcf101498a1c2c01c3341cd9491f248711b8",
|
||||||
|
when="@6",
|
||||||
)
|
)
|
||||||
resource(
|
resource(
|
||||||
name="env-paths",
|
name="env-paths",
|
||||||
destination="env-paths",
|
destination="env-paths",
|
||||||
url="https://registry.npmjs.org/env-paths/-/env-paths-2.2.0.tgz",
|
url="https://registry.npmjs.org/env-paths/-/env-paths-2.2.0.tgz",
|
||||||
sha256="168b394fbca60ea81dc84b1824466df96246b9eb4d671c2541f55f408a264b4c",
|
sha256="168b394fbca60ea81dc84b1824466df96246b9eb4d671c2541f55f408a264b4c",
|
||||||
|
when="@6",
|
||||||
)
|
)
|
||||||
|
|
||||||
phases = ["configure", "build", "install"]
|
@when("@6")
|
||||||
|
|
||||||
def patch(self):
|
def patch(self):
|
||||||
shutil.rmtree("node_modules/node-gyp")
|
shutil.rmtree("node_modules/node-gyp")
|
||||||
install_tree("node-gyp/package", "node_modules/node-gyp")
|
install_tree("node-gyp/package", "node_modules/node-gyp")
|
||||||
filter_file(r'"node-gyp": "\^5\..*"', '"node-gyp": "^6.0.1"', "package.json")
|
filter_file(r'"node-gyp": "\^5\..*"', '"node-gyp": "^6.0.1"', "package.json")
|
||||||
install_tree("env-paths/package", "node_modules/env-paths")
|
install_tree("env-paths/package", "node_modules/env-paths")
|
||||||
|
|
||||||
def configure(self, spec, prefix):
|
@when("@:8")
|
||||||
configure("--prefix={0}".format(prefix))
|
|
||||||
|
|
||||||
def build(self, spec, prefix):
|
|
||||||
make()
|
|
||||||
|
|
||||||
def install(self, spec, prefix):
|
def install(self, spec, prefix):
|
||||||
make("install")
|
# `npm install .` doesn't work properly out of the box on npm up to 8, so we do
|
||||||
|
# what it would do manually. The only thing we seem to miss is docs. In
|
||||||
|
# particular, it will end up symlinking into the stage, which spack then
|
||||||
|
# deletes. You can avoid that with `npm install $(npm pack .)`, but `npm pack`
|
||||||
|
# also seems to fail when run from the tarball on macos. So we just copy manually.
|
||||||
|
to_install = [
|
||||||
|
"LICENSE",
|
||||||
|
"README.md",
|
||||||
|
"bin",
|
||||||
|
"docs",
|
||||||
|
"index.js",
|
||||||
|
"lib",
|
||||||
|
"node_modules",
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
mkdirp(prefix.bin)
|
||||||
|
mkdirp(prefix.lib.node_modules.npm)
|
||||||
|
|
||||||
|
# manually install all the files above (if they exist for a particular node version)
|
||||||
|
for filename in to_install:
|
||||||
|
if os.path.exists(filename):
|
||||||
|
install_fn = install if os.path.isfile(filename) else install_tree
|
||||||
|
install_fn(filename, os.path.join(prefix.lib.node_modules.npm, filename))
|
||||||
|
|
||||||
|
# set up symlinks in bin
|
||||||
|
node_modules_bin = os.path.relpath(prefix.lib.node_modules.npm.bin, prefix.bin)
|
||||||
|
symlink(os.path.join(node_modules_bin, "npm-cli.js"), prefix.bin.npm)
|
||||||
|
symlink(os.path.join(node_modules_bin, "npx-cli.js"), prefix.bin.npx)
|
||||||
|
|
||||||
|
@when("@9:")
|
||||||
|
def install(self, spec, prefix):
|
||||||
|
# in npm 9, `npm install .` finally works within the repo, so we can just call it.
|
||||||
|
node = which("node", required=True)
|
||||||
|
node("bin/npm-cli.js", "install", "-ddd", "--global", f"--prefix={prefix}", ".")
|
||||||
|
|
||||||
def setup_dependent_build_environment(self, env, dependent_spec):
|
def setup_dependent_build_environment(self, env, dependent_spec):
|
||||||
npm_config_cache_dir = "%s/npm-cache" % dependent_spec.prefix
|
npm_config_cache_dir = "%s/npm-cache" % dependent_spec.prefix
|
||||||
|
@ -68,6 +128,4 @@ def setup_dependent_build_environment(self, env, dependent_spec):
|
||||||
|
|
||||||
def setup_dependent_run_environment(self, env, dependent_spec):
|
def setup_dependent_run_environment(self, env, dependent_spec):
|
||||||
npm_config_cache_dir = "%s/npm-cache" % dependent_spec.prefix
|
npm_config_cache_dir = "%s/npm-cache" % dependent_spec.prefix
|
||||||
if not os.path.isdir(npm_config_cache_dir):
|
|
||||||
mkdirp(npm_config_cache_dir)
|
|
||||||
env.set("npm_config_cache", npm_config_cache_dir)
|
env.set("npm_config_cache", npm_config_cache_dir)
|
||||||
|
|
Loading…
Reference in a new issue