Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rush] Add a reset function to the pnpmfile to allow for clearing state #4696

Merged
merged 3 commits into from
May 13, 2024
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,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"
}
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');
Copy link
Contributor

Choose a reason for hiding this comment

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

Were the installs running in the same process? If not I don't see how there could be contamination of in-memory state, and if so, then we need to purge the require.cache entry corresponding to ./pnpmfileSettings.json to ensure that we get the latest.

}
settings = context.pnpmfileShimSettings!;
settings = context.pnpmfileShimSettings as IPnpmfileShimSettings;
} else if (!context.pnpmfileShimSettings) {
// Reuse the already initialized settings
context.pnpmfileShimSettings = settings;
Expand Down
Loading