Skip to content

Commit

Permalink
fix(core): fix having multiple versions of nx/devkit (#9998)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed May 19, 2022
1 parent c15a25e commit 1987251
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
8 changes: 5 additions & 3 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Expand Up @@ -28,7 +28,7 @@ type Arguments = {
style: string;
nxCloud: boolean;
allPrompts: boolean;
packageManager: string;
packageManager: PackageManager;
defaultBase: string;
};

Expand Down Expand Up @@ -605,11 +605,13 @@ async function determineStyle(
return Promise.resolve(parsedArgs.style);
}

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(
Expand All @@ -625,7 +627,7 @@ async function createSandbox(packageManager: string) {
})
);

await execAndWait(`${packageManager} install --silent`, tmpDir);
await execAndWait(`${install} --silent`, tmpDir);

installSpinner.succeed();
} catch (e) {
Expand Down
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 1987251

Please sign in to comment.