Skip to content

Commit 2982613

Browse files
fix(build): Use global angular reference if require('angular') is falsey or empty
- its empty when required from bower, which doesnt export anything Closes #3113
1 parent 2582fca commit 2982613

11 files changed

+28
-39
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"clean": "shx rm -rf lib lib-esm _doc release",
77
"build": "tsc && tsc -m es6 --outDir lib-esm",
8-
"package": "npm run clean && npm run build && webpack",
8+
"package": "npm run clean && npm run build && webpack --hide-modules",
99
"test": "npm run test:integrate",
1010
"test:ng12": "karma start --ngversion 1.2.28",
1111
"test:ng13": "karma start --ngversion 1.3.16",

src/angular.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare var angular;
2+
import * as ng_from_import from "angular";
3+
let ng_from_global = angular;
4+
5+
export const ng = (ng_from_import && ng_from_import.module) ? ng_from_import : ng_from_global;

src/ng1/directives/stateDirectives.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
*
66
* @preferred @module ng1_directives
77
*/ /** for typedoc */
8-
import * as angular from 'angular';
8+
import { ng as angular } from '../../angular';
9+
import { IAugmentedJQuery, ITimeoutService, IScope, IInterpolateService } from "angular";
10+
911
import {Obj, extend, forEach, toJson, tail} from "ui-router-core";
1012
import {isString, isObject} from "ui-router-core";
1113
import {UIViewData} from "./viewDirective";
1214
import {parse} from "ui-router-core";
1315
import {PathNode} from "ui-router-core";
1416
import {StateOrName} from "ui-router-core";
1517
import {StateService} from "ui-router-core";
16-
import IAugmentedJQuery = angular.IAugmentedJQuery;
17-
import ITimeoutService = angular.ITimeoutService;
18-
import IScope = angular.IScope;
19-
import IInterpolateService = angular.IInterpolateService;
2018
import {TransitionService} from "ui-router-core";
2119
import {State} from "ui-router-core";
2220
import {UIRouter} from "ui-router-core";

src/ng1/directives/viewDirective.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/** @module ng1_directives */ /** for typedoc */
2-
"use strict";
2+
import { ng as angular } from '../../angular';
3+
import { IInterpolateService, IScope, ITranscludeFunction, IAugmentedJQuery,
4+
ICompileService, IControllerService, ITimeoutService } from "angular";
5+
36
import {extend, unnestR, filter, tail} from "ui-router-core";
47
import {isDefined, isFunction, isString} from "ui-router-core";
58
import {trace} from "ui-router-core";
@@ -19,15 +22,6 @@ import {ViewService} from "ui-router-core";
1922
import {$QLike} from "ui-router-core";
2023
import {Obj} from "ui-router-core";
2124

22-
import * as angular from 'angular';
23-
import IInterpolateService = angular.IInterpolateService;
24-
import IScope = angular.IScope;
25-
import ITranscludeFunction = angular.ITranscludeFunction;
26-
import IAugmentedJQuery = angular.IAugmentedJQuery;
27-
import ICompileService = angular.ICompileService;
28-
import IControllerService = angular.IControllerService;
29-
import ITimeoutService = angular.ITimeoutService;
30-
3125
/** @hidden */
3226
export type UIViewData = {
3327
$cfg: Ng1ViewConfig;

src/ng1/legacy/stateEvents.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
*
1717
* @module ng1_state_events
1818
*/ /** */
19-
import {IServiceProviderFactory} from "angular";
19+
import { ng as angular } from '../../angular';
20+
import { IScope, IAngularEvent, IServiceProviderFactory } from "angular";
21+
2022
import {Obj} from "ui-router-core";
2123
import {TargetState} from "ui-router-core";
2224
import {StateService} from "ui-router-core";
2325
import {StateProvider} from "../stateProvider";
2426
import {Transition} from "ui-router-core";
25-
import IAngularEvent = angular.IAngularEvent;
2627
import {TransitionService} from "ui-router-core";
2728
import {UrlRouter} from "ui-router-core";
28-
import * as angular from 'angular';
29-
import IScope = angular.IScope;
3029
import {HookResult} from "ui-router-core";
3130
import {UIInjector} from "ui-router-core";
3231

src/ng1/services.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
*/
1111

1212
/** for typedoc */
13+
import { ng as angular } from '../angular';
14+
import IInjectorService = angular.auto.IInjectorService;
15+
import { IRootScopeService, IQService, ILocationService, ILocationProvider, IHttpService, ITemplateCacheService } from 'angular';
16+
1317
import {UIRouter} from "ui-router-core";
1418
import {services, $InjectorLike} from "ui-router-core";
1519
import {bindFunctions, removeFrom, applyPairs, IInjectable} from "ui-router-core";
@@ -29,15 +33,6 @@ import {UrlMatcherFactory} from "ui-router-core";
2933
import {getStateHookBuilder} from "./statebuilders/onEnterExitRetain";
3034
import {ResolveContext} from "ui-router-core";
3135

32-
import * as angular from 'angular';
33-
import IInjectorService = angular.auto.IInjectorService;
34-
import IQService = angular.IQService;
35-
import ILocationProvider = angular.ILocationProvider;
36-
import ILocationService = angular.ILocationService;
37-
import IHttpService = angular.IHttpService;
38-
import ITemplateCacheService = angular.ITemplateCacheService;
39-
import IScope = angular.IScope;
40-
4136
/** @hidden */
4237
let app = angular.module("ui.router.angular1", []);
4338

@@ -194,7 +189,7 @@ function $uiRouter($locationProvider: ILocationProvider) {
194189

195190
this.$get = $get;
196191
$get.$inject = ['$location', '$browser', '$sniffer', '$rootScope', '$http', '$templateCache'];
197-
function $get($location: ILocationService, $browser: any, $sniffer: any, $rootScope: IScope, $http: IHttpService, $templateCache: ITemplateCacheService) {
192+
function $get($location: ILocationService, $browser: any, $sniffer: any, $rootScope: ng.IScope, $http: IHttpService, $templateCache: ITemplateCacheService) {
198193

199194
// Bind $locationChangeSuccess to the listeners registered in LocationService.onChange
200195
$rootScope.$on("$locationChangeSuccess", evt => urlListeners.forEach(fn => fn(evt)));
@@ -291,7 +286,7 @@ angular.module('ui.router').factory('$resolve', <any> resolveFactory);
291286
// $trace service
292287
angular.module("ui.router").service("$trace", () => trace);
293288
watchDigests.$inject = ['$rootScope'];
294-
export function watchDigests($rootScope: IScope) {
289+
export function watchDigests($rootScope: IRootScopeService) {
295290
$rootScope.$watch(function() { trace.approximateDigests++; });
296291
}
297292
angular.module("ui.router").run(watchDigests);

src/ng1/stateFilters.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/** @module state */ /** for typedoc */
22

3+
import { ng as angular } from '../angular';
34
import {Obj} from "ui-router-core";
45
import {StateService} from "ui-router-core";
56
import {StateOrName} from "ui-router-core";
6-
import * as angular from 'angular';
77

88
/**
99
* @ngdoc filter

src/ng1/statebuilders/onEnterExitRetain.ts

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import {ResolveContext} from "ui-router-core";
88
import {extend} from "ui-router-core";
99
import {BuilderFunction} from "ui-router-core";
1010

11-
import * as angular from 'angular';
12-
import IInjectorService = angular.auto.IInjectorService;
13-
1411
/**
1512
* This is a [[StateBuilder.builder]] function for angular1 `onEnter`, `onExit`,
1613
* `onRetain` callback hooks on a [[Ng1StateDeclaration]].

src/ng1/statebuilders/views.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/** @module ng1 */ /** */
2+
import { ng as angular } from '../../angular';
3+
import IInjectorService = angular.auto.IInjectorService;
4+
25
import {State} from "ui-router-core";
36
import {Obj, pick, forEach, anyTrueR, unnestR, tail, extend} from "ui-router-core";
47
import {kebobString} from "ui-router-core";
@@ -14,9 +17,6 @@ import {ResolveContext} from "ui-router-core";
1417
import {Resolvable} from "ui-router-core";
1518
import {RawParams} from "ui-router-core";
1619

17-
import * as angular from 'angular';
18-
import IInjectorService = angular.auto.IInjectorService;
19-
2020
export const ng1ViewConfigFactory: ViewConfigFactory = (path, view) =>
2121
[new Ng1ViewConfig(path, view)];
2222

src/ng1/viewScroll.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @module ng1 */ /** */
2-
import * as angular from 'angular';
2+
import { ng as angular } from '../angular';
33
import {IServiceProviderFactory} from "angular";
44
import IAnchorScrollService = angular.IAnchorScrollService;
55
import ITimeoutService = angular.ITimeoutService;

webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module.exports = {
4343
{ test: /\.ts$/, loader: "awesome-typescript-loader?declaration=false" }
4444
]
4545
},
46+
4647
ts: {
4748
compilerOptions: {
4849
declaration: false

0 commit comments

Comments
 (0)