Skip to content

Commit

Permalink
fix: css experiment detection (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Jan 10, 2024
1 parent 98acf2b commit 82f4a47
Show file tree
Hide file tree
Showing 20 changed files with 2,841 additions and 19,153 deletions.
21,923 changes: 2,803 additions & 19,120 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"bootstrap": "^4.6.2",
"cross-env": "^7.0.3",
"cspell": "^6.31.1",
"css-loader": "^6.7.4",
"css-loader": "^6.9.0",
"del": "^6.0.0",
"del-cli": "^4.0.0",
"es-check": "^7.1.0",
Expand Down
18 changes: 13 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ class MiniCssExtractPlugin {
updateHash(hash, context) {
super.updateHash(hash, context);

hash.update(this.buildInfo.hash);
hash.update(
/** @type {NonNullable<Module["buildInfo"]>} */ (this.buildInfo).hash
);
}

/**
Expand Down Expand Up @@ -825,8 +827,11 @@ class MiniCssExtractPlugin {
const {
runtimeTemplate,
outputOptions: { crossOriginLoading },
} = this.compilation;
const chunkMap = getCssChunkObject(chunk, this.compilation);
} = /** @type {Compilation} */ (this.compilation);
const chunkMap = getCssChunkObject(
/** @type {Chunk} */ (chunk),
/** @type {Compilation} */ (this.compilation)
);

const withLoading =
runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
Expand Down Expand Up @@ -953,7 +958,7 @@ class MiniCssExtractPlugin {
"var installedCssChunks = {",
Template.indent(
/** @type {string[]} */
(chunk.ids)
(/** @type {Chunk} */ (chunk).ids)
.map((id) => `${JSON.stringify(id)}: 0`)
.join(",\n")
),
Expand Down Expand Up @@ -1162,7 +1167,10 @@ class MiniCssExtractPlugin {
})
// eslint-disable-next-line no-undefined
.filter((item) => item.index !== undefined)
.sort((a, b) => b.index - a.index)
.sort(
(a, b) =>
/** @type {number} */ (b.index) - /** @type {number} */ (a.index)
)
.map((item) => item.module);

for (let i = 0; i < sortedModules.length; i++) {
Expand Down
11 changes: 9 additions & 2 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ function pitch(request) {
this._compiler.options.experiments &&
this._compiler.options.experiments.css &&
this._module &&
this._module.type === "css"
(this._module.type === "css" ||
this._module.type === "css/auto" ||
this._module.type === "css/global" ||
this._module.type === "css/module")
) {
this.emitWarning(
new Error(
Expand Down Expand Up @@ -373,6 +376,7 @@ function pitch(request) {
const { NodeTemplatePlugin } = webpack.node;
const { NodeTargetPlugin } = webpack.node;

// @ts-ignore
new NodeTemplatePlugin(outputOptions).apply(childCompiler);
new NodeTargetPlugin().apply(childCompiler);

Expand Down Expand Up @@ -517,7 +521,10 @@ function loader(content) {
this._compiler.options.experiments &&
this._compiler.options.experiments.css &&
this._module &&
this._module.type === "css"
(this._module.type === "css" ||
this._module.type === "css/auto" ||
this._module.type === "css/global" ||
this._module.type === "css/module")
) {
return content;
}
Expand Down
22 changes: 2 additions & 20 deletions test/TestCache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ describe("TestCache", () => {
"static/react.svg",
]
`);
expect(
Array.from(stats.compilation.emittedAssets).sort()
).toMatchInlineSnapshot(`Array []`);
expect(stats.compilation.warnings).toHaveLength(0);
expect(stats.compilation.errors).toHaveLength(0);

Expand Down Expand Up @@ -192,9 +189,6 @@ describe("TestCache", () => {
"static/react.svg",
]
`);
expect(
Array.from(stats.compilation.emittedAssets).sort()
).toMatchInlineSnapshot(`Array []`);
expect(stats.compilation.warnings).toHaveLength(0);
expect(stats.compilation.errors).toHaveLength(0);

Expand Down Expand Up @@ -297,9 +291,6 @@ describe("TestCache", () => {
"main.js",
]
`);
expect(
Array.from(stats.compilation.emittedAssets).sort()
).toMatchInlineSnapshot(`Array []`);
expect(stats.compilation.warnings).toHaveLength(0);
expect(stats.compilation.errors).toHaveLength(0);

Expand Down Expand Up @@ -402,9 +393,6 @@ describe("TestCache", () => {
"main.js",
]
`);
expect(
Array.from(stats.compilation.emittedAssets).sort()
).toMatchInlineSnapshot(`Array []`);
expect(stats.compilation.warnings).toHaveLength(0);
expect(stats.compilation.errors).toHaveLength(0);

Expand All @@ -428,7 +416,7 @@ describe("TestCache", () => {
);
const fileSystemCacheDirectory = path.resolve(
__dirname,
"./js/.cache/type-filesystem"
"./js/.cache/type-filesystem-asset-modules"
);

await del([outputPath, fileSystemCacheDirectory]);
Expand Down Expand Up @@ -513,9 +501,6 @@ describe("TestCache", () => {
"static/react.svg",
]
`);
expect(
Array.from(stats.compilation.emittedAssets).sort()
).toMatchInlineSnapshot(`Array []`);
expect(stats.compilation.warnings).toHaveLength(0);
expect(stats.compilation.errors).toHaveLength(0);

Expand All @@ -539,7 +524,7 @@ describe("TestCache", () => {
);
const fileSystemCacheDirectory = path.resolve(
__dirname,
"./js/.cache/type-filesystem"
"./js/.cache/type-filesystem-file-loader"
);

await del([outputPath, fileSystemCacheDirectory]);
Expand Down Expand Up @@ -624,9 +609,6 @@ describe("TestCache", () => {
"static/react.svg",
]
`);
expect(
Array.from(stats.compilation.emittedAssets).sort()
).toMatchInlineSnapshot(`Array []`);
expect(stats.compilation.warnings).toHaveLength(0);
expect(stats.compilation.errors).toHaveLength(0);

Expand Down
2 changes: 1 addition & 1 deletion test/cases/build-in-css-support/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
},
plugins: [
new Self({
filename: "[name].css",
filename: "[name].extract.css",
}),
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("db7007e0f10c80a36b7a")
/******/ __webpack_require__.h = () => ("55be87a9aa9996fc905c")
/******/ })();
/******/
/******/ /* webpack/runtime/global */
Expand Down Expand Up @@ -118,6 +118,7 @@ __webpack_require__.r(__webpack_exports__);
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/
/******/
/******/ script.src = url;
/******/ }
/******/ inProgress[url] = [done];
Expand Down
3 changes: 2 additions & 1 deletion test/cases/chunkFilename-fullhash/expected/webpack-5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("106784193c04ad826b7a")
/******/ __webpack_require__.h = () => ("4a73d63c8c2357971fc6")
/******/ })();
/******/
/******/ /* webpack/runtime/global */
Expand Down Expand Up @@ -118,6 +118,7 @@ __webpack_require__.r(__webpack_exports__);
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/
/******/
/******/ script.src = url;
/******/ }
/******/ inProgress[url] = [done];
Expand Down
1 change: 1 addition & 0 deletions test/cases/hmr/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ __webpack_require__.r(__webpack_exports__);
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/
/******/
/******/ script.src = url;
/******/ }
/******/ inProgress[url] = [done];
Expand Down
1 change: 1 addition & 0 deletions test/cases/insert-function/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/
/******/
/******/ script.src = url;
/******/ }
/******/ inProgress[url] = [done];
Expand Down
1 change: 1 addition & 0 deletions test/cases/insert-string/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/
/******/
/******/ script.src = url;
/******/ }
/******/ inProgress[url] = [done];
Expand Down
1 change: 1 addition & 0 deletions test/cases/insert-undefined/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/
/******/
/******/ script.src = url;
/******/ }
/******/ inProgress[url] = [done];
Expand Down
1 change: 1 addition & 0 deletions test/cases/no-runtime/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ __webpack_require__.r(__webpack_exports__);
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/
/******/
/******/ script.src = url;
/******/ }
/******/ inProgress[url] = [done];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
body {
background: green;
background-image: url(http://example.com/0ecdbda184223cdb3d36/c9e192c015437a21dea1.svg);
background-image: url(http://example.com/b284f5dc5823af841415/c9e192c015437a21dea1.svg);
}

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

1 change: 1 addition & 0 deletions test/cases/runtime/expected/runtime~main.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/
/******/
/******/ script.src = url;
/******/ }
/******/ inProgress[url] = [done];
Expand Down

0 comments on commit 82f4a47

Please sign in to comment.