Skip to content

Commit c2c0a67

Browse files
authored
feat(init): enforce canonical feature display order (#388)
## Summary Sorts the feature multi-select prompt into a fixed display order instead of relying on whatever the server sends. Also tweaks a couple of feature labels/hints for clarity. **Display order**: Errors → Replay → Tracing → Logs → Metrics → Profiling → Source Maps ## Changes - Add `FEATURE_DISPLAY_ORDER` constant and `sortFeatures()` helper in `clack-utils.ts` - Apply sorting in `handleMultiSelect()` before rendering the prompt - Minor copy tweaks: "Performance Monitoring" → "Performance Monitoring (Tracing)", drop "Automatic" from error monitoring hint ## Test plan - `bun run typecheck` passes - `bun test` passes (no regressions) - Manual: run `bun run dev` against staging API, confirm multi-select shows features in the expected order --------
1 parent 39de00f commit c2c0a67

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

src/lib/init/clack-utils.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export function abortIfCancelled<T>(value: T | symbol): T {
2727
const FEATURE_INFO: Record<string, { label: string; hint: string }> = {
2828
errorMonitoring: {
2929
label: "Error Monitoring",
30-
hint: "Automatic error and crash reporting",
30+
hint: "Error and crash reporting",
3131
},
3232
performanceMonitoring: {
33-
label: "Performance Monitoring",
33+
label: "Performance Monitoring (Tracing)",
3434
hint: "Transaction and span tracing",
3535
},
3636
sessionReplay: {
@@ -57,6 +57,28 @@ export function featureHint(id: string): string | undefined {
5757
return FEATURE_INFO[id]?.hint;
5858
}
5959

60+
const FEATURE_DISPLAY_ORDER = [
61+
"errorMonitoring",
62+
"sessionReplay",
63+
"performanceMonitoring",
64+
"logs",
65+
"metrics",
66+
"profiling",
67+
"sourceMaps",
68+
];
69+
70+
/** Sort features into canonical display order for the multi-select prompt. */
71+
export function sortFeatures(features: string[]): string[] {
72+
return features.slice().sort((a, b) => {
73+
const ai = FEATURE_DISPLAY_ORDER.indexOf(a);
74+
const bi = FEATURE_DISPLAY_ORDER.indexOf(b);
75+
return (
76+
(ai === -1 ? Number.MAX_SAFE_INTEGER : ai) -
77+
(bi === -1 ? Number.MAX_SAFE_INTEGER : bi)
78+
);
79+
});
80+
}
81+
6082
export const STEP_LABELS: Record<string, string> = {
6183
"discover-context": "Analyzing project structure",
6284
"select-target-app": "Selecting target application",

src/lib/init/interactive.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
import { confirm, log, multiselect, select } from "@clack/prompts";
1010
import chalk from "chalk";
11-
import { abortIfCancelled, featureHint, featureLabel } from "./clack-utils.js";
11+
import {
12+
abortIfCancelled,
13+
featureHint,
14+
featureLabel,
15+
sortFeatures,
16+
} from "./clack-utils.js";
1217
import { REQUIRED_FEATURE } from "./constants.js";
1318
import type {
1419
ConfirmPayload,
@@ -90,7 +95,9 @@ async function handleMultiSelect(
9095
return { features: available };
9196
}
9297

93-
const optional = available.filter((f) => f !== REQUIRED_FEATURE);
98+
const optional = sortFeatures(
99+
available.filter((f) => f !== REQUIRED_FEATURE)
100+
);
94101

95102
if (optional.length === 0) {
96103
if (hasRequired) {

test/lib/init/clack-utils.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("featureLabel", () => {
4646
test("returns label for known feature", () => {
4747
expect(featureLabel("errorMonitoring")).toBe("Error Monitoring");
4848
expect(featureLabel("performanceMonitoring")).toBe(
49-
"Performance Monitoring"
49+
"Performance Monitoring (Tracing)"
5050
);
5151
expect(featureLabel("logs")).toBe("Logging");
5252
});
@@ -58,9 +58,7 @@ describe("featureLabel", () => {
5858

5959
describe("featureHint", () => {
6060
test("returns hint for known feature", () => {
61-
expect(featureHint("errorMonitoring")).toBe(
62-
"Automatic error and crash reporting"
63-
);
61+
expect(featureHint("errorMonitoring")).toBe("Error and crash reporting");
6462
expect(featureHint("sessionReplay")).toBe("Visual replay of user sessions");
6563
});
6664

0 commit comments

Comments
 (0)