Skip to content

Commit

Permalink
fix: invert Function behavior for url and import options (#939)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: you should return `true` when you want handle `url`/`@import` and return `false` if not
  • Loading branch information
evilebottnawi authored May 28, 2019
1 parent 888cca0 commit e9eb5ad
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ module.exports = {
options: {
url: (url, resourcePath) => {
// resourcePath - path to css file

// Don't handle `img.png` urls
if (url.includes('img.png')) {
return false;
}

// `url()` with `img.png` stay untouched
return url.includes('img.png');
return true;
},
},
},
Expand Down Expand Up @@ -262,8 +266,12 @@ module.exports = {
// parsedImport.media - media query of `@import`
// resourcePath - path to css file

// `@import` with `style.css` stay untouched
return parsedImport.url.includes('style.css');
// Don't handle `style.css` import
if (parsedImport.url.includes('style.css')) {
return false;
}

return true;
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
}

function getFilter(filter, resourcePath, defaultFilter = null) {
return (content) => {
if (defaultFilter && !defaultFilter(content)) {
return (item) => {
if (defaultFilter && !defaultFilter(item)) {
return false;
}

if (typeof filter === 'function') {
return !filter(content, resourcePath);
return filter(item, resourcePath);
}

return true;
Expand Down
7 changes: 6 additions & 1 deletion test/import-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ describe('import option', () => {
import: (parsedImport, resourcePath) => {
expect(typeof resourcePath === 'string').toBe(true);

return parsedImport.url.includes('test.css');
// Don't handle `test.css`
if (parsedImport.url.includes('test.css')) {
return false;
}

return true;
},
},
},
Expand Down
7 changes: 6 additions & 1 deletion test/url-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ describe('url option', () => {
url: (url, resourcePath) => {
expect(typeof resourcePath === 'string').toBe(true);

return url.includes('img.png');
// Don't handle `img.png`
if (url.includes('img.png')) {
return false;
}

return true;
},
},
},
Expand Down

0 comments on commit e9eb5ad

Please sign in to comment.