fix(core): fix having multiple versions of nx/devkit (#9998)

This commit is contained in:
Jason Jean 2022-04-26 14:39:18 -04:00 committed by GitHub
parent 6e72dc6c12
commit 3d563685d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 21 deletions

View File

@ -29,7 +29,7 @@ type Arguments = {
style: string;
nxCloud: boolean;
allPrompts: boolean;
packageManager: string;
packageManager: PackageManager;
defaultBase: string;
ci: string[];
};
@ -693,11 +693,13 @@ async function determineCI(
return [];
}
async function createSandbox(packageManager: string) {
async function createSandbox(packageManager: PackageManager) {
const installSpinner = ora(
`Installing dependencies with ${packageManager}`
).start();
const { install } = getPackageManagerCommand(packageManager);
const tmpDir = dirSync().name;
try {
writeFileSync(
@ -713,7 +715,7 @@ async function createSandbox(packageManager: string) {
})
);
await execAndWait(`${packageManager} install --silent`, tmpDir);
await execAndWait(`${install} --silent`, tmpDir);
installSpinner.succeed();
} catch (e) {

View File

@ -27,11 +27,13 @@
},
"homepage": "https://nx.dev",
"dependencies": {
"nx": "*",
"ejs": "^3.1.5",
"ignore": "^5.0.4",
"rxjs": "^6.5.4",
"semver": "7.3.4",
"tslib": "^2.3.0"
},
"peerDependencies": {
"nx": ">= 13.10 <= 15"
}
}

View File

@ -8,8 +8,6 @@ import {
import type { PackageManager } from 'nx/src/utils/package-manager';
import { joinPathFragments } from 'nx/src/utils/path';
let storedPackageJsonValue: string;
/**
* Runs `npm install` or `yarn install`. It will skip running the install if
* `package.json` hasn't changed at all or it hasn't changed since the last invocation.
@ -23,24 +21,27 @@ export function installPackagesTask(
cwd: string = '',
packageManager: PackageManager = detectPackageManager(cwd)
): void {
if (
!tree
.listChanges()
.find((f) => f.path === joinPathFragments(cwd, 'package.json')) &&
!alwaysRun
) {
return;
}
const packageJsonValue = tree.read(
joinPathFragments(cwd, 'package.json'),
'utf-8'
);
if (
tree
.listChanges()
.find((f) => f.path === joinPathFragments(cwd, 'package.json')) ||
alwaysRun
) {
// Don't install again if install was already executed with package.json
if (storedPackageJsonValue != packageJsonValue || alwaysRun) {
storedPackageJsonValue = packageJsonValue;
const pmc = getPackageManagerCommand(packageManager);
execSync(pmc.install, {
cwd: join(tree.root, cwd),
stdio: [0, 1, 2],
});
}
let storedPackageJsonValue: string = global['__packageJsonInstallCache__'];
// Don't install again if install was already executed with package.json
if (storedPackageJsonValue != packageJsonValue || alwaysRun) {
global['__packageJsonInstallCache__'] = packageJsonValue;
const pmc = getPackageManagerCommand(packageManager);
execSync(pmc.install, {
cwd: join(tree.root, cwd),
stdio: [0, 1, 2],
});
}
}