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}" }