diff --git a/plugins/babel-plugin-canyon/src/helpers/provider.ts b/plugins/babel-plugin-canyon/src/helpers/provider.ts index 5aa93f8e..7551de0d 100644 --- a/plugins/babel-plugin-canyon/src/helpers/provider.ts +++ b/plugins/babel-plugin-canyon/src/helpers/provider.ts @@ -49,5 +49,12 @@ export function walkProviders(inputs: UploaderInputs): IServiceParams { return provider.getServiceParams(inputs) } } - throw new Error(`Unable to detect provider.`) + // 返回默认值 + return { + projectID: '-', + sha: '-', + instrumentCwd: '-', + branch: '-', + } + // throw new Error(`Unable to detect provider.`) } diff --git a/plugins/babel-plugin-canyon/src/index.ts b/plugins/babel-plugin-canyon/src/index.ts index 0b20219b..a571c32d 100644 --- a/plugins/babel-plugin-canyon/src/index.ts +++ b/plugins/babel-plugin-canyon/src/index.ts @@ -13,6 +13,8 @@ export default declare((api, config) => { exit: (path) => { // 侦测流水线 // 优先级:手动设置 > CI/CD提供商 + // hit需要打到__coverage__中,因为ui自动化测试工具部署地方不确定 + // map就不需要,写到本地时,可以侦测本地流水线变量,直接上报上来 const serviceParams = detectProvider({ envs: process.env, args: { @@ -23,7 +25,7 @@ export default declare((api, config) => { } }) console.log(serviceParams,'serviceParams') - visitorProgramExit(api,path) + visitorProgramExit(api,path,serviceParams) } }, }, diff --git a/plugins/babel-plugin-canyon/src/visitor-program-exit.ts b/plugins/babel-plugin-canyon/src/visitor-program-exit.ts index 7d415572..e5fb8264 100644 --- a/plugins/babel-plugin-canyon/src/visitor-program-exit.ts +++ b/plugins/babel-plugin-canyon/src/visitor-program-exit.ts @@ -1,7 +1,8 @@ import {generateInitialCoverage} from "./helpers/generate-initial-coverage"; import generate from "@babel/generator"; -export const visitorProgramExit = (api,path) => { +// 关键参数 serviceParams ,它由 detectProvider 函数返回,手动设置的参数优先级高于 CI/CD 提供商 +export const visitorProgramExit = (api,path,serviceParams) => { // 生成初始覆盖率数据 generateInitialCoverage(generate(path.node).code) if (generate(path.node).code.includes('coverageData')) { @@ -41,19 +42,19 @@ export const visitorProgramExit = (api,path) => { // 增加 sha 字段 const shaField = t.objectProperty( t.identifier("sha"), // 键名 - t.stringLiteral('__canyon__.COMMIT_SHA') // 键值 + t.stringLiteral(serviceParams.sha) // 键值 ); properties.push(shaField); // 添加新字段 // 增加 sha 字段 const projectIDField = t.objectProperty( t.identifier("projectID"), // 键名 - t.stringLiteral('__canyon__.PROJECT_ID') // 键值 + t.stringLiteral(serviceParams.projectID) // 键值 ); properties.push(projectIDField); // 添加新字段 // 增加 sha 字段 const instrumentCwdField = t.objectProperty( t.identifier("instrumentCwd"), // 键名 - t.stringLiteral('__canyon__.INSTRUMENT_CWD') // 键值 + t.stringLiteral(serviceParams.instrumentCwd) // 键值 ); properties.push(instrumentCwdField); // 添加新字段 }