ng.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env node
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.io/license
  8. */
  9. /* eslint-disable no-console */
  10. /* eslint-disable import/no-unassigned-import */
  11. 'use strict';
  12. // Provide a title to the process in `ps`.
  13. // Due to an obscure Mac bug, do not start this title with any symbol.
  14. try {
  15. process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
  16. } catch (_) {
  17. // If an error happened above, use the most basic title.
  18. process.title = 'ng';
  19. }
  20. const rawCommandName = process.argv[2];
  21. if (rawCommandName === '--get-yargs-completions' || rawCommandName === 'completion') {
  22. // Skip Node.js supported checks when running ng completion.
  23. // A warning at this stage could cause a broken source action (`source <(ng completion script)`) when in the shell init script.
  24. require('./bootstrap');
  25. return;
  26. }
  27. // This node version check ensures that extremely old versions of node are not used.
  28. // These may not support ES2015 features such as const/let/async/await/etc.
  29. // These would then crash with a hard to diagnose error message.
  30. var version = process.versions.node.split('.').map((part) => Number(part));
  31. if (version[0] % 2 === 1) {
  32. // Allow new odd numbered releases with a warning (currently v17+)
  33. console.warn(
  34. 'Node.js version ' +
  35. process.version +
  36. ' detected.\n' +
  37. 'Odd numbered Node.js versions will not enter LTS status and should not be used for production.' +
  38. ' For more information, please see https://nodejs.org/en/about/releases/.',
  39. );
  40. require('./bootstrap');
  41. } else if (
  42. version[0] < 14 ||
  43. (version[0] === 14 && version[1] < 20) ||
  44. (version[0] === 16 && version[1] < 14) ||
  45. (version[0] === 18 && version[1] < 10)
  46. ) {
  47. // Error and exit if less than 14.20, 16.14 or 18.10
  48. console.error(
  49. 'Node.js version ' +
  50. process.version +
  51. ' detected.\n' +
  52. 'The Angular CLI requires a minimum Node.js version of either v14.20, v16.14 or v18.10.\n\n' +
  53. 'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
  54. );
  55. process.exitCode = 3;
  56. } else {
  57. require('./bootstrap');
  58. }