Skip to content

Commit f0d2a9b

Browse files
authored
Fix typescript workspace resolution error (#26)
1 parent 74c6575 commit f0d2a9b

18 files changed

Lines changed: 14607 additions & 16160 deletions

.pnp.cjs

Lines changed: 12925 additions & 14604 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.pnp.loader.mjs

Lines changed: 34 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
},
99
"typescript.enablePromptUseWorkspaceTsdk": true,
1010
"typescript.tsdk": ".yarn/sdks/typescript/lib",
11-
"eslint.nodePath": ".yarn/sdks"
11+
"eslint.nodePath": ".yarn/sdks",
12+
"eslint.workingDirectories": [
13+
"./packages/browser-extension"
14+
]
1215
}
-10.7 MB
Binary file not shown.
11.2 MB
Binary file not shown.
-10.8 MB
Binary file not shown.
11.2 MB
Binary file not shown.

.yarn/releases/yarn-3.1.1.cjs

Lines changed: 0 additions & 768 deletions
This file was deleted.

.yarn/releases/yarn-3.2.1.cjs

Lines changed: 786 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const moduleWrapper = tsserver => {
1818
const pnpApi = require(`pnpapi`);
1919

2020
const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//);
21+
const isPortal = str => str.startsWith("portal:/");
2122
const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`);
2223

2324
const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
@@ -44,7 +45,7 @@ const moduleWrapper = tsserver => {
4445
const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str;
4546
if (resolved) {
4647
const locator = pnpApi.findPackageLocator(resolved);
47-
if (locator && dependencyTreeRoots.has(`${locator.name}@${locator.reference}`)) {
48+
if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) {
4849
str = resolved;
4950
}
5051
}
@@ -60,14 +61,30 @@ const moduleWrapper = tsserver => {
6061
//
6162
// Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
6263
//
63-
// Update Oct 8 2021: VSCode changed their format in 1.61.
64+
// 2021-10-08: VSCode changed the format in 1.61.
6465
// Before | ^zip:/c:/foo/bar.zip/package.json
6566
// After | ^/zip//c:/foo/bar.zip/package.json
6667
//
68+
// 2022-04-06: VSCode changed the format in 1.66.
69+
// Before | ^/zip//c:/foo/bar.zip/package.json
70+
// After | ^/zip/c:/foo/bar.zip/package.json
71+
//
72+
// 2022-05-06: VSCode changed the format in 1.68
73+
// Before | ^/zip/c:/foo/bar.zip/package.json
74+
// After | ^/zip//c:/foo/bar.zip/package.json
75+
//
6776
case `vscode <1.61`: {
6877
str = `^zip:${str}`;
6978
} break;
7079

80+
case `vscode <1.66`: {
81+
str = `^/zip/${str}`;
82+
} break;
83+
84+
case `vscode <1.68`: {
85+
str = `^/zip${str}`;
86+
} break;
87+
7188
case `vscode`: {
7289
str = `^/zip/${str}`;
7390
} break;
@@ -85,7 +102,7 @@ const moduleWrapper = tsserver => {
85102
// everything else is up to neovim
86103
case `neovim`: {
87104
str = normalize(resolved).replace(/\.zip\//, `.zip::`);
88-
str = `zipfile:${str}`;
105+
str = `zipfile://${str}`;
89106
} break;
90107

91108
default: {
@@ -100,8 +117,7 @@ const moduleWrapper = tsserver => {
100117

101118
function fromEditorPath(str) {
102119
switch (hostInfo) {
103-
case `coc-nvim`:
104-
case `neovim`: {
120+
case `coc-nvim`: {
105121
str = str.replace(/\.zip::/, `.zip/`);
106122
// The path for coc-nvim is in format of /<pwd>/zipfile:/<pwd>/.yarn/...
107123
// So in order to convert it back, we use .* to match all the thing
@@ -111,11 +127,15 @@ const moduleWrapper = tsserver => {
111127
: str.replace(/^.*zipfile:/, ``);
112128
} break;
113129

130+
case `neovim`: {
131+
str = str.replace(/\.zip::/, `.zip/`);
132+
// The path for neovim is in format of zipfile:///<pwd>/.yarn/...
133+
return str.replace(/^zipfile:\/\//, ``);
134+
} break;
135+
114136
case `vscode`:
115137
default: {
116-
return process.platform === `win32`
117-
? str.replace(/^\^?(zip:|\/zip)\/+/, ``)
118-
: str.replace(/^\^?(zip:|\/zip)\/+/, `/`);
138+
return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`)
119139
} break;
120140
}
121141
}
@@ -143,8 +163,9 @@ const moduleWrapper = tsserver => {
143163
let hostInfo = `unknown`;
144164

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

149170
if (
150171
parsedMessage != null &&
@@ -153,14 +174,32 @@ const moduleWrapper = tsserver => {
153174
typeof parsedMessage.arguments.hostInfo === `string`
154175
) {
155176
hostInfo = parsedMessage.arguments.hostInfo;
156-
if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK && process.env.VSCODE_IPC_HOOK.match(/Code\/1\.([1-5][0-9]|60)\./)) {
157-
hostInfo += ` <1.61`;
177+
if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) {
178+
const [, major, minor] = (process.env.VSCODE_IPC_HOOK.match(
179+
// The RegExp from https://semver.org/ but without the caret at the start
180+
/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
181+
) ?? []).map(Number)
182+
183+
if (major === 1) {
184+
if (minor < 61) {
185+
hostInfo += ` <1.61`;
186+
} else if (minor < 66) {
187+
hostInfo += ` <1.66`;
188+
} else if (minor < 68) {
189+
hostInfo += ` <1.68`;
190+
}
191+
}
158192
}
159193
}
160194

161-
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
162-
return typeof value === `string` ? fromEditorPath(value) : value;
163-
}));
195+
const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => {
196+
return typeof value === 'string' ? fromEditorPath(value) : value;
197+
});
198+
199+
return originalOnMessage.call(
200+
this,
201+
isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)
202+
);
164203
},
165204

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

0 commit comments

Comments
 (0)