Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/python-wasm
Path: blob/main/core/build/make-dependencies.js
1391 views
1
const { existsSync, readFileSync, realpathSync } = require("fs");
2
const { join } = require("path");
3
const { execSync } = require("child_process");
4
5
if (existsSync("package.json")) {
6
const package = JSON.parse(readFileSync("package.json").toString());
7
8
const root = realpathSync(".");
9
10
const MAKE_DEP_EXCLUDE = process.env.MAKE_DEP_EXCLUDE ?? "";
11
12
for (const key of ["devDependencies", "dependencies"]) {
13
for (const name in package[key] ?? {}) {
14
if (package[key][name].startsWith("workspace:")) {
15
if (MAKE_DEP_EXCLUDE.includes(`:${name}:`)) {
16
// Avoid possibility of infinite recursion in case of circular dep.
17
// I don't think I have any, but sometime it's going to happen.
18
throw Error(
19
`CIRCULAR DEPENDENCY: MAKE_DEP_EXCLUDE=${MAKE_DEP_EXCLUDE}, name=${name}`
20
);
21
}
22
if (existsSync(join(root, "node_modules", name, "dist"))) {
23
// assume it was already built. This isn't meant to be a "always ensure up to date",
24
// but rather -- build if it obviously wasn't built.
25
continue;
26
}
27
console.log(`\nDEPENDENCY: ${name} - make`);
28
const cwd = realpathSync(join(root, "node_modules", name));
29
console.log(`cd '${cwd}'`);
30
// run make there
31
execSync("make", {
32
stdio: "inherit",
33
cwd,
34
env: {
35
...process.env,
36
MAKE_DEP_EXCLUDE: MAKE_DEP_EXCLUDE + ":" + name + ":",
37
},
38
});
39
console.log(`DEPENDENCY: ${name} successfully built\n`);
40
console.log(`cd "${root}"`);
41
}
42
}
43
}
44
}
45
46