Skip to content

Commit

Permalink
fix: avoid query string in source maps (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Apr 24, 2020
1 parent 841423f commit f64de13
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -151,8 +151,6 @@ export default function loader(content, map, meta) {
})
.catch((error) => {
if (error.file) {
console.log(error.file);

this.addDependency(error.file);
}

Expand Down
43 changes: 43 additions & 0 deletions test/__snapshots__/sourceMap-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/source-map/with-query.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
color: red;
}
5 changes: 5 additions & 0 deletions test/fixtures/source-map/with-query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import css from './with-query.css?url=false';

__export__ = css;

export default css;
16 changes: 16 additions & 0 deletions test/sourceMap-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f64de13

Please sign in to comment.