sentry-cli目录识别异常的问题解决方案
原因:缺失sentry-cli根据系统类型的二进制执行文件,未能正确的实行已经提供的安装脚本,脚本路径紊乱.
结果:导致sentry-cli重新从外网下载,而由于最近一段时间外网翻墙限制,导致sentry包无法正常install、安装
解决方法如下:install之后辅助完成下载
// package.json
"scripts": {
"prepare": "husky install; node check-sentry.js",
}
// check-sentry.js
const { execSync } = require('child_process');
const { existsSync } = require('fs');
const { join } = require('path');
const basePath = process.cwd();
function getJoinPath(relativePath) {
return join(basePath, relativePath);
}
const sentryCliBinPath = getJoinPath('./node_modules/.bin/sentry-cli');
const nodeModulesSentryInstallPath = getJoinPath('./node_modules/@sentry/cli/scripts/install.js');
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const SLEEP_TIME = 10000;
async function checkSentry() {
const stdio = ['ignore', 'inherit', 'ignore'];
if (existsSync(sentryCliBinPath)) {
try {
execSync(`${sentryCliBinPath} -V`, { stdio });
} catch (error) {
if (existsSync(nodeModulesSentryInstallPath)) {
execSync(`node ${nodeModulesSentryInstallPath}`);
await sleep(SLEEP_TIME);
execSync(`${sentryCliBinPath} -V`, { stdio });
}
}
}
}
checkSentry();