Repository navigation
Conversation
get-contracts-metadata.js, update-docs-branch.js and docs/templates/helpers.ts located the artifacts and package.json relative to their own location. Read them from the working directory instead, like the rest of these scripts already do. This lets projects that depend on OpenZeppelin Contracts symlink these files from the submodule.
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the changes to read project files from the working directory.
No open issues 🎉
What changed in this PR
This PR makes repository scripts and documentation helpers read project files from the working directory, allowing downstream repositories to reuse them through symlinks without reading files from the OpenZeppelin submodule.
Changes:
- Read compiler artifacts directly from the supplied paths.
- Read package versions from the working directory’s
package.json. - Preserve existing behavior when run from the repository root.
| File | Description |
|---|---|
scripts/update-docs-branch.js |
Reads the local package version and removes the unused path import. |
scripts/get-contracts-metadata.js |
Reads artifact paths without resolving them relative to the script. |
docs/templates/helpers.ts |
Loads the documentation version from the working directory’s package file. |
Review effort: Balanced
|
No actionable comments were generated in the recent review. WalkthroughDocumentation helpers and the docs branch script now read Change: Refactor Merge Risk:
|
| const pkgVersion = JSON.parse(fs.readFileSync('package.json', 'utf8')).version; | ||
|
|
||
| if (pkgVersion.includes('-') && !pkgVersion.includes('.0.0-')) { | ||
| console.error('Refusing to update docs: non-major prerelease detected'); |
There was a problem hiding this comment.
I would:
a. rollback changes in scripts/update-docs-branch.js & use a modified copy in community
b. or parametrize this script enough to be used in community (branch, ..)
get-contracts-metadata.js,update-docs-branch.jsanddocs/templates/helpers.tslocated the build artifacts andpackage.jsonrelative to their own location (import.meta.dirname, or a relativeimportofpackage.json). They now read them from the working directory, like the rest of these scripts already do:get-contracts-metadata.jsalready finds the.solfiles (glob.sync(pattern),fs.readFileSync(file)) and Foundry'sout/from the working directory. Only the artifacts were read relative to the script. The artifact paths are shell globs (artifacts/build-info/*.output.json), which the shell also expands from the working directory.update-docs-branch.jsalready runsgit show <ref>:package.json,npm run prepare-docsandgit add -f docsfrom the working directory.These scripts are always run from the repository root (through npm scripts, or from the
docs.ymlworkflow), so nothing changes here.Motivation
OpenZeppelin Community Contracts reuses these scripts, and keeps copies of them because Node resolves a symlinked module to its target. Through a symlink to
lib/@openzeppelin-contracts, the current versions read the artifacts andpackage.jsonof the submodule instead of those of the project. With this change, they can be symlinked (see OpenZeppelin/openzeppelin-community-contracts#283 (comment)).minimize-pragma.jsandchecks/pragma-validity.jscan then be symlinked too, sinceget-contracts-metadata.jswas the only reason they couldn't be.Testing
npm run test:pragmapasses here.node <this branch>/scripts/checks/pragma-validity.js artifacts/build-info/*passes, while the current version crashes because the submodule has no matching artifacts.ozVersion()fromdocs/templates/helpers.tsstill returns the version inpackage.json.PR Checklist
npx changeset add)