@xh/hoist-docs 0.0.0-stage → 0.0.1
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/LICENSE.md +190 -0
- package/README.md +145 -2
- package/bin/hoist-docs.mjs +16 -0
- package/dist/IndexStore.d.ts +78 -0
- package/dist/IndexStore.js +249 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +258 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +18 -0
- package/dist/docs/index.d.ts +70 -0
- package/dist/docs/index.js +101 -0
- package/dist/index/DocEntry.d.ts +16 -0
- package/dist/index/DocEntry.js +32 -0
- package/dist/index/DocIdResolver.d.ts +31 -0
- package/dist/index/DocIdResolver.js +159 -0
- package/dist/index/DocSearch.d.ts +41 -0
- package/dist/index/DocSearch.js +180 -0
- package/dist/index/LibraryIndex.d.ts +62 -0
- package/dist/index/LibraryIndex.js +153 -0
- package/dist/index/SymbolSearch.d.ts +52 -0
- package/dist/index/SymbolSearch.js +249 -0
- package/dist/index/doc-sections.d.ts +94 -0
- package/dist/index/doc-sections.js +260 -0
- package/dist/index/search-text.d.ts +78 -0
- package/dist/index/search-text.js +140 -0
- package/dist/index/types.d.ts +115 -0
- package/dist/index/types.js +11 -0
- package/dist/libraries.d.ts +57 -0
- package/dist/libraries.js +38 -0
- package/dist/local/cache.d.ts +25 -0
- package/dist/local/cache.js +62 -0
- package/dist/local/checkout.d.ts +6 -0
- package/dist/local/checkout.js +178 -0
- package/dist/local/installed.d.ts +22 -0
- package/dist/local/installed.js +99 -0
- package/dist/local/maven.d.ts +49 -0
- package/dist/local/maven.js +184 -0
- package/dist/local/npm.d.ts +24 -0
- package/dist/local/npm.js +66 -0
- package/dist/local/project.d.ts +26 -0
- package/dist/local/project.js +103 -0
- package/dist/local/registry.d.ts +15 -0
- package/dist/local/registry.js +67 -0
- package/dist/local/sources.d.ts +30 -0
- package/dist/local/sources.js +50 -0
- package/dist/local/tar.d.ts +6 -0
- package/dist/local/tar.js +31 -0
- package/dist/log.d.ts +10 -0
- package/dist/log.js +31 -0
- package/dist/mcp.d.ts +23 -0
- package/dist/mcp.js +396 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.js +88 -0
- package/dist/tools/DocTools.d.ts +19 -0
- package/dist/tools/DocTools.js +245 -0
- package/dist/tools/SymbolTools.d.ts +27 -0
- package/dist/tools/SymbolTools.js +572 -0
- package/dist/tools/types.d.ts +6 -0
- package/dist/tools/types.js +7 -0
- package/dist/usage.d.ts +10 -0
- package/dist/usage.js +11 -0
- package/package.json +62 -4
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IndexCache } from './cache.ts';
|
|
2
|
+
import type { Registry } from './registry.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Pulls the index out of a published npm package, where a TypeScript library ships it (declared by
|
|
5
|
+
* `hoistDocs.index` in its `package.json`), into the local cache. For when the package is not
|
|
6
|
+
* installed: a gateway serving any release, or a library checkout serving another library's newest
|
|
7
|
+
* snapshot. An installed package's index is read in place (see `installed.ts`).
|
|
8
|
+
*/
|
|
9
|
+
export declare class NpmSource {
|
|
10
|
+
private readonly registry;
|
|
11
|
+
private readonly cache;
|
|
12
|
+
private readonly now;
|
|
13
|
+
constructor(registry: Registry, cache?: IndexCache, now?: () => number);
|
|
14
|
+
/** Local path of the index shipped in `version` of `pkg`, fetching it if needed. */
|
|
15
|
+
resolve(pkg: string, version: string): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* The version and index a dist-tag (`latest`, `next`) points at, rechecked at most daily. When
|
|
18
|
+
* the registry cannot be reached, the last one fetched is used.
|
|
19
|
+
*/
|
|
20
|
+
resolveTag(pkg: string, tag: string): Promise<{
|
|
21
|
+
version: string;
|
|
22
|
+
path: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
import { log } from '../log.js';
|
|
8
|
+
import { IndexCache, RECHECK_MS } from './cache.js';
|
|
9
|
+
import { readFromTgz } from './tar.js';
|
|
10
|
+
/**
|
|
11
|
+
* Pulls the index out of a published npm package, where a TypeScript library ships it (declared by
|
|
12
|
+
* `hoistDocs.index` in its `package.json`), into the local cache. For when the package is not
|
|
13
|
+
* installed: a gateway serving any release, or a library checkout serving another library's newest
|
|
14
|
+
* snapshot. An installed package's index is read in place (see `installed.ts`).
|
|
15
|
+
*/
|
|
16
|
+
export class NpmSource {
|
|
17
|
+
registry;
|
|
18
|
+
cache;
|
|
19
|
+
now;
|
|
20
|
+
constructor(registry, cache = new IndexCache(), now = Date.now) {
|
|
21
|
+
this.registry = registry;
|
|
22
|
+
this.cache = cache;
|
|
23
|
+
this.now = now;
|
|
24
|
+
}
|
|
25
|
+
/** Local path of the index shipped in `version` of `pkg`, fetching it if needed. */
|
|
26
|
+
async resolve(pkg, version) {
|
|
27
|
+
const name = `${slug(pkg)}-${version}.json.gz`;
|
|
28
|
+
if (this.cache.has(name))
|
|
29
|
+
return this.cache.path(name);
|
|
30
|
+
const tgz = await this.registry.pack(pkg, version), pkgJson = readFromTgz(tgz, 'package/package.json'), indexPath = pkgJson && JSON.parse(pkgJson.toString('utf8')).hoistDocs?.index, index = indexPath && readFromTgz(tgz, `package/${indexPath.replace(/^\.\//, '')}`);
|
|
31
|
+
if (!index) {
|
|
32
|
+
throw new Error(`${pkg}@${version} ships no Hoist Docs index - releases from before Hoist Docs shipped indexes carry none. Upgrade, or serve an index directory (INDEX_DIR).`);
|
|
33
|
+
}
|
|
34
|
+
const path = this.cache.write(name, index);
|
|
35
|
+
log.info('Fetched index', { pkg, version });
|
|
36
|
+
return path;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The version and index a dist-tag (`latest`, `next`) points at, rechecked at most daily. When
|
|
40
|
+
* the registry cannot be reached, the last one fetched is used.
|
|
41
|
+
*/
|
|
42
|
+
async resolveTag(pkg, tag) {
|
|
43
|
+
const key = `npm:${pkg}#${tag}`, cached = this.cache.resolution(key), cachedVersion = () => cached.file.slice(slug(pkg).length + 1, -'.json.gz'.length);
|
|
44
|
+
if (cached && this.now() - cached.checkedAt < RECHECK_MS) {
|
|
45
|
+
return { version: cachedVersion(), path: this.cache.path(cached.file) };
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const version = await this.registry.distTag(pkg, tag);
|
|
49
|
+
if (!version)
|
|
50
|
+
throw new Error(`${pkg} has no '${tag}' dist-tag`);
|
|
51
|
+
const path = await this.resolve(pkg, version);
|
|
52
|
+
this.cache.setResolution(key, `${slug(pkg)}-${version}.json.gz`, this.now());
|
|
53
|
+
return { version, path };
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
if (!cached)
|
|
57
|
+
throw e;
|
|
58
|
+
log.warn('npm registry unreachable - using cached index', { pkg, tag, error: String(e) });
|
|
59
|
+
return { version: cachedVersion(), path: this.cache.path(cached.file) };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** `@xh/hoist` to `xh-hoist`, for file names. */
|
|
64
|
+
function slug(pkg) {
|
|
65
|
+
return pkg.replace(/^@/, '').replace(/\//g, '-');
|
|
66
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The versions of the built-in libraries a project uses, as found on disk. */
|
|
2
|
+
export interface ProjectVersions {
|
|
3
|
+
/** Version of each library the project uses, by library id. Libraries it lacks are absent. */
|
|
4
|
+
versions: Record<string, string>;
|
|
5
|
+
/** Problems worth telling the developer about, e.g. dependencies not installed. */
|
|
6
|
+
notes: string[];
|
|
7
|
+
/** The library, if `root` is a checkout of a built-in library itself. */
|
|
8
|
+
checkout?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Version standing for a library's newest published snapshot: npm's `next` dist-tag, or the
|
|
12
|
+
* newest snapshot in the Maven snapshot repository. Served in a library checkout, which has no
|
|
13
|
+
* installed build of itself.
|
|
14
|
+
*/
|
|
15
|
+
export declare const LATEST_SNAPSHOT = "latest-snapshot";
|
|
16
|
+
/**
|
|
17
|
+
* Find the versions of the built-in libraries the project at `root` uses. An npm library's is the
|
|
18
|
+
* exact version installed in `client-app/node_modules` (or `node_modules`), rather than the range
|
|
19
|
+
* in package.json, since that is the code the app actually runs; hoist-core's is
|
|
20
|
+
* `hoistCoreVersion` from `gradle.properties`.
|
|
21
|
+
*
|
|
22
|
+
* A checkout of a built-in library itself is served its own newest published snapshot - for
|
|
23
|
+
* hoist-core, the newest build of its own snapshot line - plus the other libraries as installed
|
|
24
|
+
* there, else, for hoist-react and hoist-core, their newest published snapshots.
|
|
25
|
+
*/
|
|
26
|
+
export declare function detectProjectVersions(root: string): ProjectVersions;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
import { join, resolve } from 'node:path';
|
|
9
|
+
import { LIBRARIES } from '../libraries.js';
|
|
10
|
+
/**
|
|
11
|
+
* Version standing for a library's newest published snapshot: npm's `next` dist-tag, or the
|
|
12
|
+
* newest snapshot in the Maven snapshot repository. Served in a library checkout, which has no
|
|
13
|
+
* installed build of itself.
|
|
14
|
+
*/
|
|
15
|
+
export const LATEST_SNAPSHOT = 'latest-snapshot';
|
|
16
|
+
/**
|
|
17
|
+
* Find the versions of the built-in libraries the project at `root` uses. An npm library's is the
|
|
18
|
+
* exact version installed in `client-app/node_modules` (or `node_modules`), rather than the range
|
|
19
|
+
* in package.json, since that is the code the app actually runs; hoist-core's is
|
|
20
|
+
* `hoistCoreVersion` from `gradle.properties`.
|
|
21
|
+
*
|
|
22
|
+
* A checkout of a built-in library itself is served its own newest published snapshot - for
|
|
23
|
+
* hoist-core, the newest build of its own snapshot line - plus the other libraries as installed
|
|
24
|
+
* there, else, for hoist-react and hoist-core, their newest published snapshots.
|
|
25
|
+
*/
|
|
26
|
+
export function detectProjectVersions(root) {
|
|
27
|
+
const projectRoot = resolve(root), checkout = detectCheckout(projectRoot), ret = { versions: {}, notes: [] };
|
|
28
|
+
if (checkout)
|
|
29
|
+
ret.checkout = checkout.library;
|
|
30
|
+
for (const lib of LIBRARIES) {
|
|
31
|
+
const version = checkout?.library === lib.id
|
|
32
|
+
? checkout.version
|
|
33
|
+
: (installedVersion(projectRoot, lib, ret.notes) ??
|
|
34
|
+
(checkout && !lib.optional ? LATEST_SNAPSHOT : null));
|
|
35
|
+
if (version)
|
|
36
|
+
ret.versions[lib.id] = version;
|
|
37
|
+
}
|
|
38
|
+
return ret;
|
|
39
|
+
}
|
|
40
|
+
//------------------------
|
|
41
|
+
// Implementation
|
|
42
|
+
//------------------------
|
|
43
|
+
/** The version of `lib` the project uses, or null. Notes a declared but uninstalled package. */
|
|
44
|
+
function installedVersion(root, lib, notes) {
|
|
45
|
+
if ('gradleProperty' in lib.installed) {
|
|
46
|
+
return gradleProperty(root, lib.installed.gradleProperty);
|
|
47
|
+
}
|
|
48
|
+
const name = lib.installed.npm;
|
|
49
|
+
for (const dir of [join(root, 'client-app'), root]) {
|
|
50
|
+
const installed = readJson(join(dir, 'node_modules', ...name.split('/'), 'package.json'));
|
|
51
|
+
if (installed?.version)
|
|
52
|
+
return installed.version;
|
|
53
|
+
const pkg = readJson(join(dir, 'package.json')), deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
|
|
54
|
+
if (deps[name]) {
|
|
55
|
+
notes.push(`${join(dir, 'package.json')} depends on ${name}, but it is not installed - run your package manager's install, then restart.`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/** The built-in library and version of a checkout at `root`, if it is one. */
|
|
62
|
+
function detectCheckout(root) {
|
|
63
|
+
const pkg = readJson(join(root, 'package.json')), settings = readText(join(root, 'settings.gradle'));
|
|
64
|
+
for (const lib of LIBRARIES) {
|
|
65
|
+
const c = lib.checkout;
|
|
66
|
+
if ('packageName' in c) {
|
|
67
|
+
if (pkg?.name === c.packageName)
|
|
68
|
+
return { library: lib.id, version: LATEST_SNAPSHOT };
|
|
69
|
+
}
|
|
70
|
+
else if (settings && rootProjectName(settings) === c.gradleProject) {
|
|
71
|
+
return {
|
|
72
|
+
library: lib.id,
|
|
73
|
+
version: gradleProperty(root, c.versionProperty) ?? LATEST_SNAPSHOT
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
function rootProjectName(settings) {
|
|
80
|
+
return /^\s*rootProject\.name\s*=\s*['"]([^'"]+)['"]/m.exec(settings)?.[1] ?? null;
|
|
81
|
+
}
|
|
82
|
+
function gradleProperty(root, name) {
|
|
83
|
+
const props = readText(join(root, 'gradle.properties'));
|
|
84
|
+
if (!props)
|
|
85
|
+
return null;
|
|
86
|
+
return new RegExp(`^\\s*${name}\\s*[=:]\\s*(\\S+)\\s*$`, 'm').exec(props)?.[1] ?? null;
|
|
87
|
+
}
|
|
88
|
+
function readText(path) {
|
|
89
|
+
try {
|
|
90
|
+
return readFileSync(path, 'utf8');
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function readJson(path) {
|
|
97
|
+
try {
|
|
98
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The npm registry operations the local tool needs. Injectable for tests. */
|
|
2
|
+
export interface Registry {
|
|
3
|
+
/** The version a dist-tag points at, or null. */
|
|
4
|
+
distTag(pkg: string, tag: string): Promise<string | null>;
|
|
5
|
+
/** The package tarball (.tgz) for one version. */
|
|
6
|
+
pack(pkg: string, version: string): Promise<Buffer>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Registry access through the developer's own `npm` command, so their `.npmrc` registry,
|
|
10
|
+
* credentials, proxy and certificates apply unchanged - including an organization's Artifactory.
|
|
11
|
+
*/
|
|
12
|
+
export declare class NpmRegistry implements Registry {
|
|
13
|
+
distTag(pkg: string, tag: string): Promise<string | null>;
|
|
14
|
+
pack(pkg: string, version: string): Promise<Buffer>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
import { execFile } from 'node:child_process';
|
|
8
|
+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { promisify } from 'node:util';
|
|
12
|
+
const run = promisify(execFile);
|
|
13
|
+
/**
|
|
14
|
+
* Registry access through the developer's own `npm` command, so their `.npmrc` registry,
|
|
15
|
+
* credentials, proxy and certificates apply unchanged - including an organization's Artifactory.
|
|
16
|
+
*/
|
|
17
|
+
export class NpmRegistry {
|
|
18
|
+
async distTag(pkg, tag) {
|
|
19
|
+
const out = await npmView(pkg, 'dist-tags');
|
|
20
|
+
return out == null
|
|
21
|
+
? null
|
|
22
|
+
: (JSON.parse(out || '{}')[tag] ?? null);
|
|
23
|
+
}
|
|
24
|
+
async pack(pkg, version) {
|
|
25
|
+
const dir = mkdtempSync(join(tmpdir(), 'hoist-docs-pack-'));
|
|
26
|
+
try {
|
|
27
|
+
const out = await npm([
|
|
28
|
+
'pack',
|
|
29
|
+
`${pkg}@${version}`,
|
|
30
|
+
'--json',
|
|
31
|
+
'--pack-destination',
|
|
32
|
+
dir
|
|
33
|
+
]), [{ filename }] = JSON.parse(out);
|
|
34
|
+
return readFileSync(join(dir, filename));
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
rmSync(dir, { recursive: true, force: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** `npm view <pkg> <field> --json`, or null if the package is not published. */
|
|
42
|
+
async function npmView(pkg, field) {
|
|
43
|
+
try {
|
|
44
|
+
return await npm(['view', pkg, field, '--json']);
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
if (/\bE404\b/.test(String(e)))
|
|
48
|
+
return null;
|
|
49
|
+
throw e;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function npm(args) {
|
|
53
|
+
const win = process.platform === 'win32';
|
|
54
|
+
try {
|
|
55
|
+
const { stdout } = await run(win ? 'npm.cmd' : 'npm', args, {
|
|
56
|
+
shell: win,
|
|
57
|
+
maxBuffer: 64 * 1024 * 1024
|
|
58
|
+
});
|
|
59
|
+
return stdout.trim();
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
const err = e;
|
|
63
|
+
throw new Error(`npm ${args.join(' ')} failed: ${(err.stderr || err.message).trim()}`, {
|
|
64
|
+
cause: e
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MavenSource } from './maven.ts';
|
|
2
|
+
import type { NpmSource } from './npm.ts';
|
|
3
|
+
/** Where a built-in library's index is fetched from when it is not installed. */
|
|
4
|
+
export interface LibrarySource {
|
|
5
|
+
/** The newest release of a library. */
|
|
6
|
+
latestRelease(libraryId: string): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* The local path of a library version's index, fetching it if needed. `version` may be
|
|
9
|
+
* {@link LATEST_SNAPSHOT}; the version returned is then the one it resolved to.
|
|
10
|
+
*/
|
|
11
|
+
resolve(libraryId: string, version: string): Promise<{
|
|
12
|
+
version: string;
|
|
13
|
+
path: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The built-in libraries' own channels: an npm library's published package, from which its index
|
|
18
|
+
* is pulled, or a Grails library's `docs-index` Maven artifact.
|
|
19
|
+
*/
|
|
20
|
+
export declare class BuiltInSource implements LibrarySource {
|
|
21
|
+
private readonly npm;
|
|
22
|
+
private readonly maven;
|
|
23
|
+
constructor(npm: NpmSource, maven: MavenSource);
|
|
24
|
+
latestRelease(libraryId: string): Promise<string>;
|
|
25
|
+
resolve(libraryId: string, version: string): Promise<{
|
|
26
|
+
version: string;
|
|
27
|
+
path: string;
|
|
28
|
+
}>;
|
|
29
|
+
private lib;
|
|
30
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
import { libraryDef } from '../libraries.js';
|
|
8
|
+
import { LATEST_SNAPSHOT } from './project.js';
|
|
9
|
+
/**
|
|
10
|
+
* The built-in libraries' own channels: an npm library's published package, from which its index
|
|
11
|
+
* is pulled, or a Grails library's `docs-index` Maven artifact.
|
|
12
|
+
*/
|
|
13
|
+
export class BuiltInSource {
|
|
14
|
+
npm;
|
|
15
|
+
maven;
|
|
16
|
+
constructor(npm, maven) {
|
|
17
|
+
this.npm = npm;
|
|
18
|
+
this.maven = maven;
|
|
19
|
+
}
|
|
20
|
+
async latestRelease(libraryId) {
|
|
21
|
+
const lib = this.lib(libraryId);
|
|
22
|
+
if (lib.maven)
|
|
23
|
+
return this.maven.latestRelease(lib.maven.group, lib.maven.artifact);
|
|
24
|
+
return (await this.npm.resolveTag(npmName(lib), 'latest')).version;
|
|
25
|
+
}
|
|
26
|
+
async resolve(libraryId, version) {
|
|
27
|
+
const lib = this.lib(libraryId);
|
|
28
|
+
if (lib.maven) {
|
|
29
|
+
const { group, artifact } = lib.maven, v = version === LATEST_SNAPSHOT
|
|
30
|
+
? await this.maven.latestSnapshot(group, artifact)
|
|
31
|
+
: version;
|
|
32
|
+
return { version: v, path: await this.maven.resolve(group, artifact, v) };
|
|
33
|
+
}
|
|
34
|
+
const pkg = npmName(lib);
|
|
35
|
+
return version === LATEST_SNAPSHOT
|
|
36
|
+
? this.npm.resolveTag(pkg, 'next')
|
|
37
|
+
: { version, path: await this.npm.resolve(pkg, version) };
|
|
38
|
+
}
|
|
39
|
+
lib(libraryId) {
|
|
40
|
+
const lib = libraryDef(libraryId);
|
|
41
|
+
if (!lib)
|
|
42
|
+
throw new Error(`Unknown library '${libraryId}'`);
|
|
43
|
+
return lib;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function npmName(lib) {
|
|
47
|
+
if (!('npm' in lib.installed))
|
|
48
|
+
throw new Error(`${lib.id} is not an npm library`);
|
|
49
|
+
return lib.installed.npm;
|
|
50
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read one file out of a gzipped tar (an npm package tarball), or return null if it is not
|
|
3
|
+
* there. Handles the plain ustar entries npm writes; enough to pull an index out of a
|
|
4
|
+
* package, and saves a dependency.
|
|
5
|
+
*/
|
|
6
|
+
export declare function readFromTgz(tgz: Buffer, name: string): Buffer | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
import { gunzipSync } from 'node:zlib';
|
|
8
|
+
/**
|
|
9
|
+
* Read one file out of a gzipped tar (an npm package tarball), or return null if it is not
|
|
10
|
+
* there. Handles the plain ustar entries npm writes; enough to pull an index out of a
|
|
11
|
+
* package, and saves a dependency.
|
|
12
|
+
*/
|
|
13
|
+
export function readFromTgz(tgz, name) {
|
|
14
|
+
const tar = gunzipSync(tgz);
|
|
15
|
+
let offset = 0;
|
|
16
|
+
while (offset + 512 <= tar.length) {
|
|
17
|
+
const header = tar.subarray(offset, offset + 512);
|
|
18
|
+
if (header.every(b => b === 0))
|
|
19
|
+
break;
|
|
20
|
+
const field = (start, len) => header
|
|
21
|
+
.subarray(start, start + len)
|
|
22
|
+
.toString('utf8')
|
|
23
|
+
.replace(/\0.*$/s, ''), prefix = field(345, 155), path = prefix ? `${prefix}/${field(0, 100)}` : field(0, 100), size = parseInt(field(124, 12).trim() || '0', 8), type = field(156, 1);
|
|
24
|
+
offset += 512;
|
|
25
|
+
if ((type === '0' || type === '') && path === name) {
|
|
26
|
+
return Buffer.from(tar.subarray(offset, offset + size));
|
|
27
|
+
}
|
|
28
|
+
offset += Math.ceil(size / 512) * 512;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Send every log line to stderr. Call before anything logs, when serving over stdio. */
|
|
2
|
+
export declare function logToStderr(): void;
|
|
3
|
+
export declare const log: {
|
|
4
|
+
debug: (msg: string, data?: Record<string, unknown>) => void;
|
|
5
|
+
info: (msg: string, data?: Record<string, unknown>) => void;
|
|
6
|
+
warn: (msg: string, data?: Record<string, unknown>) => void;
|
|
7
|
+
error: (msg: string, data?: Record<string, unknown>) => void;
|
|
8
|
+
};
|
|
9
|
+
/** Error details for a log line. */
|
|
10
|
+
export declare function errorData(e: unknown): Record<string, unknown>;
|
package/dist/log.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
const DEBUG = process.env.LOG_LEVEL === 'debug';
|
|
8
|
+
let allToStderr = false;
|
|
9
|
+
/** Send every log line to stderr. Call before anything logs, when serving over stdio. */
|
|
10
|
+
export function logToStderr() {
|
|
11
|
+
allToStderr = true;
|
|
12
|
+
}
|
|
13
|
+
function write(level, msg, data) {
|
|
14
|
+
if (level === 'debug' && !DEBUG)
|
|
15
|
+
return;
|
|
16
|
+
const line = JSON.stringify({ time: new Date().toISOString(), level, msg, ...data });
|
|
17
|
+
if (allToStderr || level === 'error' || level === 'warn')
|
|
18
|
+
process.stderr.write(line + '\n');
|
|
19
|
+
else
|
|
20
|
+
process.stdout.write(line + '\n');
|
|
21
|
+
}
|
|
22
|
+
export const log = {
|
|
23
|
+
debug: (msg, data) => write('debug', msg, data),
|
|
24
|
+
info: (msg, data) => write('info', msg, data),
|
|
25
|
+
warn: (msg, data) => write('warn', msg, data),
|
|
26
|
+
error: (msg, data) => write('error', msg, data)
|
|
27
|
+
};
|
|
28
|
+
/** Error details for a log line. */
|
|
29
|
+
export function errorData(e) {
|
|
30
|
+
return e instanceof Error ? { error: e.message, stack: e.stack } : { error: String(e) };
|
|
31
|
+
}
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Hoist Docs MCP server, built on the official MCP TypeScript SDK v2
|
|
3
|
+
* (`@modelcontextprotocol/server`), which implements the 2026-07-28 spec - including
|
|
4
|
+
* `server/discover` and stateless serving - and the 2025-era `initialize` handshake for older
|
|
5
|
+
* clients. {@link createMcpServer} is the server factory both transports use: `serveStdio` for the
|
|
6
|
+
* local tool, and `createMcpHandler` for HTTP (see `server.ts`).
|
|
7
|
+
*
|
|
8
|
+
* Tools keep the names, arguments and output of the stdio servers this replaces.
|
|
9
|
+
*/
|
|
10
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
11
|
+
import type { JsonSchemaType } from '@modelcontextprotocol/server';
|
|
12
|
+
import type { Config } from './config.ts';
|
|
13
|
+
import { type IndexStore } from './IndexStore.ts';
|
|
14
|
+
/** A fresh MCP server over the store's indexes - one per HTTP request, or per stdio connection. */
|
|
15
|
+
export declare function createMcpServer(store: IndexStore, config: Config): McpServer;
|
|
16
|
+
interface ToolDefinition {
|
|
17
|
+
name: string;
|
|
18
|
+
title: string;
|
|
19
|
+
description: string;
|
|
20
|
+
inputSchema: JsonSchemaType;
|
|
21
|
+
}
|
|
22
|
+
export declare const TOOL_DEFINITIONS: ToolDefinition[];
|
|
23
|
+
export {};
|