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"
}
}
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 likepreinstall
orpostinstall
—you must explicitly run the script entries you want to run (ex.deno cache main.ts && deno task postinstall
).
Task runner refs: