Skip to content

Commit

Permalink
fix(core): fix having multiple versions of nx/devkit
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 25, 2022
1 parent 7d4255e commit 923aef7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
4 changes: 3 additions & 1 deletion packages/devkit/package.json
Expand Up @@ -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"
}
}
35 changes: 18 additions & 17 deletions packages/devkit/src/tasks/install-packages-task.ts
Expand Up @@ -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.
Expand All @@ -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],
});
}
}

0 comments on commit 923aef7

Please sign in to comment.