Can't load YAML file with multiple documents
lufego opened this issue · 3 comments
The problem
When trying to load a file with many documents, I get the following error:
Module Error (from ./node_modules/yaml-loader/index.js): expected a single document in the stream, but found more
The YAML file looks like something like this:
---
kind: example
apiVersion: v1
name: test
---
kind: example2
apiVersion: v1
name: test2
---
kind: example3
apiVersion: v1
name: test3
The solution
Ideally, I'd add a checker to count the documents, and if length > 1, then I'd invoke the safeLoadAll
method instead of safeLoad
. But since js-yaml
doesn't export this counter function, would it be possible to replace safeLoad
to safeLoadAll
? I've tested and it would load both single and multiple documents in a file.
The change
module.exports = function (source) {
this.cacheable && this.cacheable();
try {
var res = yaml.safeLoadAll(source);
return JSON.stringify(res, undefined, '\t');
}
catch (err) {
this.emitError(err);
return null;
}
};
Unfortunately I don’t have time to maintain this package. Would you be interested in taking over it?
To your proposition: yeah make sense to me.
I added a new option for this, asStream
.