英文:
deno.json pre- and post- script options like npm
问题
在 deno.json 任务中,是否有办法像 npm 一样在脚本运行前(pre*
)或后(post*
)运行脚本(*
)?
英文:
In npm it is possible to have a script run before (pre*
) or after (post*
) a script (*
). https://docs.npmjs.com/cli/v6/using-npm/scripts
Is there a way to do the same for deno.json tasks?
Currently I'm handling it like this:
{
"tasks": {
"start": "deno run -A --unstable --watch=static/,routes/ dev.ts",
"pretest": "jq -s '.[0] * .[1]' import_map.json unit.test.import_map.json > unit.test.import_map.gen.json",
"test": "deno task pretest && deno test --allow-read --watch --import-map=unit.test.import_map.gen.json"
},
"importMap": "./import_map.json",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}
答案1
得分: 1
No, Deno的任务运行器不支持该模式。
除了对Node.js生态系统的最近支持之外,Deno的历史哲学是更喜欢显式行为而不是不透明和自动/算法性的默认行为。
如果你喜欢npm
运行器的行为,你可以使用package.json
文件来管理你的任务/脚本,并使用npm
来运行它们 - 以及在你觉得方便的时候,Deno的任务运行器也可以从该文件中运行单独的脚本 - 来自手册:
> ## package.json支持
>
> 如果发现,deno task
会回退到读取package.json文件中的"scripts"
条目。请注意,Deno不尊重或支持任何npm生命周期事件,比如preinstall
或postinstall
- 你必须显式运行你想要运行的脚本条目(例如deno cache main.ts && deno task postinstall
)。
任务运行器参考:
英文:
No, Deno's task runner does not support that pattern.
Apart from recent support for the Node.js ecosystem, Deno's historical philosophy has been to prefer explicit behavior over opaque and automatic/algorithmic defaults.
If you prefer the behavior of npm
's runner, you can use a package.json
file to manage your tasks/scripts, and run them using npm
— and whenever you find it convenient, Deno's task runner can also run individual scripts from that file — from the manual:
> ## package.json support
>
> deno task
falls back to reading from the "scripts"
entries in a package.json file if it is discovered. Note that Deno does not respect or support any npm life cycle events like preinstall
or postinstall
—you must explicitly run the script entries you want to run (ex. deno cache main.ts && deno task postinstall
).
Task runner refs:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论