From fc0c66c57266b00f219db86fea8e21bda18e2051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bazyli=20Brzo=CC=81ska?= Date: Fri, 18 Dec 2020 01:18:43 -0800 Subject: [PATCH] chore: setup pnpify --- .vscode/extensions.json | 7 ++ .vscode/pnpify/eslint/lib/api.js | 17 ---- .vscode/pnpify/eslint/package.json | 5 - .vscode/pnpify/prettier/index.js | 17 ---- .vscode/pnpify/prettier/package.json | 5 - .vscode/pnpify/typescript/lib/tsserver.js | 17 ---- .vscode/pnpify/typescript/package.json | 4 - .vscode/settings.json | 16 +++- .yarn/sdks/eslint/bin/eslint.js | 20 ++++ .yarn/sdks/eslint/lib/api.js | 20 ++++ .yarn/sdks/eslint/package.json | 6 ++ .yarn/sdks/integrations.yml | 5 + .yarn/sdks/prettier/index.js | 30 ++++++ .yarn/sdks/prettier/package.json | 6 ++ .yarn/sdks/typescript/bin/tsc | 20 ++++ .yarn/sdks/typescript/bin/tsserver | 20 ++++ .yarn/sdks/typescript/lib/tsc.js | 20 ++++ .yarn/sdks/typescript/lib/tsserver.js | 111 ++++++++++++++++++++++ .yarn/sdks/typescript/lib/typescript.js | 20 ++++ .yarn/sdks/typescript/package.json | 6 ++ 20 files changed, 302 insertions(+), 70 deletions(-) create mode 100644 .vscode/extensions.json delete mode 100644 .vscode/pnpify/eslint/lib/api.js delete mode 100644 .vscode/pnpify/eslint/package.json delete mode 100644 .vscode/pnpify/prettier/index.js delete mode 100644 .vscode/pnpify/prettier/package.json delete mode 100644 .vscode/pnpify/typescript/lib/tsserver.js delete mode 100644 .vscode/pnpify/typescript/package.json create mode 100755 .yarn/sdks/eslint/bin/eslint.js create mode 100644 .yarn/sdks/eslint/lib/api.js create mode 100644 .yarn/sdks/eslint/package.json create mode 100644 .yarn/sdks/integrations.yml create mode 100755 .yarn/sdks/prettier/index.js create mode 100644 .yarn/sdks/prettier/package.json create mode 100755 .yarn/sdks/typescript/bin/tsc create mode 100755 .yarn/sdks/typescript/bin/tsserver create mode 100644 .yarn/sdks/typescript/lib/tsc.js create mode 100644 .yarn/sdks/typescript/lib/tsserver.js create mode 100644 .yarn/sdks/typescript/lib/typescript.js create mode 100644 .yarn/sdks/typescript/package.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..daaa5ee --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "arcanis.vscode-zipfs", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode" + ] +} diff --git a/.vscode/pnpify/eslint/lib/api.js b/.vscode/pnpify/eslint/lib/api.js deleted file mode 100644 index 538327d..0000000 --- a/.vscode/pnpify/eslint/lib/api.js +++ /dev/null @@ -1,17 +0,0 @@ -const {createRequire, createRequireFromPath} = require(`module`); -const {dirname, resolve} = require(`path`); - -const relPnpApiPath = "../../../../.pnp.js"; - -const absPnpApiPath = resolve(__dirname, relPnpApiPath); -const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); - -// Setup the environment to be able to require eslint -require(absPnpApiPath).setup(); - -// Prepare the environment (to be ready in case of child_process.spawn etc) -process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``; -process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`; - -// Defer to the real eslint your application uses -module.exports = absRequire(`eslint`); diff --git a/.vscode/pnpify/eslint/package.json b/.vscode/pnpify/eslint/package.json deleted file mode 100644 index ffa475c..0000000 --- a/.vscode/pnpify/eslint/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "eslint", - "version": "6.8.0-pnpify", - "main": "lib/api.js" -} \ No newline at end of file diff --git a/.vscode/pnpify/prettier/index.js b/.vscode/pnpify/prettier/index.js deleted file mode 100644 index 24c19b6..0000000 --- a/.vscode/pnpify/prettier/index.js +++ /dev/null @@ -1,17 +0,0 @@ -const {createRequire, createRequireFromPath} = require(`module`); -const {dirname, resolve} = require(`path`); - -const relPnpApiPath = "../../../.pnp.js"; - -const absPnpApiPath = resolve(__dirname, relPnpApiPath); -const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); - -// Setup the environment to be able to require prettier -require(absPnpApiPath).setup(); - -// Prepare the environment (to be ready in case of child_process.spawn etc) -process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``; -process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`; - -// Defer to the real prettier your application uses -module.exports = absRequire(`prettier`); diff --git a/.vscode/pnpify/prettier/package.json b/.vscode/pnpify/prettier/package.json deleted file mode 100644 index 22d48ae..0000000 --- a/.vscode/pnpify/prettier/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "prettier", - "version": "1.19.1-pnpify", - "main": "index.js" -} \ No newline at end of file diff --git a/.vscode/pnpify/typescript/lib/tsserver.js b/.vscode/pnpify/typescript/lib/tsserver.js deleted file mode 100644 index 124eede..0000000 --- a/.vscode/pnpify/typescript/lib/tsserver.js +++ /dev/null @@ -1,17 +0,0 @@ -const {createRequire, createRequireFromPath} = require(`module`); -const {dirname, resolve} = require(`path`); - -const relPnpApiPath = "../../../../.pnp.js"; - -const absPnpApiPath = resolve(__dirname, relPnpApiPath); -const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); - -// Setup the environment to be able to require typescript/lib/tsserver -require(absPnpApiPath).setup(); - -// Prepare the environment (to be ready in case of child_process.spawn etc) -process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``; -process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`; - -// Defer to the real typescript/lib/tsserver your application uses -module.exports = absRequire(`typescript/lib/tsserver`); diff --git a/.vscode/pnpify/typescript/package.json b/.vscode/pnpify/typescript/package.json deleted file mode 100644 index 3b0298f..0000000 --- a/.vscode/pnpify/typescript/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "typescript", - "version": "3.7.5-pnpify" -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 335e514..f977784 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,10 +16,11 @@ "titleBar.inactiveForeground": "#e7e7e799", "statusBar.background": "#39698e", "statusBarItem.hoverBackground": "#4884b2", - "statusBar.foreground": "#e7e7e7" + "statusBar.foreground": "#e7e7e7", + "activityBar.activeBackground": "#4884b2" }, "peacock.color": "#39698e", - "typescript.tsdk": ".vscode/pnpify/typescript/lib", + "typescript.tsdk": ".yarn/sdks/typescript/lib", "eslint.alwaysShowStatus": true, "eslint.packageManager": "yarn", "eslint.validate": [ @@ -30,7 +31,12 @@ ], "tslint.packageManager": "yarn", "npm.packageManager": "yarn", - "eslint.nodePath": ".vscode/pnpify", - "prettier.prettierPath": ".vscode/pnpify/prettier", - "eslint.enable": true + "eslint.nodePath": ".yarn/sdks", + "prettier.prettierPath": ".yarn/sdks/prettier/index.js", + "eslint.enable": true, + "search.exclude": { + "**/.yarn": true, + "**/.pnp.*": true + }, + "typescript.enablePromptUseWorkspaceTsdk": true } diff --git a/.yarn/sdks/eslint/bin/eslint.js b/.yarn/sdks/eslint/bin/eslint.js new file mode 100755 index 0000000..4e7554d --- /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 0000000..ac3c9fc --- /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 0000000..d7d92db --- /dev/null +++ b/.yarn/sdks/eslint/package.json @@ -0,0 +1,6 @@ +{ + "name": "eslint", + "version": "7.15.0-pnpify", + "main": "./lib/api.js", + "type": "commonjs" +} diff --git a/.yarn/sdks/integrations.yml b/.yarn/sdks/integrations.yml new file mode 100644 index 0000000..76ed42b --- /dev/null +++ b/.yarn/sdks/integrations.yml @@ -0,0 +1,5 @@ +# This file is automatically generated by PnPify. +# Manual changes will be lost! + +integrations: + - vscode diff --git a/.yarn/sdks/prettier/index.js b/.yarn/sdks/prettier/index.js new file mode 100755 index 0000000..80134e1 --- /dev/null +++ b/.yarn/sdks/prettier/index.js @@ -0,0 +1,30 @@ +#!/usr/bin/env node + +const {existsSync} = require(`fs`); +const {createRequire, createRequireFromPath} = require(`module`); +const {resolve, dirname} = 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 prettier/index.js + require(absPnpApiPath).setup(); + } + + const pnpifyResolution = require.resolve(`@yarnpkg/pnpify`, {paths: [dirname(absPnpApiPath)]}); + if (typeof global[`__yarnpkg_sdk_is_using_pnpify__`] === `undefined`) { + Object.defineProperty(global, `__yarnpkg_sdk_is_using_pnpify__`, {configurable: true, value: true}); + + process.env.NODE_OPTIONS += ` -r ${pnpifyResolution}`; + + // Apply PnPify to the current process + absRequire(pnpifyResolution).patchFs(); + } +} + +// Defer to the real prettier/index.js your application uses +module.exports = absRequire(`prettier/index.js`); diff --git a/.yarn/sdks/prettier/package.json b/.yarn/sdks/prettier/package.json new file mode 100644 index 0000000..adf3389 --- /dev/null +++ b/.yarn/sdks/prettier/package.json @@ -0,0 +1,6 @@ +{ + "name": "prettier", + "version": "2.2.1-pnpify", + "main": "./index.js", + "type": "commonjs" +} diff --git a/.yarn/sdks/typescript/bin/tsc b/.yarn/sdks/typescript/bin/tsc new file mode 100755 index 0000000..06e51d0 --- /dev/null +++ b/.yarn/sdks/typescript/bin/tsc @@ -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 typescript/bin/tsc + require(absPnpApiPath).setup(); + } +} + +// Defer to the real typescript/bin/tsc your application uses +module.exports = absRequire(`typescript/bin/tsc`); diff --git a/.yarn/sdks/typescript/bin/tsserver b/.yarn/sdks/typescript/bin/tsserver new file mode 100755 index 0000000..2d03f3d --- /dev/null +++ b/.yarn/sdks/typescript/bin/tsserver @@ -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 typescript/bin/tsserver + require(absPnpApiPath).setup(); + } +} + +// Defer to the real typescript/bin/tsserver your application uses +module.exports = absRequire(`typescript/bin/tsserver`); diff --git a/.yarn/sdks/typescript/lib/tsc.js b/.yarn/sdks/typescript/lib/tsc.js new file mode 100644 index 0000000..e030711 --- /dev/null +++ b/.yarn/sdks/typescript/lib/tsc.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 typescript/lib/tsc.js + require(absPnpApiPath).setup(); + } +} + +// Defer to the real typescript/lib/tsc.js your application uses +module.exports = absRequire(`typescript/lib/tsc.js`); diff --git a/.yarn/sdks/typescript/lib/tsserver.js b/.yarn/sdks/typescript/lib/tsserver.js new file mode 100644 index 0000000..1d6dfb6 --- /dev/null +++ b/.yarn/sdks/typescript/lib/tsserver.js @@ -0,0 +1,111 @@ +#!/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); + +const moduleWrapper = tsserver => { + const {isAbsolute} = require(`path`); + const pnpApi = require(`pnpapi`); + + const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => { + return `${locator.name}@${locator.reference}`; + })); + + // VSCode sends the zip paths to TS using the "zip://" prefix, that TS + // doesn't understand. This layer makes sure to remove the protocol + // before forwarding it to TS, and to add it back on all returned paths. + + 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\//))) { + // We also take the opportunity to turn virtual paths into physical ones; + // this makes is 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. + // + // We only do this to modules owned by the the dependency tree roots. + // This avoids breaking the resolution when jumping inside a vendor + // with peer dep (otherwise jumping into react-dom would show resolution + // errors on react). + // + const resolved = pnpApi.resolveVirtual(str); + if (resolved) { + const locator = pnpApi.findPackageLocator(resolved); + if (locator && dependencyTreeRoots.has(`${locator.name}@${locator.reference}`)) { + str = resolved; + } + } + + str = str.replace(/\\/g, `/`) + str = str.replace(/^\/?/, `/`); + + // 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}`; + } + } + + return str; + } + + function fromEditorPath(str) { + return process.platform === `win32` + ? str.replace(/^\^?zip:\//, ``) + : str.replace(/^\^?zip:/, ``); + } + + // And here is the point where we hijack the VSCode <-> TS communications + // by adding ourselves in the middle. We locate everything that looks + // like an absolute path of ours and normalize it. + + const Session = tsserver.server.Session; + const {onMessage: originalOnMessage, send: originalSend} = Session.prototype; + let isVSCode = false; + + return Object.assign(Session.prototype, { + onMessage(/** @type {string} */ message) { + const parsedMessage = JSON.parse(message) + + if ( + parsedMessage != null && + typeof parsedMessage === `object` && + parsedMessage.arguments && + parsedMessage.arguments.hostInfo === `vscode` + ) { + isVSCode = true; + } + + return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => { + return typeof value === `string` ? fromEditorPath(value) : value; + })); + }, + + send(/** @type {any} */ msg) { + return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => { + return typeof value === `string` ? toEditorPath(value) : value; + }))); + } + }); +}; + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require typescript/lib/tsserver.js + require(absPnpApiPath).setup(); + } +} + +// Defer to the real typescript/lib/tsserver.js your application uses +module.exports = moduleWrapper(absRequire(`typescript/lib/tsserver.js`)); diff --git a/.yarn/sdks/typescript/lib/typescript.js b/.yarn/sdks/typescript/lib/typescript.js new file mode 100644 index 0000000..7e3c852 --- /dev/null +++ b/.yarn/sdks/typescript/lib/typescript.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 typescript/lib/typescript.js + require(absPnpApiPath).setup(); + } +} + +// Defer to the real typescript/lib/typescript.js your application uses +module.exports = absRequire(`typescript/lib/typescript.js`); diff --git a/.yarn/sdks/typescript/package.json b/.yarn/sdks/typescript/package.json new file mode 100644 index 0000000..69b595c --- /dev/null +++ b/.yarn/sdks/typescript/package.json @@ -0,0 +1,6 @@ +{ + "name": "typescript", + "version": "4.1.3-pnpify", + "main": "./lib/typescript.js", + "type": "commonjs" +}