From e9eb5ad8e16a4586042773bf77457daf31bd68d4 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Tue, 28 May 2019 20:32:35 +0300 Subject: [PATCH] fix: invert `Function` behavior for `url` and `import` options (#939) BREAKING CHANGE: you should return `true` when you want handle `url`/`@import` and return `false` if not --- README.md | 16 ++++++++++++---- src/utils.js | 6 +++--- test/import-option.test.js | 7 ++++++- test/url-option.test.js | 7 ++++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index efd6bb52..5c67b34a 100644 --- a/README.md +++ b/README.md @@ -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; }, }, }, @@ -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; }, }, }, diff --git a/src/utils.js b/src/utils.js index 5d8c2d27..d115ce8f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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; diff --git a/test/import-option.test.js b/test/import-option.test.js index fc6f92d1..0cc4590e 100644 --- a/test/import-option.test.js +++ b/test/import-option.test.js @@ -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; }, }, }, diff --git a/test/url-option.test.js b/test/url-option.test.js index 42c1a938..a04faa1f 100644 --- a/test/url-option.test.js +++ b/test/url-option.test.js @@ -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; }, }, },