Skip to content

Commit

Permalink
fix: make ng build pass
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed Apr 12, 2018
1 parent 8db6908 commit eca45fc
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 65 deletions.
5 changes: 4 additions & 1 deletion ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"deleteDestPath": false,
"whitelistedNonPeerDependencies": ["moment"],
"lib": {
"entryFile": "src/index.ts"
"entryFile": "src/index.ts",
"umdModuleIds": {
"moment": "moment"
}
}
}
6 changes: 4 additions & 2 deletions src/add.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */

import {Pipe, ChangeDetectorRef, PipeTransform} from '@angular/core';
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';

const momentConstructor = moment;

@Pipe({ name: 'amAdd' })
export class AddPipe implements PipeTransform {
transform(value: any, amount: moment.DurationInputArg1, unit?: moment.DurationInputArg2): any {
if (typeof amount === 'undefined' || (typeof amount === 'number' && typeof unit === 'undefined')) {
throw new Error('AddPipe: missing required arguments');
}
return moment(value).add(amount, unit);
return momentConstructor(value).add(amount, unit);
}
}
3 changes: 1 addition & 2 deletions src/calendar.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Pipe, ChangeDetectorRef, PipeTransform, EventEmitter, OnDestroy, NgZone
import * as moment from 'moment';
import { Subscription } from 'rxjs';

// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;
const momentConstructor = moment;

@Pipe({ name: 'amCalendar', pure: false })
export class CalendarPipe implements PipeTransform, OnDestroy {
Expand Down
5 changes: 2 additions & 3 deletions src/date-format.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */

import {Pipe, ChangeDetectorRef, PipeTransform} from '@angular/core';
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';

// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;
const momentConstructor = moment;

@Pipe({ name: 'amDateFormat' })
export class DateFormatPipe implements PipeTransform {
Expand Down
1 change: 0 additions & 1 deletion src/difference.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {DifferencePipe} from './difference.pipe';
import * as moment from 'moment';

describe('DifferencePipe', () => {
let pipe: DifferencePipe;
Expand Down
5 changes: 2 additions & 3 deletions src/difference.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */

import {Pipe, ChangeDetectorRef, PipeTransform} from '@angular/core';
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';

// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;
const momentConstructor = moment;

@Pipe({ name: 'amDifference' })
export class DifferencePipe implements PipeTransform {
Expand Down
2 changes: 1 addition & 1 deletion src/from-unix.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */

import {Pipe, ChangeDetectorRef, PipeTransform} from '@angular/core';
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';

@Pipe({ name: 'amFromUnix' })
Expand Down
5 changes: 2 additions & 3 deletions src/local.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';

// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;
const momentConstructor = moment;

@Pipe({ name: 'amLocal' })
export class LocalTimePipe implements PipeTransform {
transform(value: Date | moment.Moment | string | number): moment.Moment {
return moment(value).local();
return momentConstructor(value).local();
}
}
4 changes: 2 additions & 2 deletions src/locale.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';

// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;
const momentConstructor = moment;

@Pipe({ name: 'amLocale' })
export class LocalePipe implements PipeTransform {
transform(value: string, locale: string): moment.Moment {
return moment(value).locale(locale);
return momentConstructor(value).locale(locale);
}
}
5 changes: 2 additions & 3 deletions src/parse.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';

// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;
const momentConstructor = moment;

@Pipe({ name: 'amParse' })
export class ParsePipe implements PipeTransform {
transform(value: string, format: string): moment.Moment {
return moment(value, format);
return momentConstructor(value, format);
}
}
6 changes: 4 additions & 2 deletions src/subtract.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */

import {Pipe, ChangeDetectorRef, PipeTransform} from '@angular/core';
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';

const momentConstructor = moment;

@Pipe({ name: 'amSubtract' })
export class SubtractPipe implements PipeTransform {
transform(value: any, amount: moment.DurationInputArg1, unit?: moment.DurationInputArg2): any {
if (typeof amount === 'undefined' || (typeof amount === 'number' && typeof unit === 'undefined')) {
throw new Error('SubtractPipe: missing required arguments');
}
return moment(value).subtract(amount, unit);
return momentConstructor(value).subtract(amount, unit);
}
}
3 changes: 0 additions & 3 deletions src/time-ago.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import 'moment/min/locales';

declare var global: any;

// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;

class NgZoneMock {
runOutsideAngular(fn: Function) {
return fn();
Expand Down
3 changes: 1 addition & 2 deletions src/time-ago.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import {Pipe, ChangeDetectorRef, PipeTransform, OnDestroy, NgZone} from '@angular/core';
import * as moment from 'moment';

// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;
const momentConstructor = moment;

@Pipe({name: 'amTimeAgo', pure: false})
export class TimeAgoPipe implements PipeTransform, OnDestroy {
Expand Down
5 changes: 2 additions & 3 deletions src/utc.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';

// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;
const momentConstructor = moment;

@Pipe({ name: 'amUtc' })
export class UtcPipe implements PipeTransform {
transform(value: Date | moment.Moment | string | number): moment.Moment {
return moment(value).utc();
return momentConstructor(value).utc();
}
}
41 changes: 7 additions & 34 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": "2.0.3",
"compilerOptions": {
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"lib": [
Expand All @@ -10,41 +9,15 @@
],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"sourceMap": true,
"inlineSources": true,
"declaration": true
},
"files": [
"src/add.pipe.ts",
"src/add.pipe.spec.ts",
"src/calendar.pipe.ts",
"src/calendar.pipe.spec.ts",
"src/date-format.pipe.ts",
"src/date-format.pipe.spec.ts",
"src/difference.pipe.ts",
"src/difference.pipe.spec.ts",
"src/duration.pipe.ts",
"src/duration.pipe.spec.ts",
"src/from-unix.pipe.ts",
"src/from-unix.pipe.spec.ts",
"src/index.ts",
"src/parse.pipe.ts",
"src/parse.pipe.spec.ts",
"src/moment.module.ts",
"src/subtract.pipe.ts",
"src/subtract.pipe.spec.ts",
"src/time-ago.pipe.ts",
"src/time-ago.pipe.spec.ts",
"src/utc.pipe.ts",
"src/utc.pipe.spec.ts",
"src/from-utc.pipe.ts",
"src/from-utc.pipe.spec.ts",
"src/local.pipe.ts",
"src/local.pipe.spec.ts",
"src/locale.pipe.ts",
"src/locale.pipe.spec.ts"
],
"angularCompilerOptions": {
"genDir": "compiled"
}
"include": [
"src/*.ts"
]
}

0 comments on commit eca45fc

Please sign in to comment.