Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "Fix a regression where Rush change-detection treated any `pnpm-config.json` containing comments as unparseable, causing every project to be flagged as impacted.",
"type": "patch",
"packageName": "@microsoft/rush"
}
],
"packageName": "@microsoft/rush",
"email": "bartvandenende-wm@users.noreply.github.com"
}
11 changes: 5 additions & 6 deletions libraries/rush-lib/src/logic/ProjectChangeAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from 'node:path';
import ignore, { type Ignore } from 'ignore';

import type { IReadonlyLookupByPath, LookupByPath, IPrefixMatch } from '@rushstack/lookup-by-path';
import { Path, FileSystem, Async, AlreadyReportedError, Sort } from '@rushstack/node-core-library';
import { Path, FileSystem, Async, AlreadyReportedError, Sort, JsonFile } from '@rushstack/node-core-library';
import {
getRepoChanges,
getRepoRoot,
Expand Down Expand Up @@ -545,16 +545,16 @@ export class ProjectChangeAnalyzer {
blobSpec: `${mergeCommit}:${pnpmConfigRelativePath}`,
repositoryRoot: repoRoot
});
const oldPnpmConfig: IPnpmOptionsJson = JSON.parse(oldPnpmConfigText);
const oldPnpmConfig: IPnpmOptionsJson = JsonFile.parseString(oldPnpmConfigText);
oldCatalogs = oldPnpmConfig.globalCatalogs ?? {};
} catch {
// Old file didn't exist or was unparseable — treat all packages in all current catalogs as changed
if (rushConfiguration.subspacesFeatureEnabled) {
terminal.writeLine(
terminal.writeWarningLine(
`"${subspace.subspaceName}" subspace pnpm-config.json was created or unparseable. Assuming all projects are affected.`
);
} else {
terminal.writeLine(
terminal.writeWarningLine(
`pnpm-config.json was created or unparseable. Assuming all projects are affected.`
);
}
Expand Down Expand Up @@ -608,8 +608,7 @@ export class ProjectChangeAnalyzer {
// Check each project in the subspace to see if it depends on a changed catalog package
const subspaceProjects: RushConfigurationProject[] = subspace.getProjects();
subspaceProjects.forEach((project) => {
const { dependencies, devDependencies, optionalDependencies, peerDependencies } =
project.packageJson;
const { dependencies, devDependencies, optionalDependencies, peerDependencies } = project.packageJson;
const allDependencies: Set<[string, string]> = new Set(
[dependencies, devDependencies, optionalDependencies, peerDependencies].flatMap((deps) =>
Object.entries(deps ?? {})
Expand Down
29 changes: 29 additions & 0 deletions libraries/rush-lib/src/logic/test/ProjectChangeAnalyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,35 @@ describe(ProjectChangeAnalyzer.name, () => {
// 'c' has no catalog deps
expect(changedProjects.has(rushConfiguration.getProjectByName('c')!)).toBe(false);
});

it('parses pnpm-config.json blobs containing comments (regression #5813)', async () => {
const rushConfiguration: RushConfiguration = getCatalogRushConfiguration();
mockPnpmConfigChanged();
mockGetBlobContentAsync.mockImplementation(() => {
return Promise.resolve(
`// banner comment from rush init template\n` +
`/* block comment */\n` +
JSON.stringify({
globalCatalogs: {
default: { react: '^18.0.0', semver: '^7.5.4' },
tools: { typescript: '~5.3.0', eslint: '^8.50.0' }
}
})
);
});

const projectChangeAnalyzer: ProjectChangeAnalyzer = new ProjectChangeAnalyzer(rushConfiguration);
const terminal: Terminal = new Terminal(new StringBufferTerminalProvider(true));

const changedProjects = await projectChangeAnalyzer.getChangedProjectsAsync({
enableFiltering: false,
includeExternalDependencies: false,
targetBranchName: 'main',
terminal
});

expect(changedProjects.size).toBe(0);
});
});

describe('subspace catalog change detection', () => {
Expand Down
Loading