Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does yarn add package --build-from-source behave like npm install package --build-from-source when passing node-gyp flags to packages?

It looks like yarn does not pass node-gyp flags to native packages the way npm does.

For example when attempting to install [email protected] with:

npm install [email protected] \
  --build-from-source \
  --sqlite_libname=sqlcipher \
  --sqlite=`brew --prefix` \
  --verbose

we get a successful installation of sqlite3 with sqlcipher extensions, due to passing --sqlite_libname and --sqlite, which are specified in sqlite3's binding.gyp.

But, when attempting to use yarn, and running what I would think to be the equivalent command, it looks like the flags aren't honored:

yarn add [email protected] \
  --force \
  --build-from-source \
  --sqlite_libname=sqlcipher \
  --sqlite=`brew --prefix` \
  --verbose

With npm unrecognized command line arguments are converted to gyp flags.

With yarn that doesn't seem to work.

Is there a way to get this functionality with yarn?

like image 362
zealoushacker Avatar asked Sep 05 '25 03:09

zealoushacker


2 Answers

This is currently possible by using environment variables on the format npm_config_{snake_case_param}=true/false

For example, npm install --build-from-source=true becomes:

npm_config_build_from_source=true yarn install

It's documented here https://yarnpkg.com/lang/en/docs/envvars/#toc-npm-config

like image 104
jonathancardoso Avatar answered Sep 09 '25 03:09

jonathancardoso


Yarn does not automatically expose -- arguments of install command to lifecycle scripts (pre/post/install scripts in package.json of dependencies). Here is the code where Yarn builds Env for the script execution https://github.com/yarnpkg/yarn/blob/master/src/util/execute-lifecycle-script.js#L39.

You can pass specific values via env setting in .yarnrc and also it builds npm_config_* settings based on .yarnrc/.npmrc configuration.

like image 23
bestander Avatar answered Sep 09 '25 05:09

bestander