Commit 28dea982 by lxyang

feat:0.0.2-bat 新增全局变量传输接收方式process.env同样可取到对应配置后插桩全量或增量代码文件抑或是禁止插桩。

parent 67d840bc
# babel-plugin-istanbul
# babel-plugin-ry-istanbul
[![Coverage Status](https://coveralls.io/repos/github/istanbuljs/babel-plugin-istanbul/badge.svg?branch=master)](https://coveralls.io/github/istanbuljs/babel-plugin-istanbul?branch=master)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
......@@ -30,12 +30,17 @@ BRANCH需要对比的分支isPitchingPile为true时默认origin/master当ISPITCH
}
]
]
## 新增全局传值方法
IS_PITCHING_PILE是否插桩
INCREMENT是否过滤增量文件
BRANCH需要对比的分支isPitchingPile为true时默认origin/master当ISPITCHINGPILE为false的时候可以不穿
全局配置:如.env.dev文件下增加全局变量插桩,babel-plugin-ry-istanbul同样可以取到对应值,如VUE全局变量前记得添加VUE_APP_前缀,其他则需要看使用框架是否需要添加前缀
## Usage
Install it:
```
npm install --save-dev babel-plugin-istanbul
npm install --save-dev babel-plugin-ry-istanbul
```
Add it to `.babelrc` in test mode:
......@@ -73,7 +78,7 @@ It has been tested with [bemusic/bemuse](https://codecov.io/github/bemusic/bemus
Configure Mocha to transpile JavaScript code using Babel, then you can run your tests with [`nyc`](https://github.com/bcoe/nyc), which will collect all the coverage report.
babel-plugin-istanbul respects the `include`/`exclude` configuration options from nyc,
babel-plugin-ry-istanbul respects the `include`/`exclude` configuration options from nyc,
but you also need to __configure NYC not to instrument your code__ by adding these settings in your `package.json`:
```js
......@@ -127,7 +132,7 @@ By default, this plugin will pick up inline source maps and attach them to the i
If you're instrumenting code programatically, you can pass a source map explicitly.
```js
import babelPluginIstanbul from 'babel-plugin-istanbul';
import babelPluginIstanbul from 'babel-plugin-ry-istanbul';
function instrument(sourceCode, sourceMap, fileName) {
return babel.transform(sourceCode, {
......@@ -143,10 +148,10 @@ function instrument(sourceCode, sourceMap, fileName) {
## Credit where credit is due
The approach used in `babel-plugin-istanbul` was inspired by [Thai Pangsakulyanont](https://github.com/dtinth)'s original library [`babel-plugin-__coverage__`](https://github.com/dtinth/babel-plugin-__coverage__).
The approach used in `babel-plugin-ry-istanbul` was inspired by [Thai Pangsakulyanont](https://github.com/dtinth)'s original library [`babel-plugin-__coverage__`](https://github.com/dtinth/babel-plugin-__coverage__).
## `babel-plugin-istanbul` for enterprise
## `babel-plugin-ry-istanbul` for enterprise
Available as part of the Tidelift Subscription.
The maintainers of `babel-plugin-istanbul` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-babel-plugin-istanbul?utm_source=npm-babel-plugin-istanbul&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
The maintainers of `babel-plugin-ry-istanbul` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-babel-plugin-ry-istanbul?utm_source=npm-babel-plugin-ry-istanbul&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
{
"name": "babel-plugin-ry-istanbul",
"version": "0.0.1-bat",
"version": "0.0.2-bat",
"author": "Thai Pangsakulyanont @dtinth",
"license": "BSD-3-Clause",
"description": "A babel plugin that adds istanbul instrumentation to ES6 code",
......
......@@ -108,14 +108,36 @@ export default declare(api => {
this.nycConfig = findConfig(this.opts)
const realPath = getRealpath(this.file.opts.filename)
const { instrmenttation } = this.nycConfig // npm引入参数
const {
IS_PITCHING_PILE = false,
INCREMENT = false,
BRANCH = 'origin/master'
} = instrmenttation || {} // 是否全量代码和对比分支
console.log(IS_PITCHING_PILE, INCREMENT, BRANCH, 'IS_PITCHING_PILE, INCREMENT, BRANCH')
let IS_PITCHING_PILE_DATA = false
let INCREMENT_DATA = false
let BRANCH_DATA = 'origin/master'
let processData = {}
Object.keys(process.env).forEach(item => {
let isItem =
typeof process.env[item] === 'string' ? Boolean(process.env[item]) : process.env[item]
if (item.indexOf('INCREMENT')) {
processData.INCREMENT = isItem
}
if (item.indexOf('IS_PITCHING_PILE')) {
processData.IS_PITCHING_PILE = isItem
}
if (item.indexOf('PROSRC')) {
processData.PROSRC = process.env[item]
}
// Object.keys(processData).length
})
// 全局变量优先
if (Object.keys(processData).length) {
BRANCH_DATA = processData.BRANCH
INCREMENT_DATA = processData.INCREMENT
IS_PITCHING_PILE_DATA = processData.IS_PITCHING_PILE
} else if (Object.keys(instrmenttation).length) {
BRANCH_DATA = instrmenttation.BRANCH
INCREMENT_DATA = instrmenttation.INCREMENT
IS_PITCHING_PILE_DATA = instrmenttation.IS_PITCHING_PILE
}
// instrumenttation (branch: git diff 跟那个分支对比, increment 是否开启增量代码检测) 拿配置到底是全量代码还是增量代码
if (!IS_PITCHING_PILE) {
if (!IS_PITCHING_PILE_DATA) {
return
}
// const changeList = []
......@@ -126,8 +148,8 @@ export default declare(api => {
// return realPath.indexOf(item.to) > -1
// })
// 后面解开
if (INCREMENT && BRANCH) {
const gitDiffCode = execSync(`git diff ${BRANCH}`)
if (INCREMENT_DATA && BRANCH_DATA) {
const gitDiffCode = execSync(`git diff ${BRANCH_DATA}`)
const diffData = parseDiffData(gitDiffCode.toString())
diffScreen = diffData.find(item => {
return realPath.indexOf(item.to) > -1
......
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