Skip to content

Commit

Permalink
refactor(build): move to npm @types defs from typings and update code…
Browse files Browse the repository at this point in the history
… so angular is loaded not from global namespace

- remove bash script for appending manual typings to core.d.ts which doesn't work
- remove typings
- update packages ( ts, ts-node, mocha, chai )
  • Loading branch information
Hotell committed Nov 12, 2016
1 parent eb4e21b commit 82f72ca
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 67 deletions.
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "3.0.3",
"description": "Angular 2 decorators and utils for Angular 1.x",
"scripts": {
"typings": "typings",
"typings:install": "typings install",
"prepublish": "npm run typings:install && tsc && ./scripts/create_core.sh",
"prepublish": "tsc",
"start": "tsc -w",
"test": "mocha ./test/index.ts --require ts-node/register --colors --watch-extensions ts",
"test:watch": "npm run test -- --watch",
Expand All @@ -31,24 +29,28 @@
},
"homepage": "https://github.com/ngParty/ng-metadata#readme",
"devDependencies": {
"@types/angular": "1.5.19",
"@types/chai": "3.4.34",
"@types/jquery": "2.0.34",
"@types/mocha": "2.2.32",
"@types/node": "6.0.46",
"@types/sinon": "1.16.31",
"angular": "1.4.10",
"chai": "3.4.1",
"chai": "3.5.0",
"commitizen": "2.4.6",
"concurrently": "2.1.0",
"conventional-changelog": "1.1.0",
"conventional-recommended-bump": "0.2.1",
"cz-conventional-changelog": "1.1.4",
"ghooks": "1.0.1",
"live-server": "0.8.2",
"mocha": "2.3.4",
"reflect-metadata": "0.1.3",
"mocha": "3.1.2",
"reflect-metadata": "0.1.8",
"rxjs": "5.0.0-rc.1",
"sinon": "1.17.2",
"sinon": "1.17.6",
"systemjs": "0.19.6",
"systemjs-builder": "0.14.11",
"ts-node": "0.7.3",
"typescript": "2.0.3",
"typings": "1.0.4",
"ts-node": "1.7.0",
"typescript": "2.0.9",
"validate-commit-msg": "2.0.0"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as angular from 'angular';
import {
Component,
ChangeDetectionStrategy,
Expand Down
1 change: 1 addition & 0 deletions playground/app/components/tester/tester.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as angular from 'angular';
import { Component, Input, Output } from 'ng-metadata/core';

@Component({
Expand Down
1 change: 1 addition & 0 deletions playground/app/directives/my-tester.directive.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as angular from 'angular';
import { Directive, Input, Output, Attr, HostListener } from 'ng-metadata/core';

@Directive({
Expand Down
3 changes: 3 additions & 0 deletions playground/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// @FIXME remove this line when https://github.com/ngParty/ng-metadata/issues/175 is resolved
///<reference path="../../manual_typings/globals.d.ts"/>

import * as angular from 'angular';
import { provide, OpaqueToken, Injectable } from 'ng-metadata/core';

Expand Down
2 changes: 1 addition & 1 deletion playground/app/todo/add-todo.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Output, EventEmitter } from 'ng-metadata/core';
import { TodoModel } from './todo-store.service.ts';
import { TodoModel } from './todo-store.service';

@Component({
selector: 'add-todo',
Expand Down
1 change: 1 addition & 0 deletions playground/app/todo/todo-store.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as angular from 'angular';
import {Injectable} from 'ng-metadata/core';

export type TodoModel = {
Expand Down
19 changes: 5 additions & 14 deletions playground/ng-metadata.legacy.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// import * as angular from 'angular';
// import Subject = require('rxjs/Subject');
declare type Observable<T> = any;
declare type Subject<T> = any;
Expand Down Expand Up @@ -1014,16 +1015,17 @@ declare module ngMetadataCommon {
$isEmpty(value: any): boolean;
}
export abstract class NgForm implements ng.IFormController {
$name: string;
$pristine: boolean;
$dirty: boolean;
$valid: boolean;
$invalid: boolean;
$submitted: boolean;
$error: any;
$pending: any;
$addControl(control: angular.INgModelController): void;
$removeControl(control: angular.INgModelController): void;
$setValidity(validationErrorKey: string, isValid: boolean, control: angular.INgModelController): void;
$addControl(control: ng.INgModelController): void;
$removeControl(control: ng.INgModelController): void;
$setValidity(validationErrorKey: string, isValid: boolean, control: ng.INgModelController): void;
$setDirty(): void;
$setPristine(): void;
$commitViewValue(): void;
Expand Down Expand Up @@ -1067,14 +1069,3 @@ declare module "ng-metadata/common" {
export = ngMetadataCommon
}
declare type Type = Function;
declare type ProvideSpreadType = string|Type;

declare module angular {
interface IModule {
// constant(object: Object): IModule;
// value(object: Object): IModule;
directive(...args: ProvideSpreadType[]): IModule;
filter(...args: ProvideSpreadType[]): IModule;
service(...args: ProvideSpreadType[]): IModule;
}
}
12 changes: 8 additions & 4 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"pretty": true
"pretty": true,
"lib": [
"es5",
"dom",
"es2015.promise"
]
},
"files": [
"app/main.ts",
"../typings/index.d.ts",
"ng-metadata.legacy.d.ts"
"./app/main.ts",
"./ng-metadata.legacy.d.ts"
]
}
3 changes: 0 additions & 3 deletions scripts/create_core.sh

This file was deleted.

1 change: 0 additions & 1 deletion scripts/typings_import.txt

This file was deleted.

6 changes: 3 additions & 3 deletions src/common/directives/ng_form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export abstract class NgForm implements ng.IFormController {
$name: string;
$pending: any;

$addControl( control: angular.INgModelController ): void {}
$addControl( control: ng.INgModelController ): void {}

$removeControl( control: angular.INgModelController ): void {}
$removeControl( control: ng.INgModelController ): void {}

$setValidity( validationErrorKey: string, isValid: boolean, control: angular.INgModelController ): void {}
$setValidity( validationErrorKey: string, isValid: boolean, control: ng.INgModelController ): void {}

$setDirty(): void {}

Expand Down
2 changes: 1 addition & 1 deletion src/core/directives/binding/binding_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function _createDirectiveBindings(
oldValue = initialValue;
}
recordChanges( propName, newValue, oldValue );
ctrl[ propName ] = isImmutable ? angular.copy(newValue) : newValue;
ctrl[ propName ] = isImmutable ? global.angular.copy(newValue) : newValue;
}, parentGet.literal );

}
Expand Down
5 changes: 3 additions & 2 deletions src/core/directives/host/host_resolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HostBindingsProcessed, HostListenersProcessed } from './constants';
import { global } from '../../../facade/lang';
import { StringMapWrapper } from '../../../facade/collections';
import { StringWrapper } from '../../../facade/primitives';
/**
Expand Down Expand Up @@ -171,11 +172,11 @@ function _getGlobalTargetReference( $injector: ng.auto.IInjectorService, targetN
}

if ( targetName === 'window' ) {
return angular.element( $injector.get<ng.IWindowService>( `$${targetName}` ) );
return global.angular.element( $injector.get<ng.IWindowService>( `$${targetName}` ) );
}

if ( targetName === 'body' ) {
return angular.element($document[ 0 ][ targetName ]);
return global.angular.element($document[ 0 ][ targetName ]);
}

throw new Error(`unsupported global target '${targetName}', only '${globalEventTargets}' are supported`)
Expand Down
6 changes: 3 additions & 3 deletions src/facade/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export interface BrowserNodeGlobal {
setTimeout: Function,
clearTimeout: Function,
setInterval: Function,
clearInterval: Function
clearInterval: Function,
}

var globalScope: BrowserNodeGlobal;
let globalScope: BrowserNodeGlobal;

if ( typeof window === 'undefined' ) {
globalScope = global as any;
Expand All @@ -33,7 +33,7 @@ if ( typeof window === 'undefined' ) {

// Need to declare a new variable for global here since TypeScript
// exports the original value of the symbol.
var _global: BrowserNodeGlobal = globalScope;
const _global: BrowserNodeGlobal = globalScope;

export {_global as global};

Expand Down
8 changes: 4 additions & 4 deletions src/platform/browser_utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertionsEnabled } from '../facade/lang';
import { global, assertionsEnabled } from '../facade/lang';
import { bundle } from '../core/util/bundler';
import { Type } from '../facade/type';

Expand All @@ -19,7 +19,7 @@ function prodModeConfig( $compileProvider: ng.ICompileProvider, $httpProvider: n
$httpProvider.useApplyAsync( true );
}

export function createBootstrapFn(bootstrapFn: Function = angular.bootstrap.bind(angular)): Function {
export function createBootstrapFn(bootstrapFn: Function = global.angular.bootstrap.bind(global.angular)): Function {

/**
* bootstrap angular app
Expand All @@ -40,12 +40,12 @@ export function createBootstrapFn(bootstrapFn: Function = angular.bootstrap.bind
'Angular is running in the development mode. Call enableProdMode() to enable the production mode.'
);
} else {
angular.module( angular1ModuleName ).config( prodModeConfig );
global.angular.module( angular1ModuleName ).config( prodModeConfig );
}

const appRoot = _getAppRoot( element );

angular.element( document ).ready( ()=> {
global.angular.element( document ).ready( ()=> {
bootstrapFn( appRoot, [ angular1ModuleName ], {
strictDi
} )
Expand Down
3 changes: 2 additions & 1 deletion src/testing/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getInjectableName } from '../core/di/provider';
import { StringWrapper } from '../facade/primitives';
import { Type } from '../facade/type';
import { global } from '../facade/lang';

// public helpers

Expand Down Expand Up @@ -42,7 +43,7 @@ export function renderFactory( $compile: ng.ICompileService, $scope: any ) {
// is Component

const hostElement = `<${selector}></${selector}>`;
jqHost = angular.element( hostElement );
jqHost = global.angular.element( hostElement );

}
// since attributes can be undefined we check them
Expand Down
2 changes: 1 addition & 1 deletion src/upgrade/upgrade_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface UpgradeAdapterInstance {
/**
* Bootstrap a hybrid AngularJS v1 / Angular v2 application.
*/
bootstrap(element: Element, modules?: any[], config?: angular.IAngularBootstrapConfig): UpgradeAdapterRef;
bootstrap(element: Element, modules?: any[], config?: ng.IAngularBootstrapConfig): UpgradeAdapterRef;
/**
* Allows Angular v2 service to be accessible from AngularJS v1.
*/
Expand Down
1 change: 0 additions & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as angular from 'angular';
import { isArray, isFunction, assign } from '../src/facade/lang';

// ============================
Expand Down
11 changes: 10 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
"emitDecoratorMetadata": true,
"declaration": true,
"pretty": true,
"preserveConstEnums": true
"preserveConstEnums": true,
"moduleResolution": "node",
"lib": [
"es5",
"dom",
"es2015.promise"
]
},
"include": [
"manual_typings/globals.d.ts"
],
"exclude": [
"_book",
"playground",
Expand Down
16 changes: 0 additions & 16 deletions typings.json

This file was deleted.

0 comments on commit 82f72ca

Please sign in to comment.