create-nx-workspace 16.6.0-beta.3 → 16.6.0-beta.4

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.
@@ -6,12 +6,9 @@ interface BaseArguments extends CreateWorkspaceOptions {
6
6
  }
7
7
  interface NoneArguments extends BaseArguments {
8
8
  stack: 'none';
9
- workspaceType: 'package-based' | 'integrated';
10
- }
11
- interface TsArguments extends BaseArguments {
12
- stack: 'ts';
13
- workspaceType: 'standalone' | 'integrated';
9
+ workspaceType: 'package-based' | 'integrated' | 'standalone';
14
10
  js: boolean;
11
+ appName: string | undefined;
15
12
  }
16
13
  interface ReactArguments extends BaseArguments {
17
14
  stack: 'react';
@@ -40,6 +37,6 @@ interface NodeArguments extends BaseArguments {
40
37
  interface UnknownStackArguments extends BaseArguments {
41
38
  stack: 'unknown';
42
39
  }
43
- type Arguments = NoneArguments | TsArguments | ReactArguments | AngularArguments | NodeArguments | UnknownStackArguments;
40
+ type Arguments = NoneArguments | ReactArguments | AngularArguments | NodeArguments | UnknownStackArguments;
44
41
  export declare const commandsObject: yargs.Argv<Arguments>;
45
42
  export {};
@@ -229,10 +229,9 @@ function determineStack(parsedArgs) {
229
229
  case preset_1.Preset.Empty:
230
230
  case preset_1.Preset.Apps:
231
231
  case preset_1.Preset.NPM:
232
- return 'none';
233
232
  case preset_1.Preset.TS:
234
233
  case preset_1.Preset.TsStandalone:
235
- return 'ts';
234
+ return 'none';
236
235
  case preset_1.Preset.WebComponents:
237
236
  case preset_1.Preset.ReactNative:
238
237
  case preset_1.Preset.Expo:
@@ -248,23 +247,19 @@ function determineStack(parsedArgs) {
248
247
  choices: [
249
248
  {
250
249
  name: `none`,
251
- message: `None: Configures a minimal structure without specific frameworks or technologies.`,
252
- },
253
- {
254
- name: `ts`,
255
- message: `TS/JS: Configures a TypeScript/JavaScript package without specific frameworks or platforms.`,
250
+ message: `None: Configures a TypeScript/JavaScript project with minimal structure.`,
256
251
  },
257
252
  {
258
253
  name: `react`,
259
- message: `React: Configures a React app with your framework of choice.`,
254
+ message: `React: Configures a React application with your framework of choice.`,
260
255
  },
261
256
  {
262
257
  name: `angular`,
263
- message: `Angular: Configures a Angular app with modern tooling.`,
258
+ message: `Angular: Configures a Angular application with modern tooling.`,
264
259
  },
265
260
  {
266
261
  name: `node`,
267
- message: `Node: Configures a Node API with your framework of choice.`,
262
+ message: `Node: Configures a Node API application with your framework of choice.`,
268
263
  },
269
264
  ],
270
265
  },
@@ -277,8 +272,6 @@ function determinePresetOptions(parsedArgs) {
277
272
  switch (parsedArgs.stack) {
278
273
  case 'none':
279
274
  return determineNoneOptions(parsedArgs);
280
- case 'ts':
281
- return determineTsOptions(parsedArgs);
282
275
  case 'react':
283
276
  return determineReactOptions(parsedArgs);
284
277
  case 'angular':
@@ -291,51 +284,25 @@ function determinePresetOptions(parsedArgs) {
291
284
  });
292
285
  }
293
286
  function determineNoneOptions(parsedArgs) {
294
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
295
- if (parsedArgs.preset)
296
- return parsedArgs;
297
- const { workspaceType } = yield enquirer.prompt([
298
- {
299
- type: 'autocomplete',
300
- name: 'workspaceType',
301
- message: `Package-based or integrated?`,
302
- initial: 'package-based',
303
- choices: [
304
- {
305
- name: 'package-based',
306
- message: 'Package-based: Nx makes it fast, but lets you run things your way.',
307
- },
308
- {
309
- name: 'integrated',
310
- message: 'Integrated: Nx creates a workspace structure most suitable for building apps.',
311
- },
312
- ],
313
- },
314
- ]);
315
- if (workspaceType === 'integrated') {
316
- return {
317
- preset: preset_1.Preset.Apps,
318
- };
319
- }
320
- else {
321
- return {
322
- preset: preset_1.Preset.NPM,
323
- };
324
- }
325
- });
326
- }
327
- function determineTsOptions(parsedArgs) {
328
287
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
329
288
  let preset;
330
289
  let workspaceType = undefined;
331
290
  let appName = undefined;
332
- let js = false;
291
+ let js;
333
292
  if (parsedArgs.preset) {
334
293
  preset = parsedArgs.preset;
335
294
  }
336
295
  else {
337
- workspaceType = yield determineStandAloneOrMonorepo();
338
- preset = workspaceType === 'standalone' ? preset_1.Preset.TsStandalone : preset_1.Preset.TS;
296
+ workspaceType = yield determinePackageBasedOrIntegratedOrStandalone();
297
+ if (workspaceType === 'standalone') {
298
+ preset = preset_1.Preset.TsStandalone;
299
+ }
300
+ else if (workspaceType === 'integrated') {
301
+ preset = preset_1.Preset.Apps;
302
+ }
303
+ else {
304
+ preset = preset_1.Preset.NPM;
305
+ }
339
306
  }
340
307
  if (parsedArgs.js !== undefined) {
341
308
  js = parsedArgs.js;
@@ -388,7 +355,7 @@ function determineReactOptions(parsedArgs) {
388
355
  // TODO(jack): Add standalone support for React Native and Expo.
389
356
  const workspaceType = framework === 'react-native' || framework === 'expo'
390
357
  ? 'integrated'
391
- : yield determineStandAloneOrMonorepo();
358
+ : yield determineStandaloneOrMonorepo();
392
359
  if (workspaceType === 'standalone') {
393
360
  appName = parsedArgs.name;
394
361
  }
@@ -487,7 +454,7 @@ function determineAngularOptions(parsedArgs) {
487
454
  }
488
455
  }
489
456
  else {
490
- const workspaceType = yield determineStandAloneOrMonorepo();
457
+ const workspaceType = yield determineStandaloneOrMonorepo();
491
458
  if (workspaceType === 'standalone') {
492
459
  preset = preset_1.Preset.AngularStandalone;
493
460
  appName = parsedArgs.name;
@@ -597,7 +564,7 @@ function determineNodeOptions(parsedArgs) {
597
564
  }
598
565
  else {
599
566
  framework = yield determineNodeFramework(parsedArgs);
600
- const workspaceType = yield determineStandAloneOrMonorepo();
567
+ const workspaceType = yield determineStandaloneOrMonorepo();
601
568
  if (workspaceType === 'standalone') {
602
569
  preset = preset_1.Preset.NodeStandalone;
603
570
  appName = parsedArgs.name;
@@ -638,23 +605,56 @@ function determineNodeOptions(parsedArgs) {
638
605
  };
639
606
  });
640
607
  }
641
- function determineStandAloneOrMonorepo() {
608
+ function determinePackageBasedOrIntegratedOrStandalone() {
642
609
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
643
610
  const { workspaceType } = yield enquirer.prompt([
644
611
  {
645
612
  type: 'autocomplete',
646
613
  name: 'workspaceType',
647
- message: `Standalone project or integrated monorepo?`,
648
- initial: 'standalone',
614
+ message: `Package-based monorepo, integrated monorepo, or standalone project?`,
615
+ initial: 'package-based',
649
616
  choices: [
617
+ {
618
+ name: 'package-based',
619
+ message: 'Package-based Monorepo: Nx makes it fast, but lets you run things your way.',
620
+ },
621
+ {
622
+ name: 'integrated',
623
+ message: 'Integrated Monorepo: Nx creates a monorepo that contains multiple projects.',
624
+ },
650
625
  {
651
626
  name: 'standalone',
652
- message: 'Standalone: Nx creates a single project and makes it fast.',
627
+ message: 'Standalone: Nx creates a single project and makes it fast.',
653
628
  },
629
+ ],
630
+ },
631
+ ]);
632
+ invariant(workspaceType, {
633
+ title: 'Invalid workspace type',
634
+ bodyLines: [
635
+ `It must be one of the following: standalone, integrated. Got ${workspaceType}`,
636
+ ],
637
+ });
638
+ return workspaceType;
639
+ });
640
+ }
641
+ function determineStandaloneOrMonorepo() {
642
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
643
+ const { workspaceType } = yield enquirer.prompt([
644
+ {
645
+ type: 'autocomplete',
646
+ name: 'workspaceType',
647
+ message: `Integrated monorepo, or standalone project?`,
648
+ initial: 'standalone',
649
+ choices: [
654
650
  {
655
651
  name: 'integrated',
656
652
  message: 'Integrated Monorepo: Nx creates a monorepo that contains multiple projects.',
657
653
  },
654
+ {
655
+ name: 'standalone',
656
+ message: 'Standalone: Nx creates a single project and makes it fast.',
657
+ },
658
658
  ],
659
659
  },
660
660
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nx-workspace",
3
- "version": "16.6.0-beta.3",
3
+ "version": "16.6.0-beta.4",
4
4
  "private": false,
5
5
  "description": "Smart, Fast and Extensible Build System",
6
6
  "repository": {
@@ -43,5 +43,5 @@
43
43
  },
44
44
  "main": "./index.js",
45
45
  "types": "./index.d.ts",
46
- "gitHead": "cd8c61d7a3b8ab9bc7bab068f5ca49bbf14abbf5"
46
+ "gitHead": "b1a9ae7ce76697019b26ec9a172005840cca8da6"
47
47
  }
@@ -37,7 +37,7 @@ function createEmptyWorkspace(tmpDir, name, packageManager, options) {
37
37
  if (process.platform === 'win32' &&
38
38
  /\s/.test(nxWorkspaceRoot) &&
39
39
  packageManager === 'npm') {
40
- const pmVersion = +(0, package_manager_1.getPackageManagerVersion)(packageManager).split('.')[0];
40
+ const pmVersion = +(0, package_manager_1.getPackageManagerVersion)(packageManager, tmpDir).split('.')[0];
41
41
  if (pmVersion < 7) {
42
42
  nxWorkspaceRoot = `\\"${nxWorkspaceRoot.slice(1, -1)}\\"`;
43
43
  }
@@ -18,7 +18,7 @@ function createPreset(preset, parsedArgs, packageManager, directory) {
18
18
  if (process.platform === 'win32' &&
19
19
  /\s/.test(nxWorkspaceRoot) &&
20
20
  packageManager === 'npm') {
21
- const pmVersion = +(0, package_manager_1.getPackageManagerVersion)(packageManager).split('.')[0];
21
+ const pmVersion = +(0, package_manager_1.getPackageManagerVersion)(packageManager, workingDir).split('.')[0];
22
22
  if (pmVersion < 7) {
23
23
  nxWorkspaceRoot = `\\"${nxWorkspaceRoot.slice(1, -1)}\\"`;
24
24
  }
@@ -56,7 +56,7 @@ function recordStat(opts) {
56
56
  if (process.env.NX_VERBOSE_LOGGING === 'true') {
57
57
  console.log(`Record stat. Major: ${major}`);
58
58
  }
59
- if (major < 10 || major > 15)
59
+ if (major < 10 || major > 16)
60
60
  return; // test version, skip it
61
61
  const axios = require('axios');
62
62
  yield ((_a = axios['default']) !== null && _a !== void 0 ? _a : axios)
@@ -19,7 +19,7 @@ export declare function getPackageManagerCommand(packageManager?: PackageManager
19
19
  preInstall?: string;
20
20
  };
21
21
  export declare function generatePackageManagerFiles(root: string, packageManager?: PackageManager): void;
22
- export declare function getPackageManagerVersion(packageManager: PackageManager): string;
22
+ export declare function getPackageManagerVersion(packageManager: PackageManager, cwd?: string): string;
23
23
  /**
24
24
  * Detects which package manager was used to invoke create-nx-{plugin|workspace} command
25
25
  * based on the main Module process that invokes the command
@@ -42,7 +42,8 @@ function getPackageManagerCommand(packageManager = detectPackageManager()) {
42
42
  install: useBerry
43
43
  ? installCommand
44
44
  : `${installCommand} --ignore-scripts`,
45
- exec: 'yarn',
45
+ // using npx is necessary to avoid yarn classic manipulating the version detection when using berry
46
+ exec: useBerry ? 'npx' : 'yarn',
46
47
  };
47
48
  case 'pnpm':
48
49
  let useExec = false;
@@ -67,13 +68,24 @@ function generatePackageManagerFiles(root, packageManager = detectPackageManager
67
68
  case 'yarn':
68
69
  if (+pmMajor >= 2) {
69
70
  (0, fs_1.writeFileSync)((0, path_1.join)(root, '.yarnrc.yml'), 'nodeLinker: node-modules\nenableScripts: false');
71
+ // avoids errors when using nested yarn projects
72
+ (0, fs_1.writeFileSync)((0, path_1.join)(root, 'yarn.lock'), '');
70
73
  }
71
74
  break;
72
75
  }
73
76
  }
74
77
  exports.generatePackageManagerFiles = generatePackageManagerFiles;
75
- function getPackageManagerVersion(packageManager) {
76
- return (0, child_process_1.execSync)(`${packageManager} --version`).toString('utf-8').trim();
78
+ const pmVersionCache = new Map();
79
+ function getPackageManagerVersion(packageManager, cwd = process.cwd()) {
80
+ if (pmVersionCache.has(packageManager)) {
81
+ return pmVersionCache.get(packageManager);
82
+ }
83
+ const version = (0, child_process_1.execSync)(`${packageManager} --version`, {
84
+ cwd,
85
+ encoding: 'utf-8',
86
+ }).trim();
87
+ pmVersionCache.set(packageManager, version);
88
+ return version;
77
89
  }
78
90
  exports.getPackageManagerVersion = getPackageManagerVersion;
79
91
  /**