Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/olive-bees-yawn.md
@@ -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).
1 change: 1 addition & 0 deletions config/config/src/Config.ts
Expand Up @@ -158,6 +158,7 @@ export interface Config {
onlyBuiltDependencies?: string[]
dedupePeerDependents?: boolean
patchesDir?: string
ignoreWorkspaceCycles?: boolean

registries: Registries
ignoreWorkspaceRootCheck: boolean
Expand Down
2 changes: 2 additions & 0 deletions config/config/src/index.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions pkg-manager/core/src/install/extendInstallOptions.ts
Expand Up @@ -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
Expand Down Expand Up @@ -205,6 +206,7 @@ const defaults = async (opts: InstallOptions) => {
dedupePeerDependents: true,
resolvePeersFromWorkspaceRoot: true,
extendNodePath: true,
ignoreWorkspaceCycles: false,
} as StrictInstallOptions
}

Expand Down
Expand Up @@ -88,6 +88,7 @@ export type ImportCommandOptions = Pick<Config,
| 'allProjectsGraph'
| 'selectedProjectsGraph'
| 'workspaceDir'
| 'ignoreWorkspaceCycles'
> & CreateStoreControllerOptions & Omit<InstallOptions, 'storeController' | 'lockfileOnly' | 'preferredVersions'>

export async function handler (
Expand Down Expand Up @@ -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('; ')}`
: ''
Expand Down
1 change: 1 addition & 0 deletions pkg-manager/plugin-commands-installation/src/install.ts
Expand Up @@ -286,6 +286,7 @@ export type InstallCommandOptions = Pick<Config,
| 'workspaceDir'
| 'extraEnv'
| 'resolutionMode'
| 'ignoreWorkspaceCycles'
> & CreateStoreControllerOptions & {
argv: {
original: string[]
Expand Down
Expand Up @@ -78,6 +78,7 @@ export type InstallDepsOptions = Pick<Config,
| 'workspaceConcurrency'
| 'workspaceDir'
| 'extraEnv'
| 'ignoreWorkspaceCycles'
> & CreateStoreControllerOptions & {
argv: {
original: string[]
Expand Down Expand Up @@ -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('; ')}`
: ''
Expand Down
Expand Up @@ -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([
{
Expand Down