UNPKG

2.5 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const executor_options_utils_1 = require("@nrwl/workspace/src/utilities/executor-options-utils");
5const devkit_1 = require("@nrwl/devkit");
6const path_1 = require("path");
7function updateTsConfigsForTests(tree) {
8 (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/jest:jest', (jestOptions, projectName) => {
9 const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
10 (0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.root, (path) => {
11 const fileName = (0, path_1.basename)(path);
12 if (fileName.startsWith('tsconfig') && fileName.endsWith('.json')) {
13 updateTsConfig(tree, path);
14 }
15 });
16 });
17 function updateTsConfig(tree, tsconfigSpecPath) {
18 try {
19 (0, devkit_1.updateJson)(tree, tsconfigSpecPath, (value) => {
20 if (value.include) {
21 value.include = makeAllPatternsFromSpecPatterns(value.include);
22 }
23 if (value.exclude) {
24 value.exclude = makeAllPatternsFromSpecPatterns(value.exclude);
25 }
26 return value;
27 });
28 }
29 catch (error) {
30 // issue trying to parse the tsconfig file bc it's invalid JSON from template markup/comments
31 // ignore and move on
32 devkit_1.logger.warn((0, devkit_1.stripIndents) `Unable to update ${tsconfigSpecPath}. `);
33 }
34 }
35}
36/**
37 * take an array of patterns and create patterns from those containing .spec. with .test.
38 * by default the pattern ** /*.spec.ts will be used if no value is passed in.
39 */
40function makeAllPatternsFromSpecPatterns(specGlobs = ['**/*.spec.ts']) {
41 return makeUniquePatterns(specGlobs.reduce((patterns, current) => {
42 patterns.push(current);
43 // .spec. and _spec. can used as testing file name patterns
44 if (current.includes('spec.')) {
45 patterns.push(current.replace('spec.', 'test.'));
46 }
47 return patterns;
48 }, []));
49}
50function makeUniquePatterns(items = []) {
51 return [...new Set(items)];
52}
53function update(tree) {
54 return tslib_1.__awaiter(this, void 0, void 0, function* () {
55 updateTsConfigsForTests(tree);
56 yield (0, devkit_1.formatFiles)(tree);
57 });
58}
59exports.default = update;
60//# sourceMappingURL=update-tsconfigs-for-tests.js.map
\No newline at end of file