Don't let vendor-rome connect to dev-rome daemon and skip trunk build if dev daemon running
MODIFY
packages/@romejs/core/common/constants.ts
packages/@romejs/core/common/constants.ts
@@ -25,7 +25,13 @@ export const MAX_WORKER_BYTES_BEFORE_ADD = 1 * MEGABYTE;
const CPU_COUNT: number = os.cpus().length;
export const MAX_WORKER_COUNT = Math.min(CPU_COUNT, 4);
-export const VERSION = String(packageJson.version);
+export let VERSION = String(packageJson.version);
+
+// Vendor Rome and Trunk Rome could have the same version number if there was no release in between
+// Ensure they are properly namespaced to avoid having daemon socket conflicts
+if (process.env.ROME_DEV === "1") {
+ VERSION += "-dev";
+}
export const SOCKET_PATH = TEMP_PATH.append(`rome-${VERSION}.sock`);

MODIFY
scripts/_utils.cjs
scripts/_utils.cjs
*/
const {root, devFolder} = require("./_constants.cjs");
+const packageJson = require("../package.json");
const child = require("child_process");
const path = require("path");
+const net = require("net");
const fs = require("fs");
+const os = require("os");
exports.unlink = function(loc) {
if (!fs.existsSync(loc)) {
@@ -75,8 +78,35 @@ exports.heading = function(str) {
console.log(`\u001b[7m ${str} \u001b[27m`);
};
-exports.execDev = function(argv) {
- exports.buildTrunk();
+exports.isDevDaemonRunning = function() {
+ // Path and version logic copied from packages/@romejs/core/common/constants.ts
+ // If there is a running daemon then we shouldn't build and just use the existing bundle
+ // We'll log to let the developer know what's going on
+ const version = `${packageJson.version}-dev`;
+ const socketPath = path.join(os.tmpdir(), `rome-${version}.sock`);
+
+ return new Promise((resolve) => {
+ const socket = net.createConnection(
+ {
+ path: socketPath,
+ },
+ () => {
+ resolve(true);
+ socket.end();
+ },
+ );
+
+ socket.on(
+ "error",
+ () => {
+ resolve(false);
+ },
+ );
+ });
+};
+
+exports.execDev = async function(argv) {
+ await exports.buildTrunk();
process.env.ROME_CACHE = "0";
exports.heading("Executing trunk");
exports.execNode([path.join(devFolder, "index.js"), ...argv]);
@@ -91,7 +121,19 @@ exports.buildRelease = function(argv) {
]);
};
-exports.buildTrunk = function() {
+exports.buildTrunk = async function() {
+ if (await exports.isDevDaemonRunning()) {
+ console.log(
+ `\x1b[1m\x1b[33m!!!! A dev daemon is currently running. Skipping new build. !!!!\x1b[39m\x1b[22m`,
+ );
+ console.log(
+ "\x1b[34mIf you want to run new code and stop the daemon you can stop the daemon with:\x1b[39m",
+ );
+ console.log("\x1b[2m$ ./scripts/dev-rome stop\x1b[22m");
+ console.log();
+ return;
+ }
+
exports.unlink(devFolder);
fs.mkdirSync(devFolder);

MODIFY
scripts/assert-generated
scripts/assert-generated
@@ -23,8 +23,7 @@ const filteredWrittenFiles = writtenFiles.filter(function(file){
});
// Autofix them
-execDev(["check", ...filteredWrittenFiles, "--apply"]);
-
+execDev(["check", ...filteredWrittenFiles, "--apply"]).finally(() => {
// Check that `git status` is fine
const out = child_process
.spawnSync("git", ["ls-files", "-m"])
@@ -37,3 +36,5 @@ if (out !== "") {
console.log();
process.exit(1);
}
+});
+

MODIFY
scripts/run-vscode-extension
scripts/run-vscode-extension
@@ -14,10 +14,11 @@ const os = require("os");
const outFolder = path.join(os.tmpdir(), "rome-vscode-dev");
-buildTrunk();
+async function main() {
+ await buildTrunk();
heading("Bundling Extension");
-execDev([
+ await execDev([
"bundle",
"@romejs-integration/vscode",
outFolder,
@@ -30,3 +31,6 @@ exec("code", [
"--disable-extensions",
...argv,
]);
+}
+
+main();

Don't let vendor-rome connect to dev-rome daemon and skip trunk build if dev daemon running (#685)