将 node-gyp 标志传递给包时, yarn add package --build-from-source 的行为是否像 npm install package --build-from-source 一样?
Does yarn add package --build-from-source behave like npm install package --build-from-source when passing node-gyp flags to packages?
看起来 yarn
没有像 npm
那样将 node-gyp 标志传递给本机包。
例如,当尝试安装 sqlite3@3.1.6 时:
npm install sqlite3@3.1.6 \
--build-from-source \
--sqlite_libname=sqlcipher \
--sqlite=`brew --prefix` \
--verbose
由于传递了 --sqlite_libname
和 --sqlite
,我们成功安装了带有 sqlcipher 扩展的 sqlite3,它们在 sqlite3 的 binding.gyp
.[=22= 中是 specified ]
但是,当尝试使用 yarn
和 运行 时,我认为是等效的命令,看起来这些标志没有得到尊重:
yarn add sqlite3@3.1.6 \
--force \
--build-from-source \
--sqlite_libname=sqlcipher \
--sqlite=`brew --prefix` \
--verbose
使用 npm
无法识别的命令行参数将转换为 gyp 标志。
使用 yarn
似乎不起作用。
有没有办法通过 yarn
获得此功能?
Yarn 不会自动将安装命令的 --
参数公开给生命周期脚本(pre/post/install 依赖项 package.json 中的脚本)。
这是 Yarn 为脚本执行构建 Env 的代码 https://github.com/yarnpkg/yarn/blob/master/src/util/execute-lifecycle-script.js#L39.
您可以通过 .yarnrc 中的 env
设置传递特定值,它还可以根据 .yarnrc/.npmrc 配置构建 npm_config_*
设置。
目前可以通过在格式 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
看起来 yarn
没有像 npm
那样将 node-gyp 标志传递给本机包。
例如,当尝试安装 sqlite3@3.1.6 时:
npm install sqlite3@3.1.6 \
--build-from-source \
--sqlite_libname=sqlcipher \
--sqlite=`brew --prefix` \
--verbose
由于传递了 --sqlite_libname
和 --sqlite
,我们成功安装了带有 sqlcipher 扩展的 sqlite3,它们在 sqlite3 的 binding.gyp
.[=22= 中是 specified ]
但是,当尝试使用 yarn
和 运行 时,我认为是等效的命令,看起来这些标志没有得到尊重:
yarn add sqlite3@3.1.6 \
--force \
--build-from-source \
--sqlite_libname=sqlcipher \
--sqlite=`brew --prefix` \
--verbose
使用 npm
无法识别的命令行参数将转换为 gyp 标志。
使用 yarn
似乎不起作用。
有没有办法通过 yarn
获得此功能?
Yarn 不会自动将安装命令的 --
参数公开给生命周期脚本(pre/post/install 依赖项 package.json 中的脚本)。
这是 Yarn 为脚本执行构建 Env 的代码 https://github.com/yarnpkg/yarn/blob/master/src/util/execute-lifecycle-script.js#L39.
您可以通过 .yarnrc 中的 env
设置传递特定值,它还可以根据 .yarnrc/.npmrc 配置构建 npm_config_*
设置。
目前可以通过在格式 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