fix(ts-docs): move typedoc config heredoc to column 0#59
Conversation
The first multi-package run failed with `syntax error: unexpected end of file`. The heredoc was nested inside a bash subshell with 14-space indentation and the closing `JSON` marker was also indented — bash heredocs only ignore leading TABS via `<<-`, not spaces. Lift the heredoc out of the subshell, write the typedoc config once to a tmp path, and cp it into each package dir before running typedoc. The typedoc options are identical across packages, so emitting once is also a tiny optimization.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the API documentation generation workflow by centralizing the TypeDoc configuration into a single temporary file that is copied into each package, rather than being redefined in every iteration. Feedback suggests implementing a cleanup mechanism for the temporary file using a trap and ensuring that per-package configuration files are removed after use to maintain a clean workspace. Additionally, a recommendation was made to ensure source links resolve correctly in monorepos.
| # 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)" |
There was a problem hiding this comment.
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| 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 | ||
| ) || { |
There was a problem hiding this comment.
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
- In monorepos, documentation generator source links must include the relative path to the package directory for correct resolution.
First multi-package run failed with
syntax error: unexpected end of file. The heredoc was nested inside a bash subshell with 14-space indentation, and the closingJSONmarker was also indented — bash heredocs only ignore leading tabs via<<-, not spaces.Lift the heredoc out of the subshell, write the typedoc config once to a tmp path, and
cpit into each package dir. The typedoc options are identical across packages, so emitting once is also a tiny optimization.