Skip to content

Commit ad5968a

Browse files
committed
only make absolute pathy things relative
1 parent 5b42e39 commit ad5968a

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

lib/RecordIdsPlugin.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
*/
55
"use strict";
66

7+
const path = require("path");
8+
9+
const looksLikeAbsolutePath = (maybeAbsolutePath) => /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath);
10+
711
function makeRelative(compiler, identifier) {
812
const context = compiler.context;
913
return identifier.split("|")
1014
.map(str => str.split("!")
1115
.map(str => str.split(" ")
12-
.map(str => path.relative(context, str))
16+
.map(str => looksLikeAbsolutePath(str) ? path.relative(context, str) : str)
1317
.join(" "))
1418
.join("!"))
1519
.join("|");
1620
}
1721

18-
const path = require("path");
19-
2022
class RecordIdsPlugin {
23+
2124
apply(compiler) {
2225
compiler.plugin("compilation", compilation => {
2326
compilation.plugin("record-modules", (modules, records) => {

test/RecordIdsPlugin.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ const webpack = require("../lib/webpack");
77

88
const RecordIdsPlugin = require("../lib/RecordIdsPlugin");
99

10+
const looksLikeAbsolutePath = (maybeAbsolutePath) => /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath);
11+
1012
function makeRelative(compiler, identifier) {
1113
const context = compiler.context;
1214
return identifier.split("|")
1315
.map(str => str.split("!")
1416
.map(str => str.split(" ")
15-
.map(str => path.relative(context, str))
17+
.map(str => looksLikeAbsolutePath(str) ? path.relative(context, str) : str)
1618
.join(" "))
1719
.join("!"))
1820
.join("|");

test/configCases/records/issue-2991/test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ it("should write relative paths to records", function() {
66
var fs = require("fs");
77
var path = require("path");
88
var content = fs.readFileSync(path.join(__dirname, "records.json"), "utf-8");
9-
content.replace(/\\\\/g, "/").should.eql(`{
9+
content.should.eql(`{
1010
"modules": {
1111
"byIdentifier": {
12-
"../../../../external \\"fs\\"": 0,
13-
"../../../../external \\"path\\"": 1,
14-
"../../../../ignored ../test/configCases/records/issue-2991 pkgs/somepackage/foo": 2,
12+
"external \\"fs\\"": 0,
13+
"external \\"path\\"": 1,
14+
"ignored pkgs/somepackage/foo": 2,
1515
"test.js": 3
1616
},
1717
"usedIds": {

0 commit comments

Comments
 (0)