claylo / yaml-include

Valid, modular YAML documents with js-yaml. Seriously.
ISC License
39 stars 17 forks source link

inc/file inconsistent about base path #3

Closed joefiorini closed 7 years ago

joefiorini commented 8 years ago

I have a directory structure like the following (example demonstrating my actual setup):

config/
-- development.yml
-- production.yml
-- databases.yml
-- assetHosts.yml
tests/
-- test.js

and I want to assign the objects loaded from databases.yml and assetHosts.yml to top-level keys in each of development.yml and production.yml like so:

databases: !! inc/file development.yml
assetHosts: !! inc/file assetHosts.yml

Then I load these files in both webpack from the root of the project, and running unit tests from the tests directory (ie. cd tests && mocha **/*.test.js).

Expected

It would find the files located in its own directory and parse them.

Actual

Webpack reports a file not found error trying to load databases.yml. So I change the directory to be relative to where I'm running webpack from (ie. inc/file config/databases.yml). This works for webpack, but then mocha reports an error when running tests because it can't find config/databases.yml.

Explanation

Since lib/file.js uses process.cwd() as its base, the actual path to the file is dependent on how I run js-yaml. This results in the path behavior being very unpredictable.

claylo commented 7 years ago

Thanks for making this an issue, Joe. I felt kinda creepy-crawly about doing it the way I originally did it, and it is now fixed. Please give version 1.2.0 a spin.