Skip to content

Commit

Permalink
Fix add bug with overlapping workspace packages (#4575)
Browse files Browse the repository at this point in the history
Co-authored-by: Zoltan Kochan <z@kochan.io>
  • Loading branch information
jondlm and zkochan committed Apr 16, 2022
1 parent f531e09 commit 0087000
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
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 @@ -1312,3 +1312,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

0 comments on commit 0087000

Please sign in to comment.