Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix modules concatenation with importModule usage #15681

Merged
merged 1 commit into from Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/dependencies/LoaderDependency.js
Expand Up @@ -7,6 +7,11 @@

const ModuleDependency = require("./ModuleDependency");

/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */

class LoaderDependency extends ModuleDependency {
/**
* @param {string} request request string
Expand All @@ -22,6 +27,14 @@ class LoaderDependency extends ModuleDependency {
get category() {
return "loader";
}

/**
* @param {ModuleGraph} moduleGraph module graph
* @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
*/
getCondition(moduleGraph) {
return false;
}
}

module.exports = LoaderDependency;
13 changes: 13 additions & 0 deletions lib/dependencies/LoaderImportDependency.js
Expand Up @@ -7,6 +7,11 @@

const ModuleDependency = require("./ModuleDependency");

/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */

class LoaderImportDependency extends ModuleDependency {
/**
* @param {string} request request string
Expand All @@ -23,6 +28,14 @@ class LoaderImportDependency extends ModuleDependency {
get category() {
return "loaderImport";
}

/**
* @param {ModuleGraph} moduleGraph module graph
* @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
*/
getCondition(moduleGraph) {
return false;
}
}

module.exports = LoaderImportDependency;
2 changes: 1 addition & 1 deletion lib/optimize/ModuleConcatenationPlugin.js
Expand Up @@ -606,7 +606,7 @@ class ModuleConcatenationPlugin {
incomingConnectionsFromNonModules.filter(connection => {
// We are not interested in inactive connections
// or connections without dependency
return connection.isActive(runtime) || connection.dependency;
return connection.isActive(runtime);
});
if (activeNonModulesConnections.length > 0) {
const problem = requestShortener => {
Expand Down
1 change: 1 addition & 0 deletions test/configCases/concatenate-modules/import-module/a.txt
@@ -0,0 +1 @@
data
7 changes: 7 additions & 0 deletions test/configCases/concatenate-modules/import-module/index.js
@@ -0,0 +1,7 @@
import url from "./loader!!";
import {url as url2} from "./module1";

it("should compile and run", () => {
expect(url).toBe("webpack:///a.txt");
expect(url2.toString()).toMatch(/^file:/);
});
8 changes: 8 additions & 0 deletions test/configCases/concatenate-modules/import-module/loader.js
@@ -0,0 +1,8 @@
/** @type {import("../../../../").LoaderDefinitionFunction} */
module.exports = function () {
const callback = this.async();
this.importModule("./module1", { baseUri: "webpack://" }, (err, exports) => {
if (err) return callback(err);
callback(null, `module.exports = ${JSON.stringify(exports.url)}`);
});
};
3 changes: 3 additions & 0 deletions test/configCases/concatenate-modules/import-module/module1.js
@@ -0,0 +1,3 @@
const url = new URL("./a.txt", import.meta.url);

export { url }
@@ -0,0 +1,6 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
output: {
assetModuleFilename: "[name][ext]"
}
};