Commit fb018631 by 刘旭阳

Merge branch '0.1.1' into 'master'

feat: 增加IS_HTML_CSS参数,是否能查看vue文件的html结构 See merge request !14
parents d6e49efd 87586db7
...@@ -28,6 +28,7 @@ npm install --save-dev babel-plugin-ry-istanbul ...@@ -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 | | 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. | | 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 | | 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 ## 增加参数说明instrmenttation
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 其他说明 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 其他说明 |
...@@ -35,6 +36,8 @@ npm install --save-dev babel-plugin-ry-istanbul ...@@ -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)允许插桩 | | 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)看全量代码,不显示“新增或变更语句” | | 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的时候可以不穿 | | 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 ## Increment interpolation
*In the case of `vue`, This is done via babel.config.js's plugins configuration, as shown in the following code: *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: [ ...@@ -47,7 +50,8 @@ plugins: [
instrmenttation: { instrmenttation: {
BRANCH: 'origin/master', BRANCH: 'origin/master',
INCREMENT: 'true', INCREMENT: 'true',
IS_PITCHING_PILE: true IS_PITCHING_PILE: true,
IS_HTML_CSS: false
} }
} }
] ]
...@@ -66,7 +70,8 @@ plugins: [ ...@@ -66,7 +70,8 @@ plugins: [
instrmenttation: { instrmenttation: {
BRANCH: 'origin/master', BRANCH: 'origin/master',
INCREMENT: 'true', INCREMENT: 'true',
IS_PITCHING_PILE: true IS_PITCHING_PILE: true,
IS_HTML_CSS: false
} }
} }
] ]
...@@ -79,11 +84,13 @@ plugins: [ ...@@ -79,11 +84,13 @@ plugins: [
1. IS_PITCHING_PILE determines if code coverage can be instrumentalized 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 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 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参数 * 新增instrmenttation参数
1. 通过IS_PITCHING_PILE判断是否可以插装收集代码覆盖率 1. 通过IS_PITCHING_PILE判断是否可以插装收集代码覆盖率
2. 通过BRANCH参数确认需要对比的git分支 2. 通过BRANCH参数确认需要对比的git分支
3. 通过INCREMENT判断是否需要查看增量代码 3. 通过INCREMENT判断是否需要查看增量代码
4. 通过IS_HTML_CSS判断vue下是否要看html及css结构
## other description ## other description
......
{ {
"name": "babel-plugin-istanbul-ry", "name": "babel-plugin-istanbul-ry",
"version": "0.0.2", "version": "0.0.3",
"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",
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"istanbul-lib-coverage": "^1.0.0", "istanbul-lib-coverage": "^1.0.0",
"onchange": "^7.1.0", "onchange": "^7.1.0",
"ry-istanbul-web": "^0.0.1", "ry-istanbul-web": "^0.0.4",
"semver": "^6.3.0", "semver": "^6.3.0",
"test-exclude": "^6.0.0" "test-exclude": "^6.0.0"
}, },
...@@ -54,9 +54,7 @@ ...@@ -54,9 +54,7 @@
"standard": "^14.3.1", "standard": "^14.3.1",
"standard-version": "^3.0.0" "standard-version": "^3.0.0"
}, },
"peerDependenciesMeta": { "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",
......
const path = require('path') "use strict";
import { realpathSync } from 'fs'
import { execFileSync, execSync } from 'child_process' Object.defineProperty(exports, "__esModule", {
import { declare } from '@babel/helper-plugin-utils' value: true
import { programVisitor } from './dist' });
// import { programVisitor } from 'istanbul-lib-instrument' exports.default = void 0;
import TestExclude from 'test-exclude'
import schema from '@istanbuljs/schema' var _fs = require("fs");
import parseDiffData from './parse-diff'
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) { function getRealpath(n) {
try { try {
return realpathSync(n) || /* istanbul ignore next */ n return (0, _fs.realpathSync)(n) ||
/* istanbul ignore next */
n;
} catch (e) { } catch (e) {
/* istanbul ignore next */ /* istanbul ignore next */
return n return n;
} }
} }
const memoize = new Map() const memoize = new Map();
/* istanbul ignore next */ /* istanbul ignore next */
const memosep = path.sep === '/' ? ':' : ';'
function loadNycConfig (cwd, opts) { const memosep = path.sep === '/' ? ':' : ';';
let memokey = cwd
const args = [
path.resolve(__dirname, 'load-nyc-config-sync.js'),
cwd
]
if ('nycrcPath' in opts) { function loadNycConfig(cwd, opts) {
args.push(opts.nycrcPath) 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! */ /* execFileSync is expensive, avoid it if possible! */
if (memoize.has(memokey)) { if (memoize.has(memokey)) {
return memoize.get(memokey) return memoize.get(memokey);
} }
const result = JSON.parse(execFileSync(process.execPath, args)) const result = JSON.parse((0, _child_process.execFileSync)(process.execPath, args));
const error = result['load-nyc-config-sync-error'] const error = result['load-nyc-config-sync-error'];
if (error) { if (error) {
throw new Error(error) throw new Error(error);
} }
const config = { const config = { ..._schema.default.defaults.babelPluginIstanbul,
...schema.defaults.babelPluginIstanbul,
cwd, cwd,
...result ...result
} };
memoize.set(memokey, config) memoize.set(memokey, config);
return config return config;
} }
function findConfig (opts) { function findConfig(opts) {
const cwd = getRealpath(opts.cwd || process.env.NYC_CWD || /* istanbul ignore next */ process.cwd()) const cwd = getRealpath(opts.cwd || process.env.NYC_CWD ||
const keys = Object.keys(opts) /* istanbul ignore next */
const ignored = Object.keys(opts).filter(s => s === 'nycrcPath' || s === 'cwd') process.cwd());
const keys = Object.keys(opts);
const ignored = Object.keys(opts).filter(s => s === 'nycrcPath' || s === 'cwd');
if (keys.length > ignored.length) { if (keys.length > ignored.length) {
// explicitly configuring options in babel // explicitly configuring options in babel
// takes precedence. // takes precedence.
return { return { ..._schema.default.defaults.babelPluginIstanbul,
...schema.defaults.babelPluginIstanbul,
cwd, cwd,
...opts ...opts
} };
} }
if (ignored.length === 0 && process.env.NYC_CONFIG) { if (ignored.length === 0 && process.env.NYC_CONFIG) {
// defaults were already applied by nyc // 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 () { function makeShouldSkip() {
let exclude let exclude;
return function shouldSkip(file, nycConfig) {
return function shouldSkip (file, nycConfig) { if (!exclude || exclude.cwd !== nycConfig.cwd) {
if (!exclude || (exclude.cwd !== nycConfig.cwd)) { exclude = new _testExclude.default({
exclude = new TestExclude({
cwd: nycConfig.cwd, cwd: nycConfig.cwd,
include: nycConfig.include, include: nycConfig.include,
exclude: nycConfig.exclude, exclude: nycConfig.exclude,
extension: nycConfig.extension, extension: nycConfig.extension,
// Make sure this is true unless explicitly set to `false`. `undefined` is still `true`. // Make sure this is true unless explicitly set to `false`. `undefined` is still `true`.
excludeNodeModules: nycConfig.excludeNodeModules !== false excludeNodeModules: nycConfig.excludeNodeModules !== false
}) });
} }
return !exclude.shouldInstrument(file) return !exclude.shouldInstrument(file);
} };
} }
function isValue(item, isNumber = false, defaultNumber) { function isValue(item, isNumber = false, defaultNumber) {
let data = '' let data = '';
if (isNumber) { if (isNumber) {
data = item ? Number(item) : defaultNumber data = item ? Number(item) : defaultNumber;
} else { } else {
data = item ? item : defaultNumber data = item ? item : defaultNumber;
} }
return data
return data;
} }
export default declare(api => { var _default = (0, _helperPluginUtils.declare)(api => {
api.assertVersion(7) api.assertVersion(7);
const shouldSkip = makeShouldSkip() const shouldSkip = makeShouldSkip();
const t = api.types const t = api.types;
return { return {
visitor: { visitor: {
Program: { Program: {
enter(path) { enter(path) {
// 筛选后的数据增量文件 // 筛选后的数据增量文件
let diffScreen = null let diffScreen = null;
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 {
let IS_PITCHING_PILE_DATA = false instrmenttation = {}
let INCREMENT_DATA = false } = this.nycConfig; // npm引入参数
let BRANCH_DATA = 'origin/master'
let processData = {} 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 => { 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) { if (item.indexOf('INCREMENT') !== -1) {
processData.INCREMENT = isItem processData.INCREMENT = isItem;
} }
if (item.indexOf('IS_PITCHING_PILE') !== -1) { if (item.indexOf('IS_PITCHING_PILE') !== -1) {
processData.IS_PITCHING_PILE = isItem processData.IS_PITCHING_PILE = isItem;
} }
if (item.indexOf('BRANCH') !== -1) { if (item.indexOf('BRANCH') !== -1) {
processData.BRANCH = process.env[item] processData.BRANCH = process.env[item];
} } // Object.keys(processData).length
// Object.keys(processData).length
}) }); // 全局变量优先
// 全局变量优先
if (Object.keys(instrmenttation).length) { if (Object.keys(instrmenttation).length) {
BRANCH_DATA = isValue(instrmenttation.BRANCH, false, 'origin/master') BRANCH_DATA = isValue(instrmenttation.BRANCH, false, 'origin/master');
INCREMENT_DATA = isValue(instrmenttation.INCREMENT, false, 'false') INCREMENT_DATA = isValue(instrmenttation.INCREMENT, false, 'false');
IS_PITCHING_PILE_DATA = isValue(instrmenttation.IS_PITCHING_PILE, 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) { } else if (Object.keys(processData).length) {
BRANCH_DATA = isValue(processData.BRANCH, false, 'origin/master') BRANCH_DATA = isValue(processData.BRANCH, false, 'origin/master');
INCREMENT_DATA = isValue(processData.INCREMENT, false, 'false') INCREMENT_DATA = isValue(processData.INCREMENT, false, 'false');
IS_PITCHING_PILE_DATA = isValue(processData.IS_PITCHING_PILE, 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 是否开启增量代码检测) 拿配置到底是全量代码还是增量代码 } // 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') {
return false return false;
} }
const changeList = []
// 下面的是零时的 const changeList = []; // 下面的是零时的
// // const gitDiffCode = execSync(`git diff ${branch}`) // // const gitDiffCode = execSync(`git diff ${branch}`)
// const diffData = parseDiffData(gitDiffCode.toString()) // const diffData = parseDiffData(gitDiffCode.toString())
// diffScreen = diffData.find(item => { // diffScreen = diffData.find(item => {
// return realPath.indexOf(item.to) > -1 // return realPath.indexOf(item.to) > -1
// }) // })
// 后面解开 // 后面解开
if ((INCREMENT_DATA || INCREMENT_DATA === 'true') && BRANCH_DATA) { if ((INCREMENT_DATA || INCREMENT_DATA === 'true') && BRANCH_DATA) {
const gitDiffCode = execSync(`git add . && git diff --cached ${BRANCH_DATA}`) const gitDiffCode = (0, _child_process.execSync)(`git add . && git diff --cached ${BRANCH_DATA}`);
const diffData = parseDiffData(gitDiffCode.toString()) const diffData = (0, _parseDiff.default)(gitDiffCode.toString());
const less = '.less';
const css = '.css';
diffScreen = diffData.find(item => { 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)) { if (shouldSkip(realPath, this.nycConfig)) {
return return;
} }
let { inputSourceMap } = this.opts
let {
inputSourceMap
} = this.opts;
if (this.opts.useInlineSourceMaps) { if (this.opts.useInlineSourceMaps) {
if (!inputSourceMap && this.file.inputMap) { 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) { if (name in this.nycConfig) {
visitorOptions[name] = this.nycConfig[name] visitorOptions[name] = this.nycConfig[name];
} else { } 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 !== 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 => {
let changes = Array.isArray(item.changes) ? item.changes : [] let changes = Array.isArray(item.changes) ? item.changes : [];
changes.forEach(items => { changes.forEach(items => {
if (items && items.add) { if (items && items.add) {
changeList.push(items.ln) changeList.push(items.ln);
} }
}) });
}) });
} }
if (changeList.length) { if (changeList.length) {
visitorOptions.changeList = changeList visitorOptions.changeList = changeList;
// changeList visitorOptions.IS_HTML_CSS = IS_HTML_CSS; // changeList
this.__dv__ = programVisitor(t, realPath, {
...visitorOptions, this.__dv__ = (0, _dist.programVisitor)(t, realPath, { ...visitorOptions,
inputSourceMap inputSourceMap
}) });
this.__dv__.enter(path)
} this.__dv__.enter(path);
// } } // }
} else if (!INCREMENT_DATA || INCREMENT_DATA === 'false') { } else if (!INCREMENT_DATA || INCREMENT_DATA === 'false') {
visitorOptions.changeList = changeList visitorOptions.changeList = changeList;
this.__dv__ = programVisitor(t, realPath, { visitorOptions.IS_HTML_CSS = IS_HTML_CSS;
...visitorOptions, this.__dv__ = (0, _dist.programVisitor)(t, realPath, { ...visitorOptions,
inputSourceMap, inputSourceMap
}) });
this.__dv__.enter(path)
this.__dv__.enter(path);
} }
}, },
exit(path) { exit(path) {
if (!this.__dv__) { if (!this.__dv__) {
return return;
} }
const result = this.__dv__.exit(path)
const result = this.__dv__.exit(path);
if (this.opts.onCover) { 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) // api.assertVersion(7)
// console.log(api, 'api') // console.log(api, 'api')
// const shouldSkip = makeShouldSkip() // const shouldSkip = makeShouldSkip()
// const t = api.types // const t = api.types
// return { // return {
// visitor: { // visitor: {
...@@ -276,7 +325,6 @@ export default declare(api => { ...@@ -276,7 +325,6 @@ export default declare(api => {
// } // }
// } // }
// }) // })
// 增量代码babel引入方法 babel.js 或 babel.config.js // 增量代码babel引入方法 babel.js 或 babel.config.js
// 'plugins': [ // 'plugins': [
// ['@hliang/babel-plugin-transfrom-modules-commonjs', { // ['@hliang/babel-plugin-transfrom-modules-commonjs', {
...@@ -287,3 +335,6 @@ export default declare(api => { ...@@ -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