diff --git a/runtime/reference/cli/task.md b/runtime/reference/cli/task.md index 76f724761..45c5279e9 100644 --- a/runtime/reference/cli/task.md +++ b/runtime/reference/cli/task.md @@ -98,8 +98,8 @@ Running `deno task "build:*"` will run both `build:client` and `build:server` tasks. For multi-word task names, we recommend using `:` as the separator (e.g. -`build:client`, `test:unit`, `lint:fix`) to match the convention used in the -npm ecosystem and to group related tasks for wildcard matching. +`build:client`, `test:unit`, `lint:fix`) to match the convention used in the npm +ecosystem and to group related tasks for wildcard matching. :::note @@ -146,13 +146,13 @@ Dependency tasks are executed in parallel, with the default parallel limit being equal to number of cores on your machine. To change this limit, use the `DENO_JOBS` environmental variable. -Dependencies are tracked and if multiple tasks depend on the same task, that -task will only be run once: +Dependencies are tracked and if multiple tasks depend on the same task, the task +will only be run once: ```jsonc title="deno.json" { // a - // / \ + // / // b c // \ / // d @@ -301,8 +301,8 @@ defined tasks. ### Boolean lists -Boolean lists provide a way to execute additional commands based on the exit -code of the initial command. They separate commands using the `&&` and `||` +Boolean lists provide a way to execute additional commands based on the exit code +of the initial command. They separate commands using the `&&` and `||` operators. The `&&` operator provides a way to execute a command and if it _succeeds_ (has @@ -662,3 +662,66 @@ 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 install --entrypoint main.ts && deno task postinstall`). + +## Command Resolution + +When a task command references a binary (e.g., `ohm`, `tsc`, `eslint`), Deno +resolves it using the following order: + +1. **`node_modules/.bin/`** - If the task's directory or a parent directory has + a `node_modules/.bin/` folder, Deno looks there first. Note that `deno add + npm:` updates `deno.json` imports and `deno.lock` but does **not** + create a `node_modules` directory. The `node_modules` directory is only + created when using `deno install` or other npm-compatible tooling. + +2. **Package.json `bin` field** - When a dependency defines a `bin` field in its + `package.json`, Deno automatically makes those commands available within task + scripts through its npm compatibility layer. + +3. **System PATH** - If the command is not found above, Deno falls back to + searching the system PATH. + +### Example + +Given a `package.json` with: + +```json +{ + "dependencies": { + "@ohm-js/cli": "^2.0.0" + } +} +``` + +And a `deno.json` with: + +```json +{ + "tasks": { + "generate": "ohm src/grammar.ohm -o src/grammar.js" + } +} +``` + +Running `deno task generate` will: + +1. Look for `ohm` in `node_modules/.bin/ohm` +2. If found, execute it using Deno's Node.js compatibility layer +3. The command runs under Deno's runtime, not Node.js. + +### Deno's Equivalent to `npx` + +The equivalent of `npx ` in Deno is: + +```bash +deno run -A npm:@latest +``` + +For example: + +- `npx cowsay hello` -> `deno run -A npm:cowsay@latest hello` +- `npx create-react-app my-app` -> + `deno run -A npm:create-react-app@latest my-app` + +You can also use `deno add npm:` to add an npm dependency and then +reference its binaries in `deno task` scripts.