refactor: centralize channel ui metadata
This commit is contained in:
28
src/plugins/runtime/native-deps.ts
Normal file
28
src/plugins/runtime/native-deps.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
export type NativeDependencyHintParams = {
|
||||
packageName: string;
|
||||
manager?: "pnpm" | "npm" | "yarn";
|
||||
rebuildCommand?: string;
|
||||
approveBuildsCommand?: string;
|
||||
downloadCommand?: string;
|
||||
};
|
||||
|
||||
export function formatNativeDependencyHint(params: NativeDependencyHintParams): string {
|
||||
const manager = params.manager ?? "pnpm";
|
||||
const rebuildCommand =
|
||||
params.rebuildCommand ??
|
||||
(manager === "npm"
|
||||
? `npm rebuild ${params.packageName}`
|
||||
: manager === "yarn"
|
||||
? `yarn rebuild ${params.packageName}`
|
||||
: `pnpm rebuild ${params.packageName}`);
|
||||
const approveBuildsCommand =
|
||||
params.approveBuildsCommand ??
|
||||
(manager === "pnpm" ? `pnpm approve-builds (select ${params.packageName})` : undefined);
|
||||
const steps = [approveBuildsCommand, rebuildCommand, params.downloadCommand].filter(
|
||||
(step): step is string => Boolean(step),
|
||||
);
|
||||
if (steps.length === 0) {
|
||||
return `Install ${params.packageName} and rebuild its native module.`;
|
||||
}
|
||||
return `Install ${params.packageName} and rebuild its native module (${steps.join("; ")}).`;
|
||||
}
|
||||
Reference in New Issue
Block a user