Skip to content

Commit

Permalink
feat: allow default condition to be anywhere
Browse files Browse the repository at this point in the history
alexander-akait authored Jun 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents e389708 + 1213f32 commit 5994a0f
Showing 3 changed files with 3 additions and 10 deletions.
8 changes: 1 addition & 7 deletions lib/util/entrypoints.js
Original file line number Diff line number Diff line change
@@ -464,17 +464,11 @@ function conditionalMapping(conditionalMapping_, conditionNames) {

loop: while (lookup.length > 0) {
const [mapping, conditions, j] = lookup[lookup.length - 1];
const last = conditions.length - 1;

for (let i = j; i < conditions.length; i++) {
const condition = conditions[i];

// assert default. Could be last only
if (i !== last) {
if (condition === "default") {
throw new Error("Default condition should be last one");
}
} else if (condition === "default") {
if (condition === "default") {
const innerMapping = mapping[condition];
// is nested
if (isConditionalMapping(innerMapping)) {
2 changes: 1 addition & 1 deletion test/exportsField.test.js
Original file line number Diff line number Diff line change
@@ -543,7 +543,7 @@ describe("Process exports field", function exportsField() {
},
{
name: "Direct mapping #7",
expect: new Error(), // Default is first one
expect: ["./src/index.js"], // Default is first one
suite: [
{
".": {
3 changes: 1 addition & 2 deletions test/importsField.test.js
Original file line number Diff line number Diff line change
@@ -451,7 +451,7 @@ describe("Process imports field", function exportsField() {
},
{
name: "Direct mapping #7",
expect: new Error(), // Default is first one
expect: ["./src/index.js"], // Default is first one
suite: [
{
"#a": {
@@ -1309,7 +1309,6 @@ describe("ImportsFieldPlugin", () => {
fs.rmdirSync(dir);
if (err) return done(err);
if (!result) return done(new Error("No result"));
console.log(result);
expect(result).toEqual(file);
done();
});

0 comments on commit 5994a0f

Please sign in to comment.