Repository navigation
fix(workspaces): read pnpm-workspace.yaml with a YAML parser, and refuse patterns that match nothing - #17
Merged
Conversation
…use patterns that match nothing
workspacePackagesOf read pnpm-workspace.yaml line by line and only knew the
block list. The flow form, packages: ['packages/*', 'apps/*'], which pnpm
accepts, produced no patterns, so check and fix silently looked at the root
alone. Globs were also limited to one 'dir/*' level, and an exclusion such
as '!**/test/**' could never match.
The file is parsed with the yaml package core already ships (block and flow
lists, quotes, comments); package.json "workspaces" is read as an array or
as yarn's { packages: [...] }. Patterns are matched as globs over the
directories holding a package.json (node_modules and dot-directories
skipped): * and ? within a segment, ** across segments, ! exclusions.
A workspace file whose patterns match no package is an INVALID_WORKSPACE
error naming the file and the patterns; invalid YAML is the same error. A
pnpm-workspace.yaml with settings and no packages key stays a
single-package repository.
Fixtures for each form live in fixtures/workspaces/.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lucas Braum <[email protected]>
…prefixes, memoized Review of the previous commit: - Probes no longer throw. fetch/npmrc.ts walks parent directories looking for the project root, and action/detect.ts reads workspaces of two checkouts; both use workspacePackagesOrRoot, which answers ['.'] for a broken workspace file. list, check and fix keep the error. A broken pnpm-workspace.yaml in a parent directory no longer breaks list in a child repository (list.test.ts, invalid YAML and patterns matching nothing). - Each pattern walks only its static prefix (packages/* reads packages/ one level deep), as deep as the pattern reaches; ** is unbounded and a leading one walks the repository. Wildcards do not descend into dist, build, coverage, out, bower_components, node_modules or dot-directories; an exact path is taken as written. Results (and errors) are memoized per root for the process, and callers get a copy. - '.' names the root: a pnpm-workspace.yaml listing only '.' (with exclusions) is a single-package repository. The previous commit called it an INVALID_WORKSPACE error, found on a real repository while timing this. - action/detect.ts's matchesPaths uses the same globRegExp instead of its own copy. On a synthetic 63,566-directory repository (601 packages), the first call went from 1,315 ms (previous commit) to 6.4 ms, and 50 further calls from 69 s to 0.3 ms. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lucas Braum <[email protected]>
… hide a match With packages/*, a real package at packages/build or tools/out was dropped silently: the walk skipped dist, build, coverage, out and dot-directories before testing the pattern (netlify/build has packages/build). Each entry is now matched first; those names only stop the walk into them. node_modules and bower_components are still never a match: pnpm's own package finder ignores them, so neither is a workspace package. Fixtures: pnpm-build-names (packages/build, packages/dist and tools/out are found) and pnpm-globstar (packages/** reaches packages/build but not what sits inside node_modules, dist or a build-named package). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lucas Braum <[email protected]>
pnpm globs workspace patterns with dot: false, so a directory whose name starts with a dot is never a workspace package, even under **. The previous commit matched packages/.hidden; it is now excluded and not walked, like node_modules and bower_components. Build-named directories (dist, build, coverage, out) still match and are only not walked into. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lucas Braum <[email protected]>
7 tasks done
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.
Problem
workspacePackagesOfreadpnpm-workspace.yamlline by line and only understood the block list. The flow form,packages: ['packages/*', 'apps/*'], is valid pnpm config, but it produced no patterns, socheckandfixsilently looked at the root alone. Two more gaps:dir/*level.'!**/test/**'could never match.Changes
pnpm-workspace.yamlis read with theyamlpackage core already ships. Block and flow lists, quotes and comments all work."workspaces"is read as an array (npm, yarn) or as yarn's{ packages: [...], nohoist: [...] }.package.json, skippingnode_modulesand dot-directories.*and?match within one path segment,**across segments, and!patterns exclude. This is a small built-in matcher rather than a new dependency for the bundled CLI.ignore(already installed) was not usable: under gitignore rules,packages/*also matches everything nested below it.INVALID_WORKSPACEerror (CLI exit 2) that names the file and patterns. Invalid YAML gets the same error. Apnpm-workspace.yamlwith settings or catalogs and nopackageskey is still a single-package repository.Fixtures (
fixtures/workspaces/)pnpm-blockpackages/**,!**/test/**.,apps/web,packages/corepnpm-flow.,apps/web,packages/corenpm-array"workspaces": [...].,apps/web,packages/coreyarn-object"workspaces": { "packages": [...] }.,apps/web,packages/corepnpm-settings-onlypackages.pnpm-root-onlypackages: ['.', '!vendor/**'].pnpm-build-namespackages/*,tools/*with packages namedbuild,dist,outpnpm-globstarpackages/**packages/aandpackages/build; nothing insidenode_modules,distorbuildpnpm-no-matchpackages: ['libs/*']with nolibs/INVALID_WORKSPACEIn both pnpm fixtures,
packages/core/test/fixture/package.jsonis excluded by!**/test/**.Against main's implementation, 4 of the 7 new tests fail.
uptide list --jsononpnpm-flownow reports the three workspaces.Tests: core 804 passed, cli 313 passed.
tscandbiomeare clean (public:checkwas not run: it needs the private denylist). A patch changeset is included.After review
INVALID_WORKSPACE.list,checkandfixkeep the error. Two callers only probe:fetch/npmrc.ts(walks parent directories for the project's.npmrc) andaction/detect.ts. Both now useworkspacePackagesOrRoot, which answers['.']for a broken workspace file. Test: a parent directory whosepnpm-workspace.yamlis invalid YAML, or matches nothing, no longer breakslistin a child repository.packages/*readspackages/one level deep), as deep as the pattern reaches.**has no depth limit, and a leading**walks the whole repository.node_modules,bower_componentsand dot-directories are never a match and never walked: pnpm's finder ignores the first two and globs withdot: false.dist,build,coverageandoutare matched like any other directory, sopackages/buildis found withpackages/*(netlify/build has one), but the walk never goes inside them.'.'names the root, sopackages: ['.', '!x/**']is a single-package repository. The first commit wrongly raisedINVALID_WORKSPACEfor this; timing against a real repository caught it.matchesPathsinaction/detect.tsuses the sharedglobRegExpinstead of its own copy.Timing (median of 3 runs, Node 22, macOS)
Synthetic repository: 63,566 directories, 9,301
package.jsonfiles, 601 workspace packages underapps/*,packages/*andtooling/**. Every package has deepsrc/trees, plusdist/,coverage/and anode_modules/with 15 packages.On 7 real local monorepos (3–12k directories; pnpm and npm), main and this PR resolve byte-identical package lists, rechecked after the build-name fix (1, 1, 1, 10, 3, 7 and 3 packages). The first call takes 0.3–4.8 ms, mostly loading the YAML parser, and repeat calls take 0.0–0.1 ms.
🤖 Generated with Claude Code