From 4fa28da2c894722cb55f5fec816a9055631615b2 Mon Sep 17 00:00:00 2001 From: Jan Keromnes Date: Fri, 17 Jun 2022 14:46:30 +0200 Subject: [PATCH 1/2] [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"); } From 0b4a8f8eca052457ad8decd4b3715f3c3cd1a925 Mon Sep 17 00:00:00 2001 From: Jan Keromnes Date: Mon, 25 Jul 2022 14:10:57 +0000 Subject: [PATCH 2/2] [config-inferrer] Add tests for npm and pnpm Node.js variants --- .../server/src/config/config-inferrer.spec.ts | 55 ++++++++++++++++++- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/components/server/src/config/config-inferrer.spec.ts b/components/server/src/config/config-inferrer.spec.ts index 9cde3c58a3f770..5ce3a42be5bb1f 100644 --- a/components/server/src/config/config-inferrer.spec.ts +++ b/components/server/src/config/config-inferrer.spec.ts @@ -53,7 +53,7 @@ vscode: }); describe("config inferrer", () => { - it("check node", async () => + it("[node] yarn", async () => expect( { "yarn.lock": "", @@ -65,8 +65,7 @@ describe("config inferrer", () => { "build": "npx tsc", "watch": "npx tsc -w" } - } - `, + }`, }, { tasks: [ @@ -80,6 +79,56 @@ describe("config inferrer", () => { }, }, )), + it("[node] npm", async () => + expect( + { + "package.json": ` + { + "scripts": { + "clean": "npx rimraf lib", + "build": "npx tsc", + "watch": "npx tsc -w" + } + }`, + }, + { + tasks: [ + { + init: "npm install && npm run build", + command: "npm run watch", + }, + ], + vscode: { + extensions: ["dbaeumer.vscode-eslint"], + }, + }, + )), + it("[node] pnpm", async () => + expect( + { + "pnpm-lock.yaml": "", + "package.json": ` + { + "packageManager": "pnpm@6.32.4", + "scripts": { + "clean": "npx rimraf lib", + "build": "npx tsc", + "watch": "npx tsc -w" + } + }`, + }, + { + tasks: [ + { + init: "pnpm install && pnpm run build", + command: "pnpm run watch", + }, + ], + vscode: { + extensions: ["dbaeumer.vscode-eslint"], + }, + }, + )), it("[java] mvn wrapper", async () => expect( {