File tree Expand file tree Collapse file tree 4 files changed +13
-8
lines changed Expand file tree Collapse file tree 4 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 88
99import { Arguments } from '../models/interface' ;
1010import { SchematicCommand } from '../models/schematic-command' ;
11+ import { VERSION } from '../models/version' ;
1112import { Schema as NewCommandSchema } from './new' ;
1213
1314export class NewCommand extends SchematicCommand < NewCommandSchema > {
@@ -22,9 +23,7 @@ export class NewCommand extends SchematicCommand<NewCommandSchema> {
2223
2324 public async run ( options : NewCommandSchema & Arguments ) {
2425 // 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 ;
2827 this . _workflow . registry . addSmartDefaultProvider ( 'ng-cli-version' , ( ) => version ) ;
2928
3029 return this . runSchematic ( {
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import { PackageManager } from '../lib/config/workspace-schema';
1616import { Command } from '../models/command' ;
1717import { Arguments } from '../models/interface' ;
1818import { SchematicEngineHost } from '../models/schematic-engine-host' ;
19+ import { VERSION } from '../models/version' ;
1920import { colors } from '../utilities/color' ;
2021import { installAllPackages , runTempPackageBin } from '../utilities/install-package' ;
2122import { writeErrorToLogFile } from '../utilities/log-file' ;
@@ -860,7 +861,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
860861 * @returns `true` when the installed version is older.
861862 */
862863 private async checkCLILatestVersion ( verbose = false , next = false ) : Promise < boolean > {
863- const { version : installedCLIVersion } = require ( '../package.json' ) ;
864+ const installedCLIVersion = VERSION . full ;
864865
865866 const LatestCLIManifest = await fetchPackageManifest (
866867 `@angular/cli@${ next ? 'next' : 'latest' } ` ,
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import 'symbol-observable';
1111import * as fs from 'fs' ;
1212import * as path from 'path' ;
1313import { SemVer } from 'semver' ;
14+ import { VERSION } from '../models/version' ;
1415import { colors } from '../utilities/color' ;
1516import { isWarningEnabled } from '../utilities/config' ;
1617
@@ -80,14 +81,17 @@ if (process.env['NG_CLI_PROFILING']) {
8081 const projectLocalCli = require . resolve ( '@angular/cli' , { paths : [ process . cwd ( ) ] } ) ;
8182 cli = await import ( projectLocalCli ) ;
8283
83- const globalVersion = new SemVer ( require ( '../package.json' ) . version ) ;
84+ const globalVersion = new SemVer ( VERSION . full ) ;
8485
8586 // Older versions might not have the VERSION export
8687 let localVersion = cli . VERSION ?. full ;
8788 if ( ! localVersion ) {
8889 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 ;
9195 } catch ( error ) {
9296 // eslint-disable-next-line no-console
9397 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';
1010import debug from 'debug' ;
1111import * as inquirer from 'inquirer' ;
1212import { v4 as uuidV4 } from 'uuid' ;
13+ import { VERSION } from '../models/version' ;
1314import { colors } from '../utilities/color' ;
1415import { getWorkspace , getWorkspaceRaw } from '../utilities/config' ;
1516import { isTTY } from '../utilities/tty' ;
@@ -27,7 +28,7 @@ export const AnalyticsProperties = {
2728 return _defaultAngularCliPropertyCache ;
2829 }
2930
30- const v = require ( '../package.json' ) . version ;
31+ const v = VERSION . full ;
3132
3233 // The logic is if it's a full version then we should use the prod GA property.
3334 if ( / ^ \d + \. \d + \. \d + $ / . test ( v ) && v !== '0.0.0' ) {
You can’t perform that action at this time.
0 commit comments