Skip to content
Open
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
3 changes: 2 additions & 1 deletion apps/lockfile-explorer/src/utils/shrinkwrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ interface IPackageInfo {
export function convertLockfileV6DepPathToV5DepPath(newDepPath: string): string {
if (!newDepPath.includes('@', 2) || newDepPath.startsWith('file:')) return newDepPath;
const index = newDepPath.indexOf('@', newDepPath.indexOf('/@') + 2);
if (newDepPath.includes('(') && index > dependencyPathLockfilePreV9.indexOfPeersSuffix(newDepPath)) return newDepPath;
if (newDepPath.includes('(') && index > dependencyPathLockfilePreV9.indexOfPeersSuffix(newDepPath))
return newDepPath;
return `${newDepPath.substring(0, index)}/${newDepPath.substring(index + 1)}`;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix an issue with `rush-pnpm patch-commit`, where it would error if it was run from the root of the monorepo.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix an issue with `rush-pnpm patch-commit` where it did not correctly sync patches on subsequent runs for the same dependency.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
83 changes: 41 additions & 42 deletions libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import * as path from 'path';
import {
AlreadyReportedError,
EnvironmentMap,
Expand All @@ -28,10 +27,8 @@ import { PurgeManager } from '../logic/PurgeManager';
import type { IBuiltInPluginConfiguration } from '../pluginFramework/PluginLoader/BuiltInPluginLoader';
import type { BaseInstallManager } from '../logic/base/BaseInstallManager';
import type { IInstallManagerOptions } from '../logic/base/BaseInstallManagerTypes';
import { objectsAreDeepEqual } from '../utilities/objectUtilities';
import { Utilities } from '../utilities/Utilities';
import type { Subspace } from '../api/Subspace';
import type { PnpmOptionsConfiguration } from '../logic/pnpm/PnpmOptionsConfiguration';
import { EnvironmentVariableNames } from '../api/EnvironmentConfiguration';
import { initializeDotEnv } from '../logic/dotenv';

Expand Down Expand Up @@ -146,7 +143,7 @@ export class RushPnpmCommandLineParser {
this._subspace = subspace;

const workspaceFolder: string = subspace.getSubspaceTempFolderPath();
const workspaceFilePath: string = path.join(workspaceFolder, 'pnpm-workspace.yaml');
const workspaceFilePath: string = `${workspaceFolder}/pnpm-workspace.yaml`;

if (!FileSystem.exists(workspaceFilePath)) {
this._terminal.writeErrorLine('Error: The PNPM workspace file has not been generated:');
Expand Down Expand Up @@ -327,12 +324,10 @@ export class RushPnpmCommandLineParser {
}
break;
}

case 'patch-commit': {
const pnpmOptionsJsonFilename: string = path.join(
this._rushConfiguration.commonRushConfigFolder,
RushConstants.pnpmConfigFilename
);
if (this._rushConfiguration.rushConfigurationJson.pnpmOptions) {
const pnpmOptionsJsonFilename: string = `${this._rushConfiguration.commonRushConfigFolder}/${RushConstants.pnpmConfigFilename}`;
this._terminal.writeErrorLine(
PrintUtilities.wrapWords(
`Error: The "pnpm patch-commit" command is incompatible with specifying "pnpmOptions" in ${RushConstants.rushJsonFilename} file.` +
Expand All @@ -341,6 +336,15 @@ export class RushPnpmCommandLineParser {
);
throw new AlreadyReportedError();
}

// patch-commit internally calls installation under cwd instead of the common/temp folder
// It throws missing package.json error, so in this case, we need to set the dir to the common/temp folder here
if (!pnpmArgs.includes('--dir') && !pnpmArgs.includes('-C')) {
if (!(await FileSystem.existsAsync(`${process.cwd()}/${FileConstants.PackageJson}`))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some repos that have a package.json in the root of a Rush repo, even though it's not considered by Rush/PNPM during install. Does this condition interfere with that scenario?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that I mentioned this in my last round of reviews a couple years ago... I'm not sure where that landed in the comments though. Do we not need to care about this?

pnpmArgs.push('--dir');
pnpmArgs.push(this._rushConfiguration.commonTempFolder);
}
}
break;
}
case 'patch-remove': {
Expand Down Expand Up @@ -488,48 +492,43 @@ export class RushPnpmCommandLineParser {

// Example: "C:\MyRepo\common\temp\package.json"
const commonPackageJsonFilename: string = `${subspaceTempFolder}/${FileConstants.PackageJson}`;
const commonPackageJson: JsonObject = JsonFile.load(commonPackageJsonFilename);
const commonPackageJson: JsonObject = await JsonFile.loadAsync(commonPackageJsonFilename);
const newGlobalPatchedDependencies: Record<string, string> | undefined =
commonPackageJson?.pnpm?.patchedDependencies;
const pnpmOptions: PnpmOptionsConfiguration | undefined = this._subspace.getPnpmOptions();
const currentGlobalPatchedDependencies: Record<string, string> | undefined =
pnpmOptions?.globalPatchedDependencies;

if (!objectsAreDeepEqual(currentGlobalPatchedDependencies, newGlobalPatchedDependencies)) {
const commonTempPnpmPatchesFolder: string = `${subspaceTempFolder}/${RushConstants.pnpmPatchesFolderName}`;
const rushPnpmPatchesFolder: string = this._subspace.getSubspacePnpmPatchesFolderPath();

// Copy (or delete) common\temp\subspace\patches\ --> common\config\pnpm-patches\ OR common\config\rush\pnpm-patches\
if (FileSystem.exists(commonTempPnpmPatchesFolder)) {
FileSystem.ensureEmptyFolder(rushPnpmPatchesFolder);
// eslint-disable-next-line no-console
console.log(`Copying ${commonTempPnpmPatchesFolder}`);
const commonTempPnpmPatchesFolder: string = `${subspaceTempFolder}/${RushConstants.pnpmPatchesFolderName}`;
const rushPnpmPatchesFolder: string = this._subspace.getSubspacePnpmPatchesFolderPath();

// Copy (or delete) common\temp\subspace\patches\ --> common\config\pnpm-patches\ OR common\config\rush\pnpm-patches\
if (await FileSystem.existsAsync(commonTempPnpmPatchesFolder)) {
await FileSystem.ensureEmptyFolderAsync(rushPnpmPatchesFolder);
// eslint-disable-next-line no-console
console.log(`Copying ${commonTempPnpmPatchesFolder}`);
// eslint-disable-next-line no-console
console.log(` --> ${rushPnpmPatchesFolder}`);
await FileSystem.copyFilesAsync({
sourcePath: commonTempPnpmPatchesFolder,
destinationPath: rushPnpmPatchesFolder
});
} else {
if (await FileSystem.existsAsync(rushPnpmPatchesFolder)) {
// eslint-disable-next-line no-console
console.log(` --> ${rushPnpmPatchesFolder}`);
FileSystem.copyFiles({
sourcePath: commonTempPnpmPatchesFolder,
destinationPath: rushPnpmPatchesFolder
});
} else {
if (FileSystem.exists(rushPnpmPatchesFolder)) {
// eslint-disable-next-line no-console
console.log(`Deleting ${rushPnpmPatchesFolder}`);
FileSystem.deleteFolder(rushPnpmPatchesFolder);
}
console.log(`Deleting ${rushPnpmPatchesFolder}`);
await FileSystem.deleteFolderAsync(rushPnpmPatchesFolder);
}
}

// Update patchedDependencies to pnpm configuration file
pnpmOptions?.updateGlobalPatchedDependencies(newGlobalPatchedDependencies);
// Update patchedDependencies to pnpm configuration file
this._rushConfiguration.pnpmOptions.updateGlobalPatchedDependencies(newGlobalPatchedDependencies);

// Rerun installation to update
await this._doRushUpdateAsync();
// Rerun installation to update
await this._doRushUpdateAsync();

this._terminal.writeWarningLine(
`Rush refreshed the ${RushConstants.pnpmConfigFilename}, shrinkwrap file and patch files under the ` +
`"${commonTempPnpmPatchesFolder}" folder.\n` +
' Please commit this change to Git.'
);
}
this._terminal.writeWarningLine(
`Rush refreshed the ${RushConstants.pnpmConfigFilename}, shrinkwrap file and patch files under the ` +
`"${commonTempPnpmPatchesFolder}" folder.\n` +
' Please commit this change to Git.'
);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe(convertLockfileV9ToLockfileObject.name, () => {
});
});

it("no nullish values", () => {
it('no nullish values', () => {
const importers = new Map<string, ProjectSnapshot>(Object.entries(lockfile.importers || {}));

const currentPackage = importers.get('.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ settings:
excludeLinksFromLockfile: false

importers:

.: {}

../../apps/bar:
Expand All @@ -15,12 +14,13 @@ importers:
version: 2.3.2

packages:

prettier@2.3.2:
resolution: {integrity: sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==}
engines: {node: '>=10.13.0'}
resolution:
{
integrity: sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==
}
engines: { node: '>=10.13.0' }
hasBin: true

snapshots:

prettier@2.3.2: {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ settings:
excludeLinksFromLockfile: false

importers:

.: {}

../../apps/foo:
Expand All @@ -19,17 +18,21 @@ importers:
version: 5.0.4

packages:

tslib@2.3.1:
resolution: {integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==}
resolution:
{
integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
}

typescript@5.0.4:
resolution: {integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==}
engines: {node: '>=12.20'}
resolution:
{
integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==
}
engines: { node: '>=12.20' }
hasBin: true

snapshots:

tslib@2.3.1: {}

typescript@5.0.4: {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ settings:
excludeLinksFromLockfile: false

importers:

.: {}

../../apps/foo:
Expand All @@ -19,17 +18,21 @@ importers:
version: 5.0.4

packages:

tslib@2.3.1:
resolution: {integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==}
resolution:
{
integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
}

typescript@5.0.4:
resolution: {integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==}
engines: {node: '>=12.20'}
resolution:
{
integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==
}
engines: { node: '>=12.20' }
hasBin: true

snapshots:

tslib@2.3.1: {}

typescript@5.0.4: {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ overrides:
typescript: 5.0.4

importers:

.: {}

../../apps/foo:
Expand All @@ -22,17 +21,21 @@ importers:
version: 5.0.4

packages:

tslib@2.3.1:
resolution: {integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==}
resolution:
{
integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
}

typescript@5.0.4:
resolution: {integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==}
engines: {node: '>=12.20'}
resolution:
{
integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==
}
engines: { node: '>=12.20' }
hasBin: true

snapshots:

tslib@2.3.1: {}

typescript@5.0.4: {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ settings:
excludeLinksFromLockfile: false

importers:

.:
dependencies:
jquery:
Expand All @@ -16,20 +15,27 @@ importers:
version: 2.1.0

packages:

jquery@3.7.1:
resolution: {integrity: sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==}
resolution:
{
integrity: sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==
}

pad-left@2.1.0:
resolution: {integrity: sha512-HJxs9K9AztdIQIAIa/OIazRAUW/L6B9hbQDxO4X07roW3eo9XqZc2ur9bn1StH9CnbbI9EgvejHQX7CBpCF1QA==}
engines: {node: '>=0.10.0'}
resolution:
{
integrity: sha512-HJxs9K9AztdIQIAIa/OIazRAUW/L6B9hbQDxO4X07roW3eo9XqZc2ur9bn1StH9CnbbI9EgvejHQX7CBpCF1QA==
}
engines: { node: '>=0.10.0' }

repeat-string@1.6.1:
resolution: {integrity: sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==}
engines: {node: '>=0.10'}
resolution:
{
integrity: sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==
}
engines: { node: '>=0.10' }

snapshots:

jquery@3.7.1: {}

pad-left@2.1.0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ export class BridgeCachePlugin implements IRushPlugin {
const projectFolder: string = operation.associatedProject?.projectFolder;
const missingFolders: string[] = [];
operation.settings.outputFolderNames.forEach((outputFolderName: string) => {
if (!FileSystem.exists(`${projectFolder}/${outputFolderName}`)) {
missingFolders.push(outputFolderName);
}
if (!FileSystem.exists(`${projectFolder}/${outputFolderName}`)) {
missingFolders.push(outputFolderName);
}
});
if (missingFolders.length > 0) {
terminal.writeWarningLine(
Expand Down
Loading