diff --git a/.yarn/sdks/eslint/bin/eslint.js b/.yarn/sdks/eslint/bin/eslint.js new file mode 100755 index 0000000000..4e7554dc1a --- /dev/null +++ b/.yarn/sdks/eslint/bin/eslint.js @@ -0,0 +1,20 @@ +#!/usr/bin/env node + +const {existsSync} = require(`fs`); +const {createRequire, createRequireFromPath} = require(`module`); +const {resolve} = require(`path`); + +const relPnpApiPath = "../../../../.pnp.js"; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require eslint/bin/eslint.js + require(absPnpApiPath).setup(); + } +} + +// Defer to the real eslint/bin/eslint.js your application uses +module.exports = absRequire(`eslint/bin/eslint.js`); diff --git a/.yarn/sdks/eslint/lib/api.js b/.yarn/sdks/eslint/lib/api.js new file mode 100644 index 0000000000..ac3c9fc064 --- /dev/null +++ b/.yarn/sdks/eslint/lib/api.js @@ -0,0 +1,20 @@ +#!/usr/bin/env node + +const {existsSync} = require(`fs`); +const {createRequire, createRequireFromPath} = require(`module`); +const {resolve} = require(`path`); + +const relPnpApiPath = "../../../../.pnp.js"; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require eslint/lib/api.js + require(absPnpApiPath).setup(); + } +} + +// Defer to the real eslint/lib/api.js your application uses +module.exports = absRequire(`eslint/lib/api.js`); diff --git a/.yarn/sdks/eslint/package.json b/.yarn/sdks/eslint/package.json new file mode 100644 index 0000000000..8e25b10bcc --- /dev/null +++ b/.yarn/sdks/eslint/package.json @@ -0,0 +1,6 @@ +{ + "name": "eslint", + "version": "7.26.0-pnpify", + "main": "./lib/api.js", + "type": "commonjs" +} diff --git a/.yarn/sdks/typescript/lib/tsserver.js b/.yarn/sdks/typescript/lib/tsserver.js index baffff80e4..488c4b8a89 100644 --- a/.yarn/sdks/typescript/lib/tsserver.js +++ b/.yarn/sdks/typescript/lib/tsserver.js @@ -13,6 +13,9 @@ const moduleWrapper = tsserver => { const {isAbsolute} = require(`path`); const pnpApi = require(`pnpapi`); + const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//); + const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`); + const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => { return `${locator.name}@${locator.reference}`; })); @@ -23,9 +26,9 @@ const moduleWrapper = tsserver => { function toEditorPath(str) { // We add the `zip:` prefix to both `.zip/` paths and virtual paths - if (isAbsolute(str) && !str.match(/^\^zip:/) && (str.match(/\.zip\//) || str.match(/\/(\$\$virtual|__virtual__)\//))) { + if (isAbsolute(str) && !str.match(/^\^zip:/) && (str.match(/\.zip\//) || isVirtual(str))) { // We also take the opportunity to turn virtual paths into physical ones; - // this makes is much easier to work with workspaces that list peer + // this makes it much easier to work with workspaces that list peer // dependencies, since otherwise Ctrl+Click would bring us to the virtual // file instances instead of the real ones. // @@ -34,26 +37,41 @@ const moduleWrapper = tsserver => { // with peer dep (otherwise jumping into react-dom would show resolution // errors on react). // - const resolved = pnpApi.resolveVirtual(str); + const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str; if (resolved) { const locator = pnpApi.findPackageLocator(resolved); if (locator && dependencyTreeRoots.has(`${locator.name}@${locator.reference}`)) { - str = resolved; + str = resolved; } } - str = str.replace(/\\/g, `/`) - str = str.replace(/^\/?/, `/`); + str = normalize(str); - // Absolute VSCode `Uri.fsPath`s need to start with a slash. - // VSCode only adds it automatically for supported schemes, - // so we have to do it manually for the `zip` scheme. - // The path needs to start with a caret otherwise VSCode doesn't handle the protocol - // - // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910 - // if (str.match(/\.zip\//)) { - str = `${isVSCode ? `^` : ``}zip:${str}`; + switch (hostInfo) { + // Absolute VSCode `Uri.fsPath`s need to start with a slash. + // VSCode only adds it automatically for supported schemes, + // so we have to do it manually for the `zip` scheme. + // The path needs to start with a caret otherwise VSCode doesn't handle the protocol + // + // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910 + // + case `vscode`: { + str = `^zip:${str}`; + } break; + + // To make "go to definition" work, + // We have to resolve the actual file system path from virtual path + // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip) + case `coc-nvim`: { + str = normalize(resolved).replace(/\.zip\//, `.zip::`); + str = resolve(`zipfile:${str}`); + } break; + + default: { + str = `zip:${str}`; + } break; + } } } @@ -86,7 +104,7 @@ const moduleWrapper = tsserver => { const Session = tsserver.server.Session; const {onMessage: originalOnMessage, send: originalSend} = Session.prototype; - let isVSCode = false; + let hostInfo = `unknown`; return Object.assign(Session.prototype, { onMessage(/** @type {string} */ message) { @@ -96,9 +114,9 @@ const moduleWrapper = tsserver => { parsedMessage != null && typeof parsedMessage === `object` && parsedMessage.arguments && - parsedMessage.arguments.hostInfo === `vscode` + typeof parsedMessage.arguments.hostInfo === `string` ) { - isVSCode = true; + hostInfo = parsedMessage.arguments.hostInfo; } return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {