Skip to content

Resolve repository files from the working directory in scripts - #6878

Open
Amxx wants to merge 1 commit into
masterfrom
scripts-cwd-paths
Open

Amxx wants to merge 1 commit into
masterfrom
scripts-cwd-paths

Conversation

@Amxx

@Amxx Amxx commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

get-contracts-metadata.js, update-docs-branch.js and docs/templates/helpers.ts located the build artifacts and package.json relative to their own location (import.meta.dirname, or a relative import of package.json). They now read them from the working directory, like the rest of these scripts already do:

  • get-contracts-metadata.js already finds the .sol files (glob.sync(pattern), fs.readFileSync(file)) and Foundry's out/ 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.js already runs git show <ref>:package.json, npm run prepare-docs and git add -f docs from the working directory.

These scripts are always run from the repository root (through npm scripts, or from the docs.yml workflow), 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 and package.json of the submodule instead of those of the project. With this change, they can be symlinked (see OpenZeppelin/openzeppelin-community-contracts#283 (comment)). minimize-pragma.js and checks/pragma-validity.js can then be symlinked too, since get-contracts-metadata.js was the only reason they couldn't be.

Testing

  • npm run test:pragma passes here.
  • From the root of OpenZeppelin Community Contracts, 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() from docs/templates/helpers.ts still returns the version in package.json.

PR Checklist

  • Tests
  • Documentation
  • Changeset entry (run npx changeset add)

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.
@Amxx
Amxx requested a review from a team as a code owner November 13, 2026 17:56
Copilot AI balanced review requested due to automatic review settings November 13, 2026 17:56
@changeset-bot

changeset-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d31f639

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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

@coderabbitai

coderabbitai Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Documentation helpers and the docs branch script now read package.json from the process working directory. ozVersion continues to use the parsed version. The contract metadata script now reads artifacts from the supplied paths.

Change: Refactor

Merge Risk: Minimal · up to d31f6

The change makes helper scripts resolve files from the working directory so they can be symlinked from a submodule. Running from the repository root keeps existing behavior. The only visible blocker is the missing changeset, which can be added as an empty one.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: scripts now resolve repository files from the working directory instead of relative to their own location. The raw summary confirms the changes to get-contracts-metada…
Description check Passed The description states which files changed, why (letting OpenZeppelin Community Contracts symlink the scripts), how the change was tested, and that the scripts run from the repository root. It matches…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: scripts now resolve repository files from the working directory instead of relative to their own location. The raw summary confirms the changes to get-contracts-metadata.js, update-docs-branch.js, and docs/templates/helpers.ts match this.

Full details: Description check

Explanation

The description states which files changed, why (letting OpenZeppelin Community Contracts symlink the scripts), how the change was tested, and that the scripts run from the repository root. It matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b0b611a5-b28c-4a2b-922f-9a66de96cd46
Commits

Reviewing files that changed from the base of the PR and between 7df9390 and d31f639.

Files selected for processing: 3

  • docs/templates/helpers.ts
  • scripts/get-contracts-metadata.js
  • scripts/update-docs-branch.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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, ..)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants