( state: RuntimeState | undefined, raw: string, global = false, )
| 889 | } |
| 890 | |
| 891 | async function installPluginBySpec( |
| 892 | state: RuntimeState | undefined, |
| 893 | raw: string, |
| 894 | global = false, |
| 895 | ): Promise<TuiPluginInstallResult> { |
| 896 | if (!state) { |
| 897 | return { |
| 898 | ok: false, |
| 899 | message: "Plugin runtime is not ready.", |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | const spec = raw.trim() |
| 904 | if (!spec) { |
| 905 | return { |
| 906 | ok: false, |
| 907 | message: "Plugin package name is required", |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | const dir = state.api.state.path |
| 912 | if (!dir.directory) { |
| 913 | return { |
| 914 | ok: false, |
| 915 | message: "Paths are still syncing. Try again in a moment.", |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | const install = await installModulePlugin(spec) |
| 920 | if (!install.ok) { |
| 921 | const out = installDetail(install.error) |
| 922 | return { |
| 923 | ok: false, |
| 924 | message: out.message, |
| 925 | missing: out.missing, |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | const manifest = await readPluginManifest(install.target) |
| 930 | if (!manifest.ok) { |
| 931 | if (manifest.code === "manifest_no_targets") { |
| 932 | return { |
| 933 | ok: false, |
| 934 | message: `"${spec}" does not expose plugin entrypoints or oc-themes in package.json`, |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | return { |
| 939 | ok: false, |
| 940 | message: `Installed "${spec}" but failed to read ${manifest.file}`, |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | const patch = await patchPluginConfig({ |
| 945 | spec, |
| 946 | targets: manifest.targets, |
| 947 | global, |
| 948 | vcs: dir.worktree && dir.worktree !== "/" ? "git" : undefined, |
no test coverage detected