Commit 87586db7 by lxyang

feat: 增加IS_HTML_CSS参数,是否能查看vue文件的html结构

parent ee601c00
......@@ -28,6 +28,7 @@ npm install --save-dev babel-plugin-ry-istanbul
| IS_PITCHING_PILE | Whether in pile | String/Boolean | true (String、Boolean) /false (String、Boolean) | false (Boolean) | false (String, Boolean) true (String) disables instrumentation, true (Boolean) allows it |
| INCREMENT | Whether to filter delta files | String/Boolean | true (String、Boolean) /false (String、Boolean) | false (Boolean) | true (String, Boolean) looks at incremental code, false (String) looks at the full code (including incremental code), false (Boolean) looks at the full code, and does not display new or changed statements. |
| BRANCH | git diff the branch to compare against | String | The branch name to compare against | origin/master | Don't wear it when the IS PITCHING PILE is false |
| IS_HTML_CSS | Whether you can view the html structure of a vue file | Boolean | You can pass false if you don't want to see the html structure | true | false does not allow you to view html or css structures; true allows you to view html or css structures |
## 增加参数说明instrmenttation
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 其他说明 |
......@@ -35,6 +36,8 @@ npm install --save-dev babel-plugin-ry-istanbul
| IS_PITCHING_PILE | 是否插桩 | String/Boolean | true (String、Boolean) /false (String、Boolean) | false(Boolean) | false (String、Boolean) true(String)禁止插桩,true (Boolean)允许插桩 |
| INCREMENT | 是否过滤增量文件 | String/Boolean | true (String、Boolean) /false (String、Boolean) | false(Boolean) | true(String、Boolean)看增量代码,false(String)看全量代码(包括增量代码), false(Boolean)看全量代码,不显示“新增或变更语句” |
| BRANCH | git diff需要对比的分支 | String | 需要对比的分支名 | origin/master | 当IS_PITCHING_PILE为false的时候可以不穿 |
| IS_HTML_CSS | 是否能查看vue文件的html结构 | Boolean | 如果不想看到html结构可以传输false | true | false不能看html、css结构, true可以看html、css结构 |
## Increment interpolation
*In the case of `vue`, This is done via babel.config.js's plugins configuration, as shown in the following code:
......@@ -47,7 +50,8 @@ plugins: [
instrmenttation: {
BRANCH: 'origin/master',
INCREMENT: 'true',
IS_PITCHING_PILE: true
IS_PITCHING_PILE: true,
IS_HTML_CSS: false
}
}
]
......@@ -66,7 +70,8 @@ plugins: [
instrmenttation: {
BRANCH: 'origin/master',
INCREMENT: 'true',
IS_PITCHING_PILE: true
IS_PITCHING_PILE: true,
IS_HTML_CSS: false
}
}
]
......@@ -79,11 +84,13 @@ plugins: [
1. IS_PITCHING_PILE determines if code coverage can be instrumentalized
2. Use the BRANCH parameter to identify the git branch you want to compare against
3. Use INCREMENT to determine if you want to see the incremental code
4. IS HTML CSS to determine if vue should look at html and css structure
## 新增功能说明
* 新增instrmenttation参数
1. 通过IS_PITCHING_PILE判断是否可以插装收集代码覆盖率
2. 通过BRANCH参数确认需要对比的git分支
3. 通过INCREMENT判断是否需要查看增量代码
4. 通过IS_HTML_CSS判断vue下是否要看html及css结构
## other description
......
{
"name": "babel-plugin-istanbul-ry",
"version": "0.0.2",
"version": "0.0.3",
"author": "Thai Pangsakulyanont @dtinth",
"license": "BSD-3-Clause",
"description": "A babel plugin that adds istanbul instrumentation to ES6 code",
......@@ -21,7 +21,7 @@
"cross-env": "^7.0.3",
"istanbul-lib-coverage": "^1.0.0",
"onchange": "^7.1.0",
"ry-istanbul-web": "^0.0.1",
"ry-istanbul-web": "^0.0.4",
"semver": "^6.3.0",
"test-exclude": "^6.0.0"
},
......@@ -54,9 +54,7 @@
"standard": "^14.3.1",
"standard-version": "^3.0.0"
},
"peerDependenciesMeta": {
},
"peerDependenciesMeta": {},
"scripts": {
"coverage": "nyc report --reporter=text-lcov | coveralls",
"release": "babel src --out-dir lib",
......
const path = require('path')
import { realpathSync } from 'fs'
import { execFileSync, execSync } from 'child_process'
import { declare } from '@babel/helper-plugin-utils'
import { programVisitor } from './dist'
// import { programVisitor } from 'istanbul-lib-instrument'
import TestExclude from 'test-exclude'
import schema from '@istanbuljs/schema'
import parseDiffData from './parse-diff'
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _fs = require("fs");
var _child_process = require("child_process");
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _dist = require("./dist");
var _testExclude = _interopRequireDefault(require("test-exclude"));
var _schema = _interopRequireDefault(require("@istanbuljs/schema"));
var _parseDiff = _interopRequireDefault(require("./parse-diff"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const path = require('path');
function getRealpath(n) {
try {
return realpathSync(n) || /* istanbul ignore next */ n
return (0, _fs.realpathSync)(n) ||
/* istanbul ignore next */
n;
} catch (e) {
/* istanbul ignore next */
return n
return n;
}
}
const memoize = new Map()
const memoize = new Map();
/* istanbul ignore next */
const memosep = path.sep === '/' ? ':' : ';'
function loadNycConfig (cwd, opts) {
let memokey = cwd
const args = [
path.resolve(__dirname, 'load-nyc-config-sync.js'),
cwd
]
const memosep = path.sep === '/' ? ':' : ';';
if ('nycrcPath' in opts) {
args.push(opts.nycrcPath)
function loadNycConfig(cwd, opts) {
let memokey = cwd;
const args = [path.resolve(__dirname, 'load-nyc-config-sync.js'), cwd];
memokey += memosep + opts.nycrcPath
if ('nycrcPath' in opts) {
args.push(opts.nycrcPath);
memokey += memosep + opts.nycrcPath;
}
/* execFileSync is expensive, avoid it if possible! */
if (memoize.has(memokey)) {
return memoize.get(memokey)
return memoize.get(memokey);
}
const result = JSON.parse(execFileSync(process.execPath, args))
const error = result['load-nyc-config-sync-error']
const result = JSON.parse((0, _child_process.execFileSync)(process.execPath, args));
const error = result['load-nyc-config-sync-error'];
if (error) {
throw new Error(error)
throw new Error(error);
}
const config = {
...schema.defaults.babelPluginIstanbul,
const config = { ..._schema.default.defaults.babelPluginIstanbul,
cwd,
...result
}
memoize.set(memokey, config)
return config
};
memoize.set(memokey, config);
return config;
}
function findConfig (opts) {
const cwd = getRealpath(opts.cwd || process.env.NYC_CWD || /* istanbul ignore next */ process.cwd())
const keys = Object.keys(opts)
const ignored = Object.keys(opts).filter(s => s === 'nycrcPath' || s === 'cwd')
function findConfig(opts) {
const cwd = getRealpath(opts.cwd || process.env.NYC_CWD ||
/* istanbul ignore next */
process.cwd());
const keys = Object.keys(opts);
const ignored = Object.keys(opts).filter(s => s === 'nycrcPath' || s === 'cwd');
if (keys.length > ignored.length) {
// explicitly configuring options in babel
// takes precedence.
return {
...schema.defaults.babelPluginIstanbul,
return { ..._schema.default.defaults.babelPluginIstanbul,
cwd,
...opts
}
};
}
if (ignored.length === 0 && process.env.NYC_CONFIG) {
// defaults were already applied by nyc
return JSON.parse(process.env.NYC_CONFIG)
return JSON.parse(process.env.NYC_CONFIG);
}
return loadNycConfig(cwd, opts)
return loadNycConfig(cwd, opts);
}
function makeShouldSkip () {
let exclude
return function shouldSkip (file, nycConfig) {
if (!exclude || (exclude.cwd !== nycConfig.cwd)) {
exclude = new TestExclude({
function makeShouldSkip() {
let exclude;
return function shouldSkip(file, nycConfig) {
if (!exclude || exclude.cwd !== nycConfig.cwd) {
exclude = new _testExclude.default({
cwd: nycConfig.cwd,
include: nycConfig.include,
exclude: nycConfig.exclude,
extension: nycConfig.extension,
// Make sure this is true unless explicitly set to `false`. `undefined` is still `true`.
excludeNodeModules: nycConfig.excludeNodeModules !== false
})
});
}
return !exclude.shouldInstrument(file)
}
return !exclude.shouldInstrument(file);
};
}
function isValue(item, isNumber = false, defaultNumber) {
let data = ''
let data = '';
if (isNumber) {
data = item ? Number(item) : defaultNumber
data = item ? Number(item) : defaultNumber;
} else {
data = item ? item : defaultNumber
data = item ? item : defaultNumber;
}
return data
return data;
}
export default declare(api => {
api.assertVersion(7)
const shouldSkip = makeShouldSkip()
const t = api.types
var _default = (0, _helperPluginUtils.declare)(api => {
api.assertVersion(7);
const shouldSkip = makeShouldSkip();
const t = api.types;
return {
visitor: {
Program: {
enter(path) {
// 筛选后的数据增量文件
let diffScreen = null
this.__dv__ = null
this.nycConfig = findConfig(this.opts)
const realPath = getRealpath(this.file.opts.filename)
const { instrmenttation = {} } = this.nycConfig // npm引入参数
let IS_PITCHING_PILE_DATA = false
let INCREMENT_DATA = false
let BRANCH_DATA = 'origin/master'
let processData = {}
let diffScreen = null;
this.__dv__ = null;
this.nycConfig = findConfig(this.opts);
const realPath = getRealpath(this.file.opts.filename);
const {
instrmenttation = {}
} = this.nycConfig; // npm引入参数
let IS_PITCHING_PILE_DATA = false;
let INCREMENT_DATA = false;
let IS_HTML_CSS = false; // 是否能看html结构
let BRANCH_DATA = 'origin/master';
let processData = {};
Object.keys(process.env).forEach(item => {
let isItem = process.env[item]
let isItem = process.env[item];
if (item.indexOf('IS_HTML_CSS') !== -1) {
processData.IS_HTML_CSS = isItem;
}
if (item.indexOf('INCREMENT') !== -1) {
processData.INCREMENT = isItem
processData.INCREMENT = isItem;
}
if (item.indexOf('IS_PITCHING_PILE') !== -1) {
processData.IS_PITCHING_PILE = isItem
processData.IS_PITCHING_PILE = isItem;
}
if (item.indexOf('BRANCH') !== -1) {
processData.BRANCH = process.env[item]
}
// Object.keys(processData).length
})
// 全局变量优先
processData.BRANCH = process.env[item];
} // Object.keys(processData).length
}); // 全局变量优先
if (Object.keys(instrmenttation).length) {
BRANCH_DATA = isValue(instrmenttation.BRANCH, false, 'origin/master')
INCREMENT_DATA = isValue(instrmenttation.INCREMENT, false, 'false')
IS_PITCHING_PILE_DATA = isValue(instrmenttation.IS_PITCHING_PILE, false, false)
BRANCH_DATA = isValue(instrmenttation.BRANCH, false, 'origin/master');
INCREMENT_DATA = isValue(instrmenttation.INCREMENT, false, 'false');
IS_PITCHING_PILE_DATA = isValue(instrmenttation.IS_PITCHING_PILE, false, false);
IS_HTML_CSS = isValue(instrmenttation.IS_HTML_CSS, false, false);
} else if (Object.keys(processData).length) {
BRANCH_DATA = isValue(processData.BRANCH, false, 'origin/master')
INCREMENT_DATA = isValue(processData.INCREMENT, false, 'false')
IS_PITCHING_PILE_DATA = isValue(processData.IS_PITCHING_PILE, false, false)
}
// instrumenttation (branch: git diff 跟那个分支对比, increment 是否开启增量代码检测) 拿配置到底是全量代码还是增量代码
BRANCH_DATA = isValue(processData.BRANCH, false, 'origin/master');
INCREMENT_DATA = isValue(processData.INCREMENT, false, 'false');
IS_PITCHING_PILE_DATA = isValue(processData.IS_PITCHING_PILE, false, false);
IS_HTML_CSS = isValue(processData.IS_HTML_CSS, false, false);
} // instrumenttation (branch: git diff 跟那个分支对比, increment 是否开启增量代码检测) 拿配置到底是全量代码还是增量代码
if (!IS_PITCHING_PILE_DATA || IS_PITCHING_PILE_DATA === 'false') {
return false
return false;
}
const changeList = []
// 下面的是零时的
const changeList = []; // 下面的是零时的
// // const gitDiffCode = execSync(`git diff ${branch}`)
// const diffData = parseDiffData(gitDiffCode.toString())
// diffScreen = diffData.find(item => {
// return realPath.indexOf(item.to) > -1
// })
// 后面解开
if ((INCREMENT_DATA || INCREMENT_DATA === 'true') && BRANCH_DATA) {
const gitDiffCode = execSync(`git add . && git diff --cached ${BRANCH_DATA}`)
const diffData = parseDiffData(gitDiffCode.toString())
const gitDiffCode = (0, _child_process.execSync)(`git add . && git diff --cached ${BRANCH_DATA}`);
const diffData = (0, _parseDiff.default)(gitDiffCode.toString());
const less = '.less';
const css = '.css';
diffScreen = diffData.find(item => {
return realPath.indexOf(item.to) > -1
})
if (IS_HTML_CSS) {
return realPath.indexOf(item.to) > -1;
} else {
return realPath.indexOf(item.to) > -1 && realPath.indexOf(less) === -1 && realPath.indexOf(css) === -1;
}
});
}
if (shouldSkip(realPath, this.nycConfig)) {
return
return;
}
let { inputSourceMap } = this.opts
let {
inputSourceMap
} = this.opts;
if (this.opts.useInlineSourceMaps) {
if (!inputSourceMap && this.file.inputMap) {
inputSourceMap = this.file.inputMap.sourcemap
inputSourceMap = this.file.inputMap.sourcemap;
}
}
const visitorOptions = {}
Object.entries(schema.defaults.instrumentVisitor).forEach(([name, defaultValue]) => {
const visitorOptions = {};
Object.entries(_schema.default.defaults.instrumentVisitor).forEach(([name, defaultValue]) => {
if (name in this.nycConfig) {
visitorOptions[name] = this.nycConfig[name]
visitorOptions[name] = this.nycConfig[name];
} else {
visitorOptions[name] = schema.defaults.instrumentVisitor[name]
visitorOptions[name] = _schema.default.defaults.instrumentVisitor[name];
}
})
// 后增加|| !increment这个条件判断条件后面加上
}); // 后增加|| !increment这个条件判断条件后面加上
if (diffScreen !== null && diffScreen && (INCREMENT_DATA || INCREMENT_DATA === 'true')) {
// if (diffScreen) {
if (Array.isArray(diffScreen && diffScreen.chunks)) {
diffScreen.chunks.forEach(item => {
let changes = Array.isArray(item.changes) ? item.changes : []
let changes = Array.isArray(item.changes) ? item.changes : [];
changes.forEach(items => {
if (items && items.add) {
changeList.push(items.ln)
changeList.push(items.ln);
}
})
})
});
});
}
if (changeList.length) {
visitorOptions.changeList = changeList
// changeList
this.__dv__ = programVisitor(t, realPath, {
...visitorOptions,
visitorOptions.changeList = changeList;
visitorOptions.IS_HTML_CSS = IS_HTML_CSS; // changeList
this.__dv__ = (0, _dist.programVisitor)(t, realPath, { ...visitorOptions,
inputSourceMap
})
this.__dv__.enter(path)
}
// }
});
this.__dv__.enter(path);
} // }
} else if (!INCREMENT_DATA || INCREMENT_DATA === 'false') {
visitorOptions.changeList = changeList
this.__dv__ = programVisitor(t, realPath, {
...visitorOptions,
inputSourceMap,
})
this.__dv__.enter(path)
visitorOptions.changeList = changeList;
visitorOptions.IS_HTML_CSS = IS_HTML_CSS;
this.__dv__ = (0, _dist.programVisitor)(t, realPath, { ...visitorOptions,
inputSourceMap
});
this.__dv__.enter(path);
}
},
exit(path) {
if (!this.__dv__) {
return
return;
}
const result = this.__dv__.exit(path)
const result = this.__dv__.exit(path);
if (this.opts.onCover) {
this.opts.onCover(getRealpath(this.file.opts.filename), result.fileCoverage)
}
this.opts.onCover(getRealpath(this.file.opts.filename), result.fileCoverage);
}
}
}
}
})
// export default declare(api => {
};
}); // export default declare(api => {
// api.assertVersion(7)
// console.log(api, 'api')
// const shouldSkip = makeShouldSkip()
// const t = api.types
// return {
// visitor: {
......@@ -276,7 +325,6 @@ export default declare(api => {
// }
// }
// })
// 增量代码babel引入方法 babel.js 或 babel.config.js
// 'plugins': [
// ['@hliang/babel-plugin-transfrom-modules-commonjs', {
......@@ -287,3 +335,6 @@ export default declare(api => {
// }
// }]
// ]
exports.default = _default;
\ No newline at end of file
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