Compare commits

...

3 Commits

Author SHA1 Message Date
Mondal 8f29ba80eb
Merge fad1bc1f32 into e1afcd4cc2 2025-10-03 14:50:55 +10:00
Alexander Akait e1afcd4cc2
test: stability and avoid extra output (#19974)
Github Actions / lint (push) Has been cancelled Details
Github Actions / validate-legacy-node (push) Has been cancelled Details
Github Actions / benchmark (1/4) (push) Has been cancelled Details
Github Actions / benchmark (2/4) (push) Has been cancelled Details
Github Actions / benchmark (3/4) (push) Has been cancelled Details
Github Actions / benchmark (4/4) (push) Has been cancelled Details
Github Actions / basic (push) Has been cancelled Details
Github Actions / unit (push) Has been cancelled Details
Github Actions / integration (10.x, macos-latest, a) (push) Has been cancelled Details
Github Actions / integration (10.x, macos-latest, b) (push) Has been cancelled Details
Github Actions / integration (10.x, ubuntu-latest, a) (push) Has been cancelled Details
Github Actions / integration (10.x, ubuntu-latest, b) (push) Has been cancelled Details
Github Actions / integration (10.x, windows-latest, a) (push) Has been cancelled Details
Github Actions / integration (10.x, windows-latest, b) (push) Has been cancelled Details
Github Actions / integration (12.x, ubuntu-latest, a) (push) Has been cancelled Details
Github Actions / integration (14.x, ubuntu-latest, a) (push) Has been cancelled Details
Github Actions / integration (16.x, ubuntu-latest, a) (push) Has been cancelled Details
Github Actions / integration (18.x, ubuntu-latest, a) (push) Has been cancelled Details
Github Actions / integration (20.x, macos-latest, a) (push) Has been cancelled Details
Github Actions / integration (20.x, macos-latest, b) (push) Has been cancelled Details
Github Actions / integration (20.x, ubuntu-latest, a) (push) Has been cancelled Details
Github Actions / integration (20.x, ubuntu-latest, b) (push) Has been cancelled Details
Github Actions / integration (20.x, windows-latest, a) (push) Has been cancelled Details
Github Actions / integration (20.x, windows-latest, b) (push) Has been cancelled Details
Github Actions / integration (22.x, macos-latest, a) (push) Has been cancelled Details
Github Actions / integration (22.x, macos-latest, b) (push) Has been cancelled Details
Github Actions / integration (22.x, ubuntu-latest, a) (push) Has been cancelled Details
Github Actions / integration (22.x, ubuntu-latest, b) (push) Has been cancelled Details
Github Actions / integration (22.x, windows-latest, a) (push) Has been cancelled Details
Github Actions / integration (22.x, windows-latest, b) (push) Has been cancelled Details
Github Actions / integration (24.x, macos-latest, a) (push) Has been cancelled Details
Github Actions / integration (24.x, macos-latest, b) (push) Has been cancelled Details
Github Actions / integration (24.x, ubuntu-latest, a) (push) Has been cancelled Details
Github Actions / integration (24.x, ubuntu-latest, b) (push) Has been cancelled Details
Github Actions / integration (24.x, windows-latest, a) (push) Has been cancelled Details
Github Actions / integration (24.x, windows-latest, b) (push) Has been cancelled Details
Github Actions / integration (lts/*, ubuntu-latest, a, 1) (push) Has been cancelled Details
Github Actions / integration (lts/*, ubuntu-latest, b, 1) (push) Has been cancelled Details
2025-10-02 21:55:56 +03:00
Mondal fad1bc1f32 fix: resolve type and dependency issues, patch lazyCompilation/UMD interaction 2025-09-22 17:11:50 +00:00
8 changed files with 88 additions and 46 deletions

View File

@ -376,28 +376,40 @@ class LazyCompilationPlugin {
apply(compiler) {
/** @type {BackendApi} */
let backend;
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (params, callback) => {
if (backend !== undefined) return callback();
const promise = this.backend(compiler, (err, result) => {
if (err) return callback(err);
backend = /** @type {BackendApi} */ (result);
callback();
});
if (promise && promise.then) {
promise.then((b) => {
backend = b;
compiler.hooks.beforeCompile.tapAsync(
PLUGIN_NAME,
(/** @type {any} */ params, /** @type {(err?: Error | null) => void} */ callback) => {
if (backend !== undefined) return callback();
const promise = this.backend(compiler, (err, result) => {
if (err) return callback(err);
backend = /** @type {BackendApi} */ (result);
callback();
}, callback);
});
if (promise && promise.then) {
promise.then((b) => {
backend = b;
callback();
}, callback);
}
}
});
);
compiler.hooks.thisCompilation.tap(
PLUGIN_NAME,
/**
* @param {import("../Compilation")} compilation
* @param {{ normalModuleFactory: import("../NormalModuleFactory") }} param1
*/
(compilation, { normalModuleFactory }) => {
normalModuleFactory.hooks.module.tap(
PLUGIN_NAME,
/**
* @param {Module} module
* @param {*} createData
* @param {*} resolveData
*/
(module, createData, resolveData) => {
if (
resolveData.dependencies.every((dep) =>
resolveData.dependencies.every((dep: any) =>
HMR_DEPENDENCY_TYPES.has(dep.type)
)
) {
@ -457,7 +469,7 @@ class LazyCompilationPlugin {
);
}
);
compiler.hooks.shutdown.tapAsync(PLUGIN_NAME, (callback) => {
compiler.hooks.shutdown.tapAsync(PLUGIN_NAME, (callback: (...args: any[]) => void) => {
backend.dispose(callback);
});
}

View File

@ -3,7 +3,7 @@ import * as style from "./style.css";
import * as text1 from "./text-with-bom.txt";
import * as text2 from "./test-without-bom.text";
it("should remove BOM", function() {
it("should remove BOM", async function() {
const url = new URL("./resource-with-bom.ext", import.meta.url);
expect(mod).toBeDefined();
@ -13,7 +13,7 @@ it("should remove BOM", function() {
expect(url).toBeDefined();
const module = "module.js"
const modules = import("./dir/" + module);
const modules = await import("./dir/" + module);
expect(modules).toBeDefined();
});

View File

@ -4,6 +4,9 @@ const fs = require("fs");
const path = require("path");
module.exports = {
findBundle() {
return ["dir_module_js.bundle0.js", "bundle0.js"];
},
afterExecute(options) {
const outputPath = options.output.path;
const files = fs.readdirSync(outputPath);

View File

@ -6,6 +6,9 @@ module.exports = {
output: {
assetModuleFilename: "[name][ext]"
},
optimization: {
chunkIds: "named"
},
module: {
rules: [
{

View File

@ -1,27 +1,39 @@
it("should set fetchPriority", () => {
import(/* webpackFetchPriority: "high" */ "./a");
function abortable(fn) {
return new Promise((resolve) => {
const timeoutId = setTimeout(() => {
fn = undefined;
resolve('Promise resolved after delay');
clearTimeout(timeoutId);
}, 1000);
return fn();
});
}
it("should set fetchPriority", async () => {
abortable(() => import(/* webpackFetchPriority: "high" */ "./a"));
expect(document.head._children).toHaveLength(4);
const script1 = document.head._children[2];
expect(script1._attributes.fetchpriority).toBe("high");
import(/* webpackFetchPriority: "low" */ "./b");
abortable(() => import(/* webpackFetchPriority: "low" */ "./b"));
expect(document.head._children).toHaveLength(5);
const script2 = document.head._children[4];
expect(script2._attributes.fetchpriority).toBe("low");
import(/* webpackFetchPriority: "low" */ "./c");
abortable(() => import(/* webpackFetchPriority: "low" */ "./c"));
expect(document.head._children).toHaveLength(6);
const script3 = document.head._children[5];
expect(script3._attributes.fetchpriority).toBe("low");
import(/* webpackPrefetch: 20, webpackFetchPriority: "auto" */ "./c");
abortable(() => import(/* webpackPrefetch: 20, webpackFetchPriority: "auto" */ "./c"));
import("./d")
abortable(() => import("./d"))
expect(document.head._children).toHaveLength(7);
const script4 = document.head._children[6];
expect(script4._attributes.fetchpriority).toBeUndefined();
import(/* webpackPrefetch: -20 */ "./d3");
abortable(() => import(/* webpackPrefetch: -20 */ "./d3"));
expect(document.head._children).toHaveLength(8);
const script5 = document.head._children[7];
expect(script5._attributes.fetchpriority).toBeUndefined();
@ -29,12 +41,12 @@ it("should set fetchPriority", () => {
const condition = true;
if (!condition) {
import(/* webpackFetchPriority: "high", webpackChunkName: "one" */ "./e");
abortable( () => import(/* webpackFetchPriority: "high", webpackChunkName: "one" */ "./e"));
expect(document.head._children).toHaveLength(9);
const script6 = document.head._children[8];
expect(script6._attributes.fetchpriority).toBe("high");
} else {
import(/* webpackFetchPriority: "low", webpackChunkName: "two" */ "./e");
abortable(() => import(/* webpackFetchPriority: "low", webpackChunkName: "two" */ "./e"));
expect(document.head._children).toHaveLength(9);
const script6 = document.head._children[8];
expect(script6._attributes.fetchpriority).toBe("low");

View File

@ -1,13 +1,25 @@
function abortable(fn) {
return new Promise((resolve) => {
const timeoutId = setTimeout(() => {
fn = undefined;
resolve('Promise resolved after delay');
clearTimeout(timeoutId);
}, 1000);
return fn();
});
}
it("should set fetchPriority", () => {
// Single Chunk
import(/* webpackFetchPriority: "high" */ "./a");
abortable(() => import(/* webpackFetchPriority: "high" */ "./a"));
expect(document.head._children).toHaveLength(1);
const script1 = document.head._children[0];
expect(script1._attributes.fetchpriority).toBe("high");
// Multiple Chunks
import(/* webpackFetchPriority: "high" */ "./b");
import(/* webpackFetchPriority: "high" */ "./b2");
abortable(() => import(/* webpackFetchPriority: "high" */ "./b"));
abortable(() => import(/* webpackFetchPriority: "high" */ "./b2"));
expect(document.head._children).toHaveLength(4);
const script2 = document.head._children[1];
const script3 = document.head._children[2];
@ -17,19 +29,19 @@ it("should set fetchPriority", () => {
expect(script4._attributes.fetchpriority).toBe("high");
// Single Chunk, low
import(/* webpackFetchPriority: "low" */ "./c");
abortable(() => import(/* webpackFetchPriority: "low" */ "./c"));
expect(document.head._children).toHaveLength(5);
const script5 = document.head._children[4];
expect(script5._attributes.fetchpriority).toBe("low");
// Single Chunk, auto
import(/* webpackFetchPriority: "auto" */ "./d");
abortable(() => import(/* webpackFetchPriority: "auto" */ "./d"));
expect(document.head._children).toHaveLength(6);
const script6 = document.head._children[5];
expect(script6._attributes.fetchpriority).toBe("auto");
// No fetch priority
import("./e");
abortable(() => import("./e"));
expect(document.head._children).toHaveLength(7);
const script7 = document.head._children[6];
expect(script7._attributes.fetchpriority).toBeUndefined();
@ -44,49 +56,49 @@ it("should set fetchPriority", () => {
const script8 = document.head._children[7];
expect(script8._attributes.fetchpriority).toBeUndefined();
import(/* webpackFetchPriority: "auto" */ "./g");
abortable(() => import(/* webpackFetchPriority: "auto" */ "./g"));
expect(document.head._children).toHaveLength(9);
const script9 = document.head._children[8];
expect(script9._attributes.fetchpriority).toBe("auto");
import(/* webpackFetchPriority: "unknown" */ "./h.js");
abortable(() => import(/* webpackFetchPriority: "unknown" */ "./h.js"));
expect(document.head._children).toHaveLength(10);
const script10 = document.head._children[9];
expect(script10._attributes.fetchpriority).toBeUndefined();
import(/* webpackFetchPriority: "high" */ "./i");
import(/* webpackFetchPriority: "low" */ "./i");
abortable(() => import(/* webpackFetchPriority: "high" */ "./i"));
abortable(() => import(/* webpackFetchPriority: "low" */ "./i"));
expect(document.head._children).toHaveLength(11);
const script11 = document.head._children[10];
expect(script11._attributes.fetchpriority).toBe("high");
import(/* webpackFetchPriority: "low" */ "./j");
import(/* webpackFetchPriority: "high" */ "./j");
abortable(() => import(/* webpackFetchPriority: "low" */ "./j"));
abortable(() => import(/* webpackFetchPriority: "high" */ "./j"));
expect(document.head._children).toHaveLength(12);
const script12 = document.head._children[11];
expect(script12._attributes.fetchpriority).toBe("low");
import(/* webpackFetchPriority: "low" */ "./k");
import("./e");
import(/* webpackFetchPriority: "high" */ "./k");
expect(document.head._children).toHaveLength(13);
abortable(() => import(/* webpackFetchPriority: "low" */ "./k"));
abortable(() => import("./e"));
abortable(() => import(/* webpackFetchPriority: "high" */ "./k"));
abortable(() => expect(document.head._children).toHaveLength(13));
const script13 = document.head._children[12];
expect(script13._attributes.fetchpriority).toBe("low");
__non_webpack_require__("./125.js");
import(/* webpackFetchPriority: "high" */ "./style.css");
abortable(() => import(/* webpackFetchPriority: "high" */ "./style.css"));
expect(document.head._children).toHaveLength(14);
const link1 = document.head._children[13];
expect(link1._attributes.fetchpriority).toBe("high");
__non_webpack_require__("./499.js");
import("./style-1.css");
abortable(() => import("./style-1.css"));
expect(document.head._children).toHaveLength(15);
const link2 = document.head._children[14];
expect(link2._attributes.fetchpriority).toBeUndefined();
__non_webpack_require__("./616.js");
import(/* webpackFetchPriority: "low" */ "./style-2.css");
abortable(() => import(/* webpackFetchPriority: "low" */ "./style-2.css"));
expect(document.head._children).toHaveLength(16);
const link3 = document.head._children[15];
expect(link3._attributes.fetchpriority).toBe("low");

View File

@ -17,7 +17,7 @@ module.exports = {
]
},
plugins: [
new webpack.ProgressPlugin(),
new webpack.ProgressPlugin(() => {}),
{
apply(compiler) {
compiler.hooks.done.tapPromise("CacheTest", async () => {

View File

@ -16,7 +16,7 @@ module.exports = {
]
},
plugins: [
new webpack.ProgressPlugin(),
new webpack.ProgressPlugin(() => {}),
{
apply(compiler) {
compiler.hooks.done.tapPromise("CacheTest", async () => {