Skip to content

fix: sort discovered license files for deterministic cross-platform output#743

Open
overbalance wants to merge 1 commit into
TobyAndToby:mainfrom
overbalance:overbalance/case-sensitivity
Open

fix: sort discovered license files for deterministic cross-platform output#743
overbalance wants to merge 1 commit into
TobyAndToby:mainfrom
overbalance:overbalance/case-sensitivity

Conversation

@overbalance

@overbalance overbalance commented Jul 1, 2026

Copy link
Copy Markdown

Problem

licenseFile picks filteredLicenseFiles[0] from glob(...), whose match order is filesystem-dependent. With { nocase: true } the casing differs too: macOS yields license, Linux yields LICENSE. So a dependency shipping multiple matches (e.g. import-in-the-middle ships both LICENSE and LICENSE-3rdparty.csv) can resolve to different license text on macOS vs Linux CI, breaking committed-notices drift checks.

Fix

Sort the matches case-insensitively (locale-independently) before picking. A plain .sort() isn't enough: LICENSE-3rdparty.csv sorts ahead of lowercase license, so macOS would pick the CSV. Lowercasing first puts the base license ahead of variants like license-3rdparty.csv on both platforms.

-  const filteredLicenseFiles = licenseFiles.filter(file => !extensionDenyList.includes(extname(file)));
+  const filteredLicenseFiles = licenseFiles
+    .filter(file => !extensionDenyList.includes(extname(file)))
+    .sort((a, b) => {
+      const lowerA = a.toLowerCase();
+      const lowerB = b.toLowerCase();
+      return lowerA < lowerB ? -1 : lowerA > lowerB ? 1 : 0;
+    });

Test

Simulates both filesystems (glob returning LICENSE and lowercase license, each alongside LICENSE-3rdparty.csv) and asserts both resolve to the real license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant