diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-09-04 20:50:07 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-09-06 01:05:23 +0200 |
commit | cb65a28d2aaaf3f4305fd7308cd504903a833e5f (patch) | |
tree | 2bac0375fd42f6c3c606449c5fcee839f45ac1f4 | |
parent | feat(frontend): XState statecharts (diff) | |
download | refinery-cb65a28d2aaaf3f4305fd7308cd504903a833e5f.tar.gz refinery-cb65a28d2aaaf3f4305fd7308cd504903a833e5f.tar.zst refinery-cb65a28d2aaaf3f4305fd7308cd504903a833e5f.zip |
build(frontend): include TS SDK in repo
The recommended Codium extensions may be used to quickly get to
developing.
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | .vscode/extensions.json | 8 | ||||
-rw-r--r-- | .vscode/settings.json | 9 | ||||
-rw-r--r-- | .yarn/sdks/eslint/lib/api.js | 20 | ||||
-rw-r--r-- | .yarn/sdks/eslint/package.json | 6 | ||||
-rw-r--r-- | .yarn/sdks/integrations.yml | 5 | ||||
-rw-r--r-- | .yarn/sdks/typescript/lib/tsc.js | 20 | ||||
-rw-r--r-- | .yarn/sdks/typescript/lib/tsserver.js | 196 | ||||
-rw-r--r-- | .yarn/sdks/typescript/lib/tsserverlibrary.js | 196 | ||||
-rw-r--r-- | .yarn/sdks/typescript/lib/typescript.js | 20 | ||||
-rw-r--r-- | .yarn/sdks/typescript/package.json | 6 |
11 files changed, 487 insertions, 1 deletions
@@ -7,11 +7,11 @@ | |||
7 | .pnp.* | 7 | .pnp.* |
8 | .project | 8 | .project |
9 | .settings | 9 | .settings |
10 | .vscode/ | ||
11 | .yarn/* | 10 | .yarn/* |
12 | !.yarn/patches | 11 | !.yarn/patches |
13 | !.yarn/plugins | 12 | !.yarn/plugins |
14 | !.yarn/releases | 13 | !.yarn/releases |
14 | !.yarn/sdks | ||
15 | !.yarn/versions | 15 | !.yarn/versions |
16 | bin/ | 16 | bin/ |
17 | build/ | 17 | build/ |
diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..fa381855 --- /dev/null +++ b/.vscode/extensions.json | |||
@@ -0,0 +1,8 @@ | |||
1 | { | ||
2 | "recommendations": [ | ||
3 | "EditorConfig.EditorConfig", | ||
4 | "arcanis.vscode-zipfs", | ||
5 | "dbaeumer.vscode-eslint", | ||
6 | "statelyai.stately-vscode" | ||
7 | ] | ||
8 | } | ||
diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..66e5806b --- /dev/null +++ b/.vscode/settings.json | |||
@@ -0,0 +1,9 @@ | |||
1 | { | ||
2 | "search.exclude": { | ||
3 | "**/.yarn": true, | ||
4 | "**/.pnp.*": true | ||
5 | }, | ||
6 | "eslint.nodePath": ".yarn/sdks", | ||
7 | "typescript.tsdk": ".yarn/sdks/typescript/lib", | ||
8 | "typescript.enablePromptUseWorkspaceTsdk": true | ||
9 | } | ||
diff --git a/.yarn/sdks/eslint/lib/api.js b/.yarn/sdks/eslint/lib/api.js new file mode 100644 index 00000000..fc728d95 --- /dev/null +++ b/.yarn/sdks/eslint/lib/api.js | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/usr/bin/env node | ||
2 | |||
3 | const {existsSync} = require(`fs`); | ||
4 | const {createRequire, createRequireFromPath} = require(`module`); | ||
5 | const {resolve} = require(`path`); | ||
6 | |||
7 | const relPnpApiPath = "../../../../.pnp.cjs"; | ||
8 | |||
9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); | ||
10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); | ||
11 | |||
12 | if (existsSync(absPnpApiPath)) { | ||
13 | if (!process.versions.pnp) { | ||
14 | // Setup the environment to be able to require eslint | ||
15 | require(absPnpApiPath).setup(); | ||
16 | } | ||
17 | } | ||
18 | |||
19 | // Defer to the real eslint your application uses | ||
20 | module.exports = absRequire(`eslint`); | ||
diff --git a/.yarn/sdks/eslint/package.json b/.yarn/sdks/eslint/package.json new file mode 100644 index 00000000..c2abd332 --- /dev/null +++ b/.yarn/sdks/eslint/package.json | |||
@@ -0,0 +1,6 @@ | |||
1 | { | ||
2 | "name": "eslint", | ||
3 | "version": "8.23.0-sdk", | ||
4 | "main": "./lib/api.js", | ||
5 | "type": "commonjs" | ||
6 | } | ||
diff --git a/.yarn/sdks/integrations.yml b/.yarn/sdks/integrations.yml new file mode 100644 index 00000000..aa9d0d0a --- /dev/null +++ b/.yarn/sdks/integrations.yml | |||
@@ -0,0 +1,5 @@ | |||
1 | # This file is automatically generated by @yarnpkg/sdks. | ||
2 | # Manual changes might be lost! | ||
3 | |||
4 | integrations: | ||
5 | - vscode | ||
diff --git a/.yarn/sdks/typescript/lib/tsc.js b/.yarn/sdks/typescript/lib/tsc.js new file mode 100644 index 00000000..16042d01 --- /dev/null +++ b/.yarn/sdks/typescript/lib/tsc.js | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/usr/bin/env node | ||
2 | |||
3 | const {existsSync} = require(`fs`); | ||
4 | const {createRequire, createRequireFromPath} = require(`module`); | ||
5 | const {resolve} = require(`path`); | ||
6 | |||
7 | const relPnpApiPath = "../../../../.pnp.cjs"; | ||
8 | |||
9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); | ||
10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); | ||
11 | |||
12 | if (existsSync(absPnpApiPath)) { | ||
13 | if (!process.versions.pnp) { | ||
14 | // Setup the environment to be able to require typescript/lib/tsc.js | ||
15 | require(absPnpApiPath).setup(); | ||
16 | } | ||
17 | } | ||
18 | |||
19 | // Defer to the real typescript/lib/tsc.js your application uses | ||
20 | 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 00000000..a82ef796 --- /dev/null +++ b/.yarn/sdks/typescript/lib/tsserver.js | |||
@@ -0,0 +1,196 @@ | |||
1 | #!/usr/bin/env node | ||
2 | |||
3 | const {existsSync} = require(`fs`); | ||
4 | const {createRequire, createRequireFromPath} = require(`module`); | ||
5 | const {resolve} = require(`path`); | ||
6 | |||
7 | const relPnpApiPath = "../../../../.pnp.cjs"; | ||
8 | |||
9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); | ||
10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); | ||
11 | |||
12 | const moduleWrapper = tsserver => { | ||
13 | if (!process.versions.pnp) { | ||
14 | return tsserver; | ||
15 | } | ||
16 | |||
17 | const {isAbsolute} = require(`path`); | ||
18 | const pnpApi = require(`pnpapi`); | ||
19 | |||
20 | const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//); | ||
21 | const isPortal = str => str.startsWith("portal:/"); | ||
22 | const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`); | ||
23 | |||
24 | const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => { | ||
25 | return `${locator.name}@${locator.reference}`; | ||
26 | })); | ||
27 | |||
28 | // VSCode sends the zip paths to TS using the "zip://" prefix, that TS | ||
29 | // doesn't understand. This layer makes sure to remove the protocol | ||
30 | // before forwarding it to TS, and to add it back on all returned paths. | ||
31 | |||
32 | function toEditorPath(str) { | ||
33 | // We add the `zip:` prefix to both `.zip/` paths and virtual paths | ||
34 | if (isAbsolute(str) && !str.match(/^\^?(zip:|\/zip\/)/) && (str.match(/\.zip\//) || isVirtual(str))) { | ||
35 | // We also take the opportunity to turn virtual paths into physical ones; | ||
36 | // this makes it much easier to work with workspaces that list peer | ||
37 | // dependencies, since otherwise Ctrl+Click would bring us to the virtual | ||
38 | // file instances instead of the real ones. | ||
39 | // | ||
40 | // We only do this to modules owned by the the dependency tree roots. | ||
41 | // This avoids breaking the resolution when jumping inside a vendor | ||
42 | // with peer dep (otherwise jumping into react-dom would show resolution | ||
43 | // errors on react). | ||
44 | // | ||
45 | const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str; | ||
46 | if (resolved) { | ||
47 | const locator = pnpApi.findPackageLocator(resolved); | ||
48 | if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) { | ||
49 | str = resolved; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | str = normalize(str); | ||
54 | |||
55 | if (str.match(/\.zip\//)) { | ||
56 | switch (hostInfo) { | ||
57 | // Absolute VSCode `Uri.fsPath`s need to start with a slash. | ||
58 | // VSCode only adds it automatically for supported schemes, | ||
59 | // so we have to do it manually for the `zip` scheme. | ||
60 | // The path needs to start with a caret otherwise VSCode doesn't handle the protocol | ||
61 | // | ||
62 | // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910 | ||
63 | // | ||
64 | // Update Oct 8 2021: VSCode changed their format in 1.61. | ||
65 | // Before | ^zip:/c:/foo/bar.zip/package.json | ||
66 | // After | ^/zip//c:/foo/bar.zip/package.json | ||
67 | // | ||
68 | case `vscode <1.61`: { | ||
69 | str = `^zip:${str}`; | ||
70 | } break; | ||
71 | |||
72 | case `vscode`: { | ||
73 | str = `^/zip/${str}`; | ||
74 | } break; | ||
75 | |||
76 | // To make "go to definition" work, | ||
77 | // We have to resolve the actual file system path from virtual path | ||
78 | // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip) | ||
79 | case `coc-nvim`: { | ||
80 | str = normalize(resolved).replace(/\.zip\//, `.zip::`); | ||
81 | str = resolve(`zipfile:${str}`); | ||
82 | } break; | ||
83 | |||
84 | // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server) | ||
85 | // We have to resolve the actual file system path from virtual path, | ||
86 | // everything else is up to neovim | ||
87 | case `neovim`: { | ||
88 | str = normalize(resolved).replace(/\.zip\//, `.zip::`); | ||
89 | str = `zipfile://${str}`; | ||
90 | } break; | ||
91 | |||
92 | default: { | ||
93 | str = `zip:${str}`; | ||
94 | } break; | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | |||
99 | return str; | ||
100 | } | ||
101 | |||
102 | function fromEditorPath(str) { | ||
103 | switch (hostInfo) { | ||
104 | case `coc-nvim`: { | ||
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 `neovim`: { | ||
115 | str = str.replace(/\.zip::/, `.zip/`); | ||
116 | // The path for neovim is in format of zipfile:///<pwd>/.yarn/... | ||
117 | return str.replace(/^zipfile:\/\//, ``); | ||
118 | } break; | ||
119 | |||
120 | case `vscode`: | ||
121 | default: { | ||
122 | return process.platform === `win32` | ||
123 | ? str.replace(/^\^?(zip:|\/zip)\/+/, ``) | ||
124 | : str.replace(/^\^?(zip:|\/zip)\/+/, `/`); | ||
125 | } break; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | // Force enable 'allowLocalPluginLoads' | ||
130 | // TypeScript tries to resolve plugins using a path relative to itself | ||
131 | // which doesn't work when using the global cache | ||
132 | // https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238 | ||
133 | // VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but | ||
134 | // TypeScript already does local loads and if this code is running the user trusts the workspace | ||
135 | // https://github.com/microsoft/vscode/issues/45856 | ||
136 | const ConfiguredProject = tsserver.server.ConfiguredProject; | ||
137 | const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype; | ||
138 | ConfiguredProject.prototype.enablePluginsWithOptions = function() { | ||
139 | this.projectService.allowLocalPluginLoads = true; | ||
140 | return originalEnablePluginsWithOptions.apply(this, arguments); | ||
141 | }; | ||
142 | |||
143 | // And here is the point where we hijack the VSCode <-> TS communications | ||
144 | // by adding ourselves in the middle. We locate everything that looks | ||
145 | // like an absolute path of ours and normalize it. | ||
146 | |||
147 | const Session = tsserver.server.Session; | ||
148 | const {onMessage: originalOnMessage, send: originalSend} = Session.prototype; | ||
149 | let hostInfo = `unknown`; | ||
150 | |||
151 | Object.assign(Session.prototype, { | ||
152 | onMessage(/** @type {string | object} */ message) { | ||
153 | const isStringMessage = typeof message === 'string'; | ||
154 | const parsedMessage = isStringMessage ? JSON.parse(message) : message; | ||
155 | |||
156 | if ( | ||
157 | parsedMessage != null && | ||
158 | typeof parsedMessage === `object` && | ||
159 | parsedMessage.arguments && | ||
160 | typeof parsedMessage.arguments.hostInfo === `string` | ||
161 | ) { | ||
162 | hostInfo = parsedMessage.arguments.hostInfo; | ||
163 | if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK && process.env.VSCODE_IPC_HOOK.match(/Code\/1\.([1-5][0-9]|60)\./)) { | ||
164 | hostInfo += ` <1.61`; | ||
165 | } | ||
166 | } | ||
167 | |||
168 | const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => { | ||
169 | return typeof value === 'string' ? fromEditorPath(value) : value; | ||
170 | }); | ||
171 | |||
172 | return originalOnMessage.call( | ||
173 | this, | ||
174 | isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON) | ||
175 | ); | ||
176 | }, | ||
177 | |||
178 | send(/** @type {any} */ msg) { | ||
179 | return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => { | ||
180 | return typeof value === `string` ? toEditorPath(value) : value; | ||
181 | }))); | ||
182 | } | ||
183 | }); | ||
184 | |||
185 | return tsserver; | ||
186 | }; | ||
187 | |||
188 | if (existsSync(absPnpApiPath)) { | ||
189 | if (!process.versions.pnp) { | ||
190 | // Setup the environment to be able to require typescript/lib/tsserver.js | ||
191 | require(absPnpApiPath).setup(); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | // Defer to the real typescript/lib/tsserver.js your application uses | ||
196 | 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 00000000..0d70146a --- /dev/null +++ b/.yarn/sdks/typescript/lib/tsserverlibrary.js | |||
@@ -0,0 +1,196 @@ | |||
1 | #!/usr/bin/env node | ||
2 | |||
3 | const {existsSync} = require(`fs`); | ||
4 | const {createRequire, createRequireFromPath} = require(`module`); | ||
5 | const {resolve} = require(`path`); | ||
6 | |||
7 | const relPnpApiPath = "../../../../.pnp.cjs"; | ||
8 | |||
9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); | ||
10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); | ||
11 | |||
12 | const moduleWrapper = tsserver => { | ||
13 | if (!process.versions.pnp) { | ||
14 | return tsserver; | ||
15 | } | ||
16 | |||
17 | const {isAbsolute} = require(`path`); | ||
18 | const pnpApi = require(`pnpapi`); | ||
19 | |||
20 | const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//); | ||
21 | const isPortal = str => str.startsWith("portal:/"); | ||
22 | const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`); | ||
23 | |||
24 | const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => { | ||
25 | return `${locator.name}@${locator.reference}`; | ||
26 | })); | ||
27 | |||
28 | // VSCode sends the zip paths to TS using the "zip://" prefix, that TS | ||
29 | // doesn't understand. This layer makes sure to remove the protocol | ||
30 | // before forwarding it to TS, and to add it back on all returned paths. | ||
31 | |||
32 | function toEditorPath(str) { | ||
33 | // We add the `zip:` prefix to both `.zip/` paths and virtual paths | ||
34 | if (isAbsolute(str) && !str.match(/^\^?(zip:|\/zip\/)/) && (str.match(/\.zip\//) || isVirtual(str))) { | ||
35 | // We also take the opportunity to turn virtual paths into physical ones; | ||
36 | // this makes it much easier to work with workspaces that list peer | ||
37 | // dependencies, since otherwise Ctrl+Click would bring us to the virtual | ||
38 | // file instances instead of the real ones. | ||
39 | // | ||
40 | // We only do this to modules owned by the the dependency tree roots. | ||
41 | // This avoids breaking the resolution when jumping inside a vendor | ||
42 | // with peer dep (otherwise jumping into react-dom would show resolution | ||
43 | // errors on react). | ||
44 | // | ||
45 | const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str; | ||
46 | if (resolved) { | ||
47 | const locator = pnpApi.findPackageLocator(resolved); | ||
48 | if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) { | ||
49 | str = resolved; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | str = normalize(str); | ||
54 | |||
55 | if (str.match(/\.zip\//)) { | ||
56 | switch (hostInfo) { | ||
57 | // Absolute VSCode `Uri.fsPath`s need to start with a slash. | ||
58 | // VSCode only adds it automatically for supported schemes, | ||
59 | // so we have to do it manually for the `zip` scheme. | ||
60 | // The path needs to start with a caret otherwise VSCode doesn't handle the protocol | ||
61 | // | ||
62 | // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910 | ||
63 | // | ||
64 | // Update Oct 8 2021: VSCode changed their format in 1.61. | ||
65 | // Before | ^zip:/c:/foo/bar.zip/package.json | ||
66 | // After | ^/zip//c:/foo/bar.zip/package.json | ||
67 | // | ||
68 | case `vscode <1.61`: { | ||
69 | str = `^zip:${str}`; | ||
70 | } break; | ||
71 | |||
72 | case `vscode`: { | ||
73 | str = `^/zip/${str}`; | ||
74 | } break; | ||
75 | |||
76 | // To make "go to definition" work, | ||
77 | // We have to resolve the actual file system path from virtual path | ||
78 | // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip) | ||
79 | case `coc-nvim`: { | ||
80 | str = normalize(resolved).replace(/\.zip\//, `.zip::`); | ||
81 | str = resolve(`zipfile:${str}`); | ||
82 | } break; | ||
83 | |||
84 | // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server) | ||
85 | // We have to resolve the actual file system path from virtual path, | ||
86 | // everything else is up to neovim | ||
87 | case `neovim`: { | ||
88 | str = normalize(resolved).replace(/\.zip\//, `.zip::`); | ||
89 | str = `zipfile://${str}`; | ||
90 | } break; | ||
91 | |||
92 | default: { | ||
93 | str = `zip:${str}`; | ||
94 | } break; | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | |||
99 | return str; | ||
100 | } | ||
101 | |||
102 | function fromEditorPath(str) { | ||
103 | switch (hostInfo) { | ||
104 | case `coc-nvim`: { | ||
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 `neovim`: { | ||
115 | str = str.replace(/\.zip::/, `.zip/`); | ||
116 | // The path for neovim is in format of zipfile:///<pwd>/.yarn/... | ||
117 | return str.replace(/^zipfile:\/\//, ``); | ||
118 | } break; | ||
119 | |||
120 | case `vscode`: | ||
121 | default: { | ||
122 | return process.platform === `win32` | ||
123 | ? str.replace(/^\^?(zip:|\/zip)\/+/, ``) | ||
124 | : str.replace(/^\^?(zip:|\/zip)\/+/, `/`); | ||
125 | } break; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | // Force enable 'allowLocalPluginLoads' | ||
130 | // TypeScript tries to resolve plugins using a path relative to itself | ||
131 | // which doesn't work when using the global cache | ||
132 | // https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238 | ||
133 | // VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but | ||
134 | // TypeScript already does local loads and if this code is running the user trusts the workspace | ||
135 | // https://github.com/microsoft/vscode/issues/45856 | ||
136 | const ConfiguredProject = tsserver.server.ConfiguredProject; | ||
137 | const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype; | ||
138 | ConfiguredProject.prototype.enablePluginsWithOptions = function() { | ||
139 | this.projectService.allowLocalPluginLoads = true; | ||
140 | return originalEnablePluginsWithOptions.apply(this, arguments); | ||
141 | }; | ||
142 | |||
143 | // And here is the point where we hijack the VSCode <-> TS communications | ||
144 | // by adding ourselves in the middle. We locate everything that looks | ||
145 | // like an absolute path of ours and normalize it. | ||
146 | |||
147 | const Session = tsserver.server.Session; | ||
148 | const {onMessage: originalOnMessage, send: originalSend} = Session.prototype; | ||
149 | let hostInfo = `unknown`; | ||
150 | |||
151 | Object.assign(Session.prototype, { | ||
152 | onMessage(/** @type {string | object} */ message) { | ||
153 | const isStringMessage = typeof message === 'string'; | ||
154 | const parsedMessage = isStringMessage ? JSON.parse(message) : message; | ||
155 | |||
156 | if ( | ||
157 | parsedMessage != null && | ||
158 | typeof parsedMessage === `object` && | ||
159 | parsedMessage.arguments && | ||
160 | typeof parsedMessage.arguments.hostInfo === `string` | ||
161 | ) { | ||
162 | hostInfo = parsedMessage.arguments.hostInfo; | ||
163 | if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK && process.env.VSCODE_IPC_HOOK.match(/Code\/1\.([1-5][0-9]|60)\./)) { | ||
164 | hostInfo += ` <1.61`; | ||
165 | } | ||
166 | } | ||
167 | |||
168 | const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => { | ||
169 | return typeof value === 'string' ? fromEditorPath(value) : value; | ||
170 | }); | ||
171 | |||
172 | return originalOnMessage.call( | ||
173 | this, | ||
174 | isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON) | ||
175 | ); | ||
176 | }, | ||
177 | |||
178 | send(/** @type {any} */ msg) { | ||
179 | return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => { | ||
180 | return typeof value === `string` ? toEditorPath(value) : value; | ||
181 | }))); | ||
182 | } | ||
183 | }); | ||
184 | |||
185 | return tsserver; | ||
186 | }; | ||
187 | |||
188 | if (existsSync(absPnpApiPath)) { | ||
189 | if (!process.versions.pnp) { | ||
190 | // Setup the environment to be able to require typescript/lib/tsserverlibrary.js | ||
191 | require(absPnpApiPath).setup(); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | // Defer to the real typescript/lib/tsserverlibrary.js your application uses | ||
196 | 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 00000000..cbdbf150 --- /dev/null +++ b/.yarn/sdks/typescript/lib/typescript.js | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/usr/bin/env node | ||
2 | |||
3 | const {existsSync} = require(`fs`); | ||
4 | const {createRequire, createRequireFromPath} = require(`module`); | ||
5 | const {resolve} = require(`path`); | ||
6 | |||
7 | const relPnpApiPath = "../../../../.pnp.cjs"; | ||
8 | |||
9 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); | ||
10 | const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); | ||
11 | |||
12 | if (existsSync(absPnpApiPath)) { | ||
13 | if (!process.versions.pnp) { | ||
14 | // Setup the environment to be able to require typescript/lib/typescript.js | ||
15 | require(absPnpApiPath).setup(); | ||
16 | } | ||
17 | } | ||
18 | |||
19 | // Defer to the real typescript/lib/typescript.js your application uses | ||
20 | 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 00000000..a79dfd9d --- /dev/null +++ b/.yarn/sdks/typescript/package.json | |||
@@ -0,0 +1,6 @@ | |||
1 | { | ||
2 | "name": "typescript", | ||
3 | "version": "4.8.2-sdk", | ||
4 | "main": "./lib/typescript.js", | ||
5 | "type": "commonjs" | ||
6 | } | ||