From 3ca90a5f89d9bb53e845a544b6e830c4cce268bd Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 5 Jul 2019 11:54:04 -0500 Subject: [PATCH] Use nbin in forked processes --- main.js | 10 ---------- scripts/nbin-loader.js | 9 +++++++++ scripts/tasks.bash | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 scripts/nbin-loader.js diff --git a/main.js b/main.js index 03e616b7..765f4181 100644 --- a/main.js +++ b/main.js @@ -1,11 +1 @@ -try { - const nbin = require("nbin"); - const path = require("path"); - const rootPath = path.resolve(__dirname, "../../.."); - console.log("Shimming", rootPath); - nbin.shimNativeFs(rootPath); -} catch (error) { - console.log("Not in the binary"); -} - require("../../bootstrap-amd").load("vs/server/cli"); diff --git a/scripts/nbin-loader.js b/scripts/nbin-loader.js new file mode 100644 index 00000000..344e6b53 --- /dev/null +++ b/scripts/nbin-loader.js @@ -0,0 +1,9 @@ +if (!global.NBIN_LOADED) { + try { + const nbin = require("nbin"); + nbin.shimNativeFs("{{ROOT_PATH}}"); + global.NBIN_LOADED = true; + } catch (error) { + console.log("Not in the binary"); + } +} diff --git a/scripts/tasks.bash b/scripts/tasks.bash index d0fdc418..f430c1a5 100755 --- a/scripts/tasks.bash +++ b/scripts/tasks.bash @@ -41,6 +41,18 @@ function copy-server() { fi } +# Prepend the nbin loading code which allows the code to find files within +# the binary. +function prepend-loader() { + local filePath="${codeServerBuildPath}/${1}" ; shift + cat "${rootPath}/scripts/nbin-loader.js" "${filePath}" > "${filePath}.temp" + mv "${filePath}.temp" "${filePath}" + # Using : as the delimiter so the escaping here is easier to read. + # ${parameter/pattern/string}, so the pattern is /: (if the pattern starts + # with / it matches all instances) and the string is \\: (results in \:). + sed -i "s:{{ROOT_PATH}}:${codeServerBuildPath//:/\\:}:g" "${filePath}" +} + # Copy code-server into VS Code then build it. function build-code-server() { copy-server @@ -62,6 +74,9 @@ function build-code-server() { rm -rf "${codeServerBuildPath}/out/vs/server/node_modules" cp -r "${vscodeSourcePath}/remote/node_modules" "${codeServerBuildPath}" + prepend-loader "out/vs/server/main.js" + prepend-loader "out/bootstrap-fork.js" + log "Final build: ${codeServerBuildPath}" }