Skip to content

Commit

Permalink
fix(sdks): support typescript IPC (#3991)
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz authored and arcanis committed Jan 18, 2022
1 parent 5f8ae50 commit 533014f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
16 changes: 11 additions & 5 deletions .yarn/sdks/typescript/lib/tsserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ const moduleWrapper = tsserver => {
let hostInfo = `unknown`;

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

if (
parsedMessage != null &&
Expand All @@ -158,9 +159,14 @@ const moduleWrapper = tsserver => {
}
}

return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
return typeof value === `string` ? fromEditorPath(value) : value;
}));
const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => {
return typeof value === 'string' ? fromEditorPath(value) : value;
});

return originalOnMessage.call(
this,
isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)
);
},

send(/** @type {any} */ msg) {
Expand Down
16 changes: 11 additions & 5 deletions .yarn/sdks/typescript/lib/tsserverlibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ const moduleWrapper = tsserver => {
let hostInfo = `unknown`;

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

if (
parsedMessage != null &&
Expand All @@ -158,9 +159,14 @@ const moduleWrapper = tsserver => {
}
}

return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
return typeof value === `string` ? fromEditorPath(value) : value;
}));
const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => {
return typeof value === 'string' ? fromEditorPath(value) : value;
});

return originalOnMessage.call(
this,
isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)
);
},

send(/** @type {any} */ msg) {
Expand Down
2 changes: 1 addition & 1 deletion .yarn/sdks/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript",
"version": "4.4.2-sdk",
"version": "4.5.2-sdk",
"main": "./lib/typescript.js",
"type": "commonjs"
}
2 changes: 2 additions & 0 deletions .yarn/versions/dd3df2e2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
"@yarnpkg/sdks": patch
16 changes: 11 additions & 5 deletions packages/yarnpkg-sdks/sources/sdks/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
let hostInfo = \`unknown\`;
Object.assign(Session.prototype, {
onMessage(/** @type {string} */ message) {
const parsedMessage = JSON.parse(message)
onMessage(/** @type {string | object} */ message) {
const isStringMessage = typeof message === 'string';
const parsedMessage = isStringMessage ? JSON.parse(message) : message;
if (
parsedMessage != null &&
Expand All @@ -185,9 +186,14 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
}
}
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
return typeof value === \`string\` ? fromEditorPath(value) : value;
}));
const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => {
return typeof value === 'string' ? fromEditorPath(value) : value;
});
return originalOnMessage.call(
this,
isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)
);
},
send(/** @type {any} */ msg) {
Expand Down

0 comments on commit 533014f

Please sign in to comment.