From ee2b483417c5ce3f5ea020af3954f2b729190bbd Mon Sep 17 00:00:00 2001 From: Sonic853 Date: Mon, 10 Oct 2022 17:36:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=88=E6=A3=80=E6=9F=A5=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E9=87=8C=E6=98=AF=E5=90=A6=E6=9C=89=20package.json=20?= =?UTF-8?q?perf:=20=E6=9B=BF=E6=8D=A2=E5=BC=83=E7=94=A8=E7=9A=84=20substr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index c7df0c6..bce2c7b 100644 --- a/src/index.js +++ b/src/index.js @@ -68,6 +68,10 @@ function getTranslation() { return locales[locale]; } +if (!fs.existsSync(path.join(process.cwd(), 'package.json'))) { + logger.error('package.json does not exist'); + process.exit(1); +} const PKG = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'))); const INITIAL_VERSION = '1.0.0'; const TAG_PREFIX = 'v'; @@ -100,7 +104,7 @@ async function fetchLatestVersion(info) { }); }); if (release.tag_name && release.tag_name.charAt(0) === 'v') { - const version = release.tag_name.substr(1); + const version = release.tag_name.slice(1); logger.log(`Latest version: ${version}`); return [version, release.target_commitish]; } @@ -173,8 +177,8 @@ function getGitRepoInfo() { function parseUrl(url) { [info.owner, info.repo] = url.split(':')[1].split('/'); - if (info.repo.substr(info.repo.length - 4) === '.git') { - info.repo = info.repo.substr(0, info.repo.length - 4); + if (info.repo.endsWith('.git')) { + info.repo = info.repo.slice(0, -4); } } @@ -220,11 +224,11 @@ async function collect(latestVersion) { return false; } - let message = line.substr(1); + let message = line.slice(1); const i = message.indexOf('('); if (i > 0) { - message = message.substr(0, i).trim(); + message = message.substring(0, i).trim(); } // 忽略重复的提交信息 if (messages.has(message)) { -- Gitee