Skip to content

Commit 37ae893

Browse files
committed
Fix spdlog and node-pty in binary
1 parent 1f39a9e commit 37ae893

File tree

11 files changed

+58
-81
lines changed

11 files changed

+58
-81
lines changed

build/tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
8282
const webOutputPath = path.join(pkgsPath, "web", "out");
8383
const browserAppOutputPath = path.join(pkgsPath, "app", "browser", "out");
8484
const nodePtyModule = path.join(pkgsPath, "protocol", "node_modules", "node-pty", "build", "Release", "pty.node");
85-
const spdlogModule = path.join(pkgsPath, "server", "node_modules", "spdlog", "build", "Release", "spdlog.node");
85+
const spdlogModule = path.join(pkgsPath, "protocol", "node_modules", "spdlog", "build", "Release", "spdlog.node");
8686

8787
if (!fs.existsSync(nodePtyModule)) {
8888
throw new Error("Could not find pty.node. Ensure all packages have been installed");

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
},
5151
"dependencies": {
5252
"node-loader": "^0.6.0",
53-
"spdlog": "^0.7.2",
5453
"trash": "^4.3.0",
5554
"webpack-merge": "^4.2.1"
5655
}

packages/protocol/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"express": "^4.16.4",
66
"google-protobuf": "^3.6.1",
77
"node-pty": "^0.8.1",
8+
"spdlog": "^0.7.2",
89
"tslib": "^1.9.3",
910
"ws": "^6.1.2"
1011
},

packages/protocol/src/common/helpers.ts

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference path="../../../../lib/vscode/src/typings/spdlog.d.ts" />
12
import { ChildProcess, SpawnOptions, ForkOptions } from "child_process";
23
import { EventEmitter } from "events";
34
import { Socket } from "net";
@@ -7,9 +8,6 @@ import { logger } from "@coder/logger";
78

89
// tslint:disable no-any
910

10-
declare var __non_webpack_require__: typeof require;
11-
declare var __webpack_require__: typeof require;
12-
1311
export type ForkProvider = (modulePath: string, args: string[], options: ForkOptions) => ChildProcess;
1412

1513
export interface Disposer extends IDisposable {
@@ -26,6 +24,19 @@ interface ActiveEvalEmitter {
2624
* Helper class for server-side evaluations.
2725
*/
2826
export class EvalHelper {
27+
// For any non-external modules that are not built in, we need to require and
28+
// access them here. A require on the client-side won't work since that code
29+
// won't exist on the server (and bloat the client with an unused import), and
30+
// we can't manually import on the server-side and then call
31+
// `__webpack_require__` on the client-side because Webpack stores modules by
32+
// their paths which would require us to hard-code the path. These aren't
33+
// required immediately so we have a chance to unpack the .node files and set
34+
// their locations.
35+
public modules = {
36+
spdlog: require("spdlog") as typeof import("spdlog"),
37+
pty: require("node-pty") as typeof import("node-pty"),
38+
};
39+
2940
/**
3041
* Some spawn code tries to preserve the env (the debug adapter for instance)
3142
* but the env is mostly blank (since we're in the browser), so we'll just
@@ -38,29 +49,6 @@ export class EvalHelper {
3849
options.env = { ...process.env, ...options.env };
3950
}
4051
}
41-
42-
/**
43-
* Try a non-webpack require, then a webpack require if that fails.
44-
*/
45-
public require(modulePath: string): any {
46-
logger.info(`Attempting to require ${modulePath}`);
47-
try {
48-
return __non_webpack_require__(modulePath);
49-
} catch (error) { /* Nothing. */ }
50-
51-
logger.warn(`Non-webpack require failed for ${modulePath}`);
52-
try {
53-
return __webpack_require__(modulePath);
54-
} catch (error) { /* Nothing. */ }
55-
56-
logger.warn(`Webpack require failed for ${modulePath}`);
57-
try {
58-
return require(modulePath);
59-
} catch (error) {
60-
logger.error(`Failed to require ${modulePath}`);
61-
throw error;
62-
}
63-
}
6452
}
6553

6654
/**
@@ -125,20 +113,17 @@ export class ActiveEvalHelper implements ActiveEvalEmitter {
125113
* Helper class for server-side active evaluations.
126114
*/
127115
export class ServerActiveEvalHelper extends ActiveEvalHelper implements EvalHelper {
128-
private readonly evalHelper: EvalHelper;
116+
private readonly evalHelper = new EvalHelper();
117+
public modules = this.evalHelper.modules;
118+
129119
public constructor(emitter: ActiveEvalEmitter, public readonly fork: ForkProvider) {
130120
super(emitter);
131-
this.evalHelper = new EvalHelper();
132121
}
133122

134123
public preserveEnv(options: SpawnOptions | ForkOptions): void {
135124
this.evalHelper.preserveEnv(options);
136125
}
137126

138-
public require(modulePath: string): any {
139-
return this.evalHelper.require(modulePath);
140-
}
141-
142127
/**
143128
* If there is a callback ID, return a function that emits the callback event
144129
* on the active evaluation with that ID and all arguments passed to it.

packages/protocol/yarn.lock

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ async-limiter@~1.0.0:
3030
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8"
3131
integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==
3232

33+
bindings@^1.3.0:
34+
version "1.4.0"
35+
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.4.0.tgz#909efa49f2ebe07ecd3cb136778f665052040127"
36+
integrity sha512-7znEVX22Djn+nYjxCWKDne0RRloa9XfYa84yk3s+HkE3LpDYZmhArYr9O9huBoHY3/oXispx5LorIX7Sl2CgSQ==
37+
dependencies:
38+
file-uri-to-path "1.0.0"
39+
3340
3441
version "1.18.3"
3542
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.18.3.tgz#5b292198ffdd553b3a0f20ded0592b956955c8b4"
@@ -144,6 +151,11 @@ express@^4.16.4:
144151
utils-merge "1.0.1"
145152
vary "~1.1.2"
146153

154+
155+
version "1.0.0"
156+
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
157+
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==
158+
147159
148160
version "1.1.1"
149161
resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.1.1.tgz#eebf4ed840079c83f4249038c9d703008301b105"
@@ -231,12 +243,24 @@ [email protected]:
231243
resolved "https://registry.yarnpkg.com/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6"
232244
integrity sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==
233245

246+
247+
version "0.0.8"
248+
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
249+
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=
250+
251+
mkdirp@^0.5.1:
252+
version "0.5.1"
253+
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
254+
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
255+
dependencies:
256+
minimist "0.0.8"
257+
234258
235259
version "2.0.0"
236260
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
237261
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=
238262

239-
263+
[email protected], nan@^2.8.0:
240264
version "2.12.1"
241265
resolved "https://registry.yarnpkg.com/nan/-/nan-2.12.1.tgz#7b1aa193e9aa86057e3c7bbd0ac448e770925552"
242266
integrity sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==
@@ -342,6 +366,15 @@ [email protected]:
342366
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.0.tgz#d0bd85536887b6fe7c0d818cb962d9d91c54e656"
343367
integrity sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==
344368

369+
spdlog@^0.7.2:
370+
version "0.7.2"
371+
resolved "https://registry.yarnpkg.com/spdlog/-/spdlog-0.7.2.tgz#9298753d7694b9ee9bbfd7e01ea1e4c6ace1e64d"
372+
integrity sha512-rHfWCaWMD4NindDnql6rc6kn7Bs8JR92jhiUpCl3D6v+jYcQ6GozMLig0RliOOR8st5mU+IHLZnr15fBys5x/Q==
373+
dependencies:
374+
bindings "^1.3.0"
375+
mkdirp "^0.5.1"
376+
nan "^2.8.0"
377+
345378
"statuses@>= 1.4.0 < 2":
346379
version "1.5.0"
347380
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"

packages/server/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"node-netstat": "^1.6.0",
2525
"pem": "^1.14.1",
2626
"promise.prototype.finally": "^3.1.0",
27-
"spdlog": "^0.7.2",
2827
"ws": "^6.1.2",
2928
"xhr2": "^0.1.4"
3029
},

packages/server/src/cli.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export class Entry extends Command {
8080
if (!fs.existsSync(dataDir)) {
8181
fs.mkdirSync(dataDir);
8282
}
83-
require("spdlog");
8483

8584
const logDir = path.join(dataDir, "logs", new Date().toISOString().replace(/[-:.TZ]/g, ""));
8685
process.env.VSCODE_LOGS = logDir;

packages/server/yarn.lock

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,6 @@ binary-extensions@^1.0.0:
437437
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.12.0.tgz#c2d780f53d45bba8317a8902d4ceeaf3a6385b14"
438438
integrity sha512-DYWGk01lDcxeS/K9IHPGWfT8PsJmbXRtRd2Sx72Tnb8pcYZQFF1oSDb8hJtS1vhp212q1Rzi5dUf9+nq0o9UIg==
439439

440-
bindings@^1.3.0:
441-
version "1.3.1"
442-
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.1.tgz#21fc7c6d67c18516ec5aaa2815b145ff77b26ea5"
443-
integrity sha512-i47mqjF9UbjxJhxGf+pZ6kSxrnI3wBLlnGI2ArWJ4r0VrvDS7ZYXkprq/pLaBWYq4GM0r4zdHY+NNRqEMU7uew==
444-
445440
bl@^1.0.0:
446441
version "1.2.2"
447442
resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.2.tgz#a160911717103c07410cef63ef51b397c025af9c"
@@ -2447,7 +2442,7 @@ [email protected]:
24472442
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
24482443
integrity sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=
24492444

2450-
nan@^2.8.0, nan@^2.9.2:
2445+
nan@^2.9.2:
24512446
version "2.12.1"
24522447
resolved "https://registry.yarnpkg.com/nan/-/nan-2.12.1.tgz#7b1aa193e9aa86057e3c7bbd0ac448e770925552"
24532448
integrity sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==
@@ -3327,15 +3322,6 @@ source-map@~0.1.38:
33273322
dependencies:
33283323
amdefine ">=0.0.4"
33293324

3330-
spdlog@^0.7.2:
3331-
version "0.7.2"
3332-
resolved "https://registry.yarnpkg.com/spdlog/-/spdlog-0.7.2.tgz#9298753d7694b9ee9bbfd7e01ea1e4c6ace1e64d"
3333-
integrity sha512-rHfWCaWMD4NindDnql6rc6kn7Bs8JR92jhiUpCl3D6v+jYcQ6GozMLig0RliOOR8st5mU+IHLZnr15fBys5x/Q==
3334-
dependencies:
3335-
bindings "^1.3.0"
3336-
mkdirp "^0.5.1"
3337-
nan "^2.8.0"
3338-
33393325
split-string@^3.0.1, split-string@^3.0.2:
33403326
version "3.1.0"
33413327
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"

packages/vscode/src/fill/node-pty.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ class Pty implements nodePty.IPty {
1515

1616
public constructor(file: string, args: string[] | string, options: nodePty.IPtyForkOptions) {
1717
this.ae = client.run((ae, file, args, options) => {
18-
const nodePty = ae.require("node-pty") as typeof import("node-pty");
19-
2018
ae.preserveEnv(options);
2119

22-
const ptyProc = nodePty.spawn(file, args, options);
20+
const ptyProc = ae.modules.pty.spawn(file, args, options);
2321

2422
let process = ptyProc.process;
2523
ae.emit("process", process);

packages/vscode/src/fill/spdlog.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
/// <reference path="../../../../lib/vscode/src/typings/spdlog.d.ts" />
21
import { RotatingLogger as NodeRotatingLogger } from "spdlog";
32
import { logger } from "@coder/logger";
43
import { client } from "@coder/ide/src/fill/client";
54

65
const ae = client.run((ae) => {
7-
const spdlog = ae.require("spdlog") as typeof import("spdlog");
86
const loggers = new Map<number, NodeRotatingLogger>();
97

108
ae.on("new", (id: number, name: string, filePath: string, fileSize: number, fileCount: number) => {
11-
const logger = new spdlog.RotatingLogger(name, filePath, fileSize, fileCount);
9+
const logger = new ae.modules.spdlog.RotatingLogger(name, filePath, fileSize, fileCount);
1210
loggers.set(id, logger);
1311
});
1412

@@ -19,7 +17,7 @@ const ae = client.run((ae) => {
1917
ae.on("errorLog", (id: number, message: string) => loggers.get(id)!.error(message));
2018
ae.on("flush", (id: number) => loggers.get(id)!.flush());
2119
ae.on("info", (id: number, message: string) => loggers.get(id)!.info(message));
22-
ae.on("setAsyncMode", (bufferSize: number, flushInterval: number) => spdlog.setAsyncMode(bufferSize, flushInterval));
20+
ae.on("setAsyncMode", (bufferSize: number, flushInterval: number) => ae.modules.spdlog.setAsyncMode(bufferSize, flushInterval));
2321
ae.on("setLevel", (id: number, level: number) => loggers.get(id)!.setLevel(level));
2422
ae.on("trace", (id: number, message: string) => loggers.get(id)!.trace(message));
2523
ae.on("warn", (id: number, message: string) => loggers.get(id)!.warn(message));

0 commit comments

Comments
 (0)