fastypest 1.3.2 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,232 +1,232 @@
1
- #!/usr/bin/env node
2
-
3
- const {existsSync} = require(`fs`);
4
- const {createRequire} = require(`module`);
5
- const {resolve} = require(`path`);
6
-
7
- const relPnpApiPath = "../../../../.pnp.cjs";
8
-
9
- const absPnpApiPath = resolve(__dirname, relPnpApiPath);
10
- const absRequire = createRequire(absPnpApiPath);
11
-
12
- if (existsSync(absPnpApiPath)) {
13
- if (!process.versions.pnp) {
14
- // Setup the environment to be able to require typescript/lib/tsserver.js
15
- require(absPnpApiPath).setup();
16
- }
17
- }
18
-
19
- const moduleWrapper = tsserver => {
20
- if (!process.versions.pnp) {
21
- return tsserver;
22
- }
23
-
24
- const {isAbsolute} = require(`path`);
25
- const pnpApi = require(`pnpapi`);
26
-
27
- const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//);
28
- const isPortal = str => str.startsWith("portal:/");
29
- const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`);
30
-
31
- const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
32
- return `${locator.name}@${locator.reference}`;
33
- }));
34
-
35
- // VSCode sends the zip paths to TS using the "zip://" prefix, that TS
36
- // doesn't understand. This layer makes sure to remove the protocol
37
- // before forwarding it to TS, and to add it back on all returned paths.
38
-
39
- function toEditorPath(str) {
40
- // We add the `zip:` prefix to both `.zip/` paths and virtual paths
41
- if (isAbsolute(str) && !str.match(/^\^?(zip:|\/zip\/)/) && (str.match(/\.zip\//) || isVirtual(str))) {
42
- // We also take the opportunity to turn virtual paths into physical ones;
43
- // this makes it much easier to work with workspaces that list peer
44
- // dependencies, since otherwise Ctrl+Click would bring us to the virtual
45
- // file instances instead of the real ones.
46
- //
47
- // We only do this to modules owned by the the dependency tree roots.
48
- // This avoids breaking the resolution when jumping inside a vendor
49
- // with peer dep (otherwise jumping into react-dom would show resolution
50
- // errors on react).
51
- //
52
- const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str;
53
- if (resolved) {
54
- const locator = pnpApi.findPackageLocator(resolved);
55
- if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) {
56
- str = resolved;
57
- }
58
- }
59
-
60
- str = normalize(str);
61
-
62
- if (str.match(/\.zip\//)) {
63
- switch (hostInfo) {
64
- // Absolute VSCode `Uri.fsPath`s need to start with a slash.
65
- // VSCode only adds it automatically for supported schemes,
66
- // so we have to do it manually for the `zip` scheme.
67
- // The path needs to start with a caret otherwise VSCode doesn't handle the protocol
68
- //
69
- // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
70
- //
71
- // 2021-10-08: VSCode changed the format in 1.61.
72
- // Before | ^zip:/c:/foo/bar.zip/package.json
73
- // After | ^/zip//c:/foo/bar.zip/package.json
74
- //
75
- // 2022-04-06: VSCode changed the format in 1.66.
76
- // Before | ^/zip//c:/foo/bar.zip/package.json
77
- // After | ^/zip/c:/foo/bar.zip/package.json
78
- //
79
- // 2022-05-06: VSCode changed the format in 1.68
80
- // Before | ^/zip/c:/foo/bar.zip/package.json
81
- // After | ^/zip//c:/foo/bar.zip/package.json
82
- //
83
- case `vscode <1.61`: {
84
- str = `^zip:${str}`;
85
- } break;
86
-
87
- case `vscode <1.66`: {
88
- str = `^/zip/${str}`;
89
- } break;
90
-
91
- case `vscode <1.68`: {
92
- str = `^/zip${str}`;
93
- } break;
94
-
95
- case `vscode`: {
96
- str = `^/zip/${str}`;
97
- } break;
98
-
99
- // To make "go to definition" work,
100
- // We have to resolve the actual file system path from virtual path
101
- // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
102
- case `coc-nvim`: {
103
- str = normalize(resolved).replace(/\.zip\//, `.zip::`);
104
- str = resolve(`zipfile:${str}`);
105
- } break;
106
-
107
- // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server)
108
- // We have to resolve the actual file system path from virtual path,
109
- // everything else is up to neovim
110
- case `neovim`: {
111
- str = normalize(resolved).replace(/\.zip\//, `.zip::`);
112
- str = `zipfile://${str}`;
113
- } break;
114
-
115
- default: {
116
- str = `zip:${str}`;
117
- } break;
118
- }
119
- } else {
120
- str = str.replace(/^\/?/, process.platform === `win32` ? `` : `/`);
121
- }
122
- }
123
-
124
- return str;
125
- }
126
-
127
- function fromEditorPath(str) {
128
- switch (hostInfo) {
129
- case `coc-nvim`: {
130
- str = str.replace(/\.zip::/, `.zip/`);
131
- // The path for coc-nvim is in format of /<pwd>/zipfile:/<pwd>/.yarn/...
132
- // So in order to convert it back, we use .* to match all the thing
133
- // before `zipfile:`
134
- return process.platform === `win32`
135
- ? str.replace(/^.*zipfile:\//, ``)
136
- : str.replace(/^.*zipfile:/, ``);
137
- } break;
138
-
139
- case `neovim`: {
140
- str = str.replace(/\.zip::/, `.zip/`);
141
- // The path for neovim is in format of zipfile:///<pwd>/.yarn/...
142
- return str.replace(/^zipfile:\/\//, ``);
143
- } break;
144
-
145
- case `vscode`:
146
- default: {
147
- return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`)
148
- } break;
149
- }
150
- }
151
-
152
- // Force enable 'allowLocalPluginLoads'
153
- // TypeScript tries to resolve plugins using a path relative to itself
154
- // which doesn't work when using the global cache
155
- // https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238
156
- // VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but
157
- // TypeScript already does local loads and if this code is running the user trusts the workspace
158
- // https://github.com/microsoft/vscode/issues/45856
159
- const ConfiguredProject = tsserver.server.ConfiguredProject;
160
- const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype;
161
- ConfiguredProject.prototype.enablePluginsWithOptions = function() {
162
- this.projectService.allowLocalPluginLoads = true;
163
- return originalEnablePluginsWithOptions.apply(this, arguments);
164
- };
165
-
166
- // And here is the point where we hijack the VSCode <-> TS communications
167
- // by adding ourselves in the middle. We locate everything that looks
168
- // like an absolute path of ours and normalize it.
169
-
170
- const Session = tsserver.server.Session;
171
- const {onMessage: originalOnMessage, send: originalSend} = Session.prototype;
172
- let hostInfo = `unknown`;
173
-
174
- Object.assign(Session.prototype, {
175
- onMessage(/** @type {string | object} */ message) {
176
- const isStringMessage = typeof message === 'string';
177
- const parsedMessage = isStringMessage ? JSON.parse(message) : message;
178
-
179
- if (
180
- parsedMessage != null &&
181
- typeof parsedMessage === `object` &&
182
- parsedMessage.arguments &&
183
- typeof parsedMessage.arguments.hostInfo === `string`
184
- ) {
185
- hostInfo = parsedMessage.arguments.hostInfo;
186
- if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) {
187
- const [, major, minor] = (process.env.VSCODE_IPC_HOOK.match(
188
- // The RegExp from https://semver.org/ but without the caret at the start
189
- /(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-]+)*))?$/
190
- ) ?? []).map(Number)
191
-
192
- if (major === 1) {
193
- if (minor < 61) {
194
- hostInfo += ` <1.61`;
195
- } else if (minor < 66) {
196
- hostInfo += ` <1.66`;
197
- } else if (minor < 68) {
198
- hostInfo += ` <1.68`;
199
- }
200
- }
201
- }
202
- }
203
-
204
- const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => {
205
- return typeof value === 'string' ? fromEditorPath(value) : value;
206
- });
207
-
208
- return originalOnMessage.call(
209
- this,
210
- isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)
211
- );
212
- },
213
-
214
- send(/** @type {any} */ msg) {
215
- return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => {
216
- return typeof value === `string` ? toEditorPath(value) : value;
217
- })));
218
- }
219
- });
220
-
221
- return tsserver;
222
- };
223
-
224
- const [major, minor] = absRequire(`typescript/package.json`).version.split(`.`, 2).map(value => parseInt(value, 10));
225
- // In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well.
226
- // Ref https://github.com/microsoft/TypeScript/pull/55326
227
- if (major > 5 || (major === 5 && minor >= 5)) {
228
- moduleWrapper(absRequire(`typescript`));
229
- }
230
-
231
- // Defer to the real typescript/lib/tsserver.js your application uses
232
- module.exports = moduleWrapper(absRequire(`typescript/lib/tsserver.js`));
1
+ #!/usr/bin/env node
2
+
3
+ const {existsSync} = require(`fs`);
4
+ const {createRequire} = require(`module`);
5
+ const {resolve} = require(`path`);
6
+
7
+ const relPnpApiPath = "../../../../.pnp.cjs";
8
+
9
+ const absPnpApiPath = resolve(__dirname, relPnpApiPath);
10
+ const absRequire = createRequire(absPnpApiPath);
11
+
12
+ if (existsSync(absPnpApiPath)) {
13
+ if (!process.versions.pnp) {
14
+ // Setup the environment to be able to require typescript/lib/tsserver.js
15
+ require(absPnpApiPath).setup();
16
+ }
17
+ }
18
+
19
+ const moduleWrapper = tsserver => {
20
+ if (!process.versions.pnp) {
21
+ return tsserver;
22
+ }
23
+
24
+ const {isAbsolute} = require(`path`);
25
+ const pnpApi = require(`pnpapi`);
26
+
27
+ const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//);
28
+ const isPortal = str => str.startsWith("portal:/");
29
+ const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`);
30
+
31
+ const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
32
+ return `${locator.name}@${locator.reference}`;
33
+ }));
34
+
35
+ // VSCode sends the zip paths to TS using the "zip://" prefix, that TS
36
+ // doesn't understand. This layer makes sure to remove the protocol
37
+ // before forwarding it to TS, and to add it back on all returned paths.
38
+
39
+ function toEditorPath(str) {
40
+ // We add the `zip:` prefix to both `.zip/` paths and virtual paths
41
+ if (isAbsolute(str) && !str.match(/^\^?(zip:|\/zip\/)/) && (str.match(/\.zip\//) || isVirtual(str))) {
42
+ // We also take the opportunity to turn virtual paths into physical ones;
43
+ // this makes it much easier to work with workspaces that list peer
44
+ // dependencies, since otherwise Ctrl+Click would bring us to the virtual
45
+ // file instances instead of the real ones.
46
+ //
47
+ // We only do this to modules owned by the the dependency tree roots.
48
+ // This avoids breaking the resolution when jumping inside a vendor
49
+ // with peer dep (otherwise jumping into react-dom would show resolution
50
+ // errors on react).
51
+ //
52
+ const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str;
53
+ if (resolved) {
54
+ const locator = pnpApi.findPackageLocator(resolved);
55
+ if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) {
56
+ str = resolved;
57
+ }
58
+ }
59
+
60
+ str = normalize(str);
61
+
62
+ if (str.match(/\.zip\//)) {
63
+ switch (hostInfo) {
64
+ // Absolute VSCode `Uri.fsPath`s need to start with a slash.
65
+ // VSCode only adds it automatically for supported schemes,
66
+ // so we have to do it manually for the `zip` scheme.
67
+ // The path needs to start with a caret otherwise VSCode doesn't handle the protocol
68
+ //
69
+ // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
70
+ //
71
+ // 2021-10-08: VSCode changed the format in 1.61.
72
+ // Before | ^zip:/c:/foo/bar.zip/package.json
73
+ // After | ^/zip//c:/foo/bar.zip/package.json
74
+ //
75
+ // 2022-04-06: VSCode changed the format in 1.66.
76
+ // Before | ^/zip//c:/foo/bar.zip/package.json
77
+ // After | ^/zip/c:/foo/bar.zip/package.json
78
+ //
79
+ // 2022-05-06: VSCode changed the format in 1.68
80
+ // Before | ^/zip/c:/foo/bar.zip/package.json
81
+ // After | ^/zip//c:/foo/bar.zip/package.json
82
+ //
83
+ case `vscode <1.61`: {
84
+ str = `^zip:${str}`;
85
+ } break;
86
+
87
+ case `vscode <1.66`: {
88
+ str = `^/zip/${str}`;
89
+ } break;
90
+
91
+ case `vscode <1.68`: {
92
+ str = `^/zip${str}`;
93
+ } break;
94
+
95
+ case `vscode`: {
96
+ str = `^/zip/${str}`;
97
+ } break;
98
+
99
+ // To make "go to definition" work,
100
+ // We have to resolve the actual file system path from virtual path
101
+ // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
102
+ case `coc-nvim`: {
103
+ str = normalize(resolved).replace(/\.zip\//, `.zip::`);
104
+ str = resolve(`zipfile:${str}`);
105
+ } break;
106
+
107
+ // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server)
108
+ // We have to resolve the actual file system path from virtual path,
109
+ // everything else is up to neovim
110
+ case `neovim`: {
111
+ str = normalize(resolved).replace(/\.zip\//, `.zip::`);
112
+ str = `zipfile://${str}`;
113
+ } break;
114
+
115
+ default: {
116
+ str = `zip:${str}`;
117
+ } break;
118
+ }
119
+ } else {
120
+ str = str.replace(/^\/?/, process.platform === `win32` ? `` : `/`);
121
+ }
122
+ }
123
+
124
+ return str;
125
+ }
126
+
127
+ function fromEditorPath(str) {
128
+ switch (hostInfo) {
129
+ case `coc-nvim`: {
130
+ str = str.replace(/\.zip::/, `.zip/`);
131
+ // The path for coc-nvim is in format of /<pwd>/zipfile:/<pwd>/.yarn/...
132
+ // So in order to convert it back, we use .* to match all the thing
133
+ // before `zipfile:`
134
+ return process.platform === `win32`
135
+ ? str.replace(/^.*zipfile:\//, ``)
136
+ : str.replace(/^.*zipfile:/, ``);
137
+ } break;
138
+
139
+ case `neovim`: {
140
+ str = str.replace(/\.zip::/, `.zip/`);
141
+ // The path for neovim is in format of zipfile:///<pwd>/.yarn/...
142
+ return str.replace(/^zipfile:\/\//, ``);
143
+ } break;
144
+
145
+ case `vscode`:
146
+ default: {
147
+ return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`)
148
+ } break;
149
+ }
150
+ }
151
+
152
+ // Force enable 'allowLocalPluginLoads'
153
+ // TypeScript tries to resolve plugins using a path relative to itself
154
+ // which doesn't work when using the global cache
155
+ // https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238
156
+ // VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but
157
+ // TypeScript already does local loads and if this code is running the user trusts the workspace
158
+ // https://github.com/microsoft/vscode/issues/45856
159
+ const ConfiguredProject = tsserver.server.ConfiguredProject;
160
+ const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype;
161
+ ConfiguredProject.prototype.enablePluginsWithOptions = function() {
162
+ this.projectService.allowLocalPluginLoads = true;
163
+ return originalEnablePluginsWithOptions.apply(this, arguments);
164
+ };
165
+
166
+ // And here is the point where we hijack the VSCode <-> TS communications
167
+ // by adding ourselves in the middle. We locate everything that looks
168
+ // like an absolute path of ours and normalize it.
169
+
170
+ const Session = tsserver.server.Session;
171
+ const {onMessage: originalOnMessage, send: originalSend} = Session.prototype;
172
+ let hostInfo = `unknown`;
173
+
174
+ Object.assign(Session.prototype, {
175
+ onMessage(/** @type {string | object} */ message) {
176
+ const isStringMessage = typeof message === 'string';
177
+ const parsedMessage = isStringMessage ? JSON.parse(message) : message;
178
+
179
+ if (
180
+ parsedMessage != null &&
181
+ typeof parsedMessage === `object` &&
182
+ parsedMessage.arguments &&
183
+ typeof parsedMessage.arguments.hostInfo === `string`
184
+ ) {
185
+ hostInfo = parsedMessage.arguments.hostInfo;
186
+ if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) {
187
+ const [, major, minor] = (process.env.VSCODE_IPC_HOOK.match(
188
+ // The RegExp from https://semver.org/ but without the caret at the start
189
+ /(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-]+)*))?$/
190
+ ) ?? []).map(Number)
191
+
192
+ if (major === 1) {
193
+ if (minor < 61) {
194
+ hostInfo += ` <1.61`;
195
+ } else if (minor < 66) {
196
+ hostInfo += ` <1.66`;
197
+ } else if (minor < 68) {
198
+ hostInfo += ` <1.68`;
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => {
205
+ return typeof value === 'string' ? fromEditorPath(value) : value;
206
+ });
207
+
208
+ return originalOnMessage.call(
209
+ this,
210
+ isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)
211
+ );
212
+ },
213
+
214
+ send(/** @type {any} */ msg) {
215
+ return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => {
216
+ return typeof value === `string` ? toEditorPath(value) : value;
217
+ })));
218
+ }
219
+ });
220
+
221
+ return tsserver;
222
+ };
223
+
224
+ const [major, minor] = absRequire(`typescript/package.json`).version.split(`.`, 2).map(value => parseInt(value, 10));
225
+ // In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well.
226
+ // Ref https://github.com/microsoft/TypeScript/pull/55326
227
+ if (major > 5 || (major === 5 && minor >= 5)) {
228
+ moduleWrapper(absRequire(`typescript`));
229
+ }
230
+
231
+ // Defer to the real typescript/lib/tsserver.js your application uses
232
+ module.exports = moduleWrapper(absRequire(`typescript/lib/tsserver.js`));