Skip to content

Commit dbb6263

Browse files
crowlKatsbartlomieju
authored andcommitted
fix(tools/doc): HTML resolve main entrypoint from config file (#27103)
Fixes #26901
1 parent 317aa50 commit dbb6263

File tree

6 files changed

+46
-10
lines changed

6 files changed

+46
-10
lines changed

cli/tools/doc.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,14 @@ pub async fn doc(
209209
Default::default()
210210
};
211211

212+
let mut main_entrypoint = None;
213+
212214
let rewrite_map =
213215
if let Some(config_file) = cli_options.start_dir.maybe_deno_json() {
214216
let config = config_file.to_exports_config()?;
215217

218+
main_entrypoint = config.get_resolved(".").ok().flatten();
219+
216220
let rewrite_map = config
217221
.clone()
218222
.into_map()
@@ -240,6 +244,7 @@ pub async fn doc(
240244
html_options,
241245
deno_ns,
242246
rewrite_map,
247+
main_entrypoint,
243248
)
244249
} else {
245250
let modules_len = doc_nodes_by_url.len();
@@ -383,6 +388,7 @@ fn generate_docs_directory(
383388
html_options: &DocHtmlFlag,
384389
deno_ns: std::collections::HashMap<Vec<String>, Option<Rc<ShortPath>>>,
385390
rewrite_map: Option<IndexMap<ModuleSpecifier, String>>,
391+
main_entrypoint: Option<ModuleSpecifier>,
386392
) -> Result<(), AnyError> {
387393
let cwd = std::env::current_dir().context("Failed to get CWD")?;
388394
let output_dir_resolved = cwd.join(&html_options.output);
@@ -415,7 +421,7 @@ fn generate_docs_directory(
415421

416422
let options = deno_doc::html::GenerateOptions {
417423
package_name: html_options.name.clone(),
418-
main_entrypoint: None,
424+
main_entrypoint,
419425
rewrite_map,
420426
href_resolver: Rc::new(DocResolver {
421427
deno_ns,

tests/specs/doc/html/__test__.jsonc

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
{
22
"tempDir": true,
3-
"args": [
4-
"doc",
5-
"--html",
6-
"--name=MyLib",
7-
"--output=temp_dir_path_here",
8-
"referenced_private_types_fixed.ts"
9-
],
10-
"output": "[WILDCARD]",
11-
"exitCode": 0
3+
"steps": [
4+
{
5+
"args": [
6+
"doc",
7+
"--html",
8+
"--name=MyLib",
9+
"a.ts",
10+
"b.ts"
11+
],
12+
"output": "Written 23 files to \"./docs/\"\n",
13+
"exitCode": 0
14+
},
15+
{
16+
"args": "run --allow-read check_file.ts",
17+
"output": "",
18+
"exitCode": 0
19+
}
20+
]
1221
}

tests/specs/doc/html/b.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** Doc comment */
2+
export interface MyInterface2 {
3+
/** Doc comment */
4+
prop?: string;
5+
}
6+
7+
/** Doc comment */
8+
export class MyClass2 {
9+
/** Doc comment */
10+
prop: MyInterface2 = {};
11+
}

tests/specs/doc/html/check_file.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const content = Deno.readTextFileSync("./docs/index.html");
2+
3+
if (content.includes("..")) {
4+
throw new Error();
5+
}

tests/specs/doc/html/deno.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"exports": {
3+
".": "./a.ts"
4+
}
5+
}

0 commit comments

Comments
 (0)