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:
@ -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));
|
||||
};
|
||||
|
@ -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");
|
||||
};
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user