Skip to content

chore: derive the workspace layout from pnpm-workspace.yaml only#3752

Merged
cixzhang merged 1 commit into
facebook:mainfrom
Han5991:chore/workspace-globs-from-yaml
Jul 12, 2026
Merged

chore: derive the workspace layout from pnpm-workspace.yaml only#3752
cixzhang merged 1 commit into
facebook:mainfrom
Han5991:chore/workspace-globs-from-yaml

Conversation

@Han5991

@Han5991 Han5991 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What

pnpm-workspace.yaml becomes the single source of truth for the workspace layout, and the root package.json drops its workspaces array.

Four scripts already walked the packages: globs in pnpm-workspace.yaml, each carrying its own copy of the same loop. scripts/npm/setup-trusted-publishing.mjs even apologizes for it in a comment:

Ported from scripts/check-changesets.mjs discoverPackages() (which is NOT exported, so it is copied here).

apps/docsite/scripts/generate-data.mjs was the lone holdout, reading the root package.json workspaces array instead — and it was the only remaining reason that array existed. (packages/cli/src/utils/paths.mjs also reads pkg.workspaces, but findProjectRoot() has no callers anywhere in the repo and its tests build their own fixtures.)

This extracts the shared walk into scripts/lib/workspace-globs.mjs, points all five files at it, and deletes the array.

Two bugs fixed on the way

The copied regex was over-matching. /^\s*-\s*["']?([^"'\n]+)["']?/gm swept the entire YAML file rather than the packages: block, so it also picked up minimumReleaseAgeExclude's entry:

["apps/*", "packages/*", "packages/themes/*", "internal/*", "@astryxdesign/*"]
                                                             ^^^^^^^^^^^^^^^^

Five globs where the file declares four. Harmless only because @astryxdesign/ is not a real directory, so a downstream existsSync skipped it. Any future list item under overrides: or allowBuilds: that happened to name a real directory would have been walked as a workspace root. The replacement parse is line-based and scoped to the packages: block.

generate-data.mjs had a silent-empty failure mode. rootPkg.workspaces || [] meant a missing array yielded an empty package list, no exception, and a docsite build that shipped zero components. readWorkspaceGlobs() throws instead.

Verification

  • discoverPackageDirs() returns the same 13 directories before and after.
  • node apps/docsite/scripts/generate-data.mjs prints a byte-identical summary on this branch and on main: 8 packages, 219 components, 582 blocks (167 showcases, 448 examples), 40 templates, 18 doc topics, 3 blog posts, 6 themes.
  • check-changesets, format-changelogs --check, check-package-boundaries, and format-changelogs.test.mjs (8 tests) all pass.
  • pnpm install --frozen-lockfile still resolves all 26 workspace projects.
  • @manypkg/get-packages — what changesets uses to enumerate the workspace — still reports tool: pnpm with 25 packages, so removing the array does not affect release tooling.
  • The guard fires: a pnpm-workspace.yaml with no packages: block throws instead of returning [].

Note

scripts/ is outside the eslint ignore boundary, so these files get no lint coverage — the unused-import check after the refactor was done by hand.

@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 12, 2026 6:30am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 10, 2026
@Han5991
Han5991 force-pushed the chore/workspace-globs-from-yaml branch from 7f4c7eb to 2583388 Compare July 11, 2026 12:30
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 11, 2026

@cixzhang cixzhang 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.

🟡 Maintainer judgment recommended — the change itself looks clean, but the branch has a merge conflict with main and can't be merged as-is.

Initial review pass (community contributor).

Blocking (mechanical): rebase needed. main has moved under this branch — both package.json and apps/docsite/scripts/generate-data.mjs were changed upstream after the branch point, and the PR reports CONFLICTING. Please rebase on latest origin/main and re-push; the review can't clear a branch that won't merge.

On the change itself (looks good): consolidating the four copied workspace-walking loops into scripts/lib/workspace-globs.mjs and dropping the redundant root package.json workspaces array is a solid cleanup. Two things I verified:

  • The line-based packages: parser correctly scopes to that block, fixing the prior regex that over-matched entries from minimumReleaseAgeExclude/overrides/allowBuilds.
  • The throw-on-empty guard in readWorkspaceGlobs closes the silent-empty failure mode in generate-data.mjs.
  • Remaining pkg.workspaces readers (packages/cli/src/utils/paths.mjs, scripts/verify-exports.mjs) are unaffected — findProjectRoot has no callers and verify-exports walks packages/ directly.

Please confirm the post-rebase verification still holds (discoverPackageDirs() → same 13 dirs; docsite generate-data byte-identical summary) since the conflict is in exactly those two files.


Recap#3752 · chore: derive the workspace layout from pnpm-workspace.yaml only · @Han5991
What it does: makes pnpm-workspace.yaml the single source of truth for the workspace layout, extracting the shared glob-walk into one helper and removing the duplicated workspaces array.
Recommendation: Rebase on main to resolve the conflict, then re-review. No objections to the change on its merits.

Four scripts already walked the `packages:` globs in pnpm-workspace.yaml,
each with its own copy of the same loop — setup-trusted-publishing.mjs even
apologizes for it ("Ported from check-changesets.mjs, which is NOT exported,
so it is copied here"). apps/docsite/scripts/generate-data.mjs was the lone
holdout, reading the root package.json `workspaces` array instead.

Extract the shared walk into scripts/lib/workspace-globs.mjs, point all five
at it, and drop the now-unused `workspaces` array from the root package.json.

Fixes a latent bug in the copied regex. `/^\s*-\s*["']?([^"'\n]+)["']?/gm`
swept the whole file, not just the `packages:` block, so it also picked up
`minimumReleaseAgeExclude`'s `@astryxdesign/*` — five globs where the file
declares four. It was harmless only because `@astryxdesign/` is not a real
directory and got skipped by a downstream existsSync. Any future list item
that happens to name one would have been walked as a workspace root. The
replacement is line-based and scoped to the `packages:` block.

generate-data.mjs also lost its silent-empty failure mode. `rootPkg.workspaces
|| []` meant a missing array produced an empty registry, no exception, and a
docsite build that shipped zero components. readWorkspaceGlobs() throws.

Verified:
- discoverPackageDirs() returns the same 13 directories before and after.
- `node apps/docsite/scripts/generate-data.mjs` prints a byte-identical
  summary on this branch and on main (8 packages, 219 components, 582
  blocks, 40 templates, 18 doc topics, 3 blog posts, 6 themes).
- check-changesets, format-changelogs --check, check-package-boundaries,
  and format-changelogs.test.mjs (8 tests) all pass.
- `pnpm install --frozen-lockfile` still resolves all 26 workspace projects,
  and @manypkg (what changesets uses) still reports tool=pnpm with 25
  packages, so removing the array does not affect the release tooling.
@Han5991
Han5991 force-pushed the chore/workspace-globs-from-yaml branch from 2583388 to 666efaf Compare July 12, 2026 06:28
@github-actions
github-actions Bot requested a review from cixzhang July 12, 2026 06:28
@Han5991

Han5991 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on latest main and re-pushed — the branch is MERGEABLE again.

The conflict was semantic, not just textual: #3858 landed resolveContentRoot() in the meantime, so discoverPackageDirs() must now expand against CONTENT_ROOT (live workspace on canary, materialized npm snapshot on latest), not REPO_ROOT. Resolution:

  • generate-data.mjs: discovery is now expandWorkspaceDirs(CONTENT_ROOT) — same helper, correct root for both targets.
  • resolve-content-root.mjs: the materialized snapshot now writes a synthetic pnpm-workspace.yaml (instead of a workspaces array in the synthetic package.json), so the snapshot keeps mirroring what a real monorepo declares post-this-PR. The cache stamp is bumped to v2: so pre-existing snapshots from the old layout get rebuilt rather than failing discovery.

Post-rebase verification (as requested):

  • discoverPackageDirs() parity on canary: old (workspaces-array walk against upstream/main's package.json) vs new (pnpm-workspace.yaml) → identical 13 dirs.
  • Full generate-data.mjs run, old scripts vs new scripts in the same tree, same content: src/generated/ output is byte-identical.
  • latest target end-to-end: DOCSITE_TARGET=latest materialized 0.1.4 from npm; the snapshot carries the synthetic pnpm-workspace.yaml and discovery surfaces the expected 8 published dirs (cli, core, 6 stable themes).

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.6KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 12, 2026
@cixzhang
cixzhang merged commit 79d73f3 into facebook:main Jul 12, 2026
21 checks passed
@Han5991
Han5991 deleted the chore/workspace-globs-from-yaml branch July 12, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants