diff --git a/apps/lockfile-explorer/src/utils/shrinkwrap.ts b/apps/lockfile-explorer/src/utils/shrinkwrap.ts index 8cb289fc1e6..3cebb4e9657 100644 --- a/apps/lockfile-explorer/src/utils/shrinkwrap.ts +++ b/apps/lockfile-explorer/src/utils/shrinkwrap.ts @@ -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)}`; } diff --git a/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json new file mode 100644 index 00000000000..e4ead83d4e5 --- /dev/null +++ b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json @@ -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" +} \ No newline at end of file diff --git a/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json new file mode 100644 index 00000000000..793397fcfd4 --- /dev/null +++ b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json @@ -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" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts index ffee5ae280d..84a80c31199 100644 --- a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts +++ b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts @@ -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, @@ -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'; @@ -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:'); @@ -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.` + @@ -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}`))) { + pnpmArgs.push('--dir'); + pnpmArgs.push(this._rushConfiguration.commonTempFolder); + } + } break; } case 'patch-remove': { @@ -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 | undefined = commonPackageJson?.pnpm?.patchedDependencies; - const pnpmOptions: PnpmOptionsConfiguration | undefined = this._subspace.getPnpmOptions(); - const currentGlobalPatchedDependencies: Record | 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; } } diff --git a/libraries/rush-lib/src/logic/pnpm/test/PnpmShrinkwrapConverters.test.ts b/libraries/rush-lib/src/logic/pnpm/test/PnpmShrinkwrapConverters.test.ts index 673bf4826ff..a6d94e25e55 100644 --- a/libraries/rush-lib/src/logic/pnpm/test/PnpmShrinkwrapConverters.test.ts +++ b/libraries/rush-lib/src/logic/pnpm/test/PnpmShrinkwrapConverters.test.ts @@ -39,7 +39,7 @@ describe(convertLockfileV9ToLockfileObject.name, () => { }); }); - it("no nullish values", () => { + it('no nullish values', () => { const importers = new Map(Object.entries(lockfile.importers || {})); const currentPackage = importers.get('.'); diff --git a/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/inconsistent-dep-devDep.yaml b/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/inconsistent-dep-devDep.yaml index 7f26989631c..08f6420eaf5 100644 --- a/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/inconsistent-dep-devDep.yaml +++ b/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/inconsistent-dep-devDep.yaml @@ -5,7 +5,6 @@ settings: excludeLinksFromLockfile: false importers: - .: {} ../../apps/bar: @@ -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: {} diff --git a/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/modified.yaml b/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/modified.yaml index 71509e89efe..7f156d05a28 100644 --- a/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/modified.yaml +++ b/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/modified.yaml @@ -5,7 +5,6 @@ settings: excludeLinksFromLockfile: false importers: - .: {} ../../apps/foo: @@ -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: {} diff --git a/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/not-modified.yaml b/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/not-modified.yaml index 47ef29262c3..f17060bc2eb 100644 --- a/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/not-modified.yaml +++ b/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/not-modified.yaml @@ -5,7 +5,6 @@ settings: excludeLinksFromLockfile: false importers: - .: {} ../../apps/foo: @@ -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: {} diff --git a/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/overrides-not-modified.yaml b/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/overrides-not-modified.yaml index d21630b1d81..69e66401e1e 100644 --- a/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/overrides-not-modified.yaml +++ b/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/overrides-not-modified.yaml @@ -8,7 +8,6 @@ overrides: typescript: 5.0.4 importers: - .: {} ../../apps/foo: @@ -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: {} diff --git a/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/pnpm-lock-v9.yaml b/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/pnpm-lock-v9.yaml index 9fe144e1b91..91130e28c33 100644 --- a/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/pnpm-lock-v9.yaml +++ b/libraries/rush-lib/src/logic/pnpm/test/yamlFiles/pnpm-lock-v9/pnpm-lock-v9.yaml @@ -5,7 +5,6 @@ settings: excludeLinksFromLockfile: false importers: - .: dependencies: jquery: @@ -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: diff --git a/rush-plugins/rush-bridge-cache-plugin/src/BridgeCachePlugin.ts b/rush-plugins/rush-bridge-cache-plugin/src/BridgeCachePlugin.ts index 0f22d3d85b0..0b16736e912 100644 --- a/rush-plugins/rush-bridge-cache-plugin/src/BridgeCachePlugin.ts +++ b/rush-plugins/rush-bridge-cache-plugin/src/BridgeCachePlugin.ts @@ -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(