在将node-gyp标志传递给包时,yarn添加包--build-from-source的行为类似于npm安装包--build-from-source吗?

问题描述 投票:19回答:2

看起来yarn没有像npm那样将node-gyp标志传递给本地包。

例如,当尝试使用以下命令安装[email protected]时:

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

由于传递了--sqlite_libname--sqlite,它们是sqlite3的specified中的binding.gyp,因此我们成功安装了带有sqlcipher扩展的sqlite3。

但是,当试图使用yarn,并运行我认为是等效的命令时,它看起来像标志不尊重:

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

使用npm无法识别的命令行参数转换为gyp标志。

使用yarn似乎不起作用。

有没有办法通过yarn获得此功能?

node.js npm node-gyp yarnpkg
2个回答
2
投票

Yarn不会自动将install命令的--参数暴露给生命周期脚本(依赖项的package.json中的pre / post / install脚本)。这是Yarn为脚本执行https://github.com/yarnpkg/yarn/blob/master/src/util/execute-lifecycle-script.js#L39构建Env的代码。

您可以通过.yarnrc中的env设置传递特定值,还可以基于.yarnrc / .npmrc配置构建npm_config_*设置。


1
投票

目前,这可以通过使用格式为npm_config_{snake_case_param}=true/false的环境变量来实现

例如,npm install --build-from-source=true变为:

npm_config_build_from_source=true yarn install

它在这里记录https://yarnpkg.com/lang/en/docs/envvars/#toc-npm-config

© www.soinside.com 2019 - 2024. All rights reserved.