# -*- 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.18.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  7eae4fe343e7ec9014f24324a997e10455d1c3b9 \
                    sha256  73f6155215ebabf4ed96dca1f567c2372cc713c33af2e5b9b62fde4e92373e2e \
                    size    2997746

worksrcdir          package

depends_run         path:bin/node:nodejs24

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

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
}

use_configure       no

build {}

destroot.cmd        ${prefix}/bin/node ./bin/npm-cli.js
destroot.args       --location global --install-links ${worksrcpath}
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":"(.*?)"}
