-
Notifications
You must be signed in to change notification settings - Fork 356
feat: support yarn catalogs #1582
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
Open
MKruschke
wants to merge
2
commits into
raineorshine:main
Choose a base branch
from
MKruschke:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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 |
|---|---|---|
|
|
@@ -550,7 +550,6 @@ catalogs: | |
| output.should.deep.equal({ | ||
| 'pnpm-workspace.yaml': { | ||
| packages: ['packages/**'], | ||
| catalog: { 'ncu-test-v2': '2.0.0' }, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this shouldn't happen because |
||
| catalogs: { default: { 'ncu-test-v2': '2.0.0' }, test: { 'ncu-test-tag': '1.1.0' } }, | ||
| }, | ||
| 'package.json': { dependencies: { 'ncu-test-v2': '2.0.0' } }, | ||
|
|
@@ -696,6 +695,128 @@ catalog: | |
| }) | ||
| }) | ||
|
|
||
| describe('yarn', () => { | ||
| it('update yarn catalog dependencies from yarnrc.yml (named catalogs)', async () => { | ||
| const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-')) | ||
| try { | ||
| const pkgDataRoot = JSON.stringify({ | ||
| workspaces: ['packages/**'], | ||
| dependencies: { | ||
| 'ncu-test-v2': '1.0.0', | ||
| }, | ||
| }) | ||
|
|
||
| const yarnConfig = ` | ||
| catalogs: | ||
| default: | ||
| ncu-test-v2: '1.0.0' | ||
| test: | ||
| ncu-test-tag: '1.0.0' | ||
| ` | ||
|
|
||
| // write root package file and yarnrc.yml | ||
| await fs.writeFile(path.join(tempDir, 'package.json'), pkgDataRoot, 'utf-8') | ||
| await fs.writeFile(path.join(tempDir, 'yarnrc.yml'), yarnConfig, 'utf-8') | ||
| await fs.writeFile(path.join(tempDir, 'yarn.lock'), '', 'utf-8') | ||
|
|
||
| // create workspace package | ||
| await fs.mkdir(path.join(tempDir, 'packages/a'), { recursive: true }) | ||
| await fs.writeFile( | ||
| path.join(tempDir, 'packages/a/package.json'), | ||
| JSON.stringify({ | ||
| dependencies: { | ||
| 'ncu-test-tag': 'catalog:test', | ||
| }, | ||
| }), | ||
| 'utf-8', | ||
| ) | ||
|
|
||
| const { stdout, stderr } = await spawn( | ||
| 'node', | ||
| [bin, '--jsonAll', '--workspaces'], | ||
| { rejectOnError: false }, | ||
| { cwd: tempDir }, | ||
| ) | ||
|
|
||
| // Assert no errors and valid output | ||
| stderr.should.be.empty | ||
| stdout.should.not.be.empty | ||
|
|
||
| const output = JSON.parse(stdout) | ||
|
|
||
| // Should include catalog updates | ||
| output.should.deep.equal({ | ||
| 'yarnrc.yml': { | ||
| catalogs: { default: { 'ncu-test-v2': '2.0.0' }, test: { 'ncu-test-tag': '1.1.0' } }, | ||
| }, | ||
| 'package.json': { workspaces: ['packages/**'], dependencies: { 'ncu-test-v2': '2.0.0' } }, | ||
| 'packages/a/package.json': { dependencies: { 'ncu-test-tag': 'catalog:test' } }, | ||
| }) | ||
| } finally { | ||
| await fs.rm(tempDir, { recursive: true, force: true }) | ||
| } | ||
| }) | ||
|
|
||
| it('update yarn catalog dependencies from yarnrc.yml (singular catalog)', async () => { | ||
| const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-')) | ||
| try { | ||
| const pkgDataRoot = JSON.stringify({ | ||
| workspaces: ['packages/**'], | ||
| dependencies: { | ||
| 'ncu-test-v2': '1.0.0', | ||
| }, | ||
| }) | ||
|
|
||
| const yarnConfig = ` | ||
| catalog: | ||
| ncu-test-v2: '1.0.0' | ||
| ncu-test-tag: '1.0.0' | ||
| ` | ||
|
|
||
| // write root package file and pnpm-workspace.yaml | ||
| await fs.writeFile(path.join(tempDir, 'package.json'), pkgDataRoot, 'utf-8') | ||
| await fs.writeFile(path.join(tempDir, 'yarnrc.yml'), yarnConfig, 'utf-8') | ||
| await fs.writeFile(path.join(tempDir, 'yarn.lock'), '', 'utf-8') | ||
|
|
||
| // create workspace package | ||
| await fs.mkdir(path.join(tempDir, 'packages/a'), { recursive: true }) | ||
| await fs.writeFile( | ||
| path.join(tempDir, 'packages/a/package.json'), | ||
| JSON.stringify({ | ||
| dependencies: { | ||
| 'ncu-test-tag': 'catalog:', | ||
| }, | ||
| }), | ||
| 'utf-8', | ||
| ) | ||
|
|
||
| const { stdout, stderr } = await spawn( | ||
| 'node', | ||
| [bin, '--jsonAll', '--workspaces'], | ||
| { rejectOnError: false }, | ||
| { cwd: tempDir }, | ||
| ) | ||
|
|
||
| // Assert no errors and valid output | ||
| stderr.should.be.empty | ||
| stdout.should.not.be.empty | ||
|
|
||
| const output = JSON.parse(stdout) | ||
|
|
||
| // Should include catalog updates | ||
| output.should.deep.equal({ | ||
| 'yarnrc.yml': { | ||
| catalog: { 'ncu-test-v2': '2.0.0', 'ncu-test-tag': '1.1.0' }, | ||
| }, | ||
| 'package.json': { workspaces: ['packages/**'], dependencies: { 'ncu-test-v2': '2.0.0' } }, | ||
| 'packages/a/package.json': { dependencies: { 'ncu-test-tag': 'catalog:' } }, | ||
| }) | ||
| } finally { | ||
| await fs.rm(tempDir, { recursive: true, force: true }) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| describe('bun', () => { | ||
| it('update bun catalog dependencies from package.json (top-level)', async () => { | ||
| const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-')) | ||
|
|
||
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.
this doesn't make really sense to me and would create an catalog entry which wasn't defined before (see also workspace.test.ts)
Uh oh!
There was an error while loading. Please reload this page.
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.
Are we sure this was wrong? I'm hesitant to remove anything from the existing catalog implementation, as this would be a breaking change.
i.e. is this a patch change or major change, and how many people are relying on this behavior currently.
@jakeboone02 Can you weigh in on the purpose of this block and the implications of removing it?
Uh oh!
There was an error while loading. Please reload this page.
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.
Hi @raineorshine, Hi @jakeboone02 ,
yes I'm pretty sure that this is the wrong behaviour and needs to be removed. Would even classify it as bug and not as breaking change.
Details:
For everyone that explicit is using a named catalog with the name
default(e.g.catalogs.defaultit will also break the usage of pnpm (see provide screenshot) because it will automatically introduce the default catalogcatalog(in the current ncu implementation called singular catalog) after running ncu. I tested it without ncu just added a named catalog default and run install with v10.13.1 as well as v10.26.2 of pnpm.