UNPKG

@nx/cypress

Version:

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

85 lines (84 loc) 3.53 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/cypress:cypress'; 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 && options.copyFiles === 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 const nxJson = (0, devkit_1.readNxJson)(tree); if (nxJson.targetDefaults) { const targetDefaults = nxJson.targetDefaults; for (const key of Object.keys(targetDefaults)) { const value = targetDefaults[key]; const entries = Array.isArray(value) ? value : [value]; const usesExecutor = (entry) => key === EXECUTOR_TO_MIGRATE || entry.executor === EXECUTOR_TO_MIGRATE || entry.filter?.executor === EXECUTOR_TO_MIGRATE; const kept = entries.filter((entry) => { if (usesExecutor(entry)) { if (entry.options) { updateOptions(entry); } Object.keys(entry.configurations ?? {}).forEach((config) => { updateConfiguration(entry, config); }); } // Drop entries left with nothing but their `filter`/`executor` locator. return Object.keys(entry).some((k) => k !== 'filter' && k !== 'executor'); }); if (kept.length === 0) { delete targetDefaults[key]; } else if (kept.length === 1 && kept[0].filter === undefined) { // A lone unfiltered entry is stored as the plain object form (which // omits `filter`). const { filter: _filter, ...config } = kept[0]; targetDefaults[key] = config; } else { targetDefaults[key] = kept; } } if (Object.keys(targetDefaults).length === 0) { delete nxJson.targetDefaults; } (0, devkit_1.updateNxJson)(tree, nxJson); } await (0, devkit_1.formatFiles)(tree); } function updateOptions(target) { delete target.options.tsConfig; delete target.options.copyFiles; if (!Object.keys(target.options).length) { delete target.options; } } function updateConfiguration(target, configuration) { delete target.configurations[configuration].tsConfig; delete target.configurations[configuration].copyFiles; 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; } }