Permalink
Browse files

fix(build): Use global `angular` reference if require('angular') is f…

…alsey or empty

- its empty when required from bower, which doesnt export anything

Closes #3113
  • Loading branch information...
1 parent 2582fca commit 298261382f4ad0134c070caefcce859e2b693891 @christopherthielen christopherthielen committed Nov 1, 2016
View
@@ -5,7 +5,7 @@
"scripts": {
"clean": "shx rm -rf lib lib-esm _doc release",
"build": "tsc && tsc -m es6 --outDir lib-esm",
- "package": "npm run clean && npm run build && webpack",
+ "package": "npm run clean && npm run build && webpack --hide-modules",
"test": "npm run test:integrate",
"test:ng12": "karma start --ngversion 1.2.28",
"test:ng13": "karma start --ngversion 1.3.16",
View
@@ -0,0 +1,5 @@
+declare var angular;
+import * as ng_from_import from "angular";
+let ng_from_global = angular;
+
+export const ng = (ng_from_import && ng_from_import.module) ? ng_from_import : ng_from_global;
@@ -5,18 +5,16 @@
*
* @preferred @module ng1_directives
*/ /** for typedoc */
-import * as angular from 'angular';
+import { ng as angular } from '../../angular';
+import { IAugmentedJQuery, ITimeoutService, IScope, IInterpolateService } from "angular";
+
import {Obj, extend, forEach, toJson, tail} from "ui-router-core";
import {isString, isObject} from "ui-router-core";
import {UIViewData} from "./viewDirective";
import {parse} from "ui-router-core";
import {PathNode} from "ui-router-core";
import {StateOrName} from "ui-router-core";
import {StateService} from "ui-router-core";
-import IAugmentedJQuery = angular.IAugmentedJQuery;
-import ITimeoutService = angular.ITimeoutService;
-import IScope = angular.IScope;
-import IInterpolateService = angular.IInterpolateService;
import {TransitionService} from "ui-router-core";
import {State} from "ui-router-core";
import {UIRouter} from "ui-router-core";
@@ -1,5 +1,8 @@
/** @module ng1_directives */ /** for typedoc */
-"use strict";
+import { ng as angular } from '../../angular';
+import { IInterpolateService, IScope, ITranscludeFunction, IAugmentedJQuery,
+ ICompileService, IControllerService, ITimeoutService } from "angular";
+
import {extend, unnestR, filter, tail} from "ui-router-core";
import {isDefined, isFunction, isString} from "ui-router-core";
import {trace} from "ui-router-core";
@@ -19,15 +22,6 @@ import {ViewService} from "ui-router-core";
import {$QLike} from "ui-router-core";
import {Obj} from "ui-router-core";
-import * as angular from 'angular';
-import IInterpolateService = angular.IInterpolateService;
-import IScope = angular.IScope;
-import ITranscludeFunction = angular.ITranscludeFunction;
-import IAugmentedJQuery = angular.IAugmentedJQuery;
-import ICompileService = angular.ICompileService;
-import IControllerService = angular.IControllerService;
-import ITimeoutService = angular.ITimeoutService;
-
/** @hidden */
export type UIViewData = {
$cfg: Ng1ViewConfig;
@@ -16,17 +16,16 @@
*
* @module ng1_state_events
*/ /** */
-import {IServiceProviderFactory} from "angular";
+import { ng as angular } from '../../angular';
+import { IScope, IAngularEvent, IServiceProviderFactory } from "angular";
+
import {Obj} from "ui-router-core";
import {TargetState} from "ui-router-core";
import {StateService} from "ui-router-core";
import {StateProvider} from "../stateProvider";
import {Transition} from "ui-router-core";
-import IAngularEvent = angular.IAngularEvent;
import {TransitionService} from "ui-router-core";
import {UrlRouter} from "ui-router-core";
-import * as angular from 'angular';
-import IScope = angular.IScope;
import {HookResult} from "ui-router-core";
import {UIInjector} from "ui-router-core";
View
@@ -10,6 +10,10 @@
*/
/** for typedoc */
+import { ng as angular } from '../angular';
+import IInjectorService = angular.auto.IInjectorService;
+import { IRootScopeService, IQService, ILocationService, ILocationProvider, IHttpService, ITemplateCacheService } from 'angular';
+
import {UIRouter} from "ui-router-core";
import {services, $InjectorLike} from "ui-router-core";
import {bindFunctions, removeFrom, applyPairs, IInjectable} from "ui-router-core";
@@ -29,15 +33,6 @@ import {UrlMatcherFactory} from "ui-router-core";
import {getStateHookBuilder} from "./statebuilders/onEnterExitRetain";
import {ResolveContext} from "ui-router-core";
-import * as angular from 'angular';
-import IInjectorService = angular.auto.IInjectorService;
-import IQService = angular.IQService;
-import ILocationProvider = angular.ILocationProvider;
-import ILocationService = angular.ILocationService;
-import IHttpService = angular.IHttpService;
-import ITemplateCacheService = angular.ITemplateCacheService;
-import IScope = angular.IScope;
-
/** @hidden */
let app = angular.module("ui.router.angular1", []);
@@ -194,7 +189,7 @@ function $uiRouter($locationProvider: ILocationProvider) {
this.$get = $get;
$get.$inject = ['$location', '$browser', '$sniffer', '$rootScope', '$http', '$templateCache'];
- function $get($location: ILocationService, $browser: any, $sniffer: any, $rootScope: IScope, $http: IHttpService, $templateCache: ITemplateCacheService) {
+ function $get($location: ILocationService, $browser: any, $sniffer: any, $rootScope: ng.IScope, $http: IHttpService, $templateCache: ITemplateCacheService) {
// Bind $locationChangeSuccess to the listeners registered in LocationService.onChange
$rootScope.$on("$locationChangeSuccess", evt => urlListeners.forEach(fn => fn(evt)));
@@ -291,7 +286,7 @@ angular.module('ui.router').factory('$resolve', <any> resolveFactory);
// $trace service
angular.module("ui.router").service("$trace", () => trace);
watchDigests.$inject = ['$rootScope'];
-export function watchDigests($rootScope: IScope) {
+export function watchDigests($rootScope: IRootScopeService) {
$rootScope.$watch(function() { trace.approximateDigests++; });
}
angular.module("ui.router").run(watchDigests);
@@ -1,9 +1,9 @@
/** @module state */ /** for typedoc */
+import { ng as angular } from '../angular';
import {Obj} from "ui-router-core";
import {StateService} from "ui-router-core";
import {StateOrName} from "ui-router-core";
-import * as angular from 'angular';
/**
* @ngdoc filter
@@ -8,9 +8,6 @@ import {ResolveContext} from "ui-router-core";
import {extend} from "ui-router-core";
import {BuilderFunction} from "ui-router-core";
-import * as angular from 'angular';
-import IInjectorService = angular.auto.IInjectorService;
-
/**
* This is a [[StateBuilder.builder]] function for angular1 `onEnter`, `onExit`,
* `onRetain` callback hooks on a [[Ng1StateDeclaration]].
@@ -1,4 +1,7 @@
/** @module ng1 */ /** */
+import { ng as angular } from '../../angular';
+import IInjectorService = angular.auto.IInjectorService;
+
import {State} from "ui-router-core";
import {Obj, pick, forEach, anyTrueR, unnestR, tail, extend} from "ui-router-core";
import {kebobString} from "ui-router-core";
@@ -14,9 +17,6 @@ import {ResolveContext} from "ui-router-core";
import {Resolvable} from "ui-router-core";
import {RawParams} from "ui-router-core";
-import * as angular from 'angular';
-import IInjectorService = angular.auto.IInjectorService;
-
export const ng1ViewConfigFactory: ViewConfigFactory = (path, view) =>
[new Ng1ViewConfig(path, view)];
@@ -1,5 +1,5 @@
/** @module ng1 */ /** */
-import * as angular from 'angular';
+import { ng as angular } from '../angular';
import {IServiceProviderFactory} from "angular";
import IAnchorScrollService = angular.IAnchorScrollService;
import ITimeoutService = angular.ITimeoutService;
View
@@ -43,6 +43,7 @@ module.exports = {
{ test: /\.ts$/, loader: "awesome-typescript-loader?declaration=false" }
]
},
+
ts: {
compilerOptions: {
declaration: false

0 comments on commit 2982613

Please sign in to comment.