# -*- 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                npm11
version             11.8.0
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 npm7 npm8 npm9 npm10

homepage            https://www.npmjs.com/

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

distname            npm-${version}

extract.suffix      .tgz

checksums           rmd160  6d7b8090185394fe1cc0ca786428e9ba9753dec1 \
                    sha256  5a219dd7d4e71d7d289ed45097182cedaf93370223b143108f6dcb8eccac1375 \
                    size    2710490

worksrcdir          package

depends_lib         path:bin/node:nodejs24

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

use_configure       no

patchfiles          patch-lib-commands-update.js.diff \
                    patch-package.json.diff

post-patch {
    reinplace "s|^#!/usr/bin/env node|#!${prefix}/bin/node|" \
        ${worksrcpath}/bin/npm-cli.js \
        ${worksrcpath}/bin/npx-cli.js
}

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

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

set root            ${prefix}/lib/node_modules/npm
set completions     ${prefix}/share/bash-completion/completions

post-destroot {
    xinstall -d ${destroot}${completions}
    ln -s ${root}/lib/utils/completion.sh ${destroot}${completions}/npm

    foreach f [glob -tails -directory ${destroot}${root}/man/man1 *] {
        ln -s ${root}/man/man1/$f ${destroot}${prefix}/share/man/man1/
    }

    foreach f [glob -tails -directory ${destroot}${root}/man/man5 *] {
        ln -s ${root}/man/man5/$f ${destroot}${prefix}/share/man/man5/
    }

    foreach f [glob -tails -directory ${destroot}${root}/man/man7 *] {
        ln -s ${root}/man/man7/$f ${destroot}${prefix}/share/man/man7/npm-$f
    }

    foreach f {package package-lock npm-shrinkwrap} {
        move ${destroot}${prefix}/share/man/man5/$f-json.5 \
            ${destroot}${prefix}/share/man/man5/$f.json.5
    }

    foreach f {install npm-global npm-json} {
        delete ${destroot}${prefix}/share/man/man5/$f.5
    }

    move ${destroot}${prefix}/share/man/man5/folders.5 \
        ${destroot}${prefix}/share/man/man7/npm-folders.7
}

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     {"latest":"(.*?)"}
