@after-work.js/utils
Advanced tools
Comparing version 6.0.1 to 6.0.2
{ | ||
"name": "@after-work.js/utils", | ||
"version": "6.0.1", | ||
"version": "6.0.2", | ||
"publishConfig": { | ||
@@ -32,3 +32,3 @@ "access": "public" | ||
}, | ||
"gitHead": "f976e152f93189e419e221c0b8dfbd70d490c2f5" | ||
"gitHead": "fa6f774cb046917812bc8c81cc0ea255203b5b11" | ||
} |
113
src/index.js
@@ -21,11 +21,4 @@ /* eslint max-len: 0, import/no-dynamic-require: 0, global-require: 0 */ | ||
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_EXT_PATTERN = '*.{spec,test}.{js,jsx,ts,tsx}'; | ||
const DEFAULT_TEST_GLOB_PATTERN = `**/${DEFAULT_TEST_EXT_PATTERN}`; | ||
@@ -44,19 +37,29 @@ | ||
'**/dist/**', | ||
`**/${DEFAULT_TEST_EXT_PATTERN}`, | ||
DEFAULT_TEST_EXT_PATTERN, | ||
'**/*.config.*', | ||
]; | ||
const TEST_GLOB = [ | ||
const DEFAULT_NEGATED_SRC_EXCLUDE_PATTERN = DEFAULT_SRC_EXCLUDE_PATTERN.reduce( | ||
(acc, curr) => [...acc, `!**/${curr}/**`, `!./${curr}/**`], | ||
[], | ||
); | ||
const getTestGlob = ({ testExt }) => [ | ||
...(packagesPath.length | ||
? packagesPath.map(p => `${p}/${DEFAULT_TEST_GLOB_PATTERN}`) | ||
: [DEFAULT_TEST_GLOB_PATTERN]), | ||
? packagesPath.map(p => `${p}/**/${testExt}`) | ||
: [`**/${testExt}`]), | ||
'!**/node_modules/**', | ||
'!./node_modules/**', | ||
]; | ||
const SRC_GLOB = [ | ||
const TEST_GLOB = getTestGlob({ testExt: DEFAULT_TEST_EXT_PATTERN }); | ||
const getSrcGlob = ({ srcExt }) => [ | ||
...(packagesPath.length | ||
? packagesPath.map(p => `${p}/${DEFAULT_SRC_GLOB_PATTERN}`) | ||
: [DEFAULT_SRC_GLOB_PATTERN]), | ||
? packagesPath.map(p => `${p}/src/**/${srcExt}`) | ||
: [`src/**/${srcExt}`]), | ||
'!**/node_modules/**', | ||
'!./node_modules/**', | ||
]; | ||
const SRC_GLOB = getSrcGlob({ srcExt: DEFAULT_SRC_EXT_PATTERN }); | ||
const WATCH_GLOB = [...TEST_GLOB, ...SRC_GLOB]; | ||
@@ -67,2 +70,5 @@ | ||
'./node_modules/**', | ||
'**/scripts/**', | ||
'**/dist/**', | ||
'**/docs/**', | ||
'**/coverage/**', | ||
@@ -76,17 +82,82 @@ '**/external/**', | ||
]; | ||
const DEFAULT_INSTRUMENT_EXCLUDE_PATTERN = DEFAULT_TRANSFORM_EXCLUDE_PATTERN; | ||
const DEFAULT_INSTRUMENT_EXCLUDE_PATTERN = [ | ||
...DEFAULT_TRANSFORM_EXCLUDE_PATTERN, | ||
'**/test/**', | ||
'**/__tests__/**', | ||
'**/mocks/**', | ||
'**/__mocks__/**', | ||
DEFAULT_TEST_EXT_PATTERN, | ||
DEFAULT_TEST_GLOB_PATTERN, | ||
]; | ||
const DEFAULT_CONFIGS = `{${[ | ||
'aw', | ||
'ava', | ||
'babel', | ||
'jest', | ||
'nyc', | ||
'rollup', | ||
'webpack', | ||
].join()}}.config.js`; | ||
const getInstrumentExcludePattern = ({ | ||
testExt = DEFAULT_TEST_EXT_PATTERN, | ||
}) => [ | ||
...DEFAULT_TRANSFORM_EXCLUDE_PATTERN, | ||
'**/test/**', | ||
'**/__tests__/**', | ||
'**/mocks/**', | ||
'**/__mocks__/**', | ||
`**/${DEFAULT_CONFIGS}`, | ||
DEFAULT_CONFIGS, | ||
`**/${testExt}`, | ||
testExt, | ||
]; | ||
const addDefaults = (argv) => { | ||
// Re-evaluate if it's the default values e.g `testExt` or `srcExt` could be changed | ||
if (argv.glob === TEST_GLOB) { | ||
argv.glob = getTestGlob(argv); | ||
} | ||
if (argv.src === SRC_GLOB) { | ||
argv.src = getSrcGlob(argv); | ||
} | ||
if (argv.watchGlob === WATCH_GLOB) { | ||
argv.watchGlob = [...argv.glob, ...argv.src]; | ||
} | ||
if (argv.nyc.exclude === DEFAULT_INSTRUMENT_EXCLUDE_PATTERN) { | ||
argv.nyc.exclude = getInstrumentExcludePattern(argv); | ||
} | ||
}; | ||
const getPackages = ({ testExt }) => { | ||
const packagesMap = new Map(); | ||
let packages = []; | ||
packagesPath.forEach((root) => { | ||
const { name } = importCwd(`./${root}/package.json`); | ||
const tests = globby.sync(`${root}/**/${testExt}`); | ||
if (tests.length) { | ||
packages = [...packages, name]; | ||
} | ||
packagesMap.set(name, root); | ||
}); | ||
return { packagesMap, packages }; | ||
}; | ||
const utils = { | ||
packages, | ||
addDefaults, | ||
getPackages, | ||
getInstrumentExcludePattern, | ||
packagesPath, | ||
packagesMap, | ||
workspaces, | ||
lernaPackages, | ||
TEST_GLOB, | ||
SRC_GLOB, | ||
WATCH_GLOB, | ||
DEFAULT_TEST_EXT_PATTERN, | ||
DEFAULT_TEST_GLOB_PATTERN, | ||
DEFAULT_SRC_EXT_PATTERN, | ||
DEFAULT_SRC_GLOB_PATTERN, | ||
DEFAULT_SRC_EXCLUDE_PATTERN, | ||
TEST_GLOB, | ||
SRC_GLOB, | ||
WATCH_GLOB, | ||
DEFAULT_NEGATED_SRC_EXCLUDE_PATTERN, | ||
DEFAULT_TRANSFORM_EXCLUDE_PATTERN, | ||
@@ -93,0 +164,0 @@ DEFAULT_INSTRUMENT_EXCLUDE_PATTERN, |
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
11090
333