Skip to content

extra-watch-dirs does not work if cwd is not the root of the book #2113

@naxmefy

Description

@naxmefy

Problem

HINT: cwd = current working directory

command mdbook allows to serve a book from a different cwd like

# 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

# 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.

[build]
extra-watch-dirs = [
    "assets"
]

Case 1

  1. call mdbook serve from root of the repo
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
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
mdbook serve

error from output: No Error


Additional info

If u set configuration to path the resolves the cwd to the target directory like

[build]
extra-watch-dirs = [
    "book/assets"
]

or like

[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

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

v0.4.30

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: A bug, incorrect or unintended behaviorCommand-serveCommand: serveE-Help-wantedExperience: Help Needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions