UNPKG

@nx/jest

Version:

The Nx Plugin for Jest contains executors and generators allowing your workspace to use the powerful Jest testing capabilities.

61 lines (60 loc) 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const internal_1 = require("@nx/devkit/internal"); const devkit_1 = require("@nx/devkit"); const EXECUTOR_TO_MIGRATE = '@nx/jest:jest'; async function default_1(tree) { // update options from project configs (0, internal_1.forEachExecutorOptions)(tree, EXECUTOR_TO_MIGRATE, (options, project, target, configuration) => { if (options.tsConfig === undefined) { return; } const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, project); if (configuration) { updateConfiguration(projectConfiguration.targets[target], configuration); } else { updateOptions(projectConfiguration.targets[target]); } (0, devkit_1.updateProjectConfiguration)(tree, project, projectConfiguration); }); // update options from nx.json target defaults. `updateTargetDefault` walks // both the object and filtered array value forms, drops entries left with // nothing but their executor locator, and collapses lone unfiltered ones // back to the object form. const nxJson = (0, devkit_1.readNxJson)(tree); if (nxJson?.targetDefaults) { (0, internal_1.updateTargetDefault)(nxJson, { executor: EXECUTOR_TO_MIGRATE }, (config) => { if (config.options) updateOptions(config); Object.keys(config.configurations ?? {}).forEach((configuration) => { updateConfiguration(config, configuration); }); // Drop the entry once nothing but its executor locator remains. const keys = Object.keys(config); if (keys.length === 0 || (keys.length === 1 && keys[0] === 'executor')) { return null; } }); (0, devkit_1.updateNxJson)(tree, nxJson); } await (0, devkit_1.formatFiles)(tree); } function updateOptions(target) { delete target.options.tsConfig; if (!Object.keys(target.options).length) { delete target.options; } } function updateConfiguration(target, configuration) { delete target.configurations[configuration].tsConfig; if (!Object.keys(target.configurations[configuration]).length && (!target.defaultConfiguration || target.defaultConfiguration !== configuration)) { delete target.configurations[configuration]; } if (!Object.keys(target.configurations).length) { delete target.configurations; } }