我想从node.js 以编程方式运行yarn 命令,但找不到任何sdk 或cli 实用程序。唯一的事情就是产生一个新的进程,但这很麻烦......
截至 2019 年 1 月,Yarn 尚无可直接调用的 API。你cannot需要 Yarn 并使用类似于 npm 的纱线命令
var npm = require('npm');
npm.load(function(err) {
// handle errors
// install module ffi
npm.commands.install(['ffi'], function(er, data) {
// log errors or data
});
你只能使用节点的子进程执行纱线命令。
const { exec } = require('child_process');
exec('yarn add package@beta', (err, stdout, stderr) => {
if (err) {
// node couldn't execute the command
return;
}
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)