rspress-plugin-api-extractor 0.11.0 → 0.13.0
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/BuildEnv.js +3 -3
- package/README.md +1 -0
- package/build-program.js +14 -5
- package/build-stages.js +88 -49
- package/config-helpers.js +7 -7
- package/errors.js +1 -5
- package/index.d.ts +1 -86
- package/layers/AppLayer.js +67 -0
- package/layers/api-results.js +83 -0
- package/layers/build-metrics.js +1 -1
- package/layers/{ConfigServiceLive.js → config-resolution.js} +115 -175
- package/layers/external-types.js +74 -0
- package/layers/{ObservabilityLive.js → observability.js} +3 -3
- package/layers/type-environment.js +109 -0
- package/layers/xdg.js +1 -1
- package/markdown/helpers.js +8 -33
- package/markdown/shiki-utils.js +1 -1
- package/model-loader.js +3 -3
- package/observability/EventBus.js +2 -2
- package/observability/heartbeat.js +1 -1
- package/observability/sinks/metrics-sink.js +1 -1
- package/observability/sinks/trace-sink.js +4 -4
- package/package.json +5 -4
- package/plugin.js +30 -33
- package/prettier-formatter.js +1 -1
- package/remark-api-codeblocks.js +1 -1
- package/remark-with-api.js +1 -1
- package/schemas/config.js +1 -3
- package/services/ConfigService.js +37 -2
- package/services/HighlighterService.js +48 -3
- package/services/OgService.js +154 -2
- package/services/PluginConfig.js +1 -1
- package/services/TwoslashCacheService.js +128 -2
- package/services/TwoslashEnvironments.js +30 -2
- package/services/TypeRegistryService.js +178 -2
- package/shiki-transformer.js +1 -1
- package/sync-node-fs.js +6 -6
- package/tsconfig-parser.js +77 -95
- package/twoslash-access.js +1 -1
- package/twoslash-transformer.js +1 -1
- package/layers/HighlighterServiceLive.js +0 -52
- package/layers/OgServiceLive.js +0 -134
- package/layers/TwoslashCacheServiceLive.js +0 -108
- package/layers/TwoslashEnvironmentsLive.js +0 -33
- package/layers/TypeRegistryServiceLive.js +0 -162
- package/markdown/index.js +0 -11
- package/og-resolver.js +0 -64
- package/schemas/index.js +0 -6
- package/schemas/opengraph.js +0 -56
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { PluginEvent } from "../observability/events.js";
|
|
2
|
-
import { emit } from "../observability/EventBus.js";
|
|
3
|
-
import { HighlighterService } from "../services/HighlighterService.js";
|
|
4
|
-
import { SHIKI_LANGS } from "../markdown/shiki-utils.js";
|
|
5
|
-
import { Effect, Layer } from "effect";
|
|
6
|
-
import { createHighlighter } from "shiki";
|
|
7
|
-
|
|
8
|
-
//#region src/layers/HighlighterServiceLive.ts
|
|
9
|
-
/**
|
|
10
|
-
* Acquire the build's highlighter, and release it when the runtime is
|
|
11
|
-
* disposed.
|
|
12
|
-
*
|
|
13
|
-
* @remarks
|
|
14
|
-
* `Layer.effect` over `Effect.acquireRelease` is the v4 scoped-constructor
|
|
15
|
-
* idiom (`Layer.scoped` is gone; `Layer.effect` strips `Scope` from `R`).
|
|
16
|
-
* Because the layer sits in the `ManagedRuntime`'s stack, the highlighter is
|
|
17
|
-
* created on the runtime's first use and `dispose()`d by
|
|
18
|
-
* `effectRuntime.dispose()` — which `plugin.ts` calls on production builds
|
|
19
|
-
* only, so a dev HMR session keeps one highlighter across rebuilds instead of
|
|
20
|
-
* leaking one per rebuild.
|
|
21
|
-
*
|
|
22
|
-
* **Bind the result to a `const`.** This is a layer FACTORY: each call mints a
|
|
23
|
-
* fresh layer reference, and layers memoize by reference, so calling it twice
|
|
24
|
-
* in one graph acquires two highlighters — the exact leak this layer exists to
|
|
25
|
-
* fix.
|
|
26
|
-
*
|
|
27
|
-
* The themes are passed in rather than read from a resolved build context
|
|
28
|
-
* because the layer builds before `ConfigService.resolve()` runs. Passing them
|
|
29
|
-
* as an argument rather than through a `Context.Reference` is deliberate: a
|
|
30
|
-
* Reference carries a default, so forgetting to wire it would silently load
|
|
31
|
-
* only the default themes and render every custom-themed block wrong. A
|
|
32
|
-
* missing argument is a type error.
|
|
33
|
-
*/
|
|
34
|
-
function HighlighterServiceLive(themes) {
|
|
35
|
-
return Layer.effect(HighlighterService, Effect.gen(function* () {
|
|
36
|
-
const startedMs = performance.now();
|
|
37
|
-
const highlighter = yield* Effect.acquireRelease(Effect.promise(() => createHighlighter({
|
|
38
|
-
themes: [...themes],
|
|
39
|
-
langs: [...SHIKI_LANGS]
|
|
40
|
-
})), (instance) => Effect.sync(() => instance.dispose()));
|
|
41
|
-
yield* emit(PluginEvent.PhaseCompleted({
|
|
42
|
-
ctx: {},
|
|
43
|
-
level: "debug",
|
|
44
|
-
phase: "shikiInit",
|
|
45
|
-
durationMs: Math.round(performance.now() - startedMs)
|
|
46
|
-
}));
|
|
47
|
-
return { highlighter };
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//#endregion
|
|
52
|
-
export { HighlighterServiceLive };
|
package/layers/OgServiceLive.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { PluginEvent } from "../observability/events.js";
|
|
2
|
-
import { emit } from "../observability/EventBus.js";
|
|
3
|
-
import { imageMimeType, ogAltText, resolveOgUrl } from "../og-resolver.js";
|
|
4
|
-
import { OgImageError, OgService } from "../services/OgService.js";
|
|
5
|
-
import { Effect, FileSystem, Layer, Option, Path } from "effect";
|
|
6
|
-
import { imageSize } from "image-size";
|
|
7
|
-
|
|
8
|
-
//#region src/layers/OgServiceLive.ts
|
|
9
|
-
/**
|
|
10
|
-
* Resolve OG images through the core `FileSystem`, with one read per file per
|
|
11
|
-
* build.
|
|
12
|
-
*
|
|
13
|
-
* @remarks
|
|
14
|
-
* The `node:fs` `existsSync` + `imageSizeFromFile` pair this replaces ran once
|
|
15
|
-
* per PAGE, so a 400-page API re-read the same image 400 times. The memo below
|
|
16
|
-
* keys on the absolute path and removes that entirely.
|
|
17
|
-
*
|
|
18
|
-
* The memo is per build, not persisted. A cross-build cache in the shared XDG
|
|
19
|
-
* store was considered and deliberately deferred: it would need mtime/size
|
|
20
|
-
* invalidation to stay sound, and a stale image dimension is a silent wrong
|
|
21
|
-
* answer. There is nothing expensive enough here to justify that yet — when
|
|
22
|
-
* phase 4 starts GENERATING images, which are expensive and content-addressed,
|
|
23
|
-
* the XDG cache is the right home for them.
|
|
24
|
-
*
|
|
25
|
-
* `imageSize` over the read bytes replaces `imageSizeFromFile`, which took a
|
|
26
|
-
* path and therefore required real `node:fs`. Same parser, same output.
|
|
27
|
-
*/
|
|
28
|
-
const OgServiceLive = Layer.effect(OgService, Effect.gen(function* () {
|
|
29
|
-
const fileSystem = yield* FileSystem.FileSystem;
|
|
30
|
-
const path = yield* Path.Path;
|
|
31
|
-
/** Absolute path → facts, or `null` for "looked, could not use it". */
|
|
32
|
-
const factsByPath = /* @__PURE__ */ new Map();
|
|
33
|
-
/** Locate a root-relative image under the docs `public/` directory. */
|
|
34
|
-
const findLocalImage = (imagePath, docsRoot) => {
|
|
35
|
-
if (docsRoot == null || !imagePath.startsWith("/")) return Effect.succeed(Option.none());
|
|
36
|
-
const candidate = path.join(docsRoot, "public", imagePath);
|
|
37
|
-
return fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false), Effect.map((found) => found ? Option.some(candidate) : Option.none()));
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Read dimensions and MIME type. A file that cannot be parsed warns and
|
|
41
|
-
* yields nothing — the page still gets its `og:image`, just without
|
|
42
|
-
* dimensions, which is what the class this replaced did.
|
|
43
|
-
*/
|
|
44
|
-
const readImageFacts = (filePath) => Effect.gen(function* () {
|
|
45
|
-
const memoed = factsByPath.get(filePath);
|
|
46
|
-
if (memoed !== void 0) return memoed;
|
|
47
|
-
const result = yield* Effect.result(fileSystem.readFile(filePath).pipe(Effect.flatMap((bytes) => Effect.try(() => imageSize(bytes)))));
|
|
48
|
-
if (result._tag === "Failure") {
|
|
49
|
-
const error = new OgImageError({
|
|
50
|
-
code: "unreadable-image",
|
|
51
|
-
field: "ogImage",
|
|
52
|
-
value: filePath,
|
|
53
|
-
cause: result.failure
|
|
54
|
-
});
|
|
55
|
-
yield* emit(PluginEvent.ConfigValidationWarning({
|
|
56
|
-
ctx: {},
|
|
57
|
-
field: "ogImage",
|
|
58
|
-
value: filePath,
|
|
59
|
-
reason: error.message,
|
|
60
|
-
level: "warn"
|
|
61
|
-
}));
|
|
62
|
-
factsByPath.set(filePath, null);
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
const size = result.success;
|
|
66
|
-
const mimeType = imageMimeType(size.type);
|
|
67
|
-
const facts = {
|
|
68
|
-
...size.width != null ? { width: size.width } : {},
|
|
69
|
-
...size.height != null ? { height: size.height } : {},
|
|
70
|
-
...mimeType != null ? { type: mimeType } : {}
|
|
71
|
-
};
|
|
72
|
-
factsByPath.set(filePath, facts);
|
|
73
|
-
return facts;
|
|
74
|
-
});
|
|
75
|
-
const resolveFromString = (imageUrl, request) => Effect.gen(function* () {
|
|
76
|
-
const resolvedUrl = resolveOgUrl(request.siteUrl, imageUrl);
|
|
77
|
-
if (resolvedUrl == null) return yield* Effect.fail(new OgImageError({
|
|
78
|
-
code: "invalid-url",
|
|
79
|
-
field: "ogImage",
|
|
80
|
-
value: imageUrl
|
|
81
|
-
}));
|
|
82
|
-
const localPath = yield* findLocalImage(imageUrl, request.docsRoot);
|
|
83
|
-
const facts = Option.isSome(localPath) ? yield* readImageFacts(localPath.value) : null;
|
|
84
|
-
return Option.some({
|
|
85
|
-
url: resolvedUrl,
|
|
86
|
-
type: facts?.type,
|
|
87
|
-
width: facts?.width,
|
|
88
|
-
height: facts?.height,
|
|
89
|
-
alt: ogAltText(request.packageName, request.apiName)
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
const resolveFromMetadata = (metadata, request) => Effect.gen(function* () {
|
|
93
|
-
const { url, secureUrl, type, width, height, alt } = metadata;
|
|
94
|
-
const resolvedUrl = resolveOgUrl(request.siteUrl, url);
|
|
95
|
-
if (resolvedUrl == null) return yield* Effect.fail(new OgImageError({
|
|
96
|
-
code: "invalid-url",
|
|
97
|
-
field: "ogImage.url",
|
|
98
|
-
value: url
|
|
99
|
-
}));
|
|
100
|
-
let resolvedSecureUrl;
|
|
101
|
-
if (secureUrl != null) {
|
|
102
|
-
if (secureUrl.startsWith("https://")) resolvedSecureUrl = secureUrl;
|
|
103
|
-
else {
|
|
104
|
-
const error = new OgImageError({
|
|
105
|
-
code: "invalid-secure-url",
|
|
106
|
-
field: "ogImage.secureUrl",
|
|
107
|
-
value: secureUrl
|
|
108
|
-
});
|
|
109
|
-
yield* emit(PluginEvent.ConfigValidationWarning({
|
|
110
|
-
ctx: {},
|
|
111
|
-
field: "ogImage.secureUrl",
|
|
112
|
-
value: secureUrl,
|
|
113
|
-
reason: error.message,
|
|
114
|
-
level: "warn"
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return Option.some({
|
|
119
|
-
url: resolvedUrl,
|
|
120
|
-
secureUrl: resolvedSecureUrl,
|
|
121
|
-
type,
|
|
122
|
-
width,
|
|
123
|
-
height,
|
|
124
|
-
alt: alt ?? ogAltText(request.packageName, request.apiName)
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
return { resolveImage: (request) => {
|
|
128
|
-
if (request.config == null) return Effect.succeed(Option.none());
|
|
129
|
-
return typeof request.config === "object" ? resolveFromMetadata(request.config, request) : resolveFromString(request.config, request);
|
|
130
|
-
} };
|
|
131
|
-
}));
|
|
132
|
-
|
|
133
|
-
//#endregion
|
|
134
|
-
export { OgServiceLive };
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { TwoslashCacheService } from "../services/TwoslashCacheService.js";
|
|
2
|
-
import { decodeTwoslashCache, encodeTwoslashCache, makeTwoslashCache, twoslashBlobKey } from "../twoslash-cache.js";
|
|
3
|
-
import { AppDirsLive, PlatformLive } from "./xdg.js";
|
|
4
|
-
import { Effect, Layer, Option, Path } from "effect";
|
|
5
|
-
import { Cache } from "@effected/store";
|
|
6
|
-
import { AppDirs } from "@effected/xdg";
|
|
7
|
-
|
|
8
|
-
//#region src/layers/TwoslashCacheServiceLive.ts
|
|
9
|
-
/**
|
|
10
|
-
* A sqlite-backed `@effected/store` Cache in the XDG cache dir, separate from
|
|
11
|
-
* the registry's `metadata.sqlite`.
|
|
12
|
-
*
|
|
13
|
-
* XDG rather than the repo: these are regenerable results derived from content
|
|
14
|
-
* hashes, so they belong with the user's other caches — shared across worktrees
|
|
15
|
-
* and checkouts of the same project, and untouched by cleaning `dist/`. Nothing
|
|
16
|
-
* here needs to be committed for a build to be correct.
|
|
17
|
-
*/
|
|
18
|
-
const CacheLive = Layer.unwrap(Effect.gen(function* () {
|
|
19
|
-
const appDirs = yield* AppDirs;
|
|
20
|
-
const path = yield* Path.Path;
|
|
21
|
-
const cacheDir = yield* appDirs.ensureCache;
|
|
22
|
-
return Cache.layerSqlite({ filename: path.join(cacheDir, "twoslash.sqlite") });
|
|
23
|
-
})).pipe(Layer.provide(Layer.mergeAll(AppDirsLive, PlatformLive)));
|
|
24
|
-
/**
|
|
25
|
-
* Live Twoslash cache persistence.
|
|
26
|
-
*
|
|
27
|
-
* Both operations swallow every failure by design — see the service docs. A
|
|
28
|
-
* missing HOME, an unwritable cache dir or a corrupt database degrades the
|
|
29
|
-
* build to "type-check everything", which is exactly the behaviour before this
|
|
30
|
-
* cache existed.
|
|
31
|
-
*/
|
|
32
|
-
/**
|
|
33
|
-
* Add the build-generation half of the service on top of a load/save pair.
|
|
34
|
-
*
|
|
35
|
-
* @remarks
|
|
36
|
-
* Shared by the real and degraded layers so the two cannot drift: a degraded
|
|
37
|
-
* build must still hand out a working in-memory cache, otherwise the
|
|
38
|
-
* transformers have nothing to read or write and the render pass changes
|
|
39
|
-
* shape rather than merely losing persistence.
|
|
40
|
-
*/
|
|
41
|
-
function withGeneration(base) {
|
|
42
|
-
let open = null;
|
|
43
|
-
return {
|
|
44
|
-
...base,
|
|
45
|
-
open: (envHash) => base.load(envHash).pipe(Effect.map((restored) => {
|
|
46
|
-
const cache = makeTwoslashCache(restored);
|
|
47
|
-
open = {
|
|
48
|
-
cache,
|
|
49
|
-
envHash
|
|
50
|
-
};
|
|
51
|
-
return cache;
|
|
52
|
-
})),
|
|
53
|
-
persist: () => Effect.suspend(() => {
|
|
54
|
-
if (open === null) return Effect.succeed(Option.none());
|
|
55
|
-
const { cache, envHash } = open;
|
|
56
|
-
const stats = cache.stats();
|
|
57
|
-
const report = Option.some({
|
|
58
|
-
...stats,
|
|
59
|
-
envHash
|
|
60
|
-
});
|
|
61
|
-
return stats.dirty ? base.save(envHash, cache.entries()).pipe(Effect.as(report)) : Effect.succeed(report);
|
|
62
|
-
})
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const CacheBackedLive = Layer.effect(TwoslashCacheService, Effect.gen(function* () {
|
|
66
|
-
const cache = yield* Cache;
|
|
67
|
-
return withGeneration({
|
|
68
|
-
load: (envHash) => cache.get(twoslashBlobKey(envHash)).pipe(Effect.map((entry) => Option.isSome(entry) ? decodeTwoslashCache(entry.value.value) : /* @__PURE__ */ new Map()), Effect.catch(() => Effect.succeed(/* @__PURE__ */ new Map()))),
|
|
69
|
-
save: (envHash, entries) => cache.set({
|
|
70
|
-
key: twoslashBlobKey(envHash),
|
|
71
|
-
value: encodeTwoslashCache(entries),
|
|
72
|
-
tags: ["twoslash"]
|
|
73
|
-
}).pipe(Effect.catch(() => Effect.void))
|
|
74
|
-
});
|
|
75
|
-
})).pipe(Layer.provide(CacheLive));
|
|
76
|
-
/**
|
|
77
|
-
* A cache that holds nothing, for when the real one cannot be opened.
|
|
78
|
-
*
|
|
79
|
-
* @remarks
|
|
80
|
-
* `load` returns empty and `save` discards, which is precisely the behaviour
|
|
81
|
-
* before this cache existed: type-check everything, persist nothing.
|
|
82
|
-
*/
|
|
83
|
-
const DegradedLive = Layer.succeed(TwoslashCacheService, withGeneration({
|
|
84
|
-
load: () => Effect.succeed(/* @__PURE__ */ new Map()),
|
|
85
|
-
save: () => Effect.void
|
|
86
|
-
}));
|
|
87
|
-
/**
|
|
88
|
-
* Live Twoslash cache persistence.
|
|
89
|
-
*
|
|
90
|
-
* @remarks
|
|
91
|
-
* Failure is absorbed at TWO levels, and both are load-bearing. Inside the
|
|
92
|
-
* service, a failed read or write degrades that one operation. Around the
|
|
93
|
-
* layer, a failed CONSTRUCTION — no HOME for XDG, an unwritable cache
|
|
94
|
-
* directory, a corrupt database — degrades to {@link DegradedLive}.
|
|
95
|
-
*
|
|
96
|
-
* The second is why `Layer.catchCause` wraps this at all. While the sqlite
|
|
97
|
-
* layer was provided inside each method, a construction failure surfaced as
|
|
98
|
-
* that method's failure and the in-method handler swallowed it. Hoisting
|
|
99
|
-
* acquisition to layer construction moved the failure to `ManagedRuntime`
|
|
100
|
-
* build time, where it would abort the entire build — breaking the contract
|
|
101
|
-
* this service documents, that an unreachable cache must never fail a build
|
|
102
|
-
* that would otherwise succeed. `catchCause` rather than a failure-only catch
|
|
103
|
-
* because a defect thrown by the sqlite driver must degrade too.
|
|
104
|
-
*/
|
|
105
|
-
const TwoslashCacheServiceLive = CacheBackedLive.pipe(Layer.catchCause(() => DegradedLive));
|
|
106
|
-
|
|
107
|
-
//#endregion
|
|
108
|
-
export { TwoslashCacheServiceLive };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { TwoslashEnvironments } from "../services/TwoslashEnvironments.js";
|
|
2
|
-
import { TwoslashEnvironmentRegistry } from "../twoslash-transformer.js";
|
|
3
|
-
import { Layer } from "effect";
|
|
4
|
-
|
|
5
|
-
//#region src/layers/TwoslashEnvironmentsLive.ts
|
|
6
|
-
/**
|
|
7
|
-
* One environment registry per runtime.
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* `Layer.sync` rather than `Layer.succeed`: the registry is mutable, and a
|
|
11
|
-
* `Layer.succeed` would capture a single instance shared by every layer graph
|
|
12
|
-
* that referenced this const — including, in a test run, every test file in
|
|
13
|
-
* the process. Building it when the layer builds is what makes substitution
|
|
14
|
-
* work: a test that wants an isolated registry provides its own layer, which
|
|
15
|
-
* is what the old static `TwoslashManager.reset()` was standing in for.
|
|
16
|
-
*
|
|
17
|
-
* Deliberately NOT `Layer.effect` with a finalizer. The registry holds Shiki
|
|
18
|
-
* transformers, which the render pass uses AFTER `config()` returns — the same
|
|
19
|
-
* lifetime constraint the highlighter has, and for the same reason.
|
|
20
|
-
*/
|
|
21
|
-
const TwoslashEnvironmentsLive = Layer.sync(TwoslashEnvironments, () => {
|
|
22
|
-
const registry = new TwoslashEnvironmentRegistry();
|
|
23
|
-
return {
|
|
24
|
-
registerEnvironment: (options) => registry.registerEnvironment(options),
|
|
25
|
-
registerScope: (apiScope, compilerOptions) => registry.registerScope(apiScope, compilerOptions),
|
|
26
|
-
transformerFor: (apiScope) => registry.transformerFor(apiScope),
|
|
27
|
-
setCurrentFile: (path) => registry.setCurrentFile(path),
|
|
28
|
-
reportErrorForTest: (error, code, file) => registry.reportErrorForTest(error, code, file)
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
export { TwoslashEnvironmentsLive };
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { PluginEvent } from "../observability/events.js";
|
|
2
|
-
import { emit } from "../observability/EventBus.js";
|
|
3
|
-
import { resolveExternalPackageVersions } from "../config-utils.js";
|
|
4
|
-
import { TypeRegistryError } from "../errors.js";
|
|
5
|
-
import { TypeRegistryService } from "../services/TypeRegistryService.js";
|
|
6
|
-
import { AppDirsLive, PlatformLive } from "./xdg.js";
|
|
7
|
-
import { NodeHttpClient } from "@effect/platform-node";
|
|
8
|
-
import { Duration, Effect, Layer, Path } from "effect";
|
|
9
|
-
import { PackageFetcher, PackageSpec, RegistryObserver, TypeCache, TypeRegistry } from "@tsdoctor/registry";
|
|
10
|
-
import { Cache } from "@effected/store";
|
|
11
|
-
import { AppDirs } from "@effected/xdg";
|
|
12
|
-
|
|
13
|
-
//#region src/layers/TypeRegistryServiceLive.ts
|
|
14
|
-
/**
|
|
15
|
-
* Forward @tsdoctor/registry's typed `RegistryEvent`s to the plugin's Effect
|
|
16
|
-
* logger. Since v1 the library emits no logs of its own — observers are the only
|
|
17
|
-
* diagnostic surface — so this restores the build output and routes it through
|
|
18
|
-
* the plugin's configured log level/format (a single source, no duplication).
|
|
19
|
-
*
|
|
20
|
-
* The summary (`BatchComplete`) and failures are surfaced at info/warning;
|
|
21
|
-
* per-package detail stays at debug so a normal build is quiet.
|
|
22
|
-
*/
|
|
23
|
-
const RegistryObserverLayer = Layer.succeed(RegistryObserver, { emit: (event) => {
|
|
24
|
-
switch (event._tag) {
|
|
25
|
-
case "VersionResolved": return emit(PluginEvent.TypeRegistryEvent({
|
|
26
|
-
ctx: { packageName: event.package },
|
|
27
|
-
level: "debug",
|
|
28
|
-
kind: "VersionResolved",
|
|
29
|
-
detail: `${event.requested} -> ${event.resolved}`
|
|
30
|
-
}));
|
|
31
|
-
case "VersionResolveFailed": return emit(PluginEvent.TypeRegistryEvent({
|
|
32
|
-
ctx: { packageName: event.package },
|
|
33
|
-
level: "debug",
|
|
34
|
-
kind: "VersionResolveFailed",
|
|
35
|
-
detail: `${event.requested}: ${event.kind}`
|
|
36
|
-
}));
|
|
37
|
-
case "CacheHit":
|
|
38
|
-
case "CacheMiss":
|
|
39
|
-
case "FetchStart": return emit(PluginEvent.TypeRegistryEvent({
|
|
40
|
-
ctx: {
|
|
41
|
-
packageName: event.package,
|
|
42
|
-
version: event.version
|
|
43
|
-
},
|
|
44
|
-
level: "debug",
|
|
45
|
-
kind: event._tag,
|
|
46
|
-
detail: ""
|
|
47
|
-
}));
|
|
48
|
-
case "CacheStale": return emit(PluginEvent.TypeRegistryEvent({
|
|
49
|
-
ctx: {
|
|
50
|
-
packageName: event.package,
|
|
51
|
-
version: event.version
|
|
52
|
-
},
|
|
53
|
-
level: "debug",
|
|
54
|
-
kind: "CacheStale",
|
|
55
|
-
detail: ""
|
|
56
|
-
}));
|
|
57
|
-
case "FetchFailed": return emit(PluginEvent.TypeRegistryEvent({
|
|
58
|
-
ctx: {},
|
|
59
|
-
level: "debug",
|
|
60
|
-
kind: "FetchFailed",
|
|
61
|
-
detail: `HTTP ${event.status}: ${event.url}${event.bodySnippet ? ` — ${event.bodySnippet}` : ""}`
|
|
62
|
-
}));
|
|
63
|
-
case "PackageLoaded": return emit(PluginEvent.TypeRegistryEvent({
|
|
64
|
-
ctx: {
|
|
65
|
-
packageName: event.package,
|
|
66
|
-
version: event.version
|
|
67
|
-
},
|
|
68
|
-
level: "debug",
|
|
69
|
-
kind: "PackageLoaded",
|
|
70
|
-
detail: `${event.files} files, ${event.source}`
|
|
71
|
-
}));
|
|
72
|
-
case "PackageLoadFailed": return emit(PluginEvent.TypeRegistryEvent({
|
|
73
|
-
ctx: {
|
|
74
|
-
packageName: event.package,
|
|
75
|
-
version: event.version
|
|
76
|
-
},
|
|
77
|
-
level: "warn",
|
|
78
|
-
kind: "PackageLoadFailed",
|
|
79
|
-
detail: `[${event.kind}] ${event.error instanceof Error ? event.error.message : String(event.error)}`
|
|
80
|
-
}));
|
|
81
|
-
case "BatchStart": return emit(PluginEvent.TypeRegistryEvent({
|
|
82
|
-
ctx: {},
|
|
83
|
-
level: "debug",
|
|
84
|
-
kind: "BatchStart",
|
|
85
|
-
detail: `${event.total} package(s)`
|
|
86
|
-
}));
|
|
87
|
-
case "BatchComplete": return emit(PluginEvent.TypeRegistryEvent({
|
|
88
|
-
ctx: {},
|
|
89
|
-
level: "info",
|
|
90
|
-
kind: "BatchComplete",
|
|
91
|
-
detail: `${event.loaded}/${event.total} packages, ${event.totalFiles} files, ${Math.round(Duration.toMillis(event.duration))}ms`
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
} });
|
|
95
|
-
/** Metadata plane: a sqlite-backed `@effected/store` Cache rooted in the XDG cache dir. */
|
|
96
|
-
const MetadataCacheLive = Layer.unwrap(Effect.gen(function* () {
|
|
97
|
-
const appDirs = yield* AppDirs;
|
|
98
|
-
const path = yield* Path.Path;
|
|
99
|
-
const cacheDir = yield* appDirs.ensureCache;
|
|
100
|
-
return Cache.layerSqlite({ filename: path.join(cacheDir, "metadata.sqlite") });
|
|
101
|
-
})).pipe(Layer.provide(Layer.mergeAll(AppDirsLive, PlatformLive)));
|
|
102
|
-
/**
|
|
103
|
-
* The full registry runtime: TypeRegistry over an XDG-rooted TypeCache and the
|
|
104
|
-
* jsDelivr PackageFetcher, with the observer that forwards registry events to
|
|
105
|
-
* the plugin's EventBus (found ambiently via serviceOption at emit time).
|
|
106
|
-
*/
|
|
107
|
-
const RegistryLayer = TypeRegistry.layer.pipe(Layer.provideMerge(Layer.mergeAll(TypeCache.layerXdg(), PackageFetcher.layer)), Layer.provideMerge(RegistryObserverLayer), Layer.provide(Layer.mergeAll(MetadataCacheLive, AppDirsLive, PlatformLive, NodeHttpClient.layerUndici)));
|
|
108
|
-
/**
|
|
109
|
-
* TypeRegistryServiceLive: uses @tsdoctor/registry Effect programs directly.
|
|
110
|
-
*/
|
|
111
|
-
const RegistryBackedLive = Layer.effect(TypeRegistryService, Effect.gen(function* () {
|
|
112
|
-
const registry = yield* TypeRegistry;
|
|
113
|
-
return {
|
|
114
|
-
resolveVersions: (packages) => resolveExternalPackageVersions(packages, (pkg) => registry.resolveVersion(pkg.name, pkg.version)).pipe(Effect.catch(() => Effect.succeed([...packages]))),
|
|
115
|
-
loadPackages: (packages) => packages.length === 0 ? Effect.succeed({ vfs: /* @__PURE__ */ new Map() }) : Effect.gen(function* () {
|
|
116
|
-
const specs = packages.map((pkg) => new PackageSpec({
|
|
117
|
-
name: pkg.name,
|
|
118
|
-
version: pkg.version
|
|
119
|
-
}));
|
|
120
|
-
return { vfs: yield* registry.getVfs(specs, { autoFetch: true }) };
|
|
121
|
-
}).pipe(Effect.catch((error) => Effect.fail(new TypeRegistryError({
|
|
122
|
-
packageName: packages.map((p) => p.name).join(", "),
|
|
123
|
-
version: packages.map((p) => p.version).join(", "),
|
|
124
|
-
reason: error instanceof Error ? error.message ?? String(error) : String(error)
|
|
125
|
-
}))))
|
|
126
|
-
};
|
|
127
|
-
})).pipe(Layer.provide(RegistryLayer));
|
|
128
|
-
/**
|
|
129
|
-
* The service when the registry stack cannot be built at all.
|
|
130
|
-
*
|
|
131
|
-
* @remarks
|
|
132
|
-
* Preserves exactly the split the working service documents: `resolveVersions`
|
|
133
|
-
* passes its specs through unresolved rather than swallowing the problem, so
|
|
134
|
-
* the failure surfaces from `loadPackages` as a {@link PluginTypeRegistryError}
|
|
135
|
-
* with a message, which `ConfigServiceLive` turns into a build-continues
|
|
136
|
-
* warning. Before acquisition moved to layer construction this fell out of the
|
|
137
|
-
* per-method handlers; it has to be stated explicitly now.
|
|
138
|
-
*/
|
|
139
|
-
const DegradedLive = Layer.succeed(TypeRegistryService, {
|
|
140
|
-
resolveVersions: (packages) => Effect.succeed([...packages]),
|
|
141
|
-
loadPackages: (packages) => Effect.fail(new TypeRegistryError({
|
|
142
|
-
packageName: packages.map((p) => p.name).join(", "),
|
|
143
|
-
version: packages.map((p) => p.version).join(", "),
|
|
144
|
-
reason: "type registry unavailable: its cache directory or metadata database could not be opened"
|
|
145
|
-
}))
|
|
146
|
-
});
|
|
147
|
-
/**
|
|
148
|
-
* TypeRegistryServiceLive: the `@tsdoctor/registry` stack, acquired once.
|
|
149
|
-
*
|
|
150
|
-
* @remarks
|
|
151
|
-
* `Layer.catchCause` keeps a broken environment — no HOME for XDG, an
|
|
152
|
-
* unwritable cache directory — from aborting the build at `ManagedRuntime`
|
|
153
|
-
* construction. External type loading is an enhancement: without it code
|
|
154
|
-
* blocks render without Twoslash enrichment, which is a degradation, not a
|
|
155
|
-
* failure. That was true while the stack was provided per method and the
|
|
156
|
-
* in-method handlers absorbed it; hoisting acquisition made it something the
|
|
157
|
-
* layer has to say for itself.
|
|
158
|
-
*/
|
|
159
|
-
const TypeRegistryServiceLive = RegistryBackedLive.pipe(Layer.catchCause(() => DegradedLive));
|
|
160
|
-
|
|
161
|
-
//#endregion
|
|
162
|
-
export { TypeRegistryServiceLive };
|
package/markdown/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { linkProse, setProseLinker } from "./prose-linker.js";
|
|
2
|
-
import { ClassPageGenerator } from "./page-generators/class-page.js";
|
|
3
|
-
import { EnumPageGenerator } from "./page-generators/enum-page.js";
|
|
4
|
-
import { FunctionPageGenerator } from "./page-generators/function-page.js";
|
|
5
|
-
import { MainIndexPageGenerator } from "./page-generators/index-pages.js";
|
|
6
|
-
import { InterfacePageGenerator } from "./page-generators/interface-page.js";
|
|
7
|
-
import { NamespacePageGenerator } from "./page-generators/namespace-page.js";
|
|
8
|
-
import { TypeAliasPageGenerator } from "./page-generators/type-alias-page.js";
|
|
9
|
-
import { VariablePageGenerator } from "./page-generators/variable-page.js";
|
|
10
|
-
|
|
11
|
-
export { ClassPageGenerator, EnumPageGenerator, FunctionPageGenerator, InterfacePageGenerator, MainIndexPageGenerator, NamespacePageGenerator, TypeAliasPageGenerator, VariablePageGenerator, setProseLinker };
|
package/og-resolver.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
//#region src/og-resolver.ts
|
|
2
|
-
/**
|
|
3
|
-
* MIME type mappings for common image formats, used for `og:image:type`.
|
|
4
|
-
*/
|
|
5
|
-
const IMAGE_MIME_TYPES = {
|
|
6
|
-
jpg: "image/jpeg",
|
|
7
|
-
jpeg: "image/jpeg",
|
|
8
|
-
png: "image/png",
|
|
9
|
-
gif: "image/gif",
|
|
10
|
-
webp: "image/webp",
|
|
11
|
-
svg: "image/svg+xml"
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* The `og:image:type` value for a detected image format, or `undefined` for a
|
|
15
|
-
* format with no mapping.
|
|
16
|
-
*/
|
|
17
|
-
function imageMimeType(type) {
|
|
18
|
-
if (type == null) return void 0;
|
|
19
|
-
return IMAGE_MIME_TYPES[type.toLowerCase()];
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Turn a configured image URL into an absolute one.
|
|
23
|
-
*
|
|
24
|
-
* @returns The absolute URL, or `undefined` when the input is neither an
|
|
25
|
-
* absolute `http(s)` URL nor a site-root-relative path. A bare relative path
|
|
26
|
-
* is deliberately rejected rather than guessed at — there is no base to
|
|
27
|
-
* resolve it against that would not silently produce a broken link.
|
|
28
|
-
*/
|
|
29
|
-
function resolveOgUrl(siteUrl, url) {
|
|
30
|
-
if (url.startsWith("http://") || url.startsWith("https://")) return url;
|
|
31
|
-
if (url.startsWith("/")) return `${siteUrl}${url}`;
|
|
32
|
-
}
|
|
33
|
-
/** Descriptive alt text for a package's (or one API's) OG image. */
|
|
34
|
-
function ogAltText(packageName, apiName) {
|
|
35
|
-
return apiName ? `${apiName} - ${packageName} API Documentation` : `${packageName} API Documentation`;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Assemble the complete Open Graph metadata for one documentation page.
|
|
39
|
-
*
|
|
40
|
-
* @remarks
|
|
41
|
-
* Was `OpenGraphResolver.createPageMetadata`. It never touched the resolver's
|
|
42
|
-
* instance state, so it is a free function now rather than a static on a class
|
|
43
|
-
* that no longer exists.
|
|
44
|
-
*/
|
|
45
|
-
function createPageMetadata(options) {
|
|
46
|
-
return {
|
|
47
|
-
siteUrl: options.siteUrl,
|
|
48
|
-
pageRoute: options.pageRoute,
|
|
49
|
-
description: options.description,
|
|
50
|
-
publishedTime: options.publishedTime,
|
|
51
|
-
modifiedTime: options.modifiedTime,
|
|
52
|
-
section: options.section,
|
|
53
|
-
tags: [
|
|
54
|
-
"TypeScript",
|
|
55
|
-
"API",
|
|
56
|
-
options.packageName
|
|
57
|
-
],
|
|
58
|
-
...options.ogImage != null ? { ogImage: options.ogImage } : {},
|
|
59
|
-
ogType: "article"
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
export { createPageMetadata, imageMimeType, ogAltText, resolveOgUrl };
|
package/schemas/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { PerformanceConfig, PerformanceThresholds } from "./performance.js";
|
|
2
|
-
import { EventLevelSchema, ObservabilityConfig, resolveObservability } from "./observability.js";
|
|
3
|
-
import { OpenGraphImageConfig, OpenGraphImageMetadata } from "./opengraph.js";
|
|
4
|
-
import { AutoDetectDependencies, CategoryConfig, DEFAULT_CATEGORIES, ErrorConfig, ExternalPackageSpec, LlmsPlugin, LogLevel, ModelInput, MultiApiConfig, PluginOptions, SingleApiConfig, SourceConfig, ThemeConfig, VersionConfig } from "./config.js";
|
|
5
|
-
|
|
6
|
-
export { DEFAULT_CATEGORIES, PluginOptions };
|
package/schemas/opengraph.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
|
|
3
|
-
//#region src/schemas/opengraph.ts
|
|
4
|
-
/**
|
|
5
|
-
* Structured Open Graph image metadata (alternative to a plain URL string).
|
|
6
|
-
*
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
const OpenGraphImageMetadata = Schema.Struct({
|
|
10
|
-
/** Absolute URL of the image. */
|
|
11
|
-
url: Schema.String,
|
|
12
|
-
/** HTTPS URL of the image (for secure contexts). */
|
|
13
|
-
secureUrl: Schema.optional(Schema.String),
|
|
14
|
-
/** MIME type of the image (e.g. `"image/png"`). */
|
|
15
|
-
type: Schema.optional(Schema.String),
|
|
16
|
-
/** Image width in pixels. */
|
|
17
|
-
width: Schema.optional(Schema.Number),
|
|
18
|
-
/** Image height in pixels. */
|
|
19
|
-
height: Schema.optional(Schema.Number),
|
|
20
|
-
/** Alt text for the image. */
|
|
21
|
-
alt: Schema.optional(Schema.String)
|
|
22
|
-
});
|
|
23
|
-
/**
|
|
24
|
-
* Open Graph image: either a plain URL string or structured `OpenGraphImageMetadata`.
|
|
25
|
-
*
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
const OpenGraphImageConfig = Schema.Union([Schema.String, OpenGraphImageMetadata]);
|
|
29
|
-
/**
|
|
30
|
-
* Resolved Open Graph metadata emitted into each generated page's frontmatter.
|
|
31
|
-
*
|
|
32
|
-
* @public
|
|
33
|
-
*/
|
|
34
|
-
const OpenGraphMetadata = Schema.Struct({
|
|
35
|
-
/** Canonical site base URL. */
|
|
36
|
-
siteUrl: Schema.String,
|
|
37
|
-
/** Page route path (e.g. `/api/classes/myclass`). */
|
|
38
|
-
pageRoute: Schema.String,
|
|
39
|
-
/** Page description for the `og:description` tag. */
|
|
40
|
-
description: Schema.String,
|
|
41
|
-
/** ISO 8601 date string for `article:published_time`. */
|
|
42
|
-
publishedTime: Schema.String,
|
|
43
|
-
/** ISO 8601 date string for `article:modified_time`. */
|
|
44
|
-
modifiedTime: Schema.String,
|
|
45
|
-
/** Article section label (e.g. `"API"`). */
|
|
46
|
-
section: Schema.String,
|
|
47
|
-
/** Article tag keywords. */
|
|
48
|
-
tags: Schema.mutable(Schema.Array(Schema.String)),
|
|
49
|
-
/** Optional structured image metadata. */
|
|
50
|
-
ogImage: Schema.optional(OpenGraphImageMetadata),
|
|
51
|
-
/** Open Graph object type (e.g. `"article"`). */
|
|
52
|
-
ogType: Schema.String
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
//#endregion
|
|
56
|
-
export { OpenGraphImageConfig, OpenGraphImageMetadata };
|