Skip to content

Commit dca2b5d

Browse files
Hotellmgechev
authored andcommitted
build: add prettier and tweak build (#30)
* build: add prettier and fix tslint * build: add lint/format scipts with prebuild hook * fix: resolve all tslint issues * style: apply prettier on whole project * fix: add missing tslint disable pragma * build(tools): get rid of ts-node and use vanilla js with proper TS checking * chore: commit package lock * ci: execute build script on ci * style: apply prettier
1 parent 7014b7e commit dca2b5d

38 files changed

+939
-440
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
dist-test

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"printWidth": 140,
4+
"trailingComma": "es5",
5+
"singleQuote": true,
6+
"useTabs": false,
7+
"bracketSpacing": true
8+
}

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ os:
1111
before_script:
1212
- npm install
1313

14+
script:
15+
- npm run build

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ $ yarn add injection-js
2626
>
2727
> For ES5 `Class` syntax and TypeScript you need a polyfill for the [Reflect API](http://www.ecma-international.org/ecma-262/6.0/#sec-reflection).
2828
> You can use:
29+
>
2930
> - [reflect-metadata](https://www.npmjs.com/package/reflect-metadata)
3031
> - [`core-js` (`core-js/es7/reflect`)](https://www.npmjs.com/package/core-js)
3132
>
@@ -53,16 +54,11 @@ class Service2 {
5354
}
5455

5556
createChildInjector(): void {
56-
const childInjector = ReflectiveInjector.resolveAndCreate([
57-
Service
58-
], this.injector);
57+
const childInjector = ReflectiveInjector.resolveAndCreate([Service], this.injector);
5958
}
6059
}
6160

62-
const injector = ReflectiveInjector.resolveAndCreate([
63-
Service,
64-
Http
65-
]);
61+
const injector = ReflectiveInjector.resolveAndCreate([Service, Http]);
6662

6763
console.log(injector.get(Service) instanceof Service);
6864
```
@@ -96,13 +92,16 @@ require('reflect-metadata');
9692
var di = require('injection-js');
9793

9894
var Http = di.Class({
99-
constructor: function () {}
95+
constructor: function() {},
10096
});
10197

10298
var Service = di.Class({
103-
constructor: [Http, function (http) {
104-
this.http = http;
105-
}]
99+
constructor: [
100+
Http,
101+
function(http) {
102+
this.http = http;
103+
},
104+
],
106105
});
107106

108107
var injector = di.ReflectiveInjector.resolveAndCreate([Http, Service]);
@@ -119,4 +118,3 @@ For full documentation check Angular DI docs:
119118
# License
120119

121120
MIT
122-

demo/index-es6.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ class Service {
1515
const injector = ReflectiveInjector.resolveAndCreate([Http, Service]);
1616

1717
console.log(injector.get(Service) instanceof Service);
18-

demo/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ require('reflect-metadata');
22
var di = require('../dist/injection.bundle');
33

44
var Http = di.Class({
5-
constructor: function () {}
5+
constructor: function() {},
66
});
77

88
var Service = di.Class({
9-
constructor: [Http, function (http) {
10-
this.http = http;
11-
}]
9+
constructor: [
10+
Http,
11+
function(http) {
12+
this.http = http;
13+
},
14+
],
1215
});
1316

1417
var injector = di.ReflectiveInjector.resolveAndCreate([Http, Service]);
1518

1619
console.log(injector.get(Service) instanceof Service);
17-

lib/facade/errors.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const ERROR_DEBUG_CONTEXT = 'ngDebugContext';
1313
export const ERROR_ORIGINAL_ERROR = 'ngOriginalError';
1414
export const ERROR_LOGGER = 'ngErrorLogger';
1515

16-
1716
export function getType(error: Error): Function {
1817
return (error as any)[ERROR_TYPE];
1918
}
@@ -35,8 +34,7 @@ export function getErrorLogger(error: Error): (console: Console, ...values: any[
3534
}
3635

3736
export function wrappedError(message: string, originalError: any): Error {
38-
const msg =
39-
`${message} caused by: ${originalError instanceof Error ? originalError.message: originalError }`;
37+
const msg = `${message} caused by: ${originalError instanceof Error ? originalError.message : originalError}`;
4038
const error = Error(msg);
4139
(error as any)[ERROR_ORIGINAL_ERROR] = originalError;
4240
return error;

lib/facade/lang.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface BrowserNodeGlobal {
1515
Date: DateConstructor;
1616
RegExp: RegExpConstructor;
1717
JSON: typeof JSON;
18-
Math: any; // typeof Math;
18+
Math: any; // typeof Math;
1919
assert(condition: any): void;
2020
Reflect: any;
2121
getAngularTestability: Function;
@@ -52,7 +52,7 @@ if (typeof window === 'undefined') {
5252
// exports the original value of the symbol.
5353
const _global: BrowserNodeGlobal = globalScope;
5454

55-
export {_global as global};
55+
export { _global as global };
5656

5757
export function isPresent(obj: any): boolean {
5858
return obj != null;
@@ -83,11 +83,11 @@ export function stringify(token: any): string {
8383
export abstract class DebugContext {
8484
// We don't really need this
8585
// abstract get view(): ViewData;
86-
abstract get nodeIndex(): number|null;
86+
abstract get nodeIndex(): number | null;
8787
abstract get injector(): Injector;
8888
abstract get component(): any;
8989
abstract get providerTokens(): any[];
90-
abstract get references(): {[key: string]: any};
90+
abstract get references(): { [key: string]: any };
9191
abstract get context(): any;
9292
abstract get componentRenderElement(): any;
9393
abstract get renderNode(): any;

lib/facade/type.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ export function isType(v: any): v is Type<any> {
2222
return typeof v === 'function';
2323
}
2424

25-
export interface Type<T> extends Function { new (...args: any[]): T; }
25+
export interface Type<T> extends Function {
26+
new (...args: any[]): T;
27+
}

lib/forward_ref.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {stringify} from './facade/lang';
10-
import {Type} from './facade/type';
11-
9+
import { stringify } from './facade/lang';
10+
import { Type } from './facade/type';
1211

1312
/**
1413
* An interface that a function passed into {@link forwardRef} has to implement.
@@ -18,7 +17,9 @@ import {Type} from './facade/type';
1817
* {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref_fn'}
1918
* @experimental
2019
*/
21-
export interface ForwardRefFn { (): any; }
20+
export interface ForwardRefFn {
21+
(): any;
22+
}
2223

2324
/**
2425
* Allows to refer to references which are not yet defined.
@@ -34,8 +35,10 @@ export interface ForwardRefFn { (): any; }
3435
*/
3536
export function forwardRef(forwardRefFn: ForwardRefFn): Type<any> {
3637
(<any>forwardRefFn).__forward_ref__ = forwardRef;
37-
(<any>forwardRefFn).toString = function() { return stringify(this()); };
38-
return (<Type<any>><any>forwardRefFn);
38+
(<any>forwardRefFn).toString = function() {
39+
return stringify(this());
40+
};
41+
return <Type<any>>(<any>forwardRefFn);
3942
}
4043

4144
/**
@@ -51,8 +54,7 @@ export function forwardRef(forwardRefFn: ForwardRefFn): Type<any> {
5154
* @experimental
5255
*/
5356
export function resolveForwardRef(type: any): any {
54-
if (typeof type === 'function' && type.hasOwnProperty('__forward_ref__') &&
55-
type.__forward_ref__ === forwardRef) {
57+
if (typeof type === 'function' && type.hasOwnProperty('__forward_ref__') && type.__forward_ref__ === forwardRef) {
5658
return (<ForwardRefFn>type)();
5759
} else {
5860
return type;

lib/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
export * from './metadata';
1616

17-
export {forwardRef, resolveForwardRef, ForwardRefFn} from './forward_ref';
17+
export { forwardRef, resolveForwardRef, ForwardRefFn } from './forward_ref';
1818

19-
export {Injector} from './injector';
20-
export {ReflectiveInjector} from './reflective_injector';
21-
export {Provider, TypeProvider, ValueProvider, ClassProvider, ExistingProvider, FactoryProvider} from './provider';
22-
export {ResolvedReflectiveFactory, ResolvedReflectiveProvider} from './reflective_provider';
23-
export {ReflectiveKey} from './reflective_key';
24-
export {InjectionToken, OpaqueToken} from './injection_token';
25-
export {Class, TypeDecorator, makeDecorator} from './util/decorators';
26-
export {Type} from './facade/type';
19+
export { Injector } from './injector';
20+
export { ReflectiveInjector } from './reflective_injector';
21+
export { Provider, TypeProvider, ValueProvider, ClassProvider, ExistingProvider, FactoryProvider } from './provider';
22+
export { ResolvedReflectiveFactory, ResolvedReflectiveProvider } from './reflective_provider';
23+
export { ReflectiveKey } from './reflective_key';
24+
export { InjectionToken, OpaqueToken } from './injection_token';
25+
export { Class, TypeDecorator, makeDecorator } from './util/decorators';
26+
export { Type } from './facade/type';

lib/injection_token.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
export class OpaqueToken {
3333
constructor(protected _desc: string) {}
3434

35-
toString(): string { return `Token ${this._desc}`; }
35+
toString(): string {
36+
return `Token ${this._desc}`;
37+
}
3638
}
3739

3840
/**
@@ -61,7 +63,11 @@ export class InjectionToken<T> extends OpaqueToken {
6163
// This unused property is needed here so that TS can differentiate InjectionToken from
6264
// OpaqueToken since otherwise they would have the same shape and be treated as equivalent.
6365
private _differentiate_from_OpaqueToken_structurally: any;
64-
constructor(desc: string) { super(desc); }
66+
constructor(desc: string) {
67+
super(desc);
68+
}
6569

66-
toString(): string { return `InjectionToken ${this._desc}`; }
70+
toString(): string {
71+
return `InjectionToken ${this._desc}`;
72+
}
6773
}

lib/injector.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {stringify} from './facade/lang';
10-
import {Type} from './facade/type';
9+
import { stringify } from './facade/lang';
10+
import { Type } from './facade/type';
1111

12-
import {InjectionToken} from './injection_token';
12+
import { InjectionToken } from './injection_token';
1313

1414
const _THROW_IF_NOT_FOUND = new Object();
1515
export const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
1616

17+
// tslint:disable-next-line:class-name no-use-before-declare
1718
class _NullInjector implements Injector {
1819
get(token: any, notFoundValue: any = _THROW_IF_NOT_FOUND): any {
1920
if (notFoundValue === _THROW_IF_NOT_FOUND) {
@@ -54,7 +55,7 @@ export abstract class Injector {
5455
* Injector.THROW_IF_NOT_FOUND is given
5556
* - Returns the `notFoundValue` otherwise
5657
*/
57-
abstract get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T): T;
58+
abstract get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T): T;
5859
/**
5960
* @deprecated from v4.0.0 use Type<T> or InjectionToken<T>
6061
* @suppress {duplicate}

lib/metadata.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {makeDecorator, makeParamDecorator} from './util/decorators';
10-
9+
import { makeDecorator, makeParamDecorator } from './util/decorators';
1110

1211
/**
1312
* Type of the Inject decorator / constructor function.
@@ -50,7 +49,9 @@ export interface InjectDecorator {
5049
*
5150
* @stable
5251
*/
53-
export interface Inject { token: any; }
52+
export interface Inject {
53+
token: any;
54+
}
5455

5556
/**
5657
* Inject decorator and metadata.
@@ -60,7 +61,6 @@ export interface Inject { token: any; }
6061
*/
6162
export const Inject: InjectDecorator = makeParamDecorator('Inject', [['token', undefined]]);
6263

63-
6464
/**
6565
* Type of the Optional decorator / constructor function.
6666
*
@@ -197,7 +197,6 @@ export interface Self {}
197197
*/
198198
export const Self: SelfDecorator = makeParamDecorator('Self', []);
199199

200-
201200
/**
202201
* Type of the SkipSelf decorator / constructor function.
203202
*

lib/provider.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Type} from './facade/type';
9+
import { Type } from './facade/type';
1010

1111
/**
1212
* @whatItDoes Configures the {@link Injector} to return an instance of `Type` when `Type' is used
@@ -216,5 +216,4 @@ export interface FactoryProvider {
216216
*
217217
* @stable
218218
*/
219-
export type Provider =
220-
TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider | any[];
219+
export type Provider = TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider | any[];

lib/reflection/platform_reflection_capabilities.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Type} from '../facade/type';
10-
import {GetterFn, MethodFn, SetterFn} from './types';
9+
import { Type } from '../facade/type';
10+
import { GetterFn, MethodFn, SetterFn } from './types';
1111

1212
export interface PlatformReflectionCapabilities {
1313
isReflectionEnabled(): boolean;
1414
factory(type: Type<any>): Function;
1515
hasLifecycleHook(type: any, lcProperty: string): boolean;
1616
parameters(type: Type<any>): any[][];
1717
annotations(type: Type<any>): any[];
18-
propMetadata(typeOrFunc: Type<any>): {[key: string]: any[]};
18+
propMetadata(typeOrFunc: Type<any>): { [key: string]: any[] };
1919
getter(name: string): GetterFn;
2020
setter(name: string): SetterFn;
2121
method(name: string): MethodFn;
2222
importUri(type: Type<any>): string;
2323
resourceUri(type: Type<any>): string;
24-
resolveIdentifier(name: string, moduleUrl: string, members: string[]|null, runtime: any): any;
24+
resolveIdentifier(name: string, moduleUrl: string, members: string[] | null, runtime: any): any;
2525
resolveEnum(enumIdentifier: any, name: string): any;
2626
}

lib/reflection/reflection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ReflectionCapabilities} from './reflection_capabilities';
10-
import {Reflector} from './reflector';
9+
import { ReflectionCapabilities } from './reflection_capabilities';
10+
import { Reflector } from './reflector';
1111

12-
export {Reflector} from './reflector';
12+
export { Reflector } from './reflector';
1313

1414
/**
1515
* The {@link Reflector} used internally in Angular to access metadata

0 commit comments

Comments
 (0)