@pikokr/command.ts 5.5.0 → 5.6.0-dev.2
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.js +19 -0
- package/.github/workflows/docs.yml +22 -6
- package/.github/workflows/lint.yml +41 -0
- package/.github/workflows/release.yml +49 -0
- package/.vscode/settings.json +6 -3
- package/dist/index.d.ts +48 -46
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +20 -3
- package/publish-version.js +1 -23
- package/scripts/docs.ts +8 -8
- package/src/applicationCommand/ApplicationCommand.ts +1 -9
- package/src/applicationCommand/ApplicationCommandExtension.ts +14 -17
- package/src/applicationCommand/ApplicationCommandOption.ts +1 -9
- package/src/applicationCommand/group.ts +2 -1
- package/src/applicationCommand/index.ts +4 -12
- package/src/core/components/BaseComponent.ts +3 -11
- package/src/core/components/ComponentArgument.ts +1 -9
- package/src/core/components/ComponentArgumentDecorator.ts +0 -8
- package/src/core/components/decoratorCreator.ts +4 -12
- package/src/core/components/index.ts +5 -13
- package/src/core/converter/index.ts +8 -15
- package/src/core/extensions/CTSExtension.ts +0 -8
- package/src/core/extensions/Extension.ts +5 -13
- package/src/core/extensions/index.ts +0 -8
- package/src/core/hooks/componentHook.ts +4 -11
- package/src/core/hooks/index.ts +3 -11
- package/src/core/hooks/moduleHook.ts +2 -9
- package/src/core/index.ts +0 -8
- package/src/core/listener/index.ts +0 -8
- package/src/core/structures/CommandClient.ts +7 -12
- package/src/core/structures/Registry.ts +8 -16
- package/src/core/structures/index.ts +0 -8
- package/src/core/symbols.ts +6 -14
- package/src/core/utils/checks.ts +5 -12
- package/src/core/utils/errors.ts +0 -8
- package/src/core/utils/index.ts +3 -11
- package/src/index.ts +3 -11
- package/src/textCommand/TextCommand.ts +0 -8
- package/src/textCommand/TextCommandExtension.ts +11 -32
- package/src/textCommand/index.ts +0 -8
- package/src/textCommand/parameters.ts +6 -14
- package/src/utils/types.ts +1 -0
- package/test/index.ts +5 -4
- package/tsup.config.ts +8 -8
- package/.github/workflows/publish.stable.yml +0 -18
- package/.github/workflows/publish.yml +0 -20
- package/.yarn/releases/yarn-3.2.3.cjs +0 -783
- package/.yarn/sdks/integrations.yml +0 -5
- package/.yarn/sdks/prettier/index.js +0 -20
- package/.yarn/sdks/prettier/package.json +0 -6
- package/.yarn/sdks/typescript/bin/tsc +0 -20
- package/.yarn/sdks/typescript/bin/tsserver +0 -20
- package/.yarn/sdks/typescript/lib/tsc.js +0 -20
- package/.yarn/sdks/typescript/lib/tsserver.js +0 -196
- package/.yarn/sdks/typescript/lib/tsserverlibrary.js +0 -196
- package/.yarn/sdks/typescript/lib/typescript.js +0 -20
- package/.yarn/sdks/typescript/package.json +0 -6
- package/.yarnrc.yml +0 -1
@@ -1,20 +0,0 @@
|
|
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 prettier/index.js
|
15
|
-
require(absPnpApiPath).setup();
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
// Defer to the real prettier/index.js your application uses
|
20
|
-
module.exports = absRequire(`prettier/index.js`);
|
@@ -1,20 +0,0 @@
|
|
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/bin/tsc
|
15
|
-
require(absPnpApiPath).setup();
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
// Defer to the real typescript/bin/tsc your application uses
|
20
|
-
module.exports = absRequire(`typescript/bin/tsc`);
|
@@ -1,20 +0,0 @@
|
|
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/bin/tsserver
|
15
|
-
require(absPnpApiPath).setup();
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
// Defer to the real typescript/bin/tsserver your application uses
|
20
|
-
module.exports = absRequire(`typescript/bin/tsserver`);
|
@@ -1,20 +0,0 @@
|
|
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`);
|
@@ -1,196 +0,0 @@
|
|
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`));
|
@@ -1,196 +0,0 @@
|
|
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`));
|
@@ -1,20 +0,0 @@
|
|
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`);
|
package/.yarnrc.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
yarnPath: .yarn/releases/yarn-3.2.3.cjs
|