-
Notifications
You must be signed in to change notification settings - Fork 0
chore: release 5.1.0 #65
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| import { ui } from '../utils/ui.js'; | ||
| import { colors } from '../utils/styling.js'; | ||
| import { compareSemver } from './version.service.js'; | ||
|
|
||
| export type NoticeLevel = 'deprecation' | 'warn' | 'info' | 'marketing'; | ||
|
|
||
| export interface NoticeMatchRule { | ||
| field: string; | ||
| op: 'present' | 'absent' | 'equals' | 'in' | 'not_in' | 'lt' | 'gt'; | ||
| value?: unknown; | ||
| } | ||
|
|
||
| export interface NoticeMatch { | ||
| rules: NoticeMatchRule[]; | ||
| } | ||
|
|
||
| /** | ||
| * The client-facing notice shape returned by the API (embedded in the | ||
| * compatibility response and from GET /notices). `match` is an optional display | ||
| * gate the CLI evaluates locally against its own context (e.g. the selected iOS | ||
| * version) — the API can't know those at fetch time. | ||
| */ | ||
| export interface Notice { | ||
| id: string; | ||
| slug: string | null; | ||
| level: NoticeLevel; | ||
| title: string; | ||
| body: string; | ||
| learnMoreUrl: string | null; | ||
| dismissible: boolean; | ||
| match: NoticeMatch | null; | ||
| } | ||
|
|
||
| /** Flat key/value context the `match` DSL is evaluated against. */ | ||
| export type NoticeContext = Record<string, unknown>; | ||
|
|
||
| function isPresent(raw: unknown): boolean { | ||
| return raw !== null && raw !== undefined && raw !== false && raw !== ''; | ||
| } | ||
|
|
||
| function ruleMatches(rule: NoticeMatchRule, ctx: NoticeContext): boolean { | ||
| const raw = ctx[rule.field]; | ||
| switch (rule.op) { | ||
| case 'present': | ||
| return isPresent(raw); | ||
| case 'absent': | ||
| return !isPresent(raw); | ||
| case 'equals': | ||
| return isPresent(raw) && String(raw) === String(rule.value); | ||
| case 'in': | ||
| return ( | ||
| isPresent(raw) && | ||
| Array.isArray(rule.value) && | ||
| rule.value.map(String).includes(String(raw)) | ||
| ); | ||
| case 'not_in': | ||
| return ( | ||
| isPresent(raw) && | ||
| Array.isArray(rule.value) && | ||
| !rule.value.map(String).includes(String(raw)) | ||
| ); | ||
| case 'lt': | ||
| return ( | ||
| isPresent(raw) && | ||
| rule.value != null && | ||
| compareSemver(String(raw), String(rule.value)) < 0 | ||
| ); | ||
| case 'gt': | ||
| return ( | ||
| isPresent(raw) && | ||
| rule.value != null && | ||
| compareSemver(String(raw), String(rule.value)) > 0 | ||
| ); | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** A null / empty match imposes no constraint; otherwise every rule must match (AND). */ | ||
| export function matchesRules( | ||
| match: NoticeMatch | null | undefined, | ||
| ctx: NoticeContext, | ||
| ): boolean { | ||
| if (!match || !Array.isArray(match.rules) || match.rules.length === 0) { | ||
| return true; | ||
| } | ||
| return match.rules.every((rule) => ruleMatches(rule, ctx)); | ||
| } | ||
|
|
||
| export interface RenderNoticesOptions { | ||
| /** | ||
| * Emit a line of human output. Notices route through the same gated `out` as | ||
| * the rest of the CLI (suppressed under `--json`); we don't use the `warn` | ||
| * channel because its logger prepends its own `⚠`, which would double up with | ||
| * the symbol the `ui.*` helpers already add. | ||
| */ | ||
| out: (message: string) => void; | ||
| } | ||
|
|
||
| /** Render a single notice with styling appropriate to its level. */ | ||
| function renderNotice(notice: Notice, opts: RenderNoticesOptions): void { | ||
| const rows = [notice.body]; | ||
| if (notice.learnMoreUrl) { | ||
| rows.push(`${colors.dim('See:')} ${colors.url(notice.learnMoreUrl)}`); | ||
| } | ||
|
|
||
| switch (notice.level) { | ||
| case 'deprecation': | ||
| opts.out(ui.deprecation(colors.bold(notice.title))); | ||
| opts.out(ui.branch(rows)); | ||
| break; | ||
| case 'warn': | ||
| opts.out(ui.warn(colors.bold(notice.title))); | ||
| opts.out(ui.branch(rows)); | ||
| break; | ||
| case 'marketing': | ||
| opts.out(ui.section(notice.title)); | ||
| opts.out(ui.branch(rows)); | ||
| break; | ||
| case 'info': | ||
| default: | ||
| opts.out(ui.info(colors.bold(notice.title))); | ||
| opts.out(ui.branch(rows)); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Filter notices by their local-context `match` gate and render those that pass. | ||
| * Returns the visible notices so a `--json` caller can include them in its | ||
| * payload instead of printing. `opts.out` is the caller's `--json`-gated | ||
| * emitter, so under `--json` nothing prints but the list is still returned. | ||
| */ | ||
| export function renderNotices( | ||
| notices: Notice[] | undefined, | ||
| ctx: NoticeContext, | ||
| opts: RenderNoticesOptions, | ||
| ): Notice[] { | ||
| if (!notices || notices.length === 0) return []; | ||
| const visible = notices.filter((n) => matchesRules(n.match, ctx)); | ||
| for (const notice of visible) { | ||
| renderNotice(notice, opts); | ||
| } | ||
| return visible; | ||
| } | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.