Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid query string in source maps #1082

Merged
merged 1 commit into from Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/index.js
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
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
@@ -0,0 +1,3 @@
.foo {
color: red;
}
5 changes: 5 additions & 0 deletions test/fixtures/source-map/with-query.js
@@ -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
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