Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions automation/source-repo-templates/api-docs.typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@ jobs:
set -euo pipefail
mkdir -p "$OUTPUT_DIR"
rm -rf "${OUTPUT_DIR:?}"/*

# The typedoc config is identical across packages; write it
# once to a tmp path and copy into each package dir.
# Heredoc body lives at column 0 so the bash parser doesn't
# trip on the indented closing marker (tabs vs spaces).
tmp_cfg="$(mktemp)"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The temporary file created by mktemp should be cleaned up to avoid leaking files in /tmp. While GitHub Action runners are ephemeral, it is good practice to ensure cleanup, especially if this template is used in persistent environments or self-hosted runners.

          tmp_cfg="$(mktemp)"
          trap 'rm -f "$tmp_cfg"' EXIT

cat > "$tmp_cfg" <<'JSON'
{
"$schema": "https://typedoc-plugin-markdown.org/schema.json",
"plugin": ["typedoc-plugin-markdown"],
"tsconfig": "tsconfig.json",
"entryPointStrategy": "Expand",
"entryPoints": ["src"],
"exclude": [
"**/*.cy.ts",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.stories.ts",
"**/*.stories.tsx",
"**/*.spec.ts",
"**/*.spec.tsx"
],
"out": "generated-docs",
"readme": "none",
"cleanOutputDir": true
}
JSON

generated=0
for pkg in $PUBLIC_PACKAGES; do
pkg_dir="packages/$pkg"
Expand All @@ -119,31 +147,11 @@ jobs:
continue
fi
echo "==> generating $pkg"
cp "$tmp_cfg" "$pkg_dir/typedoc.docs-site.json"
(
cd "$pkg_dir"
bun add --dev typedoc-plugin-markdown@latest >/dev/null
bun add --dev typedoc@latest >/dev/null
cat > typedoc.docs-site.json <<'JSON'
{
"$schema": "https://typedoc-plugin-markdown.org/schema.json",
"plugin": ["typedoc-plugin-markdown"],
"tsconfig": "tsconfig.json",
"entryPointStrategy": "Expand",
"entryPoints": ["src"],
"exclude": [
"**/*.cy.ts",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.stories.ts",
"**/*.stories.tsx",
"**/*.spec.ts",
"**/*.spec.tsx"
],
"out": "generated-docs",
"readme": "none",
"cleanOutputDir": true
}
JSON
rm -rf generated-docs
bunx typedoc --options typedoc.docs-site.json
) || {
Comment on lines +150 to 157
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The per-package TypeDoc configuration file should be removed after use to keep the workspace clean. Additionally, ensure the configuration includes the relative path to the package directory in the source code link base URL, as required for monorepos to ensure 'View source' links resolve correctly.

            cp "$tmp_cfg" "$pkg_dir/typedoc.docs-site.json"
            (
              cd "$pkg_dir"
              bun add --dev typedoc-plugin-markdown@latest >/dev/null
              bun add --dev typedoc@latest >/dev/null
              rm -rf generated-docs
              bunx typedoc --options typedoc.docs-site.json
              rm -f typedoc.docs-site.json
            ) || {
              rm -f "$pkg_dir/typedoc.docs-site.json"
            }
References
  1. In monorepos, documentation generator source links must include the relative path to the package directory for correct resolution.

Expand Down
Loading