-
-
Notifications
You must be signed in to change notification settings - Fork 364
fix: show version-specific license and highlight license changes #2215
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
Closed
+135
β20
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
90aadf8
fix: show version-specific license, no-deps empty state, layout stabiβ¦
thealxlabs a552f01
fix: resolve type errors and remove unused computed in name.vue
thealxlabs 8fb5c5b
test: add license change detection unit tests and i18n schema entries
thealxlabs 25409b6
[autofix.ci] apply automated fixes
autofix-ci[bot] c5b4cf2
fix: add missing license and dependencies i18n keys and regenerate scβ¦
thealxlabs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| /** | ||
| * Tests for the license change detection logic used in app/pages/package/[[org]]/[name].vue. | ||
| * | ||
| * The `licenseChanged` computed detects when the license of the currently | ||
| * viewed version differs from the package-level (latest) license, so an | ||
| * amber "changed" badge can be shown to alert users. | ||
| */ | ||
|
|
||
| type LicenseValue = string | { type?: string } | undefined | null | ||
|
|
||
| function normalize(l: LicenseValue): string { | ||
| if (!l) return '' | ||
| return typeof l === 'string' ? l : ((l as { type?: string })?.type ?? '') | ||
| } | ||
|
|
||
| function licenseChanged(currentLicense: LicenseValue, packageLicense: LicenseValue): boolean { | ||
| if (!currentLicense || !packageLicense) return false | ||
| return normalize(currentLicense) !== normalize(packageLicense) | ||
| } | ||
|
|
||
| describe('licenseChanged detection', () => { | ||
| it('returns false when both licenses are the same string', () => { | ||
| expect(licenseChanged('MIT', 'MIT')).toBe(false) | ||
| }) | ||
|
|
||
| it('returns true when a non-latest version has a different license', () => { | ||
| // e.g. old version had GPL, latest has MIT | ||
| expect(licenseChanged('GPL-2.0-only', 'MIT')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns false when current license is missing', () => { | ||
| expect(licenseChanged(null, 'MIT')).toBe(false) | ||
| expect(licenseChanged(undefined, 'MIT')).toBe(false) | ||
| }) | ||
|
|
||
| it('returns false when package license is missing', () => { | ||
| expect(licenseChanged('MIT', null)).toBe(false) | ||
| expect(licenseChanged('MIT', undefined)).toBe(false) | ||
| }) | ||
|
|
||
| it('returns false when both licenses are missing', () => { | ||
| expect(licenseChanged(null, null)).toBe(false) | ||
| }) | ||
|
|
||
| it('normalizes object-shaped licenses for comparison', () => { | ||
| // Some old package.json use { type: "MIT" } instead of "MIT" | ||
| expect(licenseChanged({ type: 'MIT' }, 'MIT')).toBe(false) | ||
| expect(licenseChanged('MIT', { type: 'MIT' })).toBe(false) | ||
| expect(licenseChanged({ type: 'GPL-2.0' }, { type: 'MIT' })).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for Apache-2.0 changed to MIT (real-world case)', () => { | ||
| expect(licenseChanged('Apache-2.0', 'MIT')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns false for complex SPDX expression that matches', () => { | ||
| expect(licenseChanged('MIT OR Apache-2.0', 'MIT OR Apache-2.0')).toBe(false) | ||
| }) | ||
| }) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing UI feedback for the modern clipboard path.
When
navigator.clipboard.write()succeeds (Safari path), the function returns without updating thecopiedReadmestate. The user won't see the "Copied" feedback that the legacy path provides viacopyReadme().π Proposed fix
async function copyReadmeHandler() { // Safari requires navigator.clipboard.write() to be called synchronously within // the user gesture, but accepts a Promise inside ClipboardItem. // This pattern works in Safari 13.1+, Chrome, and Firefox. if (typeof ClipboardItem !== 'undefined' && navigator.clipboard?.write) { const blobPromise = (async () => { await fetchReadmeMarkdown() const markdown = readmeMarkdownData.value?.markdown ?? '' return new Blob([markdown], { type: 'text/plain' }) })() try { await navigator.clipboard.write([new ClipboardItem({ 'text/plain': blobPromise })]) + // Manually trigger copied state for UI feedback + await copyReadme(readmeMarkdownData.value?.markdown ?? '') return } catch { // Fall through to legacy approach } } // Legacy fallback (non-Safari, or older browsers) await fetchReadmeMarkdown() const markdown = readmeMarkdownData.value?.markdown if (!markdown) return await copyReadme(markdown) }Alternatively, if calling
copyReadmeagain feels redundant, you could expose thecopiedref setter fromuseClipboardor use a separateshallowRefto track copied state.