Skip to content

Commit

Permalink
fix: serializing big strings in sourceMap (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito committed Dec 10, 2020
1 parent 4277d4d commit f7a5e53
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
12 changes: 9 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.3",
"bootstrap": "^4.5.3",
"cross-env": "^7.0.2",
"css-loader": "^5.0.1",
"del": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ class MiniCssExtractPlugin {
new SourceMapSource(
content,
m.readableIdentifier(requestShortener),
m.sourceMap
m.sourceMap.toString()
)
);
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ export function pitch(request) {
context: module.context,
content: Buffer.from(content),
media,
sourceMap,
sourceMap: sourceMap
? Buffer.from(JSON.stringify(sourceMap))
: // eslint-disable-next-line no-undefined
undefined,
};
});
}
Expand Down
4 changes: 4 additions & 0 deletions test/TestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ describe('TestCases', () => {
if (!/^(\.|_)/.test(directory)) {
// eslint-disable-next-line no-loop-func
it(`${directory} should compile to the expected result`, (done) => {
if (directory === 'serializingBigStrings') {
clearDirectory(path.resolve(__dirname, '../node_modules/.cache'));
}

const directoryForCase = path.resolve(casesDirectory, directory);
const outputDirectoryForCase = path.resolve(outputDirectory, directory);
// eslint-disable-next-line import/no-dynamic-require, global-require
Expand Down
35 changes: 35 additions & 0 deletions test/cases/serializingBigStrings/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Self from '../../../src/index';

module.exports = {
cache: { type: 'filesystem' },
entry: 'bootstrap/dist/css/bootstrap.css',
module: {
rules: [
{
test: /\.css$/,
use: [
Self.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
],
},
],
},

plugins: [
new Self(),
{
apply(compiler) {
compiler.hooks.infrastructureLog.tap('test', (origin, type, args) => {
if (type === 'warn' || type === 'error') {
throw new Error(`<${type}> [${origin}] ${args.toString()}`);
}
});
},
},
],
};

0 comments on commit f7a5e53

Please sign in to comment.