docgen: support hardhat3-style branches in injectTemplates#174
Open
ernestognw wants to merge 1 commit into
Open
docgen: support hardhat3-style branches in injectTemplates#174ernestognw wants to merge 1 commit into
ernestognw wants to merge 1 commit into
Conversation
The injectTemplates pipeline assumed a Hardhat 2 / solidity-docgen layout (docs/config.js + docs/templates-md/). The hardhat3 branch of openzeppelin-contracts replaces solidity-docgen with an in-tree plugin that reads docs/config.mjs and templates from docs/templates/, emits .adoc by default, and loads helpers/properties only from helpers.ts/ properties.ts via ESM dynamic import — so the previous injection was silently ignored and AsciiDoc landed in content/, breaking every guide xref into the API. Detect the layout from the cloned repo and route accordingly: - New layout: overwrite docs/config.mjs with our canonical config (forces pageExtension '.mdx' and templates path 'docs/templates'), wipe and re-populate docs/templates/, rename helpers.js / properties.js to .cjs (Node treats .js as ESM under "type": "module" on hardhat3), patch the internal require, and emit thin ESM shim helpers.ts / properties.ts so the in-tree plugin's loader picks up named exports. - Legacy layout: unchanged behaviour. Rename the kebab-case Handlebars helpers (oz-version, has-functions, typed-params, …) to camelCase across the templates and helpers/ properties modules. ESM named exports cannot carry hyphens, and Handlebars is name-agnostic, so this is transparent to solidity-docgen on older tags. Verified by running against the hardhat3 branch locally: 200 → 1 broken links in next-validate-link, and the one residual is a pre-existing EIP712 NatSpec xref to /<base>/learn/upgrading-smart-contracts that also fails on current main's content/contracts/5.x. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for openzeppelin-docs-v2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Amxx
reviewed
May 29, 2026
Comment on lines
+147
to
+152
| return [ | ||
| `import ${varName} from '${sourcePath}';`, | ||
| "", | ||
| ...exports.map(e => `export const ${e} = ${varName}.${e};`), | ||
| "", | ||
| ].join("\n"); |
There was a problem hiding this comment.
I believe this is usually done using
Suggested change
| return [ | |
| `import ${varName} from '${sourcePath}';`, | |
| "", | |
| ...exports.map(e => `export const ${e} = ${varName}.${e};`), | |
| "", | |
| ].join("\n"); | |
| return `export { `e.join(",")` } from "${sourcePath}";`; |
Basically, that gives things like what we can find in ethers.ts
export {
getAddress, getIcapAddress,
getCreateAddress, getCreate2Address,
isAddressable, isAddress, resolveAddress
} from "./address/index.js";There was a problem hiding this comment.
that is assuming we don't need the varName to be declared and its only used as an intermediary
Amxx
reviewed
May 29, 2026
Comment on lines
+164
to
+168
| let newLayout = false; | ||
| try { | ||
| await fs.access(path.join(tempDir, "docs", "config.mjs")); | ||
| newLayout = true; | ||
| } catch {} |
There was a problem hiding this comment.
Suggested change
| let newLayout = false; | |
| try { | |
| await fs.access(path.join(tempDir, "docs", "config.mjs")); | |
| newLayout = true; | |
| } catch {} | |
| const newLayout = await fs.access(path.join(tempDir, "docs", "config.mjs")).then(() => true, () => false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The docgen-pipeline (#140) assumed a Hardhat 2 /
solidity-docgensource repo:docs/config.js,docs/templates-md/, kebab-case helpers, all CJS. The hardhat3 branch of openzeppelin-contracts ships an in-tree docgen plugin that:docs/config.mjs(ESM, loaded viaimport()inprepare-docs.sh)docs/templates/pageExtension: '.adoc'helpers.ts/properties.tsviaawait import()— and only picks up ESM named function exportsResult on run 26575968521: our injection wrote
docs/config.jsanddocs/templates-md/, both silently ignored. The plugin ran with the source repo's own AsciiDoc templates, copied.adocfiles intocontent/contracts/latest/api/, fumadocs couldn't route them, and every guide xref into the API 404'd — 200 errors innext-validate-link.What this PR does
injectTemplates. If the cloned repo hasdocs/config.mjs, treat it as the new layout; otherwise fall through to the legacy code path unchanged.docs/config.mjswithdocgen/config-md.mjs(forcespageExtension: '.mdx'andtemplates: 'docs/templates').docs/templates/, renaminghelpers.js/properties.jsto.cjs(the hardhat3 branch sets\"type\": \"module\"so plain.jswould be treated as ESM and ourmodule.exportswould break). Patch the internalrequire('./helpers')inproperties.cjsaccordingly.helpers.ts/properties.tsthat re-export each function — the new plugin's loader only walks.tsnamed exports.oz-version,has-functions,typed-params, …) to camelCase across templates and helpers/properties modules. ESM named exports can't carry hyphens, and Handlebars is name-agnostic, so this is transparent to solidity-docgen on older tags.Verified locally
Ran the updated
generate-api-docs.jsagainst the hardhat3 branch end to end (hardhat docgen+convert-adoc.js+pnpm run lint:links). 200 → 1 broken link. The residual is a pre-existing EIP712 NatSpec xref to/<base>/learn/upgrading-smart-contractsthat also fails today oncontent/contracts/5.x/— unrelated to this change.Test plan
tag_name: hardhat3andtrigger_type: commit; confirm the validate step is clean (or only flags the EIP712 learn-module xref).tag_name: v5.6.1; confirm legacy path still works./contracts/latest/api/access#AccessManager-RoleRevoked-uint64-address-resolve.🤖 Generated with Claude Code