Skip to content

Commit e325b6f

Browse files
committed
0.1.1
1 parent 6ae2db4 commit e325b6f

File tree

11 files changed

+2077
-1893
lines changed

11 files changed

+2077
-1893
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@
3535
"prettier.prettierPath": ".yarn/sdks/prettier/index.js",
3636
"typescript.tsdk": ".yarn/sdks/typescript/lib",
3737
"typescript.enablePromptUseWorkspaceTsdk": true,
38-
"cSpell.words": ["envars", "pgsslkey"]
38+
"cSpell.words": [
39+
"envars",
40+
"pgsslkey"
41+
]
3942
}
Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

.yarn/sdks/eslint/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint",
3-
"version": "7.24.0-pnpify",
3+
"version": "0.0.0-sdk",
44
"main": "./lib/api.js",
55
"type": "commonjs"
66
}

.yarn/sdks/integrations.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# This file is automatically generated by PnPify.
2-
# Manual changes will be lost!
1+
# This file is automatically generated by @yarnpkg/sdks.
2+
# Manual changes might be lost!
33

44
integrations:
55
- vscode

.yarn/sdks/prettier/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prettier",
3-
"version": "2.2.1-pnpify",
3+
"version": "0.0.0-sdk",
44
"main": "./index.js",
55
"type": "commonjs"
66
}

.yarn/sdks/typescript/lib/tsserver.js

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
1111

1212
const moduleWrapper = tsserver => {
13+
if (!process.versions.pnp) {
14+
return tsserver;
15+
}
16+
1317
const {isAbsolute} = require(`path`);
1418
const pnpApi = require(`pnpapi`);
1519

20+
const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//);
21+
const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`);
22+
1623
const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
1724
return `${locator.name}@${locator.reference}`;
1825
}));
@@ -23,9 +30,9 @@ const moduleWrapper = tsserver => {
2330

2431
function toEditorPath(str) {
2532
// We add the `zip:` prefix to both `.zip/` paths and virtual paths
26-
if (isAbsolute(str) && !str.match(/^\^zip:/) && (str.match(/\.zip\//) || str.match(/\/(\$\$virtual|__virtual__)\//))) {
33+
if (isAbsolute(str) && !str.match(/^\^zip:/) && (str.match(/\.zip\//) || isVirtual(str))) {
2734
// We also take the opportunity to turn virtual paths into physical ones;
28-
// this makes is much easier to work with workspaces that list peer
35+
// this makes it much easier to work with workspaces that list peer
2936
// dependencies, since otherwise Ctrl+Click would bring us to the virtual
3037
// file instances instead of the real ones.
3138
//
@@ -34,26 +41,49 @@ const moduleWrapper = tsserver => {
3441
// with peer dep (otherwise jumping into react-dom would show resolution
3542
// errors on react).
3643
//
37-
const resolved = pnpApi.resolveVirtual(str);
44+
const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str;
3845
if (resolved) {
3946
const locator = pnpApi.findPackageLocator(resolved);
4047
if (locator && dependencyTreeRoots.has(`${locator.name}@${locator.reference}`)) {
41-
str = resolved;
48+
str = resolved;
4249
}
4350
}
4451

45-
str = str.replace(/\\/g, `/`)
46-
str = str.replace(/^\/?/, `/`);
52+
str = normalize(str);
4753

48-
// Absolute VSCode `Uri.fsPath`s need to start with a slash.
49-
// VSCode only adds it automatically for supported schemes,
50-
// so we have to do it manually for the `zip` scheme.
51-
// The path needs to start with a caret otherwise VSCode doesn't handle the protocol
52-
//
53-
// Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
54-
//
5554
if (str.match(/\.zip\//)) {
56-
str = `${isVSCode ? `^` : ``}zip:${str}`;
55+
switch (hostInfo) {
56+
// Absolute VSCode `Uri.fsPath`s need to start with a slash.
57+
// VSCode only adds it automatically for supported schemes,
58+
// so we have to do it manually for the `zip` scheme.
59+
// The path needs to start with a caret otherwise VSCode doesn't handle the protocol
60+
//
61+
// Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
62+
//
63+
case `vscode`: {
64+
str = `^zip:${str}`;
65+
} break;
66+
67+
// To make "go to definition" work,
68+
// We have to resolve the actual file system path from virtual path
69+
// and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
70+
case `coc-nvim`: {
71+
str = normalize(resolved).replace(/\.zip\//, `.zip::`);
72+
str = resolve(`zipfile:${str}`);
73+
} break;
74+
75+
// Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server)
76+
// We have to resolve the actual file system path from virtual path,
77+
// everything else is up to neovim
78+
case `neovim`: {
79+
str = normalize(resolved).replace(/\.zip\//, `.zip::`);
80+
str = `zipfile:${str}`;
81+
} break;
82+
83+
default: {
84+
str = `zip:${str}`;
85+
} break;
86+
}
5787
}
5888
}
5989

@@ -86,19 +116,19 @@ const moduleWrapper = tsserver => {
86116

87117
const Session = tsserver.server.Session;
88118
const {onMessage: originalOnMessage, send: originalSend} = Session.prototype;
89-
let isVSCode = false;
119+
let hostInfo = `unknown`;
90120

91-
return Object.assign(Session.prototype, {
121+
Object.assign(Session.prototype, {
92122
onMessage(/** @type {string} */ message) {
93123
const parsedMessage = JSON.parse(message)
94124

95125
if (
96126
parsedMessage != null &&
97127
typeof parsedMessage === `object` &&
98128
parsedMessage.arguments &&
99-
parsedMessage.arguments.hostInfo === `vscode`
129+
typeof parsedMessage.arguments.hostInfo === `string`
100130
) {
101-
isVSCode = true;
131+
hostInfo = parsedMessage.arguments.hostInfo;
102132
}
103133

104134
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
@@ -112,6 +142,8 @@ const moduleWrapper = tsserver => {
112142
})));
113143
}
114144
});
145+
146+
return tsserver;
115147
};
116148

117149
if (existsSync(absPnpApiPath)) {
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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.js";
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 normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`);
22+
23+
const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
24+
return `${locator.name}@${locator.reference}`;
25+
}));
26+
27+
// VSCode sends the zip paths to TS using the "zip://" prefix, that TS
28+
// doesn't understand. This layer makes sure to remove the protocol
29+
// before forwarding it to TS, and to add it back on all returned paths.
30+
31+
function toEditorPath(str) {
32+
// We add the `zip:` prefix to both `.zip/` paths and virtual paths
33+
if (isAbsolute(str) && !str.match(/^\^zip:/) && (str.match(/\.zip\//) || isVirtual(str))) {
34+
// We also take the opportunity to turn virtual paths into physical ones;
35+
// this makes it much easier to work with workspaces that list peer
36+
// dependencies, since otherwise Ctrl+Click would bring us to the virtual
37+
// file instances instead of the real ones.
38+
//
39+
// We only do this to modules owned by the the dependency tree roots.
40+
// This avoids breaking the resolution when jumping inside a vendor
41+
// with peer dep (otherwise jumping into react-dom would show resolution
42+
// errors on react).
43+
//
44+
const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str;
45+
if (resolved) {
46+
const locator = pnpApi.findPackageLocator(resolved);
47+
if (locator && dependencyTreeRoots.has(`${locator.name}@${locator.reference}`)) {
48+
str = resolved;
49+
}
50+
}
51+
52+
str = normalize(str);
53+
54+
if (str.match(/\.zip\//)) {
55+
switch (hostInfo) {
56+
// Absolute VSCode `Uri.fsPath`s need to start with a slash.
57+
// VSCode only adds it automatically for supported schemes,
58+
// so we have to do it manually for the `zip` scheme.
59+
// The path needs to start with a caret otherwise VSCode doesn't handle the protocol
60+
//
61+
// Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
62+
//
63+
case `vscode`: {
64+
str = `^zip:${str}`;
65+
} break;
66+
67+
// To make "go to definition" work,
68+
// We have to resolve the actual file system path from virtual path
69+
// and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
70+
case `coc-nvim`: {
71+
str = normalize(resolved).replace(/\.zip\//, `.zip::`);
72+
str = resolve(`zipfile:${str}`);
73+
} break;
74+
75+
// Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server)
76+
// We have to resolve the actual file system path from virtual path,
77+
// everything else is up to neovim
78+
case `neovim`: {
79+
str = normalize(resolved).replace(/\.zip\//, `.zip::`);
80+
str = `zipfile:${str}`;
81+
} break;
82+
83+
default: {
84+
str = `zip:${str}`;
85+
} break;
86+
}
87+
}
88+
}
89+
90+
return str;
91+
}
92+
93+
function fromEditorPath(str) {
94+
return process.platform === `win32`
95+
? str.replace(/^\^?zip:\//, ``)
96+
: str.replace(/^\^?zip:/, ``);
97+
}
98+
99+
// Force enable 'allowLocalPluginLoads'
100+
// TypeScript tries to resolve plugins using a path relative to itself
101+
// which doesn't work when using the global cache
102+
// https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238
103+
// VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but
104+
// TypeScript already does local loads and if this code is running the user trusts the workspace
105+
// https://github.com/microsoft/vscode/issues/45856
106+
const ConfiguredProject = tsserver.server.ConfiguredProject;
107+
const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype;
108+
ConfiguredProject.prototype.enablePluginsWithOptions = function() {
109+
this.projectService.allowLocalPluginLoads = true;
110+
return originalEnablePluginsWithOptions.apply(this, arguments);
111+
};
112+
113+
// And here is the point where we hijack the VSCode <-> TS communications
114+
// by adding ourselves in the middle. We locate everything that looks
115+
// like an absolute path of ours and normalize it.
116+
117+
const Session = tsserver.server.Session;
118+
const {onMessage: originalOnMessage, send: originalSend} = Session.prototype;
119+
let hostInfo = `unknown`;
120+
121+
Object.assign(Session.prototype, {
122+
onMessage(/** @type {string} */ message) {
123+
const parsedMessage = JSON.parse(message)
124+
125+
if (
126+
parsedMessage != null &&
127+
typeof parsedMessage === `object` &&
128+
parsedMessage.arguments &&
129+
typeof parsedMessage.arguments.hostInfo === `string`
130+
) {
131+
hostInfo = parsedMessage.arguments.hostInfo;
132+
}
133+
134+
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
135+
return typeof value === `string` ? fromEditorPath(value) : value;
136+
}));
137+
},
138+
139+
send(/** @type {any} */ msg) {
140+
return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => {
141+
return typeof value === `string` ? toEditorPath(value) : value;
142+
})));
143+
}
144+
});
145+
146+
return tsserver;
147+
};
148+
149+
if (existsSync(absPnpApiPath)) {
150+
if (!process.versions.pnp) {
151+
// Setup the environment to be able to require typescript/lib/tsserverlibrary.js
152+
require(absPnpApiPath).setup();
153+
}
154+
}
155+
156+
// Defer to the real typescript/lib/tsserverlibrary.js your application uses
157+
module.exports = moduleWrapper(absRequire(`typescript/lib/tsserverlibrary.js`));

.yarn/sdks/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript",
3-
"version": "4.2.4-pnpify",
3+
"version": "0.0.0-sdk",
44
"main": "./lib/typescript.js",
55
"type": "commonjs"
66
}

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ plugins:
44
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
55
spec: "@yarnpkg/plugin-typescript"
66

7-
yarnPath: .yarn/releases/yarn-2.4.1.cjs
7+
yarnPath: .yarn/releases/yarn-2.4.2.cjs

package.json

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "envars",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Securely store and load environment variables to/from .env files.",
55
"keywords": [
66
".env",
@@ -26,9 +26,7 @@
2626
"type": "patreon",
2727
"url": "https://patreon.com/koistya"
2828
},
29-
"bin": {
30-
"envars": "./cli.js"
31-
},
29+
"bin": "./cli.js",
3230
"main": "index.js",
3331
"types": "index.d.ts",
3432
"scripts": {
@@ -39,27 +37,27 @@
3937
},
4038
"dependencies": {
4139
"chalk": "^4.1.1",
42-
"dotenv": "^8.2.0",
40+
"dotenv": "^10.0.0",
4341
"make-dir": "^3.1.0",
44-
"meow": "^9.0.0"
42+
"meow": "^10.1.0"
4543
},
4644
"devDependencies": {
47-
"@babel/cli": "^7.13.16",
48-
"@babel/core": "^7.14.0",
49-
"@babel/plugin-proposal-class-properties": "^7.13.0",
50-
"@babel/preset-env": "^7.14.0",
51-
"@babel/preset-typescript": "^7.13.0",
52-
"@types/jest": "^26.0.23",
53-
"@types/lodash": "^4.14.168",
54-
"@types/node": "^15.0.1",
55-
"@typescript-eslint/eslint-plugin": "^4.22.0",
56-
"@typescript-eslint/parser": "^4.22.0",
57-
"@yarnpkg/pnpify": "^3.0.0-rc.3",
45+
"@babel/cli": "^7.14.5",
46+
"@babel/core": "^7.14.6",
47+
"@babel/plugin-proposal-class-properties": "^7.14.5",
48+
"@babel/preset-env": "^7.14.7",
49+
"@babel/preset-typescript": "^7.14.5",
50+
"@types/jest": "^26.0.24",
51+
"@types/lodash": "^4.14.171",
52+
"@types/node": "^16.3.3",
53+
"@typescript-eslint/eslint-plugin": "^4.28.4",
54+
"@typescript-eslint/parser": "^4.28.4",
55+
"@yarnpkg/sdks": "^2.4.1-rc.3",
5856
"del": "^6.0.0",
59-
"eslint": "^7.25.0",
57+
"eslint": "^7.31.0",
6058
"eslint-config-prettier": "^8.3.0",
61-
"jest": "^26.6.3",
62-
"prettier": "^2.2.1",
59+
"jest": "^27.0.6",
60+
"prettier": "^2.3.2",
6361
"typescript": "^4.2.4"
6462
},
6563
"jest": {

0 commit comments

Comments
 (0)