You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过npmExecuteScripts向npm脚本传递参数?

如何在SAP Project Piper的npmExecuteScripts中向npm脚本传递参数?

核心逻辑回顾

根据Project Piper文档,scriptOptions中的配置会通过--分隔符传递给所有指定的runScripts脚本,最终对应npm run <脚本名> -- <参数>的执行格式。

正确配置写法

根据参数类型的不同,配置方式略有区别:

1. 传递无值的标记类参数(如--debug、--tag1)

直接将标记作为字符串放入scriptOptions数组即可:

npmExecuteScripts:
    runScripts: ["testScript"]
    scriptOptions: ["--debug", "--tag1"]

最终执行的命令为:npm run testScript -- --debug --tag1

2. 传递带值的参数(如--myArg myVal)

有两种可行的配置方式:

  • 方式一(拆分参数名与值):
npmExecuteScripts:
    runScripts: ["testScript"]
    scriptOptions: ["--myArg", "myVal"]

最终执行命令:npm run testScript -- --myArg myVal

  • 方式二(等号拼接参数):
npmExecuteScripts:
    runScripts: ["testScript"]
    scriptOptions: ["--myArg=myVal"]

最终执行命令:npm run testScript -- --myArg=myVal

验证参数是否传递成功

可以在package.json的testScript中添加参数打印逻辑,确认参数是否接收正常:

{
  "scripts": {
    "testScript": "node -e \"console.log('Received arguments:', process.argv.slice(2))\""
  }
}

执行后会输出传递的参数列表,方便快速排查问题。

内容的提问来源于stack exchange,提问作者Mike

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 12:01:01