mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-28 02:53:15 -04:00
6
.changeset/calm-lamps-occur.md
Normal file
6
.changeset/calm-lamps-occur.md
Normal file
@@ -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).
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { promises as fs } from 'fs'
|
import { promises as fs } from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { LOCKFILE_VERSION } from '@pnpm/constants'
|
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 { addDistTag } from '@pnpm/registry-mock'
|
||||||
import fixtures from '@pnpm/test-fixtures'
|
import fixtures from '@pnpm/test-fixtures'
|
||||||
import {
|
import {
|
||||||
@@ -11,6 +12,7 @@ import {
|
|||||||
} from '@pnpm/core'
|
} from '@pnpm/core'
|
||||||
import rimraf from '@zkochan/rimraf'
|
import rimraf from '@zkochan/rimraf'
|
||||||
import normalizePath from 'normalize-path'
|
import normalizePath from 'normalize-path'
|
||||||
|
import readYamlFile from 'read-yaml-file'
|
||||||
import symlinkDir from 'symlink-dir'
|
import symlinkDir from 'symlink-dir'
|
||||||
import { testDefaults } from '../utils'
|
import { testDefaults } from '../utils'
|
||||||
|
|
||||||
@@ -239,3 +241,41 @@ test('frozen-lockfile: installation fails if the integrity of a tarball dependen
|
|||||||
install(manifest, await testDefaults({ frozenLockfile: true }))
|
install(manifest, await testDefaults({ frozenLockfile: true }))
|
||||||
).rejects.toThrow(/Got unexpected checksum/)
|
).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'])
|
||||||
|
})
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ export type PkgAddress = {
|
|||||||
pkg: PackageManifest
|
pkg: PackageManifest
|
||||||
version?: string
|
version?: string
|
||||||
updated: boolean
|
updated: boolean
|
||||||
|
rootDir: string
|
||||||
} & ({
|
} & ({
|
||||||
isLinkedDependency: true
|
isLinkedDependency: true
|
||||||
version: string
|
version: string
|
||||||
@@ -199,7 +200,7 @@ export interface ResolvedPackage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParentPkg = Pick<PkgAddress, 'nodeId' | 'installable' | 'depPath'>
|
type ParentPkg = Pick<PkgAddress, 'nodeId' | 'installable' | 'depPath' | 'rootDir'>
|
||||||
|
|
||||||
interface ResolvedDependenciesOptions {
|
interface ResolvedDependenciesOptions {
|
||||||
currentDepth: number
|
currentDepth: number
|
||||||
@@ -625,7 +626,7 @@ async function resolveDependency (
|
|||||||
!wantedDependency.pref.startsWith('file:')
|
!wantedDependency.pref.startsWith('file:')
|
||||||
)
|
)
|
||||||
? ctx.lockfileDir
|
? ctx.lockfileDir
|
||||||
: ctx.prefix,
|
: options.parentPkg.rootDir,
|
||||||
registry: wantedDependency.alias && pickRegistryForPackage(ctx.registries, wantedDependency.alias, wantedDependency.pref) || ctx.registries.default,
|
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
|
// 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
|
// so fetching of the tarball cannot be ever avoided. Related issue: https://github.com/pnpm/pnpm/issues/1176
|
||||||
@@ -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 {
|
return {
|
||||||
alias: wantedDependency.alias || pkg.name,
|
alias: wantedDependency.alias || pkg.name,
|
||||||
depIsLinked,
|
depIsLinked,
|
||||||
@@ -831,6 +835,7 @@ async function resolveDependency (
|
|||||||
nodeId,
|
nodeId,
|
||||||
normalizedPref: options.currentDepth === 0 ? pkgResponse.body.normalizedPref : undefined,
|
normalizedPref: options.currentDepth === 0 ? pkgResponse.body.normalizedPref : undefined,
|
||||||
pkgId: pkgResponse.body.id,
|
pkgId: pkgResponse.body.id,
|
||||||
|
rootDir,
|
||||||
|
|
||||||
// Next fields are actually only needed when isNew = true
|
// Next fields are actually only needed when isNew = true
|
||||||
installable,
|
installable,
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ export default async function<T> (
|
|||||||
nodeId: `>${importer.id}>`,
|
nodeId: `>${importer.id}>`,
|
||||||
optional: false,
|
optional: false,
|
||||||
depPath: importer.id,
|
depPath: importer.id,
|
||||||
|
rootDir: importer.rootDir,
|
||||||
},
|
},
|
||||||
proceed,
|
proceed,
|
||||||
resolvedDependencies: {
|
resolvedDependencies: {
|
||||||
|
|||||||
Reference in New Issue
Block a user