Skip to content

Commit

Permalink
fix(tools/doc): HTML resolve main entrypoint from config file (#27103)
Browse files Browse the repository at this point in the history
Fixes #26901
  • Loading branch information
crowlKats authored Nov 27, 2024
1 parent 927352b commit 7400181
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
8 changes: 7 additions & 1 deletion cli/tools/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,14 @@ pub async fn doc(
Default::default()
};

let mut main_entrypoint = None;

let rewrite_map =
if let Some(config_file) = cli_options.start_dir.maybe_deno_json() {
let config = config_file.to_exports_config()?;

main_entrypoint = config.get_resolved(".").ok().flatten();

let rewrite_map = config
.clone()
.into_map()
Expand Down Expand Up @@ -240,6 +244,7 @@ pub async fn doc(
html_options,
deno_ns,
rewrite_map,
main_entrypoint,
)
} else {
let modules_len = doc_nodes_by_url.len();
Expand Down Expand Up @@ -383,6 +388,7 @@ fn generate_docs_directory(
html_options: &DocHtmlFlag,
deno_ns: std::collections::HashMap<Vec<String>, Option<Rc<ShortPath>>>,
rewrite_map: Option<IndexMap<ModuleSpecifier, String>>,
main_entrypoint: Option<ModuleSpecifier>,
) -> Result<(), AnyError> {
let cwd = std::env::current_dir().context("Failed to get CWD")?;
let output_dir_resolved = cwd.join(&html_options.output);
Expand Down Expand Up @@ -415,7 +421,7 @@ fn generate_docs_directory(

let options = deno_doc::html::GenerateOptions {
package_name: html_options.name.clone(),
main_entrypoint: None,
main_entrypoint,
rewrite_map,
href_resolver: Rc::new(DocResolver {
deno_ns,
Expand Down
27 changes: 18 additions & 9 deletions tests/specs/doc/html/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"tempDir": true,
"args": [
"doc",
"--html",
"--name=MyLib",
"--output=temp_dir_path_here",
"referenced_private_types_fixed.ts"
],
"output": "[WILDCARD]",
"exitCode": 0
"steps": [
{
"args": [
"doc",
"--html",
"--name=MyLib",
"a.ts",
"b.ts"
],
"output": "Written 23 files to \"./docs/\"\n",
"exitCode": 0
},
{
"args": "run --allow-read check_file.ts",
"output": "",
"exitCode": 0
}
]
}
File renamed without changes.
11 changes: 11 additions & 0 deletions tests/specs/doc/html/b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** Doc comment */
export interface MyInterface2 {
/** Doc comment */
prop?: string;
}

/** Doc comment */
export class MyClass2 {
/** Doc comment */
prop: MyInterface2 = {};
}
5 changes: 5 additions & 0 deletions tests/specs/doc/html/check_file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const content = Deno.readTextFileSync("./docs/index.html");

if (content.includes("..")) {
throw new Error();
}
5 changes: 5 additions & 0 deletions tests/specs/doc/html/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exports": {
".": "./a.ts"
}
}

0 comments on commit 7400181

Please sign in to comment.