Repository: webpack-contrib/css-loader
Pull request #1082 (2020-04-24 11:41:38)

fix: avoid query string in source maps
<!--
  HOLY CRAP a Pull Request. We ❤️ those!

  If you remove or skip this template, you'll make the 🐼 sad and the mighty god
  of Github will appear and pile-drive the close button from a great height
  while making animal noises.

  Please place an x (no spaces!) in all [ ] that apply
-->

This PR contains a:

- [x] **bugfix**
- [ ] new **feature**
- [ ] **code refactor**
- [x] **test update** <!-- if bug or feature is checked, this should be too -->
- [ ] **typo fix**
- [ ] **metadata update**

### Motivation / Use-Case

we don't need queries in sources

### Breaking Changes

No

### Additional Info

No

codecov[bot]: # [Codecov](https://codecov.io/gh/webpack-contrib/css-loader/pull/1082?src=pr&el=h1) Report
> Merging [#1082](https://codecov.io/gh/webpack-contrib/css-loader/pull/1082?src=pr&el=desc) into [master](https://codecov.io/gh/webpack-contrib/css-loader/commit/841423fca2932c18f8ac0cf0a1f0012fc0a62fb6&el=desc) will **decrease** coverage by `0.00%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/webpack-contrib/css-loader/pull/1082/graphs/tree.svg?width=650&height=150&src=pr&token=DlN3OQ0JnO)](https://codecov.io/gh/webpack-contrib/css-loader/pull/1082?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1082      +/-   ##
==========================================
- Coverage   97.29%   97.28%   -0.01%     
==========================================
  Files          10       10              
  Lines         480      479       -1     
  Branches      161      161              
==========================================
- Hits          467      466       -1     
  Misses         12       12              
  Partials        1        1              
```


| [Impacted Files](https://codecov.io/gh/webpack-contrib/css-loader/pull/1082?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/index.js](https://codecov.io/gh/webpack-contrib/css-loader/pull/1082/diff?src=pr&el=tree#diff-c3JjL2luZGV4Lmpz) | `100.00% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/webpack-contrib/css-loader/pull/1082?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/webpack-contrib/css-loader/pull/1082?src=pr&el=footer). Last update [841423f...d35bdb5](https://codecov.io/gh/webpack-contrib/css-loader/pull/1082?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/index.js b/src/index.js
index 38eaeb8..1183061 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);
       }
 


Test patch:
diff --git a/test/__snapshots__/sourceMap-option.test.js.snap b/test/__snapshots__/sourceMap-option.test.js.snap
index 02092fd..7cee4dd 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 0000000..a15c877
--- /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 0000000..497fdf9
--- /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 8aacdce..05c51bb 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',