File tree 4 files changed +13
-8
lines changed
4 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 8
8
9
9
import { Arguments } from '../models/interface' ;
10
10
import { SchematicCommand } from '../models/schematic-command' ;
11
+ import { VERSION } from '../models/version' ;
11
12
import { Schema as NewCommandSchema } from './new' ;
12
13
13
14
export class NewCommand extends SchematicCommand < NewCommandSchema > {
@@ -22,9 +23,7 @@ export class NewCommand extends SchematicCommand<NewCommandSchema> {
22
23
23
24
public async run ( options : NewCommandSchema & Arguments ) {
24
25
// Register the version of the CLI in the registry.
25
- const packageJson = require ( '../package.json' ) ;
26
- const version = packageJson . version ;
27
-
26
+ const version = VERSION . full ;
28
27
this . _workflow . registry . addSmartDefaultProvider ( 'ng-cli-version' , ( ) => version ) ;
29
28
30
29
return this . runSchematic ( {
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import { PackageManager } from '../lib/config/workspace-schema';
16
16
import { Command } from '../models/command' ;
17
17
import { Arguments } from '../models/interface' ;
18
18
import { SchematicEngineHost } from '../models/schematic-engine-host' ;
19
+ import { VERSION } from '../models/version' ;
19
20
import { colors } from '../utilities/color' ;
20
21
import { installAllPackages , runTempPackageBin } from '../utilities/install-package' ;
21
22
import { writeErrorToLogFile } from '../utilities/log-file' ;
@@ -860,7 +861,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
860
861
* @returns `true` when the installed version is older.
861
862
*/
862
863
private async checkCLILatestVersion ( verbose = false , next = false ) : Promise < boolean > {
863
- const { version : installedCLIVersion } = require ( '../package.json' ) ;
864
+ const installedCLIVersion = VERSION . full ;
864
865
865
866
const LatestCLIManifest = await fetchPackageManifest (
866
867
`@angular/cli@${ next ? 'next' : 'latest' } ` ,
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import 'symbol-observable';
11
11
import * as fs from 'fs' ;
12
12
import * as path from 'path' ;
13
13
import { SemVer } from 'semver' ;
14
+ import { VERSION } from '../models/version' ;
14
15
import { colors } from '../utilities/color' ;
15
16
import { isWarningEnabled } from '../utilities/config' ;
16
17
@@ -80,14 +81,17 @@ if (process.env['NG_CLI_PROFILING']) {
80
81
const projectLocalCli = require . resolve ( '@angular/cli' , { paths : [ process . cwd ( ) ] } ) ;
81
82
cli = await import ( projectLocalCli ) ;
82
83
83
- const globalVersion = new SemVer ( require ( '../package.json' ) . version ) ;
84
+ const globalVersion = new SemVer ( VERSION . full ) ;
84
85
85
86
// Older versions might not have the VERSION export
86
87
let localVersion = cli . VERSION ?. full ;
87
88
if ( ! localVersion ) {
88
89
try {
89
- localVersion = require ( path . join ( path . dirname ( projectLocalCli ) , '../../package.json' ) )
90
- . version ;
90
+ const localPackageJson = await fs . promises . readFile (
91
+ path . join ( path . dirname ( projectLocalCli ) , '../../package.json' ) ,
92
+ 'utf-8' ,
93
+ ) ;
94
+ localVersion = ( JSON . parse ( localPackageJson ) as { version : string } ) . version ;
91
95
} catch ( error ) {
92
96
// eslint-disable-next-line no-console
93
97
console . error ( 'Version mismatch check skipped. Unable to retrieve local version: ' + error ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { json, tags } from '@angular-devkit/core';
10
10
import debug from 'debug' ;
11
11
import * as inquirer from 'inquirer' ;
12
12
import { v4 as uuidV4 } from 'uuid' ;
13
+ import { VERSION } from '../models/version' ;
13
14
import { colors } from '../utilities/color' ;
14
15
import { getWorkspace , getWorkspaceRaw } from '../utilities/config' ;
15
16
import { isTTY } from '../utilities/tty' ;
@@ -27,7 +28,7 @@ export const AnalyticsProperties = {
27
28
return _defaultAngularCliPropertyCache ;
28
29
}
29
30
30
- const v = require ( '../package.json' ) . version ;
31
+ const v = VERSION . full ;
31
32
32
33
// The logic is if it's a full version then we should use the prod GA property.
33
34
if ( / ^ \d + \. \d + \. \d + $ / . test ( v ) && v !== '0.0.0' ) {
You can’t perform that action at this time.
0 commit comments