1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const executor_options_utils_1 = require("@nrwl/workspace/src/utilities/executor-options-utils");
|
5 | const devkit_1 = require("@nrwl/devkit");
|
6 | const path_1 = require("path");
|
7 | function 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 |
|
31 |
|
32 | devkit_1.logger.warn((0, devkit_1.stripIndents) `Unable to update ${tsconfigSpecPath}. `);
|
33 | }
|
34 | }
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | function makeAllPatternsFromSpecPatterns(specGlobs = ['**/*.spec.ts']) {
|
41 | return makeUniquePatterns(specGlobs.reduce((patterns, current) => {
|
42 | patterns.push(current);
|
43 |
|
44 | if (current.includes('spec.')) {
|
45 | patterns.push(current.replace('spec.', 'test.'));
|
46 | }
|
47 | return patterns;
|
48 | }, []));
|
49 | }
|
50 | function makeUniquePatterns(items = []) {
|
51 | return [...new Set(items)];
|
52 | }
|
53 | function 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 | }
|
59 | exports.default = update;
|
60 |
|
\ | No newline at end of file |