mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
feat(publish): support "publishConfig.directory" field (#3490)
This commit is contained in:
7
.changeset/pretty-moose-speak.md
Normal file
7
.changeset/pretty-moose-speak.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-publishing": minor
|
||||
"@pnpm/run-npm": minor
|
||||
"@pnpm/types": minor
|
||||
---
|
||||
|
||||
support "publishConfig.directory" field
|
||||
@@ -188,7 +188,12 @@ Do you want to continue?`,
|
||||
}
|
||||
}
|
||||
|
||||
const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', ...args])
|
||||
const cwd = manifest.publishConfig?.directory ? path.join(dir, manifest.publishConfig.directory) : undefined
|
||||
|
||||
const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', ...args], {
|
||||
cwd,
|
||||
})
|
||||
|
||||
_status = status!
|
||||
}
|
||||
)
|
||||
|
||||
@@ -277,6 +277,57 @@ test('publish: package with all possible fields in publishConfig', async () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('publish: package with publishConfig.directory', async () => {
|
||||
const packages = preparePackages([
|
||||
{
|
||||
name: 'test-publish-config-directory',
|
||||
version: '1.0.0',
|
||||
|
||||
publishConfig: {
|
||||
directory: 'dist',
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
const testPublishConfigDirectory = packages['test-publish-config-directory']
|
||||
|
||||
expect(testPublishConfigDirectory).toBeTruthy()
|
||||
|
||||
await fs.mkdir(path.join(testPublishConfigDirectory.dir(), 'dist'))
|
||||
|
||||
await fs.writeFile(
|
||||
path.join(testPublishConfigDirectory.dir(), 'dist/package.json'),
|
||||
`
|
||||
{
|
||||
"name": "publish_config_directory_dist_package",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
`,
|
||||
{
|
||||
encoding: 'utf-8',
|
||||
}
|
||||
)
|
||||
|
||||
process.chdir('test-publish-config-directory')
|
||||
|
||||
await publish.handler(
|
||||
{
|
||||
...DEFAULT_OPTS,
|
||||
argv: { original: ['publish', ...CREDENTIALS] },
|
||||
dir: process.cwd(),
|
||||
},
|
||||
[]
|
||||
)
|
||||
|
||||
crossSpawn.sync(pnpmBin, ['add', 'publish_config_directory_dist_package', '--no-link-workspace-packages', `--registry=http://localhost:${REGISTRY_MOCK_PORT}`])
|
||||
|
||||
expect(JSON.parse(await fs.readFile('node_modules/publish_config_directory_dist_package/package.json', { encoding: 'utf-8' })))
|
||||
.toStrictEqual({
|
||||
name: 'publish_config_directory_dist_package',
|
||||
version: '1.0.0',
|
||||
})
|
||||
})
|
||||
|
||||
test.skip('publish package that calls executable from the workspace .bin folder in prepublishOnly script', async () => {
|
||||
preparePackages([
|
||||
{
|
||||
|
||||
@@ -3,10 +3,14 @@ import path from 'path'
|
||||
import spawn from 'cross-spawn'
|
||||
import PATH from 'path-name'
|
||||
|
||||
export default function runNpm (npmPath: string | undefined, args: string[]) {
|
||||
export interface RunNPMOptions {
|
||||
cwd?: string
|
||||
}
|
||||
|
||||
export default function runNpm (npmPath: string | undefined, args: string[], options?: RunNPMOptions) {
|
||||
const npm = npmPath ?? 'npm'
|
||||
return runScriptSync(npm, args, {
|
||||
cwd: process.cwd(),
|
||||
cwd: options?.cwd ?? process.cwd(),
|
||||
stdio: 'inherit',
|
||||
userAgent: undefined,
|
||||
})
|
||||
|
||||
@@ -46,6 +46,10 @@ export interface PeerDependenciesMeta {
|
||||
}
|
||||
}
|
||||
|
||||
export interface PublishConfig extends Record<string, unknown> {
|
||||
directory?: string
|
||||
}
|
||||
|
||||
interface BaseManifest {
|
||||
name?: string
|
||||
version?: string
|
||||
@@ -76,7 +80,7 @@ interface BaseManifest {
|
||||
module?: string
|
||||
typings?: string
|
||||
types?: string
|
||||
publishConfig?: Record<string, unknown>
|
||||
publishConfig?: PublishConfig
|
||||
}
|
||||
|
||||
export type DependencyManifest = BaseManifest & Required<Pick<BaseManifest, 'name' | 'version'>>
|
||||
|
||||
Reference in New Issue
Block a user