From 3d654a8df7f63d733a813e097901f2f67b124d27 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 7 Mar 2019 11:24:25 -0600 Subject: [PATCH] Resolve paths Fixes #19. --- packages/server/src/cli.ts | 16 ++++++++-------- packages/server/src/constants.ts | 4 +++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/server/src/cli.ts b/packages/server/src/cli.ts index b57fb8ad..a4352d82 100644 --- a/packages/server/src/cli.ts +++ b/packages/server/src/cli.ts @@ -49,11 +49,11 @@ export class Entry extends Command { } const { args, flags } = this.parse(Entry); - const dataDir = flags["data-dir"] || path.join(os.homedir(), ".code-server"); - const workingDir = args["workdir"]; + const dataDir = path.resolve(flags["data-dir"] || path.join(os.homedir(), ".code-server")); + const workingDir = path.resolve(args["workdir"]); setupNativeModules(dataDir); - const builtInExtensionsDir = path.join(buildDir || path.join(__dirname, ".."), "build/extensions"); + const builtInExtensionsDir = path.resolve(buildDir || path.join(__dirname, ".."), "build/extensions"); if (flags["bootstrap-fork"]) { const modulePath = flags["bootstrap-fork"]; if (!modulePath) { @@ -84,8 +84,8 @@ export class Entry extends Command { const logDir = path.join(dataDir, "logs", new Date().toISOString().replace(/[-:.TZ]/g, "")); process.env.VSCODE_LOGS = logDir; - const certPath = flags.cert; - const certKeyPath = flags["cert-key"]; + const certPath = flags.cert ? path.resolve(flags.cert) : undefined; + const certKeyPath = flags["cert-key"] ? path.resolve(flags["cert-key"]) : undefined; if (certPath && !certKeyPath) { logger.error("'--cert-key' flag is required when specifying a certificate!"); @@ -135,9 +135,9 @@ export class Entry extends Command { } }); - let password = flags["password"]; + let password = flags.password; if (!password) { - // Generate a random password + // Generate a random password with a length of 24. const buffer = Buffer.alloc(12); randomFillSync(buffer); password = buffer.toString("hex"); @@ -158,7 +158,7 @@ export class Entry extends Command { // If we're not running from the binary and we aren't serving the static // pre-built version, use webpack to serve the web files. if (!isCli && !serveStatic) { - const webpackConfig = require(path.join(__dirname, "..", "..", "web", "webpack.config.js")); + const webpackConfig = require(path.resolve(__dirname, "..", "..", "web", "webpack.config.js")); const compiler = require("webpack")(webpackConfig); app.use(require("webpack-dev-middleware")(compiler, { logger, diff --git a/packages/server/src/constants.ts b/packages/server/src/constants.ts index dee4b267..d603a603 100644 --- a/packages/server/src/constants.ts +++ b/packages/server/src/constants.ts @@ -1,3 +1,5 @@ +import * as path from "path"; + 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; +export const buildDir = process.env.BUILD_DIR ? path.resolve(process.env.BUILD_DIR) : "";