Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(core): update isDevMode to rely on ngDevMode (#47475)
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` and `@angular/compiler` to remove usage of `jitDevMode`, with this change we remove all internal usages of `isDevMode`.

PR Close #47475
  • Loading branch information
alan-agius4 authored and alxhub committed Sep 23, 2022
1 parent 3fe21a6 commit 85330f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
4 changes: 0 additions & 4 deletions packages/compiler/src/config.ts
Expand Up @@ -12,29 +12,25 @@ import {noUndefined} from './util';
export class CompilerConfig {
public defaultEncapsulation: ViewEncapsulation|null;
public useJit: boolean;
public jitDevMode: boolean;
public missingTranslation: MissingTranslationStrategy|null;
public preserveWhitespaces: boolean;
public strictInjectionParameters: boolean;

constructor({
defaultEncapsulation = ViewEncapsulation.Emulated,
useJit = true,
jitDevMode = false,
missingTranslation = null,
preserveWhitespaces,
strictInjectionParameters
}: {
defaultEncapsulation?: ViewEncapsulation,
useJit?: boolean,
jitDevMode?: boolean,
missingTranslation?: MissingTranslationStrategy|null,
preserveWhitespaces?: boolean,
strictInjectionParameters?: boolean,
} = {}) {
this.defaultEncapsulation = defaultEncapsulation;
this.useJit = !!useJit;
this.jitDevMode = !!jitDevMode;
this.missingTranslation = missingTranslation;
this.preserveWhitespaces = preserveWhitespacesDefault(noUndefined(preserveWhitespaces));
this.strictInjectionParameters = strictInjectionParameters === true;
Expand Down
31 changes: 9 additions & 22 deletions packages/core/src/util/is_dev_mode.ts
Expand Up @@ -9,27 +9,16 @@
import {global} from './global';

/**
* This file is used to control if the default rendering pipeline should be `ViewEngine` or `Ivy`.
* Returns whether Angular is in development mode.
*
* For more information on how to run and debug tests with either Ivy or View Engine (legacy),
* please see [BAZEL.md](./docs/BAZEL.md).
*/

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


/**
* Returns whether Angular is in development mode. After called once,
* the value is locked and won't change any more.
*
* By default, this is true, unless a user calls `enableProdMode` before calling this.
* By default, this is true, unless `enableProdMode` is invoked prior to calling this method or the
* application is built using the Angular CLI with the `optimization` option.
* @see {@link cli/build ng build}
*
* @publicApi
*/
export function isDevMode(): boolean {
_runModeLocked = true;
return _devMode;
return typeof ngDevMode === 'undefined' || !!ngDevMode;
}

/**
Expand All @@ -40,18 +29,16 @@ export function isDevMode(): boolean {
* does not result in additional changes to any bindings (also known as
* unidirectional data flow).
*
* Using this method is discouraged as the Angular CLI will set production mode when using the
* `optimization` option.
* @see {@link cli/build ng build}
*
* @publicApi
*/
export function enableProdMode(): void {
if (_runModeLocked) {
throw new Error('Cannot enable prod mode after platform setup.');
}

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

_devMode = false;
}
3 changes: 1 addition & 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,6 @@ export class JitCompilerFactory implements CompilerFactory {
// let explicit values from the compiler options overwrite options
// from the app providers
useJit: opts.useJit,
jitDevMode: isDevMode(),
// let explicit values from the compiler options overwrite options
// from the app providers
defaultEncapsulation: opts.defaultEncapsulation,
Expand Down

0 comments on commit 85330f3

Please sign in to comment.