Skip to content

Commit

Permalink
Merge pull request #4696 from william2958/will/pnpmfile-reset
Browse files Browse the repository at this point in the history
[rush] Add a reset function to the pnpmfile to allow for clearing state
  • Loading branch information
iclanton committed May 13, 2024
2 parents bf1791d + 8fe5097 commit 31a64ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix an issue where installing multiple subspaces consecutively can cause unexpected cross-contamination between pnpmfiles.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
1 change: 1 addition & 0 deletions libraries/rush-lib/src/logic/pnpm/PnpmfileConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class PnpmfileConfiguration {
private _context: IPnpmfileContext | undefined;

private constructor(context: IPnpmfileContext) {
pnpmfile.reset();
this._context = context;
}

Expand Down
15 changes: 12 additions & 3 deletions libraries/rush-lib/src/logic/pnpm/PnpmfileShim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ import type { IPackageJson } from '@rushstack/node-core-library';
import type { IPnpmShrinkwrapYaml } from './PnpmShrinkwrapFile';
import type { IPnpmfile, IPnpmfileShimSettings, IPnpmfileContext, IPnpmfileHooks } from './IPnpmfile';

let settings: IPnpmfileShimSettings;
let allPreferredVersions: Map<string, string>;
let settings: IPnpmfileShimSettings | undefined;
let allPreferredVersions: Map<string, string> | undefined;
let allowedAlternativeVersions: Map<string, Set<string>> | undefined;
let userPnpmfile: IPnpmfile | undefined;
let semver: typeof TSemver | undefined;

// Resets the internal state of the pnpmfile
export function reset(): void {
settings = undefined;
allPreferredVersions = undefined;
allowedAlternativeVersions = undefined;
userPnpmfile = undefined;
semver = undefined;
}

// Initialize all external aspects of the pnpmfile shim. When using the shim, settings
// are always expected to be available. Init must be called before running any hook that
// depends on a resource obtained from or related to the settings, and will require modules
Expand All @@ -40,7 +49,7 @@ function init(context: IPnpmfileContext | any): IPnpmfileContext {
if (!context.pnpmfileShimSettings) {
context.pnpmfileShimSettings = __non_webpack_require__('./pnpmfileSettings.json');
}
settings = context.pnpmfileShimSettings!;
settings = context.pnpmfileShimSettings as IPnpmfileShimSettings;
} else if (!context.pnpmfileShimSettings) {
// Reuse the already initialized settings
context.pnpmfileShimSettings = settings;
Expand Down

0 comments on commit 31a64ee

Please sign in to comment.