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

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

Merged
merged 1 commit into from Apr 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Expand Up @@ -29,7 +29,7 @@ type Arguments = {
style: string;
nxCloud: boolean;
allPrompts: boolean;
packageManager: string;
packageManager: PackageManager;
defaultBase: string;
ci: string[];
};
Expand Down Expand Up @@ -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(
Expand All @@ -713,7 +715,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],
});
}
}