!97 修复部分用户安装依赖出错

Merge pull request !97 from 柠檬冲水/N/A
This commit is contained in:
Kokomi 2023-09-04 03:20:35 +00:00 committed by Gitee
commit 81e1d4f5c8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 85 additions and 18 deletions

6
.npmrc Normal file
View File

@ -0,0 +1,6 @@
# sqlite3
node_sqlite3_binary_host_mirror=https://npmmirror.com/mirrors/sqlite3
# pup
PUPPETER_DOWNLOAD_BASE_URL=https://npmmirror.com/mirrors/chrome-for-testing
# 改为 npm 依赖安装方式
node-linker=hoisted

View File

@ -1,31 +1,88 @@
const os = require("os");
const { existsSync } = require("fs");
const { existsSync, realpathSync } = require("fs");
const { execSync } = require("child_process");
const arch = os.arch();
/**
* Downloa
*/
let skipDownload = false;
/**
* Path
*/
let executablePath;
// win32 存在 Edge 优先选择
if (process.platform == "win32") {
if (existsSync("C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")) {
skipDownload = true;
executablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe";
/**
* windows path
*/
const win32Edge =
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe";
/**
* linux | android
*/
if (process.platform == "linux" || process.platform == "android") {
const chromium = [
"whereis chrome-browser",
"whereis chrome",
"whereis chromium-browser",
"whereis chromium",
"whereis firefox",
];
/**
* get path
*/
for (const item of chromium) {
try {
const chromiumPath = execSync(item).toString().split(" ")[1]?.trim();
if (chromiumPath) {
skipDownload = true;
executablePath = realpathSync(chromiumPath);
console.info("[Chromium] start");
break;
}
} catch (error) {
console.error("Failed to get Chromium path:", error);
continue;
}
}
} else if (process.platform == "linux") {
// 如果 arm64 架构且存在 Chromium跳过下载
if ((arch == "arm64" || arch == "aarch64") && existsSync("/usr/bin/chromium")) {
skipDownload = true;
executablePath = "/usr/bin/chromium";
} else if (existsSync("/usr/bin/chromium")) {
// 不论什么架构,如果存在 Chromium跳过下载且配置路径
skipDownload = true;
executablePath = "/usr/bin/chromium";
/**
* not path
*/
if (!skipDownload) {
/**
* search
*/
const arr = [
"/usr/bin/chromium",
"/snap/bin/chromium",
"/usr/bin/chromium-browser",
];
for (const item of arr) {
if (existsSync(item)) {
skipDownload = true;
executablePath = item;
console.info("[Chromium] start");
break;
}
}
}
/**
* arm64/arrch64
*/
if (arch == "arm64" || arch == "aarch64") {
console.info("[arm64/aarch64] system");
skipDownload = true;
}
} else if (process.platform == "win32" && existsSync(win32Edge)) {
/**
* win32 Edge
*/
skipDownload = true;
executablePath = win32Edge;
console.info("[Win32 Edge] start");
}
/**
* @type {import("puppeteer").Configuration}
*/
module.exports = {
skipDownload,
executablePath,
};
};

View File

@ -48,6 +48,10 @@
"express": "^4.18.2",
"express-art-template": "^1.0.1"
},
"workspaces": [
"renderers/*",
"plugins/*"
],
"imports": {
"#miao": "./plugins/miao-plugin/components/index.js",
"#miao.models": "./plugins/miao-plugin/models/index.js"