Selaa lähdekoodia

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 <thomas.claveirole@green-communications.fr>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Thomas Claveirole 2 vuotta sitten
vanhempi
commit
7c73f93218
2 muutettua tiedostoa jossa 36 lisäystä ja 6 poistoa
  1. 19 2
      package/nodejs/Config.in.host
  2. 17 4
      package/nodejs/nodejs.mk

+ 19 - 2
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

+ 17 - 4
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.