Skip to content

Commit

Permalink
feat!: allow default condition to be anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood committed May 31, 2024
1 parent e389708 commit 1213f32
Show file tree
Hide file tree
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
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion test/exportsField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
".": {
Expand Down
3 changes: 1 addition & 2 deletions test/importsField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 1213f32

Please sign in to comment.