Skip to content

Commit 8d65c4f

Browse files
fix(turbo-ignore): no longer attempt to use catalog protocol (#10458)
### Description Fixes #10048 Do not attempt to use `catalog` protocol to fetch the specified version of `turbo`. Instead warn and fall back to inferring from `turbo.json`. ### Testing Instructions Added unit tests for this case
1 parent 0f9fc1b commit 8d65c4f

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "test-app",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "vercel",
11+
"dependencies": {
12+
"turbo": "catalog:"
13+
}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tasks": {
3+
"build": {}
4+
}
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "test-app",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "vercel",
11+
"dependencies": {
12+
"turbo": "^99"
13+
}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tasks": {
3+
"build": {}
4+
}
5+
}

packages/turbo-ignore/__tests__/getTurboVersion.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,20 @@ describe("getWorkspace()", () => {
6868
null
6969
);
7070
});
71+
72+
describe("pnpm catalog", () => {
73+
const fixture = "./__fixtures__/turbo_catalog";
74+
75+
it("warns on catalog usage", () => {
76+
getTurboVersion({}, fixture);
77+
expect(mockConsole.warn).toHaveBeenCalledWith(
78+
"≫ ",
79+
"Cannot infer turbo version due to use of `catalog` protocol. Remove `turbo` from your PNPM catalog to ensure correct turbo version is used"
80+
);
81+
});
82+
83+
it("falls back to inferring major from turbo.json", () => {
84+
expect(getTurboVersion({}, fixture)).toEqual("^2");
85+
});
86+
});
7187
});

packages/turbo-ignore/src/getTurboVersion.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "node:fs";
22
import path from "node:path";
33
import type { PackageJson } from "@turbo/utils";
44
import { parse as JSON5Parse } from "json5";
5-
import { error, info } from "./logger";
5+
import { error, info, warn } from "./logger";
66
import type { TurboIgnoreOptions } from "./types";
77

88
export function getTurboVersion(
@@ -23,8 +23,13 @@ export function getTurboVersion(
2323
const devDependencies = packageJson.devDependencies?.turbo;
2424
turboVersion = dependencies || devDependencies;
2525
if (turboVersion !== undefined) {
26-
info(`Inferred turbo version "${turboVersion}" from "package.json"`);
27-
return turboVersion;
26+
if (!turboVersion.startsWith("catalog:")) {
27+
info(`Inferred turbo version "${turboVersion}" from "package.json"`);
28+
return turboVersion;
29+
}
30+
warn(
31+
"Cannot infer turbo version due to use of `catalog` protocol. Remove `turbo` from your PNPM catalog to ensure correct turbo version is used"
32+
);
2833
}
2934
} catch (e) {
3035
error(

0 commit comments

Comments
 (0)