Colum Ferry f8ffc05e8d
fix(bundling): convert to inferred should handle config file (#26619)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-06-21 11:32:04 -04:00

70 lines
1.7 KiB
TypeScript

import {
createProjectGraphAsync,
formatFiles,
names,
type TargetConfiguration,
type Tree,
} from '@nx/devkit';
import { createNodesV2, PlaywrightPluginOptions } from '../../plugins/plugin';
import { migrateExecutorToPlugin } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
interface Schema {
project?: string;
all?: boolean;
skipFormat?: boolean;
}
export async function convertToInferred(tree: Tree, options: Schema) {
const projectGraph = await createProjectGraphAsync();
const migratedProjects =
await migrateExecutorToPlugin<PlaywrightPluginOptions>(
tree,
projectGraph,
'@nx/playwright:playwright',
'@nx/playwright/plugin',
(targetName) => ({ targetName, ciTargetName: 'e2e-ci' }),
postTargetTransformer,
createNodesV2,
options.project
);
if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
}
if (!options.skipFormat) {
await formatFiles(tree);
}
}
function postTargetTransformer(
target: TargetConfiguration
): TargetConfiguration {
if (target.options) {
if (target.options?.config) {
delete target.options.config;
}
handleRenameOfProperties(target.options);
}
if (target.configurations) {
for (const configurationName in target.configurations) {
const configuration = target.configurations[configurationName];
handleRenameOfProperties(configuration);
}
}
return target;
}
function handleRenameOfProperties(options: Record<string, unknown>) {
for (const [key, value] of Object.entries(options)) {
const newKeyName = names(key).fileName;
delete options[key];
options[newKeyName] = value;
}
}
export default convertToInferred;