@tunnckocore/utils
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -6,2 +6,13 @@ # Change Log | ||
## [1.2.1](https://github.com/tunnckoCore/opensource/compare/@tunnckocore/utils@1.2.0...@tunnckocore/utils@1.2.1) (2020-01-15) | ||
### Bug Fixes | ||
* deps, cov, utils update, close [#106](https://github.com/tunnckoCore/opensource/issues/106) ([4b9a968](https://github.com/tunnckoCore/opensource/commit/4b9a968932440768f04adec377313f465af8f447)) | ||
# [1.2.0](https://github.com/tunnckoCore/opensource/compare/@tunnckocore/utils@1.1.5...@tunnckocore/utils@1.2.0) (2019-11-21) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@tunnckocore/utils", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Utility functions and helpers for internal usage and monorepos", | ||
@@ -76,3 +76,3 @@ "repository": { | ||
}, | ||
"gitHead": "d831ea14f18cccd59015e7aad64388e13ffb88de" | ||
"gitHead": "a239c086fa234f7bfbd3e0ff4ed7cfc38d393e1d" | ||
} |
@@ -126,4 +126,9 @@ const fs = require('fs'); | ||
/* istanbul ignore next */ | ||
const yarnWorkspaces = Array.isArray(packageJson.workspaces) | ||
? packageJson.workspaces | ||
: packageJson.workspaces && packageJson.workspaces.packages; | ||
const workspaces = [] | ||
.concat(lernaJson.packages || packageJson.workspaces || []) | ||
.concat(lernaJson.packages || yarnWorkspaces || []) | ||
.filter((x) => typeof x === 'string') | ||
@@ -172,2 +177,4 @@ .filter(Boolean) | ||
// const monoRoot = path.basename(path.dirname(packageJsonPath)); | ||
if (!isMono) { | ||
@@ -182,6 +189,6 @@ throw new Error('This should only be used in monorepo environments.'); | ||
const LOCV_REPORT = fromRoot(lcovReportPath); | ||
const LCOV_REPORT = fromRoot(lcovReportPath); | ||
if (!fs.existsSync(LOCV_REPORT)) { | ||
const file = path.relative(cwd, LOCV_REPORT); | ||
if (!fs.existsSync(LCOV_REPORT)) { | ||
const file = path.relative(cwd, LCOV_REPORT); | ||
throw new Error( | ||
@@ -192,6 +199,7 @@ `Run tests with coverage. Missing coverage report ./${file}!`, | ||
const lcovInfo = fs.readFileSync(LOCV_REPORT, 'utf8'); | ||
const lcovInfo = fs.readFileSync(LCOV_REPORT, 'utf8'); | ||
const $ = cheerio.load(lcovInfo); | ||
const files = {}; | ||
const monoRoot = path.basename(path.dirname(packageJsonPath)); | ||
@@ -216,42 +224,57 @@ $('tr').each(function sasa(i, item) { | ||
const jestCov = Object.keys(files).reduce((acc, file) => { | ||
let value = files[file]; | ||
const [ws, folderName] = file.split('/'); | ||
const pkgRoot = `${ws}/${folderName}`; | ||
const jestCov = Object.keys(files) | ||
.filter((x) => x !== monoRoot) | ||
.reduce((acc, file) => { | ||
let value = files[file]; | ||
const res = Object.keys(files) | ||
.filter((key) => key.startsWith(pkgRoot)) | ||
.map((filename) => files[filename]); | ||
const [monoDir, ws, folderName] = file.split('/'); | ||
if (res.length > 1) { | ||
value = res.reduce( | ||
(accumulator, item) => { | ||
accumulator.statements += item.statements / res.length; | ||
accumulator.branches += item.branches / res.length; | ||
accumulator.functions += item.functions / res.length; | ||
accumulator.lines += item.lines / res.length; | ||
const pkgRoot = path.join(monoDir, ws, folderName); | ||
return accumulator; | ||
}, | ||
{ statements: 0, branches: 0, functions: 0, lines: 0 }, | ||
const res = Object.keys(files) | ||
.filter((key) => key.startsWith(pkgRoot)) | ||
.map((filename) => files[filename]); | ||
if (res.length > 1) { | ||
value = res.reduce( | ||
(accumulator, item) => { | ||
accumulator.statements += item.statements / res.length; | ||
accumulator.branches += item.branches / res.length; | ||
accumulator.functions += item.functions / res.length; | ||
accumulator.lines += item.lines / res.length; | ||
return accumulator; | ||
}, | ||
{ statements: 0, branches: 0, functions: 0, lines: 0 }, | ||
); | ||
} | ||
const cov = Object.keys(value).reduce( | ||
(accum, typeName) => accum + value[typeName], | ||
0, | ||
); | ||
} | ||
const cov = Object.keys(value).reduce( | ||
(accum, typeName) => accum + value[typeName], | ||
0, | ||
); | ||
const coverage = Number((cov / 4).toFixed(2)); | ||
const coverage = Number((cov / 4).toFixed(2)); | ||
acc[pkgRoot] = { | ||
value: coverage, | ||
color: coverageColor(coverage), | ||
}; | ||
return acc; | ||
}, {}); | ||
acc[pkgRoot] = { | ||
value: coverage, | ||
color: coverageColor(coverage), | ||
}; | ||
return acc; | ||
}, {}); | ||
return { | ||
packageJsonPath, | ||
pkg: { ...pkg, cov: jestCov }, | ||
pkg: { | ||
...pkg, | ||
cov: Object.keys(jestCov).reduce((acc, k) => { | ||
const newKey = k | ||
.split('/') | ||
.slice(1) | ||
.join('/'); | ||
acc[newKey] = jestCov[k]; | ||
return acc; | ||
}, {}), | ||
}, | ||
message: `Done. Now you have \`cov\` field in the root package.json!\nYou can use it to further generate per package badges.`, | ||
@@ -258,0 +281,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33353
273