Extract ripgrep when inside binary

This commit is contained in:
Asher 2019-07-16 19:26:05 -05:00
parent db41f106bc
commit 4b0cceb91a
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
3 changed files with 28 additions and 3 deletions

View File

@ -1,8 +1,17 @@
/* global require, global, process, __dirname */
if (!global.NBIN_LOADED) { if (!global.NBIN_LOADED) {
try { try {
const nbin = require("nbin"); const nbin = require("nbin");
nbin.shimNativeFs("{{ROOT_PATH}}"); nbin.shimNativeFs("{{ROOT_PATH}}");
global.NBIN_LOADED = true; global.NBIN_LOADED = true;
const path = require("path");
const rg = require("vscode-ripgrep");
rg.binaryRgPath = rg.rgPath;
rg.rgPath = path.join(
require("os").tmpdir(),
`code-server/${path.basename(rg.binaryRgPath)}`,
);
} catch (error) { } catch (error) {
// Not in the binary. // Not in the binary.
} }

View File

@ -10,7 +10,7 @@ import product from "vs/platform/product/node/product";
import { MainServer, WebviewServer } from "vs/server/src/server"; import { MainServer, WebviewServer } from "vs/server/src/server";
import "vs/server/src/tar"; import "vs/server/src/tar";
import { generateCertificate, generatePassword, open } from "vs/server/src/util"; import { generateCertificate, generatePassword, open, unpackExecutables } from "vs/server/src/util";
interface Args extends ParsedArgs { interface Args extends ParsedArgs {
"allow-http"?: boolean; "allow-http"?: boolean;
@ -167,9 +167,10 @@ const main = async (): Promise<void> => {
socket: args.socket, socket: args.socket,
}, webviewServer, args); }, webviewServer, args);
const [webviewAddress, serverAddress] = await Promise.all([ const [webviewAddress, serverAddress, /* ignore */] = await Promise.all([
webviewServer.listen(), webviewServer.listen(),
server.listen() server.listen(),
unpackExecutables(),
]); ]);
console.log(`Main server listening on ${serverAddress}`); console.log(`Main server listening on ${serverAddress}`);
console.log(`Webview server listening on ${webviewAddress}`); console.log(`Webview server listening on ${webviewAddress}`);

View File

@ -4,6 +4,7 @@ import * as fs from "fs";
import * as os from "os"; import * as os from "os";
import * as path from "path"; import * as path from "path";
import * as util from "util"; import * as util from "util";
import * as rg from "vscode-ripgrep";
import { getPathFromAmdModule } from "vs/base/common/amd"; import { getPathFromAmdModule } from "vs/base/common/amd";
import { getMediaMime as vsGetMediaMime } from "vs/base/common/mime"; import { getMediaMime as vsGetMediaMime } from "vs/base/common/mime";
@ -114,3 +115,17 @@ export const open = async (url: string): Promise<void> => {
}); });
}); });
}; };
/**
* Extract executables to the temporary directory. This is required since we
* can't execute binaries stored within our binary.
*/
export const unpackExecutables = async (): Promise<void> => {
const rgPath = (rg as any).binaryRgPath;
if (rgPath) {
await mkdirp(tmpdir);
const destination = path.join(tmpdir, path.basename(rgPath));
await util.promisify(fs.copyFile)(rgPath, destination);
await util.promisify(fs.chmod)(destination, "755");
}
};