(lookupName: string, allowScopedPackageNames = false)
| 204 | * Verifies that the package contains an "insomnia" attribute. |
| 205 | */ |
| 206 | export async function getPluginInfo(lookupName: string, allowScopedPackageNames = false) { |
| 207 | const validationError = validatePluginName(lookupName, allowScopedPackageNames); |
| 208 | |
| 209 | if (validationError) { |
| 210 | throw new Error(validationError); |
| 211 | } |
| 212 | |
| 213 | console.log('[plugins] Fetching module info from npm'); |
| 214 | |
| 215 | const registryUrl = await getRegistryUrl(); |
| 216 | const stdout = await runYarnCommand(['info', lookupName, '--json', '--registry', registryUrl]); |
| 217 | |
| 218 | let yarnOutput; |
| 219 | try { |
| 220 | yarnOutput = JSON.parse(stdout); |
| 221 | } catch (err) { |
| 222 | throw new Error(`Invalid JSON received from yarn: ${(err as Error).message}`); |
| 223 | } |
| 224 | |
| 225 | const data = yarnOutput.data; |
| 226 | if (!data || typeof data !== 'object') { |
| 227 | throw new Error(`Unexpected yarn output structure`); |
| 228 | } |
| 229 | |
| 230 | if (!data.insomnia) { |
| 231 | throw new Error(`Package "${lookupName}" is not an Insomnia plugin (missing "insomnia" attribute)`); |
| 232 | } |
| 233 | |
| 234 | return { |
| 235 | insomnia: data.insomnia, |
| 236 | name: data.name, |
| 237 | version: data.version, |
| 238 | dist: { |
| 239 | shasum: data.dist.shasum, |
| 240 | tarball: data.dist.tarball, |
| 241 | }, |
| 242 | }; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Installs a plugin into a temporary directory using Yarn. |
no test coverage detected