Skip to content

Commit a0186c8

Browse files
committed
fix(sdks): only patch typescript entry point for >= 5.5 (#6263)
**What's the problem this PR addresses?** The SDK changes in #6248 broke support for older TypeScript versions. I tested it on `5.4.1-rc` (master) and it was fine but it crashes on 5.2.0-beta (https://github.com/yarnpkg/berry/blob/4308dca8091438e8f88682e59ef5ba5bc72241ca/package.json#L26) **How did you fix it?** Check the TypeScript version and only apply the patch if needed. **Checklist** - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). - [x] I have set the packages that need to be released for my changes to be effective. - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent 893e1ab commit a0186c8

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

.yarn/sdks/typescript/lib/tsserver.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,12 @@ const moduleWrapper = tsserver => {
221221
return tsserver;
222222
};
223223

224-
moduleWrapper(absRequire(`typescript`));
224+
const [major, minor] = absRequire(`typescript/package.json`).version.split(`.`, 2).map(value => parseInt(value, 10));
225+
// In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well.
226+
// Ref https://github.com/microsoft/TypeScript/pull/55326
227+
if (major > 5 || (major === 5 && minor >= 5)) {
228+
moduleWrapper(absRequire(`typescript`));
229+
}
225230

226231
// Defer to the real typescript/lib/tsserver.js your application uses
227232
module.exports = moduleWrapper(absRequire(`typescript/lib/tsserver.js`));

.yarn/sdks/typescript/lib/tsserverlibrary.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,12 @@ const moduleWrapper = tsserver => {
221221
return tsserver;
222222
};
223223

224-
moduleWrapper(absRequire(`typescript`));
224+
const [major, minor] = absRequire(`typescript/package.json`).version.split(`.`, 2).map(value => parseInt(value, 10));
225+
// In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well.
226+
// Ref https://github.com/microsoft/TypeScript/pull/55326
227+
if (major > 5 || (major === 5 && minor >= 5)) {
228+
moduleWrapper(absRequire(`typescript`));
229+
}
225230

226231
// Defer to the real typescript/lib/tsserverlibrary.js your application uses
227232
module.exports = moduleWrapper(absRequire(`typescript/lib/tsserverlibrary.js`));

.yarn/versions/f094b4b7.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
releases:
2+
"@yarnpkg/sdks": patch

packages/yarnpkg-sdks/sources/sdks/base.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,12 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
251251
return tsserver;
252252
};
253253
254-
moduleWrapper(absRequire(\`typescript\`));
254+
const [major, minor] = absRequire(\`typescript/package.json\`).version.split(\`.\`, 2).map(value => parseInt(value, 10));
255+
// In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well.
256+
// Ref https://github.com/microsoft/TypeScript/pull/55326
257+
if (major > 5 || (major === 5 && minor >= 5)) {
258+
moduleWrapper(absRequire(\`typescript\`));
259+
}
255260
`;
256261

257262
const wrapper = new Wrapper(`typescript` as PortablePath, {pnpApi, target});

0 commit comments

Comments
 (0)