Skip to content

Commit f17384e

Browse files
authored
chore: update the SDK (#83)
1 parent 4344ba1 commit f17384e

File tree

6 files changed

+288
-33
lines changed

6 files changed

+288
-33
lines changed

.yarn/sdks/eslint/lib/api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111

1212
if (existsSync(absPnpApiPath)) {
1313
if (!process.versions.pnp) {
14-
// Setup the environment to be able to require eslint/lib/api.js
14+
// Setup the environment to be able to require eslint
1515
require(absPnpApiPath).setup();
1616
}
1717
}
1818

19-
// Defer to the real eslint/lib/api.js your application uses
20-
module.exports = absRequire(`eslint/lib/api.js`);
19+
// Defer to the real eslint your application uses
20+
module.exports = absRequire(`eslint`);

.yarn/sdks/eslint/package.json

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

.yarn/sdks/integrations.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# This file is automatically generated by PnPify.
2-
# Manual changes will be lost!
1+
# This file is automatically generated by @yarnpkg/sdks.
2+
# Manual changes might be lost!
33

44
integrations:
55
- vscode

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

Lines changed: 91 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111

1212
const moduleWrapper = tsserver => {
13+
if (!process.versions.pnp) {
14+
return tsserver;
15+
}
16+
1317
const {isAbsolute} = require(`path`);
1418
const pnpApi = require(`pnpapi`);
1519

20+
const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//);
21+
const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`);
22+
1623
const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
1724
return `${locator.name}@${locator.reference}`;
1825
}));
@@ -23,9 +30,9 @@ const moduleWrapper = tsserver => {
2330

2431
function toEditorPath(str) {
2532
// We add the `zip:` prefix to both `.zip/` paths and virtual paths
26-
if (isAbsolute(str) && !str.match(/^\^zip:/) && (str.match(/\.zip\//) || str.match(/\/(\$\$virtual|__virtual__)\//))) {
33+
if (isAbsolute(str) && !str.match(/^\^?(zip:|\/zip\/)/) && (str.match(/\.zip\//) || isVirtual(str))) {
2734
// We also take the opportunity to turn virtual paths into physical ones;
28-
// this makes is much easier to work with workspaces that list peer
35+
// this makes it much easier to work with workspaces that list peer
2936
// dependencies, since otherwise Ctrl+Click would bring us to the virtual
3037
// file instances instead of the real ones.
3138
//
@@ -34,36 +41,83 @@ const moduleWrapper = tsserver => {
3441
// with peer dep (otherwise jumping into react-dom would show resolution
3542
// errors on react).
3643
//
37-
const resolved = pnpApi.resolveVirtual(str);
44+
const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str;
3845
if (resolved) {
3946
const locator = pnpApi.findPackageLocator(resolved);
4047
if (locator && dependencyTreeRoots.has(`${locator.name}@${locator.reference}`)) {
41-
str = resolved;
48+
str = resolved;
4249
}
4350
}
4451

45-
str = str.replace(/\\/g, `/`)
46-
str = str.replace(/^\/?/, `/`);
52+
str = normalize(str);
4753

48-
// Absolute VSCode `Uri.fsPath`s need to start with a slash.
49-
// VSCode only adds it automatically for supported schemes,
50-
// so we have to do it manually for the `zip` scheme.
51-
// The path needs to start with a caret otherwise VSCode doesn't handle the protocol
52-
//
53-
// Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
54-
//
5554
if (str.match(/\.zip\//)) {
56-
str = `${isVSCode ? `^` : ``}zip:${str}`;
55+
switch (hostInfo) {
56+
// Absolute VSCode `Uri.fsPath`s need to start with a slash.
57+
// VSCode only adds it automatically for supported schemes,
58+
// so we have to do it manually for the `zip` scheme.
59+
// The path needs to start with a caret otherwise VSCode doesn't handle the protocol
60+
//
61+
// Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
62+
//
63+
// Update Oct 8 2021: VSCode changed their format in 1.61.
64+
// Before | ^zip:/c:/foo/bar.zip/package.json
65+
// After | ^/zip//c:/foo/bar.zip/package.json
66+
//
67+
case `vscode <1.61`: {
68+
str = `^zip:${str}`;
69+
} break;
70+
71+
case `vscode`: {
72+
str = `^/zip/${str}`;
73+
} break;
74+
75+
// To make "go to definition" work,
76+
// We have to resolve the actual file system path from virtual path
77+
// and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
78+
case `coc-nvim`: {
79+
str = normalize(resolved).replace(/\.zip\//, `.zip::`);
80+
str = resolve(`zipfile:${str}`);
81+
} break;
82+
83+
// Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server)
84+
// We have to resolve the actual file system path from virtual path,
85+
// everything else is up to neovim
86+
case `neovim`: {
87+
str = normalize(resolved).replace(/\.zip\//, `.zip::`);
88+
str = `zipfile:${str}`;
89+
} break;
90+
91+
default: {
92+
str = `zip:${str}`;
93+
} break;
94+
}
5795
}
5896
}
5997

6098
return str;
6199
}
62100

63101
function fromEditorPath(str) {
64-
return process.platform === `win32`
65-
? str.replace(/^\^?zip:\//, ``)
66-
: str.replace(/^\^?zip:/, ``);
102+
switch (hostInfo) {
103+
case `coc-nvim`:
104+
case `neovim`: {
105+
str = str.replace(/\.zip::/, `.zip/`);
106+
// The path for coc-nvim is in format of /<pwd>/zipfile:/<pwd>/.yarn/...
107+
// So in order to convert it back, we use .* to match all the thing
108+
// before `zipfile:`
109+
return process.platform === `win32`
110+
? str.replace(/^.*zipfile:\//, ``)
111+
: str.replace(/^.*zipfile:/, ``);
112+
} break;
113+
114+
case `vscode`:
115+
default: {
116+
return process.platform === `win32`
117+
? str.replace(/^\^?(zip:|\/zip)\/+/, ``)
118+
: str.replace(/^\^?(zip:|\/zip)\/+/, `/`);
119+
} break;
120+
}
67121
}
68122

69123
// Force enable 'allowLocalPluginLoads'
@@ -86,24 +140,33 @@ const moduleWrapper = tsserver => {
86140

87141
const Session = tsserver.server.Session;
88142
const {onMessage: originalOnMessage, send: originalSend} = Session.prototype;
89-
let isVSCode = false;
143+
let hostInfo = `unknown`;
90144

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

95150
if (
96151
parsedMessage != null &&
97152
typeof parsedMessage === `object` &&
98153
parsedMessage.arguments &&
99-
parsedMessage.arguments.hostInfo === `vscode`
154+
typeof parsedMessage.arguments.hostInfo === `string`
100155
) {
101-
isVSCode = true;
156+
hostInfo = parsedMessage.arguments.hostInfo;
157+
if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK && process.env.VSCODE_IPC_HOOK.match(/Code\/1\.([1-5][0-9]|60)\./)) {
158+
hostInfo += ` <1.61`;
159+
}
102160
}
103161

104-
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
105-
return typeof value === `string` ? fromEditorPath(value) : value;
106-
}));
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+
);
107170
},
108171

109172
send(/** @type {any} */ msg) {
@@ -112,6 +175,8 @@ const moduleWrapper = tsserver => {
112175
})));
113176
}
114177
});
178+
179+
return tsserver;
115180
};
116181

117182
if (existsSync(absPnpApiPath)) {

0 commit comments

Comments
 (0)