Add ripgrep, fill native fs functions, add ping endpoint (#39)

* Add ripgrep, fill native fs functions, add ping endpoint

* Make show in folder redirect to the workspace
This commit is contained in:
Kyle Carberry 2019-02-27 15:12:26 -06:00 committed by GitHub
parent 3bacbca325
commit 676b30934f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 13 deletions

View File

@ -83,6 +83,10 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
const browserAppOutputPath = path.join(pkgsPath, "app", "browser", "out");
const nodePtyModule = path.join(pkgsPath, "protocol", "node_modules", "node-pty", "build", "Release", "pty.node");
const spdlogModule = path.join(pkgsPath, "protocol", "node_modules", "spdlog", "build", "Release", "spdlog.node");
let ripgrepPath = path.join(pkgsPath, "..", "lib", "vscode", "node_modules", "vscode-ripgrep", "bin", "rg");
if (os.platform() === "win32") {
ripgrepPath += ".exe";
}
if (!fs.existsSync(nodePtyModule)) {
throw new Error("Could not find pty.node. Ensure all packages have been installed");
@ -99,6 +103,9 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
if (!fs.existsSync(bootstrapForkPath)) {
throw new Error("Bootstrap fork must exist");
}
if (!fs.existsSync(ripgrepPath)) {
throw new Error("Ripgrep must exist");
}
fse.copySync(defaultExtensionsPath, path.join(cliBuildPath, "extensions"));
fs.writeFileSync(path.join(cliBuildPath, "bootstrap-fork.js.gz"), zlib.gzipSync(fs.readFileSync(bootstrapForkPath)));
const cpDir = (dir: string, subdir: "auth" | "unauth", rootPath: string): void => {
@ -116,9 +123,10 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
};
cpDir(webOutputPath, "auth", webOutputPath);
cpDir(browserAppOutputPath, "unauth", browserAppOutputPath);
fse.mkdirpSync(path.join(cliBuildPath, "modules"));
fse.copySync(nodePtyModule, path.join(cliBuildPath, "modules", "pty.node"));
fse.copySync(spdlogModule, path.join(cliBuildPath, "modules", "spdlog.node"));
fse.mkdirpSync(path.join(cliBuildPath, "dependencies"));
fse.copySync(nodePtyModule, path.join(cliBuildPath, "dependencies", "pty.node"));
fse.copySync(spdlogModule, path.join(cliBuildPath, "dependencies", "spdlog.node"));
fse.copySync(ripgrepPath, path.join(cliBuildPath, "dependencies", "rg"));
});
const buildServerBundle = register("build:server:bundle", async (runner) => {

View File

@ -6,7 +6,7 @@ const path = require("path");
const nexePath = require.resolve("nexe");
const shimPath = path.join(path.dirname(nexePath), "lib/steps/shim.js");
let shimContent = fs.readFileSync(shimPath).toString();
const replaceString = `global.nativeFs = { readdir: originalReaddir, readdirSync: originalReaddirSync };`;
const replaceString = `global.nativeFs = { existsSync: originalExistsSync, readFile: originalReadFile, readFileSync: originalReadFileSync, createReadStream: originalCreateReadStream, readdir: originalReaddir, readdirSync: originalReaddirSync, statSync: originalStatSync, stat: originalStat, realpath: originalRealpath, realpathSync: originalRealpathSync };`;
shimContent = shimContent.replace(/compiler\.options\.resources\.length[\s\S]*wrap\("(.*\\n)"/g, (om, a) => {
return om.replace(a, `${a}${replaceString}`);
});

View File

@ -161,4 +161,35 @@ export const fillFs = (): void => {
return nativeFs.readdir(directory, callback);
});
const fillNativeFunc = <T extends keyof typeof fs>(propertyName: T): void => {
replaceNative(propertyName, (callOld, newPath, ...args) => {
if (typeof newPath !== "string") {
return callOld();
}
const rel = path.relative(newPath, buildDir!);
if (rel.startsWith("..")) {
return callOld();
}
const func = nativeFs[propertyName] as any;
return func(newPath, ...args);
});
};
const properties: Array<keyof typeof fs> = [
"existsSync",
"readFile",
"readFileSync",
"createReadStream",
"readdir",
"readdirSync",
"statSync",
"stat",
"realpath",
"realpathSync",
];
properties.forEach((p) => fillNativeFunc(p));
};

View File

@ -8,7 +8,7 @@ declare var __non_webpack_require__: typeof require;
* Handling of native modules within the CLI
*/
export const setup = (dataDirectory: string): void => {
path.resolve(dataDirectory, "modules").split(path.sep).reduce((parentDir, childDir) => {
path.resolve(dataDirectory, "dependencies").split(path.sep).reduce((parentDir, childDir) => {
const currentDir = path.join(parentDir, childDir);
try {
fs.mkdirSync(currentDir);
@ -22,8 +22,8 @@ export const setup = (dataDirectory: string): void => {
}, path.sep);
const unpackModule = (moduleName: string): void => {
const memFile = path.join(isCli ? buildDir! : path.join(__dirname, ".."), "build/modules", moduleName + ".node");
const diskFile = path.join(dataDirectory, "modules", moduleName + ".node");
const memFile = path.join(isCli ? buildDir! : path.join(__dirname, ".."), "build/dependencies", moduleName);
const diskFile = path.join(dataDirectory, "dependencies", moduleName);
if (!fs.existsSync(diskFile)) {
fs.writeFileSync(diskFile, fs.readFileSync(memFile));
}
@ -34,15 +34,17 @@ export const setup = (dataDirectory: string): void => {
* If pty.node isn't unpacked a SIGSEGV is thrown and the application exits. The exact reasoning
* for this is unknown ATM, but this patch works around it.
*/
unpackModule("pty");
unpackModule("spdlog");
unpackModule("pty.node");
unpackModule("spdlog.node");
unpackModule("rg");
const nodePtyUtils = require("../../protocol/node_modules/node-pty/lib/utils") as typeof import("../../protocol/node_modules/node-pty/src/utils");
// tslint:disable-next-line:no-any
nodePtyUtils.loadNative = (modName: string): any => {
return (typeof __non_webpack_require__ !== "undefined" ? __non_webpack_require__ : require)(path.join(dataDirectory, "modules", modName + ".node"));
return (typeof __non_webpack_require__ !== "undefined" ? __non_webpack_require__ : require)(path.join(dataDirectory, "dependencies", modName + ".node"));
};
(<any>global).RIPGREP_LOCATION = path.join(dataDirectory, "dependencies", "rg");
// tslint:disable-next-line:no-any
(<any>global).SPDLOG_LOCATION = path.join(dataDirectory, "modules", "spdlog.node");
(<any>global).SPDLOG_LOCATION = path.join(dataDirectory, "dependencies", "spdlog.node");
// tslint:disable-next-line:no-unused-expression
require("../../protocol/node_modules/node-pty/lib/index") as typeof import("../../protocol/node_modules/node-pty/src/index");
};

View File

@ -11,6 +11,7 @@ import * as httpolyglot from "httpolyglot";
import * as https from "https";
import * as mime from "mime-types";
import * as net from "net";
import * as os from "os";
import * as path from "path";
import * as pem from "pem";
import * as util from "util";
@ -168,6 +169,11 @@ export const createApp = async (options: CreateAppOptions): Promise<{
unauthStaticFunc(req, res, next);
}
});
app.get("/ping", (req, res) => {
res.json({
hostname: os.hostname(),
});
});
app.get("/resource/:url(*)", async (req, res) => {
if (!ensureAuthed(req, res)) {
return;

View File

@ -0,0 +1,4 @@
import * as path from "path";
// tslint:disable-next-line:no-any
module.exports.rgPath = (<any>global).RIPGREP_LOCATION || path.join(__dirname, "../bin/rg");

View File

@ -308,8 +308,8 @@ class WindowsService implements IWindowsService {
throw new Error("not implemented");
}
public showItemInFolder(_path: string): Promise<void> {
throw new Error("not implemented");
public async showItemInFolder(_path: string): Promise<void> {
workbench.workspace = URI.file(_path);
}
public getActiveWindowId(): Promise<number | undefined> {

View File

@ -52,6 +52,7 @@ module.exports = merge(
"vs/base/browser/browser": path.resolve(fills, "empty.ts"),
"electron": path.join(vsFills, "stdioElectron.ts"),
"vscode-ripgrep": path.join(vsFills, "ripgrep.ts"),
"native-keymap": path.join(vsFills, "native-keymap.ts"),
"native-watchdog": path.join(vsFills, "native-watchdog.ts"),
"vs/base/common/amd": path.resolve(vsFills, "amd.ts"),