Skip to content

Commit 61af005

Browse files
nx-cloud[bot]ndcunningham
authored andcommitted
fix(e2e): ensure correct package manager is used in workspace creation and reset
1 parent 65d0f81 commit 61af005

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

e2e/utils/create-project-utils.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ const nxPackages = [
6767

6868
type NxPackage = (typeof nxPackages)[number];
6969

70+
function getPackageManagerVersion(packageManager: string): string {
71+
try {
72+
const version = execSync(`${packageManager} --version`, {
73+
encoding: 'utf-8',
74+
stdio: 'pipe',
75+
}).trim();
76+
return `${packageManager}@${version}`;
77+
} catch {
78+
// Fallback to known working versions
79+
const fallbackVersions = {
80+
81+
82+
83+
84+
};
85+
return fallbackVersions[packageManager] || `${packageManager}@latest`;
86+
}
87+
}
88+
7089
/**
7190
* Sets up a new project in the temporary project path
7291
* for the currently selected CLI.
@@ -107,10 +126,18 @@ export function newProject({
107126
createNxWorkspaceEnd.name
108127
);
109128

129+
// Ensure the package manager is correctly set in the created workspace
130+
if (packageManager) {
131+
updateJson(`package.json`, (json) => {
132+
json.packageManager = getPackageManagerVersion(packageManager);
133+
return json;
134+
});
135+
}
136+
110137
// Temporary hack to prevent installing with `--frozen-lockfile`
111138
if (isCI && packageManager === 'pnpm') {
112139
updateFile(
113-
'.npmrc',
140+
`.npmrc`,
114141
'prefer-frozen-lockfile=false\nstrict-peer-dependencies=false\nauto-install-peers=true'
115142
);
116143
}
@@ -129,7 +156,7 @@ export function newProject({
129156
packageInstallEnd.name
130157
);
131158
// stop the daemon
132-
execSync(`${getPackageManagerCommand().runNx} reset`, {
159+
execSync(`${getPackageManagerCommand({ packageManager }).runNx} reset`, {
133160
cwd: `${e2eCwd}/proj`,
134161
stdio: isVerbose() ? 'inherit' : 'pipe',
135162
});

0 commit comments

Comments
 (0)