1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const devkit_1 = require("@nrwl/devkit");
|
5 | const executor_options_utils_1 = require("@nrwl/workspace/src/utilities/executor-options-utils");
|
6 | function default_1(tree) {
|
7 | var _a, _b, _c, _d;
|
8 | var _e;
|
9 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
10 | const nxJson = (0, devkit_1.readNxJson)(tree);
|
11 | const jestTargets = getJestTargetNames(tree);
|
12 | const hasProductionFileset = !!((_a = nxJson.namedInputs) === null || _a === void 0 ? void 0 : _a.production);
|
13 | if (jestTargets.size > 0 && hasProductionFileset) {
|
14 | const productionFileset = new Set(nxJson.namedInputs.production);
|
15 | for (const exclusion of [
|
16 | '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',
|
17 | '!{projectRoot}/tsconfig.spec.json',
|
18 | '!{projectRoot}/jest.config.[jt]s',
|
19 | ]) {
|
20 | productionFileset.add(exclusion);
|
21 | }
|
22 | nxJson.namedInputs.production = Array.from(productionFileset);
|
23 | }
|
24 | for (const targetName of jestTargets) {
|
25 | (_b = nxJson.targetDefaults) !== null && _b !== void 0 ? _b : (nxJson.targetDefaults = {});
|
26 | const jestTargetDefaults = ((_c = (_e = nxJson.targetDefaults)[targetName]) !== null && _c !== void 0 ? _c : (_e[targetName] = {}));
|
27 | (_d = jestTargetDefaults.inputs) !== null && _d !== void 0 ? _d : (jestTargetDefaults.inputs = [
|
28 | 'default',
|
29 | hasProductionFileset ? '^production' : '^default',
|
30 | ...(tree.exists('jest.preset.js')
|
31 | ? ['{workspaceRoot}/jest.preset.js']
|
32 | : []),
|
33 | ]);
|
34 | }
|
35 | (0, devkit_1.updateNxJson)(tree, nxJson);
|
36 | yield (0, devkit_1.formatFiles)(tree);
|
37 | });
|
38 | }
|
39 | exports.default = default_1;
|
40 | function getJestTargetNames(tree) {
|
41 | const jestTargetNames = new Set();
|
42 | (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/jest:jest', (_, __, target) => {
|
43 | jestTargetNames.add(target);
|
44 | });
|
45 | return jestTargetNames;
|
46 | }
|
47 |
|
\ | No newline at end of file |