Skip to content

Commit

Permalink
Use Github to clone the Nodejs source
Browse files Browse the repository at this point in the history
  • Loading branch information
devraymondsh committed Apr 5, 2024
1 parent e5ba5a3 commit 381cd01
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 38 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/scheduled-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ jobs:
run: apt-get install --yes ca-certificates curl gnupg && curl -sL https://deb.nodesource.com/setup_21.x | bash - && apt-get update

- name: Install building tools
run: apt-get install --yes git python3 python3-pip gcc g++ make ninja-build nodejs yarn nodejs-dev node-gyp libssl-dev
run: apt-get install --yes git python3 python3-pip gcc g++ make ninja-build nodejs

- name: Clone the repo
run: git clone https://github.com/devraymondsh/libnode-distributable

- name: Run the script
run: cd libnode-distributable && node index.js

- name: A buncha ls
run: ls . ; ls .. ; ls out/Debug ; ls ../out/Debug
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node-*
*.tar.gz
node
58 changes: 23 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import os from "node:os";
import syncFs from "node:fs";
import fs from "node:fs/promises";
import { Readable } from "node:stream";
import { finished } from "node:stream/promises";
import { spawnSync, spawn } from "node:child_process";
import { spawn, spawnSync } from "node:child_process";

const constructSourceTarballName = (version) => `node-${version}.tar.gz`;
const constructSourceTarballDirName = (version) => `node-${version}`;

const constructSourceDownloadLink = (version) =>
`https://github.com/nodejs/node/archive/refs/tags/v${version}.tar.gz`;
const coreCount = os.cpus().length;
const threadCount = coreCount * 2;

const nodejsGithubRepo = "https://github.com/nodejs/node";
const removeTheVCharacter = (str) => str.replace("v", "");

const nodeIndexUrl = "https://nodejs.org/dist/index.json";
Expand Down Expand Up @@ -41,43 +37,35 @@ const isANewerVersion = (oldVer, newVer) => {

const spawnAsync = (program, args, cwd) =>
new Promise((resolve, reject) => {
const child = spawn(program, args, { cwd });
console.log([program, ...args].join(" "));

child.stdout.on("data", (chunk) => console.log(chunk.toString()));
child.stderr.on("data", (chunk) => {
console.error(chunk.toString());
reject(chunk);
});
const child = spawn(program, args, cwd ? { cwd } : {});

child.on("close", (code) => resolve(code));
child.stdout.on("data", (chunk) => console.log(chunk.toString()));
child.stderr.on("data", (chunk) => console.warn(chunk.toString()));
child.on("close", (code) => resolve(code.toString()));
});

const latestNodeVersion = await getLatestNodeVersion();

if (!isANewerVersion(await getLatestPublishedVersion(), latestNodeVersion)) {
console.log("Nothing to do!");
process.exit(0);
}

const tarballName = constructSourceTarballName(latestNodeVersion);
if (!syncFs.existsSync(tarballName)) {
const stream = syncFs.createWriteStream(tarballName);
const { body } = await fetch(constructSourceDownloadLink(latestNodeVersion));
await finished(Readable.fromWeb(body).pipe(stream));
if (!syncFs.existsSync("node")) {
await spawnAsync(
"git",
[
"clone",
nodejsGithubRepo,
"--branch",
`v${latestNodeVersion}`,
"--depth=1",
],
undefined
);
}

const tarballDir = constructSourceTarballDirName(latestNodeVersion);
if (!syncFs.existsSync(tarballDir)) {
const { stderr } = spawnSync("tar", ["-xvf", `${tarballName}`]);
if (stderr.length > 0) {
console.error(stderr);
process.exit(0);
}
}

await spawnAsync("./configure", ["--ninja", "--shared", "--debug"], tarballDir);

const coreCount = os.cpus().length;
const threadCount = coreCount * 2;
await spawnAsync("./configure", ["--ninja", "--shared", "--debug"], "node");

await spawnAsync("make", [`-j${threadCount}`], tarballDir);
await spawnAsync("make", [`-j${threadCount}`], "node");

0 comments on commit 381cd01

Please sign in to comment.