mirror of
https://github.com/coder/code-server.git
synced 2026-06-21 17:37:11 +02:00
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));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user