mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
7
.changeset/lemon-impalas-wave.md
Normal file
7
.changeset/lemon-impalas-wave.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@pnpm/npm-resolver": minor
|
||||
"@pnpm/types": minor
|
||||
"pnpm": minor
|
||||
---
|
||||
|
||||
When `publishConfig.directory` is set, only symlink it to other workspace projects if `publishConfig.linkDirectory` is set to `true`. Otherwise, only use it for publishing [#5115](https://github.com/pnpm/pnpm/issues/5115).
|
||||
@@ -1532,7 +1532,87 @@ test('do not update dependency that has the same name as a dependency in the wor
|
||||
])
|
||||
})
|
||||
|
||||
test('symlink local package from the location described in its publishConfig.directory', async () => {
|
||||
test('symlink local package from the location described in its publishConfig.directory when linkDirectory is true', async () => {
|
||||
preparePackages([
|
||||
{
|
||||
location: 'project-1',
|
||||
package: { name: 'project-1' },
|
||||
},
|
||||
{
|
||||
location: 'project-1/dist',
|
||||
package: { name: 'project-1-dist' },
|
||||
},
|
||||
{
|
||||
location: 'project-2',
|
||||
package: { name: 'project-2' },
|
||||
},
|
||||
])
|
||||
|
||||
const project1Manifest = {
|
||||
name: 'project-1',
|
||||
version: '1.0.0',
|
||||
publishConfig: {
|
||||
directory: 'dist',
|
||||
linkDirectory: true,
|
||||
},
|
||||
}
|
||||
const project2Manifest = {
|
||||
name: 'project-2',
|
||||
version: '1.0.0',
|
||||
|
||||
dependencies: {
|
||||
'project-1': 'workspace:*',
|
||||
},
|
||||
}
|
||||
const importers: MutatedProject[] = [
|
||||
{
|
||||
buildIndex: 0,
|
||||
manifest: project1Manifest,
|
||||
mutation: 'install',
|
||||
rootDir: path.resolve('project-1'),
|
||||
},
|
||||
{
|
||||
buildIndex: 0,
|
||||
manifest: project2Manifest,
|
||||
mutation: 'install',
|
||||
rootDir: path.resolve('project-2'),
|
||||
},
|
||||
]
|
||||
const workspacePackages = {
|
||||
'project-1': {
|
||||
'1.0.0': {
|
||||
dir: path.resolve('project-1'),
|
||||
manifest: project1Manifest,
|
||||
},
|
||||
},
|
||||
'project-2': {
|
||||
'1.0.0': {
|
||||
dir: path.resolve('project-2'),
|
||||
manifest: project2Manifest,
|
||||
},
|
||||
},
|
||||
}
|
||||
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 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')
|
||||
}
|
||||
})
|
||||
|
||||
test('do not symlink local package from the location described in its publishConfig.directory', async () => {
|
||||
preparePackages([
|
||||
{
|
||||
location: 'project-1',
|
||||
@@ -1593,20 +1673,6 @@ 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 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')
|
||||
}
|
||||
const linkedManifest = await loadJsonFile<{ name: string }>('project-2/node_modules/project-1/package.json')
|
||||
expect(linkedManifest.name).toBe('project-1')
|
||||
})
|
||||
|
||||
@@ -328,7 +328,10 @@ function resolveFromLocalPackage (
|
||||
}
|
||||
|
||||
function resolveLocalPackageDir (localPackage: LocalPackage) {
|
||||
if (localPackage.manifest.publishConfig?.directory == null) return localPackage.dir
|
||||
if (
|
||||
localPackage.manifest.publishConfig?.directory == null ||
|
||||
localPackage.manifest.publishConfig?.linkDirectory !== true
|
||||
) return localPackage.dir
|
||||
return path.join(localPackage.dir, localPackage.manifest.publishConfig.directory)
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ export interface DependenciesMeta {
|
||||
|
||||
export interface PublishConfig extends Record<string, unknown> {
|
||||
directory?: string
|
||||
linkDirectory?: boolean
|
||||
executableFiles?: string[]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user