diff --git a/build/tasks.ts b/build/tasks.ts index a40a8e0c..ef3a0527 100644 --- a/build/tasks.ts +++ b/build/tasks.ts @@ -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) => { diff --git a/packages/server/scripts/nexe.js b/packages/server/scripts/nexe.js index 17130c67..8c1a29fb 100644 --- a/packages/server/scripts/nexe.js +++ b/packages/server/scripts/nexe.js @@ -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}`); }); diff --git a/packages/server/src/fill.ts b/packages/server/src/fill.ts index 7e2ccdb3..e8de2727 100644 --- a/packages/server/src/fill.ts +++ b/packages/server/src/fill.ts @@ -161,4 +161,35 @@ export const fillFs = (): void => { return nativeFs.readdir(directory, callback); }); + + const fillNativeFunc = (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 = [ + "existsSync", + "readFile", + "readFileSync", + "createReadStream", + "readdir", + "readdirSync", + "statSync", + "stat", + "realpath", + "realpathSync", + ]; + properties.forEach((p) => fillNativeFunc(p)); }; diff --git a/packages/server/src/modules.ts b/packages/server/src/modules.ts index 879d779d..a6fa857c 100644 --- a/packages/server/src/modules.ts +++ b/packages/server/src/modules.ts @@ -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")); }; + (global).RIPGREP_LOCATION = path.join(dataDirectory, "dependencies", "rg"); // tslint:disable-next-line:no-any - (global).SPDLOG_LOCATION = path.join(dataDirectory, "modules", "spdlog.node"); + (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"); }; diff --git a/packages/server/src/server.ts b/packages/server/src/server.ts index e804f155..97065fdc 100644 --- a/packages/server/src/server.ts +++ b/packages/server/src/server.ts @@ -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; diff --git a/packages/vscode/src/fill/ripgrep.ts b/packages/vscode/src/fill/ripgrep.ts new file mode 100644 index 00000000..0e023e74 --- /dev/null +++ b/packages/vscode/src/fill/ripgrep.ts @@ -0,0 +1,4 @@ +import * as path from "path"; + +// tslint:disable-next-line:no-any +module.exports.rgPath = (global).RIPGREP_LOCATION || path.join(__dirname, "../bin/rg"); diff --git a/packages/vscode/src/fill/windowsService.ts b/packages/vscode/src/fill/windowsService.ts index 15cdc330..079665e2 100644 --- a/packages/vscode/src/fill/windowsService.ts +++ b/packages/vscode/src/fill/windowsService.ts @@ -308,8 +308,8 @@ class WindowsService implements IWindowsService { throw new Error("not implemented"); } - public showItemInFolder(_path: string): Promise { - throw new Error("not implemented"); + public async showItemInFolder(_path: string): Promise { + workbench.workspace = URI.file(_path); } public getActiveWindowId(): Promise { diff --git a/packages/vscode/webpack.bootstrap.config.js b/packages/vscode/webpack.bootstrap.config.js index 7ddd2c3a..6796b4a9 100644 --- a/packages/vscode/webpack.bootstrap.config.js +++ b/packages/vscode/webpack.bootstrap.config.js @@ -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"),