Skip to content

Commit

Permalink
fix(core): update isDevMode to rely on ngDevMode
Browse files Browse the repository at this point in the history
This commits update `isDevMode` to rely on the `ngDevMode` which in the CLI is set by the bundler.

We also update `@angular/platform-dynamic-browser` to use the `ngDevMode` flag directly and remove the last usage of `isDevMode` in code base.
  • Loading branch information
alan-agius4 committed Sep 19, 2022
1 parent 4eff4d3 commit b0b9a6f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions packages/core/src/util/is_dev_mode.ts
Expand Up @@ -15,7 +15,6 @@ import {global} from './global';
* please see [BAZEL.md](./docs/BAZEL.md).
*/

let _devMode: boolean = true;
let _runModeLocked: boolean = false;


Expand All @@ -29,7 +28,8 @@ let _runModeLocked: boolean = false;
*/
export function isDevMode(): boolean {
_runModeLocked = true;
return _devMode;

return typeof ngDevMode === 'undefined' || !!ngDevMode;
}

/**
Expand All @@ -49,9 +49,7 @@ export function enableProdMode(): void {

// The below check is there so when ngDevMode is set via terser
// `global['ngDevMode'] = false;` is also dropped.
if (typeof ngDevMode === undefined || !!ngDevMode) {
if (typeof ngDevMode === 'undefined' || ngDevMode) {
global['ngDevMode'] = false;
}

_devMode = false;
}
4 changes: 2 additions & 2 deletions packages/platform-browser-dynamic/src/compiler_factory.ts
Expand Up @@ -7,7 +7,7 @@
*/

import {CompilerConfig} from '@angular/compiler';
import {Compiler, CompilerFactory, CompilerOptions, InjectionToken, Injector, isDevMode, MissingTranslationStrategy, PACKAGE_ROOT_URL, StaticProvider, ViewEncapsulation} from '@angular/core';
import {Compiler, CompilerFactory, CompilerOptions, InjectionToken, Injector, MissingTranslationStrategy, PACKAGE_ROOT_URL, StaticProvider, ViewEncapsulation} from '@angular/core';

export const ERROR_COLLECTOR_TOKEN = new InjectionToken('ErrorCollector');

Expand Down Expand Up @@ -52,7 +52,7 @@ export class JitCompilerFactory implements CompilerFactory {
// let explicit values from the compiler options overwrite options
// from the app providers
useJit: opts.useJit,
jitDevMode: isDevMode(),
jitDevMode: typeof ngDevMode === 'undefined' || !!ngDevMode,
// let explicit values from the compiler options overwrite options
// from the app providers
defaultEncapsulation: opts.defaultEncapsulation,
Expand Down

0 comments on commit b0b9a6f

Please sign in to comment.