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,5 +1,6 @@
out out
cli* cli*
!cli.ts
build build
resources resources

View File

@ -8,7 +8,7 @@
"build:webpack": "rm -rf ./out && export CLI=true && ../../node_modules/.bin/webpack --config ./webpack.config.js", "build:webpack": "rm -rf ./out && export CLI=true && ../../node_modules/.bin/webpack --config ./webpack.config.js",
"build:nexe": "node scripts/nexe.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: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: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" "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 { SharedProcess, SharedProcessState } from "./vscode/sharedProcess";
import { setup as setupNativeModules } from "./modules"; import { setup as setupNativeModules } from "./modules";
import { fillFs } from "./fill"; import { fillFs } from "./fill";
import { isCli, serveStatic, buildDir } from "./constants";
export class Entry extends Command { export class Entry extends Command {
public static description = "Start your own self-hosted browser-accessible VS Code"; 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)); logger.warn("Failed to remove extracted dependency.", field("dependency", "spdlog"), field("error", ex.message));
} }
if (process.env.CLI) { if (isCli) {
fillFs(); fillFs();
} }
@ -60,7 +61,7 @@ export class Entry extends Command {
Object.assign(process.env, JSON.parse(flags.env)); 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"]) { if (flags["bootstrap-fork"]) {
const modulePath = flags["bootstrap-fork"]; const modulePath = flags["bootstrap-fork"];
if (!modulePath) { if (!modulePath) {
@ -74,8 +75,8 @@ export class Entry extends Command {
const dataDir = flags["data-dir"] || path.join(os.homedir(), ".vscode-remote"); const dataDir = flags["data-dir"] || path.join(os.homedir(), ".vscode-remote");
const workingDir = args["workdir"]; const workingDir = args["workdir"];
if (process.env.BUILD_DIR && process.env.BUILD_DIR.startsWith(workingDir)) { if (buildDir && buildDir.startsWith(workingDir)) {
logger.error("Cannot run binary inside of BUILD_DIR", field("build_dir", process.env.BUILD_DIR), field("cwd", process.cwd())); logger.error("Cannot run binary inside of BUILD_DIR", field("build_dir", buildDir), field("cwd", process.cwd()));
process.exit(1); process.exit(1);
} }
@ -114,7 +115,7 @@ export class Entry extends Command {
next(); 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 webpackConfig = require(path.join(__dirname, "..", "..", "web", "webpack.config.js"));
const compiler = require("webpack")(webpackConfig); const compiler = require("webpack")(webpackConfig);
app.use(require("webpack-dev-middleware")(compiler, { app.use(require("webpack-dev-middleware")(compiler, {
@ -163,6 +164,6 @@ export class Entry extends Command {
} }
Entry.run(undefined, { Entry.run(undefined, {
root: process.env.BUILD_DIR as string || __dirname, root: buildDir || __dirname,
//@ts-ignore //@ts-ignore
}).catch(require("@oclif/errors/handle")); }).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 fs from "fs";
import * as util from "util"; import * as util from "util";
import { isCli } from "./constants";
const oldAccess = fs.access; const oldAccess = fs.access;
const existsWithinBinary = (path: fs.PathLike): Promise<boolean> => { const existsWithinBinary = (path: fs.PathLike): Promise<boolean> => {
@ -24,7 +25,7 @@ export const fillFs = (): void => {
* For impls * For impls
*/ */
if (!process.env.CLI) { if (!isCli) {
throw new Error("Should not fill FS when not in CLI"); throw new Error("Should not fill FS when not in CLI");
} }

View File

@ -1,5 +1,6 @@
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { isCli, buildDir } from "./constants";
declare var __non_webpack_require__: typeof require; 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 * Handling of native modules within the CLI
*/ */
export const setup = (dataDirectory: string): void => { export const setup = (dataDirectory: string): void => {
if (!process.env.CLI) { if (!isCli) {
return; return;
} }
@ -20,7 +21,7 @@ export const setup = (dataDirectory: string): void => {
} }
const unpackModule = (moduleName: 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"); const diskFile = path.join(dataDirectory, "modules", moduleName + ".node");
if (!fs.existsSync(diskFile)) { if (!fs.existsSync(diskFile)) {
fs.writeFileSync(diskFile, fs.readFileSync(memFile)); fs.writeFileSync(diskFile, fs.readFileSync(memFile));

View File

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

View File

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