Skip to content

Commit 9b356ce

Browse files
committed
chore(deps): upgrade
1 parent af128d9 commit 9b356ce

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@icebreakers/monorepo': patch
3+
---
4+
5+
Ensure pnpm-workspace.yaml merges dedupe quoted globs and stringify with single quotes to avoid churn.

packages/monorepo/src/commands/upgrade/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export async function upgradeMonorepo(opts: CliOpts) {
123123
const mergedManifest = exists
124124
? mergeWorkspaceManifest(sourceManifest, targetManifest)
125125
: sourceManifest
126-
const data = YAML.stringify(mergedManifest)
126+
const data = YAML.stringify(mergedManifest, { singleQuote: true })
127127
const intent = await evaluateWriteIntent(targetPath, { skipOverwrite, source: data })
128128
const action = async () => {
129129
await fs.outputFile(targetPath, data, 'utf8')

packages/monorepo/src/commands/upgrade/workspace.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
66
return typeof value === 'object' && value !== null && !Array.isArray(value)
77
}
88

9+
function normalizeQuotedString(value: string) {
10+
const trimmed = value.trim()
11+
const first = trimmed[0]
12+
if ((first === '\'' || first === '"') && trimmed.endsWith(first)) {
13+
return trimmed.slice(1, -1)
14+
}
15+
return trimmed
16+
}
17+
918
export function normalizeWorkspaceManifest(manifest: unknown): WorkspaceManifestLike {
1019
if (isPlainObject(manifest)) {
1120
return { ...manifest }
@@ -14,9 +23,14 @@ export function normalizeWorkspaceManifest(manifest: unknown): WorkspaceManifest
1423
}
1524

1625
function mergeUniqueArray<T>(target: T[], source: T[]) {
26+
const seen = new Set(target.map((item) => {
27+
return typeof item === 'string' ? normalizeQuotedString(item) : item
28+
}))
1729
const result = [...target]
1830
for (const item of source) {
19-
if (!result.includes(item)) {
31+
const key = typeof item === 'string' ? normalizeQuotedString(item) : item
32+
if (!seen.has(key)) {
33+
seen.add(key)
2034
result.push(item)
2135
}
2236
}

packages/monorepo/test/commands/upgrade.index.coverage.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('upgrade command coverage', () => {
108108
mergeTargets: false,
109109
})
110110

111-
getAssetTargetsMock.mockReturnValue(['README.md', 'package.json', '.github'])
111+
getAssetTargetsMock.mockReturnValue(['README.md', 'package.json', '.github', 'pnpm-workspace.yaml'])
112112

113113
const initialFeed = [
114114
{ path: '/assets/folder', isFile: false },
@@ -119,6 +119,7 @@ describe('upgrade command coverage', () => {
119119
{ path: '/assets/LICENSE', isFile: true },
120120
{ path: '/assets/.github/ISSUE_TEMPLATE/config.yml', isFile: true },
121121
{ path: '/assets/README.md', isFile: true },
122+
{ path: '/assets/pnpm-workspace.yaml', isFile: true },
122123
{ path: '/assets/error.txt', isFile: true },
123124
]
124125
klawFeeds.push(initialFeed)
@@ -135,6 +136,20 @@ describe('upgrade command coverage', () => {
135136
' about: Suggest new features for consideration',
136137
'',
137138
].join('\n'))
139+
fileContents.set('/assets/pnpm-workspace.yaml', [
140+
'packages:',
141+
' - apps/*',
142+
' - packages/*',
143+
' - \'!**/test/**\'',
144+
'',
145+
].join('\n'))
146+
fileContents.set('/workspace/pnpm-workspace.yaml', [
147+
'packages:',
148+
' - apps/*',
149+
' - packages/*',
150+
' - \"!**/test/**\"',
151+
'',
152+
].join('\n'))
138153

139154
jsonContents.set('/assets/package.json', {
140155
dependencies: {
@@ -209,6 +224,8 @@ describe('upgrade command coverage', () => {
209224
const issueTemplateCall = outputFileMock.mock.calls.find(args => args[0] === '/workspace/.github/ISSUE_TEMPLATE/config.yml')
210225
expect(issueTemplateCall?.[1]).toBeDefined()
211226
expect(issueTemplateCall?.[1] as string).toContain('https://github.com/ice/awesome/discussions')
227+
const workspaceCall = outputFileMock.mock.calls.find(args => args[0] === '/workspace/pnpm-workspace.yaml')
228+
expect(workspaceCall?.[1]).toContain('- \'!**/test/**\'')
212229

213230
evaluateWriteIntentMock.mockResolvedValueOnce({ type: 'write', reason: 'missing' })
214231
readFileMock.mockImplementation(async () => {

packages/monorepo/test/commands/upgrade.workspace.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ describe('mergeWorkspaceManifest', () => {
4242
})
4343
})
4444

45+
it('dedupes workspace globs regardless of wrapping quotes', () => {
46+
const merged = mergeWorkspaceManifest(
47+
normalizeWorkspaceManifest({ packages: ['apps/*', '!**/test/**'] }),
48+
normalizeWorkspaceManifest({ packages: [`'apps/*'`, `"!**/test/**"`] }),
49+
)
50+
51+
expect(merged.packages).toEqual([`'apps/*'`, `"!**/test/**"`])
52+
})
53+
4554
it('keeps target shapes when source types differ', () => {
4655
const merged = mergeWorkspaceManifest(
4756
normalizeWorkspaceManifest({ packages: ['apps/*'], hoist: true }),

0 commit comments

Comments
 (0)