Skip to content

Commit 38445ce

Browse files
committed
path issues
1 parent ce41c83 commit 38445ce

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed
Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
1-
// cocalc.js
2-
const VERSION = "${VERSION}";
3-
4-
const { getRawAsset } = require("node:sea");
5-
const fs = require("node:fs");
6-
const os = require("node:os");
71
const path = require("node:path");
8-
const { spawnSync } = require("node:child_process");
9-
10-
const destDir = path.join(
11-
process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache"),
12-
"cocalc",
13-
"project-runner",
14-
VERSION,
15-
);
16-
17-
const stamp = path.join(destDir, ".ok");
18-
if (!fs.existsSync(stamp)) {
19-
console.log("Unpacking...");
20-
// Read the SEA asset into a Buffer
21-
const ab = getRawAsset("cocalc-project-runner.tar.xz"); // ArrayBuffer (no copy)
22-
const buf = Buffer.from(new Uint8Array(ab)); // turn into Node Buffer
23-
24-
fs.mkdirSync(destDir, { recursive: true });
2+
const fs = require("node:fs");
253

26-
const child = spawnSync(
27-
"tar",
28-
["-Jxf", "-", "-C", destDir, "--strip-components=1"],
29-
{
30-
input: buf,
31-
stdio: ["pipe", "inherit", "inherit"],
32-
},
4+
function extractAssetsSync() {
5+
const VERSION = "${VERSION}";
6+
const { getRawAsset } = require("node:sea");
7+
const os = require("node:os");
8+
const { spawnSync } = require("node:child_process");
9+
10+
const destDir = path.join(
11+
process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache"),
12+
"cocalc",
13+
"project-runner",
14+
VERSION,
3315
);
3416

35-
if (child.error) {
36-
console.error("Failed to run tar:", child.error);
37-
process.exit(1);
38-
}
39-
if (child.status !== 0) {
40-
console.error(`tar exited with code ${child.status}`);
41-
process.exit(child.status);
17+
const stamp = path.join(destDir, ".ok");
18+
if (!fs.existsSync(stamp)) {
19+
console.log("Unpacking...");
20+
// Read the SEA asset into a Buffer
21+
const ab = getRawAsset("cocalc-project-runner.tar.xz"); // ArrayBuffer (no copy)
22+
const buf = Buffer.from(new Uint8Array(ab)); // turn into Node Buffer
23+
24+
fs.mkdirSync(destDir, { recursive: true });
25+
26+
const child = spawnSync(
27+
"tar",
28+
["-Jxf", "-", "-C", destDir, "--strip-components=1"],
29+
{
30+
input: buf,
31+
stdio: ["pipe", "inherit", "inherit"],
32+
},
33+
);
34+
35+
if (child.error) {
36+
console.error("Failed to run tar:", child.error);
37+
process.exit(1);
38+
}
39+
if (child.status !== 0) {
40+
console.error(`tar exited with code ${child.status}`);
41+
process.exit(child.status);
42+
}
43+
44+
console.log("Assets ready at:", destDir);
45+
fs.writeFileSync(stamp, "");
4246
}
43-
44-
console.log("Assets ready at:", destDir);
45-
fs.writeFileSync(stamp, "");
47+
return destDir;
4648
}
4749

4850
const Module = require("node:module");
49-
5051
const looksLikeScript = process.argv[2] && !process.argv[2].startsWith("-");
5152

5253
if (looksLikeScript) {
5354
process.argv = [process.execPath, ...process.argv.slice(2)];
5455
} else {
56+
const destDir = extractAssetsSync();
5557
console.log("Starting CoCalc Project Runner");
5658

5759
const script = path.join(destDir, "src/packages/project-runner/bin/start.js");
@@ -74,5 +76,4 @@ if (looksLikeScript) {
7476
process.env.AUTH_TOKEN = "random";
7577
}
7678

77-
// run like “node start.js”
78-
Module.runMain(); // loads process.argv[1] as the main script
79+
Module.runMain();

0 commit comments

Comments
 (0)