Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Jun 2026 06:55:04 +0000
From:      Hiroki Tagato <tagattie@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 36ee4b2d43b2 - main - Mk/Uses/electron.mk: Improve automatic npm version detection
Message-ID:  <6a3cd0c8.3bf21.a89d676@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by tagattie:

URL: https://cgit.FreeBSD.org/ports/commit/?id=36ee4b2d43b2ed4deb7130a0480185f64a602bfe

commit 36ee4b2d43b2ed4deb7130a0480185f64a602bfe
Author:     Hiroki Tagato <tagattie@FreeBSD.org>
AuthorDate: 2026-06-25 06:40:02 +0000
Commit:     Hiroki Tagato <tagattie@FreeBSD.org>
CommitDate: 2026-06-25 06:54:55 +0000

    Mk/Uses/electron.mk: Improve automatic npm version detection
    
    The framework assumed the name and the version of a node package
    manager is specified as the key "packageManager" [1] in package.json
    like:
    {
      "packageManager": "<name>@<version>+<hash>"
    }
    
    However, the name and the version can be also specified using the key
    "devEngines.packageManager" [1] like:
    {
      "devEngines":{
        "packageManager": {
          "name": "<name>",
          "version": "<version>+<hash>"
        }
      }
    }
    
    This change enables automatic npm version detection for the both
    cases.
    
    [1] https://github.com/nodejs/corepack/blob/main/README.md#when-authoring-packages
---
 Mk/Uses/electron.mk | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/Mk/Uses/electron.mk b/Mk/Uses/electron.mk
index 689777389f20..c3efa829d6c3 100644
--- a/Mk/Uses/electron.mk
+++ b/Mk/Uses/electron.mk
@@ -414,11 +414,21 @@ _EXISTS_NPM_PKGFILE=	1
 # automatically detect the version.
 .  if ${_NODEJS_NPM} == yarn2 || ${_NODEJS_NPM} == yarn4 || ${_NODEJS_NPM} == pnpm
 .    if ${_EXISTS_NPM_PKGFILE} == 1 && empty(NPM_VER)
-NPM_VER!=	${GREP} packageManager ${PKGJSONSDIR}/${NPM_PKGFILE} | \
-		${AWK} -F ':' '{print $$NF}' | \
-		${SED} -e 's/[",]//g' | \
-		${CUT} -f 2 -d '@' | \
-		${CUT} -f 1 -d '+'
+NPM_VER!=	${CAT} ${PKGJSONSDIR}/${NPM_PKGFILE} | \
+		${TR} -d '\n\r\t' | ${SED} -e 's/ //g; s/"//g' | \
+		${SED} -E -e ' \
+			/devEngines:\{packageManager:\{/ { \
+				s/.*devEngines:\{packageManager:\{([^}]+)\}\}.*/\1/; \
+				h; \
+				s/.*name:([^,}]+).*/\1/p; \
+				g; \
+				s/.*version:([^+,}]+).*/@\1/p; \
+				d; \
+			}; \
+			/packageManager:/ { \
+				s/.*packageManager:([^+,}]+).*/\1/p; d; \
+			}' | \
+		${CUT} -f 2 -d '@'
 .    endif
 .    if empty(NPM_VER)
 IGNORE=	does not specity version of ${NPM_CMDNAME} used for prefetching node modules


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a3cd0c8.3bf21.a89d676>