feat: add ignore-workspace-cycles to silence workspace cycle warning (#6308)

This commit is contained in:
Jake Bailey
2023-03-29 13:18:27 -07:00
committed by GitHub
parent e87754df1f
commit e2cb4b63d2
8 changed files with 46 additions and 2 deletions

View File

@@ -0,0 +1,8 @@
---
"pnpm": minor
"@pnpm/plugin-commands-installation": minor
"@pnpm/core": minor
"@pnpm/config": minor
---
Add `ignore-workspace-cycles` to silence workspace cycle warning [#6308](https://github.com/pnpm/pnpm/pull/6308).

View File

@@ -158,6 +158,7 @@ export interface Config {
onlyBuiltDependencies?: string[] onlyBuiltDependencies?: string[]
dedupePeerDependents?: boolean dedupePeerDependents?: boolean
patchesDir?: string patchesDir?: string
ignoreWorkspaceCycles?: boolean
registries: Registries registries: Registries
ignoreWorkspaceRootCheck: boolean ignoreWorkspaceRootCheck: boolean

View File

@@ -64,6 +64,7 @@ export const types = Object.assign({
'ignore-dep-scripts': Boolean, 'ignore-dep-scripts': Boolean,
'ignore-pnpmfile': Boolean, 'ignore-pnpmfile': Boolean,
'ignore-workspace': Boolean, 'ignore-workspace': Boolean,
'ignore-workspace-cycles': Boolean,
'ignore-workspace-root-check': Boolean, 'ignore-workspace-root-check': Boolean,
'include-workspace-root': Boolean, 'include-workspace-root': Boolean,
'legacy-dir-filtering': Boolean, 'legacy-dir-filtering': Boolean,
@@ -205,6 +206,7 @@ export async function getConfig (
'git-branch-lockfile': false, 'git-branch-lockfile': false,
hoist: true, hoist: true,
'hoist-pattern': ['*'], 'hoist-pattern': ['*'],
'ignore-workspace-cycles': false,
'ignore-workspace-root-check': false, 'ignore-workspace-root-check': false,
'link-workspace-packages': true, 'link-workspace-packages': true,
'lockfile-include-tarball-url': false, 'lockfile-include-tarball-url': false,

View File

@@ -102,6 +102,7 @@ export interface StrictInstallOptions {
preferSymlinkedExecutables: boolean preferSymlinkedExecutables: boolean
resolutionMode: 'highest' | 'time-based' | 'lowest-direct' resolutionMode: 'highest' | 'time-based' | 'lowest-direct'
resolvePeersFromWorkspaceRoot: boolean resolvePeersFromWorkspaceRoot: boolean
ignoreWorkspaceCycles: boolean
publicHoistPattern: string[] | undefined publicHoistPattern: string[] | undefined
hoistPattern: string[] | undefined hoistPattern: string[] | undefined
@@ -205,6 +206,7 @@ const defaults = async (opts: InstallOptions) => {
dedupePeerDependents: true, dedupePeerDependents: true,
resolvePeersFromWorkspaceRoot: true, resolvePeersFromWorkspaceRoot: true,
extendNodePath: true, extendNodePath: true,
ignoreWorkspaceCycles: false,
} as StrictInstallOptions } as StrictInstallOptions
} }

View File

@@ -88,6 +88,7 @@ export type ImportCommandOptions = Pick<Config,
| 'allProjectsGraph' | 'allProjectsGraph'
| 'selectedProjectsGraph' | 'selectedProjectsGraph'
| 'workspaceDir' | 'workspaceDir'
| 'ignoreWorkspaceCycles'
> & CreateStoreControllerOptions & Omit<InstallOptions, 'storeController' | 'lockfileOnly' | 'preferredVersions'> > & CreateStoreControllerOptions & Omit<InstallOptions, 'storeController' | 'lockfileOnly' | 'preferredVersions'>
export async function handler ( export async function handler (
@@ -120,7 +121,7 @@ export async function handler (
if (selectedProjectsGraph != null) { if (selectedProjectsGraph != null) {
const sequencedGraph = sequenceGraph(selectedProjectsGraph) const sequencedGraph = sequenceGraph(selectedProjectsGraph)
// Check and warn if there are cyclic dependencies // Check and warn if there are cyclic dependencies
if (!sequencedGraph.safe) { if (!opts.ignoreWorkspaceCycles && !sequencedGraph.safe) {
const cyclicDependenciesInfo = sequencedGraph.cycles.length > 0 const cyclicDependenciesInfo = sequencedGraph.cycles.length > 0
? `: ${sequencedGraph.cycles.map(deps => deps.join(', ')).join('; ')}` ? `: ${sequencedGraph.cycles.map(deps => deps.join(', ')).join('; ')}`
: '' : ''

View File

@@ -286,6 +286,7 @@ export type InstallCommandOptions = Pick<Config,
| 'workspaceDir' | 'workspaceDir'
| 'extraEnv' | 'extraEnv'
| 'resolutionMode' | 'resolutionMode'
| 'ignoreWorkspaceCycles'
> & CreateStoreControllerOptions & { > & CreateStoreControllerOptions & {
argv: { argv: {
original: string[] original: string[]

View File

@@ -78,6 +78,7 @@ export type InstallDepsOptions = Pick<Config,
| 'workspaceConcurrency' | 'workspaceConcurrency'
| 'workspaceDir' | 'workspaceDir'
| 'extraEnv' | 'extraEnv'
| 'ignoreWorkspaceCycles'
> & CreateStoreControllerOptions & { > & CreateStoreControllerOptions & {
argv: { argv: {
original: string[] original: string[]
@@ -138,7 +139,7 @@ when running add/update with the --workspace option')
if (selectedProjectsGraph != null) { if (selectedProjectsGraph != null) {
const sequencedGraph = sequenceGraph(selectedProjectsGraph) const sequencedGraph = sequenceGraph(selectedProjectsGraph)
// Check and warn if there are cyclic dependencies // Check and warn if there are cyclic dependencies
if (!sequencedGraph.safe) { if (!opts.ignoreWorkspaceCycles && !sequencedGraph.safe) {
const cyclicDependenciesInfo = sequencedGraph.cycles.length > 0 const cyclicDependenciesInfo = sequencedGraph.cycles.length > 0
? `: ${sequencedGraph.cycles.map(deps => deps.join(', ')).join('; ')}` ? `: ${sequencedGraph.cycles.map(deps => deps.join(', ')).join('; ')}`
: '' : ''

View File

@@ -43,6 +43,34 @@ test('should warn about cyclic dependencies', async () => {
}) })
}) })
test('should not warn about cyclic dependencies if ignore-workspace-cycles is set', async () => {
preparePackages([
{
name: 'project-1',
version: '1.0.0',
dependencies: { 'project-2': 'workspace:*' },
},
{
name: 'project-2',
version: '2.0.0',
devDependencies: { 'project-1': 'workspace:*' },
},
])
const { allProjects, selectedProjectsGraph } = await readProjects(process.cwd(), [])
await install.handler({
...DEFAULT_OPTS,
allProjects,
dir: process.cwd(),
recursive: true,
selectedProjectsGraph,
workspaceDir: process.cwd(),
ignoreWorkspaceCycles: true,
})
expect(logger.warn).toHaveBeenCalledTimes(0)
})
test('should not warn about cyclic dependencies if there are not', async () => { test('should not warn about cyclic dependencies if there are not', async () => {
preparePackages([ preparePackages([
{ {