解决部分用户无法安装sqlite3,pup等安装问题,

Signed-off-by: 柠檬冲水 <10424920+ningmengchongshui@user.noreply.gitee.com>
This commit is contained in:
柠檬冲水 2023-09-03 10:24:26 +00:00 committed by Gitee
parent d46676609c
commit 3f11678705
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 os = require("os");
const { existsSync } = require("fs"); const { existsSync, realpathSync } = require("fs");
const { execSync } = require("child_process");
const arch = os.arch(); const arch = os.arch();
/**
* Downloa
*/
let skipDownload = false; let skipDownload = false;
/**
* Path
*/
let executablePath; let executablePath;
/**
// win32 存在 Edge 优先选择 * windows path
if (process.platform == "win32") { */
if (existsSync("C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")) { const win32Edge =
skipDownload = true; "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe";
executablePath = "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跳过下载 * not path
if ((arch == "arm64" || arch == "aarch64") && existsSync("/usr/bin/chromium")) { */
skipDownload = true; if (!skipDownload) {
executablePath = "/usr/bin/chromium"; /**
} else if (existsSync("/usr/bin/chromium")) { * search
// 不论什么架构,如果存在 Chromium跳过下载且配置路径 */
skipDownload = true; const arr = [
executablePath = "/usr/bin/chromium"; "/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} * @type {import("puppeteer").Configuration}
*/ */
module.exports = { module.exports = {
skipDownload, skipDownload,
executablePath, executablePath,
}; };

View File

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