Skip to content

Commit 82f4a47

Browse files
fix: css experiment detection (#1067)
1 parent 98acf2b commit 82f4a47

File tree

20 files changed

+2841
-19153
lines changed

20 files changed

+2841
-19153
lines changed

package-lock.json

+2,803-19,120
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"bootstrap": "^4.6.2",
6868
"cross-env": "^7.0.3",
6969
"cspell": "^6.31.1",
70-
"css-loader": "^6.7.4",
70+
"css-loader": "^6.9.0",
7171
"del": "^6.0.0",
7272
"del-cli": "^4.0.0",
7373
"es-check": "^7.1.0",

src/index.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ class MiniCssExtractPlugin {
301301
updateHash(hash, context) {
302302
super.updateHash(hash, context);
303303

304-
hash.update(this.buildInfo.hash);
304+
hash.update(
305+
/** @type {NonNullable<Module["buildInfo"]>} */ (this.buildInfo).hash
306+
);
305307
}
306308

307309
/**
@@ -825,8 +827,11 @@ class MiniCssExtractPlugin {
825827
const {
826828
runtimeTemplate,
827829
outputOptions: { crossOriginLoading },
828-
} = this.compilation;
829-
const chunkMap = getCssChunkObject(chunk, this.compilation);
830+
} = /** @type {Compilation} */ (this.compilation);
831+
const chunkMap = getCssChunkObject(
832+
/** @type {Chunk} */ (chunk),
833+
/** @type {Compilation} */ (this.compilation)
834+
);
830835

831836
const withLoading =
832837
runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
@@ -953,7 +958,7 @@ class MiniCssExtractPlugin {
953958
"var installedCssChunks = {",
954959
Template.indent(
955960
/** @type {string[]} */
956-
(chunk.ids)
961+
(/** @type {Chunk} */ (chunk).ids)
957962
.map((id) => `${JSON.stringify(id)}: 0`)
958963
.join(",\n")
959964
),
@@ -1162,7 +1167,10 @@ class MiniCssExtractPlugin {
11621167
})
11631168
// eslint-disable-next-line no-undefined
11641169
.filter((item) => item.index !== undefined)
1165-
.sort((a, b) => b.index - a.index)
1170+
.sort(
1171+
(a, b) =>
1172+
/** @type {number} */ (b.index) - /** @type {number} */ (a.index)
1173+
)
11661174
.map((item) => item.module);
11671175

11681176
for (let i = 0; i < sortedModules.length; i++) {

src/loader.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ function pitch(request) {
7575
this._compiler.options.experiments &&
7676
this._compiler.options.experiments.css &&
7777
this._module &&
78-
this._module.type === "css"
78+
(this._module.type === "css" ||
79+
this._module.type === "css/auto" ||
80+
this._module.type === "css/global" ||
81+
this._module.type === "css/module")
7982
) {
8083
this.emitWarning(
8184
new Error(
@@ -373,6 +376,7 @@ function pitch(request) {
373376
const { NodeTemplatePlugin } = webpack.node;
374377
const { NodeTargetPlugin } = webpack.node;
375378

379+
// @ts-ignore
376380
new NodeTemplatePlugin(outputOptions).apply(childCompiler);
377381
new NodeTargetPlugin().apply(childCompiler);
378382

@@ -517,7 +521,10 @@ function loader(content) {
517521
this._compiler.options.experiments &&
518522
this._compiler.options.experiments.css &&
519523
this._module &&
520-
this._module.type === "css"
524+
(this._module.type === "css" ||
525+
this._module.type === "css/auto" ||
526+
this._module.type === "css/global" ||
527+
this._module.type === "css/module")
521528
) {
522529
return content;
523530
}

test/TestCache.test.js

+2-20
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ describe("TestCache", () => {
9494
"static/react.svg",
9595
]
9696
`);
97-
expect(
98-
Array.from(stats.compilation.emittedAssets).sort()
99-
).toMatchInlineSnapshot(`Array []`);
10097
expect(stats.compilation.warnings).toHaveLength(0);
10198
expect(stats.compilation.errors).toHaveLength(0);
10299

@@ -192,9 +189,6 @@ describe("TestCache", () => {
192189
"static/react.svg",
193190
]
194191
`);
195-
expect(
196-
Array.from(stats.compilation.emittedAssets).sort()
197-
).toMatchInlineSnapshot(`Array []`);
198192
expect(stats.compilation.warnings).toHaveLength(0);
199193
expect(stats.compilation.errors).toHaveLength(0);
200194

@@ -297,9 +291,6 @@ describe("TestCache", () => {
297291
"main.js",
298292
]
299293
`);
300-
expect(
301-
Array.from(stats.compilation.emittedAssets).sort()
302-
).toMatchInlineSnapshot(`Array []`);
303294
expect(stats.compilation.warnings).toHaveLength(0);
304295
expect(stats.compilation.errors).toHaveLength(0);
305296

@@ -402,9 +393,6 @@ describe("TestCache", () => {
402393
"main.js",
403394
]
404395
`);
405-
expect(
406-
Array.from(stats.compilation.emittedAssets).sort()
407-
).toMatchInlineSnapshot(`Array []`);
408396
expect(stats.compilation.warnings).toHaveLength(0);
409397
expect(stats.compilation.errors).toHaveLength(0);
410398

@@ -428,7 +416,7 @@ describe("TestCache", () => {
428416
);
429417
const fileSystemCacheDirectory = path.resolve(
430418
__dirname,
431-
"./js/.cache/type-filesystem"
419+
"./js/.cache/type-filesystem-asset-modules"
432420
);
433421

434422
await del([outputPath, fileSystemCacheDirectory]);
@@ -513,9 +501,6 @@ describe("TestCache", () => {
513501
"static/react.svg",
514502
]
515503
`);
516-
expect(
517-
Array.from(stats.compilation.emittedAssets).sort()
518-
).toMatchInlineSnapshot(`Array []`);
519504
expect(stats.compilation.warnings).toHaveLength(0);
520505
expect(stats.compilation.errors).toHaveLength(0);
521506

@@ -539,7 +524,7 @@ describe("TestCache", () => {
539524
);
540525
const fileSystemCacheDirectory = path.resolve(
541526
__dirname,
542-
"./js/.cache/type-filesystem"
527+
"./js/.cache/type-filesystem-file-loader"
543528
);
544529

545530
await del([outputPath, fileSystemCacheDirectory]);
@@ -624,9 +609,6 @@ describe("TestCache", () => {
624609
"static/react.svg",
625610
]
626611
`);
627-
expect(
628-
Array.from(stats.compilation.emittedAssets).sort()
629-
).toMatchInlineSnapshot(`Array []`);
630612
expect(stats.compilation.warnings).toHaveLength(0);
631613
expect(stats.compilation.errors).toHaveLength(0);
632614

test/cases/build-in-css-support/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
},
2020
plugins: [
2121
new Self({
22-
filename: "[name].css",
22+
filename: "[name].extract.css",
2323
}),
2424
],
2525
};

test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
7373
/******/
7474
/******/ /* webpack/runtime/getFullHash */
7575
/******/ (() => {
76-
/******/ __webpack_require__.h = () => ("db7007e0f10c80a36b7a")
76+
/******/ __webpack_require__.h = () => ("55be87a9aa9996fc905c")
7777
/******/ })();
7878
/******/
7979
/******/ /* webpack/runtime/global */
@@ -118,6 +118,7 @@ __webpack_require__.r(__webpack_exports__);
118118
/******/ script.setAttribute("nonce", __webpack_require__.nc);
119119
/******/ }
120120
/******/
121+
/******/
121122
/******/ script.src = url;
122123
/******/ }
123124
/******/ inProgress[url] = [done];

test/cases/chunkFilename-fullhash/expected/webpack-5/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
7373
/******/
7474
/******/ /* webpack/runtime/getFullHash */
7575
/******/ (() => {
76-
/******/ __webpack_require__.h = () => ("106784193c04ad826b7a")
76+
/******/ __webpack_require__.h = () => ("4a73d63c8c2357971fc6")
7777
/******/ })();
7878
/******/
7979
/******/ /* webpack/runtime/global */
@@ -118,6 +118,7 @@ __webpack_require__.r(__webpack_exports__);
118118
/******/ script.setAttribute("nonce", __webpack_require__.nc);
119119
/******/ }
120120
/******/
121+
/******/
121122
/******/ script.src = url;
122123
/******/ }
123124
/******/ inProgress[url] = [done];

test/cases/hmr/expected/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ __webpack_require__.r(__webpack_exports__);
487487
/******/ script.setAttribute("nonce", __webpack_require__.nc);
488488
/******/ }
489489
/******/
490+
/******/
490491
/******/ script.src = url;
491492
/******/ }
492493
/******/ inProgress[url] = [done];

test/cases/insert-function/expected/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
/******/ script.setAttribute("nonce", __webpack_require__.nc);
103103
/******/ }
104104
/******/
105+
/******/
105106
/******/ script.src = url;
106107
/******/ }
107108
/******/ inProgress[url] = [done];

test/cases/insert-string/expected/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
/******/ script.setAttribute("nonce", __webpack_require__.nc);
103103
/******/ }
104104
/******/
105+
/******/
105106
/******/ script.src = url;
106107
/******/ }
107108
/******/ inProgress[url] = [done];

test/cases/insert-undefined/expected/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
/******/ script.setAttribute("nonce", __webpack_require__.nc);
103103
/******/ }
104104
/******/
105+
/******/
105106
/******/ script.src = url;
106107
/******/ }
107108
/******/ inProgress[url] = [done];

test/cases/no-runtime/expected/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ __webpack_require__.r(__webpack_exports__);
104104
/******/ script.setAttribute("nonce", __webpack_require__.nc);
105105
/******/ }
106106
/******/
107+
/******/
107108
/******/ script.src = url;
108109
/******/ }
109110
/******/ inProgress[url] = [done];
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
body {
22
background: green;
3-
background-image: url(http://example.com/0ecdbda184223cdb3d36/c9e192c015437a21dea1.svg);
3+
background-image: url(http://example.com/b284f5dc5823af841415/c9e192c015437a21dea1.svg);
44
}
55

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
body {
22
background: red;
3-
background-image: url(http://example.com/398b3f33c59de2ae9221/c9e192c015437a21dea1.svg);
3+
background-image: url(http://example.com/405f78bf9e607b76da4a/c9e192c015437a21dea1.svg);
44
}
55

test/cases/runtime/expected/runtime~main.js

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
/******/ script.setAttribute("nonce", __webpack_require__.nc);
178178
/******/ }
179179
/******/
180+
/******/
180181
/******/ script.src = url;
181182
/******/ }
182183
/******/ inProgress[url] = [done];

0 commit comments

Comments
 (0)