Skip to content

Commit

Permalink
feat: allow passing functions option as function (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunelson authored and evilebottnawi committed Dec 17, 2018
1 parent 2d6045b commit 6c9654d
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 6c9654d

Please sign in to comment.