Skip to content
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

Fix add bug with overlapping workspace packages #4575

Merged
merged 5 commits into from Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/strange-parents-drum.md
@@ -0,0 +1,7 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---

Don't update a direct dependency that has the same name as a dependency in the workspace, when adding a new dependency to a workspace project [#4575](https://github.com/pnpm/pnpm/pull/4575).

69 changes: 69 additions & 0 deletions packages/core/test/install/multipleImporters.ts
Expand Up @@ -1316,3 +1316,72 @@ test('install the dependency that is already present in the workspace when addin
expect(currentLockfile.importers['project-1'].dependencies?.['dep-of-pkg-with-1-dep']).toBe('100.0.0')
expect(currentLockfile.importers['project-2'].dependencies?.['dep-of-pkg-with-1-dep']).toBe('100.0.0')
})

test('do not update dependency that has the same name as a dependency in the workspace', async () => {
await addDistTag({ package: 'dep-of-pkg-with-1-dep', version: '100.0.0', distTag: 'latest' })
const manifest1: ProjectManifest = {
name: 'project-1',
version: '1.0.0',
dependencies: {
'dep-of-pkg-with-1-dep': '^100.0.0',
},
}
const manifest2: ProjectManifest = { name: 'dep-of-pkg-with-1-dep', version: '100.1.0' }

preparePackages([
{
location: 'project-1',
package: manifest1,
},
{
location: 'project-2',
package: manifest2,
},
])

const importers: MutatedProject[] = [
{
buildIndex: 0,
manifest: manifest1,
mutation: 'install',
rootDir: path.resolve('project-1'),
},
{
buildIndex: 0,
manifest: manifest2,
mutation: 'install',
rootDir: path.resolve('project-2'),
},
]
const workspacePackages = {
'project-1': {
'1.0.0': {
dir: path.resolve('project-1'),
manifest: manifest1,
},
},
'dep-of-pkg-with-1-dep': {
'100.1.0': {
dir: path.resolve('project-2'),
manifest: manifest2,
},
},
}
await mutateModules(importers, await testDefaults({ linkWorkspacePackagesDepth: -1, workspacePackages }))
await addDistTag({ package: 'dep-of-pkg-with-1-dep', version: '100.1.0', distTag: 'latest' })
await mutateModules([
{
...importers[0],
dependencySelectors: ['is-negative@2.1.0'],
mutation: 'installSome',
},
importers[1],
], await testDefaults({ linkWorkspacePackagesDepth: -1, workspacePackages, preferredVersions: {} }))

const rootModules = assertProject(process.cwd())
const currentLockfile = await rootModules.readCurrentLockfile()
expect(Object.keys(currentLockfile.packages)).toStrictEqual([
'/dep-of-pkg-with-1-dep/100.0.0',
'/is-negative/2.1.0',
])
})
1 change: 1 addition & 0 deletions packages/resolve-dependencies/src/resolveDependencies.ts
Expand Up @@ -283,6 +283,7 @@ async function resolveDependenciesOfDependency (
)
) || Boolean(
(options.workspacePackages != null) &&
ctx.linkWorkspacePackagesDepth !== -1 &&
wantedDepIsLocallyAvailable(
options.workspacePackages,
extendedWantedDep.wantedDependency,
Expand Down
3 changes: 1 addition & 2 deletions utils/eslint-config/package.json
Expand Up @@ -10,8 +10,7 @@
"bugs": {
"url": "https://github.com/pnpm/eslint-config/issues"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "index.js",
"directories": {
"test": "test"
},
Expand Down