Skip to content

Commit

Permalink
fix(nx-ignore): check that yarn/pnpm are installed before using on Ne…
Browse files Browse the repository at this point in the history
…tlify (#362)
  • Loading branch information
jaysoo authored Dec 19, 2023
1 parent 289762d commit 29228a6
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions packages/nx-ignore/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,20 @@ function installTempNx(root: string, plugins: string[]): string | null {
}
writeFileSync(join(tmpPath, 'package.json'), JSON.stringify(json));

if (existsSync(join(root, 'yarn.lock'))) {
if (
existsSync(join(root, 'yarn.lock')) &&
isPackageManagerInstalled(`yarn`)
) {
logDebug(`Using yarn to install Nx.`);
execSync(`yarn install`, { cwd: tmpPath });
} else if (existsSync(join(root, 'pnpm-lock.yaml'))) {
} else if (
existsSync(join(root, 'pnpm-lock.yaml')) &&
isPackageManagerInstalled(`pnpm`)
) {
logDebug(`Using pnpm to install Nx.`);
execSync(`pnpm install --force`, { cwd: tmpPath });
} else {
logDebug(`Using npm to install Nx.`);
execSync(`npm install --force`, { cwd: tmpPath });
}
moveSync(join(tmpPath, 'node_modules'), join(root, 'node_modules'));
Expand All @@ -183,6 +192,19 @@ function installTempNx(root: string, plugins: string[]): string | null {
return null;
}

function isPackageManagerInstalled(pm: 'yarn' | 'pnpm'): boolean {
try {
const version = execSync(`${pm} --version`, {
stdio: 'pipe',
})?.toString();
logDebug(`Found ${pm} version ${version}.`);
return true;
} catch {
logDebug(`Could not find ${pm}. Check that it is installed.`);
return false;
}
}

function commitHasSkipMessage(message: string): boolean {
return [
'[skip ci]',
Expand Down

0 comments on commit 29228a6

Please sign in to comment.