Skip to content

Commit

Permalink
Merge pull request #340 from webpack/fix/issues-118
Browse files Browse the repository at this point in the history
use only alias field properties
  • Loading branch information
sokra authored Apr 12, 2022
2 parents c960801 + 6460447 commit 23c3e7c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/AliasFieldPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ module.exports = class AliasFieldPlugin {
);
return callback();
}
const data1 = fieldData[innerRequest];
const data2 = fieldData[innerRequest.replace(/^\.\//, "")];
const data = typeof data1 !== "undefined" ? data1 : data2;
const data = Object.prototype.hasOwnProperty.call(
fieldData,
innerRequest
)
? fieldData[innerRequest]
: innerRequest.startsWith("./")
? fieldData[innerRequest.slice(2)]
: undefined;
if (data === innerRequest) return callback();
if (data === undefined) return callback();
if (data === false) {
Expand Down
6 changes: 6 additions & 0 deletions test/browserField.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ describe("browserField", function () {
.resolveSync({}, p(), "./lib/main2.js")
.should.be.eql(p("lib", "browser.js"));
});

it("should check only alias field properties", () => {
resolver
.resolveSync({}, p(), "./toString")
.should.be.eql(p("lib", "toString.js"));
});
});
Empty file.
1 change: 1 addition & 0 deletions test/fixtures/browser-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"./lib/replaced.js": "./lib/browser",
"module-a": "./browser/module-a.js",
"module-b": "module-c",
"./toString": "./lib/toString.js",
".": false
},
"innerBrowser1": {
Expand Down

0 comments on commit 23c3e7c

Please sign in to comment.