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

[.gitpod.yml generator] Use 'pnpm' package manager when there is a pnpm-lock.yaml file or the package.json specifies it #10731

Merged
merged 2 commits into from
Jul 25, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions components/server/src/config/config-inferrer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ vscode:
});

describe("config inferrer", () => {
it("check node", async () =>
it("[node] yarn", async () =>
expect(
{
"yarn.lock": "",
Expand All @@ -65,8 +65,7 @@ describe("config inferrer", () => {
"build": "npx tsc",
"watch": "npx tsc -w"
}
}
`,
}`,
},
{
tasks: [
Expand All @@ -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": "[email protected]",
"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(
{
Expand Down
16 changes: 10 additions & 6 deletions components/server/src/config/config-inferrer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ 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";
jankeromnes marked this conversation as resolved.
Show resolved Hide resolved
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");
Expand All @@ -62,9 +69,6 @@ export class ConfigInferrer {
this.addCommand(ctx.config, command + " run watch", "command");
}
}
} catch (e) {
console.log(e, pckjsonContent);
}
this.addExtension(ctx, "dbaeumer.vscode-eslint");
}

Expand Down