1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-28 13:15:25 +00:00

Add constants file

This commit is contained in:
Asher 2019-02-07 11:47:00 -06:00
parent 81f48b8b06
commit 86d70ec790
No known key found for this signature in database
GPG Key ID: 7BB4BA9C783D2BBC
8 changed files with 27 additions and 20 deletions

View File

@ -1,8 +1,9 @@
out
cli*
!cli.ts
build
resources
# This file is generated when the binary is created.
# We want to use the parent tsconfig so we can ignore it.
tsconfig.json
tsconfig.json

View File

@ -8,7 +8,7 @@
"build:webpack": "rm -rf ./out && export CLI=true && ../../node_modules/.bin/webpack --config ./webpack.config.js",
"build:nexe": "node scripts/nexe.js",
"build:bootstrap-fork": "cd ../vscode && npm run build:bootstrap-fork; mkdir -p ./packages/server/resources; cp ./bin/bootstrap-fork.js ../server/resources/bootstrap-fork.js",
"build:default-extensions": "cd ../../lib/vscode && npx gulp vscode-linux-arm && cd ../.. && mkdir -p ./packages/server/resources; cp -r ./lib/VSCode-linux-arm/resources/app/extensions/* ./packages/server/resources/extensions/",
"build:default-extensions": "cd ../../lib/vscode && npx gulp vscode-linux-arm && cd ../.. && mkdir -p ./packages/server/resources/extensions; cp -r ./lib/VSCode-linux-arm/resources/app/extensions/* ./packages/server/resources/extensions/",
"build:web": "cd ../web; rm -rf ./out; NODE_ENV=production npm run build; rm -rf ../server/resources/web; mkdir -p ../server/resources/web; cp -r ./out/* ../server/resources/web",
"build": "npm run build:bootstrap-fork && npm run build:webpack && npm run build:nexe"
},

View File

@ -10,6 +10,7 @@ import { requireModule } from "./vscode/bootstrapFork";
import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess";
import { setup as setupNativeModules } from "./modules";
import { fillFs } from "./fill";
import { isCli, serveStatic, buildDir } from "./constants";
export class Entry extends Command {
public static description = "Start your own self-hosted browser-accessible VS Code";
@ -50,7 +51,7 @@ export class Entry extends Command {
logger.warn("Failed to remove extracted dependency.", field("dependency", "spdlog"), field("error", ex.message));
}
if (process.env.CLI) {
if (isCli) {
fillFs();
}
@ -60,7 +61,7 @@ export class Entry extends Command {
Object.assign(process.env, JSON.parse(flags.env));
}
const builtInExtensionsDir = path.join(process.env.BUILD_DIR || path.join(__dirname, ".."), "build/extensions");
const builtInExtensionsDir = path.join(buildDir || path.join(__dirname, ".."), "build/extensions");
if (flags["bootstrap-fork"]) {
const modulePath = flags["bootstrap-fork"];
if (!modulePath) {
@ -74,8 +75,8 @@ export class Entry extends Command {
const dataDir = flags["data-dir"] || path.join(os.homedir(), ".vscode-remote");
const workingDir = args["workdir"];
if (process.env.BUILD_DIR && process.env.BUILD_DIR.startsWith(workingDir)) {
logger.error("Cannot run binary inside of BUILD_DIR", field("build_dir", process.env.BUILD_DIR), field("cwd", process.cwd()));
if (buildDir && buildDir.startsWith(workingDir)) {
logger.error("Cannot run binary inside of BUILD_DIR", field("build_dir", buildDir), field("cwd", process.cwd()));
process.exit(1);
}
@ -114,7 +115,7 @@ export class Entry extends Command {
next();
});
if ((process.env.CLI === "false" || !process.env.CLI) && !process.env.SERVE_STATIC) {
if (!isCli && !serveStatic) {
const webpackConfig = require(path.join(__dirname, "..", "..", "web", "webpack.config.js"));
const compiler = require("webpack")(webpackConfig);
app.use(require("webpack-dev-middleware")(compiler, {
@ -163,6 +164,6 @@ export class Entry extends Command {
}
Entry.run(undefined, {
root: process.env.BUILD_DIR as string || __dirname,
root: buildDir || __dirname,
//@ts-ignore
}).catch(require("@oclif/errors/handle"));

View File

@ -0,0 +1,3 @@
export const isCli = typeof process.env.CLI !== "undefined" && process.env.CLI !== "false";
export const serveStatic = typeof process.env.SERVE_STATIC !== "undefined" && process.env.SERVE_STATIC !== "false";
export const buildDir = process.env.BUILD_DIR;

View File

@ -1,5 +1,6 @@
import * as fs from "fs";
import * as util from "util";
import { isCli } from "./constants";
const oldAccess = fs.access;
const existsWithinBinary = (path: fs.PathLike): Promise<boolean> => {
@ -24,7 +25,7 @@ export const fillFs = (): void => {
* For impls
*/
if (!process.env.CLI) {
if (!isCli) {
throw new Error("Should not fill FS when not in CLI");
}

View File

@ -1,5 +1,6 @@
import * as fs from "fs";
import * as path from "path";
import { isCli, buildDir } from "./constants";
declare var __non_webpack_require__: typeof require;
@ -7,7 +8,7 @@ declare var __non_webpack_require__: typeof require;
* Handling of native modules within the CLI
*/
export const setup = (dataDirectory: string): void => {
if (!process.env.CLI) {
if (!isCli) {
return;
}
@ -20,7 +21,7 @@ export const setup = (dataDirectory: string): void => {
}
const unpackModule = (moduleName: string): void => {
const memFile = path.join(process.env.BUILD_DIR!, "build/modules", moduleName + ".node");
const memFile = path.join(buildDir!, "build/modules", moduleName + ".node");
const diskFile = path.join(dataDirectory, "modules", moduleName + ".node");
if (!fs.existsSync(diskFile)) {
fs.writeFileSync(diskFile, fs.readFileSync(memFile));
@ -38,4 +39,4 @@ export const setup = (dataDirectory: string): void => {
return __non_webpack_require__(path.join(dataDirectory, "modules", modName + ".node"));
};
require("../../protocol/node_modules/node-pty/lib/index") as typeof import("../../protocol/node_modules/node-pty/src/index");
};
};

View File

@ -13,6 +13,7 @@ import * as path from "path";
import * as util from "util";
import * as ws from "ws";
import { forkModule } from "./vscode/bootstrapFork";
import { isCli, buildDir } from "./constants";
export const createApp = (registerMiddleware?: (app: express.Application) => void, options?: ServerOptions): {
readonly express: express.Application;
@ -69,8 +70,8 @@ export const createApp = (registerMiddleware?: (app: express.Application) => voi
} : undefined);
});
const baseDir = process.env.BUILD_DIR || path.join(__dirname, "..");
if (process.env.CLI) {
const baseDir = buildDir || path.join(__dirname, "..");
if (isCli) {
app.use(expressStaticGzip(path.join(baseDir, "build/web")));
} else {
app.use(express.static(path.join(baseDir, "resources/web")));
@ -84,16 +85,14 @@ export const createApp = (registerMiddleware?: (app: express.Application) => voi
// }
const exists = fs.existsSync(fullPath);
if (!exists) {
res.status(404).end();
return;
return res.status(404).end();
}
const stat = await util.promisify(fs.stat)(fullPath);
if (!stat.isFile()) {
res.write("Resource must be a file.");
res.status(422);
res.end();
return;
return res.end();
}
let mimeType = mime.lookup(fullPath);
if (mimeType === false) {

View File

@ -3,6 +3,7 @@ import * as fs from "fs";
import * as path from "path";
import * as zlib from "zlib";
import * as vm from "vm";
import { isCli } from "../constants";
export const requireModule = (modulePath: string, builtInExtensionsDir: string): void => {
process.env.AMD_ENTRYPOINT = modulePath;
@ -37,7 +38,7 @@ export const requireModule = (modulePath: string, builtInExtensionsDir: string):
const readFile = (name: string): Buffer => {
return fs.readFileSync(path.join(process.env.BUILD_DIR as string || path.join(__dirname, "../.."), "./build", name));
};
if (process.env.CLI) {
if (isCli) {
content = zlib.gunzipSync(readFile("bootstrap-fork.js.gz"));
} else {
content = readFile("../resources/bootstrap-fork.js");
@ -63,7 +64,7 @@ export const forkModule = (modulePath: string, env?: NodeJS.ProcessEnv): cp.Chil
const options: cp.SpawnOptions = {
stdio: [null, null, null, "ipc"],
};
if (process.env.CLI === "true") {
if (isCli) {
proc = cp.execFile(process.execPath, args, options);
} else {
proc = cp.spawn(process.execPath, ["--require", "ts-node/register", "--require", "tsconfig-paths/register", process.argv[1], ...args], options);