Skip to content

Commit 02f6288

Browse files
nhooyrcode-asher
authored andcommitted
Propagate full env to browser (#756)
* Propogate full env to browser * Add support for setting $ITEM_URL * Add serviceURL getter
1 parent 362715b commit 02f6288

File tree

13 files changed

+95
-37
lines changed

13 files changed

+95
-37
lines changed

packages/ide/src/fill/os.ts

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class OS {
3535
default: this._platform = "linux"; break;
3636
}
3737
process.platform = this._platform;
38+
process.env = {};
39+
data.env.forEach((v, k) => {
40+
process.env[k] = v;
41+
});
3842
}
3943

4044
public release(): string {

packages/protocol/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
"rimraf": "^2.6.3",
1515
"text-encoding": "^0.7.0",
1616
"ts-protoc-gen": "^0.8.0"
17+
},
18+
"scripts": {
19+
"gen": "./scripts/generate_proto.sh"
1720
}
1821
}
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#!/bin/bash
22

3-
protoc --plugin="protoc-gen-ts=./node_modules/.bin/protoc-gen-ts" --js_out="import_style=commonjs,binary:./src/proto" --ts_out="./src/proto" ./src/proto/*.proto --proto_path="./src/proto"
3+
cd "$(dirname "$0")/.."
4+
5+
protoc --plugin="protoc-gen-ts=./node_modules/.bin/protoc-gen-ts" --js_out="import_style=commonjs,binary:./src/proto" --ts_out="./src/proto" ./src/proto/*.proto --proto_path="./src/proto"

packages/protocol/src/browser/client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export class Client {
280280
builtInExtensionsDirectory: init.getBuiltinExtensionsDir(),
281281
extraExtensionDirectories: init.getExtraExtensionDirectoriesList(),
282282
extraBuiltinExtensionDirectories: init.getExtraBuiltinExtensionDirectoriesList(),
283+
env: init.getEnvMap(),
283284
};
284285
this.initDataEmitter.emit(this._initData);
285286
break;

packages/protocol/src/common/connection.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as jspb from "google-protobuf";
2+
13
export interface SendableConnection {
24
send(data: Buffer | Uint8Array): void;
35
}
@@ -27,6 +29,7 @@ export interface InitData {
2729
readonly builtInExtensionsDirectory: string;
2830
readonly extraExtensionDirectories: string[];
2931
readonly extraBuiltinExtensionDirectories: string[];
32+
readonly env: jspb.Map<string, string>;
3033
}
3134

3235
export interface SharedProcessData {

packages/protocol/src/node/server.ts

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ export class Server {
103103
initMsg.setShell(os.userInfo().shell || global.process.env.SHELL || "");
104104
initMsg.setExtraExtensionDirectoriesList(this.options.extraExtensionDirectories || []);
105105
initMsg.setExtraBuiltinExtensionDirectoriesList(this.options.extraBuiltinExtensionDirectories || []);
106+
107+
for (let key in process.env) {
108+
initMsg.getEnvMap().set(key, process.env[key] as string);
109+
}
110+
106111
const srvMsg = new ServerMessage();
107112
srvMsg.setInit(initMsg);
108113
connection.send(srvMsg.serializeBinary());

packages/protocol/src/proto/client.proto

+2
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ message WorkingInit {
4444
string extensions_directory = 8;
4545
repeated string extra_extension_directories = 9;
4646
repeated string extra_builtin_extension_directories = 10;
47+
48+
map<string, string> env = 11;
4749
}

packages/protocol/src/proto/client_pb.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ export class WorkingInit extends jspb.Message {
145145
setExtraBuiltinExtensionDirectoriesList(value: Array<string>): void;
146146
addExtraBuiltinExtensionDirectories(value: string, index?: number): string;
147147

148+
getEnvMap(): jspb.Map<string, string>;
149+
clearEnvMap(): void;
148150
serializeBinary(): Uint8Array;
149151
toObject(includeInstance?: boolean): WorkingInit.AsObject;
150152
static toObject(includeInstance: boolean, msg: WorkingInit): WorkingInit.AsObject;
@@ -167,6 +169,7 @@ export namespace WorkingInit {
167169
extensionsDirectory: string,
168170
extraExtensionDirectoriesList: Array<string>,
169171
extraBuiltinExtensionDirectoriesList: Array<string>,
172+
envMap: Array<[string, string]>,
170173
}
171174

172175
export enum OperatingSystem {

packages/protocol/src/proto/client_pb.js

+36-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ proto.ClientMessage.prototype.toObject = function(opt_includeInstance) {
137137
* @suppress {unusedLocalVariables} f is only used for nested messages
138138
*/
139139
proto.ClientMessage.toObject = function(includeInstance, msg) {
140-
var obj = {
140+
var f, obj = {
141141
method: (f = msg.getMethod()) && node_pb.Method.toObject(includeInstance, f),
142142
ping: (f = msg.getPing()) && node_pb.Ping.toObject(includeInstance, f)
143143
};
@@ -360,7 +360,7 @@ proto.ServerMessage.prototype.toObject = function(opt_includeInstance) {
360360
* @suppress {unusedLocalVariables} f is only used for nested messages
361361
*/
362362
proto.ServerMessage.toObject = function(includeInstance, msg) {
363-
var obj = {
363+
var f, obj = {
364364
fail: (f = msg.getFail()) && node_pb.Method.Fail.toObject(includeInstance, f),
365365
success: (f = msg.getSuccess()) && node_pb.Method.Success.toObject(includeInstance, f),
366366
event: (f = msg.getEvent()) && node_pb.Event.toObject(includeInstance, f),
@@ -794,7 +794,7 @@ proto.WorkingInit.prototype.toObject = function(opt_includeInstance) {
794794
* @suppress {unusedLocalVariables} f is only used for nested messages
795795
*/
796796
proto.WorkingInit.toObject = function(includeInstance, msg) {
797-
var obj = {
797+
var f, obj = {
798798
homeDirectory: jspb.Message.getFieldWithDefault(msg, 1, ""),
799799
tmpDirectory: jspb.Message.getFieldWithDefault(msg, 2, ""),
800800
dataDirectory: jspb.Message.getFieldWithDefault(msg, 3, ""),
@@ -804,7 +804,8 @@ proto.WorkingInit.toObject = function(includeInstance, msg) {
804804
builtinExtensionsDir: jspb.Message.getFieldWithDefault(msg, 7, ""),
805805
extensionsDirectory: jspb.Message.getFieldWithDefault(msg, 8, ""),
806806
extraExtensionDirectoriesList: jspb.Message.getRepeatedField(msg, 9),
807-
extraBuiltinExtensionDirectoriesList: jspb.Message.getRepeatedField(msg, 10)
807+
extraBuiltinExtensionDirectoriesList: jspb.Message.getRepeatedField(msg, 10),
808+
envMap: (f = msg.getEnvMap()) ? f.toObject(includeInstance, undefined) : []
808809
};
809810

810811
if (includeInstance) {
@@ -881,6 +882,12 @@ proto.WorkingInit.deserializeBinaryFromReader = function(msg, reader) {
881882
var value = /** @type {string} */ (reader.readString());
882883
msg.addExtraBuiltinExtensionDirectories(value);
883884
break;
885+
case 11:
886+
var value = msg.getEnvMap();
887+
reader.readMessage(value, function(message, reader) {
888+
jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readString, null, "");
889+
});
890+
break;
884891
default:
885892
reader.skipField();
886893
break;
@@ -980,6 +987,10 @@ proto.WorkingInit.serializeBinaryToWriter = function(message, writer) {
980987
f
981988
);
982989
}
990+
f = message.getEnvMap(true);
991+
if (f && f.getLength() > 0) {
992+
f.serializeBinary(11, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeString);
993+
}
983994
};
984995

985996

@@ -1176,4 +1187,25 @@ proto.WorkingInit.prototype.clearExtraBuiltinExtensionDirectoriesList = function
11761187
};
11771188

11781189

1190+
/**
1191+
* map<string, string> env = 11;
1192+
* @param {boolean=} opt_noLazyCreate Do not create the map if
1193+
* empty, instead returning `undefined`
1194+
* @return {!jspb.Map<string,string>}
1195+
*/
1196+
proto.WorkingInit.prototype.getEnvMap = function(opt_noLazyCreate) {
1197+
return /** @type {!jspb.Map<string,string>} */ (
1198+
jspb.Message.getMapField(this, 11, opt_noLazyCreate,
1199+
null));
1200+
};
1201+
1202+
1203+
/**
1204+
* Clears values from the map. The map will be non-null.
1205+
*/
1206+
proto.WorkingInit.prototype.clearEnvMap = function() {
1207+
this.getEnvMap().clear();
1208+
};
1209+
1210+
11791211
goog.object.extend(exports, proto);

packages/protocol/src/proto/node_pb.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ proto.Argument.prototype.toObject = function(opt_includeInstance) {
583583
* @suppress {unusedLocalVariables} f is only used for nested messages
584584
*/
585585
proto.Argument.toObject = function(includeInstance, msg) {
586-
var obj = {
586+
var f, obj = {
587587
error: (f = msg.getError()) && proto.Argument.ErrorValue.toObject(includeInstance, f),
588588
buffer: (f = msg.getBuffer()) && proto.Argument.BufferValue.toObject(includeInstance, f),
589589
object: (f = msg.getObject()) && proto.Argument.ObjectValue.toObject(includeInstance, f),
@@ -843,7 +843,7 @@ proto.Argument.ErrorValue.prototype.toObject = function(opt_includeInstance) {
843843
* @suppress {unusedLocalVariables} f is only used for nested messages
844844
*/
845845
proto.Argument.ErrorValue.toObject = function(includeInstance, msg) {
846-
var obj = {
846+
var f, obj = {
847847
message: jspb.Message.getFieldWithDefault(msg, 1, ""),
848848
stack: jspb.Message.getFieldWithDefault(msg, 2, ""),
849849
code: jspb.Message.getFieldWithDefault(msg, 3, "")
@@ -1022,7 +1022,7 @@ proto.Argument.BufferValue.prototype.toObject = function(opt_includeInstance) {
10221022
* @suppress {unusedLocalVariables} f is only used for nested messages
10231023
*/
10241024
proto.Argument.BufferValue.toObject = function(includeInstance, msg) {
1025-
var obj = {
1025+
var f, obj = {
10261026
data: msg.getData_asB64()
10271027
};
10281028

@@ -1171,7 +1171,7 @@ proto.Argument.ObjectValue.prototype.toObject = function(opt_includeInstance) {
11711171
* @suppress {unusedLocalVariables} f is only used for nested messages
11721172
*/
11731173
proto.Argument.ObjectValue.toObject = function(includeInstance, msg) {
1174-
var obj = {
1174+
var f, obj = {
11751175
dataMap: (f = msg.getDataMap()) ? f.toObject(includeInstance, proto.Argument.toObject) : []
11761176
};
11771177

@@ -1308,7 +1308,7 @@ proto.Argument.ArrayValue.prototype.toObject = function(opt_includeInstance) {
13081308
* @suppress {unusedLocalVariables} f is only used for nested messages
13091309
*/
13101310
proto.Argument.ArrayValue.toObject = function(includeInstance, msg) {
1311-
var obj = {
1311+
var f, obj = {
13121312
dataList: jspb.Message.toObjectList(msg.getDataList(),
13131313
proto.Argument.toObject, includeInstance)
13141314
};
@@ -1455,7 +1455,7 @@ proto.Argument.ProxyValue.prototype.toObject = function(opt_includeInstance) {
14551455
* @suppress {unusedLocalVariables} f is only used for nested messages
14561456
*/
14571457
proto.Argument.ProxyValue.toObject = function(includeInstance, msg) {
1458-
var obj = {
1458+
var f, obj = {
14591459
id: jspb.Message.getFieldWithDefault(msg, 1, 0)
14601460
};
14611461

@@ -1580,7 +1580,7 @@ proto.Argument.FunctionValue.prototype.toObject = function(opt_includeInstance)
15801580
* @suppress {unusedLocalVariables} f is only used for nested messages
15811581
*/
15821582
proto.Argument.FunctionValue.toObject = function(includeInstance, msg) {
1583-
var obj = {
1583+
var f, obj = {
15841584
id: jspb.Message.getFieldWithDefault(msg, 1, 0)
15851585
};
15861586

@@ -1705,7 +1705,7 @@ proto.Argument.NullValue.prototype.toObject = function(opt_includeInstance) {
17051705
* @suppress {unusedLocalVariables} f is only used for nested messages
17061706
*/
17071707
proto.Argument.NullValue.toObject = function(includeInstance, msg) {
1708-
var obj = {
1708+
var f, obj = {
17091709

17101710
};
17111711

@@ -1804,7 +1804,7 @@ proto.Argument.UndefinedValue.prototype.toObject = function(opt_includeInstance)
18041804
* @suppress {unusedLocalVariables} f is only used for nested messages
18051805
*/
18061806
proto.Argument.UndefinedValue.toObject = function(includeInstance, msg) {
1807-
var obj = {
1807+
var f, obj = {
18081808

18091809
};
18101810

@@ -1903,7 +1903,7 @@ proto.Argument.DateValue.prototype.toObject = function(opt_includeInstance) {
19031903
* @suppress {unusedLocalVariables} f is only used for nested messages
19041904
*/
19051905
proto.Argument.DateValue.toObject = function(includeInstance, msg) {
1906-
var obj = {
1906+
var f, obj = {
19071907
date: jspb.Message.getFieldWithDefault(msg, 1, "")
19081908
};
19091909

@@ -2449,7 +2449,7 @@ proto.Method.prototype.toObject = function(opt_includeInstance) {
24492449
* @suppress {unusedLocalVariables} f is only used for nested messages
24502450
*/
24512451
proto.Method.toObject = function(includeInstance, msg) {
2452-
var obj = {
2452+
var f, obj = {
24532453
namedProxy: (f = msg.getNamedProxy()) && proto.Method.Named.toObject(includeInstance, f),
24542454
numberedProxy: (f = msg.getNumberedProxy()) && proto.Method.Numbered.toObject(includeInstance, f)
24552455
};
@@ -2582,7 +2582,7 @@ proto.Method.Named.prototype.toObject = function(opt_includeInstance) {
25822582
* @suppress {unusedLocalVariables} f is only used for nested messages
25832583
*/
25842584
proto.Method.Named.toObject = function(includeInstance, msg) {
2585-
var obj = {
2585+
var f, obj = {
25862586
id: jspb.Message.getFieldWithDefault(msg, 1, 0),
25872587
module: jspb.Message.getFieldWithDefault(msg, 2, 0),
25882588
method: jspb.Message.getFieldWithDefault(msg, 3, ""),
@@ -2817,7 +2817,7 @@ proto.Method.Numbered.prototype.toObject = function(opt_includeInstance) {
28172817
* @suppress {unusedLocalVariables} f is only used for nested messages
28182818
*/
28192819
proto.Method.Numbered.toObject = function(includeInstance, msg) {
2820-
var obj = {
2820+
var f, obj = {
28212821
id: jspb.Message.getFieldWithDefault(msg, 1, 0),
28222822
proxyId: jspb.Message.getFieldWithDefault(msg, 2, 0),
28232823
method: jspb.Message.getFieldWithDefault(msg, 3, ""),
@@ -3045,7 +3045,7 @@ proto.Method.Fail.prototype.toObject = function(opt_includeInstance) {
30453045
* @suppress {unusedLocalVariables} f is only used for nested messages
30463046
*/
30473047
proto.Method.Fail.toObject = function(includeInstance, msg) {
3048-
var obj = {
3048+
var f, obj = {
30493049
id: jspb.Message.getFieldWithDefault(msg, 1, 0),
30503050
response: (f = msg.getResponse()) && proto.Argument.toObject(includeInstance, f)
30513051
};
@@ -3217,7 +3217,7 @@ proto.Method.Success.prototype.toObject = function(opt_includeInstance) {
32173217
* @suppress {unusedLocalVariables} f is only used for nested messages
32183218
*/
32193219
proto.Method.Success.toObject = function(includeInstance, msg) {
3220-
var obj = {
3220+
var f, obj = {
32213221
id: jspb.Message.getFieldWithDefault(msg, 1, 0),
32223222
response: (f = msg.getResponse()) && proto.Argument.toObject(includeInstance, f)
32233223
};
@@ -3481,7 +3481,7 @@ proto.Callback.prototype.toObject = function(opt_includeInstance) {
34813481
* @suppress {unusedLocalVariables} f is only used for nested messages
34823482
*/
34833483
proto.Callback.toObject = function(includeInstance, msg) {
3484-
var obj = {
3484+
var f, obj = {
34853485
namedCallback: (f = msg.getNamedCallback()) && proto.Callback.Named.toObject(includeInstance, f),
34863486
numberedCallback: (f = msg.getNumberedCallback()) && proto.Callback.Numbered.toObject(includeInstance, f)
34873487
};
@@ -3614,7 +3614,7 @@ proto.Callback.Named.prototype.toObject = function(opt_includeInstance) {
36143614
* @suppress {unusedLocalVariables} f is only used for nested messages
36153615
*/
36163616
proto.Callback.Named.toObject = function(includeInstance, msg) {
3617-
var obj = {
3617+
var f, obj = {
36183618
module: jspb.Message.getFieldWithDefault(msg, 1, 0),
36193619
callbackId: jspb.Message.getFieldWithDefault(msg, 2, 0),
36203620
argsList: jspb.Message.toObjectList(msg.getArgsList(),
@@ -3822,7 +3822,7 @@ proto.Callback.Numbered.prototype.toObject = function(opt_includeInstance) {
38223822
* @suppress {unusedLocalVariables} f is only used for nested messages
38233823
*/
38243824
proto.Callback.Numbered.toObject = function(includeInstance, msg) {
3825-
var obj = {
3825+
var f, obj = {
38263826
proxyId: jspb.Message.getFieldWithDefault(msg, 1, 0),
38273827
callbackId: jspb.Message.getFieldWithDefault(msg, 2, 0),
38283828
argsList: jspb.Message.toObjectList(msg.getArgsList(),
@@ -4115,7 +4115,7 @@ proto.Event.prototype.toObject = function(opt_includeInstance) {
41154115
* @suppress {unusedLocalVariables} f is only used for nested messages
41164116
*/
41174117
proto.Event.toObject = function(includeInstance, msg) {
4118-
var obj = {
4118+
var f, obj = {
41194119
namedEvent: (f = msg.getNamedEvent()) && proto.Event.Named.toObject(includeInstance, f),
41204120
numberedEvent: (f = msg.getNumberedEvent()) && proto.Event.Numbered.toObject(includeInstance, f)
41214121
};
@@ -4248,7 +4248,7 @@ proto.Event.Named.prototype.toObject = function(opt_includeInstance) {
42484248
* @suppress {unusedLocalVariables} f is only used for nested messages
42494249
*/
42504250
proto.Event.Named.toObject = function(includeInstance, msg) {
4251-
var obj = {
4251+
var f, obj = {
42524252
module: jspb.Message.getFieldWithDefault(msg, 1, 0),
42534253
event: jspb.Message.getFieldWithDefault(msg, 2, ""),
42544254
argsList: jspb.Message.toObjectList(msg.getArgsList(),
@@ -4456,7 +4456,7 @@ proto.Event.Numbered.prototype.toObject = function(opt_includeInstance) {
44564456
* @suppress {unusedLocalVariables} f is only used for nested messages
44574457
*/
44584458
proto.Event.Numbered.toObject = function(includeInstance, msg) {
4459-
var obj = {
4459+
var f, obj = {
44604460
proxyId: jspb.Message.getFieldWithDefault(msg, 1, 0),
44614461
event: jspb.Message.getFieldWithDefault(msg, 2, ""),
44624462
argsList: jspb.Message.toObjectList(msg.getArgsList(),
@@ -4723,7 +4723,7 @@ proto.Ping.prototype.toObject = function(opt_includeInstance) {
47234723
* @suppress {unusedLocalVariables} f is only used for nested messages
47244724
*/
47254725
proto.Ping.toObject = function(includeInstance, msg) {
4726-
var obj = {
4726+
var f, obj = {
47274727

47284728
};
47294729

@@ -4822,7 +4822,7 @@ proto.Pong.prototype.toObject = function(opt_includeInstance) {
48224822
* @suppress {unusedLocalVariables} f is only used for nested messages
48234823
*/
48244824
proto.Pong.toObject = function(includeInstance, msg) {
4825-
var obj = {
4825+
var f, obj = {
48264826

48274827
};
48284828

packages/protocol/src/proto/vscode_pb.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ proto.SharedProcessActive.prototype.toObject = function(opt_includeInstance) {
6262
* @suppress {unusedLocalVariables} f is only used for nested messages
6363
*/
6464
proto.SharedProcessActive.toObject = function(includeInstance, msg) {
65-
var obj = {
65+
var f, obj = {
6666
socketPath: jspb.Message.getFieldWithDefault(msg, 1, ""),
6767
logPath: jspb.Message.getFieldWithDefault(msg, 2, "")
6868
};

0 commit comments

Comments
 (0)