Commit 77152e9f by 刘旭阳

Merge branch '0.0.9' into 'master'

feat:增量代码插桩增加,优化插桩代码 See merge request !9
parents 97ebaf16 71a77430
...@@ -21,7 +21,7 @@ Serve packjson启动增加配置到时候不需要可以更改IS_PITCHING_PILE ...@@ -21,7 +21,7 @@ Serve packjson启动增加配置到时候不需要可以更改IS_PITCHING_PILE
IS_PITCHING_PILE是否插桩 IS_PITCHING_PILE是否插桩
INCREMENT是否过滤增量文件 INCREMENT是否过滤增量文件
BRANCH需要对比的分支isPitchingPile为true时默认origin/master当ISPITCHINGPILE为false的时候可以不穿 BRANCH需要对比的分支isPitchingPile为true时默认origin/master当ISPITCHINGPILE为false的时候可以不穿
二种(第一种后期优化加上现在使用第二种如参方式) 一种
[ [
babel-plugin-ry-istanbul, babel-plugin-ry-istanbul,
{ {
...@@ -32,7 +32,7 @@ BRANCH需要对比的分支isPitchingPile为true时默认origin/master当ISPITCH ...@@ -32,7 +32,7 @@ BRANCH需要对比的分支isPitchingPile为true时默认origin/master当ISPITCH
] ]
## 新增全局传值方法 ## 新增全局传值方法
IS_PITCHING_PILE是否插桩 IS_PITCHING_PILE是否插桩
INCREMENT是否过滤增量文件 INCREMENT是否插桩增量代码
BRANCH需要对比的分支isPitchingPile为true时默认origin/master当ISPITCHINGPILE为false的时候可以不穿 BRANCH需要对比的分支isPitchingPile为true时默认origin/master当ISPITCHINGPILE为false的时候可以不穿
全局配置:如.env.dev文件下增加全局变量插桩,babel-plugin-ry-istanbul同样可以取到对应值,如VUE全局变量前记得添加VUE_APP_前缀,其他则需要看使用框架是否需要添加前缀 全局配置:如.env.dev文件下增加全局变量插桩,babel-plugin-ry-istanbul同样可以取到对应值,如VUE全局变量前记得添加VUE_APP_前缀,其他则需要看使用框架是否需要添加前缀
## 新增parse-diff ## 新增parse-diff
......
{ {
"name": "babel-plugin-ry-istanbul-web", "name": "babel-plugin-ry-istanbul-web",
"version": "0.0.6", "version": "0.0.9",
"author": "Thai Pangsakulyanont @dtinth", "author": "Thai Pangsakulyanont @dtinth",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"description": "A babel plugin that adds istanbul instrumentation to ES6 code", "description": "A babel plugin that adds istanbul instrumentation to ES6 code",
...@@ -54,6 +54,9 @@ ...@@ -54,6 +54,9 @@
"standard": "^14.3.1", "standard": "^14.3.1",
"standard-version": "^3.0.0" "standard-version": "^3.0.0"
}, },
"peerDependenciesMeta": {
},
"scripts": { "scripts": {
"coverage": "nyc report --reporter=text-lcov | coveralls", "coverage": "nyc report --reporter=text-lcov | coveralls",
"release": "babel src --out-dir lib", "release": "babel src --out-dir lib",
......
...@@ -103,6 +103,7 @@ function isValue(item, isNumber = false, defaultNumber) { ...@@ -103,6 +103,7 @@ function isValue(item, isNumber = false, defaultNumber) {
} }
return data return data
} }
export default declare(api => { export default declare(api => {
api.assertVersion(7) api.assertVersion(7)
const shouldSkip = makeShouldSkip() const shouldSkip = makeShouldSkip()
...@@ -116,9 +117,9 @@ export default declare(api => { ...@@ -116,9 +117,9 @@ export default declare(api => {
this.__dv__ = null this.__dv__ = null
this.nycConfig = findConfig(this.opts) this.nycConfig = findConfig(this.opts)
const realPath = getRealpath(this.file.opts.filename) const realPath = getRealpath(this.file.opts.filename)
const { instrmenttation } = this.nycConfig // npm引入参数 const { instrmenttation = {} } = this.nycConfig // npm引入参数
let IS_PITCHING_PILE_DATA = false let IS_PITCHING_PILE_DATA = true
let INCREMENT_DATA = false let INCREMENT_DATA = true
let BRANCH_DATA = 'origin/master' let BRANCH_DATA = 'origin/master'
let processData = {} let processData = {}
Object.keys(process.env).forEach(item => { Object.keys(process.env).forEach(item => {
...@@ -135,14 +136,14 @@ export default declare(api => { ...@@ -135,14 +136,14 @@ export default declare(api => {
// Object.keys(processData).length // Object.keys(processData).length
}) })
// 全局变量优先 // 全局变量优先
if (Object.keys(processData).length) { if (Object.keys(instrmenttation).length) {
BRANCH_DATA = isValue(processData.BRANCH, false, BRANCH_DATA)
INCREMENT_DATA = isValue(processData.INCREMENT, false, INCREMENT_DATA)
IS_PITCHING_PILE_DATA = isValue(processData.IS_PITCHING_PILE, false, IS_PITCHING_PILE_DATA)
} else if (Object.keys(instrmenttation).length) {
BRANCH_DATA = isValue(instrmenttation.BRANCH, false, BRANCH_DATA) BRANCH_DATA = isValue(instrmenttation.BRANCH, false, BRANCH_DATA)
INCREMENT_DATA = isValue(instrmenttation.INCREMENT, false, INCREMENT_DATA) INCREMENT_DATA = isValue(instrmenttation.INCREMENT, false, INCREMENT_DATA)
IS_PITCHING_PILE_DATA = isValue(instrmenttation.IS_PITCHING_PILE, false, IS_PITCHING_PILE_DATA) IS_PITCHING_PILE_DATA = isValue(instrmenttation.IS_PITCHING_PILE, false, IS_PITCHING_PILE_DATA)
} else if (Object.keys(processData).length) {
BRANCH_DATA = isValue(processData.BRANCH, false, BRANCH_DATA)
INCREMENT_DATA = isValue(processData.INCREMENT, false, INCREMENT_DATA)
IS_PITCHING_PILE_DATA = isValue(processData.IS_PITCHING_PILE, false, IS_PITCHING_PILE_DATA)
} }
// instrumenttation (branch: git diff 跟那个分支对比, increment 是否开启增量代码检测) 拿配置到底是全量代码还是增量代码 // instrumenttation (branch: git diff 跟那个分支对比, increment 是否开启增量代码检测) 拿配置到底是全量代码还是增量代码
if (!IS_PITCHING_PILE_DATA || IS_PITCHING_PILE_DATA === 'false') { if (!IS_PITCHING_PILE_DATA || IS_PITCHING_PILE_DATA === 'false') {
...@@ -181,7 +182,7 @@ export default declare(api => { ...@@ -181,7 +182,7 @@ export default declare(api => {
} }
}) })
// 后增加|| !increment这个条件判断条件后面加上 // 后增加|| !increment这个条件判断条件后面加上
if (diffScreen !== null && !diffScreen && (INCREMENT_DATA || INCREMENT_DATA === 'true')) { if (diffScreen !== null && diffScreen && (INCREMENT_DATA || INCREMENT_DATA === 'true')) {
// if (diffScreen) { // if (diffScreen) {
if (Array.isArray(diffScreen && diffScreen.chunks)) { if (Array.isArray(diffScreen && diffScreen.chunks)) {
diffScreen.chunks.forEach(item => { diffScreen.chunks.forEach(item => {
...@@ -225,6 +226,56 @@ export default declare(api => { ...@@ -225,6 +226,56 @@ export default declare(api => {
} }
} }
}) })
// export default declare(api => {
// api.assertVersion(7)
// console.log(api, 'api')
// const shouldSkip = makeShouldSkip()
// const t = api.types
// return {
// visitor: {
// Program: {
// enter (path) {
// console.log(121212121)
// this.__dv__ = null
// this.nycConfig = findConfig(this.opts)
// const realPath = getRealpath(this.file.opts.filename)
// if (shouldSkip(realPath, this.nycConfig)) {
// return
// }
// let { inputSourceMap } = this.opts
// if (this.opts.useInlineSourceMaps !== false) {
// if (!inputSourceMap && this.file.inputMap) {
// inputSourceMap = this.file.inputMap.sourcemap
// }
// }
// const visitorOptions = {}
// Object.entries(schema.defaults.instrumentVisitor).forEach(([name, defaultValue]) => {
// if (name in this.nycConfig) {
// visitorOptions[name] = this.nycConfig[name]
// } else {
// visitorOptions[name] = schema.defaults.instrumentVisitor[name]
// }
// })
// this.__dv__ = programVisitor(t, realPath, {
// ...visitorOptions,
// inputSourceMap
// })
// this.__dv__.enter(path)
// },
// exit (path) {
// if (!this.__dv__) {
// return
// }
// const result = this.__dv__.exit(path)
// if (this.opts.onCover) {
// this.opts.onCover(getRealpath(this.file.opts.filename), result.fileCoverage)
// }
// }
// }
// }
// }
// })
// 增量代码babel引入方法 babel.js 或 babel.config.js // 增量代码babel引入方法 babel.js 或 babel.config.js
// 'plugins': [ // 'plugins': [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment