From 0da26e5f986de5044a151813f7b0b58f3a821579 Mon Sep 17 00:00:00 2001 From: Nikita Elfimov Date: Tue, 17 Sep 2024 10:44:40 +0300 Subject: [PATCH] feat(react-upload): bump major (#146) --- .pnp.cjs | 80 +++++- .yarn/sdks/integrations.yml | 3 + .yarn/sdks/typescript/bin/tsc | 32 +++ .yarn/sdks/typescript/bin/tsserver | 32 +++ .yarn/sdks/typescript/lib/tsc.js | 32 +++ .yarn/sdks/typescript/lib/tsserver.js | 248 +++++++++++++++++++ .yarn/sdks/typescript/lib/tsserverlibrary.js | 248 +++++++++++++++++++ .yarn/sdks/typescript/lib/typescript.js | 32 +++ .yarn/sdks/typescript/package.json | 10 + packages/upload/package.json | 6 +- packages/upload/src/use-upload.hook.ts | 4 +- yarn.lock | 6 +- 12 files changed, 720 insertions(+), 13 deletions(-) create mode 100644 .yarn/sdks/integrations.yml 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/tsserverlibrary.js create mode 100644 .yarn/sdks/typescript/lib/typescript.js create mode 100644 .yarn/sdks/typescript/package.json diff --git a/.pnp.cjs b/.pnp.cjs index f4d2f81..839b518 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -463,14 +463,14 @@ const RAW_RUNTIME_STATE = "packageDependencies": [\ ["@atls/react-app-links", "virtual:f42b2d1fb02c9471007010ce5032a9d9bf4a9d4954fafbd9bf7342584f7439488d7209d786d2fde08fa973a76de656e34d46b85e283e9a040cb26c73ec051e33#workspace:packages/app-links"],\ ["@testing-library/jest-dom", "npm:5.17.0"],\ - ["@testing-library/react", "virtual:0f253325d64667267f8a5c1074e4aa2f59120ad20372d39bddcfd3951915b9b89e0bfaf1fa90999b4185ff651ab603643a0d5aca289d2a340e670217b32db551#npm:12.1.5"],\ - ["@testing-library/react-hooks", "virtual:0f253325d64667267f8a5c1074e4aa2f59120ad20372d39bddcfd3951915b9b89e0bfaf1fa90999b4185ff651ab603643a0d5aca289d2a340e670217b32db551#npm:7.0.2"],\ + ["@testing-library/react", "virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:12.1.5"],\ + ["@testing-library/react-hooks", "virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:7.0.2"],\ ["@types/react", "npm:18.3.6"],\ ["@types/react-dom", "npm:18.2.7"],\ ["@types/testing-library__jest-dom", "npm:5.14.9"],\ ["@types/tldjs", "npm:2.3.4"],\ - ["react", "npm:18.3.1"],\ - ["react-dom", "virtual:0f253325d64667267f8a5c1074e4aa2f59120ad20372d39bddcfd3951915b9b89e0bfaf1fa90999b4185ff651ab603643a0d5aca289d2a340e670217b32db551#npm:18.3.1"],\ + ["react", "npm:18.2.0"],\ + ["react-dom", "virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:18.3.1"],\ ["tldjs", "npm:2.3.1"]\ ],\ "packagePeers": [\ @@ -557,7 +557,7 @@ const RAW_RUNTIME_STATE = ["@types/react", "npm:18.3.6"],\ ["graphql", "npm:16.9.0"],\ ["graphql-request", "virtual:f42b2d1fb02c9471007010ce5032a9d9bf4a9d4954fafbd9bf7342584f7439488d7209d786d2fde08fa973a76de656e34d46b85e283e9a040cb26c73ec051e33#npm:4.3.0"],\ - ["react", "npm:18.3.1"]\ + ["react", "npm:18.2.0"]\ ],\ "linkType": "SOFT"\ }]\ @@ -3105,6 +3105,25 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:12.1.5", {\ + "packageLocation": "./.yarn/__virtual__/@testing-library-react-virtual-792896f736/2/.yarn/berry/cache/@testing-library-react-npm-12.1.5-745f86e555-10.zip/node_modules/@testing-library/react/",\ + "packageDependencies": [\ + ["@testing-library/react", "virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:12.1.5"],\ + ["@babel/runtime", "npm:7.25.6"],\ + ["@testing-library/dom", "npm:8.20.1"],\ + ["@types/react", "npm:18.3.6"],\ + ["@types/react-dom", "npm:18.2.7"],\ + ["react", "npm:18.2.0"],\ + ["react-dom", "virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:18.3.1"]\ + ],\ + "packagePeers": [\ + "@types/react-dom",\ + "@types/react",\ + "react-dom",\ + "react"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:3c6684a2a71ebfee624a1a07e386044939c871ad84e4f3de0a9680f3e06cb110c72bd84362a38fe0ae70f01c0f8564a8682422c054b9abc39706979b46282127#npm:12.1.5", {\ "packageLocation": "./.yarn/__virtual__/@testing-library-react-virtual-58bee1418b/2/.yarn/berry/cache/@testing-library-react-npm-12.1.5-745f86e555-10.zip/node_modules/@testing-library/react/",\ "packageDependencies": [\ @@ -3174,6 +3193,28 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:7.0.2", {\ + "packageLocation": "./.yarn/__virtual__/@testing-library-react-hooks-virtual-4a4b5a428d/2/.yarn/berry/cache/@testing-library-react-hooks-npm-7.0.2-da146b13d2-10.zip/node_modules/@testing-library/react-hooks/",\ + "packageDependencies": [\ + ["@testing-library/react-hooks", "virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:7.0.2"],\ + ["@babel/runtime", "npm:7.25.6"],\ + ["@types/react", "npm:18.3.6"],\ + ["@types/react-dom", "npm:18.2.7"],\ + ["@types/react-test-renderer", "npm:18.3.0"],\ + ["react", "npm:18.2.0"],\ + ["react-dom", "virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:18.3.1"],\ + ["react-error-boundary", "virtual:4a4b5a428d431c72b23b0ad728593a99bffda1dbce4ffc7e951c001c5da6e14e3429f1323b8ad22a82159e2012bb419a2d376dd71a024e9d5501207d06c7debb#npm:3.1.4"],\ + ["react-test-renderer", null]\ + ],\ + "packagePeers": [\ + "@types/react-dom",\ + "@types/react",\ + "react-dom",\ + "react-test-renderer",\ + "react"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:3c6684a2a71ebfee624a1a07e386044939c871ad84e4f3de0a9680f3e06cb110c72bd84362a38fe0ae70f01c0f8564a8682422c054b9abc39706979b46282127#npm:7.0.2", {\ "packageLocation": "./.yarn/__virtual__/@testing-library-react-hooks-virtual-7d64c28e32/2/.yarn/berry/cache/@testing-library-react-hooks-npm-7.0.2-da146b13d2-10.zip/node_modules/@testing-library/react-hooks/",\ "packageDependencies": [\ @@ -8844,6 +8885,21 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:18.3.1", {\ + "packageLocation": "./.yarn/__virtual__/react-dom-virtual-5b93037960/2/.yarn/berry/cache/react-dom-npm-18.3.1-a805663f38-10.zip/node_modules/react-dom/",\ + "packageDependencies": [\ + ["react-dom", "virtual:3b4c41533957ac07ce7909942d6eb1983a4ae99a72893875f6cb85c4b4b62ddf0e9f905474da9933d87eb08b7702af2a68d989aa1e4a887f00080895660386b5#npm:18.3.1"],\ + ["@types/react", "npm:18.3.6"],\ + ["loose-envify", "npm:1.4.0"],\ + ["react", "npm:18.2.0"],\ + ["scheduler", "npm:0.23.2"]\ + ],\ + "packagePeers": [\ + "@types/react",\ + "react"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:5df5417e007cf624295c3dfc9c18b541c8f15fbbead2fcd958b8514a53e86ee6c640495d53e378a3d48c5ae0b86482593ca5c241f44dea6b3f5eb1e38d547d43#npm:18.2.0", {\ "packageLocation": "./.yarn/__virtual__/react-dom-virtual-eb9a547ed4/2/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-10.zip/node_modules/react-dom/",\ "packageDependencies": [\ @@ -8868,6 +8924,20 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "SOFT"\ }],\ + ["virtual:4a4b5a428d431c72b23b0ad728593a99bffda1dbce4ffc7e951c001c5da6e14e3429f1323b8ad22a82159e2012bb419a2d376dd71a024e9d5501207d06c7debb#npm:3.1.4", {\ + "packageLocation": "./.yarn/__virtual__/react-error-boundary-virtual-dc1f1a8cd0/2/.yarn/berry/cache/react-error-boundary-npm-3.1.4-2310dba89e-10.zip/node_modules/react-error-boundary/",\ + "packageDependencies": [\ + ["react-error-boundary", "virtual:4a4b5a428d431c72b23b0ad728593a99bffda1dbce4ffc7e951c001c5da6e14e3429f1323b8ad22a82159e2012bb419a2d376dd71a024e9d5501207d06c7debb#npm:3.1.4"],\ + ["@babel/runtime", "npm:7.25.6"],\ + ["@types/react", "npm:18.3.6"],\ + ["react", "npm:18.2.0"]\ + ],\ + "packagePeers": [\ + "@types/react",\ + "react"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:b9f935a2b8d5b3ae46e332467f483427f4a4f65c8ef3e0e5ee8313ed142da617569d7d032d499a5a2e9f42cda1daca9d991b26135e1270c732d9733d96f220ec#npm:3.1.4", {\ "packageLocation": "./.yarn/__virtual__/react-error-boundary-virtual-e7b6cfc512/2/.yarn/berry/cache/react-error-boundary-npm-3.1.4-2310dba89e-10.zip/node_modules/react-error-boundary/",\ "packageDependencies": [\ diff --git a/.yarn/sdks/integrations.yml b/.yarn/sdks/integrations.yml new file mode 100644 index 0000000..9301d83 --- /dev/null +++ b/.yarn/sdks/integrations.yml @@ -0,0 +1,3 @@ +# This file is automatically generated by @yarnpkg/sdks. +# Manual changes might be lost! + diff --git a/.yarn/sdks/typescript/bin/tsc b/.yarn/sdks/typescript/bin/tsc new file mode 100755 index 0000000..867a7bd --- /dev/null +++ b/.yarn/sdks/typescript/bin/tsc @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const {existsSync} = require(`fs`); +const {createRequire, register} = require(`module`); +const {resolve} = require(`path`); +const {pathToFileURL} = require(`url`); + +const relPnpApiPath = "../../../../.pnp.cjs"; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require typescript/bin/tsc + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real typescript/bin/tsc your application uses +module.exports = wrapWithUserWrapper(absRequire(`typescript/bin/tsc`)); diff --git a/.yarn/sdks/typescript/bin/tsserver b/.yarn/sdks/typescript/bin/tsserver new file mode 100755 index 0000000..3fc5aa3 --- /dev/null +++ b/.yarn/sdks/typescript/bin/tsserver @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const {existsSync} = require(`fs`); +const {createRequire, register} = require(`module`); +const {resolve} = require(`path`); +const {pathToFileURL} = require(`url`); + +const relPnpApiPath = "../../../../.pnp.cjs"; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require typescript/bin/tsserver + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real typescript/bin/tsserver your application uses +module.exports = wrapWithUserWrapper(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..da411bd --- /dev/null +++ b/.yarn/sdks/typescript/lib/tsc.js @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const {existsSync} = require(`fs`); +const {createRequire, register} = require(`module`); +const {resolve} = require(`path`); +const {pathToFileURL} = require(`url`); + +const relPnpApiPath = "../../../../.pnp.cjs"; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require typescript/lib/tsc.js + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real typescript/lib/tsc.js your application uses +module.exports = wrapWithUserWrapper(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..6249c46 --- /dev/null +++ b/.yarn/sdks/typescript/lib/tsserver.js @@ -0,0 +1,248 @@ +#!/usr/bin/env node + +const {existsSync} = require(`fs`); +const {createRequire, register} = require(`module`); +const {resolve} = require(`path`); +const {pathToFileURL} = require(`url`); + +const relPnpApiPath = "../../../../.pnp.cjs"; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require typescript/lib/tsserver.js + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +const moduleWrapper = exports => { + return wrapWithUserWrapper(moduleWrapperFn(exports)); +}; + +const moduleWrapperFn = tsserver => { + if (!process.versions.pnp) { + return tsserver; + } + + const {isAbsolute} = require(`path`); + const pnpApi = require(`pnpapi`); + + const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//); + const isPortal = str => str.startsWith("portal:/"); + const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`); + + 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:|\/zip\/)/) && (str.match(/\.zip\//) || isVirtual(str))) { + // We also take the opportunity to turn virtual paths into physical ones; + // 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. + // + // 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 = isVirtual(str) ? pnpApi.resolveVirtual(str) : str; + if (resolved) { + const locator = pnpApi.findPackageLocator(resolved); + if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) { + str = resolved; + } + } + + str = normalize(str); + + if (str.match(/\.zip\//)) { + 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 + // + // 2021-10-08: VSCode changed the format in 1.61. + // Before | ^zip:/c:/foo/bar.zip/package.json + // After | ^/zip//c:/foo/bar.zip/package.json + // + // 2022-04-06: VSCode changed the format in 1.66. + // Before | ^/zip//c:/foo/bar.zip/package.json + // After | ^/zip/c:/foo/bar.zip/package.json + // + // 2022-05-06: VSCode changed the format in 1.68 + // Before | ^/zip/c:/foo/bar.zip/package.json + // After | ^/zip//c:/foo/bar.zip/package.json + // + case `vscode <1.61`: { + str = `^zip:${str}`; + } break; + + case `vscode <1.66`: { + str = `^/zip/${str}`; + } break; + + case `vscode <1.68`: { + str = `^/zip${str}`; + } break; + + 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; + + // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server) + // We have to resolve the actual file system path from virtual path, + // everything else is up to neovim + case `neovim`: { + str = normalize(resolved).replace(/\.zip\//, `.zip::`); + str = `zipfile://${str}`; + } break; + + default: { + str = `zip:${str}`; + } break; + } + } else { + str = str.replace(/^\/?/, process.platform === `win32` ? `` : `/`); + } + } + + return str; + } + + function fromEditorPath(str) { + switch (hostInfo) { + case `coc-nvim`: { + str = str.replace(/\.zip::/, `.zip/`); + // The path for coc-nvim is in format of //zipfile://.yarn/... + // So in order to convert it back, we use .* to match all the thing + // before `zipfile:` + return process.platform === `win32` + ? str.replace(/^.*zipfile:\//, ``) + : str.replace(/^.*zipfile:/, ``); + } break; + + case `neovim`: { + str = str.replace(/\.zip::/, `.zip/`); + // The path for neovim is in format of zipfile:////.yarn/... + return str.replace(/^zipfile:\/\//, ``); + } break; + + case `vscode`: + default: { + return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`) + } break; + } + } + + // Force enable 'allowLocalPluginLoads' + // TypeScript tries to resolve plugins using a path relative to itself + // which doesn't work when using the global cache + // https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238 + // VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but + // TypeScript already does local loads and if this code is running the user trusts the workspace + // https://github.com/microsoft/vscode/issues/45856 + const ConfiguredProject = tsserver.server.ConfiguredProject; + const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype; + ConfiguredProject.prototype.enablePluginsWithOptions = function() { + this.projectService.allowLocalPluginLoads = true; + return originalEnablePluginsWithOptions.apply(this, arguments); + }; + + // 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 hostInfo = `unknown`; + + Object.assign(Session.prototype, { + onMessage(/** @type {string | object} */ message) { + const isStringMessage = typeof message === 'string'; + const parsedMessage = isStringMessage ? JSON.parse(message) : message; + + if ( + parsedMessage != null && + typeof parsedMessage === `object` && + parsedMessage.arguments && + typeof parsedMessage.arguments.hostInfo === `string` + ) { + hostInfo = parsedMessage.arguments.hostInfo; + if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) { + const [, major, minor] = (process.env.VSCODE_IPC_HOOK.match( + // The RegExp from https://semver.org/ but without the caret at the start + /(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-]+)*))?$/ + ) ?? []).map(Number) + + if (major === 1) { + if (minor < 61) { + hostInfo += ` <1.61`; + } else if (minor < 66) { + hostInfo += ` <1.66`; + } else if (minor < 68) { + hostInfo += ` <1.68`; + } + } + } + } + + const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => { + return typeof value === 'string' ? fromEditorPath(value) : value; + }); + + return originalOnMessage.call( + this, + isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON) + ); + }, + + send(/** @type {any} */ msg) { + return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => { + return typeof value === `string` ? toEditorPath(value) : value; + }))); + } + }); + + return tsserver; +}; + +const [major, minor] = absRequire(`typescript/package.json`).version.split(`.`, 2).map(value => parseInt(value, 10)); +// In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well. +// Ref https://github.com/microsoft/TypeScript/pull/55326 +if (major > 5 || (major === 5 && minor >= 5)) { + moduleWrapper(absRequire(`typescript`)); +} + +// 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/tsserverlibrary.js b/.yarn/sdks/typescript/lib/tsserverlibrary.js new file mode 100644 index 0000000..0e50e0a --- /dev/null +++ b/.yarn/sdks/typescript/lib/tsserverlibrary.js @@ -0,0 +1,248 @@ +#!/usr/bin/env node + +const {existsSync} = require(`fs`); +const {createRequire, register} = require(`module`); +const {resolve} = require(`path`); +const {pathToFileURL} = require(`url`); + +const relPnpApiPath = "../../../../.pnp.cjs"; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require typescript/lib/tsserverlibrary.js + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +const moduleWrapper = exports => { + return wrapWithUserWrapper(moduleWrapperFn(exports)); +}; + +const moduleWrapperFn = tsserver => { + if (!process.versions.pnp) { + return tsserver; + } + + const {isAbsolute} = require(`path`); + const pnpApi = require(`pnpapi`); + + const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//); + const isPortal = str => str.startsWith("portal:/"); + const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`); + + 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:|\/zip\/)/) && (str.match(/\.zip\//) || isVirtual(str))) { + // We also take the opportunity to turn virtual paths into physical ones; + // 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. + // + // 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 = isVirtual(str) ? pnpApi.resolveVirtual(str) : str; + if (resolved) { + const locator = pnpApi.findPackageLocator(resolved); + if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) { + str = resolved; + } + } + + str = normalize(str); + + if (str.match(/\.zip\//)) { + 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 + // + // 2021-10-08: VSCode changed the format in 1.61. + // Before | ^zip:/c:/foo/bar.zip/package.json + // After | ^/zip//c:/foo/bar.zip/package.json + // + // 2022-04-06: VSCode changed the format in 1.66. + // Before | ^/zip//c:/foo/bar.zip/package.json + // After | ^/zip/c:/foo/bar.zip/package.json + // + // 2022-05-06: VSCode changed the format in 1.68 + // Before | ^/zip/c:/foo/bar.zip/package.json + // After | ^/zip//c:/foo/bar.zip/package.json + // + case `vscode <1.61`: { + str = `^zip:${str}`; + } break; + + case `vscode <1.66`: { + str = `^/zip/${str}`; + } break; + + case `vscode <1.68`: { + str = `^/zip${str}`; + } break; + + 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; + + // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server) + // We have to resolve the actual file system path from virtual path, + // everything else is up to neovim + case `neovim`: { + str = normalize(resolved).replace(/\.zip\//, `.zip::`); + str = `zipfile://${str}`; + } break; + + default: { + str = `zip:${str}`; + } break; + } + } else { + str = str.replace(/^\/?/, process.platform === `win32` ? `` : `/`); + } + } + + return str; + } + + function fromEditorPath(str) { + switch (hostInfo) { + case `coc-nvim`: { + str = str.replace(/\.zip::/, `.zip/`); + // The path for coc-nvim is in format of //zipfile://.yarn/... + // So in order to convert it back, we use .* to match all the thing + // before `zipfile:` + return process.platform === `win32` + ? str.replace(/^.*zipfile:\//, ``) + : str.replace(/^.*zipfile:/, ``); + } break; + + case `neovim`: { + str = str.replace(/\.zip::/, `.zip/`); + // The path for neovim is in format of zipfile:////.yarn/... + return str.replace(/^zipfile:\/\//, ``); + } break; + + case `vscode`: + default: { + return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`) + } break; + } + } + + // Force enable 'allowLocalPluginLoads' + // TypeScript tries to resolve plugins using a path relative to itself + // which doesn't work when using the global cache + // https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238 + // VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but + // TypeScript already does local loads and if this code is running the user trusts the workspace + // https://github.com/microsoft/vscode/issues/45856 + const ConfiguredProject = tsserver.server.ConfiguredProject; + const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype; + ConfiguredProject.prototype.enablePluginsWithOptions = function() { + this.projectService.allowLocalPluginLoads = true; + return originalEnablePluginsWithOptions.apply(this, arguments); + }; + + // 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 hostInfo = `unknown`; + + Object.assign(Session.prototype, { + onMessage(/** @type {string | object} */ message) { + const isStringMessage = typeof message === 'string'; + const parsedMessage = isStringMessage ? JSON.parse(message) : message; + + if ( + parsedMessage != null && + typeof parsedMessage === `object` && + parsedMessage.arguments && + typeof parsedMessage.arguments.hostInfo === `string` + ) { + hostInfo = parsedMessage.arguments.hostInfo; + if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) { + const [, major, minor] = (process.env.VSCODE_IPC_HOOK.match( + // The RegExp from https://semver.org/ but without the caret at the start + /(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-]+)*))?$/ + ) ?? []).map(Number) + + if (major === 1) { + if (minor < 61) { + hostInfo += ` <1.61`; + } else if (minor < 66) { + hostInfo += ` <1.66`; + } else if (minor < 68) { + hostInfo += ` <1.68`; + } + } + } + } + + const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => { + return typeof value === 'string' ? fromEditorPath(value) : value; + }); + + return originalOnMessage.call( + this, + isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON) + ); + }, + + send(/** @type {any} */ msg) { + return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => { + return typeof value === `string` ? toEditorPath(value) : value; + }))); + } + }); + + return tsserver; +}; + +const [major, minor] = absRequire(`typescript/package.json`).version.split(`.`, 2).map(value => parseInt(value, 10)); +// In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well. +// Ref https://github.com/microsoft/TypeScript/pull/55326 +if (major > 5 || (major === 5 && minor >= 5)) { + moduleWrapper(absRequire(`typescript`)); +} + +// Defer to the real typescript/lib/tsserverlibrary.js your application uses +module.exports = moduleWrapper(absRequire(`typescript/lib/tsserverlibrary.js`)); diff --git a/.yarn/sdks/typescript/lib/typescript.js b/.yarn/sdks/typescript/lib/typescript.js new file mode 100644 index 0000000..7b6cc22 --- /dev/null +++ b/.yarn/sdks/typescript/lib/typescript.js @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const {existsSync} = require(`fs`); +const {createRequire, register} = require(`module`); +const {resolve} = require(`path`); +const {pathToFileURL} = require(`url`); + +const relPnpApiPath = "../../../../.pnp.cjs"; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require typescript + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real typescript your application uses +module.exports = wrapWithUserWrapper(absRequire(`typescript`)); diff --git a/.yarn/sdks/typescript/package.json b/.yarn/sdks/typescript/package.json new file mode 100644 index 0000000..9fede10 --- /dev/null +++ b/.yarn/sdks/typescript/package.json @@ -0,0 +1,10 @@ +{ + "name": "typescript", + "version": "5.4.2-sdk", + "main": "./lib/typescript.js", + "type": "commonjs", + "bin": { + "tsc": "./bin/tsc", + "tsserver": "./bin/tsserver" + } +} diff --git a/packages/upload/package.json b/packages/upload/package.json index 96da3d4..3f8b060 100644 --- a/packages/upload/package.json +++ b/packages/upload/package.json @@ -1,6 +1,6 @@ { "name": "@atls/react-upload", - "version": "0.1.0", + "version": "1.0.0", "license": "BSD-3-Clause", "main": "src/index.ts", "type": "module", @@ -13,13 +13,13 @@ "postpack": "rm -rf dist" }, "dependencies": { - "@atls/react-app-links": "workspace:0.0.2", + "@atls/react-app-links": "workspace:*", "graphql-request": "^4.0.0" }, "devDependencies": { "@types/react": "18.3.6", "graphql": "16.9.0", - "react": "^18.2.0" + "react": "18.2.0" }, "peerDependencies": { "graphql": "^16.3.0", diff --git a/packages/upload/src/use-upload.hook.ts b/packages/upload/src/use-upload.hook.ts index 01d8f38..80d7c89 100644 --- a/packages/upload/src/use-upload.hook.ts +++ b/packages/upload/src/use-upload.hook.ts @@ -4,7 +4,7 @@ import { useMemo } from 'react' import { useGatewayUrl } from './use-gateway-url.hook.js' -const uploadMutation = gql` +const uploadMutation = gql/* Graphql */` mutation CreateUpload($input: CreateUploadInput!) { createUpload(input: $input) { id @@ -12,7 +12,7 @@ const uploadMutation = gql` } } ` -const confirmMutation = gql` +const confirmMutation = gql/* Graphql */` mutation ConfirmUpload($input: ConfirmUploadInput!) { confirmUpload(input: $input) { id diff --git a/yarn.lock b/yarn.lock index 1f6bb99..f2b0276 100644 --- a/yarn.lock +++ b/yarn.lock @@ -219,7 +219,7 @@ __metadata: languageName: unknown linkType: soft -"@atls/react-app-links@workspace:0.0.2, @atls/react-app-links@workspace:packages/app-links": +"@atls/react-app-links@workspace:*, @atls/react-app-links@workspace:packages/app-links": version: 0.0.0-use.local resolution: "@atls/react-app-links@workspace:packages/app-links" dependencies: @@ -294,11 +294,11 @@ __metadata: version: 0.0.0-use.local resolution: "@atls/react-upload@workspace:packages/upload" dependencies: - "@atls/react-app-links": "workspace:0.0.2" + "@atls/react-app-links": "workspace:*" "@types/react": "npm:18.3.6" graphql: "npm:16.9.0" graphql-request: "npm:^4.0.0" - react: "npm:^18.2.0" + react: "npm:18.2.0" peerDependencies: graphql: ^16.3.0 react: ^18.2.0