diff mbox

[1/1] package/nodejs: Fixed npm global install

Message ID 1446047993-17436-1-git-send-email-martin@barkynet.com
State Accepted
Headers show

Commit Message

Martin Bark Oct. 28, 2015, 3:59 p.m. UTC
Set npm_config_prefix to $(TARGET_DIR)/usr so that npm -g will correctly
install global modules to $(TARGET_DIR)/usr/lib/node_modules.

By using npm -g to install global modules npm will now automatically create
the symlinks to executables under $(TARGET_DIR)/usr/bin.

Signed-off-by: Martin Bark <martin@barkynet.com>
---

See https://docs.npmjs.com/misc/config#global and
https://docs.npmjs.com/files/folders for information on how the
prefix setting is used by global installs.

Signed-off-by: Martin Bark <martin@barkynet.com>
---
 package/nodejs/nodejs.mk | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

Comments

Thomas Petazzoni Nov. 2, 2015, 10:13 p.m. UTC | #1
Dear Martin Bark,

On Wed, 28 Oct 2015 15:59:53 +0000, Martin Bark wrote:
> Set npm_config_prefix to $(TARGET_DIR)/usr so that npm -g will correctly
> install global modules to $(TARGET_DIR)/usr/lib/node_modules.
> 
> By using npm -g to install global modules npm will now automatically create
> the symlinks to executables under $(TARGET_DIR)/usr/bin.
> 
> Signed-off-by: Martin Bark <martin@barkynet.com>
> ---
> 
> See https://docs.npmjs.com/misc/config#global and
> https://docs.npmjs.com/files/folders for information on how the
> prefix setting is used by global installs.

This paragraph is very useful, so I wonder why you didn't put it as
part of the commit log itself.

So I've moved this paragraph to the commit log, and I've applied your
patch. Thanks a lot, it clearly makes nodejs.mk a bit simpler!

Thomas
Martin Bark Nov. 3, 2015, 9:48 a.m. UTC | #2
Thomas,

On 2 November 2015 at 22:13, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> Dear Martin Bark,
>
> On Wed, 28 Oct 2015 15:59:53 +0000, Martin Bark wrote:
>> Set npm_config_prefix to $(TARGET_DIR)/usr so that npm -g will correctly
>> install global modules to $(TARGET_DIR)/usr/lib/node_modules.
>>
>> By using npm -g to install global modules npm will now automatically create
>> the symlinks to executables under $(TARGET_DIR)/usr/bin.
>>
>> Signed-off-by: Martin Bark <martin@barkynet.com>
>> ---
>>
>> See https://docs.npmjs.com/misc/config#global and
>> https://docs.npmjs.com/files/folders for information on how the
>> prefix setting is used by global installs.
>
> This paragraph is very useful, so I wonder why you didn't put it as
> part of the commit log itself.

You know I have no idea why I didn't either :)

>
> So I've moved this paragraph to the commit log, and I've applied your
> patch. Thanks a lot, it clearly makes nodejs.mk a bit simpler!

Thanks.

Martin

>
> Thomas
> --
> Thomas Petazzoni, CTO, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com
diff mbox

Patch

diff --git a/package/nodejs/nodejs.mk b/package/nodejs/nodejs.mk
index 099b3f0..7b6ae6b 100644
--- a/package/nodejs/nodejs.mk
+++ b/package/nodejs/nodejs.mk
@@ -106,6 +106,7 @@  NPM = $(TARGET_CONFIGURE_OPTS) \
 	npm_config_target_arch=$(NODEJS_CPU) \
 	npm_config_build_from_source=true \
 	npm_config_nodedir=$(BUILD_DIR)/nodejs-$(NODEJS_VERSION) \
+	npm_config_prefix=$(TARGET_DIR)/usr \
 	$(HOST_DIR)/usr/bin/npm
 
 #
@@ -116,17 +117,7 @@  define NODEJS_INSTALL_MODULES
 	# If you're having trouble with module installation, adding -d to the
 	# npm install call below and setting npm_config_rollback=false can both
 	# help in diagnosing the problem.
-	(cd $(TARGET_DIR)/usr/lib && mkdir -p node_modules && \
-		$(NPM) install $(NODEJS_MODULES_LIST) \
-	)
-
-	# Symlink all executables in $(TARGET_DIR)/usr/lib/node_modules/.bin to
-	# $(TARGET_DIR)/usr/bin so they are accessible from the command line
-	cd $(TARGET_DIR)/usr/bin; \
-	for f in ../../usr/lib/node_modules/.bin/*; do \
-		[ -f "$${f}" -a -x "$${f}" ] || continue; \
-		ln -sf "$${f}" "$${f##*/}" || exit 1; \
-	done
+	$(NPM) install -g $(NODEJS_MODULES_LIST)
 endef
 endif