deno.json的”pre-“和”post-“脚本选项,类似于npm。

huangapple go评论66阅读模式
英文:

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生命周期事件,比如preinstallpostinstall - 你必须显式运行你想要运行的脚本条目(例如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:

huangapple
  • 本文由 发表于 2023年5月11日 17:50:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76226320.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定