Skip to content

Commit 6244afb

Browse files
committed
fix: re-enable ngDevMode tree shaking
1 parent 7cbb2d8 commit 6244afb

File tree

8 files changed

+38
-18
lines changed

8 files changed

+38
-18
lines changed

packages/angular/ng-package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "../../node_modules/ng-packagr/package.schema.json",
2+
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
33
"assets": [".npmignore"],
44
"lib": {
55
"entryFile": "src/index.ts"

packages/angular/references.d.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
/* eslint-disable @typescript-eslint/triple-slash-reference */
2-
/// <reference path="../../references.d.ts" />
1+
/* eslint-disable */
2+
/// <reference path="../../references.d.ts" />
3+
4+
declare global {
5+
const ngDevMode: boolean;
6+
}
7+
8+
declare module globalThis {
9+
const ngDevMode: boolean;
10+
}

packages/angular/src/lib/cdk/dialog/dialog-services.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ export abstract class _NativeDialogBase<C extends NativeModalRef> implements OnD
5353
return parent ? parent._getAfterAllClosed() : this._afterAllClosedAtThisLevel;
5454
}
5555

56-
constructor(private _injector: Injector, private _defaultOptions: NativeDialogConfig | undefined, private _parentDialog: _NativeDialogBase<C> | undefined, private _dialogRefConstructor: Type<NativeDialogRef<any>>, private _nativeModalType: Type<C>, private _dialogDataToken: InjectionToken<any>, private locationStrategy: NSLocationStrategy) {}
56+
constructor(
57+
private _injector: Injector,
58+
private _defaultOptions: NativeDialogConfig | undefined,
59+
private _parentDialog: _NativeDialogBase<C> | undefined,
60+
private _dialogRefConstructor: Type<NativeDialogRef<any>>,
61+
private _nativeModalType: Type<C>,
62+
private _dialogDataToken: InjectionToken<any>,
63+
private locationStrategy: NSLocationStrategy,
64+
) {}
5765

5866
/**
5967
* Opens a modal dialog containing the given component.
@@ -76,7 +84,7 @@ export abstract class _NativeDialogBase<C extends NativeModalRef> implements OnD
7684
open<T, D = any, R = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>, config?: NativeDialogConfig<D>): NativeDialogRef<T, R> {
7785
config = _applyConfigDefaults(config, this._defaultOptions || new NativeDialogConfig());
7886

79-
if (config.id && this.getDialogById(config.id) && (typeof global.ngDevMode === 'undefined' || global.ngDevMode)) {
87+
if (config.id && this.getDialogById(config.id) && (typeof ngDevMode === 'undefined' || ngDevMode)) {
8088
throw Error(`Dialog with id "${config.id}" exists already. The dialog id must be unique.`);
8189
}
8290
const dialogRef = this._attachDialogContent<T, R>(componentOrTemplateRef, config);
@@ -141,7 +149,7 @@ export abstract class _NativeDialogBase<C extends NativeModalRef> implements OnD
141149
// detachedLoaderRef.instance.createTemplatePortal(options.templateRef);
142150
nativeModalRef.attachTemplatePortal(
143151
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
144-
new TemplatePortal<T>(componentOrTemplateRef, null!, <any>{ $implicit: config.data, dialogRef })
152+
new TemplatePortal<T>(componentOrTemplateRef, null!, <any>{ $implicit: config.data, dialogRef }),
145153
);
146154
} else {
147155
const injector = this._createInjector<T>(config, dialogRef);

packages/angular/src/lib/cdk/portal/common.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export abstract class Portal<T> {
2020

2121
/** Attach this portal to a host. */
2222
attach(host: PortalOutlet): T {
23-
if (typeof global.ngDevMode === 'undefined' || global.ngDevMode) {
23+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
2424
if (host == null) {
2525
throwNullPortalOutletError();
2626
}
@@ -41,7 +41,7 @@ export abstract class Portal<T> {
4141
if (host != null) {
4242
this._attachedHost = null;
4343
host.detach();
44-
} else if (typeof global.ngDevMode === 'undefined' || global.ngDevMode) {
44+
} else if (typeof ngDevMode === 'undefined' || ngDevMode) {
4545
throwNoPortalAttachedError();
4646
}
4747
}
@@ -187,7 +187,7 @@ export abstract class BasePortalOutlet implements PortalOutlet {
187187

188188
/** Attaches a portal. */
189189
attach(portal: Portal<any>): any {
190-
if (typeof global.ngDevMode === 'undefined' || global.ngDevMode) {
190+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
191191
if (!portal) {
192192
throwNullPortalError();
193193
}
@@ -213,7 +213,7 @@ export abstract class BasePortalOutlet implements PortalOutlet {
213213
return this.attachDomPortal(portal);
214214
}
215215

216-
if (typeof global.ngDevMode === 'undefined' || global.ngDevMode) {
216+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
217217
throwUnknownPortalTypeError();
218218
}
219219
}

packages/angular/src/lib/cdk/portal/nsdom-portal-outlet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class NativeScriptDomPortalOutlet extends BasePortalOutlet {
2424
private _componentFactoryResolver: ComponentFactoryResolver,
2525
private _appRef: ApplicationRef,
2626
private _defaultInjector: Injector,
27-
@Optional() viewUtil?: ViewUtil
27+
@Optional() viewUtil?: ViewUtil,
2828
) {
2929
super();
3030
this._viewUtil = viewUtil || this._defaultInjector.get(ViewUtil);
@@ -111,7 +111,7 @@ export class NativeScriptDomPortalOutlet extends BasePortalOutlet {
111111
*/
112112
attachDomPortal = (portal: DomPortal) => {
113113
const element = portal.element;
114-
if (!element.parentNode && (typeof global.ngDevMode === 'undefined' || global.ngDevMode)) {
114+
if (!element.parentNode && (typeof ngDevMode === 'undefined' || ngDevMode)) {
115115
throw Error('DOM portal content must be attached to a parent node.');
116116
}
117117

packages/angular/src/lib/cdk/portal/portal-directives.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export class CdkPortalOutlet extends BasePortalOutlet implements OnInit, OnDestr
5252
/** Reference to the currently-attached component/view ref. */
5353
private _attachedRef: CdkPortalOutletAttachedRef;
5454

55-
constructor(private _viewContainerRef: ViewContainerRef, private renderer: Renderer2) {
55+
constructor(
56+
private _viewContainerRef: ViewContainerRef,
57+
private renderer: Renderer2,
58+
) {
5659
super();
5760
}
5861

@@ -157,7 +160,7 @@ export class CdkPortalOutlet extends BasePortalOutlet implements OnInit, OnDestr
157160
*/
158161
attachDomPortal = (portal: DomPortal) => {
159162
const element = portal.element;
160-
if (!element.parentNode && (typeof global.ngDevMode === 'undefined' || global.ngDevMode)) {
163+
if (!element.parentNode && (typeof ngDevMode === 'undefined' || ngDevMode)) {
161164
throw Error('DOM portal content must be attached to a parent node.');
162165
}
163166

packages/angular/src/lib/nativescript-ng-zone.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ export class NativeScriptNgZone implements NgZone {
149149
self.shouldCoalesceRunChangeDetection = shouldCoalesceRunChangeDetection;
150150
self.lastRequestAnimationFrameId = -1;
151151
self.nativeRequestAnimationFrame = function (cb) {
152-
const nativeDispatchToMainThread = Utils[Zone.__symbol__('dispatchToMainThread')] || Utils.dispatchToMainThread;
153-
nativeDispatchToMainThread(cb);
152+
// const nativeDispatchToMainThread = Utils[Zone.__symbol__('dispatchToMainThread')] || Utils.dispatchToMainThread;
153+
// nativeDispatchToMainThread(cb);
154+
const nativeDispatchToMainThread = global[Zone.__symbol__('setTimeout')] || global.setTimeout;
155+
nativeDispatchToMainThread(cb, 1000);
154156
return currentRafId++;
155157
};
156158
forkInnerZoneWithAngularBehavior(self);
@@ -377,7 +379,7 @@ function delayChangeDetectionForEvents(zone: NgZonePrivate) {
377379
},
378380
undefined,
379381
() => {},
380-
() => {}
382+
() => {},
381383
);
382384
}
383385
zone.fakeTopEventTask.invoke();

references.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ declare namespace NodeJS {
77
interface Global {
88
__runtimeVersion: any;
99
TNS_ENV: string;
10-
ngDevMode: unknown | null;
1110
}
1211
}
1312

0 commit comments

Comments
 (0)