Skip to content

Commit fbd20be

Browse files
authored
fix(sdks): support typescript IPC (#3991)
1 parent 442f509 commit fbd20be

File tree

5 files changed

+36
-16
lines changed

5 files changed

+36
-16
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ const moduleWrapper = tsserver => {
143143
let hostInfo = `unknown`;
144144

145145
Object.assign(Session.prototype, {
146-
onMessage(/** @type {string} */ message) {
147-
const parsedMessage = JSON.parse(message)
146+
onMessage(/** @type {string | object} */ message) {
147+
const isStringMessage = typeof message === 'string';
148+
const parsedMessage = isStringMessage ? JSON.parse(message) : message;
148149

149150
if (
150151
parsedMessage != null &&
@@ -158,9 +159,14 @@ const moduleWrapper = tsserver => {
158159
}
159160
}
160161

161-
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
162-
return typeof value === `string` ? fromEditorPath(value) : value;
163-
}));
162+
const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => {
163+
return typeof value === 'string' ? fromEditorPath(value) : value;
164+
});
165+
166+
return originalOnMessage.call(
167+
this,
168+
isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)
169+
);
164170
},
165171

166172
send(/** @type {any} */ msg) {

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ const moduleWrapper = tsserver => {
143143
let hostInfo = `unknown`;
144144

145145
Object.assign(Session.prototype, {
146-
onMessage(/** @type {string} */ message) {
147-
const parsedMessage = JSON.parse(message)
146+
onMessage(/** @type {string | object} */ message) {
147+
const isStringMessage = typeof message === 'string';
148+
const parsedMessage = isStringMessage ? JSON.parse(message) : message;
148149

149150
if (
150151
parsedMessage != null &&
@@ -158,9 +159,14 @@ const moduleWrapper = tsserver => {
158159
}
159160
}
160161

161-
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
162-
return typeof value === `string` ? fromEditorPath(value) : value;
163-
}));
162+
const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => {
163+
return typeof value === 'string' ? fromEditorPath(value) : value;
164+
});
165+
166+
return originalOnMessage.call(
167+
this,
168+
isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)
169+
);
164170
},
165171

166172
send(/** @type {any} */ msg) {

.yarn/sdks/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript",
3-
"version": "4.4.2-sdk",
3+
"version": "4.5.2-sdk",
44
"main": "./lib/typescript.js",
55
"type": "commonjs"
66
}

.yarn/versions/dd3df2e2.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: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
170170
let hostInfo = \`unknown\`;
171171
172172
Object.assign(Session.prototype, {
173-
onMessage(/** @type {string} */ message) {
174-
const parsedMessage = JSON.parse(message)
173+
onMessage(/** @type {string | object} */ message) {
174+
const isStringMessage = typeof message === 'string';
175+
const parsedMessage = isStringMessage ? JSON.parse(message) : message;
175176
176177
if (
177178
parsedMessage != null &&
@@ -185,9 +186,14 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
185186
}
186187
}
187188
188-
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
189-
return typeof value === \`string\` ? fromEditorPath(value) : value;
190-
}));
189+
const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => {
190+
return typeof value === 'string' ? fromEditorPath(value) : value;
191+
});
192+
193+
return originalOnMessage.call(
194+
this,
195+
isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)
196+
);
191197
},
192198
193199
send(/** @type {any} */ msg) {

0 commit comments

Comments
 (0)