cargo-json-docs 0.5.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/LICENCE +21 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +26 -0
- package/dist/errors.js.map +1 -0
- package/dist/item.d.ts +100 -0
- package/dist/item.d.ts.map +1 -0
- package/dist/item.js +589 -0
- package/dist/item.js.map +1 -0
- package/dist/json.d.ts +81 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +226 -0
- package/dist/json.js.map +1 -0
- package/dist/lib.d.ts +21 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +36 -0
- package/dist/lib.js.map +1 -0
- package/package.json +26 -0
- package/readme.md +95 -0
- package/src/errors.ts +31 -0
- package/src/item.ts +658 -0
- package/src/json.ts +274 -0
- package/src/lib.ts +30 -0
- package/src/types.d.ts +84 -0
- package/test/item.test.d.ts +2 -0
- package/test/item.test.d.ts.map +1 -0
- package/test/item.test.js +107 -0
- package/test/item.test.js.map +1 -0
- package/test/item.test.ts +128 -0
- package/test/json.test.d.ts +2 -0
- package/test/json.test.d.ts.map +1 -0
- package/test/json.test.js +24 -0
- package/test/json.test.js.map +1 -0
- package/test/json.test.ts +29 -0
- package/test/test_crate/Cargo.lock +74 -0
- package/test/test_crate/Cargo.toml +7 -0
- package/test/test_crate/src/lib.rs +50 -0
- package/test/test_crate/src/module_a.rs +16 -0
- package/test/test_crate/src/module_b/inner_b.rs +10 -0
- package/test/test_crate/src/module_b.rs +1 -0
- package/tsconfig.json +23 -0
package/dist/json.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export interface CrateMetaData {
|
|
2
|
+
name: string;
|
|
3
|
+
version: string;
|
|
4
|
+
documentation: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Reads the Cargo.toml file to get the crate metadata.
|
|
8
|
+
* @param cargoTomlPath The path to the Cargo.toml file.
|
|
9
|
+
* @returns The crate metadata, or null if not found.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getCargoMeta(cargoTomlPath: string): CrateMetaData | null;
|
|
12
|
+
export declare function getCargoBinPath(): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Represents a source of documentation for a Rust crate.
|
|
15
|
+
*
|
|
16
|
+
* Note: Crate - not workspace. I don't currently support workspaces.
|
|
17
|
+
* PRs welcome to add this feature.
|
|
18
|
+
*/
|
|
19
|
+
export declare class DocumentationSource {
|
|
20
|
+
/**
|
|
21
|
+
* The path to the crate source.
|
|
22
|
+
*/
|
|
23
|
+
path: string;
|
|
24
|
+
/**
|
|
25
|
+
* The name of the crate.
|
|
26
|
+
*/
|
|
27
|
+
name: string;
|
|
28
|
+
/**
|
|
29
|
+
* The root URL for the crate's documentation.
|
|
30
|
+
*/
|
|
31
|
+
docs_root: string;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new DocumentationSource instance.
|
|
34
|
+
* @param crate_path The path to the crate source directory (where Cargo.toml is located).
|
|
35
|
+
*/
|
|
36
|
+
constructor(crate_path: string);
|
|
37
|
+
/**
|
|
38
|
+
* Gets the date and time the crate was last modified.
|
|
39
|
+
* Checks Cargo.toml and the src/ directory.
|
|
40
|
+
* @returns The last modification date.
|
|
41
|
+
*/
|
|
42
|
+
lastModified(): Date;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the date and time the documentation JSON was last modified.
|
|
45
|
+
* Checks for a *.json file in the doc directory.
|
|
46
|
+
* @returns The last modification date, or null if no JSON file found.
|
|
47
|
+
*/
|
|
48
|
+
jsonModified(): Date | null;
|
|
49
|
+
/**
|
|
50
|
+
* Determines if the documentation JSON should be regenerated.
|
|
51
|
+
* Compares the last modified time of the crate source and the JSON file.
|
|
52
|
+
* @returns True if the JSON should be regenerated, false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
shouldGenerate(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the path to the documentation directory.
|
|
57
|
+
* @returns The path to the documentation directory.
|
|
58
|
+
*/
|
|
59
|
+
getDocPath(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the path to the documentation JSON file.
|
|
62
|
+
* @returns The path to the JSON file, or null if not found.
|
|
63
|
+
*/
|
|
64
|
+
getJsonPath(): string | null;
|
|
65
|
+
/**
|
|
66
|
+
* Calls the cargo binary with the specified arguments.
|
|
67
|
+
* @param args The arguments to pass to cargo.
|
|
68
|
+
* @returns The exit code of the cargo process.
|
|
69
|
+
*/
|
|
70
|
+
callCargo(args: string[]): number;
|
|
71
|
+
/**
|
|
72
|
+
* Generates the documentation JSON using `cargo +nighly rustdoc --lub -- -Z unstable-options --output-format json`.
|
|
73
|
+
*/
|
|
74
|
+
generateJson(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Gets the documentation JSON, generating it if necessary.
|
|
77
|
+
* @returns The parsed JSON object.
|
|
78
|
+
*/
|
|
79
|
+
getJson(): any;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CA0BxE;AAqCD,wBAAgB,eAAe,IAAI,MAAM,GAAG,IAAI,CAuB/C;AAID;;;;;GAKG;AACH,qBAAa,mBAAmB;IAC5B;;OAEG;IACI,IAAI,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACI,IAAI,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACI,SAAS,EAAE,MAAM,CAAC;IAEzB;;;OAGG;gBACS,UAAU,EAAE,MAAM;IAa9B;;;;OAIG;IACH,YAAY,IAAI,IAAI;IAcpB;;;;OAIG;IACH,YAAY,IAAI,IAAI,GAAG,IAAI;IAS3B;;;;OAIG;IACH,cAAc,IAAI,OAAO;IAUzB;;;OAGG;IACH,UAAU,IAAI,MAAM;IAWpB;;;OAGG;IACH,WAAW,IAAI,MAAM,GAAG,IAAI;IAe5B;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM;IAcjC;;OAEG;IACH,YAAY,IAAI,IAAI;IAQpB;;;OAGG;IACH,OAAO,IAAI,GAAG;CAajB"}
|
package/dist/json.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DocumentationSource = void 0;
|
|
7
|
+
exports.getCargoMeta = getCargoMeta;
|
|
8
|
+
exports.getCargoBinPath = getCargoBinPath;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const child_process_1 = require("child_process");
|
|
12
|
+
/**
|
|
13
|
+
* Reads the Cargo.toml file to get the crate metadata.
|
|
14
|
+
* @param cargoTomlPath The path to the Cargo.toml file.
|
|
15
|
+
* @returns The crate metadata, or null if not found.
|
|
16
|
+
*/
|
|
17
|
+
function getCargoMeta(cargoTomlPath) {
|
|
18
|
+
if (!fs_1.default.existsSync(cargoTomlPath)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const cargoTomlContent = fs_1.default.readFileSync(cargoTomlPath, 'utf-8');
|
|
22
|
+
const packageSection = cargoTomlContent.match(/\[package\]([\s\S]*?)(\n\[|$)/);
|
|
23
|
+
if (!packageSection)
|
|
24
|
+
return null;
|
|
25
|
+
const section = packageSection[1];
|
|
26
|
+
const nameMatch = section.match(/^\s*name\s*=\s*["']([^"']+)["']/m);
|
|
27
|
+
if (!nameMatch) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const name = nameMatch[1];
|
|
31
|
+
const versionMatch = section.match(/^\s*version\s*=\s*["']([^"']+)["']/m);
|
|
32
|
+
const version = versionMatch ? versionMatch[1] : '0.0.0';
|
|
33
|
+
const documentationMatch = section.match(/^\s*documentation\s*=\s*["']([^"']+)["']/m);
|
|
34
|
+
const documentation = documentationMatch ? documentationMatch[1] : `https://docs.rs/crate/${name}/latest`;
|
|
35
|
+
let meta = { name, version, documentation };
|
|
36
|
+
return meta;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Recursively walks a directory to find the latest modification time among all files and subdirectories.
|
|
40
|
+
* @param dirPath The directory path to walk.
|
|
41
|
+
* @returns The latest modification date found.
|
|
42
|
+
*/
|
|
43
|
+
function walkDirForLatestModTime(dirPath) {
|
|
44
|
+
let latestModTime = new Date(0);
|
|
45
|
+
const entries = fs_1.default.readdirSync(dirPath, { withFileTypes: true });
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
const fullPath = path_1.default.join(dirPath, entry.name);
|
|
48
|
+
const stats = fs_1.default.statSync(fullPath);
|
|
49
|
+
if (stats.isSymbolicLink())
|
|
50
|
+
continue;
|
|
51
|
+
if (stats.mtime > latestModTime) {
|
|
52
|
+
latestModTime = stats.mtime;
|
|
53
|
+
}
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
const dirModTime = walkDirForLatestModTime(fullPath);
|
|
56
|
+
if (dirModTime > latestModTime) {
|
|
57
|
+
latestModTime = dirModTime;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return latestModTime;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets the path to the cargo binary.
|
|
65
|
+
* Checks CARGO_HOME environment variable, defaults to ~/.cargo/bin/cargo.
|
|
66
|
+
* @returns The path to the cargo binary, or null if not found.
|
|
67
|
+
*/
|
|
68
|
+
let cachedCargoPath = null;
|
|
69
|
+
function getCargoBinPath() {
|
|
70
|
+
if (cachedCargoPath !== null) {
|
|
71
|
+
return cachedCargoPath;
|
|
72
|
+
}
|
|
73
|
+
// First run the command 'where cargo' (Windows) or 'which cargo' (Unix)
|
|
74
|
+
const isWindows = process.platform === 'win32';
|
|
75
|
+
const command = isWindows ? 'where' : 'which';
|
|
76
|
+
const result = (0, child_process_1.spawnSync)(command, ['cargo'], { encoding: 'utf-8' });
|
|
77
|
+
if (result.status === 0) {
|
|
78
|
+
const cargoPath = result.stdout.split('\n')[0].trim();
|
|
79
|
+
return cargoPath;
|
|
80
|
+
}
|
|
81
|
+
// Fallback to CARGO_HOME or default path
|
|
82
|
+
const cargoHome = process.env.CARGO_HOME || path_1.default.join(process.env.HOME || process.env.USERPROFILE || '', '.cargo');
|
|
83
|
+
const cargoBin = path_1.default.join(cargoHome, 'bin', isWindows ? 'cargo.exe' : 'cargo');
|
|
84
|
+
if (fs_1.default.existsSync(cargoBin)) {
|
|
85
|
+
cachedCargoPath = cargoBin;
|
|
86
|
+
return cargoBin;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
// Cache exe path
|
|
91
|
+
/**
|
|
92
|
+
* Represents a source of documentation for a Rust crate.
|
|
93
|
+
*
|
|
94
|
+
* Note: Crate - not workspace. I don't currently support workspaces.
|
|
95
|
+
* PRs welcome to add this feature.
|
|
96
|
+
*/
|
|
97
|
+
class DocumentationSource {
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new DocumentationSource instance.
|
|
100
|
+
* @param crate_path The path to the crate source directory (where Cargo.toml is located).
|
|
101
|
+
*/
|
|
102
|
+
constructor(crate_path) {
|
|
103
|
+
this.path = crate_path;
|
|
104
|
+
const cargoTomlPath = path_1.default.join(this.path, 'Cargo.toml');
|
|
105
|
+
const metadata = getCargoMeta(cargoTomlPath);
|
|
106
|
+
if (metadata === null) {
|
|
107
|
+
throw new Error(`Could not determine crate name from ${cargoTomlPath}`);
|
|
108
|
+
}
|
|
109
|
+
this.name = metadata.name;
|
|
110
|
+
this.docs_root = metadata.documentation;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets the date and time the crate was last modified.
|
|
114
|
+
* Checks Cargo.toml and the src/ directory.
|
|
115
|
+
* @returns The last modification date.
|
|
116
|
+
*/
|
|
117
|
+
lastModified() {
|
|
118
|
+
let cargoTomlStat = fs_1.default.statSync(path_1.default.join(this.path, 'Cargo.toml'));
|
|
119
|
+
let srcDirStat = fs_1.default.statSync(path_1.default.join(this.path, 'src'));
|
|
120
|
+
let lastModified = cargoTomlStat.mtime;
|
|
121
|
+
let srcLastModified = walkDirForLatestModTime(path_1.default.join(this.path, 'src'));
|
|
122
|
+
if (srcLastModified > lastModified) {
|
|
123
|
+
lastModified = srcLastModified;
|
|
124
|
+
}
|
|
125
|
+
return lastModified;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Gets the date and time the documentation JSON was last modified.
|
|
129
|
+
* Checks for a *.json file in the doc directory.
|
|
130
|
+
* @returns The last modification date, or null if no JSON file found.
|
|
131
|
+
*/
|
|
132
|
+
jsonModified() {
|
|
133
|
+
let file = this.getJsonPath();
|
|
134
|
+
if (file === null)
|
|
135
|
+
return null;
|
|
136
|
+
let stat = fs_1.default.statSync(file);
|
|
137
|
+
if (!stat)
|
|
138
|
+
return null;
|
|
139
|
+
return stat.mtime;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Determines if the documentation JSON should be regenerated.
|
|
143
|
+
* Compares the last modified time of the crate source and the JSON file.
|
|
144
|
+
* @returns True if the JSON should be regenerated, false otherwise.
|
|
145
|
+
*/
|
|
146
|
+
shouldGenerate() {
|
|
147
|
+
let jsonMod = this.jsonModified();
|
|
148
|
+
if (jsonMod === null) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
let lastMod = this.lastModified();
|
|
152
|
+
return lastMod > jsonMod;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Gets the path to the documentation directory.
|
|
156
|
+
* @returns The path to the documentation directory.
|
|
157
|
+
*/
|
|
158
|
+
getDocPath() {
|
|
159
|
+
// Check for CARGO_TARGET_DIR environment variable
|
|
160
|
+
let cargoTargetDir = process.env.CARGO_TARGET_DIR;
|
|
161
|
+
let docDir = path_1.default.join(this.path, 'target', 'doc');
|
|
162
|
+
if (cargoTargetDir) {
|
|
163
|
+
docDir = path_1.default.join(cargoTargetDir, 'doc');
|
|
164
|
+
}
|
|
165
|
+
return docDir;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Gets the path to the documentation JSON file.
|
|
169
|
+
* @returns The path to the JSON file, or null if not found.
|
|
170
|
+
*/
|
|
171
|
+
getJsonPath() {
|
|
172
|
+
let docDir = this.getDocPath();
|
|
173
|
+
if (!fs_1.default.existsSync(docDir)) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
let files = fs_1.default.readdirSync(docDir);
|
|
177
|
+
let jsonFiles = files.filter((f) => f == `${this.name}.json`);
|
|
178
|
+
if (jsonFiles.length === 0) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
return path_1.default.join(docDir, jsonFiles[0]);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Calls the cargo binary with the specified arguments.
|
|
185
|
+
* @param args The arguments to pass to cargo.
|
|
186
|
+
* @returns The exit code of the cargo process.
|
|
187
|
+
*/
|
|
188
|
+
callCargo(args) {
|
|
189
|
+
let bin = getCargoBinPath();
|
|
190
|
+
if (bin === null) {
|
|
191
|
+
throw new Error('Cargo binary not found.');
|
|
192
|
+
}
|
|
193
|
+
let result = (0, child_process_1.spawnSync)(bin, args, {
|
|
194
|
+
cwd: this.path,
|
|
195
|
+
stdio: 'inherit',
|
|
196
|
+
});
|
|
197
|
+
return result.status || 0;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Generates the documentation JSON using `cargo +nighly rustdoc --lub -- -Z unstable-options --output-format json`.
|
|
201
|
+
*/
|
|
202
|
+
generateJson() {
|
|
203
|
+
let result = this.callCargo(['+nightly', 'rustdoc', '--lib', '--', '-Z', 'unstable-options', '--output-format', 'json']);
|
|
204
|
+
console.log(`Cargo rustdoc exited with code ${result}`);
|
|
205
|
+
if (result !== 0) {
|
|
206
|
+
throw new Error('Failed to generate documentation JSON.');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Gets the documentation JSON, generating it if necessary.
|
|
211
|
+
* @returns The parsed JSON object.
|
|
212
|
+
*/
|
|
213
|
+
getJson() {
|
|
214
|
+
if (this.shouldGenerate()) {
|
|
215
|
+
this.generateJson();
|
|
216
|
+
}
|
|
217
|
+
let jsonPath = this.getJsonPath();
|
|
218
|
+
if (jsonPath === null) {
|
|
219
|
+
throw new Error('Documentation JSON file not found after generation.');
|
|
220
|
+
}
|
|
221
|
+
let jsonData = fs_1.default.readFileSync(jsonPath, 'utf-8');
|
|
222
|
+
return JSON.parse(jsonData);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.DocumentationSource = DocumentationSource;
|
|
226
|
+
//# sourceMappingURL=json.js.map
|
package/dist/json.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;;;;AAeA,oCA0BC;AAqCD,0CAuBC;AArGD,4CAAoB;AACpB,gDAAwB;AACxB,iDAA0C;AAQ1C;;;;GAIG;AACH,SAAgB,YAAY,CAAC,aAAqB;IAC9C,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,gBAAgB,GAAG,YAAE,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAEjE,MAAM,cAAc,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EAAE,EAAE,CAAC;YACxB,IAAI,CAAC,YAAY,EAAE,CAAC;QACxB,CAAC;QAED,IAAI,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAClC,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QAC3E,CAAC;QAED,IAAI,QAAQ,GAAG,YAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;CACJ;AAlKD,kDAkKC"}
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DocumentationSource } from "./json";
|
|
2
|
+
import { CrateDocs } from "./item";
|
|
3
|
+
import { ResolutionError, CargoFormatError } from "./errors";
|
|
4
|
+
export { DocumentationSource, CrateDocs, ResolutionError, CargoFormatError };
|
|
5
|
+
/**
|
|
6
|
+
* Loads a crate's documentation from source.
|
|
7
|
+
* @param name The name of the crate.
|
|
8
|
+
* @param docs_root The root URL for the crate's documentation.
|
|
9
|
+
* @param path The path to the crate's source directory (e.g., the directory containing Cargo.toml).
|
|
10
|
+
* @returns The loaded CrateDocs object.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadCrate(path: string): CrateDocs;
|
|
13
|
+
/**
|
|
14
|
+
* Loads a crate's documentation from a JSON string.
|
|
15
|
+
* @param name The name of the crate.
|
|
16
|
+
* @param docs_root The root URL for the crate's documentation.
|
|
17
|
+
* @param json The JSON string containing the documentation data.
|
|
18
|
+
* @returns The loaded CrateDocs object.
|
|
19
|
+
*/
|
|
20
|
+
export declare function loadCrateFromJson(name: string, docs_root: string, json: string): CrateDocs;
|
|
21
|
+
//# sourceMappingURL=lib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC;AAE7E;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAIjD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAG1F"}
|
package/dist/lib.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CargoFormatError = exports.ResolutionError = exports.CrateDocs = exports.DocumentationSource = void 0;
|
|
4
|
+
exports.loadCrate = loadCrate;
|
|
5
|
+
exports.loadCrateFromJson = loadCrateFromJson;
|
|
6
|
+
const json_1 = require("./json");
|
|
7
|
+
Object.defineProperty(exports, "DocumentationSource", { enumerable: true, get: function () { return json_1.DocumentationSource; } });
|
|
8
|
+
const item_1 = require("./item");
|
|
9
|
+
Object.defineProperty(exports, "CrateDocs", { enumerable: true, get: function () { return item_1.CrateDocs; } });
|
|
10
|
+
const errors_1 = require("./errors");
|
|
11
|
+
Object.defineProperty(exports, "ResolutionError", { enumerable: true, get: function () { return errors_1.ResolutionError; } });
|
|
12
|
+
Object.defineProperty(exports, "CargoFormatError", { enumerable: true, get: function () { return errors_1.CargoFormatError; } });
|
|
13
|
+
/**
|
|
14
|
+
* Loads a crate's documentation from source.
|
|
15
|
+
* @param name The name of the crate.
|
|
16
|
+
* @param docs_root The root URL for the crate's documentation.
|
|
17
|
+
* @param path The path to the crate's source directory (e.g., the directory containing Cargo.toml).
|
|
18
|
+
* @returns The loaded CrateDocs object.
|
|
19
|
+
*/
|
|
20
|
+
function loadCrate(path) {
|
|
21
|
+
const docSource = new json_1.DocumentationSource(path);
|
|
22
|
+
const jsonSource = docSource.getJson();
|
|
23
|
+
return new item_1.CrateDocs(docSource.name, docSource.docs_root, jsonSource);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Loads a crate's documentation from a JSON string.
|
|
27
|
+
* @param name The name of the crate.
|
|
28
|
+
* @param docs_root The root URL for the crate's documentation.
|
|
29
|
+
* @param json The JSON string containing the documentation data.
|
|
30
|
+
* @returns The loaded CrateDocs object.
|
|
31
|
+
*/
|
|
32
|
+
function loadCrateFromJson(name, docs_root, json) {
|
|
33
|
+
const source = JSON.parse(json);
|
|
34
|
+
return new item_1.CrateDocs(name, docs_root, source);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=lib.js.map
|
package/dist/lib.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":";;;AAaA,8BAIC;AASD,8CAGC;AA7BD,iCAA6C;AAIpC,oGAJA,0BAAmB,OAIA;AAH5B,iCAAmC;AAGL,0FAHrB,gBAAS,OAGqB;AAFvC,qCAA6D;AAEpB,gGAFhC,wBAAe,OAEgC;AAAE,iGAFhC,yBAAgB,OAEgC;AAE1E;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,IAAY;IAClC,MAAM,SAAS,GAAG,IAAI,0BAAmB,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;IACvC,OAAO,IAAI,gBAAS,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AAC1E,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,IAAY,EAAE,SAAiB,EAAE,IAAY;IAC3E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,IAAI,gBAAS,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cargo-json-docs",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Programmatic access to Rust crate documentation via cargo JSON output",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Richard Carson",
|
|
7
|
+
"repository": "https://github.com/rscarson/cargo-json-docs",
|
|
8
|
+
"readme": "readme.md",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "dist/lib.js",
|
|
11
|
+
"types": "dist/types.d.ts",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"test": "vitest",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/jest": "^30.0.0",
|
|
19
|
+
"@types/node": "^25.0.3",
|
|
20
|
+
"jest": "^30.2.0",
|
|
21
|
+
"node-fetch": "^3.3.2",
|
|
22
|
+
"ts-node": "^10.9.2",
|
|
23
|
+
"typescript": "^5.9.3",
|
|
24
|
+
"vitest": "^4.0.16"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# cargo-json-docs
|
|
2
|
+
## Programmatic access to Rust crate documentation via cargo JSON output
|
|
3
|
+
|
|
4
|
+
Gives you access to a rust crate's documentation (functions, structs, enums, traits, constants, type aliases, macros, and modules) by their Rust path. Documentation can be loaded from a local crate source directory, or from pre-generated rustdoc JSON.
|
|
5
|
+
|
|
6
|
+
The `docs.rs` documentation URL for each item is also provided for easy linking.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install cargo-json-docs
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
### `loadCrate(path: string): CrateDocs`
|
|
17
|
+
|
|
18
|
+
Loads documentation from a local crate source directory (must contain `Cargo.toml`).
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { loadCrate } from 'cargo-json-docs';
|
|
22
|
+
|
|
23
|
+
const docs = loadCrate('path/to/crate');
|
|
24
|
+
const item = docs.get('module::Type::method');
|
|
25
|
+
console.log(item.url);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### `loadCrateFromJson(name: string, docs_root: string, json: string): CrateDocs`
|
|
29
|
+
|
|
30
|
+
Loads documentation from a JSON string (pre-generated rustdoc JSON).
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { loadCrateFromJson } from 'cargo-json-docs';
|
|
34
|
+
|
|
35
|
+
const jsonString = fs.readFileSync('crate.json', 'utf-8');
|
|
36
|
+
const docs = loadCrateFromJson('crate_name', 'https://docs.rs/crate_name/latest/', jsonString);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### `DocumentationSource`
|
|
40
|
+
|
|
41
|
+
Represents the source of a crate’s documentation. Handles:
|
|
42
|
+
|
|
43
|
+
* Cargo doc generation
|
|
44
|
+
* JSON generation and caching
|
|
45
|
+
* Stale JSON detection by file modification time
|
|
46
|
+
|
|
47
|
+
Methods:
|
|
48
|
+
|
|
49
|
+
* `lastModified(): Date` — Returns last modification timestamp
|
|
50
|
+
* `shouldGenerate(): boolean` — True if JSON generation is needed
|
|
51
|
+
* `generateJson(): void` — Generates rustdoc JSON
|
|
52
|
+
* `getJson(): any` — Retrieves the JSON object
|
|
53
|
+
* `callCargo(args: string[]): number` — Runs cargo commands
|
|
54
|
+
|
|
55
|
+
### `CrateDocs`
|
|
56
|
+
|
|
57
|
+
Provides lookup of documented items by path:
|
|
58
|
+
|
|
59
|
+
* `get(path: string): DocumentedItem | undefined` — Retrieves item metadata
|
|
60
|
+
* `DocumentedItem` fields:
|
|
61
|
+
|
|
62
|
+
* `name: string`
|
|
63
|
+
* `path: string`
|
|
64
|
+
* `kind: ItemKind`
|
|
65
|
+
* `url: string`
|
|
66
|
+
|
|
67
|
+
### Errors
|
|
68
|
+
|
|
69
|
+
* `ResolutionError` — Path lookup failure
|
|
70
|
+
* `CargoFormatError` — Cargo JSON generation failure. This usually indicates a change in the JSON format used by rustdoc - please open a GitHub issue if you encounter this error.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Example
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { loadCrate } from 'cargo-json-docs';
|
|
78
|
+
|
|
79
|
+
const docs = loadCrate('test/test_crate');
|
|
80
|
+
const addFn = docs.get('add');
|
|
81
|
+
|
|
82
|
+
if (addFn) {
|
|
83
|
+
console.log(addFn.kind); // 'function'
|
|
84
|
+
console.log(addFn.url); // 'https://docs.rs/crate/test_crate/latest/test_crate/fn.add.html'
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Assumptions & Limitations
|
|
91
|
+
|
|
92
|
+
* Cargo needs to be installed and in PATH somewhere
|
|
93
|
+
* Rust crate must build locally; `cargo doc` required
|
|
94
|
+
* It will attempt to call the nighlty toolchain, since json output is only supported there
|
|
95
|
+
* There's likely to be edge cases that aren't handled yet - please open issues as needed!
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* An error that occurs when resolving an item path.
|
|
4
|
+
*/
|
|
5
|
+
export class ResolutionError extends Error {
|
|
6
|
+
/**
|
|
7
|
+
* The last successfully resolved parent path.
|
|
8
|
+
*/
|
|
9
|
+
last_good_parent: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The unresolved item name.
|
|
13
|
+
*/
|
|
14
|
+
unresolved: string;
|
|
15
|
+
|
|
16
|
+
constructor(last_good_parent: string, unresolved: string) {
|
|
17
|
+
super(`${last_good_parent}::${unresolved} does not exist or could not be resolved.`);
|
|
18
|
+
this.last_good_parent = last_good_parent;
|
|
19
|
+
this.unresolved = unresolved;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* An error that occurs when the documentation JSON format is not as expected.
|
|
24
|
+
* Usually means the format has changed for the version of Rust used to generate the docs.
|
|
25
|
+
* Open a GitHub issue if you encounter this error.
|
|
26
|
+
*/
|
|
27
|
+
export class CargoFormatError extends Error {
|
|
28
|
+
constructor(message: string) {
|
|
29
|
+
super(`JSON format unrecognized or invalid. Please open a GitHub issue if you see this message.\nDetails: ${message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|