From 7c73f93218c293cd7a2245763c63d02910de88b8 Mon Sep 17 00:00:00 2001 From: Thomas Claveirole Date: Tue, 13 Sep 2022 19:40:38 +0200 Subject: [PATCH] package/nodejs: introduce BR2_PACKAGE_HOST_NODEJS_COREPACK Corepack is a zero-runtime-dependency Node.js script that acts as a bridge between Node.js projects and the package managers. It ships with Node.js but is disabled by default. Some JavaScript packages, such as vuejs and vuejs-router can benefit from having Corepack installed on the host. Therefore, add an option to enable Corepack with host-nodejs. Signed-off-by: Thomas Claveirole Signed-off-by: Yann E. MORIN --- package/nodejs/Config.in.host | 21 +++++++++++++++++++-- package/nodejs/nodejs.mk | 21 +++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/package/nodejs/Config.in.host b/package/nodejs/Config.in.host index f7f2b80a9b..06a1ca22ad 100644 --- a/package/nodejs/Config.in.host +++ b/package/nodejs/Config.in.host @@ -1,3 +1,6 @@ +comment "host nodejs needs a host gcc >= 8" + depends on !BR2_HOST_GCC_AT_LEAST_8 + config BR2_PACKAGE_HOST_NODEJS bool "host nodejs" depends on BR2_HOST_GCC_AT_LEAST_8 @@ -10,5 +13,19 @@ config BR2_PACKAGE_HOST_NODEJS http://nodejs.org/ -comment "host nodejs needs a host gcc >= 8" - depends on !BR2_HOST_GCC_AT_LEAST_8 +if BR2_PACKAGE_HOST_NODEJS + +config BR2_PACKAGE_HOST_NODEJS_COREPACK + bool "Corepack" + help + Enable Corepack with host nodejs. + + Corepack is a zero-runtime-dependency Node.js script that + acts as a bridge between Node.js projects and the package + managers they are intended to be used with during + development. In practical terms, Corepack will let you use + Yarn and pnpm without having to install them - just like + what currently happens with npm, which is shipped by Node.js + by default. + +endif diff --git a/package/nodejs/nodejs.mk b/package/nodejs/nodejs.mk index 367d5d2058..539ded06cd 100644 --- a/package/nodejs/nodejs.mk +++ b/package/nodejs/nodejs.mk @@ -109,10 +109,17 @@ define HOST_NODEJS_BUILD_CMDS $(HOST_NODEJS_MAKE_OPTS) endef +ifeq ($(BR2_PACKAGE_HOST_NODEJS_COREPACK),y) +define HOST_NODEJS_ENABLE_COREPACK + $(COREPACK) enable +endef +endif + define HOST_NODEJS_INSTALL_CMDS $(HOST_MAKE_ENV) PYTHON=$(HOST_DIR)/bin/python3 \ $(MAKE) -C $(@D) install \ $(HOST_NODEJS_MAKE_OPTS) + $(HOST_NODEJS_ENABLE_COREPACK) endef ifeq ($(BR2_i386),y) @@ -223,8 +230,7 @@ endef NODEJS_MODULES_LIST= $(call qstrip,\ $(BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL)) -# Define NPM for other packages to use -NPM = $(TARGET_CONFIGURE_OPTS) \ +NODEJS_BIN_ENV = $(TARGET_CONFIGURE_OPTS) \ LDFLAGS="$(NODEJS_LDFLAGS)" \ LD="$(TARGET_CXX)" \ npm_config_arch=$(NODEJS_CPU) \ @@ -232,8 +238,15 @@ NPM = $(TARGET_CONFIGURE_OPTS) \ npm_config_build_from_source=true \ npm_config_nodedir=$(BUILD_DIR)/nodejs-$(NODEJS_VERSION) \ npm_config_prefix=$(TARGET_DIR)/usr \ - npm_config_cache=$(BUILD_DIR)/.npm-cache \ - $(HOST_DIR)/bin/npm + npm_config_cache=$(BUILD_DIR)/.npm-cache + +# Define various packaging tools for other packages to use +NPM = $(NODEJS_BIN_ENV) $(HOST_DIR)/bin/npm +ifeq ($(BR2_PACKAGE_HOST_NODEJS_COREPACK),y) +COREPACK = $(NODEJS_BIN_ENV) $(HOST_DIR)/bin/corepack +PNPM = $(NODEJS_BIN_ENV) $(HOST_DIR)/bin/pnpm +YARN = $(NODEJS_BIN_ENV) $(HOST_DIR)/bin/yarn +endif # # We can only call NPM if there's something to install.