fix: logic

This commit is contained in:
alexander.akait 2024-10-10 18:37:04 +03:00
parent 1e364fabe2
commit 5a3ce4e0d7
24 changed files with 40 additions and 16 deletions

View File

@ -57,7 +57,7 @@ class EvalDevToolModulePlugin {
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
hooks.renderModuleContent.tap(
"EvalDevToolModulePlugin",
(source, module, { runtimeTemplate, chunkGraph }) => {
(source, module, { chunk, runtimeTemplate, chunkGraph }) => {
const cacheEntry = cache.get(source);
if (cacheEntry !== undefined) return cacheEntry;
if (module instanceof ExternalModule) {
@ -66,7 +66,7 @@ class EvalDevToolModulePlugin {
}
const content = source.source();
const namespace = compilation.getPath(this.namespace, {
chunk: chunkGraph.getModuleChunks(module)[0]
chunk
});
const str = ModuleFilenameHelpers.createFilename(
module,

View File

@ -77,7 +77,7 @@ class EvalSourceMapDevToolPlugin {
);
hooks.renderModuleContent.tap(
"EvalSourceMapDevToolPlugin",
(source, m, { runtimeTemplate, chunkGraph }) => {
(source, m, { chunk, runtimeTemplate, chunkGraph }) => {
const cachedSource = cache.get(source);
if (cachedSource !== undefined) {
return cachedSource;
@ -114,7 +114,7 @@ class EvalSourceMapDevToolPlugin {
}
const namespace = compilation.getPath(this.namespace, {
chunk: chunkGraph.getModuleChunks(m)[0]
chunk
});
/** @type {SourceMap} */
let sourceMap;

View File

@ -239,8 +239,7 @@ class SourceMapDevToolPlugin {
const chunk = fileToChunk.get(file);
const sourceMapNamespace = compilation.getPath(this.namespace, {
chunk,
contentHashType: "javascript"
chunk
});
const cacheItem = cache.getItemCache(
@ -277,10 +276,8 @@ class SourceMapDevToolPlugin {
/**
* Add file to chunk, if not presented there
*/
if (cachedFile !== file) {
if (chunk !== undefined)
chunk.auxiliaryFiles.add(cachedFile);
}
if (cachedFile !== file && chunk !== undefined)
chunk.auxiliaryFiles.add(cachedFile);
}
reportProgress(

View File

@ -0,0 +1,5 @@
it("should include webpack://library-entry-a/./src/entry-a.js in SourceMap", function() {
const fs = require("fs");
const source = fs.readFileSync(__filename, "utf-8");
expect(source).toContain("sourceURL=webpack://library-entry-a/./src/entry-a.js");
});

View File

@ -0,0 +1,5 @@
it("should include webpack://library-entry-b/./src/entry-b.js in SourceMap", function() {
const fs = require("fs");
const source = fs.readFileSync(__filename, "utf-8");
expect(source).toContain("sourceURL=webpack://library-entry-b/./src/entry-b.js");
});

View File

@ -0,0 +1,5 @@
module.exports = {
findBundle: function (i, options) {
return ["entry-a-bundle.js", "entry-b-bundle.js"];
}
};

View File

@ -0,0 +1,18 @@
const path = require("path");
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
entry: {
"entry-a": [path.join(__dirname, "./src/entry-a")],
"entry-b": [path.join(__dirname, "./src/entry-b")]
},
output: {
filename: "[name]-bundle.js",
library: "library-[name]",
libraryTarget: "commonjs",
devtoolNamespace: "library-[name]"
},
devtool: "eval-source-map"
};

View File

@ -1,6 +0,0 @@
it("should include webpack://library-entry-a/./src/entry-a.js in SourceMap", function() {
var fs = require("fs");
var source = fs.readFileSync(__filename + ".map", "utf-8");
var map = JSON.parse(source);
expect(map.sources).toContain("sourceURL=webpack://library-entry-a/./src/entry-a.js");
});