UNPKG

1.96 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const devkit_1 = require("@nrwl/devkit");
5const executor_options_utils_1 = require("@nrwl/workspace/src/utilities/executor-options-utils");
6const functions_1 = require("../../utils/config/functions");
7const versions_1 = require("../../utils/versions");
8function checkIfProjectNeedsUpdate(tree) {
9 if (tree.exists('babel.config.json')) {
10 // the project is already running on babel and good to go
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}
32function 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}
42exports.default = update;
43//# sourceMappingURL=add-missing-root-babel-config.js.map
\No newline at end of file