tutanota/buildSrc/postinstall.js

38 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2022-05-27 14:46:31 +02:00
/**
* @file Script to do postinstall tasks without resorting to shell (or batch) scripts.
2022-05-27 14:46:31 +02:00
*/
import { spawnSync } from "node:child_process"
2022-05-27 14:46:31 +02:00
dumpResolvedModuleVersions()
2024-07-18 18:31:32 +02:00
await tryToUpdateLibs()
updateSubmodules()
2022-05-27 14:46:31 +02:00
/**
* Dumps the dependency tree into `node_modules/.npm-deps-resolved`.
* We need to query module versions in a few places during build and npm is very slow, so it's faster to resolve everything once and read from disk later.
*/
function dumpResolvedModuleVersions() {
const command = `npm list --json > node_modules/.npm-deps-resolved`
console.log(command)
// We only depend on zx as devDependency but postinstall is also run when we are installed as a dependency so we can't use zx here.
// We anyway do not really care if it fails or not
2022-12-27 15:37:40 +01:00
spawnSync(command, { shell: true, stdio: "inherit" })
2022-05-27 14:46:31 +02:00
}
2024-07-18 18:31:32 +02:00
async function tryToUpdateLibs() {
try {
await import("rollup")
} catch (e) {
console.log("cannot update vendored libs as rollup is not installed (installed as a dependency?)")
return
}
const { updateLibs } = await import("./updateLibs.js")
await updateLibs()
}
function updateSubmodules() {
const command = "git submodule update --init"
spawnSync(command, { shell: true, stdio: "inherit" })
}