Skip to content

Commit

Permalink
Add dependencies before template compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ogonkov committed Jun 11, 2020
1 parent 7fc324f commit b704ea0
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,30 @@ function compile(source, {
}

export default function festLoader(source) {
const options = getOptions(this);
const callback = this.async();

validateOptions(schema, options || {}, {
name: 'Fest Loader',
baseDataPath: 'options'
});
let options;
try {
options = getOptions(this);
validateOptions(schema, options || {}, {
name: 'Fest Loader',
baseDataPath: 'options'
});
} catch (e) {
callback(e);

const promise = new Promise(compile(source, {
...options,
resourcePath: this.resourcePath
}));
return;
}

const callback = this.async();
Promise.all([
// Tracking dependencies is optional feature, that could fail
getDependencies(this.resourcePath, source).catch(() => []),
promise
]).then(([deps, compiled]) => {
// Tracking dependencies is optional feature, that could fail
getDependencies(this.resourcePath, source).catch(() => []).then((deps) => {
deps.forEach((dep) => this.addDependency(dep));

}).then(() => (
new Promise(compile(source, {
...options,
resourcePath: this.resourcePath
}))
)).then(function(compiled) {
callback(null, compiled);
}).catch(function(exception) {
callback(exception, '');
Expand Down

0 comments on commit b704ea0

Please sign in to comment.