Skip to content

docmaker fails to correctly reset current directory after loading data files #31

@raqbit

Description

@raqbit

Describe the bug

When processing data files, Docmaker tries to change the working directory to the project directory. This is done to allow dynamic (js) data files to be able to simply open files (fs.readFile etc.) relative to the project directory.

https://github.com/BlameButton/docmaker/blob/8516b9161278e85c053fd81c10b2f1c5c7428f32/src/data.ts#L45-L46

After processing all data files Docmaker tries to reset the path back to its original setting, but it appears getCwd() does not return a full path but a relative path (e.g. foo instead of /home/<user>/Documents/foo) which makes the call to chdir fail.

https://github.com/BlameButton/docmaker/blob/8516b9161278e85c053fd81c10b2f1c5c7428f32/src/data.ts#L52

✖  error     Error: ENOENT: no such file or directory, chdir '/path/to/foo' -> 'foo' 

To Reproduce

Steps to reproduce the behavior:

  1. Run docmaker with the configuration below
  2. See error

Expected behavior

It should correctly reset the current directory after loading all data files.

Configuration

docmaker.yaml:

layout: "layout.html"
pages:
  - "*.md"
data:
  - "data.js"

page.md:

# Test
- This is a test

layout.html:

{{ content }}

data.js:

return { foo: "bar" };

Desktop (please complete the following information)

  • OS / version: Ubuntu 20.04
  • Docmaker version: 0.1.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions