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

feat: publishConfig.linkDirectory #5125

Merged
merged 2 commits into from
Jul 31, 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
7 changes: 7 additions & 0 deletions .changeset/lemon-impalas-wave.md
Original file line number Diff line number Diff line change
@@ -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).
68 changes: 67 additions & 1 deletion packages/core/test/install/multipleImporters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ 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',
Expand All @@ -1553,6 +1553,7 @@ test('symlink local package from the location described in its publishConfig.dir
version: '1.0.0',
publishConfig: {
directory: 'dist',
linkDirectory: true,
},
}
const project2Manifest = {
Expand Down Expand Up @@ -1610,3 +1611,68 @@ test('symlink local package from the location described in its publishConfig.dir
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',
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',
},
}
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')
})
5 changes: 4 additions & 1 deletion packages/npm-resolver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions packages/types/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface DependenciesMeta {

export interface PublishConfig extends Record<string, unknown> {
directory?: string
linkDirectory?: boolean
executableFiles?: string[]
}

Expand Down