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: a file dep has a file dep #4618

Merged
merged 3 commits into from Apr 25, 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
6 changes: 6 additions & 0 deletions .changeset/calm-lamps-occur.md
@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---

It should be possible to use a chain of local file dependencies [#4611](https://github.com/pnpm/pnpm/issues/4611).
42 changes: 41 additions & 1 deletion packages/core/test/install/local.ts
@@ -1,7 +1,8 @@
import { promises as fs } from 'fs'
import path from 'path'
import { LOCKFILE_VERSION } from '@pnpm/constants'
import { prepareEmpty } from '@pnpm/prepare'
import { Lockfile } from '@pnpm/lockfile-file'
import { prepareEmpty, preparePackages } from '@pnpm/prepare'
import { addDistTag } from '@pnpm/registry-mock'
import fixtures from '@pnpm/test-fixtures'
import {
Expand All @@ -11,6 +12,7 @@ import {
} from '@pnpm/core'
import rimraf from '@zkochan/rimraf'
import normalizePath from 'normalize-path'
import readYamlFile from 'read-yaml-file'
import symlinkDir from 'symlink-dir'
import { testDefaults } from '../utils'

Expand Down Expand Up @@ -239,3 +241,41 @@ test('frozen-lockfile: installation fails if the integrity of a tarball dependen
install(manifest, await testDefaults({ frozenLockfile: true }))
).rejects.toThrow(/Got unexpected checksum/)
})

test('deep local', async () => {
const manifest1 = {
name: 'project-1',
version: '1.0.0',
dependencies: {
'project-2': 'file:../project-2',
},
}
preparePackages([
{
location: 'project-1',
package: manifest1,
},
{
location: 'project-2',
package: {
name: 'project-2',
version: '1.0.0',
dependencies: {
'project-3': 'file:./project-3',
},
},
},
{
location: 'project-2/project-3',
package: {
name: 'project-3',
version: '1.0.0',
},
},
])
process.chdir('../project-1')
await install(manifest1, await testDefaults())

const lockfile = await readYamlFile<Lockfile>('pnpm-lock.yaml')
expect(Object.keys(lockfile.packages ?? {})).toStrictEqual(['file:../project-2', 'file:../project-2/project-3'])
})
9 changes: 7 additions & 2 deletions packages/resolve-dependencies/src/resolveDependencies.ts
Expand Up @@ -159,6 +159,7 @@ export type PkgAddress = {
pkg: PackageManifest
version?: string
updated: boolean
rootDir: string
} & ({
isLinkedDependency: true
version: string
Expand Down Expand Up @@ -199,7 +200,7 @@ export interface ResolvedPackage {
}
}

type ParentPkg = Pick<PkgAddress, 'nodeId' | 'installable' | 'depPath'>
type ParentPkg = Pick<PkgAddress, 'nodeId' | 'installable' | 'depPath' | 'rootDir'>

interface ResolvedDependenciesOptions {
currentDepth: number
Expand Down Expand Up @@ -625,7 +626,7 @@ async function resolveDependency (
!wantedDependency.pref.startsWith('file:')
)
? ctx.lockfileDir
: ctx.prefix,
: options.parentPkg.rootDir,
registry: wantedDependency.alias && pickRegistryForPackage(ctx.registries, wantedDependency.alias, wantedDependency.pref) || ctx.registries.default,
// Unfortunately, even when run with --lockfile-only, we need the *real* package.json
// so fetching of the tarball cannot be ever avoided. Related issue: https://github.com/pnpm/pnpm/issues/1176
Expand Down Expand Up @@ -823,6 +824,9 @@ async function resolveDependency (
}
}

const rootDir = pkgResponse.body.resolution.type === 'directory'
? path.resolve(ctx.lockfileDir, pkgResponse.body.resolution['directory'])
: ctx.prefix
return {
alias: wantedDependency.alias || pkg.name,
depIsLinked,
Expand All @@ -831,6 +835,7 @@ async function resolveDependency (
nodeId,
normalizedPref: options.currentDepth === 0 ? pkgResponse.body.normalizedPref : undefined,
pkgId: pkgResponse.body.id,
rootDir,

// Next fields are actually only needed when isNew = true
installable,
Expand Down
Expand Up @@ -133,6 +133,7 @@ export default async function<T> (
nodeId: `>${importer.id}>`,
optional: false,
depPath: importer.id,
rootDir: importer.rootDir,
},
proceed,
resolvedDependencies: {
Expand Down