Difference between revisions of "Node.js package guidelines"

From ArchWiki
Jump to: navigation, search
m (Using npm: Link to npm package)
m (Using npm: fix wiki formatting in code snippet)
(One intermediate revision by the same user not shown)
Line 17: Line 17:
 
This is a minimal {{ic|package}} function:
 
This is a minimal {{ic|package}} function:
  
{{bc|
+
{{bc|<nowiki>
 
package() {
 
package() {
 
     cd $srcdir/$pkgname-$pkgver
 
     cd $srcdir/$pkgname-$pkgver
 
     npm install -g --user root --prefix "$pkgdir"/usr
 
     npm install -g --user root --prefix "$pkgdir"/usr
 +
    # Non-deterministic race in npm gives 777 permissions to random directories.
 +
    # See https://github.com/npm/npm/issues/9359 for details.
 +
    find "${pkgdir}"/usr -type d -exec chmod 755 {} +
 
}
 
}
}}
+
</nowiki>}}
  
 
=== Setting temporary cache ===
 
=== Setting temporary cache ===

Revision as of 16:34, 8 March 2018

Package creation guidelines

CLRCrossEclipseFree PascalGNOMEGoHaskellJavaKDEKernelLispMinGWNode.jsNonfreeOCamlPerlPHPPythonRubyVCSWebWine

This document covers standards and guidelines on writing PKGBUILDs for Node.js packages.

Package naming

Package names should start with a nodejs- prefix.

Using npm

When installing with npm, add it as a build dependency:

makedepends=('npm')

This is a minimal package function:

package() {
    cd $srcdir/$pkgname-$pkgver
    npm install -g --user root --prefix "$pkgdir"/usr
    # Non-deterministic race in npm gives 777 permissions to random directories.
    # See https://github.com/npm/npm/issues/9359 for details.
    find "${pkgdir}"/usr -type d -exec chmod 755 {} +
}

Setting temporary cache

When npm processes package.json in order to build a package it downloads dependencies to its default cache folder at $HOME/.npm. To avoid littering user's home folder we can temporarily set a different cache folder with --cache flag:

Download dependencies to ${srcdir}/npm-cache and install them in package directory

npm install --cache "${srcdir}/npm-cache" 

Continue with packaging as usual

npm run packager