-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: catalog support #6884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arcanis
merged 15 commits into
yarnpkg:master
from
ruimartin:ruimartin/feat/catalog-basic
Sep 17, 2025
+1,645
−43
Merged
feat: catalog support #6884
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b4f879d
chore: core plugin-catalog scaffolding
ruimartin f3107d5
feat: adding basic catalog functionality
ruimartin 4ba1ebc
updating error messages to use project standard
ruimartin c1db43e
adding tests for plugin-catalog
ruimartin 2e4e3ea
fixing basic readme and dropping support for named entries in catalog
ruimartin 0659a86
adding support for named catalogs
ruimartin fe756bd
adding documentation
ruimartin ece129a
adding support for publishing
ruimartin 96d425f
minor docs fixes and bumping package version
ruimartin 2da3547
addressing ci issues
ruimartin 3675832
versions check
ruimartin 3e15ac8
fixing file descriptor binding
ruimartin 7388c83
updating unit tests
ruimartin 819ee0b
adding integration tests
ruimartin fc7c1d9
Clean up async code
arcanis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| releases: | ||
| "@yarnpkg/cli": minor | ||
| "@yarnpkg/plugin-catalog": major | ||
| "@yarnpkg/plugin-pack": patch | ||
|
|
||
| declined: | ||
| - "@yarnpkg/plugin-compat" | ||
| - "@yarnpkg/plugin-constraints" | ||
| - "@yarnpkg/plugin-dlx" | ||
| - "@yarnpkg/plugin-essentials" | ||
| - "@yarnpkg/plugin-init" | ||
| - "@yarnpkg/plugin-interactive-tools" | ||
| - "@yarnpkg/plugin-nm" | ||
| - "@yarnpkg/plugin-npm" | ||
| - "@yarnpkg/plugin-npm-cli" | ||
| - "@yarnpkg/plugin-patch" | ||
| - "@yarnpkg/plugin-pnp" | ||
| - "@yarnpkg/plugin-pnpm" | ||
| - "@yarnpkg/plugin-stage" | ||
| - "@yarnpkg/plugin-typescript" | ||
| - "@yarnpkg/plugin-version" | ||
| - "@yarnpkg/plugin-workspace-tools" | ||
| - "@yarnpkg/builder" | ||
| - "@yarnpkg/core" | ||
| - "@yarnpkg/doctor" | ||
340 changes: 340 additions & 0 deletions
340
packages/acceptance-tests/pkg-tests-specs/sources/features/catalogs.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,340 @@ | ||
| import {PortablePath, xfs} from '@yarnpkg/fslib'; | ||
| import {yarn, fs as fsUtils} from 'pkg-tests-core'; | ||
|
|
||
| describe(`Features`, () => { | ||
| describe(`Catalogs`, () => { | ||
| test( | ||
| `it should resolve dependencies from the default catalog during install`, | ||
| makeTemporaryEnv( | ||
| { | ||
| dependencies: { | ||
| [`no-deps`]: `catalog:`, | ||
| }, | ||
| }, | ||
| async ({path, run, source}) => { | ||
| await yarn.writeConfiguration(path, { | ||
| catalog: { | ||
| [`no-deps`]: `2.0.0`, | ||
| }, | ||
| }); | ||
|
|
||
| await run(`install`); | ||
|
|
||
| await expect(source(`require('no-deps')`)).resolves.toMatchObject({ | ||
| name: `no-deps`, | ||
| version: `2.0.0`, | ||
| }); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should resolve dependencies from named catalogs during install`, | ||
| makeTemporaryEnv( | ||
| { | ||
| dependencies: { | ||
| [`no-deps`]: `catalog:react18`, | ||
| }, | ||
| }, | ||
| async ({path, run, source}) => { | ||
| await yarn.writeConfiguration(path, { | ||
| catalogs: { | ||
| react18: { | ||
| [`no-deps`]: `2.0.0`, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await run(`install`); | ||
|
|
||
| await expect(source(`require('no-deps')`)).resolves.toMatchObject({ | ||
| name: `no-deps`, | ||
| version: `2.0.0`, | ||
| }); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should resolve scoped package dependencies from catalogs`, | ||
| makeTemporaryEnv( | ||
| { | ||
| dependencies: { | ||
| [`@scoped/create-test-app`]: `catalog:`, | ||
| }, | ||
| }, | ||
| async ({path, run, source}) => { | ||
| await yarn.writeConfiguration(path, { | ||
| catalog: { | ||
| [`@scoped/create-test-app`]: `1.0.0`, | ||
| }, | ||
| }); | ||
|
|
||
| await run(`install`); | ||
|
|
||
| // Verify that the scoped package was resolved from catalog | ||
| const lockfile = await xfs.readFilePromise(`${path}/yarn.lock` as PortablePath, `utf8`); | ||
| expect(lockfile).toMatch(/@scoped\/create-test-app@npm:1\.0\.0/); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should support multiple catalog entries in the same project`, | ||
| makeTemporaryEnv( | ||
| { | ||
| dependencies: { | ||
| [`no-deps`]: `catalog:`, | ||
| [`one-fixed-dep`]: `catalog:react18`, | ||
| }, | ||
| }, | ||
| async ({path, run, source}) => { | ||
| await yarn.writeConfiguration(path, { | ||
| catalog: { | ||
| [`no-deps`]: `2.0.0`, | ||
| }, | ||
| catalogs: { | ||
| react18: { | ||
| [`one-fixed-dep`]: `1.0.0`, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await run(`install`); | ||
|
|
||
| await expect(source(`require('no-deps')`)).resolves.toMatchObject({ | ||
| name: `no-deps`, | ||
| version: `2.0.0`, | ||
| }); | ||
|
|
||
| await expect(source(`require('one-fixed-dep')`)).resolves.toMatchObject({ | ||
| name: `one-fixed-dep`, | ||
| version: `1.0.0`, | ||
| }); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should work with different dependency types (devDependencies, peerDependencies)`, | ||
| makeTemporaryEnv( | ||
| { | ||
| dependencies: { | ||
| [`one-fixed-dep`]: `catalog:tools`, | ||
| }, | ||
| devDependencies: { | ||
| [`no-deps`]: `catalog:`, | ||
| }, | ||
| }, | ||
| async ({path, run}) => { | ||
| await yarn.writeConfiguration(path, { | ||
| catalog: { | ||
| [`no-deps`]: `2.0.0`, | ||
| }, | ||
| catalogs: { | ||
| tools: { | ||
| [`one-fixed-dep`]: `1.0.0`, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await run(`install`); | ||
|
|
||
| // Check that the lockfile contains the resolved versions | ||
| const lockfile = await xfs.readFilePromise(`${path}/yarn.lock` as PortablePath, `utf8`); | ||
| expect(lockfile).toMatch(/no-deps@npm:2\.0\.0/); | ||
| expect(lockfile).toMatch(/one-fixed-dep@npm:1\.0\.0/); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should replace catalog references with actual versions during pack`, | ||
| makeTemporaryEnv( | ||
| { | ||
| name: `my-package`, | ||
| version: `1.0.0`, | ||
| dependencies: { | ||
| [`no-deps`]: `catalog:`, | ||
| }, | ||
| devDependencies: { | ||
| [`one-fixed-dep`]: `catalog:dev`, | ||
| }, | ||
| }, | ||
| async ({path, run}) => { | ||
| await yarn.writeConfiguration(path, { | ||
| catalog: { | ||
| [`no-deps`]: `^2.0.0`, | ||
| }, | ||
| catalogs: { | ||
| dev: { | ||
| [`one-fixed-dep`]: `~1.0.0`, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await run(`install`); | ||
| await run(`pack`); | ||
|
|
||
| // Unpack the tarball and check the package.json content | ||
| await fsUtils.unpackToDirectory(path, `${path}/package.tgz` as PortablePath); | ||
|
|
||
| const packedManifest = await xfs.readJsonPromise(`${path}/package/package.json` as PortablePath); | ||
|
|
||
| expect(packedManifest.dependencies[`no-deps`]).toBe(`npm:^2.0.0`); | ||
| expect(packedManifest.devDependencies[`one-fixed-dep`]).toBe(`npm:~1.0.0`); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should handle complex version ranges in catalogs`, | ||
| makeTemporaryEnv( | ||
| { | ||
| dependencies: { | ||
| [`no-deps`]: `catalog:`, | ||
| }, | ||
| }, | ||
| async ({path, run, source}) => { | ||
| await yarn.writeConfiguration(path, { | ||
| catalog: { | ||
| [`no-deps`]: `>=1.0.0 <3.0.0`, | ||
| }, | ||
| }); | ||
|
|
||
| await run(`install`); | ||
|
|
||
| // Should resolve to the highest compatible version (2.0.0) | ||
| await expect(source(`require('no-deps')`)).resolves.toMatchObject({ | ||
| name: `no-deps`, | ||
| version: `2.0.0`, | ||
| }); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should throw an error when catalog is not found`, | ||
| makeTemporaryEnv( | ||
| { | ||
| dependencies: { | ||
| [`no-deps`]: `catalog:nonexistent`, | ||
| }, | ||
| }, | ||
| async ({path, run}) => { | ||
| await yarn.writeConfiguration(path, { | ||
| catalog: { | ||
| [`no-deps`]: `2.0.0`, | ||
| }, | ||
| }); | ||
|
|
||
| await expect(run(`install`)).rejects.toThrow(); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should throw an error when catalog entry is not found`, | ||
| makeTemporaryEnv( | ||
| { | ||
| dependencies: { | ||
| [`nonexistent-package`]: `catalog:`, | ||
| }, | ||
| }, | ||
| async ({path, run}) => { | ||
| await yarn.writeConfiguration(path, { | ||
| catalog: { | ||
| [`no-deps`]: `2.0.0`, | ||
| }, | ||
| }); | ||
|
|
||
| await expect(run(`install`)).rejects.toThrow(); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should throw an error when default catalog is empty`, | ||
| makeTemporaryEnv( | ||
| { | ||
| dependencies: { | ||
| [`no-deps`]: `catalog:`, | ||
| }, | ||
| }, | ||
| async ({path, run}) => { | ||
| await yarn.writeConfiguration(path, { | ||
| catalog: {}, | ||
| }); | ||
|
|
||
| await expect(run(`install`)).rejects.toThrow(); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should work with file: protocol ranges in catalogs`, | ||
| makeTemporaryEnv( | ||
| { | ||
| dependencies: { | ||
| [`my-local-package`]: `catalog:`, | ||
| }, | ||
| }, | ||
| async ({path, run}) => { | ||
| // Create a local package | ||
| await xfs.mkdirPromise(`${path}/local-package` as PortablePath, {recursive: true}); | ||
| await xfs.writeJsonPromise(`${path}/local-package/package.json` as PortablePath, { | ||
| name: `my-local-package`, | ||
| version: `1.0.0`, | ||
| }); | ||
|
|
||
| await yarn.writeConfiguration(path, { | ||
| catalog: { | ||
| [`my-local-package`]: `file:./local-package`, | ||
| }, | ||
| }); | ||
|
|
||
| await run(`install`); | ||
|
|
||
| // Verify that the local package was installed | ||
| const lockfile = await xfs.readFilePromise(`${path}/yarn.lock` as PortablePath, `utf8`); | ||
| expect(lockfile).toMatch(/my-local-package@file:\.\/local-package/); | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| test( | ||
| `it should work in workspace environments`, | ||
| makeTemporaryMonorepoEnv( | ||
| { | ||
| workspaces: [`packages/*`], | ||
| }, | ||
| { | ||
| packages: {}, | ||
| }, | ||
| async ({path, run}) => { | ||
| // Create workspace package | ||
| await xfs.mkdirPromise(`${path}/packages/workspace-a` as PortablePath, {recursive: true}); | ||
| await xfs.writeJsonPromise(`${path}/packages/workspace-a/package.json` as PortablePath, { | ||
| name: `workspace-a`, | ||
| version: `1.0.0`, | ||
| dependencies: { | ||
| [`no-deps`]: `catalog:`, | ||
| }, | ||
| }); | ||
|
|
||
| await yarn.writeConfiguration(path, { | ||
| catalog: { | ||
| [`no-deps`]: `2.0.0`, | ||
| }, | ||
| }); | ||
|
|
||
| await run(`install`); | ||
|
|
||
| // Verify that the workspace dependency was resolved from catalog | ||
| const lockfile = await xfs.readFilePromise(`${path}/yarn.lock` as PortablePath, `utf8`); | ||
| expect(lockfile).toMatch(/no-deps@npm:2\.0\.0/); | ||
| }, | ||
| ), | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be updated after other discussions are resolved.