Skip to content

Commit

Permalink
allow functions option to be a function of loaderContext; add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lunelson committed Dec 16, 2018
1 parent 2d6045b commit f4ac3db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/normalizeOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ function normalizeOptions(loaderContext, content, webpackImporter) {
const options = cloneDeep(utils.getOptions(loaderContext)) || {};
const { resourcePath } = loaderContext;

// allow opt.functions to be configured WRT loaderContext
if (typeof options.functions === 'function') {
options.functions = options.functions(loaderContext);
}

let { data } = options;

if (typeof options.data === 'function') {
Expand Down
7 changes: 7 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ implementations.forEach((implementation) => {
execTest('custom-functions', {
functions: customFunctions(implementation),
}));
it('should expose custom functions if the option is a function', () =>
execTest('custom-functions', {
functions: (loaderContext) => {
should.exist(loaderContext);
return customFunctions(implementation);
},
}));
});
describe('prepending data', () => {
it('should extend the data option if present and it is string', () =>
Expand Down

0 comments on commit f4ac3db

Please sign in to comment.