···11-#!/usr/bin/env node
22-33-const {existsSync} = require(`fs`);
44-const {createRequire, createRequireFromPath} = require(`module`);
55-const {resolve} = require(`path`);
66-77-const relPnpApiPath = "../../../../.pnp.cjs";
88-99-const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010-const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111-1212-if (existsSync(absPnpApiPath)) {
1313- if (!process.versions.pnp) {
1414- // Setup the environment to be able to require eslint/bin/eslint.js
1515- require(absPnpApiPath).setup();
1616- }
1717-}
1818-1919-// Defer to the real eslint/bin/eslint.js your application uses
2020-module.exports = absRequire(`eslint/bin/eslint.js`);
-20
.yarn/sdks/eslint/lib/api.js
···11-#!/usr/bin/env node
22-33-const {existsSync} = require(`fs`);
44-const {createRequire, createRequireFromPath} = require(`module`);
55-const {resolve} = require(`path`);
66-77-const relPnpApiPath = "../../../../.pnp.cjs";
88-99-const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010-const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111-1212-if (existsSync(absPnpApiPath)) {
1313- if (!process.versions.pnp) {
1414- // Setup the environment to be able to require eslint/lib/api.js
1515- require(absPnpApiPath).setup();
1616- }
1717-}
1818-1919-// Defer to the real eslint/lib/api.js your application uses
2020-module.exports = absRequire(`eslint/lib/api.js`);
-20
.yarn/sdks/typescript/bin/tsc
···11-#!/usr/bin/env node
22-33-const {existsSync} = require(`fs`);
44-const {createRequire, createRequireFromPath} = require(`module`);
55-const {resolve} = require(`path`);
66-77-const relPnpApiPath = "../../../../.pnp.cjs";
88-99-const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010-const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111-1212-if (existsSync(absPnpApiPath)) {
1313- if (!process.versions.pnp) {
1414- // Setup the environment to be able to require typescript/bin/tsc
1515- require(absPnpApiPath).setup();
1616- }
1717-}
1818-1919-// Defer to the real typescript/bin/tsc your application uses
2020-module.exports = absRequire(`typescript/bin/tsc`);
-20
.yarn/sdks/typescript/bin/tsserver
···11-#!/usr/bin/env node
22-33-const {existsSync} = require(`fs`);
44-const {createRequire, createRequireFromPath} = require(`module`);
55-const {resolve} = require(`path`);
66-77-const relPnpApiPath = "../../../../.pnp.cjs";
88-99-const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010-const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111-1212-if (existsSync(absPnpApiPath)) {
1313- if (!process.versions.pnp) {
1414- // Setup the environment to be able to require typescript/bin/tsserver
1515- require(absPnpApiPath).setup();
1616- }
1717-}
1818-1919-// Defer to the real typescript/bin/tsserver your application uses
2020-module.exports = absRequire(`typescript/bin/tsserver`);
-20
.yarn/sdks/typescript/lib/tsc.js
···11-#!/usr/bin/env node
22-33-const {existsSync} = require(`fs`);
44-const {createRequire, createRequireFromPath} = require(`module`);
55-const {resolve} = require(`path`);
66-77-const relPnpApiPath = "../../../../.pnp.cjs";
88-99-const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010-const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111-1212-if (existsSync(absPnpApiPath)) {
1313- if (!process.versions.pnp) {
1414- // Setup the environment to be able to require typescript/lib/tsc.js
1515- require(absPnpApiPath).setup();
1616- }
1717-}
1818-1919-// Defer to the real typescript/lib/tsc.js your application uses
2020-module.exports = absRequire(`typescript/lib/tsc.js`);
-157
.yarn/sdks/typescript/lib/tsserver.js
···11-#!/usr/bin/env node
22-33-const {existsSync} = require(`fs`);
44-const {createRequire, createRequireFromPath} = require(`module`);
55-const {resolve} = require(`path`);
66-77-const relPnpApiPath = "../../../../.pnp.cjs";
88-99-const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010-const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111-1212-const moduleWrapper = tsserver => {
1313- if (!process.versions.pnp) {
1414- return tsserver;
1515- }
1616-1717- const {isAbsolute} = require(`path`);
1818- const pnpApi = require(`pnpapi`);
1919-2020- const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//);
2121- const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`);
2222-2323- const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
2424- return `${locator.name}@${locator.reference}`;
2525- }));
2626-2727- // VSCode sends the zip paths to TS using the "zip://" prefix, that TS
2828- // doesn't understand. This layer makes sure to remove the protocol
2929- // before forwarding it to TS, and to add it back on all returned paths.
3030-3131- function toEditorPath(str) {
3232- // We add the `zip:` prefix to both `.zip/` paths and virtual paths
3333- if (isAbsolute(str) && !str.match(/^\^zip:/) && (str.match(/\.zip\//) || isVirtual(str))) {
3434- // We also take the opportunity to turn virtual paths into physical ones;
3535- // this makes it much easier to work with workspaces that list peer
3636- // dependencies, since otherwise Ctrl+Click would bring us to the virtual
3737- // file instances instead of the real ones.
3838- //
3939- // We only do this to modules owned by the the dependency tree roots.
4040- // This avoids breaking the resolution when jumping inside a vendor
4141- // with peer dep (otherwise jumping into react-dom would show resolution
4242- // errors on react).
4343- //
4444- const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str;
4545- if (resolved) {
4646- const locator = pnpApi.findPackageLocator(resolved);
4747- if (locator && dependencyTreeRoots.has(`${locator.name}@${locator.reference}`)) {
4848- str = resolved;
4949- }
5050- }
5151-5252- str = normalize(str);
5353-5454- if (str.match(/\.zip\//)) {
5555- switch (hostInfo) {
5656- // Absolute VSCode `Uri.fsPath`s need to start with a slash.
5757- // VSCode only adds it automatically for supported schemes,
5858- // so we have to do it manually for the `zip` scheme.
5959- // The path needs to start with a caret otherwise VSCode doesn't handle the protocol
6060- //
6161- // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
6262- //
6363- case `vscode`: {
6464- str = `^zip:${str}`;
6565- } break;
6666-6767- // To make "go to definition" work,
6868- // We have to resolve the actual file system path from virtual path
6969- // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
7070- case `coc-nvim`: {
7171- str = normalize(resolved).replace(/\.zip\//, `.zip::`);
7272- str = resolve(`zipfile:${str}`);
7373- } break;
7474-7575- // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server)
7676- // We have to resolve the actual file system path from virtual path,
7777- // everything else is up to neovim
7878- case `neovim`: {
7979- str = normalize(resolved).replace(/\.zip\//, `.zip::`);
8080- str = `zipfile:${str}`;
8181- } break;
8282-8383- default: {
8484- str = `zip:${str}`;
8585- } break;
8686- }
8787- }
8888- }
8989-9090- return str;
9191- }
9292-9393- function fromEditorPath(str) {
9494- return process.platform === `win32`
9595- ? str.replace(/^\^?zip:\//, ``)
9696- : str.replace(/^\^?zip:/, ``);
9797- }
9898-9999- // Force enable 'allowLocalPluginLoads'
100100- // TypeScript tries to resolve plugins using a path relative to itself
101101- // which doesn't work when using the global cache
102102- // https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238
103103- // VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but
104104- // TypeScript already does local loads and if this code is running the user trusts the workspace
105105- // https://github.com/microsoft/vscode/issues/45856
106106- const ConfiguredProject = tsserver.server.ConfiguredProject;
107107- const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype;
108108- ConfiguredProject.prototype.enablePluginsWithOptions = function() {
109109- this.projectService.allowLocalPluginLoads = true;
110110- return originalEnablePluginsWithOptions.apply(this, arguments);
111111- };
112112-113113- // And here is the point where we hijack the VSCode <-> TS communications
114114- // by adding ourselves in the middle. We locate everything that looks
115115- // like an absolute path of ours and normalize it.
116116-117117- const Session = tsserver.server.Session;
118118- const {onMessage: originalOnMessage, send: originalSend} = Session.prototype;
119119- let hostInfo = `unknown`;
120120-121121- Object.assign(Session.prototype, {
122122- onMessage(/** @type {string} */ message) {
123123- const parsedMessage = JSON.parse(message)
124124-125125- if (
126126- parsedMessage != null &&
127127- typeof parsedMessage === `object` &&
128128- parsedMessage.arguments &&
129129- typeof parsedMessage.arguments.hostInfo === `string`
130130- ) {
131131- hostInfo = parsedMessage.arguments.hostInfo;
132132- }
133133-134134- return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
135135- return typeof value === `string` ? fromEditorPath(value) : value;
136136- }));
137137- },
138138-139139- send(/** @type {any} */ msg) {
140140- return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => {
141141- return typeof value === `string` ? toEditorPath(value) : value;
142142- })));
143143- }
144144- });
145145-146146- return tsserver;
147147-};
148148-149149-if (existsSync(absPnpApiPath)) {
150150- if (!process.versions.pnp) {
151151- // Setup the environment to be able to require typescript/lib/tsserver.js
152152- require(absPnpApiPath).setup();
153153- }
154154-}
155155-156156-// Defer to the real typescript/lib/tsserver.js your application uses
157157-module.exports = moduleWrapper(absRequire(`typescript/lib/tsserver.js`));
-157
.yarn/sdks/typescript/lib/tsserverlibrary.js
···11-#!/usr/bin/env node
22-33-const {existsSync} = require(`fs`);
44-const {createRequire, createRequireFromPath} = require(`module`);
55-const {resolve} = require(`path`);
66-77-const relPnpApiPath = "../../../../.pnp.cjs";
88-99-const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010-const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111-1212-const moduleWrapper = tsserver => {
1313- if (!process.versions.pnp) {
1414- return tsserver;
1515- }
1616-1717- const {isAbsolute} = require(`path`);
1818- const pnpApi = require(`pnpapi`);
1919-2020- const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//);
2121- const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`);
2222-2323- const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
2424- return `${locator.name}@${locator.reference}`;
2525- }));
2626-2727- // VSCode sends the zip paths to TS using the "zip://" prefix, that TS
2828- // doesn't understand. This layer makes sure to remove the protocol
2929- // before forwarding it to TS, and to add it back on all returned paths.
3030-3131- function toEditorPath(str) {
3232- // We add the `zip:` prefix to both `.zip/` paths and virtual paths
3333- if (isAbsolute(str) && !str.match(/^\^zip:/) && (str.match(/\.zip\//) || isVirtual(str))) {
3434- // We also take the opportunity to turn virtual paths into physical ones;
3535- // this makes it much easier to work with workspaces that list peer
3636- // dependencies, since otherwise Ctrl+Click would bring us to the virtual
3737- // file instances instead of the real ones.
3838- //
3939- // We only do this to modules owned by the the dependency tree roots.
4040- // This avoids breaking the resolution when jumping inside a vendor
4141- // with peer dep (otherwise jumping into react-dom would show resolution
4242- // errors on react).
4343- //
4444- const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str;
4545- if (resolved) {
4646- const locator = pnpApi.findPackageLocator(resolved);
4747- if (locator && dependencyTreeRoots.has(`${locator.name}@${locator.reference}`)) {
4848- str = resolved;
4949- }
5050- }
5151-5252- str = normalize(str);
5353-5454- if (str.match(/\.zip\//)) {
5555- switch (hostInfo) {
5656- // Absolute VSCode `Uri.fsPath`s need to start with a slash.
5757- // VSCode only adds it automatically for supported schemes,
5858- // so we have to do it manually for the `zip` scheme.
5959- // The path needs to start with a caret otherwise VSCode doesn't handle the protocol
6060- //
6161- // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
6262- //
6363- case `vscode`: {
6464- str = `^zip:${str}`;
6565- } break;
6666-6767- // To make "go to definition" work,
6868- // We have to resolve the actual file system path from virtual path
6969- // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
7070- case `coc-nvim`: {
7171- str = normalize(resolved).replace(/\.zip\//, `.zip::`);
7272- str = resolve(`zipfile:${str}`);
7373- } break;
7474-7575- // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server)
7676- // We have to resolve the actual file system path from virtual path,
7777- // everything else is up to neovim
7878- case `neovim`: {
7979- str = normalize(resolved).replace(/\.zip\//, `.zip::`);
8080- str = `zipfile:${str}`;
8181- } break;
8282-8383- default: {
8484- str = `zip:${str}`;
8585- } break;
8686- }
8787- }
8888- }
8989-9090- return str;
9191- }
9292-9393- function fromEditorPath(str) {
9494- return process.platform === `win32`
9595- ? str.replace(/^\^?zip:\//, ``)
9696- : str.replace(/^\^?zip:/, ``);
9797- }
9898-9999- // Force enable 'allowLocalPluginLoads'
100100- // TypeScript tries to resolve plugins using a path relative to itself
101101- // which doesn't work when using the global cache
102102- // https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238
103103- // VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but
104104- // TypeScript already does local loads and if this code is running the user trusts the workspace
105105- // https://github.com/microsoft/vscode/issues/45856
106106- const ConfiguredProject = tsserver.server.ConfiguredProject;
107107- const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype;
108108- ConfiguredProject.prototype.enablePluginsWithOptions = function() {
109109- this.projectService.allowLocalPluginLoads = true;
110110- return originalEnablePluginsWithOptions.apply(this, arguments);
111111- };
112112-113113- // And here is the point where we hijack the VSCode <-> TS communications
114114- // by adding ourselves in the middle. We locate everything that looks
115115- // like an absolute path of ours and normalize it.
116116-117117- const Session = tsserver.server.Session;
118118- const {onMessage: originalOnMessage, send: originalSend} = Session.prototype;
119119- let hostInfo = `unknown`;
120120-121121- Object.assign(Session.prototype, {
122122- onMessage(/** @type {string} */ message) {
123123- const parsedMessage = JSON.parse(message)
124124-125125- if (
126126- parsedMessage != null &&
127127- typeof parsedMessage === `object` &&
128128- parsedMessage.arguments &&
129129- typeof parsedMessage.arguments.hostInfo === `string`
130130- ) {
131131- hostInfo = parsedMessage.arguments.hostInfo;
132132- }
133133-134134- return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
135135- return typeof value === `string` ? fromEditorPath(value) : value;
136136- }));
137137- },
138138-139139- send(/** @type {any} */ msg) {
140140- return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => {
141141- return typeof value === `string` ? toEditorPath(value) : value;
142142- })));
143143- }
144144- });
145145-146146- return tsserver;
147147-};
148148-149149-if (existsSync(absPnpApiPath)) {
150150- if (!process.versions.pnp) {
151151- // Setup the environment to be able to require typescript/lib/tsserverlibrary.js
152152- require(absPnpApiPath).setup();
153153- }
154154-}
155155-156156-// Defer to the real typescript/lib/tsserverlibrary.js your application uses
157157-module.exports = moduleWrapper(absRequire(`typescript/lib/tsserverlibrary.js`));
-20
.yarn/sdks/typescript/lib/typescript.js
···11-#!/usr/bin/env node
22-33-const {existsSync} = require(`fs`);
44-const {createRequire, createRequireFromPath} = require(`module`);
55-const {resolve} = require(`path`);
66-77-const relPnpApiPath = "../../../../.pnp.cjs";
88-99-const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010-const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111-1212-if (existsSync(absPnpApiPath)) {
1313- if (!process.versions.pnp) {
1414- // Setup the environment to be able to require typescript/lib/typescript.js
1515- require(absPnpApiPath).setup();
1616- }
1717-}
1818-1919-// Defer to the real typescript/lib/typescript.js your application uses
2020-module.exports = absRequire(`typescript/lib/typescript.js`);