# -*- 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

name                npm7
version             7.24.2
revision            0
categories          devel
platforms           any
supported_archs     noarch
license             MIT
maintainers         {ciserlohn @ci42} openmaintainer
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 npm5 npm6 npm8 npm9 npm10 npm11

homepage            https://www.npmjs.com/

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

distname            npm-${version}

extract.suffix      .tgz

# Please keep the sha1 - users can use it to validate sha values
# published on npmjs.org for the package
checksums           rmd160  f9f2d6565e8223af13371d12fa2f31454a02d626 \
                    sha1    861117af8241bea592289f22407230e5300e59ca \
                    sha256  5b9eeea011f8bc3b76e55cc33339e87213800677f37e0756ad13ef0e9eaccd64 \
                    size    3146141

worksrcdir          "package"

depends_lib         path:bin/node:nodejs16

platform darwin {
    if {${os.major} < 13} {
        depends_lib-replace path:bin/node:nodejs16 path:bin/node:nodejs14
    }
}

use_configure       no

patchfiles          patch-lib-update.js.diff

post-patch {
    foreach f [concat ${worksrcpath}/bin/npm-cli.js \
                   ${worksrcpath}/bin/npx-cli.js \
                   ${worksrcpath}/node_modules/@npmcli/arborist/bin/index.js \
                   ${worksrcpath}/node_modules/ajv/scripts/info \
                   ${worksrcpath}/node_modules/mkdirp/bin/cmd.js \
                   ${worksrcpath}/node_modules/node-gyp/bin/node-gyp.js \
                   ${worksrcpath}/node_modules/nopt/bin/nopt.js \
                   ${worksrcpath}/node_modules/npm-packlist/bin/index.js \
                   ${worksrcpath}/node_modules/opener/bin/opener-bin.js \
                   ${worksrcpath}/node_modules/pacote/lib/bin.js \
                   ${worksrcpath}/node_modules/qrcode-terminal/bin/qrcode-terminal.js \
                   ${worksrcpath}/node_modules/rimraf/bin.js \
                   ${worksrcpath}/node_modules/semver/bin/semver.js \
                   ${worksrcpath}/node_modules/sshpk/bin/sshpk-conv \
                   ${worksrcpath}/node_modules/sshpk/bin/sshpk-sign \
                   ${worksrcpath}/node_modules/sshpk/bin/sshpk-verify \
                   ${worksrcpath}/node_modules/uuid/bin/uuid \
                   ${worksrcpath}/node_modules/which/bin/node-which] {
        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       https://registry.npmjs.org/npm
livecheck.regex     {"next-7":"(.*?)"}
