# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           deprecated 1.0

# "Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9, 10."
# All of these are EOL as of 2021-04-30: https://github.com/nodejs/Release
deprecated.eol_version  yes

name                npm5
version             5.10.0
revision            1

categories          devel
platforms           any
license             MIT
maintainers         { ether.org.za:light @dylanbr } openmaintainer

supported_archs     noarch

description         node package manager
long_description    npm is a package manager for node. \
                    You can use it to install and publish your node programs. \
                    It manages dependencies and does other cool stuff.

conflicts           npm3 npm4 npm6 npm7 npm8 npm9 npm10 npm11

homepage            https://www.npmjs.com/

master_sites        http://registry.npmjs.org/npm/-/

distname            npm-${version}

extract.suffix      .tgz

checksums           sha1    3bec62312c94a9b0f48f208e00b98bf0304b40db \
                    rmd160  37691467e52ef07af35afc8ab3a3467b9191a5f8 \
                    sha256  c6fe903b4b9cd3ba01dcb530dbf00140e91f5b36c344710421676468e8e4fea3 \
                    size    6732593

worksrcdir          "package"

depends_lib         path:bin/node:nodejs8

use_configure       no

patchfiles          patch-lib-update.js.diff

post-patch {
    regsub -all {/} "^${prefix}/lib" {\\\/} npm_path_jsregex
    reinplace "s|@@NPM_PATH_JSREGEX@@|${npm_path_jsregex}|g" ${worksrcpath}/lib/update.js

    foreach f [concat ${worksrcpath}/bin/npm-cli.js \
                   ${worksrcpath}/bin/npx-cli.js \
                   ${worksrcpath}/node_modules/JSONStream/bin.js \
                   ${worksrcpath}/node_modules/mkdirp/bin/cmd.js \
                   ${worksrcpath}/node_modules/node-gyp/bin/node-gyp.js \
                   ${worksrcpath}/node_modules/node-gyp/node_modules/nopt/bin/nopt.js \
                   ${worksrcpath}/node_modules/node-gyp/node_modules/nopt/examples/my-program.js \
                   ${worksrcpath}/node_modules/node-gyp/node_modules/semver/bin/semver \
                   ${worksrcpath}/node_modules/nopt/bin/nopt.js \
                   ${worksrcpath}/node_modules/nopt/examples/my-program.js \
                   ${worksrcpath}/node_modules/opener/opener.js \
                   ${worksrcpath}/node_modules/qrcode-terminal/bin/qrcode-terminal.js \
                   ${worksrcpath}/node_modules/request/node_modules/har-validator/node_modules/ajv/scripts/info \
                   ${worksrcpath}/node_modules/request/node_modules/http-signature/node_modules/sshpk/bin/sshpk-conv \
                   ${worksrcpath}/node_modules/request/node_modules/http-signature/node_modules/sshpk/bin/sshpk-sign \
                   ${worksrcpath}/node_modules/request/node_modules/http-signature/node_modules/sshpk/bin/sshpk-verify \
                   ${worksrcpath}/node_modules/rimraf/bin.js \
                   ${worksrcpath}/node_modules/semver/bin/semver \
                   ${worksrcpath}/node_modules/update-notifier/node_modules/is-ci/bin.js \
                   ${worksrcpath}/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-auth-token/node_modules/rc/cli.js \
                   ${worksrcpath}/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/rc/cli.js \
                   ${worksrcpath}/node_modules/uuid/bin/uuid \
                   ${worksrcpath}/node_modules/which/bin/which \
                   ${worksrcpath}/node_modules/worker-farm/node_modules/errno/build.js \
                   ${worksrcpath}/node_modules/worker-farm/node_modules/errno/cli.js \
                   ${worksrcpath}/scripts/index-build.js \
                   ${worksrcpath}/scripts/maketest \
                   ${worksrcpath}/scripts/relocate.sh] {
        reinplace "s|/usr/bin/env node|${prefix}/bin/node|" ${f}
    }
}

build {
    system -W ${worksrcpath} "NPM_CONFIG_UNSAFE_PERM=false ${prefix}/bin/node bin/npm-cli.js pack"
}

destroot.cmd        ${prefix}/bin/node ./bin/npm-cli.js
destroot.args       --global ${distname}.tgz
destroot.destdir    --prefix=${destroot}${prefix}

post-destroot {
    set completions_path ${destroot}${prefix}/share/bash-completion/completions/
    xinstall -d ${completions_path}
    xinstall -m 644 ${worksrcpath}/lib/utils/completion.sh ${completions_path}/npm
}

notes "
It is not recommended to install packages globally. But if you do so\
please be aware that they won't get cleaned up when you deactivate\
or uninstall ${name}. Globally installed packages will remain in\
${prefix}/lib/node_modules/ until you manually delete them.
"

livecheck.type      regex
livecheck.url       http://registry.npmjs.org/npm
livecheck.regex     {"latest-5":"(.*?)"}
