mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix: relink the project when its publish directory changes (#5109)
* fix: relink the project when its publish directory changes * test: publish directory
This commit is contained in:
9
.changeset/modern-zoos-knock.md
Normal file
9
.changeset/modern-zoos-knock.md
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
"@pnpm/lockfile-file": minor
|
||||
"@pnpm/lockfile-types": minor
|
||||
"@pnpm/lockfile-utils": minor
|
||||
"@pnpm/resolve-dependencies": minor
|
||||
"pnpm": minor
|
||||
---
|
||||
|
||||
Add `publishDirectory` field to the lockfile and relink the project when it changes.
|
||||
@@ -1593,6 +1593,20 @@ test('symlink local package from the location described in its publishConfig.dir
|
||||
}
|
||||
await mutateModules(importers, await testDefaults({ workspacePackages }))
|
||||
|
||||
const linkedManifest = await loadJsonFile<{ name: string }>('project-2/node_modules/project-1/package.json')
|
||||
expect(linkedManifest.name).toBe('project-1-dist')
|
||||
{
|
||||
const linkedManifest = await loadJsonFile<{ name: string }>('project-2/node_modules/project-1/package.json')
|
||||
expect(linkedManifest.name).toBe('project-1-dist')
|
||||
}
|
||||
|
||||
const project = assertProject(process.cwd())
|
||||
const lockfile = await project.readLockfile()
|
||||
expect(lockfile.importers['project-1'].publishDirectory).toBe('dist')
|
||||
|
||||
await rimraf('node_modules')
|
||||
await mutateModules(importers, await testDefaults({ frozenLockfile: true, workspacePackages }))
|
||||
|
||||
{
|
||||
const linkedManifest = await loadJsonFile<{ name: string }>('project-2/node_modules/project-1/package.json')
|
||||
expect(linkedManifest.name).toBe('project-1-dist')
|
||||
}
|
||||
})
|
||||
|
||||
@@ -110,7 +110,7 @@ export function normalizeLockfile (lockfile: Lockfile, forceSharedFormat: boolea
|
||||
...lockfile,
|
||||
importers: Object.keys(lockfile.importers).reduce((acc, alias) => {
|
||||
const importer = lockfile.importers[alias]
|
||||
const normalizedImporter = {
|
||||
const normalizedImporter: ProjectSnapshot = {
|
||||
specifiers: importer.specifiers ?? {},
|
||||
}
|
||||
if (importer.dependenciesMeta != null && !isEmpty(importer.dependenciesMeta)) {
|
||||
@@ -121,6 +121,9 @@ export function normalizeLockfile (lockfile: Lockfile, forceSharedFormat: boolea
|
||||
normalizedImporter[depType] = importer[depType]
|
||||
}
|
||||
}
|
||||
if (importer.publishDirectory) {
|
||||
normalizedImporter.publishDirectory = importer.publishDirectory
|
||||
}
|
||||
acc[alias] = normalizedImporter
|
||||
return acc
|
||||
}, {}),
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface ProjectSnapshot {
|
||||
optionalDependencies?: ResolvedDependencies
|
||||
devDependencies?: ResolvedDependencies
|
||||
dependenciesMeta?: DependenciesMeta
|
||||
publishDirectory?: string
|
||||
}
|
||||
|
||||
export interface PackageSnapshots {
|
||||
|
||||
@@ -22,7 +22,10 @@ export default (lockfile: Lockfile, pkg: ProjectManifest, importerId: string, op
|
||||
},
|
||||
}
|
||||
}
|
||||
if (!equals(existingDeps, importer.specifiers)) {
|
||||
if (
|
||||
!equals(existingDeps, importer.specifiers) ||
|
||||
importer.publishDirectory !== pkg.publishConfig?.directory
|
||||
) {
|
||||
return false
|
||||
}
|
||||
if (!equals(pkg.dependenciesMeta ?? {}, importer.dependenciesMeta ?? {})) return false
|
||||
|
||||
@@ -283,4 +283,50 @@ test('satisfiesPackageManifest()', () => {
|
||||
bar: '^1.0.0',
|
||||
},
|
||||
}, '.', { autoInstallPeers: true })).toBe(true)
|
||||
|
||||
expect(satisfiesPackageManifest({
|
||||
...DEFAULT_LOCKFILE_FIELDS,
|
||||
importers: {
|
||||
'.': {
|
||||
dependencies: {
|
||||
foo: '1.0.0',
|
||||
},
|
||||
specifiers: {
|
||||
foo: '1.0.0',
|
||||
},
|
||||
publishDirectory: 'dist',
|
||||
},
|
||||
},
|
||||
}, {
|
||||
...DEFAULT_PKG_FIELDS,
|
||||
dependencies: {
|
||||
foo: '1.0.0',
|
||||
},
|
||||
publishConfig: {
|
||||
directory: 'dist',
|
||||
},
|
||||
}, '.')).toBe(true)
|
||||
|
||||
expect(satisfiesPackageManifest({
|
||||
...DEFAULT_LOCKFILE_FIELDS,
|
||||
importers: {
|
||||
'.': {
|
||||
dependencies: {
|
||||
foo: '1.0.0',
|
||||
},
|
||||
specifiers: {
|
||||
foo: '1.0.0',
|
||||
},
|
||||
publishDirectory: 'dist',
|
||||
},
|
||||
},
|
||||
}, {
|
||||
...DEFAULT_PKG_FIELDS,
|
||||
dependencies: {
|
||||
foo: '1.0.0',
|
||||
},
|
||||
publishConfig: {
|
||||
directory: 'lib',
|
||||
},
|
||||
}, '.')).toBe(false)
|
||||
})
|
||||
|
||||
@@ -309,13 +309,17 @@ function addDirectDependenciesToLockfile (
|
||||
registries: Registries,
|
||||
autoInstallPeers?: boolean
|
||||
): ProjectSnapshot {
|
||||
const newProjectSnapshot = {
|
||||
const newProjectSnapshot: ProjectSnapshot & Required<Pick<ProjectSnapshot, 'dependencies' | 'devDependencies' | 'optionalDependencies'>> = {
|
||||
dependencies: {},
|
||||
devDependencies: {},
|
||||
optionalDependencies: {},
|
||||
specifiers: {},
|
||||
}
|
||||
|
||||
if (newManifest.publishConfig?.directory) {
|
||||
newProjectSnapshot.publishDirectory = newManifest.publishConfig.directory
|
||||
}
|
||||
|
||||
linkedPackages.forEach((linkedPkg) => {
|
||||
newProjectSnapshot.specifiers[linkedPkg.alias] = getSpecFromPackageManifest(newManifest, linkedPkg.alias)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user