-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathprebuild.mjs
36 lines (30 loc) · 1.07 KB
/
prebuild.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as fs from "fs";
import * as path from "path";
import { fileURLToPath } from "url";
const symlinks = {
"skiplang-std": "./skiplang/prelude/ts/binding/src",
"skipwasm-std": "./skiplang/prelude/ts/wasm/src",
"skipwasm-worker": "./skiplang/prelude/ts/worker/src",
"skipwasm-date": "./skiplang/skdate/ts/src",
"skiplang-json": "./skiplang/skjson/ts/binding/src",
"skipwasm-json": "./skiplang/skjson/ts/wasm/src",
};
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
export function link(packages) {
for (const [symlink, target] of Object.entries(symlinks)) {
if (!packages.has(symlink)) continue;
const rand = new Uint32Array(1);
crypto.getRandomValues(rand);
const tmp = "tmp" + rand.toString("hex");
fs.symlinkSync(path.resolve(dirname, target), tmp, "dir");
fs.renameSync(tmp, symlink);
}
}
if (process.argv.length <= 2) {
const thisBin = process.argv[1];
console.log(`Usage: ${thisBin} <worspace-package>...`);
process.exit(0);
}
const packages = new Set(process.argv.slice(2));
link(packages);