2020-02-14 00:52:16 +01:00
|
|
|
/*
|
2024-09-06 18:56:18 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2020-02-14 00:52:16 +01:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-06 18:56:18 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-02-14 00:52:16 +01:00
|
|
|
*/
|
|
|
|
|
2024-10-30 19:06:03 +01:00
|
|
|
import fsProm from "node:fs/promises";
|
2022-12-15 12:00:58 +01:00
|
|
|
import pacote from "pacote";
|
2022-01-10 13:57:33 +01:00
|
|
|
|
2024-10-30 19:06:03 +01:00
|
|
|
import type HakEnv from "./hakEnv.js";
|
|
|
|
import type { DependencyInfo } from "./dep.js";
|
2020-02-14 00:52:16 +01:00
|
|
|
|
2021-12-14 15:32:27 +01:00
|
|
|
export default async function fetch(hakEnv: HakEnv, moduleInfo: DependencyInfo): Promise<void> {
|
2020-02-14 00:52:16 +01:00
|
|
|
let haveModuleBuildDir;
|
|
|
|
try {
|
|
|
|
const stats = await fsProm.stat(moduleInfo.moduleBuildDir);
|
|
|
|
haveModuleBuildDir = stats.isDirectory();
|
2024-10-16 16:59:12 +02:00
|
|
|
} catch {
|
2020-02-14 00:52:16 +01:00
|
|
|
haveModuleBuildDir = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (haveModuleBuildDir) return;
|
|
|
|
|
2021-07-17 00:38:04 +02:00
|
|
|
console.log("Fetching " + moduleInfo.name + "@" + moduleInfo.version);
|
2020-02-14 00:52:16 +01:00
|
|
|
|
2021-07-17 00:38:04 +02:00
|
|
|
const packumentCache = new Map();
|
|
|
|
await pacote.extract(`${moduleInfo.name}@${moduleInfo.version}`, moduleInfo.moduleBuildDir, {
|
|
|
|
packumentCache,
|
2020-02-14 00:52:16 +01:00
|
|
|
});
|
|
|
|
|
2020-02-15 17:52:41 +01:00
|
|
|
console.log("Running yarn install in " + moduleInfo.moduleBuildDir);
|
2024-10-30 19:06:03 +01:00
|
|
|
await hakEnv.spawn("yarn", ["install", "--ignore-scripts"], {
|
|
|
|
cwd: moduleInfo.moduleBuildDir,
|
2020-02-14 00:52:16 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// also extract another copy to the output directory at this point
|
2020-02-21 11:57:52 +01:00
|
|
|
// nb. we do not yarn install in the output copy: we could install in
|
|
|
|
// production mode to get only runtime dependencies and not devDependencies,
|
|
|
|
// but usually native modules come with dependencies that are needed for
|
|
|
|
// building/fetching the native modules (eg. node-pre-gyp) rather than
|
|
|
|
// actually used at runtime: we do not want to bundle these into our app.
|
|
|
|
// We therefore just install no dependencies at all, and accept that any
|
|
|
|
// actual runtime dependencies will have to be added to the main app's
|
|
|
|
// dependencies. We can't tell what dependencies are real runtime deps
|
|
|
|
// and which are just used for native module building.
|
2021-07-17 00:38:04 +02:00
|
|
|
await pacote.extract(`${moduleInfo.name}@${moduleInfo.version}`, moduleInfo.moduleOutDir, {
|
|
|
|
packumentCache,
|
2020-02-14 00:52:16 +01:00
|
|
|
});
|
|
|
|
}
|