Skip to content

Commit

Permalink
chore: choose default installer based on the lock file presence
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Jun 7, 2021
1 parent 4e9b4d2 commit ccb8d4c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/generators/src/init-generator.ts
Expand Up @@ -100,12 +100,14 @@ export default class InitGenerator extends CustomGenerator {
}

public async installPlugins(): Promise<void> {
// Prompt for the package manager of choice
const defaultPackager = this.utils.getPackageManager();
const { packager } = await Question.List(
this,
"packager",
"Pick a package manager:",
this.utils.getAvailableInstallers(),
"npm",
defaultPackager,
false,
);
const opts: {
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-cli/lib/utils/get-available-installers.js
Expand Up @@ -2,7 +2,7 @@ const { sync } = require("execa");

const utils = require("./");

function isPmInstalled(packageManager) {
function hasPmInstalled(packageManager) {
try {
sync(packageManager, ["--version"]);
return packageManager;
Expand All @@ -13,7 +13,7 @@ function isPmInstalled(packageManager) {

function getAvailableInstallers() {
const installers = ["npm", "yarn", "pnpm"];
const availableInstallers = installers.filter((installer) => isPmInstalled(installer));
const availableInstallers = installers.filter((installer) => hasPmInstalled(installer));

if (!availableInstallers.length) {
utils.logger.error("No package manager found.");
Expand Down

0 comments on commit ccb8d4c

Please sign in to comment.