feat(core): update CNW defaults so they generate a useful workspace by default (#29915)
This PR fixes some inconsistencies when generating a TS solution workspace (e.g. `npx create-nx-workspace --workspace`). If the user chooses `None` stack (or `--preset=ts`), then we continue to default to no Prettier (and ESLint, etc.). However, for React, Vue, and Node, we want the defaults to be useful for users to run lint, test, etc. Thus, they are now updated the default does not opt out of any tooling, but users can still choose no to any of them. <!-- 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 The defaults for React, Vue, Node are inconsistent (e2e runner is there by default, but not unit test runner, etc.) ## Expected Behavior Defaults are consistent and useful, especially for tutorials. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
ef4398eb60
commit
6a65db8601
@ -461,10 +461,13 @@ async function determinePresetOptions(
|
||||
}
|
||||
}
|
||||
|
||||
async function determineFormatterOptions(args: {
|
||||
formatter?: 'none' | 'prettier';
|
||||
interactive?: boolean;
|
||||
}) {
|
||||
async function determineFormatterOptions(
|
||||
args: {
|
||||
formatter?: 'none' | 'prettier';
|
||||
interactive?: boolean;
|
||||
},
|
||||
opts?: { preferPrettier?: boolean }
|
||||
) {
|
||||
if (args.formatter) return args.formatter;
|
||||
const reply = await enquirer.prompt<{ prettier: 'Yes' | 'No' }>([
|
||||
{
|
||||
@ -479,14 +482,17 @@ async function determineFormatterOptions(args: {
|
||||
name: 'No',
|
||||
},
|
||||
],
|
||||
initial: 1,
|
||||
initial: opts?.preferPrettier ? 0 : 1,
|
||||
skip: !args.interactive || isCI(),
|
||||
},
|
||||
]);
|
||||
return reply.prettier === 'Yes' ? 'prettier' : 'none';
|
||||
}
|
||||
|
||||
async function determineLinterOptions(args: { interactive?: boolean }) {
|
||||
async function determineLinterOptions(
|
||||
args: { interactive?: boolean },
|
||||
opts?: { preferEslint?: boolean }
|
||||
) {
|
||||
const reply = await enquirer.prompt<{ eslint: 'Yes' | 'No' }>([
|
||||
{
|
||||
name: 'eslint',
|
||||
@ -500,7 +506,7 @@ async function determineLinterOptions(args: { interactive?: boolean }) {
|
||||
name: 'No',
|
||||
},
|
||||
],
|
||||
initial: 1,
|
||||
initial: opts?.preferEslint ? 0 : 1,
|
||||
skip: !args.interactive || isCI(),
|
||||
},
|
||||
]);
|
||||
@ -723,8 +729,10 @@ async function determineReactOptions(
|
||||
}
|
||||
|
||||
if (workspaces) {
|
||||
linter = await determineLinterOptions(parsedArgs);
|
||||
formatter = await determineFormatterOptions(parsedArgs);
|
||||
linter = await determineLinterOptions(parsedArgs, { preferEslint: true });
|
||||
formatter = await determineFormatterOptions(parsedArgs, {
|
||||
preferPrettier: true,
|
||||
});
|
||||
} else {
|
||||
linter = 'eslint';
|
||||
formatter = 'prettier';
|
||||
@ -831,8 +839,10 @@ async function determineVueOptions(
|
||||
}
|
||||
|
||||
if (workspaces) {
|
||||
linter = await determineLinterOptions(parsedArgs);
|
||||
formatter = await determineFormatterOptions(parsedArgs);
|
||||
linter = await determineLinterOptions(parsedArgs, { preferEslint: true });
|
||||
formatter = await determineFormatterOptions(parsedArgs, {
|
||||
preferPrettier: true,
|
||||
});
|
||||
} else {
|
||||
linter = 'eslint';
|
||||
formatter = 'prettier';
|
||||
@ -1087,8 +1097,10 @@ async function determineNodeOptions(
|
||||
});
|
||||
|
||||
if (workspaces) {
|
||||
linter = await determineLinterOptions(parsedArgs);
|
||||
formatter = await determineFormatterOptions(parsedArgs);
|
||||
linter = await determineLinterOptions(parsedArgs, { preferEslint: true });
|
||||
formatter = await determineFormatterOptions(parsedArgs, {
|
||||
preferPrettier: true,
|
||||
});
|
||||
} else {
|
||||
linter = 'eslint';
|
||||
formatter = 'prettier';
|
||||
@ -1435,13 +1447,13 @@ async function determineUnitTestRunner<T extends 'none' | 'jest' | 'vitest'>(
|
||||
]
|
||||
.filter((t) => !options?.exclude || options.exclude !== t.name)
|
||||
.sort((a, b) => {
|
||||
if (a.name === 'none') return -1;
|
||||
if (b.name === 'none') return 1;
|
||||
if (a.name === 'none') return 1;
|
||||
if (b.name === 'none') return -1;
|
||||
if (options?.preferVitest && a.name === 'vitest') return -1;
|
||||
if (options?.preferVitest && b.name === 'vitest') return 1;
|
||||
return 0;
|
||||
}),
|
||||
initial: 0,
|
||||
initial: 0, // This should be either vite or jest
|
||||
},
|
||||
]);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user