@nx/detox
Version:
80 lines (79 loc) • 4.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertToInferred = convertToInferred;
const devkit_1 = require("@nx/devkit");
const aggregate_log_util_1 = require("@nx/devkit/src/generators/plugin-migrations/aggregate-log-util");
const executor_to_plugin_migrator_1 = require("@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator");
const plugin_1 = require("../../plugins/plugin");
const process_build_options_1 = require("./lib/process-build-options");
const post_target_transformer_1 = require("./lib/post-target-transformer");
const process_test_options_1 = require("./lib/process-test-options");
async function convertToInferred(tree, options) {
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
const migrationLogs = new aggregate_log_util_1.AggregatedLog();
const migratedProjects = await (0, executor_to_plugin_migrator_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/detox/plugin', plugin_1.createNodesV2, {
buildTargetName: 'build',
startTargetName: 'start',
testTargetName: 'test',
}, [
{
executors: ['@nx/detox:build'],
postTargetTransformer: (0, post_target_transformer_1.postTargetTransformer)(migrationLogs, process_build_options_1.processBuildOptions),
targetPluginOptionMapper: (targetName) => ({
buildTargetName: targetName, // We should use "build" instead of "build-ios" or "build-android". We'll handle this later.
}),
},
{
executors: ['@nx/detox:test'],
postTargetTransformer: (0, post_target_transformer_1.postTargetTransformer)(migrationLogs, process_test_options_1.processTestOptions),
targetPluginOptionMapper: (targetName) => ({
testTargetName: targetName, // We should use "test" instead of "test-ios" or "test-android". We'll handle this later.
}),
},
], options.project);
const nxJson = (0, devkit_1.readNxJson)(tree);
const detoxPlugins = nxJson.plugins?.filter((p) => typeof p !== 'string' && p.plugin === '@nx/detox/plugin');
// These were either `build-ios`, `test-ios`, etc., and we need to set them back to their generic names.
// The per-project targets will call these with additional `--args` passed to maintain the same
// behavior as previous executor-based targets.
for (const p of detoxPlugins) {
if (typeof p === 'string')
continue;
p.options['buildTargetName'] = 'build';
p.options['testTargetName'] = 'test';
}
// Inform the users that the inferred targets are platform-agnostic, and they can remove the old targets if unnecessary.
for (const [project] of migratedProjects) {
migrationLogs.addLog({
project,
executorName: '@nx/detox:build',
log: `The "build-android" target was migrated to use "nx run ${project}:build", which is platform-agnostic. If you no longer need this target, you can remove it.`,
});
migrationLogs.addLog({
project,
executorName: '@nx/detox:test',
log: `The "test-android" target was migrated to use "nx run ${project}:test", which is platform-agnostic. If you no longer need this target, you can remove it.`,
});
migrationLogs.addLog({
project,
executorName: '@nx/detox:build',
log: `The "build-ios" target was migrated to use "nx run ${project}:build", which is platform-agnostic. If you no longer need this target, you can remove it.`,
});
migrationLogs.addLog({
project,
executorName: '@nx/detox:test',
log: `The "test-ios" target was migrated to use "nx run ${project}:test", which is platform-agnostic. If you no longer need this target, you can remove it.`,
});
}
(0, devkit_1.updateNxJson)(tree, nxJson);
if (migratedProjects.size === 0) {
throw new executor_to_plugin_migrator_1.NoTargetsToMigrateError();
}
if (!options.skipFormat) {
await (0, devkit_1.formatFiles)(tree);
}
return () => {
migrationLogs.flushLogs();
};
}
exports.default = convertToInferred;