(spec: string, pkg: PluginPackage)
| 236 | } |
| 237 | |
| 238 | export function readPackageThemes(spec: string, pkg: PluginPackage) { |
| 239 | const field = pkg.json["oc-themes"] |
| 240 | if (field === undefined) return [] |
| 241 | if (!Array.isArray(field)) { |
| 242 | throw new TypeError(`Plugin ${spec} has invalid oc-themes field`) |
| 243 | } |
| 244 | |
| 245 | const list = field.map((item) => { |
| 246 | if (typeof item !== "string") { |
| 247 | throw new TypeError(`Plugin ${spec} has invalid oc-themes entry`) |
| 248 | } |
| 249 | |
| 250 | const raw = item.trim() |
| 251 | if (!raw) { |
| 252 | throw new TypeError(`Plugin ${spec} has empty oc-themes entry`) |
| 253 | } |
| 254 | if (raw.startsWith("file://") || isAbsolutePath(raw)) { |
| 255 | throw new TypeError(`Plugin ${spec} oc-themes entry must be relative: ${item}`) |
| 256 | } |
| 257 | |
| 258 | return resolvePackageFile(spec, raw, "oc-themes", pkg) |
| 259 | }) |
| 260 | |
| 261 | return Array.from(new Set(list)) |
| 262 | } |
| 263 | |
| 264 | export function readPluginId(id: unknown, spec: string) { |
| 265 | if (id === undefined) return |
no test coverage detected