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[]
dedupePeerDependents?: boolean
patchesDir?: string
ignoreWorkspaceCycles?: boolean
registries: Registries
ignoreWorkspaceRootCheck: boolean

View File

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

View File

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

View File

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

View File

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

View File

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