Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow default condition to be anywhere #423

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading