Skip to content

Commit

Permalink
feat: publishConfig.linkDirectory (#5125)
Browse files Browse the repository at this point in the history
close #5115
  • Loading branch information
zkochan committed Jul 31, 2022
1 parent 44544b4 commit c907984
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/lemon-impalas-wave.md
@@ -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
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
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
Expand Up @@ -56,6 +56,7 @@ export interface DependenciesMeta {

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

Expand Down

0 comments on commit c907984

Please sign in to comment.