Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match options before analyzing #88

Merged
merged 1 commit into from Apr 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,20 @@ const getPattern = (decl) =>
* @returns {String|undefined}
*/
const replaceUrl = (url, dir, options, result, decl) => {
const isFunction = typeof options.url === 'function';

if (!isFunction && isUrlShouldBeIgnored(url, options)) return;

const asset = prepareAsset(url, dir, options.basePath);
const relativeToRoot = path.relative(process.cwd(), asset.absolutePath);

options = matchOptions(relativeToRoot, options);
if (!options) return;
const matchedOptions = matchOptions(relativeToRoot, options);
if (!matchedOptions) return;

const isFunction = typeof matchedOptions.url === 'function';
if (!isFunction && isUrlShouldBeIgnored(url, matchedOptions)) return;

const mode = isFunction ? 'custom' : (options.url || 'rebase');
const urlProcessor = getUrlProcessor(mode || 'rebase');
const mode = isFunction ? 'custom' : (matchedOptions.url || 'rebase');
const urlProcessor = getUrlProcessor(mode);
const warn = (message) => decl.warn(result, message);

return urlProcessor(asset, dir, options, decl, warn, result);
return urlProcessor(asset, dir, matchedOptions, decl, warn, result);
};

/**
Expand Down