From 92a8368e4ef604afa30b83f5ec4d916d8b79b858 Mon Sep 17 00:00:00 2001 From: ZauberNerd Date: Mon, 21 Aug 2023 18:19:11 +0200 Subject: [PATCH] Build as single executable application This commit adds a build script to package the `devcontainer` CLI as a single executable application using the new (and experimental) Node.js feature of the same name. https://nodejs.org/api/single-executable-applications.html Distributing the devcontainer CLI as a single executable application allows to use it on systems where Node.js is not installed. For example on immutable systems like Fedora Silverblue or openSUSE MicroOS. --- build/single-executable.js | 49 ++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 50 insertions(+) create mode 100644 build/single-executable.js diff --git a/build/single-executable.js b/build/single-executable.js new file mode 100644 index 000000000..5a3870045 --- /dev/null +++ b/build/single-executable.js @@ -0,0 +1,49 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +"use strict"; + +const fs = require("fs"); +const cp = require("child_process"); + +/** + * Create a single executable file for the devcontainer CLI. + * https://nodejs.org/api/single-executable-applications.html + */ + +process.chdir("dist/spec-node"); + +const name = "devcontainer"; +const binary = `${name}${process.platform === "win32" ? ".exe" : ""}`; + +fs.copyFileSync(process.execPath, binary); + +const config = { + main: "devContainersSpecCLI.js", + output: `prepared.blob`, +}; + +fs.writeFileSync("config.json", JSON.stringify(config)); + +cp.spawnSync(process.execPath, ["--experimental-sea-config", "config.json"], { + stdio: "inherit", +}); + +cp.spawnSync( + "npx", + [ + "--yes", + "postject", + binary, + "NODE_SEA_BLOB", + config.output, + "--sentinel-fuse", + "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2", + ...(process.platform === "darwin" + ? ["--macho-segment-name", "NODE_SEA"] + : []), + ], + { stdio: "inherit" } +); diff --git a/package.json b/package.json index 127586195..78ec6a8f4 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "definitions-clean": "rimraf dist/node_modules/vscode-dev-containers", "definitions-copy": "copyfiles \"node_modules/vscode-dev-containers/container-features/{devcontainer-features.json,feature-scripts.env,fish-debian.sh,homebrew-debian.sh,install.sh}\" dist", "npm-pack": "npm pack", + "build-executable": "node build/single-executable.js", "clean": "npm-run-all clean-dist clean-built", "clean-dist": "rimraf dist", "clean-built": "rimraf built",