@after-work.js/utils
Advanced tools
Comparing version 5.1.1 to 6.0.0-dev.20181219.0
{ | ||
"name": "@after-work.js/utils", | ||
"version": "5.1.1", | ||
"version": "6.0.0-dev.20181219.0", | ||
"publishConfig": { | ||
@@ -25,3 +25,10 @@ "access": "public" | ||
], | ||
"gitHead": "437b47d84de1baec6ce8e7810c9b8d519c41a70a" | ||
"dependencies": { | ||
"debug": "4.0.1", | ||
"globby": "8.0.1", | ||
"import-cwd": "2.1.0", | ||
"minimatch": "3.0.4", | ||
"npmlog": "4.1.2" | ||
}, | ||
"gitHead": "ae9f1ec01c01df3a23b2c65c5a070c2cde1ffb76" | ||
} |
143
src/index.js
@@ -6,6 +6,84 @@ /* eslint max-len: 0, import/no-dynamic-require: 0, global-require: 0 */ | ||
const importCwd = require('import-cwd'); | ||
const debug = require('debug'); | ||
const globby = require('globby'); | ||
const minimatch = require('minimatch'); | ||
const isCI = !!process.env.CI; | ||
const pkg = importCwd('./package.json'); | ||
const findPkgs = g => globby.sync(`${g}/package.json`); | ||
const reducePkgs = (acc, curr) => acc.concat(curr.map(c => c.slice(0, -13))); | ||
const lerna = importCwd.silent('./lerna.json'); | ||
const workspaces = (pkg.workspaces || []).map(findPkgs).reduce(reducePkgs, []); | ||
const lernaPackages = ((lerna && lerna.packages) || []) | ||
.map(findPkgs) | ||
.reduce(reducePkgs, []); | ||
const packagesPath = [...workspaces, ...lernaPackages]; | ||
let packages = []; | ||
const packagesMap = new Map(); | ||
packagesPath.forEach((root) => { | ||
const { name } = importCwd(`./${root}/package.json`); | ||
packages = [...packages, name]; | ||
packagesMap.set(name, root); | ||
}); | ||
const DEFAULT_TEST_EXT_PATTERN = '*.{spec,test}.{js,ts}'; | ||
const DEFAULT_TEST_GLOB_PATTERN = `**/${DEFAULT_TEST_EXT_PATTERN}`; | ||
const DEFAULT_SRC_EXT_PATTERN = '*.{js,ts}'; | ||
const DEFAULT_SRC_GLOB_PATTERN = `**/${DEFAULT_SRC_EXT_PATTERN}`; | ||
const DEFAULT_SRC_EXCLUDE_PATTERN = [ | ||
'**/coverage/**', | ||
'**/scripts/**', | ||
'**/docs/**', | ||
'**/tools/**', | ||
'**/__*__/**', | ||
'**/test/**', | ||
'**/mocks/**', | ||
'**/dist/**', | ||
`**/${DEFAULT_TEST_EXT_PATTERN}`, | ||
'**/*.config.*', | ||
]; | ||
const TEST_GLOB = [ | ||
...(packagesPath.length | ||
? packagesPath.map(p => `${p}/${DEFAULT_TEST_GLOB_PATTERN}`) | ||
: [DEFAULT_TEST_GLOB_PATTERN]), | ||
'!**/node_modules/**', | ||
'!./node_modules/**', | ||
]; | ||
const SRC_GLOB = [ | ||
...(packagesPath.length | ||
? packagesPath.map(p => `${p}/${DEFAULT_SRC_GLOB_PATTERN}`) | ||
: [DEFAULT_SRC_GLOB_PATTERN]), | ||
'!**/node_modules/**', | ||
'!./node_modules/**', | ||
]; | ||
const WATCH_GLOB = [...TEST_GLOB, ...SRC_GLOB]; | ||
const DEFAULT_TRANSFORM_EXCLUDE_PATTERN = [ | ||
'**/node_modules/**', | ||
'./node_modules/**', | ||
'**/coverage/**', | ||
'**/external/**', | ||
'**/autogenerated/**', | ||
'**/*.{html,css,json,txt,ttf,woff,svg,ico}', | ||
'**/*require*.js', | ||
'**/*sinon*.js', | ||
'**/*chai*.js', | ||
]; | ||
const DEFAULT_INSTRUMENT_EXCLUDE_PATTERN = DEFAULT_TRANSFORM_EXCLUDE_PATTERN; | ||
const utils = { | ||
packages, | ||
packagesPath, | ||
packagesMap, | ||
workspaces, | ||
lernaPackages, | ||
DEFAULT_TEST_EXT_PATTERN, | ||
DEFAULT_TEST_GLOB_PATTERN, | ||
DEFAULT_SRC_GLOB_PATTERN, | ||
DEFAULT_SRC_EXCLUDE_PATTERN, | ||
TEST_GLOB, | ||
SRC_GLOB, | ||
WATCH_GLOB, | ||
DEFAULT_TRANSFORM_EXCLUDE_PATTERN, | ||
DEFAULT_INSTRUMENT_EXCLUDE_PATTERN, | ||
isSourceMap(f) { | ||
@@ -27,24 +105,21 @@ return !fs.existsSync(f) && f.endsWith('.map'); | ||
ensureFilePath(js) { | ||
if (!fs.existsSync(js) && js.endsWith('.js')) { | ||
const exists = fs.existsSync(js); | ||
if (!exists && js.endsWith('.js')) { | ||
const ts = utils.getPathWithExt(js, 'ts'); | ||
if (!fs.existsSync(ts)) { | ||
throw new Error(`Can't find file ${js}`); | ||
return ''; | ||
} | ||
return ts; | ||
} | ||
return js; | ||
return exists ? js : ''; | ||
}, | ||
clearLine() { | ||
if (isCI) { | ||
return; | ||
} | ||
readline.clearLine(process.stdout, 0); | ||
readline.cursorTo(process.stdout, 0, null); | ||
readline.clearLine(process.stderr, 0); | ||
readline.cursorTo(process.stderr, 0, null); | ||
}, | ||
writeLine(msg) { | ||
if (isCI) { | ||
return; | ||
} | ||
writeLine(prefix, msg) { | ||
this.clearLine(); | ||
process.stdout.write(`${msg}`); | ||
process.stderr.write( | ||
`${prefix} ${msg.length > 60 ? '...' : ''}${msg.slice(-59)}`, | ||
); | ||
}, | ||
@@ -76,6 +151,8 @@ safeGetModule(name) { | ||
if (typeof opt.babelPluginIstanbul === 'string') { | ||
opt.babelPluginIstanbul = importCwd(opt.babelPluginIstanbul).default; | ||
opt.babelPluginIstanbul = utils.safeGetModule( | ||
opt.babelPluginIstanbul, | ||
).default; | ||
} | ||
if (typeof opt.typescript === 'string') { | ||
opt.typescript = importCwd.silent(opt.typescript); | ||
opt.typescript = utils.safeGetModule(opt.typescript); | ||
} | ||
@@ -96,3 +173,3 @@ return opt; | ||
const filename = path.resolve(parts.join(':')); | ||
return [filename, lineno, columnno]; | ||
return [filename, lineno, columnno, c]; | ||
}) | ||
@@ -122,3 +199,5 @@ .filter(([filename]) => testFiles.indexOf(filename) !== -1); | ||
return require.cache[f]; | ||
} catch (_) { } //eslint-disable-line | ||
} catch (_) { | ||
// console.error(_) | ||
} | ||
return { children: [] }; | ||
@@ -129,3 +208,8 @@ }, | ||
if (found.length > 1) { | ||
const matchName = found.filter(id => path.basename(id).split('.').shift() === testName); | ||
const matchName = found.filter( | ||
id => path | ||
.basename(id) | ||
.split('.') | ||
.shift() === testName, | ||
); | ||
if (matchName.length === 1) { | ||
@@ -140,6 +224,8 @@ use = matchName; | ||
getDependencies(files, file) { | ||
const name = path.basename(file).split('.').shift(); | ||
const name = path | ||
.basename(file) | ||
.split('.') | ||
.shift(); | ||
const mod = this.safeRequireCache(file); | ||
const found = mod | ||
.children | ||
const found = mod.children | ||
.filter(m => files.indexOf(m.id) !== -1) | ||
@@ -162,4 +248,17 @@ .map(m => m.id); | ||
}, | ||
createDebug(p) { | ||
return debug(`@after-work.js:${p}`); | ||
}, | ||
filter(arr, initialValue) { | ||
return arr.reduce( | ||
(acc, curr) => acc.filter(file => minimatch(file, curr)), | ||
initialValue, | ||
); | ||
}, | ||
isMatchingExtPattern(filePath, extPattern) { | ||
const base = path.basename(filePath); | ||
return minimatch(base, extPattern); | ||
}, | ||
}; | ||
module.exports = utils; |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
8880
250
0
3
5
1
+ Addeddebug@4.0.1
+ Addedglobby@8.0.1
+ Addedimport-cwd@2.1.0
+ Addedminimatch@3.0.4
+ Addednpmlog@4.1.2
+ Added@mrmlnc/readdir-enhanced@2.2.1(transitive)
+ Added@nodelib/fs.stat@1.1.3(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedaproba@1.2.0(transitive)
+ Addedare-we-there-yet@1.1.7(transitive)
+ Addedarr-diff@4.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedarray-union@1.0.2(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedarray-unique@0.3.2(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase@0.11.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbraces@2.3.2(transitive)
+ Addedcache-base@1.0.1(transitive)
+ Addedcall-me-maybe@1.0.2(transitive)
+ Addedclass-utils@0.3.6(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@2.6.94.0.1(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddefine-property@0.2.51.0.02.0.2(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddir-glob@2.2.2(transitive)
+ Addedexpand-brackets@2.1.4(transitive)
+ Addedextend-shallow@2.0.13.0.2(transitive)
+ Addedextglob@2.0.4(transitive)
+ Addedfast-glob@2.2.7(transitive)
+ Addedfill-range@4.0.0(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfragment-cache@0.2.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgauge@2.7.4(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-parent@3.1.0(transitive)
+ Addedglob-to-regexp@0.3.0(transitive)
+ Addedglobby@8.0.1(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedhas-value@0.3.11.0.0(transitive)
+ Addedhas-values@0.1.41.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedignore@3.3.10(transitive)
+ Addedimport-cwd@2.1.0(transitive)
+ Addedimport-from@2.1.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.71.0.3(transitive)
+ Addedis-extendable@0.1.11.0.1(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedis-glob@3.1.04.0.3(transitive)
+ Addedis-number@3.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.03.0.1(transitive)
+ Addedkind-of@3.2.24.0.06.0.3(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@3.1.10(transitive)
+ Addedminimatch@3.0.43.1.2(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedms@2.0.02.1.3(transitive)
+ Addednanomatch@1.2.13(transitive)
+ Addednpmlog@4.1.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpascalcase@0.1.1(transitive)
+ Addedpath-dirname@1.0.2(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-type@3.0.0(transitive)
+ Addedpify@3.0.0(transitive)
+ Addedposix-character-classes@0.1.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedregex-not@1.0.2(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedresolve-from@3.0.0(transitive)
+ Addedresolve-url@0.2.1(transitive)
+ Addedret@0.1.15(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsafe-regex@1.1.0(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedset-value@2.0.1(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedslash@1.0.0(transitive)
+ Addedsnapdragon@0.8.2(transitive)
+ Addedsnapdragon-node@2.1.1(transitive)
+ Addedsnapdragon-util@3.0.1(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-resolve@0.5.3(transitive)
+ Addedsource-map-url@0.4.1(transitive)
+ Addedsplit-string@3.1.0(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedto-regex@3.0.2(transitive)
+ Addedto-regex-range@2.1.1(transitive)
+ Addedunion-value@1.0.1(transitive)
+ Addedunset-value@1.0.0(transitive)
+ Addedurix@0.1.0(transitive)
+ Addeduse@3.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwrappy@1.0.2(transitive)