fix: fallback to LICENSE file when package.json has no license field - #204
Open
clanzhang wants to merge 1 commit into
Open
fix: fallback to LICENSE file when package.json has no license field#204clanzhang wants to merge 1 commit into
clanzhang wants to merge 1 commit into
Conversation
commit: |
clanzhang
force-pushed
the
fix/detect-license-from-file
branch
from
September 11, 2026 09:33
24f6e54 to
184b3f3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some packages like
require-likedon't declare alicensefield in package.json but ship a LICENSE file.Read common license file names and infer the SPDX identifier from well-known license texts.
Closes #145
🔗 Linked issue
#145
🧭 Context
Some older packages like
require-likedon't declare alicensefield intheir
package.json(this was common before npm standardized the field).Instead, they ship a
LICENSEfile with the actual license text.Currently,
normalizePkgLicense()only reads frompackage.json, so thesepackages show up as having no license at all in the inspector.
📚 Description
When
package.jsonhas nolicenseorlicensesfield, fall back toscanning common license file names (
LICENSE,LICENSE.md,LICENCE, etc.)in the package directory and infer the SPDX identifier from well-known
license text patterns.
Changes:
detectLicenseFromFile()inpackage-json.tsthat reads licensefiles and matches text patterns for MIT, ISC, Apache-2.0, BSD-2-Clause,
BSD-3-Clause, and UPL-1.0
resolvePackage()inresolve.tsto call the fallback whennormalizePkgLicense()returnsundefinedNot changed:
registry/resolve.ts) is unaffected — ithas no filesystem access
normalizePkgLicense()itself is untouched; the fallback is only appliedin the filesystem-based
resolvePackage()