mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix installing canvas on all platforms
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
988307ee7d
commit
071ba8ac24
3 files changed
+12
-108
No files matched your search
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import child_process from "child_process";
|
||||
import { remove } from "fs-extra";
|
||||
import { ensureDir } from "fs-extra";
|
||||
import fetch from "node-fetch";
|
||||
import { platform } from "process";
|
||||
import { SemVer } from "semver";
|
||||
@@ -12,14 +12,6 @@ import stream from "stream";
|
||||
import { promisify } from "util";
|
||||
import { extract } from "tar";
|
||||
|
||||
// From "Node Major Version" to NODE_MODULE_VERSION
|
||||
const NODE_MODULE_VERSIONS: Partial<Record<string, string>> = {
|
||||
"16": "93",
|
||||
"17": "102",
|
||||
"18": "108",
|
||||
"19": "111",
|
||||
};
|
||||
|
||||
function canvasPrebuiltUrlBuilder(canvasVersion: SemVer, nodeVersion: string) {
|
||||
const compiler = platform === "linux"
|
||||
? "glibc"
|
||||
@@ -31,28 +23,24 @@ function canvasPrebuiltUrlBuilder(canvasVersion: SemVer, nodeVersion: string) {
|
||||
const exec = promisify(child_process.exec);
|
||||
const pipeline = promisify(stream.pipeline);
|
||||
|
||||
const electronVersionCommand = "npm list --depth=0 --json";
|
||||
const { stdout } = await exec(electronVersionCommand);
|
||||
// This is done so that we can skip the scripts for only this package
|
||||
await exec("npm install canvas@2 --no-save --no-package-lock --ignore-scripts");
|
||||
|
||||
const { stdout } = await exec("npm list --depth=0 --json");
|
||||
const output = JSON.parse(stdout);
|
||||
|
||||
const nodeVersion = new SemVer(output.dependencies["@types/node"].version);
|
||||
const nodeModuleVersion = NODE_MODULE_VERSIONS[`${nodeVersion.major}`];
|
||||
|
||||
if (!nodeModuleVersion) {
|
||||
throw new Error(`Unknown node major version "${nodeVersion.major}". You need to update the NODE_MODULE_VERSIONS table above from https://nodejs.org/en/download/releases/`);
|
||||
}
|
||||
|
||||
const nodeModuleVersion = process.versions.modules;
|
||||
const canvasVersion = new SemVer(output.dependencies["canvas"].version);
|
||||
const canvasPrebuildUrl = canvasPrebuiltUrlBuilder(canvasVersion, nodeModuleVersion);
|
||||
|
||||
await remove("./node_modules/canvas/build/Release");
|
||||
|
||||
const canvasPrebuilt = await fetch(canvasPrebuildUrl);
|
||||
|
||||
if (canvasPrebuilt.status !== 200) {
|
||||
throw new Error(`Failed to download prebuilt from ${canvasPrebuildUrl}: ${canvasPrebuilt.statusText}`);
|
||||
}
|
||||
|
||||
await ensureDir("./node_modules/canvas/build");
|
||||
|
||||
const dest = extract({
|
||||
cwd: "./node_modules/canvas/build",
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user