-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(npm): support yarn catalogs via yarn-plugin-catalogs #37293
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
58
commits into
renovatebot:main
Choose a base branch
from
MKruschke:feat/yarn-plugin-catalogs-support
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 46 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
67da7b0
refactor: rename pnpm specific type to reuse it for yarn as well
MKruschke ab690ff
refactor: use extractCatalogDeps for both cases
MKruschke fcc0159
feat: extract dependencies for yarn catalogs
MKruschke d436370
feat: updating dependency
MKruschke 8ca30d5
test: added more tests
MKruschke 7a53772
fix: fix typo
MKruschke d1874cd
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke 350379e
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke fd9bc29
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke 4cadc5c
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke 04cb16b
fix: remove debugger stmnt and undo line deletion
MKruschke 3e254ee
Merge remote-tracking branch 'origin/main' into feat/yarn-plugin-cata…
MKruschke 6cc85df
fix: remove core file
MKruschke 5ab19aa
fix: fix lint issues
MKruschke 72b6c13
fix: fix lint issues
MKruschke 0c261e7
fix: fix lint issues
MKruschke 8622e23
test: add more tests
MKruschke c654c2f
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke 90437ee
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke bfc0732
test: add more tests
MKruschke 6c77671
test: add test comments
MKruschke 72849f0
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke 3ac804d
test: add more tests
MKruschke a918957
test: add more tests
MKruschke 414f8c3
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke 7f20994
fix: remove unused variable
MKruschke 7e38f93
test: add more tests
MKruschke 39dea8d
fix: try to fix istanbul comments
MKruschke 4211ea6
fix: try v8 instead of istanbul
MKruschke 043fd00
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke 9a75e30
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke 1e69a45
Merge branch 'main' into feat/yarn-plugin-catalogs-support
viceice adca60c
Merge remote-tracking branch 'origin/main' into feat/yarn-plugin-cata…
MKruschke 8ac44af
chore: remove debugger statement
MKruschke 0046429
chore: fix v8 ignore statements
MKruschke eb70ee3
fix: remove core file
MKruschke 02ca083
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke ff63e13
fix: applied review suggestions
MKruschke 90ccad6
fix: change to manageFilePattern
MKruschke 693b441
Merge remote-tracking branch 'origin/main' into feat/yarn-plugin-cata…
MKruschke 5f1425f
fix: remove unused import
MKruschke b95c58f
fix: add return type
MKruschke 216b519
fix: fix tests
MKruschke 91c287d
Merge branch 'main' into feat/yarn-plugin-catalogs-support
MKruschke 3f1aadd
revert: unrelated tests changes
MKruschke 0bfbc90
fix: remove unused code after change the strategy
MKruschke 9ee3c7b
fix: apply review comments
MKruschke 3619d5e
fix: remove imports
MKruschke bd8a66b
revert: unwanted changes
MKruschke 2a61349
revert: unwanted changes
MKruschke 91bcff6
Merge remote-tracking branch 'origin/main' into feat/yarn-plugin-cata…
MKruschke 6c50ae5
refactore: use loadPackageJson
MKruschke e66caec
Update lib/modules/manager/npm/extract/common/package-file.spec.ts
MKruschke 8aef009
fix: apply review comments
MKruschke c681481
fix: remove unused import
MKruschke 7adbb9f
Apply suggestion from @RahulGautamSingh
MKruschke d73cf56
Apply suggestion from @RahulGautamSingh
MKruschke bf37bad
fix: apply review comments
MKruschke 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
64 changes: 64 additions & 0 deletions
64
lib/modules/manager/npm/extract/common/package-file.spec.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,64 @@ | ||
// hasPackageManager.test.ts | ||
import { logger } from '../../../../../logger'; | ||
import { regEx } from '../../../../../util/regex'; | ||
import { hasPackageManager } from './package-file'; | ||
|
||
// Mock logger + regEx dependencies used by hasPackageManager | ||
vitest.mock('../../../../../logger', () => ({ | ||
logger: { | ||
trace: vitest.fn(), | ||
debug: vitest.fn(), | ||
}, | ||
})); | ||
vitest.mock('../../../../../util/regex', () => ({ | ||
// make regEx return a real RegExp so exec() behaves naturally | ||
regEx: vitest.fn((pattern: string) => new RegExp(pattern)), | ||
})); | ||
MKruschke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
describe('modules/manager/npm/extract/common/package-file', () => { | ||
beforeEach(() => { | ||
vitest.clearAllMocks(); | ||
MKruschke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('returns true for a valid packageManager with name@range (e.g. [email protected])', () => { | ||
const content = JSON.stringify({ packageManager: '[email protected]' }); | ||
expect(hasPackageManager(content)).toBe(true); | ||
|
||
expect(logger.trace).toHaveBeenCalledWith( | ||
'npm.hasPackageManager from package.json', | ||
); | ||
expect(regEx).toHaveBeenCalledWith('^(?<name>.+)@(?<range>.+)$'); | ||
expect(logger.debug).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('returns true for a valid range like npm@^9', () => { | ||
const content = JSON.stringify({ packageManager: 'npm@^9' }); | ||
expect(hasPackageManager(content)).toBe(true); | ||
}); | ||
|
||
it('returns true for yarn classic pin [email protected]', () => { | ||
const content = JSON.stringify({ packageManager: '[email protected]' }); | ||
expect(hasPackageManager(content)).toBe(true); | ||
}); | ||
|
||
it("returns false when packageManager does not contain '@' (e.g. 'npm')", () => { | ||
const content = JSON.stringify({ packageManager: 'npm' }); | ||
expect(hasPackageManager(content)).toBe(false); | ||
}); | ||
|
||
it('returns false when packageManager is missing', () => { | ||
const content = JSON.stringify({ name: 'demo' }); | ||
expect(hasPackageManager(content)).toBe(false); | ||
}); | ||
|
||
it("returns false and logs 'Invalid JSON' when content is not valid JSON", () => { | ||
const bad = '{ not: valid json'; | ||
expect(hasPackageManager(bad)).toBe(false); | ||
expect(logger.debug).toHaveBeenCalledWith('Invalid JSON'); | ||
}); | ||
|
||
it('returns false if packageManager is an empty string', () => { | ||
const content = JSON.stringify({ packageManager: '' }); | ||
expect(hasPackageManager(content)).toBe(false); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -15,6 +15,10 @@ const defaultExtractConfig = { | |
|
||
const input01Content = Fixtures.get('inputs/01.json', '..'); | ||
const input02Content = Fixtures.get('inputs/02.json', '..'); | ||
const input01PackageManager = Fixtures.get( | ||
'inputs/01-package-manager.json', | ||
'..', | ||
); | ||
const input01GlobContent = Fixtures.get('inputs/01-glob.json', '..'); | ||
const workspacesContent = Fixtures.get('inputs/workspaces.json', '..'); | ||
const vendorisedContent = Fixtures.get('is-object.json', '..'); | ||
|
@@ -927,7 +931,7 @@ describe('modules/manager/npm/extract/index', () => { | |
const pJsonStr = JSON.stringify(pJson); | ||
const res = await npmExtract.extractPackageFile( | ||
pJsonStr, | ||
'package.json', | ||
'.yarnrc.yml', | ||
|
||
defaultExtractConfig, | ||
); | ||
expect(res).toMatchObject({ | ||
|
@@ -1268,6 +1272,138 @@ describe('modules/manager/npm/extract/index', () => { | |
}, | ||
]); | ||
}); | ||
|
||
it('extracts yarnrc.yml and adds it as packageFile', async () => { | ||
const yarnrc = codeBlock` | ||
nodeLinker: node-modules | ||
|
||
plugins: | ||
- checksum: 4cb9601cfc0c71e5b0ffd0a85b78e37430b62257040714c2558298ce1fc058f4e918903f0d1747a4fef3f58e15722c35bd76d27492d9d08aa5b04e235bf43b22 | ||
path: .yarn/plugins/@yarnpkg/plugin-catalogs.cjs | ||
spec: 'https://raw.githubusercontent.com/toss/yarn-plugin-catalogs/main/bundles/%40yarnpkg/plugin-catalogs.js' | ||
|
||
catalogs: | ||
list: | ||
is-positive: 1.0.0 | ||
`; | ||
fs.readLocalFile.mockResolvedValueOnce(yarnrc); | ||
|
||
fs.readLocalFile.mockResolvedValueOnce(input02Content); | ||
|
||
const res = await extractAllPackageFiles(defaultExtractConfig, [ | ||
'.yarnrc.yml', | ||
]); | ||
|
||
expect(res).toEqual([ | ||
{ | ||
deps: [ | ||
{ | ||
currentValue: '1.0.0', | ||
datasource: 'npm', | ||
depName: 'is-positive', | ||
depType: 'yarn.catalog.default', | ||
prettyDepType: 'yarn.catalog.default', | ||
}, | ||
], | ||
managerData: { | ||
hasPackageManager: false, | ||
}, | ||
packageFile: '.yarnrc.yml', | ||
}, | ||
]); | ||
}); | ||
|
||
it('extracts yarnrc.yml and adds it as packageFile and packageManager to true', async () => { | ||
const yarnrc = codeBlock` | ||
nodeLinker: node-modules | ||
|
||
plugins: | ||
- checksum: 4cb9601cfc0c71e5b0ffd0a85b78e37430b62257040714c2558298ce1fc058f4e918903f0d1747a4fef3f58e15722c35bd76d27492d9d08aa5b04e235bf43b22 | ||
path: .yarn/plugins/@yarnpkg/plugin-catalogs.cjs | ||
spec: 'https://raw.githubusercontent.com/toss/yarn-plugin-catalogs/main/bundles/%40yarnpkg/plugin-catalogs.js' | ||
|
||
catalogs: | ||
list: | ||
is-positive: 1.0.0 | ||
`; | ||
fs.findLocalSiblingOrParent.mockImplementation( | ||
async (_, name) => | ||
await new Promise((resolve) => | ||
resolve(name === 'package.json' ? 'package.json' : null), | ||
), | ||
); | ||
fs.findLocalSiblingOrParent.mockResolvedValue('package.json'); | ||
|
||
fs.readLocalFile.mockResolvedValueOnce(yarnrc); | ||
fs.readLocalFile.mockResolvedValueOnce(input01PackageManager); | ||
|
||
const res = await extractAllPackageFiles(defaultExtractConfig, [ | ||
'.yarnrc.yml', | ||
]); | ||
|
||
expect(res[0]).toEqual({ | ||
deps: [ | ||
{ | ||
currentValue: '1.0.0', | ||
datasource: 'npm', | ||
depName: 'is-positive', | ||
depType: 'yarn.catalog.default', | ||
prettyDepType: 'yarn.catalog.default', | ||
}, | ||
], | ||
managerData: { | ||
hasPackageManager: true, | ||
}, | ||
packageFile: '.yarnrc.yml', | ||
}); | ||
}); | ||
|
||
it('extracts yarnrc.yml and adds it as packageFile and packageManager to false if no deps', async () => { | ||
const yarnrc = codeBlock` | ||
nodeLinker: node-modules | ||
|
||
plugins: | ||
- checksum: 4cb9601cfc0c71e5b0ffd0a85b78e37430b62257040714c2558298ce1fc058f4e918903f0d1747a4fef3f58e15722c35bd76d27492d9d08aa5b04e235bf43b22 | ||
path: .yarn/plugins/@yarnpkg/plugin-catalogs.cjs | ||
spec: 'https://raw.githubusercontent.com/toss/yarn-plugin-catalogs/main/bundles/%40yarnpkg/plugin-catalogs.js' | ||
|
||
catalogs: | ||
list: | ||
is-positive: 1.0.0 | ||
`; | ||
|
||
fs.findLocalSiblingOrParent.mockImplementation( | ||
async (_, name) => | ||
await new Promise((resolve) => | ||
resolve(name === 'package.json' ? 'package.json' : null), | ||
), | ||
); | ||
fs.readLocalFile.mockResolvedValueOnce(yarnrc); | ||
|
||
fs.readLocalFile.mockResolvedValueOnce( | ||
'{"name": "simulate deps to be null", brokenJsonHere: }', | ||
); | ||
|
||
const res = await extractAllPackageFiles(defaultExtractConfig, [ | ||
'.yarnrc.yml', | ||
]); | ||
|
||
expect(res[0]).toEqual({ | ||
deps: [ | ||
{ | ||
currentValue: '1.0.0', | ||
datasource: 'npm', | ||
depName: 'is-positive', | ||
depType: 'yarn.catalog.default', | ||
prettyDepType: 'yarn.catalog.default', | ||
}, | ||
], | ||
managerData: { | ||
hasPackageManager: false, | ||
}, | ||
packageFile: '.yarnrc.yml', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('.postExtract()', () => { | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.