From 1213f32a426f8bcf1a4902e63ffe227c2b8f103c Mon Sep 17 00:00:00 2001 From: scagood <2230835+scagood@users.noreply.github.com> Date: Fri, 31 May 2024 15:15:38 +0100 Subject: [PATCH] feat!: allow default condition to be anywhere --- lib/util/entrypoints.js | 8 +------- test/exportsField.test.js | 2 +- test/importsField.test.js | 3 +-- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/util/entrypoints.js b/lib/util/entrypoints.js index 392898ce..bba26a62 100644 --- a/lib/util/entrypoints.js +++ b/lib/util/entrypoints.js @@ -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)) { diff --git a/test/exportsField.test.js b/test/exportsField.test.js index 057f55d2..b8a03750 100644 --- a/test/exportsField.test.js +++ b/test/exportsField.test.js @@ -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: [ { ".": { diff --git a/test/importsField.test.js b/test/importsField.test.js index a57055fa..ea6702f6 100644 --- a/test/importsField.test.js +++ b/test/importsField.test.js @@ -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(); });