Repository: rust-lang/mdBook (language: rust)

Issue:
extra-watch-dirs does not work if cwd is not the root of the book
### Problem

> HINT: cwd = current working directory

command `mdbook` allows to serve a book from a different cwd like

```bash
# current cwd is path/to/repo
# book is path/to/repo/book
# we can call mdbook serve from repo root

mdbook serve book/
```

same works from an inner folder of the book folder like

```bash
# current cwd is path/to/repo/book/assets
# book is path/to/repo/book
# we can call mdbook serve from assets directory

mdbook serve ../book
```

but if we set configuration `extra-watch-dirs` - the config is using the `cwd` - not the root of the book.

```toml
[build]
extra-watch-dirs = [
    "assets"
]
```

---

**Case 1**

1. call `mdbook serve` from root of the repo

```bash
mdbook serve book/
```

error from output:

```
2023-07-03 02:54:31 [ERROR] (mdbook::cmd::serve): Unable to serve: panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', /Users/naxmefy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mdbook-0.4.30/src/cmd/watch.rs:133:39
```

---

**Case 2**

1. call `mdbook serve` from assets directory

```bash
mdbook serve ../book
```

error from output:

```
2023-07-03 02:56:30 [ERROR] (mdbook::cmd::serve): Unable to serve: panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', /Users/naxmefy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mdbook-0.4.30/src/cmd/watch.rs:133:39
```

---

**Case 3**

1. call `mdbook serve` from root of the book

```bash
mdbook serve
```

error from output: **No Error**

---

**Additional info**

If u set configuration to path the resolves the cwd to the target directory like

```toml
[build]
extra-watch-dirs = [
    "book/assets"
]
```

or like

```toml
[build]
extra-watch-dirs = [
    "../assets"
]
```

no error will be produced...but this is not expected.

### Steps

1. create a book
2. add an extra directory
3. add the configuration `extra-watch-dirs`
4. execute `mdbook serve` from an different folder than the root of the book

### Possible Solution(s)

Just change the loading of `extra-watch-dirs` from the **root of the book** like the `src` configuration and not from the cwd

### Notes

**How I came to it?**

I created a `justfile` to run some book command from root and got the error

```justfile
alias b := build
alias bb := book-build
alias bs := book-serve

build:
    cargo build --release
book-build:
    mdbook build book/
book-serve:
    mdbook serve --open book/
```

### Version

```text
v0.4.30
```



Discussion / hints:
related pr #1884

Fix patch:
diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs
index e9806e1cd0..9fd5085d8d 100644
--- a/src/cmd/watch.rs
+++ b/src/cmd/watch.rs
@@ -130,11 +130,16 @@ where
     let _ = watcher.watch(&book.root.join("book.toml"), NonRecursive);
 
     for dir in &book.config.build.extra_watch_dirs {
-        let path = dir.canonicalize().unwrap();
-        if let Err(e) = watcher.watch(&path, Recursive) {
+        let path = book.root.join(dir);
+        let canonical_path = path.canonicalize().unwrap_or_else(|e| {
+            error!("Error while watching extra directory {path:?}:\n    {e}");
+            std::process::exit(1);
+        });
+
+        if let Err(e) = watcher.watch(&canonical_path, Recursive) {
             error!(
                 "Error while watching extra directory {:?}:\n    {:?}",
-                path, e
+                canonical_path, e
             );
             std::process::exit(1);
         }


Test patch: