ng.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.dev/license
  8. */
  9. /* eslint-disable no-console */
  10. /* eslint-disable import/no-unassigned-import */
  11. 'use strict';
  12. const path = require('path');
  13. // Error if the external CLI appears to be used inside a google3 context.
  14. if (process.cwd().split(path.sep).includes('google3')) {
  15. console.error(
  16. 'This is the external Angular CLI, but you appear to be running in google3. There is a separate, internal version of the CLI which should be used instead. See http://go/angular/cli.',
  17. );
  18. process.exit();
  19. }
  20. // Provide a title to the process in `ps`.
  21. // Due to an obscure Mac bug, do not start this title with any symbol.
  22. try {
  23. process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
  24. } catch (_) {
  25. // If an error happened above, use the most basic title.
  26. process.title = 'ng';
  27. }
  28. const rawCommandName = process.argv[2];
  29. if (rawCommandName === '--get-yargs-completions' || rawCommandName === 'completion') {
  30. // Skip Node.js supported checks when running ng completion.
  31. // A warning at this stage could cause a broken source action (`source <(ng completion script)`) when in the shell init script.
  32. require('./bootstrap');
  33. return;
  34. }
  35. // This node version check ensures that extremely old versions of node are not used.
  36. // These may not support ES2015 features such as const/let/async/await/etc.
  37. // These would then crash with a hard to diagnose error message.
  38. var version = process.versions.node.split('.').map((part) => Number(part));
  39. if (version[0] % 2 === 1) {
  40. // Allow new odd numbered releases with a warning (currently v17+)
  41. console.warn(
  42. 'Node.js version ' +
  43. process.version +
  44. ' detected.\n' +
  45. 'Odd numbered Node.js versions will not enter LTS status and should not be used for production.' +
  46. ' For more information, please see https://nodejs.org/en/about/previous-releases/.',
  47. );
  48. require('./bootstrap');
  49. } else if (version[0] < 18 || (version[0] === 18 && version[1] < 19)) {
  50. // Error and exit if less than 18.19
  51. console.error(
  52. 'Node.js version ' +
  53. process.version +
  54. ' detected.\n' +
  55. 'The Angular CLI requires a minimum Node.js version of v18.19.\n\n' +
  56. 'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
  57. );
  58. process.exitCode = 3;
  59. } else {
  60. require('./bootstrap');
  61. }