From f64de13f7377eff9501348cf26213212ca696913 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Fri, 24 Apr 2020 14:58:20 +0300 Subject: [PATCH] fix: avoid query string in source maps (#1082) --- src/index.js | 6 +-- .../sourceMap-option.test.js.snap | 43 +++++++++++++++++++ test/fixtures/source-map/with-query.css | 3 ++ test/fixtures/source-map/with-query.js | 5 +++ test/sourceMap-option.test.js | 16 +++++++ 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/source-map/with-query.css create mode 100644 test/fixtures/source-map/with-query.js diff --git a/src/index.js b/src/index.js index 38eaeb8d..11830615 100644 --- a/src/index.js +++ b/src/index.js @@ -82,8 +82,8 @@ export default function loader(content, map, meta) { postcss(plugins) .process(content, { - from: this.remainingRequest.split('!').pop(), - to: this.currentRequest.split('!').pop(), + from: this.resourcePath, + to: this.resourcePath, map: options.sourceMap ? { // Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it @@ -151,8 +151,6 @@ export default function loader(content, map, meta) { }) .catch((error) => { if (error.file) { - console.log(error.file); - this.addDependency(error.file); } diff --git a/test/__snapshots__/sourceMap-option.test.js.snap b/test/__snapshots__/sourceMap-option.test.js.snap index 02092fd5..7cee4dd4 100644 --- a/test/__snapshots__/sourceMap-option.test.js.snap +++ b/test/__snapshots__/sourceMap-option.test.js.snap @@ -294,6 +294,49 @@ Array [ exports[`"sourceMap" option not specified should not generate source maps: warnings 1`] = `Array []`; +exports[`"sourceMap" option true should generate source maps #2: errors 1`] = `Array []`; + +exports[`"sourceMap" option true should generate source maps #2: module 1`] = ` +"// Imports +var ___CSS_LOADER_API_IMPORT___ = require(\\"../../../src/runtime/api.js\\"); +exports = ___CSS_LOADER_API_IMPORT___(true); +// Module +exports.push([module.id, \\".foo {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"with-query.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA;EACE,UAAU;AACZ\\",\\"file\\":\\"with-query.css\\",\\"sourcesContent\\":[\\".foo {\\\\n color: red;\\\\n}\\\\n\\"]}]); +// Exports +module.exports = exports; +" +`; + +exports[`"sourceMap" option true should generate source maps #2: result 1`] = ` +Array [ + Array [ + "./source-map/with-query.css?url=false", + ".foo { + color: red; +} +", + "", + Object { + "file": "with-query.css", + "mappings": "AAAA;EACE,UAAU;AACZ", + "names": Array [], + "sources": Array [ + "with-query.css", + ], + "sourcesContent": Array [ + ".foo { + color: red; +} +", + ], + "version": 3, + }, + ], +] +`; + +exports[`"sourceMap" option true should generate source maps #2: warnings 1`] = `Array []`; + exports[`"sourceMap" option true should generate source maps when source maps equal to "null" from an other loader: errors 1`] = `Array []`; exports[`"sourceMap" option true should generate source maps when source maps equal to "null" from an other loader: module 1`] = ` diff --git a/test/fixtures/source-map/with-query.css b/test/fixtures/source-map/with-query.css new file mode 100644 index 00000000..a15c877a --- /dev/null +++ b/test/fixtures/source-map/with-query.css @@ -0,0 +1,3 @@ +.foo { + color: red; +} diff --git a/test/fixtures/source-map/with-query.js b/test/fixtures/source-map/with-query.js new file mode 100644 index 00000000..497fdf9c --- /dev/null +++ b/test/fixtures/source-map/with-query.js @@ -0,0 +1,5 @@ +import css from './with-query.css?url=false'; + +__export__ = css; + +export default css; diff --git a/test/sourceMap-option.test.js b/test/sourceMap-option.test.js index 8aacdce8..05c51bb3 100644 --- a/test/sourceMap-option.test.js +++ b/test/sourceMap-option.test.js @@ -45,6 +45,22 @@ describe('"sourceMap" option', () => { expect(getErrors(stats)).toMatchSnapshot('errors'); }); + it('should generate source maps #2', async () => { + const compiler = getCompiler('./source-map/with-query.js', { + sourceMap: true, + }); + const stats = await compile(compiler); + + expect( + getModuleSource('./source-map/with-query.css?url=false', stats) + ).toMatchSnapshot('module'); + expect( + getExecutedCode('main.bundle.js', compiler, stats) + ).toMatchSnapshot('result'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + it('should generate source maps when source maps equal to "null" from an other loader', async () => { const compiler = getCompiler( './source-map/basic.js',