Skip to content

Commit

Permalink
chore: move cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stoffeastrom committed Mar 20, 2019
1 parent a3abcab commit fa2f0fc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 44 deletions.
2 changes: 1 addition & 1 deletion commands/protractor/src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
description: 'Glob pattern',
type: 'array',
default: [],
alias: ['glob'],
alias: 'glob',
},
coverage: {
description: 'Generate coverage',
Expand Down
4 changes: 2 additions & 2 deletions packages/transform-middleware/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const testExclude = require('test-exclude');
const { transformFile } = require('@after-work.js/transform');
const {
coerceBabel,
DEFAULT_SRC_EXCLUDE_PATTERN,
DEFAULT_TRANSFORM_EXCLUDE_PATTERN,
getInstrumentExcludePattern,
} = require('@after-work.js/utils');

module.exports = function transformFiles(userArgv) {
Expand All @@ -26,7 +26,7 @@ module.exports = function transformFiles(userArgv) {
babel,
nyc: {
include: [],
exclude: DEFAULT_SRC_EXCLUDE_PATTERN,
exclude: getInstrumentExcludePattern(userArgv),
tempDirectory: './coverage/.nyc_output',
reporter: ['lcov', 'text-summary'],
reportDir: 'coverage',
Expand Down
10 changes: 3 additions & 7 deletions packages/transform-middleware/src/options.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const {
packages,
DEFAULT_TEST_EXT_PATTERN,
TEST_GLOB,
SRC_GLOB,
DEFAULT_SRC_EXT_PATTERN,
DEFAULT_SRC_EXCLUDE_PATTERN,
WATCH_GLOB,
} = require('@after-work.js/utils');

module.exports = {
Expand Down Expand Up @@ -35,7 +32,7 @@ module.exports = {
},
test: {
description: 'Glob pattern',
default: TEST_GLOB,
default: [],
type: 'array',
alias: 'glob',
},
Expand All @@ -46,7 +43,7 @@ module.exports = {
},
src: {
description: 'Glob pattern for all source files',
default: SRC_GLOB,
default: [],
type: 'array',
hidden: true,
},
Expand All @@ -64,10 +61,9 @@ module.exports = {
},
watchGlob: {
description: 'Watch glob',
default: WATCH_GLOB,
default: [],
type: 'array',
alias: 'wg',
coerce: opt => [...opt, ...WATCH_GLOB],
},
coverage: {
description: 'Generate coverage?',
Expand Down
57 changes: 23 additions & 34 deletions packages/utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ const DEFAULT_SRC_EXCLUDE_PATTERN = [
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 getTestGlob = ({ testExt }) => [
...(packagesPath.length
? packagesPath.map(p => `${p}/**/${testExt}`)
Expand All @@ -51,36 +45,13 @@ const getTestGlob = ({ testExt }) => [
'!./node_modules/**',
];

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 SRC_GLOB = [
...(packagesPath.length
? packagesPath.map(p => `${p}/${DEFAULT_SRC_GLOB_PATTERN}`)
: [DEFAULT_SRC_GLOB_PATTERN]),
'!**/node_modules/**',
'!./node_modules/**',
];
const getSrcGlob = ({ srcExt }) => [
...(packagesPath.length
? packagesPath.map(p => `${p}/**/${srcExt}`)
: [`**/${srcExt}`]),
'!**/node_modules/**',
'!./node_modules/**',
];
const WATCH_GLOB = [...TEST_GLOB, ...SRC_GLOB];

const DEFAULT_TRANSFORM_EXCLUDE_PATTERN = [
'**/node_modules/**',
Expand Down Expand Up @@ -111,13 +82,17 @@ const DEFAULT_CONFIGS = `{${[
'rollup',
'webpack',
].join()}}.config.js`;
const getInstrumentExcludePattern = ({ testExt }) => [

const getInstrumentExcludePattern = ({
testExt = DEFAULT_TEST_EXT_PATTERN,
}) => [
...DEFAULT_TRANSFORM_EXCLUDE_PATTERN,
`**/${DEFAULT_CONFIGS}`,
DEFAULT_CONFIGS,
`**/${testExt}`,
testExt,
];

const addDefaults = (argv) => {
if (!argv.glob.length) {
argv.glob = getTestGlob(argv);
Expand All @@ -133,19 +108,33 @@ const addDefaults = (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 = {
addDefaults,
getPackages,
getInstrumentExcludePattern,
packagesPath,
workspaces,
lernaPackages,
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_TRANSFORM_EXCLUDE_PATTERN,
DEFAULT_INSTRUMENT_EXCLUDE_PATTERN,
isSourceMap(f) {
Expand Down

0 comments on commit fa2f0fc

Please sign in to comment.