UNPKG

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