|
1 |
| -import type { CheckOptions } from '../src' |
| 1 | +import type { CheckOptions, PnpmWorkspaceMeta } from '../src' |
| 2 | +import fs from 'node:fs/promises' |
2 | 3 | import process from 'node:process'
|
3 | 4 | import { expect, it } from 'vitest'
|
| 5 | +import { parse, parseDocument } from 'yaml' |
4 | 6 | import { CheckPackages } from '../src'
|
| 7 | +import { writePnpmWorkspace } from '../src/io/pnpmWorkspaces' |
5 | 8 |
|
6 | 9 | it('pnpm catalog', async () => {
|
7 | 10 | const options: CheckOptions = {
|
@@ -100,3 +103,37 @@ it('pnpm catalog', async () => {
|
100 | 103 | ]
|
101 | 104 | `)
|
102 | 105 | })
|
| 106 | + |
| 107 | +it('pnpm catalog updates should preserve yaml anchors and aliases with single string value', async () => { |
| 108 | + const workspaceYamlContents = ` |
| 109 | +catalog: |
| 110 | + react: &foo ^18.2.0 |
| 111 | + react-dom: *foo |
| 112 | + ` |
| 113 | + const document = parseDocument(workspaceYamlContents) |
| 114 | + const pkg: PnpmWorkspaceMeta = { |
| 115 | + name: 'catalog:default', |
| 116 | + resolved: [ |
| 117 | + // @ts-expect-error testing purpose |
| 118 | + { name: 'react', targetVersion: '^18.3.1', source: 'pnpm:catalog', update: true, currentVersion: '^18.2.0', diff: 'minor' }, |
| 119 | + // @ts-expect-error testing purpose |
| 120 | + { name: 'react-dom', targetVersion: '^18.3.1', source: 'pnpm:catalog', update: true, currentVersion: '^18.2.0', diff: 'minor' }, |
| 121 | + ], |
| 122 | + raw: parse(workspaceYamlContents), |
| 123 | + document, |
| 124 | + filepath: '', |
| 125 | + type: 'pnpm-workspace.yaml', |
| 126 | + } |
| 127 | + |
| 128 | + let output: string |
| 129 | + // @ts-expect-error testing purpose |
| 130 | + fs.writeFile = (_path, data, _ops) => output = data |
| 131 | + |
| 132 | + await writePnpmWorkspace(pkg, {}) |
| 133 | + // @ts-expect-error testing purpose |
| 134 | + expect(output).toMatchInlineSnapshot(` |
| 135 | +"catalog: |
| 136 | + react: &foo ^18.3.1 |
| 137 | + react-dom: *foo |
| 138 | +"`) |
| 139 | +}) |
0 commit comments