kentcdodds / match-sorter

Simple, expected, and deterministic best-match sorting of an array in JavaScript
https://npm.im/match-sorter
MIT License
3.73k stars 129 forks source link

Defer the assignment of `matchSorter.rankings` #147

Closed mochaaP closed 9 months ago

mochaaP commented 9 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch match-sorter@6.3.2 for the project I'm working on.

Rollup got confused here and rewrote matchSorter to an anonymous function assigning to a variable, making an ReferenceError.

Here is the diff that solved my problem:

diff --git a/node_modules/match-sorter/dist/match-sorter.esm.js b/node_modules/match-sorter/dist/match-sorter.esm.js
index 19a6b97..6dffe8c 100644
--- a/node_modules/match-sorter/dist/match-sorter.esm.js
+++ b/node_modules/match-sorter/dist/match-sorter.esm.js
@@ -11,7 +11,6 @@ var rankings = {
   MATCHES: 1,
   NO_MATCH: 0
 };
-matchSorter.rankings = rankings;
 var defaultBaseSortFn = function defaultBaseSortFn(a, b) {
   return String(a.rankedValue).localeCompare(String(b.rankedValue));
 };
@@ -58,6 +57,7 @@ function matchSorter(items, value, options) {
     return matches;
   }
 }
+matchSorter.rankings = rankings;

 /**
  * Gets the highest ranking for value for the given item based on its values for the given keys

This issue body was partially generated by patch-package.

kentcdodds commented 9 months ago

That change is fine for me. Could you make a PR?

github-actions[bot] commented 9 months ago

:tada: This issue has been resolved in version 6.3.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: