@theholocron/holocron-plugin-fern 5.0.0-alpha.59 → 5.0.0-alpha.590

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.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <!-- alex disable host-hostess -->
2
+
1
3
  <!-- editorconfig-checker-disable-file -->
2
4
 
3
5
  # `@theholocron/holocron-plugin-fern`
@@ -83,7 +85,7 @@ running `holocron setup`.
83
85
 
84
86
  ## CI secrets
85
87
 
86
- Add `HOLOCRON_FERN_TOKEN` to your repo's GitHub Secrets. The `wiki.yml` thin caller
88
+ Add `HOLOCRON_FERN_TOKEN` to your repo's GitHub Secrets. The `publish-wiki` thin caller
87
89
  passes it to the Fern CLI during `fern generate --docs`.
88
90
 
89
91
  | Secret | Purpose |
package/dist/index.d.mts CHANGED
@@ -1,10 +1,26 @@
1
- import { AuthError, DnsRecordRequest, ResolveTokenInput, Wiki, WikiProvisionOpts, WikiProxyConfig } from "@theholocron/cli";
2
- //#region src/capabilities/wiki.d.ts
3
- declare const FERN_VERSION = "5.114.1";
4
- interface FernWikiOptions {
1
+ /**
2
+ * `@theholocron/holocron-plugin-fern` — entrypoint.
3
+ *
4
+ * Implements the `wiki` capability using Fern (buildwithfern.com).
5
+ * `holocron setup` loads this plugin when `providers.wiki: "fern"` is
6
+ * declared in `holocron.config.ts` and calls `wiki.provision()` to write
7
+ * `fern/fern.config.json` and a `fern/docs.yml` scaffold.
8
+ *
9
+ * The Fern CLI token (`FERN_TOKEN`) is only required in CI (via the
10
+ * `wiki.yml` reusable workflow) — local setup writes config files only.
11
+ */
12
+ import { AuthError, DnsRecordRequest, PluginToken, ResolveTokenInput, Wiki, WikiInspection, WikiProvisionOpts, WikiProxyConfig } from "@theholocron/cli";
13
+ /** Resolves the Fern token from `--token`, `HOLOCRON_FERN_TOKEN`, `FERN_TOKEN` or the keyring entry for `fern`, and throws `AuthError` when none is set. */
14
+ export declare const resolveToken: import("@theholocron/cli").TokenResolver;
15
+ /** Every token this plugin takes, for `holocron doctor secrets --verify`, with the layers that hold it. */
16
+ export declare const tokens: PluginToken[];
17
+ /** The Fern CLI version written into `fern/fern.config.json`. */
18
+ export declare const FERN_VERSION = "5.114.1";
19
+ /** Options for the Fern `wiki` capability. */
20
+ interface FernWikiOptions extends ResolveTokenInput {
5
21
  /** Absolute path to the working repo root. Injected by the loader from RuntimeContext. */
6
22
  repoRoot?: string;
7
- /** Active org name (e.g. "theholocron"). Injected by the loader from RuntimeContext. */
23
+ /** Active org name (e.g. "acme"). Injected by the loader from RuntimeContext. */
8
24
  org?: string;
9
25
  /**
10
26
  * "owner/name" repo coordinate. Injected by the loader from RuntimeContext.
@@ -12,15 +28,15 @@ interface FernWikiOptions {
12
28
  */
13
29
  repo?: string;
14
30
  /**
15
- * Base domain for the Fern docs site (e.g. "wiki.theholocron.dev").
31
+ * Base domain for the Fern docs site (e.g. "wiki.example.dev").
16
32
  *
17
33
  * When provided without a path, the repo name is appended automatically:
18
- * domain "wiki.theholocron.dev" + repo "owner/holocron"
19
- * → custom-domain: wiki.theholocron.dev/holocron
34
+ * domain "wiki.example.dev" + repo "owner/holocron"
35
+ * → custom-domain: wiki.example.dev/holocron
20
36
  * → multi-source: true
21
37
  *
22
38
  * You can also supply the full path explicitly:
23
- * domain "wiki.theholocron.dev/holocron"
39
+ * domain "wiki.example.dev/holocron"
24
40
  *
25
41
  * Note: password protection is configured in the Fern Dashboard
26
42
  * (https://dashboard.buildwithfern.com) — it is not configurable via docs.yml.
@@ -30,7 +46,7 @@ interface FernWikiOptions {
30
46
  * Fern workspace org slug. Defaults to `org` (the GitHub org name).
31
47
  * Set this explicitly when the Fern workspace name differs from the
32
48
  * GitHub org — e.g. the workspace was registered as "holocron" while
33
- * the GitHub org is "theholocron".
49
+ * the GitHub org is "acme".
34
50
  */
35
51
  fernOrg?: string;
36
52
  /**
@@ -45,27 +61,62 @@ interface FernWikiOptions {
45
61
  */
46
62
  icon?: string;
47
63
  }
48
- declare class FernWiki implements Wiki {
64
+ /** `wiki` capability for Fern: writes the Fern config and docs scaffold for a repo. */
65
+ export declare class FernWiki implements Wiki {
49
66
  private readonly opts;
67
+ private readonly deps;
68
+ /** Capability key; always `"wiki"`. */
50
69
  readonly key: "wiki";
70
+ /** Provider name; always `"fern"`. */
51
71
  readonly providerName = "fern";
52
- constructor(opts: FernWikiOptions);
72
+ constructor(opts: FernWikiOptions, deps?: {
73
+ fetch?: typeof fetch;
74
+ });
75
+ /**
76
+ * Reads `fern/` and `docs/wiki` and asks the public site, sending no token (see `inspectWiki`). The instance and
77
+ * domain it expects are the ones `provision()` writes.
78
+ */
79
+ inspect(): Promise<WikiInspection>;
53
80
  provision(callOpts?: WikiProvisionOpts): Promise<string>;
54
81
  proxyConfig(): WikiProxyConfig | null;
82
+ /**
83
+ * Confirms `HOLOCRON_FERN_TOKEN`/`FERN_TOKEN` resolves, or a Fern token
84
+ * is stored in the keyring — not a live check. Fern exposes no
85
+ * lightweight endpoint to verify a token actually works (the only
86
+ * token-consuming operation is a full `fern generate`, see
87
+ * holocron#1079); this only confirms one is configured, the same way
88
+ * CI's `fern generate --docs` step would find it.
89
+ *
90
+ * Deliberately ignores `cliToken` (`--token`): CI's step only ever sees
91
+ * the env var from a GitHub Actions secret, never a CLI flag — and a
92
+ * bare `--token <value>` meant for some OTHER provider is forwarded to
93
+ * every loaded plugin as a fallback (see AGENTS.md), so honoring it
94
+ * here would report "configured" even when no Fern-specific credential
95
+ * exists anywhere CI would actually look.
96
+ *
97
+ * Only `AuthError` (the specific "no token found" signal) is treated as
98
+ * `ok: false` — any other error (e.g. a real keyring failure) is a
99
+ * genuine problem and must surface as a failure, not get misreported as
100
+ * a missing token.
101
+ */
102
+ whoami(): Promise<{
103
+ ok: boolean;
104
+ }>;
55
105
  dnsRecord(): DnsRecordRequest | null;
56
106
  }
57
- //#endregion
58
- //#region src/auth.d.ts
59
- declare const resolveToken: (input?: ResolveTokenInput) => string;
60
- //#endregion
61
- //#region src/index.d.ts
62
- type FernPluginOptions = FernWikiOptions;
63
- declare function wiki(opts: FernPluginOptions): Wiki;
64
- declare function createPlugin(options?: FernPluginOptions): {
107
+ /** Options for the Fern plugin; the same as the `wiki` capability's. */
108
+ export type FernPluginOptions = FernWikiOptions;
109
+ /** Builds the `wiki` capability from the plugin options. */
110
+ export declare function wiki(opts: FernPluginOptions): Wiki;
111
+ /** Creates the Fern plugin: its `connection` and `token` probes and the `wiki` capability. */
112
+ export declare function createPlugin(options?: FernPluginOptions): {
65
113
  name: string;
114
+ probes: {
115
+ connection: import("@theholocron/cli").Probe;
116
+ token: import("@theholocron/cli").Probe;
117
+ };
66
118
  capabilities: {
67
119
  wiki: () => Wiki;
68
120
  };
69
121
  };
70
- //#endregion
71
- export { AuthError, FERN_VERSION, FernPluginOptions, FernWiki, type FernWikiOptions, type ResolveTokenInput, createPlugin, resolveToken, wiki };
122
+ export { AuthError, type FernWikiOptions, type ResolveTokenInput };
package/dist/index.mjs CHANGED
@@ -1,14 +1,172 @@
1
- import { mkdir, readFile, writeFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
- import { AuthError, createResolveToken } from "@theholocron/cli";
4
- //#region src/capabilities/wiki.ts
1
+ import { AuthError, connectionProbe, createResolveToken, tokenExpectations } from "@theholocron/cli";
2
+ import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
3
+ import { join, relative, resolve } from "node:path";
4
+ import { stringifyJson } from "@theholocron/json-utils";
5
+ // src/probes/token/expectations.ts
6
+ /**
7
+ * Where the Fern token is held: CI only (the `publish-wiki` workflow), so `ci` is the one layer declared. Fern has no
8
+ * endpoint that reports a token's permissions, so none are declared and the probe says so instead of guessing. This is
9
+ * the plugin's `tokens` declaration, read through `tokenExpectations()`; change it and the Fern note in
10
+ * `docs/src/content/docs/tokens.mdx` together.
11
+ */
12
+ const EXPECTED = { layers: ["ci"] };
13
+ // src/auth.ts
14
+ /** Resolves the Fern token from `--token`, `HOLOCRON_FERN_TOKEN`, `FERN_TOKEN` or the keyring entry for `fern`, and throws `AuthError` when none is set. */
15
+ const resolveToken = createResolveToken({
16
+ envName: "HOLOCRON_FERN_TOKEN",
17
+ vendorEnvName: "FERN_TOKEN",
18
+ keyringService: "fern",
19
+ errorMessage: "no Fern token found. Set HOLOCRON_FERN_TOKEN / FERN_TOKEN, or run: holocron new token fern <token>"
20
+ });
21
+ /** Every token this plugin takes, for `holocron doctor secrets --verify`, with the layers that hold it. */
22
+ const tokens = [{
23
+ ...resolveToken.token,
24
+ expect: EXPECTED
25
+ }];
26
+ // src/capabilities/inspect-wiki.ts
27
+ /** How long to wait for the site before calling it unreachable. */
28
+ const SITE_TIMEOUT_MS = 8e3;
29
+ async function readText(path) {
30
+ try {
31
+ return await readFile(path, "utf8");
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+ /** The value of `key:` inside the `instances:` block, without quotes. */
37
+ function instanceValue(docs, key) {
38
+ const value = (docs.match(/^instances:(?:\n[ \t][^\n]*)*/m)?.[0])?.match(new RegExp(`^[ \\t-]*${key}:[ \\t]*(\\S+)`, "m"))?.[1];
39
+ return value ? value.replace(/^["']|["']$/g, "") : null;
40
+ }
41
+ /** Every Markdown file below `dir`, as a path relative to `root`; an absent directory is an empty list. */
42
+ async function markdownBelow(root, dir) {
43
+ let entries;
44
+ try {
45
+ entries = await readdir(dir, { withFileTypes: true });
46
+ } catch {
47
+ return [];
48
+ }
49
+ const found = [];
50
+ for (const entry of entries) {
51
+ const path = join(dir, entry.name);
52
+ if (entry.isDirectory()) found.push(...await markdownBelow(root, path));
53
+ else if (entry.name.endsWith(".md") || entry.name.endsWith(".mdx")) found.push(relative(root, path));
54
+ }
55
+ return found.sort();
56
+ }
57
+ /** One GET, reduced to a status or a reason. The body is read only when `keep` is set, and only on success. */
58
+ async function ask(url, doFetch, keep = false) {
59
+ try {
60
+ const response = await doFetch(`https://${url}`, {
61
+ redirect: "follow",
62
+ signal: AbortSignal.timeout(SITE_TIMEOUT_MS)
63
+ });
64
+ const text = keep && response.ok ? await response.text() : void 0;
65
+ if (text === void 0) await response.body?.cancel();
66
+ return {
67
+ probe: {
68
+ url,
69
+ status: response.status
70
+ },
71
+ ...text === void 0 ? {} : { text }
72
+ };
73
+ } catch (err) {
74
+ return { probe: {
75
+ url,
76
+ error: err instanceof Error && err.name === "TimeoutError" ? `no answer within ${SITE_TIMEOUT_MS / 1e3}s` : "could not be reached"
77
+ } };
78
+ }
79
+ }
80
+ /**
81
+ * Read the Fern wiki without changing anything: `fern/fern.config.json` and the `instances:` block of `fern/docs.yml`
82
+ * against what the config declares, the navigation's `path:` entries against the files under `docs/wiki`, and one GET
83
+ * each for the instance address, the custom domain and the sitemap. No token is sent; the sitemap's body is counted
84
+ * and dropped.
85
+ */
86
+ async function inspectWiki(input) {
87
+ const doFetch = input.fetch ?? fetch;
88
+ const fernDir = join(input.repoRoot, "fern");
89
+ const configText = await readText(join(fernDir, "fern.config.json"));
90
+ let found;
91
+ try {
92
+ const organization = (configText === null ? null : JSON.parse(configText))?.organization;
93
+ found = typeof organization === "string" ? organization : null;
94
+ } catch {
95
+ found = null;
96
+ }
97
+ const docs = await readText(join(fernDir, "docs.yml"));
98
+ const instance = docs === null ? null : {
99
+ expectedUrl: input.expectedUrl,
100
+ foundUrl: instanceValue(docs, "url"),
101
+ ...input.expectedDomain ? {
102
+ expectedDomain: input.expectedDomain,
103
+ foundDomain: instanceValue(docs, "custom-domain")
104
+ } : {}
105
+ };
106
+ let navigation = null;
107
+ if (docs !== null) {
108
+ const listed = new Set([...docs.matchAll(/^[ \t-]*path:[ \t]*(\S+)/gm)].map((m) => relative(input.repoRoot, resolve(fernDir, m[1].replace(/^["']|["']$/g, "")))));
109
+ const missing = [];
110
+ for (const path of listed) if (await readText(join(input.repoRoot, path)) === null) missing.push(path);
111
+ const onDisk = await markdownBelow(input.repoRoot, join(input.repoRoot, "docs", "wiki"));
112
+ navigation = {
113
+ listed: listed.size,
114
+ missing,
115
+ unlisted: onDisk.filter((p) => !listed.has(p))
116
+ };
117
+ }
118
+ const site = [(await ask(input.expectedUrl, doFetch)).probe];
119
+ if (input.expectedDomain) site.push((await ask(input.expectedDomain, doFetch)).probe);
120
+ const sitemap = await ask(`${(input.expectedDomain ?? input.expectedUrl).replace(/\/$/, "")}/sitemap.xml`, doFetch, true);
121
+ const published = {
122
+ ...sitemap.probe,
123
+ ...sitemap.text === void 0 ? {} : { pages: (sitemap.text.match(/<loc>/g) ?? []).length }
124
+ };
125
+ return {
126
+ organization: {
127
+ declared: input.fernOrg,
128
+ found
129
+ },
130
+ instance,
131
+ site,
132
+ navigation,
133
+ published
134
+ };
135
+ }
136
+ // src/capabilities/wiki.ts
137
+ /** The Fern CLI version written into `fern/fern.config.json`. */
5
138
  const FERN_VERSION = "5.114.1";
139
+ /** `wiki` capability for Fern: writes the Fern config and docs scaffold for a repo. */
6
140
  var FernWiki = class {
7
141
  opts;
142
+ deps;
143
+ /** Capability key; always `"wiki"`. */
8
144
  key = "wiki";
145
+ /** Provider name; always `"fern"`. */
9
146
  providerName = "fern";
10
- constructor(opts) {
147
+ constructor(opts, deps = {}) {
11
148
  this.opts = opts;
149
+ this.deps = deps;
150
+ }
151
+ /**
152
+ * Reads `fern/` and `docs/wiki` and asks the public site, sending no token (see `inspectWiki`). The instance and
153
+ * domain it expects are the ones `provision()` writes.
154
+ */
155
+ async inspect() {
156
+ const { org, repo, domain, fernOrg } = this.opts;
157
+ const resolvedFernOrg = fernOrg ?? org ?? "holocron";
158
+ const { instanceUrl, customDomain } = expectedInstance({
159
+ fernOrg: resolvedFernOrg,
160
+ repoName: repo?.split("/").pop(),
161
+ domain
162
+ });
163
+ return inspectWiki({
164
+ repoRoot: this.opts.repoRoot ?? process.cwd(),
165
+ fernOrg: resolvedFernOrg,
166
+ expectedUrl: instanceUrl,
167
+ ...customDomain ? { expectedDomain: customDomain } : {},
168
+ ...this.deps.fetch ? { fetch: this.deps.fetch } : {}
169
+ });
12
170
  }
13
171
  async provision(callOpts) {
14
172
  const repoRoot = this.opts.repoRoot ?? process.cwd();
@@ -33,6 +191,38 @@ var FernWiki = class {
33
191
  headers: { "X-Fern-Host": this.opts.domain.split("/")[0] }
34
192
  };
35
193
  }
194
+ /**
195
+ * Confirms `HOLOCRON_FERN_TOKEN`/`FERN_TOKEN` resolves, or a Fern token
196
+ * is stored in the keyring — not a live check. Fern exposes no
197
+ * lightweight endpoint to verify a token actually works (the only
198
+ * token-consuming operation is a full `fern generate`, see
199
+ * holocron#1079); this only confirms one is configured, the same way
200
+ * CI's `fern generate --docs` step would find it.
201
+ *
202
+ * Deliberately ignores `cliToken` (`--token`): CI's step only ever sees
203
+ * the env var from a GitHub Actions secret, never a CLI flag — and a
204
+ * bare `--token <value>` meant for some OTHER provider is forwarded to
205
+ * every loaded plugin as a fallback (see AGENTS.md), so honoring it
206
+ * here would report "configured" even when no Fern-specific credential
207
+ * exists anywhere CI would actually look.
208
+ *
209
+ * Only `AuthError` (the specific "no token found" signal) is treated as
210
+ * `ok: false` — any other error (e.g. a real keyring failure) is a
211
+ * genuine problem and must surface as a failure, not get misreported as
212
+ * a missing token.
213
+ */
214
+ async whoami() {
215
+ try {
216
+ resolveToken({
217
+ ...this.opts,
218
+ cliToken: void 0
219
+ });
220
+ return { ok: true };
221
+ } catch (err) {
222
+ if (err instanceof AuthError) return { ok: false };
223
+ throw err;
224
+ }
225
+ }
36
226
  dnsRecord() {
37
227
  const { org, domain, fernOrg } = this.opts;
38
228
  if (!domain) return null;
@@ -52,10 +242,10 @@ async function writeFernConfig({ repoRoot, fernOrg }) {
52
242
  const fernDir = join(repoRoot, "fern");
53
243
  await mkdir(fernDir, { recursive: true });
54
244
  const org = fernOrg ?? "holocron";
55
- const content = JSON.stringify({
245
+ const content = stringifyJson({
56
246
  organization: org,
57
247
  version: FERN_VERSION
58
- }, null, 2) + "\n";
248
+ });
59
249
  await writeFile(join(fernDir, "fern.config.json"), content, "utf8");
60
250
  return `fern.config.json: org=${org}, version=${FERN_VERSION}`;
61
251
  }
@@ -65,24 +255,11 @@ async function writeFernDocsYml({ repoRoot, fernOrg, repo, name, domain }) {
65
255
  const docsPath = join(fernDir, "docs.yml");
66
256
  const resolvedFernOrg = fernOrg ?? "holocron";
67
257
  const repoName = repo?.split("/").pop();
68
- let instanceUrl;
69
- let customDomain;
70
- let multiSource = false;
71
- if (domain) {
72
- const slashIdx = domain.indexOf("/");
73
- if (slashIdx !== -1) {
74
- instanceUrl = `${resolvedFernOrg}.docs.buildwithfern.com/${domain.slice(slashIdx + 1)}`;
75
- customDomain = domain;
76
- multiSource = true;
77
- } else if (repoName) {
78
- instanceUrl = `${resolvedFernOrg}.docs.buildwithfern.com/${repoName}`;
79
- customDomain = `${domain}/${repoName}`;
80
- multiSource = true;
81
- } else {
82
- instanceUrl = `${resolvedFernOrg}.docs.buildwithfern.com`;
83
- customDomain = domain;
84
- }
85
- } else instanceUrl = `${resolvedFernOrg}.docs.buildwithfern.com`;
258
+ const { instanceUrl, customDomain, multiSource } = expectedInstance({
259
+ fernOrg: resolvedFernOrg,
260
+ repoName,
261
+ domain
262
+ });
86
263
  const repoOwner = repo?.split("/")[0];
87
264
  let existing = null;
88
265
  try {
@@ -92,8 +269,7 @@ async function writeFernDocsYml({ repoRoot, fernOrg, repo, name, domain }) {
92
269
  const updated = updateInstancesBlock(existing, instanceUrl, customDomain, multiSource, repoOwner, repoName);
93
270
  if (updated !== existing) {
94
271
  await writeFile(docsPath, updated, "utf8");
95
- const domainPart = customDomain ? `, domain=${customDomain}${multiSource ? " (multi-source)" : ""}` : "";
96
- return `docs.yml: updated instances (url=${instanceUrl}${domainPart})`;
272
+ return `docs.yml: updated instances (url=${instanceUrl}${customDomain ? `, domain=${customDomain}${multiSource ? " (multi-source)" : ""}` : ""})`;
97
273
  }
98
274
  return "docs.yml: instances block already up to date";
99
275
  }
@@ -107,8 +283,35 @@ async function writeFernDocsYml({ repoRoot, fernOrg, repo, name, domain }) {
107
283
  if (multiSource) lines.push(` multi-source: true`);
108
284
  lines.push(``, `title: ${name ?? resolvedFernOrg} Engineering`, ``, `layout:`, ` page-width: full`, ` tabs-placement: header`, ` searchbar-placement: header`, ``, `tabs:`, ` decisions:`, ` display-name: Decisions`, ` icon: fa-duotone fa-scale-balanced`, ` standards:`, ` display-name: Standards`, ` icon: fa-duotone fa-book`, ` specifications:`, ` display-name: Specifications`, ` icon: fa-duotone fa-file-lines`, ``, `navigation:`, ` - tab: decisions`, ` layout:`, ` - section: Architecture Decision Records`, ` contents:`, ` - page: Index`, ` path: ../docs/wiki/decisions/README.md`, ` - tab: standards`, ` layout:`, ` - section: Standards`, ` contents:`, ` - page: Overview`, ` path: ../docs/wiki/standards/README.md`, ` - tab: specifications`, ` layout:`, ` - section: Specifications`, ` contents:`, ` - page: Overview`, ` path: ../docs/wiki/specifications/README.md`, ``, `colors:`, ` accent-primary:`, ` dark: "#70E155"`, ` light: "#008700"`, ``, `logo:`, ` height: 20`, ``, `metadata:`, ` og:dynamic: true`, ``);
109
285
  await writeFile(docsPath, lines.join("\n"), "utf8");
110
- const domainSummary = customDomain ? `, domain=${customDomain}${multiSource ? " (multi-source)" : ""}` : "";
111
- return `docs.yml: url=${instanceUrl}${domainSummary}`;
286
+ return `docs.yml: url=${instanceUrl}${customDomain ? `, domain=${customDomain}${multiSource ? " (multi-source)" : ""}` : ""}`;
287
+ }
288
+ /**
289
+ * The Fern instance URL and custom domain a docs site is declared with, and whether it is multi-source. A domain with
290
+ * no path gets the repo name as its basepath so every repo in the org shares one domain; Fern needs the instance URL
291
+ * to carry the same basepath when `multi-source` is on.
292
+ */
293
+ function expectedInstance({ fernOrg, repoName, domain }) {
294
+ if (!domain) return {
295
+ instanceUrl: `${fernOrg}.docs.buildwithfern.com`,
296
+ customDomain: void 0,
297
+ multiSource: false
298
+ };
299
+ const slashIdx = domain.indexOf("/");
300
+ if (slashIdx !== -1) return {
301
+ instanceUrl: `${fernOrg}.docs.buildwithfern.com/${domain.slice(slashIdx + 1)}`,
302
+ customDomain: domain,
303
+ multiSource: true
304
+ };
305
+ if (repoName) return {
306
+ instanceUrl: `${fernOrg}.docs.buildwithfern.com/${repoName}`,
307
+ customDomain: `${domain}/${repoName}`,
308
+ multiSource: true
309
+ };
310
+ return {
311
+ instanceUrl: `${fernOrg}.docs.buildwithfern.com`,
312
+ customDomain: domain,
313
+ multiSource: false
314
+ };
112
315
  }
113
316
  /**
114
317
  * Replace the `instances:` block in an existing docs.yml, preserving
@@ -130,24 +333,76 @@ function updateInstancesBlock(content, instanceUrl, customDomain, multiSource, r
130
333
  if (match[0] === newBlock) return content;
131
334
  return content.replace(blockRe, newBlock);
132
335
  }
133
- //#endregion
134
- //#region src/auth.ts
135
- const resolveToken = createResolveToken({
136
- envName: "HOLOCRON_FERN_TOKEN",
137
- vendorEnvName: "FERN_TOKEN",
138
- keyringService: "fern",
139
- errorMessage: "no Fern token found. Set HOLOCRON_FERN_TOKEN / FERN_TOKEN, or run: holocron auth set fern <token>"
140
- });
141
- //#endregion
142
- //#region src/index.ts
336
+ // src/probes/token/parse-layer.ts
337
+ /** Reads `--layer <word>` (or `--layer=<word>`) from the words after the probe name, which the CLI passes when `--environment` named a layer. */
338
+ function parseLayer(args) {
339
+ for (let i = 0; i < args.length; i++) {
340
+ const arg = args[i];
341
+ if (arg === "--layer") return args[i + 1];
342
+ if (arg.startsWith("--layer=")) return arg.slice(8);
343
+ }
344
+ }
345
+ // src/probes/token/token.ts
346
+ /**
347
+ * The `token` probe for Fern. Fern has no endpoint that reports who a token is or what it may do, so the probe cannot
348
+ * judge permissions: it checks that a token is set, says whether the layer holds it when `--layer` is passed (because
349
+ * `--environment` named one) against the plugin's `tokens` declaration, and states plainly that permissions are not
350
+ * checked. It makes no request and never prints the token.
351
+ */
352
+ function tokenProbe(ctx) {
353
+ return {
354
+ summary: "Check that a Fern token is set, and for a layer that it is one that should hold it. Fern cannot report a token's permissions, so those are not checked. Read-only, no request.",
355
+ writes: false,
356
+ acceptsToken: true,
357
+ async run(probe) {
358
+ probe.secret(ctx.token());
359
+ probe.say({
360
+ status: "ok",
361
+ label: "token",
362
+ detail: "set"
363
+ });
364
+ const layer = parseLayer(probe.args ?? []);
365
+ if (layer) {
366
+ const declared = tokenExpectations(tokens, { layer }).length > 0;
367
+ probe.say(declared ? {
368
+ status: "ok",
369
+ label: layer,
370
+ detail: "a layer that should hold this token"
371
+ } : {
372
+ status: "info",
373
+ label: layer,
374
+ detail: "not a layer this token is declared for, so it is only described"
375
+ });
376
+ }
377
+ probe.say({
378
+ status: "info",
379
+ label: "permissions",
380
+ detail: "Fern cannot report a token's permissions, so they are not checked"
381
+ });
382
+ }
383
+ };
384
+ }
385
+ // src/index.ts
386
+ /** Builds the `wiki` capability from the plugin options. */
143
387
  function wiki(opts) {
144
388
  return new FernWiki(opts);
145
389
  }
390
+ /** Creates the Fern plugin: its `connection` and `token` probes and the `wiki` capability. */
146
391
  function createPlugin(options = {}) {
147
392
  return {
148
393
  name: "@theholocron/holocron-plugin-fern",
394
+ probes: {
395
+ connection: connectionProbe({
396
+ provider: "Fern",
397
+ token: () => resolveToken(options),
398
+ verify: async () => ({
399
+ ok: true,
400
+ subject: "a token is set (Fern cannot check it from here)"
401
+ })
402
+ }),
403
+ token: tokenProbe({ token: () => resolveToken(options) })
404
+ },
149
405
  capabilities: { wiki: () => wiki(options) }
150
406
  };
151
407
  }
152
- //#endregion
153
- export { AuthError, FERN_VERSION, FernWiki, createPlugin, resolveToken, wiki };
408
+ export { AuthError, FERN_VERSION, FernWiki, createPlugin, resolveToken, tokens, wiki };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-fern",
3
- "version": "5.0.0-alpha.59",
3
+ "version": "5.0.0-alpha.590",
4
4
  "description": "Holocron plugin for Fern. Implements the wiki capability for engineering knowledge publishing.",
5
5
  "keywords": [
6
6
  "fern",
@@ -8,12 +8,12 @@
8
8
  "plugin",
9
9
  "wiki"
10
10
  ],
11
- "homepage": "https://github.com/theholocron/holocron/tree/main/packages/holocron-plugin-fern#readme",
11
+ "homepage": "https://docs.theholocron.dev/holocron/plugins/fern/",
12
12
  "bugs": "https://github.com/theholocron/holocron/issues",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/theholocron/holocron.git",
16
- "directory": "packages/holocron-plugin-fern"
16
+ "directory": "plugins/holocron-plugin-fern"
17
17
  },
18
18
  "license": "MIT",
19
19
  "author": "Newton Koumantzelis",
@@ -29,25 +29,28 @@
29
29
  "files": [
30
30
  "dist"
31
31
  ],
32
+ "dependencies": {
33
+ "@theholocron/json-utils": "^1.17.0-alpha.9"
34
+ },
32
35
  "devDependencies": {
33
- "@theholocron/eslint-config": "^8.4.5",
34
- "@theholocron/tsconfig": "^8.4.5",
35
- "@theholocron/tsdown-config": "^8.4.5",
36
- "@theholocron/vitest-config": "^8.4.5",
37
36
  "@types/node": "^26",
38
- "@vitest/coverage-v8": "^4.1.11",
39
- "@vitest/eslint-plugin": "^1.6.27",
40
- "eslint": "^10.8.1",
41
- "eslint-plugin-n": "^18.3.0",
42
- "globals": "^17.11.0",
43
- "tsdown": "^0.22.14",
44
- "tsx": "4.23.12",
45
- "typescript": "^5.9.3",
46
- "vitest": "^4.1.11",
47
- "@theholocron/cli": "5.0.0-alpha.59"
37
+ "@vitest/coverage-v8": "^5.1.2",
38
+ "@vitest/eslint-plugin": "^1.6.28",
39
+ "eslint": "^10.16.0",
40
+ "eslint-plugin-n": "^18.6.0",
41
+ "globals": "^17.14.0",
42
+ "tsdown": "^0.23.7",
43
+ "tsx": "4.23.15",
44
+ "typescript": "^6.0.3",
45
+ "vitest": "^5.1.2",
46
+ "@theholocron/cli": "5.0.0-alpha.590",
47
+ "@theholocron/eslint-config": "^8.9.0-alpha.24",
48
+ "@theholocron/tsconfig": "^8.9.0-alpha.24",
49
+ "@theholocron/tsdown-config": "^8.9.0-alpha.24",
50
+ "@theholocron/vitest-config": "^8.9.0-alpha.24"
48
51
  },
49
52
  "peerDependencies": {
50
- "@theholocron/cli": "5.0.0-alpha.59"
53
+ "@theholocron/cli": "5.0.0-alpha.590"
51
54
  },
52
55
  "engines": {
53
56
  "node": ">=22"
@@ -56,10 +59,10 @@
56
59
  "access": "public"
57
60
  },
58
61
  "scripts": {
59
- "delivery.build": "tsdown",
60
- "sourceQuality.staticAnalysis": "holocron run sourceQuality.staticAnalysis --",
62
+ "build": "tsdown",
63
+ "lint:code": "eslint .",
64
+ "test:unit": "vitest run --coverage",
61
65
  "test:watch": "vitest",
62
- "verification.typeSafety": "holocron run verification.typeSafety --",
63
- "verification.unitTests": "holocron run verification.unitTests --"
66
+ "typecheck": "tsc --noEmit"
64
67
  }
65
68
  }