From 3b06df28f6fcfb64c0f5c22f7380de8230ecced9 Mon Sep 17 00:00:00 2001 From: Jan Keromnes Date: Fri, 17 Jun 2022 14:46:30 +0200 Subject: [PATCH] [config-inferrer] Use 'pnpm' package manager when there is a pnpm-lock.yaml file or the package.json specifies it Co-authored-by: Jiawen Geng --- .../server/src/config/config-inferrer.ts | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/components/server/src/config/config-inferrer.ts b/components/server/src/config/config-inferrer.ts index 17f9ce59c75849..5cd7a6df3e87aa 100644 --- a/components/server/src/config/config-inferrer.ts +++ b/components/server/src/config/config-inferrer.ts @@ -41,29 +41,33 @@ export class ConfigInferrer { if (!pckjsonContent) { return; } - let command: "yarn" | "npm" = "npm"; + let pckjson; + try { + pckjson = JSON.parse(pckjsonContent); + } catch (e) { + console.log(e, pckjsonContent); + } + let command: "yarn" | "npm" | "pnpm" = "npm"; if (await ctx.exists("yarn.lock")) { command = "yarn"; } + if ((await ctx.exists("pnpm-lock.yaml")) || pckjson?.packageManager?.startsWith("pnpm")) { + command = "pnpm"; + } this.addCommand(ctx.config, command + " install", "init"); - try { - const pckjson = JSON.parse(pckjsonContent); - if (pckjson.scripts) { - if (pckjson.scripts.build) { - this.addCommand(ctx.config, command + " run build", "init"); - } else if (pckjson.scripts.compile) { - this.addCommand(ctx.config, command + " run compile", "init"); - } - if (pckjson.scripts.start) { - this.addCommand(ctx.config, command + " run start", "command"); - } else if (pckjson.scripts.dev) { - this.addCommand(ctx.config, command + " run dev", "command"); - } else if (pckjson.scripts.watch) { - this.addCommand(ctx.config, command + " run watch", "command"); - } + if (pckjson.scripts) { + if (pckjson.scripts.build) { + this.addCommand(ctx.config, command + " run build", "init"); + } else if (pckjson.scripts.compile) { + this.addCommand(ctx.config, command + " run compile", "init"); + } + if (pckjson.scripts.start) { + this.addCommand(ctx.config, command + " run start", "command"); + } else if (pckjson.scripts.dev) { + this.addCommand(ctx.config, command + " run dev", "command"); + } else if (pckjson.scripts.watch) { + this.addCommand(ctx.config, command + " run watch", "command"); } - } catch (e) { - console.log(e, pckjsonContent); } this.addExtension(ctx, "dbaeumer.vscode-eslint"); }