@acryldev/plugin-share 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { type ExtensionInfo } from '@acryldev/extensions';
2
- import { type ReleasePort } from '@acryldev/plugin-hub-core';
2
+ import { type RegistryPort, type ReleasePort } from '@acryldev/plugin-hub-core';
3
3
  import { type Context, Service } from '@deepseek-ai/cordis';
4
4
  import { type NativeAction, type NativePorts } from './native.ts';
5
5
  import { type PublishOptions, type PublishPlan, type PublishPorts, type PublishRefused, type PublishResult } from './publish.ts';
@@ -24,6 +24,10 @@ export interface PluginShareConfig {
24
24
  publish?: PublishPorts;
25
25
  /** How an https address is read: a release `.tgz` and a list of sources. Defaults to HTTPS with the hub's size and time limits. */
26
26
  download?: (url: string) => Promise<Uint8Array>;
27
+ /** Where `registry:<id>` reads the plugin registry's index. Defaults to cordisplugins.github.io. */
28
+ registryIndex?: string;
29
+ /** Where an `npm:` source reads packages. Defaults to the public registry over HTTPS, then the person's own npm (a private scope or registry). */
30
+ npm?: RegistryPort;
27
31
  /** How a plugin's native package is downloaded and unpacked (native.ts). Defaults to the npm registry and the system's tar. */
28
32
  native?: NativePorts;
29
33
  }
@@ -39,6 +43,8 @@ export type PullResult = {
39
43
  readonly state: string;
40
44
  /** Whether the app's `blend.yaml` and lock now name this source, so a copy of the app can fetch it. A local file names nothing to fetch. */
41
45
  readonly remembered: boolean;
46
+ /** The files of an older pulled copy that kept the person's own changes when this release updated it in place. */
47
+ readonly kept?: readonly string[];
42
48
  /** The native package the plugin brought for this computer (native.ts), and what installing it did. */
43
49
  readonly native?: {
44
50
  readonly package: string;
@@ -97,6 +103,8 @@ export declare class PluginShare extends Service {
97
103
  private readonly dir;
98
104
  private readonly releases;
99
105
  private readonly download;
106
+ private readonly registryIndex;
107
+ private readonly npmRegistry;
100
108
  private readonly ports;
101
109
  /** One at a time: two pulls of one name must not race for its folder, nor two publishes for its package. */
102
110
  private queue;
@@ -159,7 +167,24 @@ export declare class PluginShare extends Service {
159
167
  private restore;
160
168
  private get packages();
161
169
  private planNow;
170
+ /**
171
+ * What publishing to npm would do, read without sending anything: the account is the person's own npm login (`npm whoami`), the package is
172
+ * `@<scope>/<name>` (the scope defaults to that account), and a version npm already has makes the plan name the next patch, as a GitHub release does.
173
+ */
174
+ private planNpm;
175
+ /** The plugin as the npm package `packageName`: a package of its own folder, the same bytes whenever it is made again for the same version. */
176
+ private packNpm;
177
+ /** The confirmed npm plan, published with the person's own npm: the package is made again, and only the bytes that were planned are sent. */
178
+ private publishNpm;
179
+ /** A `registry:<id>` source turned into the release it lists, with the integrity the registry lists for it; any other source as it is. */
180
+ private resolveRegistry;
162
181
  private pullNow;
182
+ /**
183
+ * What the folder holds once a newer release of its pulled plugin comes in, the person's own changes kept: the release they pulled is the base of a
184
+ * three-way merge (fetched again from where it came from, checked against its recorded integrity, unless the folder is untouched and is the base).
185
+ * Refused, and nothing written, when the release and the person changed the same lines.
186
+ */
187
+ private planUpdate;
163
188
  /** Put the files in `plugins/<name>/` and install them; whatever does not end running takes its folder with it. */
164
189
  private install;
165
190
  }
@@ -0,0 +1,16 @@
1
+ /** A plugin's files by their `/` path. */
2
+ export type Tree = ReadonlyMap<string, Uint8Array>;
3
+ /** Merge one text file three ways: the merged bytes, or undefined when the two changes overlap. */
4
+ export type MergeFile = (base: Uint8Array, mine: Uint8Array, theirs: Uint8Array) => Uint8Array | undefined;
5
+ export interface MergedTrees {
6
+ /** What the folder holds afterwards. */
7
+ readonly files: ReadonlyMap<string, Uint8Array>;
8
+ /** The files that keep something of the person's own: their edit stands, or it was merged with the release's change. */
9
+ readonly kept: readonly string[];
10
+ /** The files whose changes overlap, or that one side changed and the other removed: nothing is written while there is one. */
11
+ readonly conflicts: readonly string[];
12
+ }
13
+ /** git's own three-way line merge. A binary file, a conflict, or no git on this computer is "cannot merge". */
14
+ export declare const gitMergeFile: MergeFile;
15
+ /** shortcut: a symlink is read as the file it points at and written back as a file; a plugin that is pulled holds none (portability refuses them). */
16
+ export declare function mergeTrees(base: Tree, mine: Tree, theirs: Tree, mergeFile?: MergeFile): MergedTrees;
@@ -0,0 +1,9 @@
1
+ import { type NpmPublishPort } from '@acryldev/plugin-hub-core';
2
+ /** The registry's login and the publish, as the plan and the confirmed publish use them. */
3
+ export interface NpmPort extends NpmPublishPort {
4
+ /** The account the person's npm is signed in as on `registry`. @throws naming `npm login` when it is not signed in. */
5
+ login(registry: string): string;
6
+ }
7
+ /** Why `npm whoami` failed, in words: not signed in (with the command), or what npm said without its pointer to a log file. */
8
+ export declare function whoamiProblem(stderr: string, registry: string): string;
9
+ export declare function npmWithLogin(): NpmPort;
@@ -2,14 +2,17 @@
2
2
  export declare function packageManifest(name: string, description: string, version?: string, release?: PackageRelease): Record<string, unknown>;
3
3
  /** Where a package is going to be released: written in now, so what is planned is byte for byte what is released. */
4
4
  export interface PackageRelease {
5
- readonly owner: string;
6
- readonly repo: string;
5
+ /** The GitHub repository the package is released from; absent for npm. */
6
+ readonly owner?: string;
7
+ readonly repo?: string;
7
8
  readonly license: string;
8
9
  }
9
10
  export interface PackageOptions {
10
11
  /** This version, instead of the one already packaged. */
11
12
  readonly version?: string;
12
13
  readonly release?: PackageRelease;
14
+ /** The name in the package's `package.json` when it is not the plugin's folder name (npm: `@scope/name`). */
15
+ readonly packageName?: string;
13
16
  }
14
17
  export interface PackagedPlugin {
15
18
  readonly dir: string;
@@ -2,8 +2,14 @@
2
2
  * Publishing a plugin: what a person is asked to say yes to, and the comparison that makes the yes mean exactly that. Pure; the service does the I/O.
3
3
  */
4
4
  import type { PublishGitPort, RepositoryHostPort } from '@acryldev/plugin-hub-core';
5
+ import type { NpmPort } from './npm-login.ts';
5
6
  /** Everything that leaves the machine, named before anything does. */
6
7
  export interface PublishPlan {
8
+ /** Where it goes: a GitHub release (absent) or an npm registry. For npm `owner` is the scope and `repo` the plugin's name. */
9
+ readonly target?: 'npm';
10
+ /** npm: the package's name (`@scope/name`) and the registry it is published to. */
11
+ readonly package?: string;
12
+ readonly registry?: string;
7
13
  readonly owner: string;
8
14
  readonly repo: string;
9
15
  readonly version: string;
@@ -40,14 +46,24 @@ export interface PublishOptions {
40
46
  readonly owner?: string;
41
47
  /** The license the plugin is offered under, as an SPDX id; MIT when absent. The plan shows it before the person says yes. */
42
48
  readonly license?: string;
49
+ /** `npm`: publish to an npm registry with the person's own npm login instead of to GitHub. */
50
+ readonly to?: 'npm';
51
+ /** npm: the scope of the package; the account npm is signed in as when absent. */
52
+ readonly scope?: string;
53
+ /** npm: the registry; the public one when absent. */
54
+ readonly registry?: string;
43
55
  }
44
56
  /** Where a publish goes through: the person's own `gh` and `git`. A test passes stand-ins, so no test publishes. */
45
57
  export interface PublishPorts {
46
58
  readonly host: RepositoryHostPort;
47
59
  readonly git: PublishGitPort;
60
+ /** The person's own npm (`npm whoami`, `npm publish`); the default is their installed npm. A test passes a stand-in. */
61
+ readonly npm?: NpmPort;
48
62
  }
49
63
  /** The line a friend copies: it names the bytes, so the check comes for free. */
50
64
  export declare const pullLineOf: (owner: string, repo: string, version: string, digest: string) => string;
65
+ /** The line a friend copies for an npm package. */
66
+ export declare const npmPullLineOf: (name: string, version: string, digest: string) => string;
51
67
  /**
52
68
  * The same plan: what the person confirmed is what would be published now. `released` only explains the version, and is gone once the next one is packaged.
53
69
  * Field by field, so a plan that came back through JSON from another surface (the frame's confirm) is the same plan whatever order its fields arrived in.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `registry:<id>`: a plugin the public registry (cordisplugins.github.io) lists, pulled by the id it shows. The registry only points at a public GitHub
3
+ * release, so the id is turned into the `github:<owner>/<repo>@<version>` source that release has, and the integrity the registry lists is the check the
4
+ * download must pass: a release changed after the registry read it is refused. Pure; the caller fetches the index.
5
+ */
6
+ export declare const REGISTRY_INDEX_URL = "https://cordisplugins.github.io/registry/index.json";
7
+ /** What a pull needs of one registry entry (the rest of the entry is for the page that shows it). */
8
+ export interface RegistryHit {
9
+ /** `github:<owner>/<repo>@<version>`: what another machine fetches, and what the app records. */
10
+ readonly source: string;
11
+ /** The sha512 the registry lists for the release file. */
12
+ readonly integrity: string;
13
+ }
14
+ export type RegistryLookup = {
15
+ readonly ok: true;
16
+ readonly hit: RegistryHit;
17
+ } | {
18
+ readonly ok: false;
19
+ readonly reason: string;
20
+ readonly next: string;
21
+ };
22
+ /** Find `id` (or the package name, `@scope/name`) in the index text; its release as a source, or why there is none. */
23
+ export declare function lookUpRegistry(indexText: string, id: string): RegistryLookup;
package/merge-edits.ts ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * A pulled plugin pulled again at a newer release, with the person's own edits in its folder. Three trees meet: `base` (the release they pulled), `mine` (the
3
+ * folder now) and `theirs` (the new release). A file only one side changed takes that side's change; a file both changed is merged line by line, and the
4
+ * merge is refused when the changes overlap. Pure over bytes, except the line merge, which is git's (`git merge-file`) and is passed in so a test needs no git.
5
+ */
6
+ import { spawnSync } from 'node:child_process'
7
+ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
8
+ import { tmpdir } from 'node:os'
9
+ import { join } from 'node:path'
10
+
11
+ /** A plugin's files by their `/` path. */
12
+ export type Tree = ReadonlyMap<string, Uint8Array>
13
+
14
+ /** Merge one text file three ways: the merged bytes, or undefined when the two changes overlap. */
15
+ export type MergeFile = (
16
+ base: Uint8Array,
17
+ mine: Uint8Array,
18
+ theirs: Uint8Array,
19
+ ) => Uint8Array | undefined
20
+
21
+ export interface MergedTrees {
22
+ /** What the folder holds afterwards. */
23
+ readonly files: ReadonlyMap<string, Uint8Array>
24
+ /** The files that keep something of the person's own: their edit stands, or it was merged with the release's change. */
25
+ readonly kept: readonly string[]
26
+ /** The files whose changes overlap, or that one side changed and the other removed: nothing is written while there is one. */
27
+ readonly conflicts: readonly string[]
28
+ }
29
+
30
+ const same = (a: Uint8Array | undefined, b: Uint8Array | undefined): boolean =>
31
+ a === undefined || b === undefined ? a === b : Buffer.from(a).equals(b)
32
+
33
+ /** git's own three-way line merge. A binary file, a conflict, or no git on this computer is "cannot merge". */
34
+ export const gitMergeFile: MergeFile = (base, mine, theirs) => {
35
+ if ([base, mine, theirs].some((bytes) => bytes.includes(0))) return undefined
36
+ const dir = mkdtempSync(join(tmpdir(), 'plugin-merge-'))
37
+ try {
38
+ const [b, m, t] = ['base', 'mine', 'theirs'].map((name) => join(dir, name)) as [
39
+ string,
40
+ string,
41
+ string,
42
+ ]
43
+ writeFileSync(b, base)
44
+ writeFileSync(m, mine)
45
+ writeFileSync(t, theirs)
46
+ // `-p` prints the result; the status is the number of conflicts (0 = clean), negative on an error.
47
+ const result = spawnSync('git', ['merge-file', '-p', m, b, t], { maxBuffer: 64 * 1024 * 1024 })
48
+ return result.error === undefined && result.status === 0 ? result.stdout : undefined
49
+ } finally {
50
+ rmSync(dir, { recursive: true, force: true })
51
+ }
52
+ }
53
+
54
+ /** shortcut: a symlink is read as the file it points at and written back as a file; a plugin that is pulled holds none (portability refuses them). */
55
+ export function mergeTrees(
56
+ base: Tree,
57
+ mine: Tree,
58
+ theirs: Tree,
59
+ mergeFile: MergeFile = gitMergeFile,
60
+ ): MergedTrees {
61
+ const files = new Map<string, Uint8Array>()
62
+ const kept: string[] = []
63
+ const conflicts: string[] = []
64
+ const paths = [...new Set([...base.keys(), ...mine.keys(), ...theirs.keys()])].sort()
65
+ for (const path of paths) {
66
+ const [b, m, t] = [base.get(path), mine.get(path), theirs.get(path)]
67
+ const put = (bytes: Uint8Array | undefined): void => {
68
+ if (bytes !== undefined) files.set(path, bytes)
69
+ }
70
+ if (same(m, t)) put(m)
71
+ else if (same(m, b)) put(t)
72
+ else if (same(t, b)) {
73
+ put(m)
74
+ kept.push(path)
75
+ } else if (b !== undefined && m !== undefined && t !== undefined) {
76
+ const merged = mergeFile(b, m, t)
77
+ if (merged === undefined) conflicts.push(path)
78
+ else {
79
+ files.set(path, merged)
80
+ kept.push(path)
81
+ }
82
+ } else conflicts.push(path)
83
+ }
84
+ return { files, kept, conflicts }
85
+ }
package/npm-login.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The person's own npm, for a publish: who is signed in (`npm whoami`) and the publish itself, both through the `npm` on this computer and its configuration
3
+ * (`.npmrc`). Nothing here reads or stores a token; a missing npm or login is reported with what to do.
4
+ */
5
+ import { spawnSync } from 'node:child_process'
6
+ import { type NpmPublishPort, npmCli } from '@acryldev/plugin-hub-core'
7
+
8
+ /** The registry's login and the publish, as the plan and the confirmed publish use them. */
9
+ export interface NpmPort extends NpmPublishPort {
10
+ /** The account the person's npm is signed in as on `registry`. @throws naming `npm login` when it is not signed in. */
11
+ login(registry: string): string
12
+ }
13
+
14
+ /** Why `npm whoami` failed, in words: not signed in (with the command), or what npm said without its pointer to a log file. */
15
+ export function whoamiProblem(stderr: string, registry: string): string {
16
+ const said = stderr
17
+ .split('\n')
18
+ .map((line) => line.replace(/^npm error\s*/u, '').trim())
19
+ .filter((line) => line !== '' && !/^npm (notice|warn)|A complete log of this run/iu.test(line))
20
+ const signedOut =
21
+ /ENEEDAUTH|E401|E403|need auth|Unauthorized|not logged in/iu.test(stderr) || said.length === 0
22
+ return signedOut
23
+ ? `npm whoami failed: you are not signed in to npm on ${registry} (sign in with: npm login --registry ${registry})`
24
+ : `npm whoami failed: ${said.slice(0, 2).join(' ')} (sign in with: npm login --registry ${registry})`
25
+ }
26
+
27
+ export function npmWithLogin(): NpmPort {
28
+ return {
29
+ ...npmCli(),
30
+ login(registry) {
31
+ // On Windows npm is a .cmd file, which Node runs only through a shell; the arguments are ours, never the person's text.
32
+ const result = spawnSync('npm', ['whoami', '--registry', registry], {
33
+ encoding: 'utf8',
34
+ shell: process.platform === 'win32',
35
+ env: { ...process.env, npm_config_update_notifier: 'false' },
36
+ })
37
+ if (result.error !== undefined)
38
+ throw new Error(
39
+ 'npm is not available here: install Node.js (https://nodejs.org), which includes npm, and sign in with: npm login',
40
+ )
41
+ const account = (result.stdout ?? '').trim()
42
+ if (result.status !== 0 || account === '') {
43
+ throw new Error(whoamiProblem(result.stderr ?? '', registry))
44
+ }
45
+ return account
46
+ },
47
+ }
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acryldev/plugin-share",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Share plugins between people. Pull one someone released into the running app: fetched without running anything, checked by digest and for every OS, then installed live. Publish one, only as a plan a person confirmed.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/package.ts CHANGED
@@ -30,10 +30,15 @@ export function packageManifest(
30
30
  ? {}
31
31
  : {
32
32
  license: release.license,
33
- repository: {
34
- type: 'git',
35
- url: `git+https://github.com/${release.owner}/${release.repo}.git`,
36
- },
33
+ // An npm package has no repository of its own to name.
34
+ ...(release.owner === undefined || release.repo === undefined
35
+ ? {}
36
+ : {
37
+ repository: {
38
+ type: 'git',
39
+ url: `git+https://github.com/${release.owner}/${release.repo}.git`,
40
+ },
41
+ }),
37
42
  }),
38
43
  type: 'module',
39
44
  exports: { '.': './index.ts', './package.json': './package.json' },
@@ -47,8 +52,9 @@ export function packageManifest(
47
52
 
48
53
  /** Where a package is going to be released: written in now, so what is planned is byte for byte what is released. */
49
54
  export interface PackageRelease {
50
- readonly owner: string
51
- readonly repo: string
55
+ /** The GitHub repository the package is released from; absent for npm. */
56
+ readonly owner?: string
57
+ readonly repo?: string
52
58
  readonly license: string
53
59
  }
54
60
 
@@ -56,6 +62,8 @@ export interface PackageOptions {
56
62
  /** This version, instead of the one already packaged. */
57
63
  readonly version?: string
58
64
  readonly release?: PackageRelease
65
+ /** The name in the package's `package.json` when it is not the plugin's folder name (npm: `@scope/name`). */
66
+ readonly packageName?: string
59
67
  }
60
68
 
61
69
  export interface PackagedPlugin {
@@ -142,7 +150,7 @@ export async function packagePlugin(
142
150
  try {
143
151
  writeFileSync(
144
152
  join(target, 'package.json'),
145
- `${JSON.stringify(packageManifest(name, description, version, options.release), null, 2)}\n`,
153
+ `${JSON.stringify(packageManifest(options.packageName ?? name, description, version, options.release), null, 2)}\n`,
146
154
  )
147
155
  if (!existsSync(join(target, 'README.md'))) {
148
156
  writeFileSync(
package/publish.ts CHANGED
@@ -2,9 +2,15 @@
2
2
  * Publishing a plugin: what a person is asked to say yes to, and the comparison that makes the yes mean exactly that. Pure; the service does the I/O.
3
3
  */
4
4
  import type { PublishGitPort, RepositoryHostPort } from '@acryldev/plugin-hub-core'
5
+ import type { NpmPort } from './npm-login.ts'
5
6
 
6
7
  /** Everything that leaves the machine, named before anything does. */
7
8
  export interface PublishPlan {
9
+ /** Where it goes: a GitHub release (absent) or an npm registry. For npm `owner` is the scope and `repo` the plugin's name. */
10
+ readonly target?: 'npm'
11
+ /** npm: the package's name (`@scope/name`) and the registry it is published to. */
12
+ readonly package?: string
13
+ readonly registry?: string
8
14
  readonly owner: string
9
15
  readonly repo: string
10
16
  readonly version: string
@@ -46,24 +52,39 @@ export interface PublishOptions {
46
52
  readonly owner?: string
47
53
  /** The license the plugin is offered under, as an SPDX id; MIT when absent. The plan shows it before the person says yes. */
48
54
  readonly license?: string
55
+ /** `npm`: publish to an npm registry with the person's own npm login instead of to GitHub. */
56
+ readonly to?: 'npm'
57
+ /** npm: the scope of the package; the account npm is signed in as when absent. */
58
+ readonly scope?: string
59
+ /** npm: the registry; the public one when absent. */
60
+ readonly registry?: string
49
61
  }
50
62
 
51
63
  /** Where a publish goes through: the person's own `gh` and `git`. A test passes stand-ins, so no test publishes. */
52
64
  export interface PublishPorts {
53
65
  readonly host: RepositoryHostPort
54
66
  readonly git: PublishGitPort
67
+ /** The person's own npm (`npm whoami`, `npm publish`); the default is their installed npm. A test passes a stand-in. */
68
+ readonly npm?: NpmPort
55
69
  }
56
70
 
57
71
  /** The line a friend copies: it names the bytes, so the check comes for free. */
58
72
  export const pullLineOf = (owner: string, repo: string, version: string, digest: string): string =>
59
73
  `npm run acryl -- plugin pull github:${owner}/${repo}@${version}@sha256:${digest}`
60
74
 
75
+ /** The line a friend copies for an npm package. */
76
+ export const npmPullLineOf = (name: string, version: string, digest: string): string =>
77
+ `npm run acryl -- plugin pull npm:${name}@${version}@sha256:${digest}`
78
+
61
79
  /**
62
80
  * The same plan: what the person confirmed is what would be published now. `released` only explains the version, and is gone once the next one is packaged.
63
81
  * Field by field, so a plan that came back through JSON from another surface (the frame's confirm) is the same plan whatever order its fields arrived in.
64
82
  */
65
83
  export function samePlan(a: PublishPlan, b: PublishPlan): boolean {
66
84
  return (
85
+ a.target === b.target &&
86
+ a.package === b.package &&
87
+ a.registry === b.registry &&
67
88
  a.owner === b.owner &&
68
89
  a.repo === b.repo &&
69
90
  a.version === b.version &&
@@ -0,0 +1,62 @@
1
+ /**
2
+ * `registry:<id>`: a plugin the public registry (cordisplugins.github.io) lists, pulled by the id it shows. The registry only points at a public GitHub
3
+ * release, so the id is turned into the `github:<owner>/<repo>@<version>` source that release has, and the integrity the registry lists is the check the
4
+ * download must pass: a release changed after the registry read it is refused. Pure; the caller fetches the index.
5
+ */
6
+
7
+ export const REGISTRY_INDEX_URL = 'https://cordisplugins.github.io/registry/index.json'
8
+
9
+ /** What a pull needs of one registry entry (the rest of the entry is for the page that shows it). */
10
+ export interface RegistryHit {
11
+ /** `github:<owner>/<repo>@<version>`: what another machine fetches, and what the app records. */
12
+ readonly source: string
13
+ /** The sha512 the registry lists for the release file. */
14
+ readonly integrity: string
15
+ }
16
+
17
+ export type RegistryLookup =
18
+ | { readonly ok: true; readonly hit: RegistryHit }
19
+ | { readonly ok: false; readonly reason: string; readonly next: string }
20
+
21
+ const GITHUB_REPO =
22
+ /^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*?)(?:\.git)?\/?$/u
23
+
24
+ /** Find `id` (or the package name, `@scope/name`) in the index text; its release as a source, or why there is none. */
25
+ export function lookUpRegistry(indexText: string, id: string): RegistryLookup {
26
+ let entries: unknown
27
+ try {
28
+ entries = (JSON.parse(indexText) as { entries?: unknown }).entries
29
+ } catch {
30
+ entries = undefined
31
+ }
32
+ if (!Array.isArray(entries))
33
+ return {
34
+ ok: false,
35
+ reason: 'the registry answered in a way this app does not understand',
36
+ next: 'try again later, or pull github:<owner>/<repo> from the plugin page',
37
+ }
38
+ const wanted = id.trim().toLowerCase()
39
+ const entry = entries.find(
40
+ (item: { id?: unknown; name?: unknown }) =>
41
+ typeof item?.id === 'string' &&
42
+ (item.id.toLowerCase() === wanted ||
43
+ (typeof item.name === 'string' && item.name.toLowerCase() === wanted)),
44
+ ) as { repo?: unknown; version?: unknown; integrity?: unknown } | undefined
45
+ if (entry === undefined)
46
+ return {
47
+ ok: false,
48
+ reason: `the registry lists no plugin ${id}`,
49
+ next: 'copy the id from https://cordisplugins.github.io, or pull github:<owner>/<repo>',
50
+ }
51
+ const repo = typeof entry.repo === 'string' ? GITHUB_REPO.exec(entry.repo) : null
52
+ if (repo === null || typeof entry.version !== 'string' || typeof entry.integrity !== 'string')
53
+ return {
54
+ ok: false,
55
+ reason: `the registry's entry for ${id} does not name a GitHub release this app can pull`,
56
+ next: 'open its page on https://cordisplugins.github.io for how to install it',
57
+ }
58
+ return {
59
+ ok: true,
60
+ hit: { source: `github:${repo[1]}/${repo[2]}@${entry.version}`, integrity: entry.integrity },
61
+ }
62
+ }