mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
feat: new setting recursive-install
When `recursive-install` is set to `false`, `pnpm install` is installing only the current project in a workspace. close #2150 close #2476 PR #2657
This commit is contained in:
5
.changeset/four-hairs-clap.md
Normal file
5
.changeset/four-hairs-clap.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/parse-cli-args": major
|
||||
---
|
||||
|
||||
move recursive for workspace check to pnpm main
|
||||
6
.changeset/little-peas-applaud.md
Normal file
6
.changeset/little-peas-applaud.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/config": minor
|
||||
"pnpm": minor
|
||||
---
|
||||
|
||||
feat: add config to make install only install package dependencies in a workspace
|
||||
@@ -111,6 +111,7 @@ export interface Config {
|
||||
npmPath?: string,
|
||||
gitChecks?: boolean,
|
||||
publishBranch?: string,
|
||||
recursiveInstall?: boolean,
|
||||
|
||||
registries: Registries,
|
||||
ignoreWorkspaceRootCheck: boolean,
|
||||
|
||||
@@ -61,6 +61,7 @@ export const types = Object.assign({
|
||||
'production': [null, true],
|
||||
'public-hoist-pattern': Array,
|
||||
'publish-branch': String,
|
||||
'recursive-install': Boolean,
|
||||
'reporter': String,
|
||||
'save-peer': Boolean,
|
||||
'save-workspace-protocol': Boolean,
|
||||
@@ -147,6 +148,7 @@ export default async (
|
||||
'package-lock': npmDefaults['package-lock'],
|
||||
'pending': false,
|
||||
'public-hoist-pattern': ['@types/*'],
|
||||
'recursive-install': true,
|
||||
'registry': npmDefaults.registry,
|
||||
'save-peer': false,
|
||||
'save-workspace-protocol': true,
|
||||
|
||||
@@ -118,14 +118,6 @@ export default async function parseCliArgs (
|
||||
? undefined
|
||||
: await findWorkspaceDir(dir)
|
||||
|
||||
if (
|
||||
(cmd === 'add' || cmd === 'install') &&
|
||||
typeof workspaceDir === 'string' &&
|
||||
params.length === 0
|
||||
) {
|
||||
options['recursive'] = true
|
||||
}
|
||||
|
||||
if (cmd === 'install' && params.length > 0) {
|
||||
cmd = 'add'
|
||||
}
|
||||
|
||||
@@ -43,29 +43,6 @@ test('a command is recursive if --recursive option is used', async (t) => {
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('the install command is recursive when executed in a subdir of a workspace', async (t) => {
|
||||
const { options, cmd, workspaceDir } = await parseCliArgs({
|
||||
...DEFAULT_OPTS,
|
||||
universalOptionsTypes: { dir: String },
|
||||
}, ['--dir', __dirname, 'install'])
|
||||
t.equal(cmd, 'install')
|
||||
t.ok(options['recursive'])
|
||||
t.equal(workspaceDir, path.join(__dirname, '../../..'))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('the install command is recursive when executed in the root of a workspace', async (t) => {
|
||||
const expectedWorkspaceDir = path.join(__dirname, '../../..')
|
||||
const { options, cmd, workspaceDir } = await parseCliArgs({
|
||||
...DEFAULT_OPTS,
|
||||
universalOptionsTypes: { dir: String },
|
||||
}, ['--dir', expectedWorkspaceDir, 'install'])
|
||||
t.equal(cmd, 'install')
|
||||
t.ok(options['recursive'])
|
||||
t.equal(workspaceDir, expectedWorkspaceDir)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('recursive is returned as the command name if no subcommand passed', async (t) => {
|
||||
const { options, cmd } = await parseCliArgs({
|
||||
...DEFAULT_OPTS,
|
||||
@@ -215,4 +192,4 @@ test("don't use the fallback command if no command is present", async (t) => {
|
||||
t.equal(cmd, null)
|
||||
t.deepEqual(params, [])
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -134,6 +134,15 @@ export default async function run (inputArgv: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
cmd === 'install' &&
|
||||
typeof workspaceDir === 'string' &&
|
||||
config.recursiveInstall
|
||||
) {
|
||||
cliOptions['recursive'] = true
|
||||
config.recursive = true
|
||||
}
|
||||
|
||||
if (cliOptions['recursive']) {
|
||||
const wsDir = workspaceDir ?? process.cwd()
|
||||
const allProjects = await findWorkspacePackages(wsDir, {
|
||||
|
||||
@@ -432,3 +432,39 @@ test('--workspace-packages', async (t: tape.Test) => {
|
||||
await projects['project-1'].has('is-positive')
|
||||
await projects['project-2'].hasNot('is-positive')
|
||||
})
|
||||
|
||||
test('set recursive-install to false in .npmrc would disable recursive install in workspace', async (t: tape.Test) => {
|
||||
const projects = preparePackages(t, [
|
||||
{
|
||||
location: 'workspace/project-1',
|
||||
package: {
|
||||
name: 'project-1',
|
||||
version: '1.0.0',
|
||||
|
||||
dependencies: {
|
||||
'is-positive': '1.0.0',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
location: 'workspace/project-2',
|
||||
package: {
|
||||
name: 'project-2',
|
||||
version: '1.0.0',
|
||||
|
||||
dependencies: {
|
||||
'is-negative': '1.0.0',
|
||||
},
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
await fs.writeFile('pnpm-workspace.yaml', '', 'utf8')
|
||||
await fs.writeFile('.npmrc', 'recursive-install = false', 'utf8')
|
||||
|
||||
process.chdir('project-1')
|
||||
await execPnpm(['install'])
|
||||
|
||||
t.ok(projects['project-1'].has('is-positive'))
|
||||
t.ok(projects['project-2'].hasNot('is-negative'))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user