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 | const functions_1 = require("../../utils/config/functions");
|
7 | const versions_1 = require("../../utils/versions");
|
8 | function checkIfProjectNeedsUpdate(tree) {
|
9 | if (tree.exists('babel.config.json')) {
|
10 |
|
11 | return false;
|
12 | }
|
13 | let shouldUpdate = false;
|
14 | (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/jest:jest', (jestOptions, projectName) => {
|
15 | const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
16 | const jestConfigPath = (0, devkit_1.joinPathFragments)(projectConfig.root, 'jest.config.js');
|
17 | if (!tree.exists(jestConfigPath)) {
|
18 | return;
|
19 | }
|
20 | const config = (0, functions_1.jestConfigObject)(tree, jestConfigPath);
|
21 | if (config.transform) {
|
22 | for (const transformer of Object.values(config.transform)) {
|
23 | if ((typeof transformer === 'string' && transformer === 'babel-jest') ||
|
24 | (Array.isArray(transformer) && transformer[0] === 'babel-jest')) {
|
25 | shouldUpdate = true;
|
26 | }
|
27 | }
|
28 | }
|
29 | });
|
30 | return shouldUpdate;
|
31 | }
|
32 | function update(tree) {
|
33 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
34 | const shouldUpdateConfigs = checkIfProjectNeedsUpdate(tree);
|
35 | if (shouldUpdateConfigs) {
|
36 | (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nrwl/web': versions_1.nxVersion });
|
37 | tree.write('babel.config.json', '{"babelrcRoots": ["*"]}');
|
38 | yield (0, devkit_1.formatFiles)(tree);
|
39 | }
|
40 | });
|
41 | }
|
42 | exports.default = update;
|
43 |
|
\ | No newline at end of file |