Skip to content

Commit fcf4efb

Browse files
committed
Extract ripgrep when inside binary
1 parent ef9b00b commit fcf4efb

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

scripts/nbin-shim.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
/* global require, global, process, __dirname */
12
if (!global.NBIN_LOADED) {
23
try {
34
const nbin = require("nbin");
45
nbin.shimNativeFs("{{ROOT_PATH}}");
56
global.NBIN_LOADED = true;
7+
8+
const path = require("path");
9+
const rg = require("vscode-ripgrep");
10+
rg.binaryRgPath = rg.rgPath;
11+
rg.rgPath = path.join(
12+
require("os").tmpdir(),
13+
`code-server/${path.basename(rg.binaryRgPath)}`,
14+
);
615
} catch (error) {
716
// Not in the binary.
817
}

src/cli.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import product from "vs/platform/product/node/product";
1010

1111
import { MainServer, WebviewServer } from "vs/server/src/server";
1212
import "vs/server/src/tar";
13-
import { generateCertificate, generatePassword, open } from "vs/server/src/util";
13+
import { generateCertificate, generatePassword, open, unpackExecutables } from "vs/server/src/util";
1414

1515
interface Args extends ParsedArgs {
1616
"allow-http"?: boolean;
@@ -167,9 +167,10 @@ const main = async (): Promise<void> => {
167167
socket: args.socket,
168168
}, webviewServer, args);
169169

170-
const [webviewAddress, serverAddress] = await Promise.all([
170+
const [webviewAddress, serverAddress, /* ignore */] = await Promise.all([
171171
webviewServer.listen(),
172-
server.listen()
172+
server.listen(),
173+
unpackExecutables(),
173174
]);
174175
console.log(`Main server listening on ${serverAddress}`);
175176
console.log(`Webview server listening on ${webviewAddress}`);

src/util.ts

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as fs from "fs";
44
import * as os from "os";
55
import * as path from "path";
66
import * as util from "util";
7+
import * as rg from "vscode-ripgrep";
78

89
import { getPathFromAmdModule } from "vs/base/common/amd";
910
import { getMediaMime as vsGetMediaMime } from "vs/base/common/mime";
@@ -114,3 +115,17 @@ export const open = async (url: string): Promise<void> => {
114115
});
115116
});
116117
};
118+
119+
/**
120+
* Extract executables to the temporary directory. This is required since we
121+
* can't execute binaries stored within our binary.
122+
*/
123+
export const unpackExecutables = async (): Promise<void> => {
124+
const rgPath = (rg as any).binaryRgPath;
125+
if (rgPath) {
126+
await mkdirp(tmpdir);
127+
const destination = path.join(tmpdir, path.basename(rgPath));
128+
await util.promisify(fs.copyFile)(rgPath, destination);
129+
await util.promisify(fs.chmod)(destination, "755");
130+
}
131+
};

0 commit comments

Comments
 (0)