diff --git a/bin/keepfast-report.js b/bin/keepfast-report.js index 26e00514d424e3ce7ead647eaef1e7d8c70b357f..df7cb62d32c046b03e61a1d15633fc4712969c3f 100644 --- a/bin/keepfast-report.js +++ b/bin/keepfast-report.js @@ -44,7 +44,7 @@ function parseBuildReportFile(file) { } } -// 获取 vue-cli-service 进程 id +// 获取构建进程 id async function getBuildToolPid(config) { if (!config.tool) { throw new Error(`invalid tool name: ${config.tool}`) @@ -61,14 +61,15 @@ async function getBuildToolPid(config) { } psList().then((list) => { let proc = null - const cmd = `bin/${config.tool}` list.forEach((p) => { // 匹配: + // webpack + // webpack --mode production // .bin/webpack // .bin/webpack --mode production // 不匹配: // .bin/webpack-dev-server - if (p.cmd.includes(`${cmd} `) || p.cmd.endsWith(cmd)) { + if (p.cmd.split(' ').some((cmd) => cmd.endsWith(`.bin/${config.tool}`) || cmd === config.tool)) { // 新进程的 pid 比较大,所以该进程最有可能是目标进程 if (!proc || proc.pid < p.pid) { proc = p @@ -115,7 +116,7 @@ async function generateBuildReport(config) { maxMemoryUsage = Math.max(stats.memory, maxMemoryUsage) }) }, 1000) - }) + }).catch(reject) }) try { diff --git a/bin/keepfast-upload.js b/bin/keepfast-upload.js index ba97e83f29b02ac2c238958785e649cb63dfd5df..24f808a18a9c3b615562af9c071aca1e93908aaf 100644 --- a/bin/keepfast-upload.js +++ b/bin/keepfast-upload.js @@ -41,7 +41,8 @@ async function uploadToCommit(config, report, commitSha) { const comment = commentsRes.data.find((item) => item.user.id === userRes.data.id) if (comment) { - return axios.patch(`${baseUrl}/comments/${comment.id}`, { body: report }) + console.log(`delete comment @${commitSha}/${comment.id}`) + await axios.delete(`${baseUrl}/comments/${comment.id}`, { body: report }) } return axios.post(commitCommentsUrl, { body: report }) } @@ -61,7 +62,8 @@ async function uploadToPullRequest(config, report, pull) { const comment = commentsRes.data.find((item) => item.user.id === userRes.data.id) if (comment) { - axios.delete(`${baseUrl}/comments/${comment.id}`) + console.log(`delete comment #${pull.number}/${comment.id}`) + await axios.delete(`${baseUrl}/comments/${comment.id}`) } return axios.post(pullCommentsUrl, { body: report }) }