-
-
Notifications
You must be signed in to change notification settings - Fork 368
feat: add a warning when the package license changes #2188
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
Open
aisiklar
wants to merge
8
commits into
npmx-dev:main
Choose a base branch
from
aisiklar:feature/1826_license_changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3a0543f
1826-add a warning and info for license changes. Added support for TR…
aisiklar bfd9550
[autofix.ci] apply automated fixes
autofix-ci[bot] fa52bff
fix:warning style changed and unintended chars erased
aisiklar bd4ebe5
[autofix.ci] apply automated fixes
autofix-ci[bot] 9afe21d
fix:added TR language support for warning text and changed logic for …
aisiklar ecbb660
[autofix.ci] apply automated fixes
autofix-ci[bot] b91aab5
fix: removed the vue-118n import and used autoimported
aisiklar 34b84c5
Merge branch 'main' into feature/1826_license_changes
ghostdevv 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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| import type { MaybeRefOrGetter } from 'vue' | ||||||||||||||||||||||||||||||||||||||||||||
| import { toValue } from 'vue' | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export interface LicenseChange { | ||||||||||||||||||||||||||||||||||||||||||||
| from: string | ||||||||||||||||||||||||||||||||||||||||||||
| to: string | ||||||||||||||||||||||||||||||||||||||||||||
| version: string | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export interface LicenseChangesResult { | ||||||||||||||||||||||||||||||||||||||||||||
| changes: LicenseChange[] | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Type definitions for npm registry response | ||||||||||||||||||||||||||||||||||||||||||||
| interface NpmRegistryVersion { | ||||||||||||||||||||||||||||||||||||||||||||
| version: string | ||||||||||||||||||||||||||||||||||||||||||||
| license?: string | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // for registry responses of $fetch function, the type includes the key versions as well as many others too. | ||||||||||||||||||||||||||||||||||||||||||||
| interface NpmRegistryResponse { | ||||||||||||||||||||||||||||||||||||||||||||
| time: Record<string, string> | ||||||||||||||||||||||||||||||||||||||||||||
| versions: Record<string, NpmRegistryVersion> | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * Composable to detect license changes across all versions of a package | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| export function useLicenseChanges(packageName: MaybeRefOrGetter<string | null | undefined>) { | ||||||||||||||||||||||||||||||||||||||||||||
| return useAsyncData<LicenseChangesResult>( | ||||||||||||||||||||||||||||||||||||||||||||
| () => `license-changes:${toValue(packageName)}`, | ||||||||||||||||||||||||||||||||||||||||||||
| async () => { | ||||||||||||||||||||||||||||||||||||||||||||
| const name = toValue(packageName) | ||||||||||||||||||||||||||||||||||||||||||||
| if (!name) return { changes: [] } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Fetch full package metadata from npm registry | ||||||||||||||||||||||||||||||||||||||||||||
| const url = `https://registry.npmjs.org/${name}` | ||||||||||||||||||||||||||||||||||||||||||||
| const data = await $fetch<NpmRegistryResponse>(url) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const changes: LicenseChange[] = [] | ||||||||||||||||||||||||||||||||||||||||||||
| let prevLicense: string | undefined = undefined | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // `data.versions` is an object with version keys | ||||||||||||||||||||||||||||||||||||||||||||
| const versions = Object.values(data.versions) as NpmRegistryVersion[] | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should only compare to the last version, there is some logic here that could be reused (you can move it into its own utility file in shared too npmx.dev/app/composables/useInstallSizeDiff.ts Lines 19 to 39 in 1dd1be9
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Sort versions ascending to compare chronologically | ||||||||||||||||||||||||||||||||||||||||||||
| versions.sort((a, b) => { | ||||||||||||||||||||||||||||||||||||||||||||
| const dateA = new Date(data.time[a.version] as string).getTime() | ||||||||||||||||||||||||||||||||||||||||||||
| const dateB = new Date(data.time[b.version] as string).getTime() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Ascending order (oldest to newest) | ||||||||||||||||||||||||||||||||||||||||||||
| return dateA - dateB | ||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Detect license changes | ||||||||||||||||||||||||||||||||||||||||||||
| for (const version of versions) { | ||||||||||||||||||||||||||||||||||||||||||||
| const license = (version.license as string) ?? 'UNKNOWN' | ||||||||||||||||||||||||||||||||||||||||||||
| if (prevLicense && license !== prevLicense) { | ||||||||||||||||||||||||||||||||||||||||||||
| changes.push({ | ||||||||||||||||||||||||||||||||||||||||||||
| from: prevLicense, | ||||||||||||||||||||||||||||||||||||||||||||
| to: license, | ||||||||||||||||||||||||||||||||||||||||||||
| version: version.version as string, | ||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| prevLicense = license | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| return { changes } | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| default: () => ({ changes: [] }), | ||||||||||||||||||||||||||||||||||||||||||||
| watch: [() => toValue(packageName)], | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
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
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.
Hey, the warning should be here like the package size increase one