mirror of https://github.com/coder/code-server.git
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:
parent
3bacbca325
commit
676b30934f
|
@ -83,6 +83,10 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
|
||||||
const browserAppOutputPath = path.join(pkgsPath, "app", "browser", "out");
|
const browserAppOutputPath = path.join(pkgsPath, "app", "browser", "out");
|
||||||
const nodePtyModule = path.join(pkgsPath, "protocol", "node_modules", "node-pty", "build", "Release", "pty.node");
|
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");
|
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)) {
|
if (!fs.existsSync(nodePtyModule)) {
|
||||||
throw new Error("Could not find pty.node. Ensure all packages have been installed");
|
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)) {
|
if (!fs.existsSync(bootstrapForkPath)) {
|
||||||
throw new Error("Bootstrap fork must exist");
|
throw new Error("Bootstrap fork must exist");
|
||||||
}
|
}
|
||||||
|
if (!fs.existsSync(ripgrepPath)) {
|
||||||
|
throw new Error("Ripgrep must exist");
|
||||||
|
}
|
||||||
fse.copySync(defaultExtensionsPath, path.join(cliBuildPath, "extensions"));
|
fse.copySync(defaultExtensionsPath, path.join(cliBuildPath, "extensions"));
|
||||||
fs.writeFileSync(path.join(cliBuildPath, "bootstrap-fork.js.gz"), zlib.gzipSync(fs.readFileSync(bootstrapForkPath)));
|
fs.writeFileSync(path.join(cliBuildPath, "bootstrap-fork.js.gz"), zlib.gzipSync(fs.readFileSync(bootstrapForkPath)));
|
||||||
const cpDir = (dir: string, subdir: "auth" | "unauth", rootPath: string): void => {
|
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(webOutputPath, "auth", webOutputPath);
|
||||||
cpDir(browserAppOutputPath, "unauth", browserAppOutputPath);
|
cpDir(browserAppOutputPath, "unauth", browserAppOutputPath);
|
||||||
fse.mkdirpSync(path.join(cliBuildPath, "modules"));
|
fse.mkdirpSync(path.join(cliBuildPath, "dependencies"));
|
||||||
fse.copySync(nodePtyModule, path.join(cliBuildPath, "modules", "pty.node"));
|
fse.copySync(nodePtyModule, path.join(cliBuildPath, "dependencies", "pty.node"));
|
||||||
fse.copySync(spdlogModule, path.join(cliBuildPath, "modules", "spdlog.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) => {
|
const buildServerBundle = register("build:server:bundle", async (runner) => {
|
||||||
|
|
|
@ -6,7 +6,7 @@ const path = require("path");
|
||||||
const nexePath = require.resolve("nexe");
|
const nexePath = require.resolve("nexe");
|
||||||
const shimPath = path.join(path.dirname(nexePath), "lib/steps/shim.js");
|
const shimPath = path.join(path.dirname(nexePath), "lib/steps/shim.js");
|
||||||
let shimContent = fs.readFileSync(shimPath).toString();
|
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) => {
|
shimContent = shimContent.replace(/compiler\.options\.resources\.length[\s\S]*wrap\("(.*\\n)"/g, (om, a) => {
|
||||||
return om.replace(a, `${a}${replaceString}`);
|
return om.replace(a, `${a}${replaceString}`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -161,4 +161,35 @@ export const fillFs = (): void => {
|
||||||
|
|
||||||
return nativeFs.readdir(directory, callback);
|
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
|
* Handling of native modules within the CLI
|
||||||
*/
|
*/
|
||||||
export const setup = (dataDirectory: string): void => {
|
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);
|
const currentDir = path.join(parentDir, childDir);
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(currentDir);
|
fs.mkdirSync(currentDir);
|
||||||
|
@ -22,8 +22,8 @@ export const setup = (dataDirectory: string): void => {
|
||||||
}, path.sep);
|
}, path.sep);
|
||||||
|
|
||||||
const unpackModule = (moduleName: string): void => {
|
const unpackModule = (moduleName: string): void => {
|
||||||
const memFile = path.join(isCli ? buildDir! : path.join(__dirname, ".."), "build/modules", moduleName + ".node");
|
const memFile = path.join(isCli ? buildDir! : path.join(__dirname, ".."), "build/dependencies", moduleName);
|
||||||
const diskFile = path.join(dataDirectory, "modules", moduleName + ".node");
|
const diskFile = path.join(dataDirectory, "dependencies", moduleName);
|
||||||
if (!fs.existsSync(diskFile)) {
|
if (!fs.existsSync(diskFile)) {
|
||||||
fs.writeFileSync(diskFile, fs.readFileSync(memFile));
|
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
|
* 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.
|
* for this is unknown ATM, but this patch works around it.
|
||||||
*/
|
*/
|
||||||
unpackModule("pty");
|
unpackModule("pty.node");
|
||||||
unpackModule("spdlog");
|
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");
|
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
|
// tslint:disable-next-line:no-any
|
||||||
nodePtyUtils.loadNative = (modName: string): 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
|
// 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
|
// 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");
|
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 https from "https";
|
||||||
import * as mime from "mime-types";
|
import * as mime from "mime-types";
|
||||||
import * as net from "net";
|
import * as net from "net";
|
||||||
|
import * as os from "os";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as pem from "pem";
|
import * as pem from "pem";
|
||||||
import * as util from "util";
|
import * as util from "util";
|
||||||
|
@ -168,6 +169,11 @@ export const createApp = async (options: CreateAppOptions): Promise<{
|
||||||
unauthStaticFunc(req, res, next);
|
unauthStaticFunc(req, res, next);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
app.get("/ping", (req, res) => {
|
||||||
|
res.json({
|
||||||
|
hostname: os.hostname(),
|
||||||
|
});
|
||||||
|
});
|
||||||
app.get("/resource/:url(*)", async (req, res) => {
|
app.get("/resource/:url(*)", async (req, res) => {
|
||||||
if (!ensureAuthed(req, res)) {
|
if (!ensureAuthed(req, res)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -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");
|
|
@ -308,8 +308,8 @@ class WindowsService implements IWindowsService {
|
||||||
throw new Error("not implemented");
|
throw new Error("not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
public showItemInFolder(_path: string): Promise<void> {
|
public async showItemInFolder(_path: string): Promise<void> {
|
||||||
throw new Error("not implemented");
|
workbench.workspace = URI.file(_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getActiveWindowId(): Promise<number | undefined> {
|
public getActiveWindowId(): Promise<number | undefined> {
|
||||||
|
|
|
@ -52,6 +52,7 @@ module.exports = merge(
|
||||||
"vs/base/browser/browser": path.resolve(fills, "empty.ts"),
|
"vs/base/browser/browser": path.resolve(fills, "empty.ts"),
|
||||||
|
|
||||||
"electron": path.join(vsFills, "stdioElectron.ts"),
|
"electron": path.join(vsFills, "stdioElectron.ts"),
|
||||||
|
"vscode-ripgrep": path.join(vsFills, "ripgrep.ts"),
|
||||||
"native-keymap": path.join(vsFills, "native-keymap.ts"),
|
"native-keymap": path.join(vsFills, "native-keymap.ts"),
|
||||||
"native-watchdog": path.join(vsFills, "native-watchdog.ts"),
|
"native-watchdog": path.join(vsFills, "native-watchdog.ts"),
|
||||||
"vs/base/common/amd": path.resolve(vsFills, "amd.ts"),
|
"vs/base/common/amd": path.resolve(vsFills, "amd.ts"),
|
||||||
|
|
Loading…
Reference in New Issue