Skip to content

Commit f994c2b

Browse files
authored
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 df5d1c2 commit f994c2b

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
@@ -250,7 +250,12 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
250250
return tsserver;
251251
};
252252
253-
moduleWrapper(absRequire(\`typescript\`));
253+
const [major, minor] = absRequire(\`typescript/package.json\`).version.split(\`.\`, 2).map(value => parseInt(value, 10));
254+
// In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well.
255+
// Ref https://github.com/microsoft/TypeScript/pull/55326
256+
if (major > 5 || (major === 5 && minor >= 5)) {
257+
moduleWrapper(absRequire(\`typescript\`));
258+
}
254259
`;
255260

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

0 commit comments

Comments
 (0)