create-nx-workspace 23.2.0-beta.7 → 23.2.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,6 @@ exports.resolveSpecialFolderName = resolveSpecialFolderName;
8
8
  exports.determineFolder = determineFolder;
9
9
  exports.determinePresetOptions = determinePresetOptions;
10
10
  const tslib_1 = require("tslib");
11
- const enquirer_1 = tslib_1.__importDefault(require("enquirer"));
12
11
  const yargs_1 = tslib_1.__importDefault(require("yargs"));
13
12
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
14
13
  const create_workspace_options_1 = require("../src/create-workspace-options");
@@ -23,9 +22,11 @@ const prompts_1 = require("../src/internal-utils/prompts");
23
22
  const yargs_options_1 = require("../src/internal-utils/yargs-options");
24
23
  const ab_testing_1 = require("../src/utils/nx/ab-testing");
25
24
  const error_utils_1 = require("../src/utils/error-utils");
25
+ const exit_codes_1 = require("../src/utils/exit-codes");
26
26
  const fs_1 = require("fs");
27
27
  const path_1 = require("path");
28
28
  const is_ci_1 = require("../src/utils/ci/is-ci");
29
+ const prompt_helpers_1 = require("../src/internal-utils/prompt-helpers");
29
30
  const git_1 = require("../src/utils/git/git");
30
31
  const ai_output_1 = require("../src/utils/ai/ai-output");
31
32
  function extractErrorFile(error) {
@@ -209,8 +210,10 @@ else {
209
210
  exports.commandsObject.epilogue(`${chalk_1.default.cyan('Documentation:')}
210
211
  https://nx.dev/getting-started/intro`);
211
212
  }
212
- // Node 24 has stricter readline behavior, and enquirer is not checking for closed state
213
- // when invoking operations, thus you get an ERR_USE_AFTER_CLOSE error.
213
+ // Node 24's stricter readline throws ERR_USE_AFTER_CLOSE when a prompt library
214
+ // operates on a closed interface. Added for enquirer, which this package no
215
+ // longer uses; verify against Node 24 before removing.
216
+ // TODO(v24): drop if @clack/prompts proves not to need it.
214
217
  process.on('uncaughtException', (error) => {
215
218
  if (error &&
216
219
  typeof error === 'object' &&
@@ -250,7 +253,7 @@ process.on('SIGINT', async () => {
250
253
  ],
251
254
  });
252
255
  }
253
- process.exit(130); // Standard exit code for SIGINT
256
+ (0, exit_codes_1.exitAsInterrupted)();
254
257
  });
255
258
  let rawArgs;
256
259
  async function main(parsedArgs) {
@@ -321,6 +324,11 @@ async function handleError(error) {
321
324
  aiAgent: (0, ai_output_1.isAiAgent)(),
322
325
  },
323
326
  });
327
+ // Cancelling is not a failure: no "Failed to create workspace" banner, and
328
+ // the process ends as interrupted rather than with a generic error code.
329
+ if (error instanceof error_utils_1.CnwError && error.code === 'CANCELLED') {
330
+ (0, exit_codes_1.exitAsInterrupted)();
331
+ }
324
332
  // Output error in appropriate format
325
333
  if ((0, ai_output_1.isAiAgent)()) {
326
334
  const errorCode = error instanceof error_utils_1.CnwError ? error.code : 'UNKNOWN';
@@ -601,10 +609,6 @@ async function normalizeArgsMiddleware(argv) {
601
609
  if (e instanceof error_utils_1.CnwError) {
602
610
  throw e;
603
611
  }
604
- // Enquirer throws an empty string when user presses Ctrl+C
605
- if (e === '') {
606
- process.exit(130);
607
- }
608
612
  const message = e instanceof Error ? e.message : String(e);
609
613
  throw new error_utils_1.CnwError('UNKNOWN', message);
610
614
  }
@@ -727,24 +731,15 @@ async function determineFolder(parsedArgs) {
727
731
  return promptForFolder(parsedArgs);
728
732
  }
729
733
  async function promptCreateInCurrentDir(dirName) {
730
- const { useCurrentDir } = await enquirer_1.default.prompt([
731
- {
732
- name: 'useCurrentDir',
733
- message: `Create workspace in the current directory (${dirName})? Existing files may be overwritten.`,
734
- type: 'autocomplete',
735
- choices: [{ name: 'Yes' }, { name: 'No' }],
736
- initial: 0,
737
- },
738
- ]);
739
- return useCurrentDir === 'Yes';
734
+ return (0, prompt_helpers_1.confirmationPrompt)({
735
+ message: `Create workspace in the current directory (${dirName})? Existing files may be overwritten.`,
736
+ });
740
737
  }
741
738
  async function promptForFolder(parsedArgs) {
742
- const reply = await enquirer_1.default.prompt([
743
- {
744
- name: 'folderName',
739
+ const reply = {
740
+ folderName: await (0, prompt_helpers_1.textPrompt)({
745
741
  message: `Where would you like to create your workspace?`,
746
- initial: 'org',
747
- type: 'input',
742
+ initialValue: 'org',
748
743
  skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
749
744
  validate: (value) => {
750
745
  if (!value) {
@@ -756,10 +751,10 @@ async function promptForFolder(parsedArgs) {
756
751
  if ((0, fs_1.existsSync)(value)) {
757
752
  return `The directory '${value}' already exists`;
758
753
  }
759
- return true;
754
+ return undefined;
760
755
  },
761
- },
762
- ]);
756
+ }),
757
+ };
763
758
  // Fallback invariants in case validate is bypassed (e.g., in CI or non-interactive mode)
764
759
  invariant(reply.folderName, 'INVALID_FOLDER_NAME', 'Folder name cannot be empty');
765
760
  validateWorkspaceName(reply.folderName);
@@ -803,37 +798,28 @@ async function determineStack(parsedArgs) {
803
798
  return 'unknown';
804
799
  }
805
800
  }
806
- const { stack } = await enquirer_1.default.prompt([
807
- {
808
- name: 'stack',
809
- message: `Which stack do you want to use?`,
810
- type: 'autocomplete',
811
- choices: [
812
- {
813
- name: `none`,
814
- message: process.env.NX_ADD_PLUGINS !== 'false' && parsedArgs.workspaces
815
- ? `None: Configures a TypeScript/JavaScript monorepo.`
816
- : `None: Configures a TypeScript/JavaScript project with minimal structure.`,
817
- },
818
- {
819
- name: `react`,
820
- message: `React: Configures a React application with your framework of choice.`,
821
- },
822
- {
823
- name: `vue`,
824
- message: `Vue: Configures a Vue application with your framework of choice.`,
825
- },
826
- {
827
- name: `angular`,
828
- message: `Angular: Configures a Angular application with modern tooling.`,
829
- },
830
- {
831
- name: `node`,
832
- message: `Node: Configures a Node API application with your framework of choice.`,
833
- },
834
- ],
835
- },
836
- ]);
801
+ const stack = await (0, prompt_helpers_1.selectPrompt)({
802
+ message: `Which stack do you want to use?`,
803
+ choices: [
804
+ { value: `none` },
805
+ {
806
+ value: `react`,
807
+ label: `React: Configures a React application with your framework of choice.`,
808
+ },
809
+ {
810
+ value: `vue`,
811
+ label: `Vue: Configures a Vue application with your framework of choice.`,
812
+ },
813
+ {
814
+ value: `angular`,
815
+ label: `Angular: Configures a Angular application with modern tooling.`,
816
+ },
817
+ {
818
+ value: `node`,
819
+ label: `Node: Configures a Node API application with your framework of choice.`,
820
+ },
821
+ ],
822
+ });
837
823
  return stack;
838
824
  }
839
825
  async function determinePresetOptions(parsedArgs) {
@@ -865,24 +851,15 @@ async function determineWebOptions(parsedArgs) {
865
851
  async function determineFormatterOptions(args, opts) {
866
852
  if (args.formatter)
867
853
  return args.formatter;
868
- const reply = await enquirer_1.default.prompt([
869
- {
870
- name: 'prettier',
871
- message: `Would you like to use Prettier for code formatting?`,
872
- type: 'autocomplete',
873
- choices: [
874
- {
875
- name: 'Yes',
876
- },
877
- {
878
- name: 'No',
879
- },
880
- ],
881
- initial: opts?.preferPrettier ? 0 : 1,
882
- skip: !args.interactive || (0, is_ci_1.isCI)(),
883
- },
884
- ]);
885
- return reply.prettier === 'Yes' ? 'prettier' : 'none';
854
+ // A skipped run answers yes regardless of `preferPrettier`, which only moves
855
+ // the highlighted option when the prompt is shown.
856
+ const usePrettier = await (0, prompt_helpers_1.confirmationPrompt)({
857
+ message: `Would you like to use Prettier for code formatting?`,
858
+ initial: opts?.preferPrettier ?? false,
859
+ skip: !args.interactive || (0, is_ci_1.isCI)(),
860
+ skippedValue: true,
861
+ });
862
+ return usePrettier ? 'prettier' : 'none';
886
863
  }
887
864
  async function determineNoneOptions(parsedArgs) {
888
865
  if ((!parsedArgs.preset || parsedArgs.preset === preset_1.Preset.TS) &&
@@ -922,24 +899,11 @@ async function determineNoneOptions(parsedArgs) {
922
899
  else if (preset === preset_1.Preset.TsStandalone) {
923
900
  // Only standalone TS preset generates a default package, so we need to provide --js and --appName options.
924
901
  appName = parsedArgs.name;
925
- const reply = await enquirer_1.default.prompt([
926
- {
927
- name: 'ts',
928
- message: `Would you like to use TypeScript with this project?`,
929
- type: 'autocomplete',
930
- choices: [
931
- {
932
- name: 'Yes',
933
- },
934
- {
935
- name: 'No',
936
- },
937
- ],
938
- initial: 0,
939
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
940
- },
941
- ]);
942
- js = reply.ts === 'No';
902
+ js = !(await (0, prompt_helpers_1.confirmationPrompt)({
903
+ message: `Would you like to use TypeScript with this project?`,
904
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
905
+ skippedValue: true,
906
+ }));
943
907
  }
944
908
  // `ts-standalone` is the only preset on this stack that generates a
945
909
  // lintable project; `apps`, `ts` and `npm` reach no generator that takes a
@@ -1025,41 +989,36 @@ async function determineReactOptions(parsedArgs) {
1025
989
  preset === preset_1.Preset.ReactMonorepo ||
1026
990
  preset === preset_1.Preset.NextJs ||
1027
991
  preset === preset_1.Preset.NextJsStandalone) {
1028
- const reply = await enquirer_1.default.prompt([
1029
- {
1030
- name: 'style',
992
+ const reply = {
993
+ style: await (0, prompt_helpers_1.selectPrompt)({
1031
994
  message: `Default stylesheet format`,
1032
- initial: 0,
1033
- type: 'autocomplete',
1034
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1035
995
  choices: [
996
+ { value: 'css', label: 'CSS' },
1036
997
  {
1037
- name: 'css',
1038
- message: 'CSS',
1039
- },
1040
- {
1041
- name: 'scss',
1042
- message: 'SASS(.scss) [ https://sass-lang.com ]',
998
+ value: 'scss',
999
+ label: 'SASS(.scss) [ https://sass-lang.com ]',
1043
1000
  },
1044
1001
  {
1045
- name: 'less',
1046
- message: 'LESS [ https://lesscss.org ]',
1002
+ value: 'less',
1003
+ label: 'LESS [ https://lesscss.org ]',
1047
1004
  },
1048
1005
  {
1049
- name: 'styled-components',
1050
- message: 'styled-components [ https://styled-components.com ]',
1006
+ value: 'styled-components',
1007
+ label: 'styled-components [ https://styled-components.com ]',
1051
1008
  },
1052
1009
  {
1053
- name: '@emotion/styled',
1054
- message: 'emotion [ https://emotion.sh ]',
1010
+ value: '@emotion/styled',
1011
+ label: 'emotion [ https://emotion.sh ]',
1055
1012
  },
1056
1013
  {
1057
- name: 'styled-jsx',
1058
- message: 'styled-jsx [ https://www.npmjs.com/package/styled-jsx ]',
1014
+ value: 'styled-jsx',
1015
+ label: 'styled-jsx [ https://www.npmjs.com/package/styled-jsx ]',
1059
1016
  },
1060
1017
  ],
1061
- },
1062
- ]);
1018
+ initial: 'css',
1019
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1020
+ }),
1021
+ };
1063
1022
  style = reply.style;
1064
1023
  }
1065
1024
  // Asked outside the gate: the linter is independent of package-manager
@@ -1154,33 +1113,25 @@ async function determineVueOptions(parsedArgs) {
1154
1113
  style = parsedArgs.style;
1155
1114
  }
1156
1115
  else {
1157
- const reply = await enquirer_1.default.prompt([
1158
- {
1159
- name: 'style',
1116
+ const reply = {
1117
+ style: await (0, prompt_helpers_1.selectPrompt)({
1160
1118
  message: `Default stylesheet format`,
1161
- initial: 0,
1162
- type: 'autocomplete',
1163
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1164
1119
  choices: [
1120
+ { value: 'css', label: 'CSS' },
1165
1121
  {
1166
- name: 'css',
1167
- message: 'CSS',
1168
- },
1169
- {
1170
- name: 'scss',
1171
- message: 'SASS(.scss) [ https://sass-lang.com ]',
1172
- },
1173
- {
1174
- name: 'less',
1175
- message: 'LESS [ https://lesscss.org ]',
1122
+ value: 'scss',
1123
+ label: 'SASS(.scss) [ https://sass-lang.com ]',
1176
1124
  },
1177
1125
  {
1178
- name: 'none',
1179
- message: 'None',
1126
+ value: 'less',
1127
+ label: 'LESS [ https://lesscss.org ]',
1180
1128
  },
1129
+ { value: 'none', label: 'None' },
1181
1130
  ],
1182
- },
1183
- ]);
1131
+ initial: 'css',
1132
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1133
+ }),
1134
+ };
1184
1135
  style = reply.style;
1185
1136
  }
1186
1137
  // Asked outside the gate: the linter is independent of package-manager
@@ -1257,76 +1208,60 @@ async function determineAngularOptions(parsedArgs) {
1257
1208
  bundler = parsedArgs.bundler;
1258
1209
  }
1259
1210
  else {
1260
- const reply = await enquirer_1.default.prompt([
1261
- {
1262
- name: 'bundler',
1211
+ const reply = {
1212
+ bundler: await (0, prompt_helpers_1.selectPrompt)({
1263
1213
  message: `Which bundler would you like to use?`,
1264
- type: 'autocomplete',
1265
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1266
1214
  choices: [
1267
- {
1268
- name: 'esbuild',
1269
- message: 'esbuild [ https://esbuild.github.io/ ]',
1270
- },
1271
- {
1272
- name: 'rspack',
1273
- message: 'Rspack [ https://rspack.dev/ ]',
1274
- },
1275
- {
1276
- name: 'webpack',
1277
- message: 'Webpack [ https://webpack.js.org/ ]',
1278
- },
1215
+ { value: 'esbuild', label: 'esbuild [ https://esbuild.github.io/ ]' },
1216
+ { value: 'rspack', label: 'Rspack [ https://rspack.dev/ ]' },
1217
+ { value: 'webpack', label: 'Webpack [ https://webpack.js.org/ ]' },
1279
1218
  ],
1280
- initial: 0,
1281
- },
1282
- ]);
1219
+ initial: 'esbuild',
1220
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1221
+ }),
1222
+ };
1283
1223
  bundler = reply.bundler;
1284
1224
  }
1285
1225
  if (parsedArgs.style) {
1286
1226
  style = parsedArgs.style;
1287
1227
  }
1288
1228
  else {
1289
- const reply = await enquirer_1.default.prompt([
1290
- {
1291
- name: 'style',
1229
+ const reply = {
1230
+ style: await (0, prompt_helpers_1.selectPrompt)({
1292
1231
  message: `Default stylesheet format`,
1293
- initial: 0,
1294
- type: 'autocomplete',
1295
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1296
1232
  choices: [
1233
+ { value: 'css', label: 'CSS' },
1297
1234
  {
1298
- name: 'css',
1299
- message: 'CSS',
1235
+ value: 'scss',
1236
+ label: 'SASS(.scss) [ https://sass-lang.com ]',
1300
1237
  },
1301
1238
  {
1302
- name: 'scss',
1303
- message: 'SASS(.scss) [ https://sass-lang.com ]',
1304
- },
1305
- {
1306
- name: 'less',
1307
- message: 'LESS [ https://lesscss.org ]',
1239
+ value: 'less',
1240
+ label: 'LESS [ https://lesscss.org ]',
1308
1241
  },
1309
1242
  ],
1310
- },
1311
- ]);
1243
+ initial: 'css',
1244
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1245
+ }),
1246
+ };
1312
1247
  style = reply.style;
1313
1248
  }
1314
1249
  if (parsedArgs.ssr !== undefined) {
1315
1250
  ssr = parsedArgs.ssr;
1316
1251
  }
1317
1252
  else {
1318
- const reply = await enquirer_1.default.prompt([
1319
- {
1320
- name: 'ssr',
1253
+ const reply = {
1254
+ ssr: (await (0, prompt_helpers_1.confirmationPrompt)({
1321
1255
  message: `Do you want to enable Server-Side Rendering (SSR)${bundler !== 'rspack'
1322
1256
  ? ' and Static Site Generation (SSG/Prerendering)?'
1323
1257
  : '?'}`,
1324
- type: 'autocomplete',
1325
- choices: [{ name: 'Yes' }, { name: 'No' }],
1326
- initial: 1,
1258
+ initial: false,
1327
1259
  skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1328
- },
1329
- ]);
1260
+ skippedValue: true,
1261
+ }))
1262
+ ? 'Yes'
1263
+ : 'No',
1264
+ };
1330
1265
  ssr = reply.ssr === 'Yes';
1331
1266
  }
1332
1267
  const linter = await (0, prompts_1.determineLinterOptions)(parsedArgs);
@@ -1337,39 +1272,32 @@ async function determineAngularOptions(parsedArgs) {
1337
1272
  unitTestRunner = undefined;
1338
1273
  }
1339
1274
  else {
1340
- unitTestRunner = await enquirer_1.default
1341
- .prompt([
1342
- {
1343
- message: 'Which unit test runner would you like to use?',
1344
- type: 'autocomplete',
1345
- name: 'unitTestRunner',
1346
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1347
- choices: [
1348
- ...(bundler === 'esbuild'
1349
- ? [
1350
- {
1351
- name: 'vitest-angular',
1352
- message: 'Vitest & Angular [ https://vitest.dev/ & https://angular.dev ]',
1353
- },
1354
- ]
1355
- : []),
1356
- {
1357
- name: 'vitest-analog',
1358
- message: 'Vitest & Analog [ https://vitest.dev/ & https://analogjs.org/ ]',
1359
- },
1360
- {
1361
- name: 'jest',
1362
- message: 'Jest [ https://jestjs.io/ ]',
1363
- },
1364
- {
1365
- name: 'none',
1366
- message: 'None',
1367
- },
1368
- ],
1369
- initial: 0,
1370
- },
1371
- ])
1372
- .then((r) => r.unitTestRunner);
1275
+ unitTestRunner = (await (0, prompt_helpers_1.selectPrompt)({
1276
+ message: 'Which unit test runner would you like to use?',
1277
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1278
+ choices: [
1279
+ ...(bundler === 'esbuild'
1280
+ ? [
1281
+ {
1282
+ value: 'vitest-angular',
1283
+ label: 'Vitest & Angular [ https://vitest.dev/ & https://angular.dev ]',
1284
+ },
1285
+ ]
1286
+ : []),
1287
+ {
1288
+ value: 'vitest-analog',
1289
+ label: 'Vitest & Analog [ https://vitest.dev/ & https://analogjs.org/ ]',
1290
+ },
1291
+ {
1292
+ value: 'jest',
1293
+ label: 'Jest [ https://jestjs.io/ ]',
1294
+ },
1295
+ {
1296
+ value: 'none',
1297
+ label: 'None',
1298
+ },
1299
+ ],
1300
+ }));
1373
1301
  }
1374
1302
  e2eTestRunner = await determineE2eTestRunner(parsedArgs);
1375
1303
  return {
@@ -1431,24 +1359,16 @@ async function determineNodeOptions(parsedArgs) {
1431
1359
  docker = parsedArgs.docker;
1432
1360
  }
1433
1361
  else {
1434
- const reply = await enquirer_1.default.prompt([
1435
- {
1436
- name: 'docker',
1362
+ const reply = {
1363
+ docker: (await (0, prompt_helpers_1.confirmationPrompt)({
1437
1364
  message: 'Would you like to generate a Dockerfile? [https://docs.docker.com/]',
1438
- type: 'autocomplete',
1365
+ initial: false,
1439
1366
  skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1440
- choices: [
1441
- {
1442
- name: 'Yes',
1443
- hint: 'I want to generate a Dockerfile',
1444
- },
1445
- {
1446
- name: 'No',
1447
- },
1448
- ],
1449
- initial: 1,
1450
- },
1451
- ]);
1367
+ skippedValue: true,
1368
+ }))
1369
+ ? 'Yes'
1370
+ : 'No',
1371
+ };
1452
1372
  docker = reply.docker === 'Yes';
1453
1373
  }
1454
1374
  // Asked outside the gate: the linter is independent of package-manager
@@ -1477,65 +1397,56 @@ async function determineNodeOptions(parsedArgs) {
1477
1397
  };
1478
1398
  }
1479
1399
  async function determinePackageBasedOrIntegratedOrStandalone() {
1480
- const { workspaceType } = await enquirer_1.default.prompt([
1481
- {
1482
- type: 'autocomplete',
1483
- name: 'workspaceType',
1484
- message: `Package-based monorepo, integrated monorepo, or standalone project?`,
1485
- initial: 0,
1486
- choices: [
1487
- {
1488
- name: 'package-based',
1489
- message: 'Package-based Monorepo: Nx makes it fast, but lets you run things your way.',
1490
- },
1491
- {
1492
- name: 'integrated',
1493
- message: 'Integrated Monorepo: Nx creates a monorepo that contains multiple projects.',
1494
- },
1495
- {
1496
- name: 'standalone',
1497
- message: 'Standalone: Nx creates a single project and makes it fast.',
1498
- },
1499
- ],
1500
- },
1501
- ]);
1400
+ const workspaceType = await (0, prompt_helpers_1.selectPrompt)({
1401
+ message: `Package-based monorepo, integrated monorepo, or standalone project?`,
1402
+ choices: [
1403
+ {
1404
+ value: 'package-based',
1405
+ label: 'Package-based Monorepo: Nx makes it fast, but lets you run things your way.',
1406
+ },
1407
+ {
1408
+ value: 'integrated',
1409
+ label: 'Integrated Monorepo: Nx creates a monorepo that contains multiple projects.',
1410
+ },
1411
+ {
1412
+ value: 'standalone',
1413
+ label: 'Standalone: Nx creates a single project and makes it fast.',
1414
+ },
1415
+ ],
1416
+ initial: 'package-based',
1417
+ });
1502
1418
  invariant(workspaceType, 'INVALID_WORKSPACE_TYPE', `Invalid workspace type. It must be one of the following: standalone, integrated. Got ${workspaceType}`);
1503
1419
  return workspaceType;
1504
1420
  }
1505
1421
  async function determineStandaloneOrMonorepo() {
1506
- const { workspaceType } = await enquirer_1.default.prompt([
1507
- {
1508
- type: 'autocomplete',
1509
- name: 'workspaceType',
1510
- message: `Integrated monorepo, or standalone project?`,
1511
- initial: 1,
1512
- choices: [
1513
- {
1514
- name: 'integrated',
1515
- message: 'Integrated Monorepo: Nx creates a monorepo that contains multiple projects.',
1516
- },
1517
- {
1518
- name: 'standalone',
1519
- message: 'Standalone: Nx creates a single project and makes it fast.',
1520
- },
1521
- ],
1522
- },
1523
- ]);
1422
+ const workspaceType = await (0, prompt_helpers_1.selectPrompt)({
1423
+ message: `Integrated monorepo, or standalone project?`,
1424
+ choices: [
1425
+ {
1426
+ value: 'integrated',
1427
+ label: 'Integrated Monorepo: Nx creates a monorepo that contains multiple projects.',
1428
+ },
1429
+ {
1430
+ value: 'standalone',
1431
+ label: 'Standalone: Nx creates a single project and makes it fast.',
1432
+ },
1433
+ ],
1434
+ initial: 'standalone',
1435
+ });
1524
1436
  invariant(workspaceType, 'INVALID_WORKSPACE_TYPE', `Invalid workspace type. It must be one of the following: standalone, integrated. Got ${workspaceType}`);
1525
1437
  return workspaceType;
1526
1438
  }
1527
1439
  async function determineAppName(parsedArgs) {
1528
1440
  if (parsedArgs.appName)
1529
1441
  return parsedArgs.appName;
1530
- const { appName } = await enquirer_1.default.prompt([
1531
- {
1532
- name: 'appName',
1533
- message: `Application name`,
1534
- type: 'input',
1535
- initial: parsedArgs.name,
1536
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1537
- },
1538
- ]);
1442
+ const appName = await (0, prompt_helpers_1.textPrompt)({
1443
+ message: `Application name`,
1444
+ initialValue: parsedArgs.name,
1445
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1446
+ // Reject here so clearing the field re-prompts. The invariant below still
1447
+ // guards the skipped path, where no validator runs.
1448
+ validate: (value) => value.trim() ? undefined : 'Application name cannot be empty',
1449
+ });
1539
1450
  invariant(appName, 'INVALID_APP_NAME', 'App name cannot be empty');
1540
1451
  return appName;
1541
1452
  }
@@ -1546,166 +1457,105 @@ async function determineReactFramework(parsedArgs) {
1546
1457
  if (!parsedArgs.interactive) {
1547
1458
  return 'none';
1548
1459
  }
1549
- const reply = await enquirer_1.default.prompt([
1550
- {
1551
- name: 'framework',
1460
+ const reply = {
1461
+ framework: await (0, prompt_helpers_1.selectPrompt)({
1552
1462
  message: 'What framework would you like to use?',
1553
- type: 'autocomplete',
1554
1463
  choices: [
1555
1464
  {
1556
- name: 'none',
1557
- message: 'None',
1465
+ value: 'none',
1466
+ label: 'None',
1558
1467
  hint: ' I only want react, react-dom or react-router',
1559
1468
  },
1469
+ { value: 'next', label: 'Next.js [ https://nextjs.org/ ]' },
1470
+ { value: 'expo', label: 'Expo [ https://expo.io/ ]' },
1560
1471
  {
1561
- name: 'next',
1562
- message: 'Next.js [ https://nextjs.org/ ]',
1563
- },
1564
- {
1565
- name: 'expo',
1566
- message: 'Expo [ https://expo.io/ ]',
1567
- },
1568
- {
1569
- name: 'react-native',
1570
- message: 'React Native [ https://reactnative.dev/ ]',
1472
+ value: 'react-native',
1473
+ label: 'React Native [ https://reactnative.dev/ ]',
1571
1474
  },
1572
1475
  ],
1573
- initial: 0,
1574
- },
1575
- ]);
1476
+ initial: 'none',
1477
+ }),
1478
+ };
1576
1479
  return reply.framework;
1577
1480
  }
1578
1481
  async function determineReactBundler(parsedArgs) {
1579
1482
  if (parsedArgs.bundler)
1580
1483
  return parsedArgs.bundler;
1581
- const reply = await enquirer_1.default.prompt([
1582
- {
1583
- name: 'bundler',
1484
+ const reply = {
1485
+ bundler: await (0, prompt_helpers_1.selectPrompt)({
1584
1486
  message: `Which bundler would you like to use?`,
1585
- type: 'autocomplete',
1586
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1587
1487
  choices: [
1588
- {
1589
- name: 'vite',
1590
- message: 'Vite [ https://vite.dev/ ]',
1591
- },
1592
- {
1593
- name: 'webpack',
1594
- message: 'Webpack [ https://webpack.js.org/ ]',
1595
- },
1596
- {
1597
- name: 'rspack',
1598
- message: 'Rspack [ https://www.rspack.dev/ ]',
1599
- },
1488
+ { value: 'vite', label: 'Vite [ https://vite.dev/ ]' },
1489
+ { value: 'webpack', label: 'Webpack [ https://webpack.js.org/ ]' },
1490
+ { value: 'rspack', label: 'Rspack [ https://www.rspack.dev/ ]' },
1600
1491
  ],
1601
- initial: 0,
1602
- },
1603
- ]);
1492
+ initial: 'vite',
1493
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1494
+ }),
1495
+ };
1604
1496
  return reply.bundler;
1605
1497
  }
1606
1498
  async function determineNextAppDir(parsedArgs) {
1607
1499
  if (parsedArgs.nextAppDir !== undefined)
1608
1500
  return parsedArgs.nextAppDir;
1609
- const reply = await enquirer_1.default.prompt([
1610
- {
1611
- name: 'nextAppDir',
1501
+ const reply = {
1502
+ nextAppDir: (await (0, prompt_helpers_1.confirmationPrompt)({
1612
1503
  message: 'Would you like to use the App Router (recommended)?',
1613
- type: 'autocomplete',
1614
1504
  skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1615
- choices: [
1616
- {
1617
- name: 'Yes',
1618
- },
1619
- {
1620
- name: 'No',
1621
- },
1622
- ],
1623
- initial: 0,
1624
- },
1625
- ]);
1505
+ skippedValue: true,
1506
+ }))
1507
+ ? 'Yes'
1508
+ : 'No',
1509
+ };
1626
1510
  return reply.nextAppDir === 'Yes';
1627
1511
  }
1628
1512
  async function determineNextSrcDir(parsedArgs) {
1629
1513
  if (parsedArgs.nextSrcDir !== undefined)
1630
1514
  return parsedArgs.nextSrcDir;
1631
- const reply = await enquirer_1.default.prompt([
1632
- {
1633
- name: 'nextSrcDir',
1515
+ const reply = {
1516
+ nextSrcDir: (await (0, prompt_helpers_1.confirmationPrompt)({
1634
1517
  message: 'Would you like to use the src/ directory?',
1635
- type: 'autocomplete',
1636
1518
  skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1637
- choices: [
1638
- {
1639
- name: 'Yes',
1640
- },
1641
- {
1642
- name: 'No',
1643
- },
1644
- ],
1645
- initial: 0,
1646
- },
1647
- ]);
1519
+ skippedValue: true,
1520
+ }))
1521
+ ? 'Yes'
1522
+ : 'No',
1523
+ };
1648
1524
  return reply.nextSrcDir === 'Yes';
1649
1525
  }
1650
1526
  async function determineVueFramework(parsedArgs) {
1651
1527
  if (!!parsedArgs.framework)
1652
1528
  return parsedArgs.framework;
1653
- const reply = await enquirer_1.default.prompt([
1654
- {
1655
- name: 'framework',
1529
+ const reply = {
1530
+ framework: await (0, prompt_helpers_1.selectPrompt)({
1656
1531
  message: 'What framework would you like to use?',
1657
- type: 'autocomplete',
1658
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1659
1532
  choices: [
1660
- {
1661
- name: 'none',
1662
- message: 'None',
1663
- hint: ' I only want Vue',
1664
- },
1665
- {
1666
- name: 'nuxt',
1667
- message: 'Nuxt [ https://nuxt.com/ ]',
1668
- },
1533
+ { value: 'none', label: 'None', hint: ' I only want Vue' },
1534
+ { value: 'nuxt', label: 'Nuxt [ https://nuxt.com/ ]' },
1669
1535
  ],
1670
- initial: 0,
1671
- },
1672
- ]);
1536
+ initial: 'none',
1537
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1538
+ }),
1539
+ };
1673
1540
  return reply.framework;
1674
1541
  }
1675
1542
  async function determineNodeFramework(parsedArgs) {
1676
1543
  if (!!parsedArgs.framework)
1677
1544
  return parsedArgs.framework;
1678
- const reply = await enquirer_1.default.prompt([
1679
- {
1545
+ const reply = {
1546
+ framework: await (0, prompt_helpers_1.selectPrompt)({
1680
1547
  message: 'What framework should be used?',
1681
- type: 'autocomplete',
1682
- name: 'framework',
1683
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1684
1548
  choices: [
1685
- {
1686
- name: 'none',
1687
- message: 'None',
1688
- },
1689
- {
1690
- name: 'express',
1691
- message: 'Express [ https://expressjs.com/ ]',
1692
- },
1693
- {
1694
- name: 'fastify',
1695
- message: 'Fastify [ https://www.fastify.dev/ ]',
1696
- },
1697
- {
1698
- name: 'koa',
1699
- message: 'Koa [ https://koajs.com/ ]',
1700
- },
1701
- {
1702
- name: 'nest',
1703
- message: 'NestJs [ https://nestjs.com/ ]',
1704
- },
1549
+ { value: 'none', label: 'None' },
1550
+ { value: 'express', label: 'Express [ https://expressjs.com/ ]' },
1551
+ { value: 'fastify', label: 'Fastify [ https://www.fastify.dev/ ]' },
1552
+ { value: 'koa', label: 'Koa [ https://koajs.com/ ]' },
1553
+ { value: 'nest', label: 'NestJs [ https://nestjs.com/ ]' },
1705
1554
  ],
1706
- initial: 0,
1707
- },
1708
- ]);
1555
+ initial: 'none',
1556
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1557
+ }),
1558
+ };
1709
1559
  return reply.framework;
1710
1560
  }
1711
1561
  async function determineUnitTestRunner(parsedArgs, options) {
@@ -1715,69 +1565,55 @@ async function determineUnitTestRunner(parsedArgs, options) {
1715
1565
  else if (!parsedArgs.workspaces) {
1716
1566
  return undefined;
1717
1567
  }
1718
- const reply = await enquirer_1.default.prompt([
1719
- {
1568
+ // `none` sorts last and the preferred runner first, because the leading
1569
+ // choice is both the interactive default and the answer a skipped prompt
1570
+ // resolves to. Callers pass `exclude` to keep a runner they cannot support
1571
+ // off the list entirely.
1572
+ const choices = [
1573
+ { value: 'none', label: 'None' },
1574
+ { value: 'jest', label: 'Jest [ https://jestjs.io/ ]' },
1575
+ { value: 'vitest', label: 'Vitest [ https://vitest.dev/ ]' },
1576
+ ]
1577
+ .filter((t) => !options?.exclude || options.exclude !== t.value)
1578
+ .sort((a, b) => {
1579
+ if (a.value === 'none')
1580
+ return 1;
1581
+ if (b.value === 'none')
1582
+ return -1;
1583
+ if (options?.preferVitest && a.value === 'vitest')
1584
+ return -1;
1585
+ if (options?.preferVitest && b.value === 'vitest')
1586
+ return 1;
1587
+ return 0;
1588
+ });
1589
+ const reply = {
1590
+ unitTestRunner: await (0, prompt_helpers_1.selectPrompt)({
1720
1591
  message: 'Which unit test runner would you like to use?',
1721
- type: 'autocomplete',
1722
- name: 'unitTestRunner',
1592
+ choices: [...choices],
1593
+ initial: choices[0].value,
1723
1594
  skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1724
- choices: [
1725
- {
1726
- name: 'none',
1727
- message: 'None',
1728
- },
1729
- {
1730
- name: 'jest',
1731
- message: 'Jest [ https://jestjs.io/ ]',
1732
- },
1733
- {
1734
- name: 'vitest',
1735
- message: 'Vitest [ https://vitest.dev/ ]',
1736
- },
1737
- ]
1738
- .filter((t) => !options?.exclude || options.exclude !== t.name)
1739
- .sort((a, b) => {
1740
- if (a.name === 'none')
1741
- return 1;
1742
- if (b.name === 'none')
1743
- return -1;
1744
- if (options?.preferVitest && a.name === 'vitest')
1745
- return -1;
1746
- if (options?.preferVitest && b.name === 'vitest')
1747
- return 1;
1748
- return 0;
1749
- }),
1750
- initial: 0, // This should be either vite or jest
1751
- },
1752
- ]);
1595
+ }),
1596
+ };
1753
1597
  return reply.unitTestRunner;
1754
1598
  }
1755
1599
  async function determineE2eTestRunner(parsedArgs) {
1756
1600
  if (parsedArgs.e2eTestRunner)
1757
1601
  return parsedArgs.e2eTestRunner;
1758
- const reply = await enquirer_1.default.prompt([
1759
- {
1602
+ const reply = {
1603
+ e2eTestRunner: await (0, prompt_helpers_1.selectPrompt)({
1760
1604
  message: 'Test runner to use for end to end (E2E) tests',
1761
- type: 'autocomplete',
1762
- name: 'e2eTestRunner',
1763
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1764
1605
  choices: [
1765
1606
  {
1766
- name: 'playwright',
1767
- message: 'Playwright [ https://playwright.dev/ ]',
1768
- },
1769
- {
1770
- name: 'cypress',
1771
- message: 'Cypress [ https://www.cypress.io/ ]',
1772
- },
1773
- {
1774
- name: 'none',
1775
- message: 'None',
1607
+ value: 'playwright',
1608
+ label: 'Playwright [ https://playwright.dev/ ]',
1776
1609
  },
1610
+ { value: 'cypress', label: 'Cypress [ https://www.cypress.io/ ]' },
1611
+ { value: 'none', label: 'None' },
1777
1612
  ],
1778
- initial: 0,
1779
- },
1780
- ]);
1613
+ initial: 'playwright',
1614
+ skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1615
+ }),
1616
+ };
1781
1617
  return reply.e2eTestRunner;
1782
1618
  }
1783
1619
  async function determineReactRouter(parsedArgs) {
@@ -1785,23 +1621,14 @@ async function determineReactRouter(parsedArgs) {
1785
1621
  return false;
1786
1622
  if (parsedArgs.useReactRouter !== undefined)
1787
1623
  return parsedArgs.useReactRouter;
1788
- const reply = await enquirer_1.default.prompt([
1789
- {
1624
+ const reply = {
1625
+ response: (await (0, prompt_helpers_1.confirmationPrompt)({
1790
1626
  message: 'Would you like to use React Router for server-side rendering [https://reactrouter.com/]?',
1791
- type: 'autocomplete',
1792
- name: 'response',
1793
1627
  skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
1794
- choices: [
1795
- {
1796
- name: 'Yes',
1797
- hint: 'I want to use React Router. (Vite will be selected as the bundler)',
1798
- },
1799
- {
1800
- name: 'No',
1801
- },
1802
- ],
1803
- initial: 0,
1804
- },
1805
- ]);
1628
+ skippedValue: true,
1629
+ }))
1630
+ ? 'Yes'
1631
+ : 'No',
1632
+ };
1806
1633
  return reply.response === 'Yes';
1807
1634
  }