Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 52 additions & 21 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
const fs = require("fs");
const os = require("os");
const path = require("path");
const { spawnSync } = require("child_process");
const node = __dirname;
const OutDir = path.join(node, "out");

// Download the record/replay driver archive, using the latest version unless
//it was overridden via the environment.
let driverArchive = `${currentPlatform()}-recordreplay.tgz`;
let downloadDriverRevision = process.env.DRIVER_REVISION ? process.env.DRIVER_REVISION : fs.readFileSync("REPLAY_BACKEND_REV", "utf8");
let downloadArchive = `${currentPlatform()}-recordreplay-${downloadDriverRevision.trim().substring(0,12)}.tgz`;
// Use local driver directory if provided, otherwise download from S3.
const localDriverDir = process.env.REPLAY_LOCAL_DRIVER_DIR;
const driverFile = `${currentPlatform()}-recordreplay.${driverExtension()}`;
const driverJSON = `${currentPlatform()}-recordreplay.json`;
spawnChecked("curl", [`https://static.replay.io/downloads/${downloadArchive}`, "-o", driverArchive], { stdio: "inherit" });
spawnChecked("tar", ["xf", driverArchive]);
fs.unlinkSync(driverArchive);

// Embed the driver in the source.
const driverContents = fs.readFileSync(driverFile);
const { revision: driverRevision, date: driverDate } = JSON.parse(fs.readFileSync(driverJSON, "utf8"));
fs.unlinkSync(driverFile);
fs.unlinkSync(driverJSON);

let driverContents;
let driverRevision;
let driverDate;

if (localDriverDir) {
console.log("[build] Loading driver from local directory:", localDriverDir);
driverContents = fs.readFileSync(path.join(localDriverDir, driverFile));
const driverInfo = JSON.parse(fs.readFileSync(path.join(localDriverDir, driverJSON), "utf8"));
driverRevision = driverInfo.revision;
driverDate = driverInfo.date;
} else {
console.log("[build] Downloading driver from S3...");
let driverArchive = `${currentPlatform()}-recordreplay.tgz`;
let downloadDriverRevision = process.env.DRIVER_REVISION ? process.env.DRIVER_REVISION : fs.readFileSync("REPLAY_BACKEND_REV", "utf8");
let downloadArchive = `${currentPlatform()}-recordreplay-${downloadDriverRevision.trim().substring(0,12)}.tgz`;
const driverArchivePath = path.join(OutDir, driverArchive);
spawnChecked("curl", [`https://static.replay.io/downloads/${downloadArchive}`, "-o", driverArchivePath], { stdio: "inherit" });
spawnChecked("tar", ["xf", driverArchivePath, "-C", OutDir]);
fs.unlinkSync(driverArchivePath);

driverContents = fs.readFileSync(path.join(OutDir, driverFile));
const driverInfo = JSON.parse(fs.readFileSync(path.join(OutDir, driverJSON), "utf8"));
driverRevision = driverInfo.revision;
driverDate = driverInfo.date;
fs.unlinkSync(path.join(OutDir, driverFile));
fs.unlinkSync(path.join(OutDir, driverJSON));
fs.unlinkSync(path.join(OutDir, `${driverFile}.symbols.json`));
}
console.log("[build] Generating driver source file...");
let driverString = "";
for (let i = 0; i < driverContents.length; i++) {
driverString += `\\${driverContents[i].toString(8)}`;
Expand All @@ -36,17 +56,28 @@ namespace node {

const numCPUs = os.cpus().length;

function getSanitizedEnv() {
const env = { ...process.env };
if (env.PATH) {
env.PATH = env.PATH.split(":").filter(p => !p.includes("/nix/")).join(":");
}
delete env.NIX_PROFILES;
delete env.NIX_SSL_CERT_FILE;
env.RECORD_REPLAY_DONT_RECORD = "1";
return env;
}

const buildEnv = getSanitizedEnv();

if (process.env.CONFIGURE_NODE) {
spawnChecked(`${node}/configure`, [], { cwd: node, stdio: "inherit" });
console.log("[build] Running configure...");
spawnChecked(`${node}/configure`, [], { cwd: node, stdio: "inherit", env: buildEnv });
}
spawnChecked("make", [`-j${numCPUs}`, "-C", "out", "BUILDTYPE=Release"], {
console.log("[build] Running make...");
spawnChecked("make", [`-j${numCPUs}`, "-C", OutDir, "BUILDTYPE=Release"], {
cwd: node,
stdio: "inherit",
env: {
...process.env,
// Disable recording when node runs as part of its compilation process.
RECORD_REPLAY_DONT_RECORD: "1",
},
env: buildEnv,
});

function spawnChecked(cmd, args, options) {
Expand Down
91 changes: 0 additions & 91 deletions replay-test/client.ts

This file was deleted.

26 changes: 0 additions & 26 deletions replay-test/examples/async.js

This file was deleted.

12 changes: 0 additions & 12 deletions replay-test/examples/basic.js

This file was deleted.

120 changes: 0 additions & 120 deletions replay-test/examples/control_flow.js

This file was deleted.

4 changes: 0 additions & 4 deletions replay-test/examples/error.js

This file was deleted.

17 changes: 0 additions & 17 deletions replay-test/examples/exceptions.js

This file was deleted.

26 changes: 0 additions & 26 deletions replay-test/examples/napi.js

This file was deleted.

Loading
Loading