Skip to content

Commit e786413

Browse files
fix: serializing big strings in sourceMap
1 parent 4277d4d commit e786413

File tree

6 files changed

+68
-2
lines changed

6 files changed

+68
-2
lines changed

Diff for: package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
5858
"babel-eslint": "^10.1.0",
5959
"babel-jest": "^26.6.3",
60+
"bootstrap": "^4.5.3",
6061
"cross-env": "^7.0.2",
6162
"css-loader": "^5.0.1",
6263
"del": "^6.0.0",

Diff for: src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class MiniCssExtractPlugin {
685685
new SourceMapSource(
686686
content,
687687
m.readableIdentifier(requestShortener),
688-
m.sourceMap
688+
m.sourceMap.toString()
689689
)
690690
);
691691
} else {

Diff for: src/loader.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ export function pitch(request) {
239239
context: module.context,
240240
content: Buffer.from(content),
241241
media,
242-
sourceMap,
242+
sourceMap: sourceMap
243+
? Buffer.from(JSON.stringify(sourceMap))
244+
: // eslint-disable-next-line no-undefined
245+
undefined,
243246
};
244247
});
245248
}

Diff for: test/TestCases.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ describe('TestCases', () => {
8989

9090
clearDirectory(outputDirectory);
9191

92+
afterEach(() => {
93+
jest.clearAllMocks();
94+
});
95+
9296
for (const directory of tests) {
9397
if (directory === 'auxiliaryAssets' && webpack.version[0] === '4') {
9498
// eslint-disable-next-line no-continue
@@ -98,6 +102,23 @@ describe('TestCases', () => {
98102
if (!/^(\.|_)/.test(directory)) {
99103
// eslint-disable-next-line no-loop-func
100104
it(`${directory} should compile to the expected result`, (done) => {
105+
if (directory !== 'serializingBigStrings') {
106+
const originalRegister = webpack.util.serialization.register;
107+
108+
webpack.util.serialization.register = jest
109+
.fn()
110+
.mockImplementation((...args) => {
111+
if (args[1].startsWith('mini-css-extract-plugin')) {
112+
// eslint-disable-next-line no-param-reassign
113+
args[1] = args[1].replace(/dist/, 'src');
114+
115+
return originalRegister(...args);
116+
}
117+
118+
return originalRegister(...args);
119+
});
120+
}
121+
101122
const directoryForCase = path.resolve(casesDirectory, directory);
102123
const outputDirectoryForCase = path.resolve(outputDirectory, directory);
103124
// eslint-disable-next-line import/no-dynamic-require, global-require

Diff for: test/cases/serializingBigStrings/webpack.config.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Self from '../../../src/index';
2+
3+
module.exports = {
4+
cache: { type: 'filesystem' },
5+
entry: 'bootstrap/dist/css/bootstrap.css',
6+
module: {
7+
rules: [
8+
{
9+
test: /\.css$/,
10+
use: [
11+
Self.loader,
12+
{
13+
loader: 'css-loader',
14+
options: {
15+
sourceMap: true,
16+
},
17+
},
18+
],
19+
},
20+
],
21+
},
22+
23+
plugins: [
24+
new Self(),
25+
{
26+
apply(compiler) {
27+
compiler.hooks.infrastructureLog.tap('test', (origin, type, args) => {
28+
if (type === 'warn' || type === 'error') {
29+
throw new Error(`<${type}> [${origin}] ${args.toString()}`);
30+
}
31+
});
32+
},
33+
},
34+
],
35+
};

0 commit comments

Comments
 (0)