Isaac Mann 839dc1585b
feat(devkit): prefer strings over Linter enum (#27209)
We should be consistent about how options are defined in our plugins.
Currently, there are some options that use `enum`s and some that use
typed strings. I think typed strings are preferable because someone
extending a generator only needs to import the main generator that
they're extending, not all the transitive dependencies of that
generator.

Current extending code:
```
// ...
import { applicationGenerator as reactApplicationGenerator } from '@nx/react';
import { Linter } from '@nx/eslint';

export async function applicationGenerator(
  tree: Tree,
  options: ApplicationGeneratorSchema
) {
  reactApplicationGenerator(tree, {
    ...options,
    linter: Linter.EsLint,
  });
}
```

Desired extending code:
```
// ...
import { applicationGenerator as reactApplicationGenerator } from '@nx/react';

export async function applicationGenerator(
  tree: Tree,
  options: ApplicationGeneratorSchema
) {
  reactApplicationGenerator(tree, {
    ...options,
    linter: 'eslint',
  });
}
```

The problem is not just an extra line of code, the person extending the
`reactApplicationGenerator` has to dig into the implementation details
of the generator itself in order to know where to find the `Linter`
enum. The `e2eTestRunner` is already a typed string and is easily
extended.

The solution I'm proposing in this PR would define a typed string in the
same file as the existing enum. None of the implementations need to
change. No community plugin code will be broken.
2024-08-19 17:07:28 -04:00

36 lines
1.0 KiB
TypeScript

import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
import type { Linter, LinterType } from '@nx/eslint';
import type { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners';
import type { Styles } from '../utils/types';
export interface Schema {
name: string;
addTailwind?: boolean;
skipFormat?: boolean;
inlineStyle?: boolean;
inlineTemplate?: boolean;
viewEncapsulation?: 'Emulated' | 'Native' | 'None';
routing?: boolean;
prefix?: string;
style?: Styles;
skipTests?: boolean;
directory?: string;
projectNameAndRootFormat?: ProjectNameAndRootFormat;
tags?: string;
linter?: Linter | LinterType;
unitTestRunner?: UnitTestRunner;
e2eTestRunner?: E2eTestRunner;
backendProject?: string;
strict?: boolean;
standaloneConfig?: boolean;
port?: number;
setParserOptionsProject?: boolean;
skipPackageJson?: boolean;
standalone?: boolean;
rootProject?: boolean;
minimal?: boolean;
bundler?: 'webpack' | 'esbuild';
ssr?: boolean;
nxCloudToken?: string;
}