Skip to content

Commit 4024bb7

Browse files
sokraartonge
authored andcommitted
cleanup
1 parent fdf28b8 commit 4024bb7

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

lib/ModuleFilenameHelpers.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"use strict";
77

8+
const NormalModule = require("./NormalModule");
89
const createHash = require("./util/createHash");
910
const memoize = require("./util/memoize");
1011

@@ -122,6 +123,7 @@ ModuleFilenameHelpers.createFilename = (
122123
};
123124

124125
let absoluteResourcePath;
126+
let resource;
125127
let hash;
126128
let identifier;
127129
let moduleId;
@@ -132,17 +134,20 @@ ModuleFilenameHelpers.createFilename = (
132134
moduleId = () => "";
133135
absoluteResourcePath = () => module.split("!").pop();
134136
hash = getHash(identifier, hashFunction);
137+
resource = memoize(() => shortIdentifier().split("!").pop());
135138
} else {
136139
shortIdentifier = memoize(() =>
137140
module.readableIdentifier(requestShortener)
138141
);
139142
identifier = memoize(() => requestShortener.shorten(module.identifier()));
140143
moduleId = () => chunkGraph.getModuleId(module);
141144
absoluteResourcePath = () =>
142-
requestShortener.shorten(module.nameForCondition());
145+
module instanceof NormalModule
146+
? module.resource
147+
: module.identifier().split("!").pop();
143148
hash = getHash(identifier, hashFunction);
149+
resource = memoize(() => requestShortener.shorten(absoluteResourcePath()));
144150
}
145-
const resource = memoize(() => shortIdentifier().split("!").pop());
146151

147152
const loaders = getBefore(shortIdentifier, "!");
148153
const allLoaders = getBefore(identifier, "!");
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
it("should not include layer or type in absoluteResourcePath", function() {
1+
it("should not include layer or type in absoluteResourcePath", function () {
22
var fs = require("fs");
3+
var path = require("path");
34
var source = fs.readFileSync(__filename + ".map", "utf-8");
45
var map = JSON.parse(source);
5-
expect(map.sources).toContain("webpack:///test.js");
6+
expect(map.sources).toContain(
7+
path.resolve(
8+
__dirname,
9+
"../../../..//configCases/source-map/resource-path/test.js"
10+
)
11+
);
612
});
713

814
if (Math.random() < 0) require("./test.js");

test/configCases/source-map/resource-path/webpack.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const path = require("path");
2-
31
/** @type {import("../../../../").Configuration} */
42
module.exports = {
53
node: {
@@ -18,9 +16,7 @@ module.exports = {
1816
},
1917
output: {
2018
devtoolModuleFilenameTemplate(info) {
21-
const rootDir = process.cwd();
22-
const rel = path.relative(rootDir, info.absoluteResourcePath);
23-
return `webpack:///${rel}`;
19+
return info.absoluteResourcePath;
2420
}
2521
}
2622
};

0 commit comments

Comments
 (0)