Skip to content

Commit

Permalink
Compatibility fix for moment update
Browse files Browse the repository at this point in the history
Running `ng build` after updating all the packages revealed a problem
with just one: moment going from 2.24.0 => 2.25.1
```
WARNING in ./node_modules/moment/src/lib/locale/locales.js
Module not found: Error: Can't resolve './locale' in '/Users/msorens/code/go/src/github.com/chef/automate/components/automate-ui/node_modules/moment/src/lib/locale'
```

The issue was encountered by many:
moment/moment#4505 (comment)

The particular comment in the thread I linked to has a suggested workaround,
though I had to modify it to get it to work.

Using it exactly as is in that thread generated this error on every `moment` use:
```
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
```

But I found that I could retain `import *...`
instead of `import moment...` to solve
the original issue without encountering the follow-up issue.

This commit, then, makes that simple change in 57 files.
One file imported `moment` slightly differently so adjusted that as well.

Signed-off-by: michael sorens <msorens@chef.io>
  • Loading branch information
msorens committed May 3, 2020
1 parent 0d67518 commit 5a819f1
Show file tree
Hide file tree
Showing 57 changed files with 70 additions and 70 deletions.
Expand Up @@ -3,7 +3,7 @@ import { Component,
Output,
EventEmitter,
ChangeDetectionStrategy } from '@angular/core';
import * as m from 'moment';
import * as moment from 'moment/moment';
import { concat,
range,
rangeRight,
Expand All @@ -17,8 +17,8 @@ import { concat,
})
export class CalendarComponent {

private _date: m.Moment = m.utc();
private _selected: m.Moment = m.utc();
private _date: moment.Moment = moment.utc();
private _selected: moment.Moment = moment.utc();

private _month: string;
private _year: number;
Expand All @@ -34,9 +34,9 @@ export class CalendarComponent {

@Input()
set date(input) {
const date = m.isMoment(input) ? input : m.utc(input);
const date = moment.isMoment(input) ? input : moment.utc(input);
this._date = date;
this._month = m.months(date.month());
this._month = moment.months(date.month());
this._year = date.year();
}
get date() {
Expand All @@ -45,7 +45,7 @@ export class CalendarComponent {

@Input()
set selected(input) {
const date = m.isMoment(input) ? input : m.utc(input);
const date = moment.isMoment(input) ? input : moment.utc(input);
this._selected = date;
}
get selected() {
Expand All @@ -58,7 +58,7 @@ export class CalendarComponent {
this.date.month(input);
// Set the normalized internal month to its string
// representation for display.
this._month = m.months(this.date.month());
this._month = moment.months(this.date.month());
}
get month(): string {
return this._month;
Expand All @@ -79,10 +79,10 @@ export class CalendarComponent {
const vy = this.date.year();
const sm = this.selected.month();
const sy = this.selected.year();
const today = m.utc().month() === this.date.month() ? m.utc().date() : null;
const today = moment.utc().month() === this.date.month() ? moment.utc().date() : null;
const selected = (vm === sm && vy === sy) ? this.selected.date() : null;
const tag = (marker) => (d: m.Moment) => [marker, d];
const tagActive = (d: m.Moment) => {
const tag = (marker) => (d: moment.Moment) => [marker, d];
const tagActive = (d: moment.Moment) => {
switch (d.date()) {
case selected:
return tag('a s')(d);
Expand All @@ -101,13 +101,13 @@ export class CalendarComponent {
// returns the names of the weekdays in a minimal form:
// [Mo, Tu, We, Th, Fr, Sa, Su]
get weekdays(): string[] {
return m.weekdaysMin();
return moment.weekdaysMin();
}

// When the first of the month is on any day other than the first
// day of the week, we need to fill in those extra days. This
// method returns the last few days of the previous month.
private daysBefore(): m.Moment[] {
private daysBefore(): moment.Moment[] {
const lastMonth = this
.date
.clone()
Expand All @@ -125,7 +125,7 @@ export class CalendarComponent {
}

// Returns the range of dates during the month
private daysDuring(): m.Moment[] {
private daysDuring(): moment.Moment[] {
const daysInThisMonth = this
.date
.daysInMonth();
Expand All @@ -135,7 +135,7 @@ export class CalendarComponent {

// Returns the first few days of the next month to fill out
// the rest of the week.
private daysAfter(): m.Moment[] {
private daysAfter(): moment.Moment[] {
const nextMonth = this
.date
.clone()
Expand Down
@@ -1,6 +1,6 @@
import { Component, Input, OnChanges, Output, EventEmitter } from '@angular/core';
import { ApplyRulesStatus } from 'app/entities/projects/project.reducer';
import * as moment from 'moment';
import * as moment from 'moment/moment';

@Component({
selector: 'app-confirm-apply-stop-modal',
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { Injectable } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { find } from 'lodash';

import { NgrxStateAtom } from '../../ngrx.reducers';
Expand Down
@@ -1,6 +1,6 @@
import { HttpErrorResponse } from '@angular/common/http';
import { EntityStatus } from '../entities';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { DateTime } from '../../helpers/datetime/datetime';

// Example JSON returned from gateway:
Expand Down
Expand Up @@ -3,7 +3,7 @@ import { Store } from '@ngrx/store';
import { HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { includes } from 'lodash/fp';
import * as moment from 'moment';
import * as moment from 'moment/moment';

import { EntityStatus } from '../../entities/entities';
import { TelemetryService } from 'app/services/telemetry/telemetry.service';
Expand Down
Expand Up @@ -11,7 +11,7 @@ import {
switchMap
} from 'rxjs/operators';
import { of } from 'rxjs';
import * as moment from 'moment';
import * as moment from 'moment/moment';

import { NgrxStateAtom } from 'app/ngrx.reducers';
import { IndexedEntities } from 'app/entities/entities';
Expand Down
@@ -1,5 +1,5 @@
import { HistorySelection } from './history-selection';
import * as moment from 'moment';
import * as moment from 'moment/moment';

describe('HistorySelection', () => {
it('contains the correct list of selections for the selector component', () => {
Expand Down
@@ -1,5 +1,5 @@
// TODO eng-ex discuss if this should be turned into a module
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { Injectable } from '@angular/core';

type Moment = moment.Moment;
Expand Down
@@ -1,7 +1,7 @@
import { TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { Store, StoreModule } from '@ngrx/store';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { MockComponent } from 'ng2-mock-component';
import { using } from 'app/testing/spec-helpers';
import { DateTime } from 'app/helpers/datetime/datetime';
Expand Down
@@ -1,7 +1,7 @@
import { AfterViewInit, Component, EventEmitter, Output } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Subscription } from 'rxjs';
import * as moment from 'moment';
import * as moment from 'moment/moment';

import { LicenseFacadeService, LicenseApplyReason } from 'app/entities/license/license.facade';
import { HttpStatus } from 'app/types/types';
Expand Down
Expand Up @@ -2,7 +2,7 @@ import { TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { StoreModule, Store } from '@ngrx/store';
import { MockComponent } from 'ng2-mock-component';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { of as observableOf } from 'rxjs';

import { DateTime } from 'app/helpers/datetime/datetime';
Expand Down
@@ -1,7 +1,7 @@
import { AfterViewInit, Component, EventEmitter, Output } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Subscription } from 'rxjs';
import * as moment from 'moment';
import * as moment from 'moment/moment';

import { LicenseFacadeService, LicenseApplyReason } from 'app/entities/license/license.facade';

Expand Down
Expand Up @@ -8,7 +8,7 @@ import { DateTime } from 'app/helpers/datetime/datetime';

import * as actions from '../../../entities/nodes/nodes.actions';
import * as selectors from '../../../entities/nodes/nodes.selectors';
import * as moment from 'moment';
import * as moment from 'moment/moment';


@Component({
Expand Down
Expand Up @@ -17,7 +17,7 @@ import {
RespEventCount,
GuitarStringCollection
} from '../../types/types';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { find } from 'lodash';
import { initialState } from '../../services/event-feed/event-feed.reducer';
import { ChefPipesModule } from 'app/pipes/chef-pipes.module';
Expand Down
Expand Up @@ -10,7 +10,7 @@ import {
SimpleChanges,
ViewChild
} from '@angular/core';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { reduce } from 'lodash/fp';
import * as d3 from 'd3';
import { GuitarString,
Expand Down
Expand Up @@ -9,7 +9,7 @@ import {
ChefEventCollection,
ChefEvent
} from '../../types/types';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { ChefPipesModule } from 'app/pipes/chef-pipes.module';

class MockEventFeedService {
Expand Down
Expand Up @@ -4,7 +4,7 @@ import { Subject, Observable } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import { ChefEvent, ChefEventCollection, EventFeedFilter, Chicklet } from '../../types/types';
import { EventFeedService } from '../../services/event-feed/event-feed.service';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { DateTime } from 'app/helpers/datetime/datetime';

const ENTITY_TYPE_TAG = 'event-type';
Expand Down
@@ -1,7 +1,7 @@
import { Component, Input } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { RRule } from 'rrule';
import * as moment from 'moment';
import * as moment from 'moment/moment';

@Component({
selector: 'chef-job-schedule-form',
Expand Down
Expand Up @@ -12,7 +12,7 @@ import { NodeRunsService } from '../../services/node-details/node-runs.service';
import { HistorySelection } from '../../helpers/history-selection/history-selection';
import { RunHistoryStore } from '../../services/run-history-store/run-history.store';
import { Subscription } from 'rxjs';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { saveAs } from 'file-saver';
import {
finalize
Expand Down
Expand Up @@ -3,7 +3,7 @@ import { Component, OnChanges, SimpleChange, Input, AfterContentInit,
import {
NodeDetailsService
} from '../../services/node-details/node-details.service';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { NodeRun } from '../../types/types';
import { DateTime } from 'app/helpers/datetime/datetime';

Expand Down
@@ -1,6 +1,6 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Credential } from '../credentials.state';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { DateTime } from '../../../../helpers/datetime/datetime';
import { CredentialsLogic } from '../credentials.logic';

Expand Down
Expand Up @@ -3,7 +3,7 @@ import { ActivatedRoute } from '@angular/router';
import { StatsService } from '../../shared/reporting/stats.service';
import { Subject } from 'rxjs';
import { ReportQueryService, ReturnParams } from '../../shared/reporting/report-query.service';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { DateTime } from 'app/helpers/datetime/datetime';
import { LayoutFacadeService, Sidebar } from 'app/entities/layout/layout.facade';
import { takeUntil } from 'rxjs/operators';
Expand Down
Expand Up @@ -2,7 +2,7 @@ import { takeUntil } from 'rxjs/operators';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs';
import { groupBy } from 'lodash';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { FilterC } from '../types';
import { paginationOverride } from '../shared';
import {
Expand Down
Expand Up @@ -11,7 +11,7 @@ import {
} from '@angular/core';
import { DOCUMENT } from '@angular/common';
import * as d3 from 'd3';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { DateTime } from 'app/helpers/datetime/datetime';

export interface TrendData {
Expand Down
Expand Up @@ -4,7 +4,7 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { CookieModule } from 'ngx-cookie';
import { of as observableOf } from 'rxjs';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { Router } from '@angular/router';
import { ReportingOverviewComponent } from './reporting-overview.component';
import { ChefSessionService } from 'app/services/chef-session/chef-session.service';
Expand Down
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../shared/reporting';
import { ActivatedRoute, Router } from '@angular/router';
import { union } from 'lodash/fp';
import * as moment from 'moment';
import * as moment from 'moment/moment';

type Tab = 'Node Status' | 'Profile Status';

Expand Down
Expand Up @@ -12,7 +12,7 @@ import { StatsService, ReportQueryService,
ScanResultsService, ReportQuery } from '../../shared/reporting';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { of as observableOf } from 'rxjs';
import * as moment from 'moment';
import * as moment from 'moment/moment';

describe('ReportingProfileComponent', () => {
let store: Store<NgrxStateAtom>;
Expand Down
Expand Up @@ -10,7 +10,7 @@ import { StatsService } from '../../shared/reporting/stats.service';
import { ReportQueryService, ReportQuery, ReturnParams } from '../../shared/reporting/report-query.service';
import { ScanResultsService } from '../../shared/reporting/scan-results.service';
import { paginationOverride } from '../shared';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { FilterC } from '../../+reporting/types';
import { LayoutFacadeService, Sidebar } from 'app/entities/layout/layout.facade';

Expand Down
Expand Up @@ -7,7 +7,7 @@ import { paginationOverride } from '../shared';
import { StatsService, ReportQueryService, ReportDataService,
ReportQuery } from '../../shared/reporting';
import { ChefSessionService } from '../../../../services/chef-session/chef-session.service';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
Expand Down
Expand Up @@ -2,7 +2,7 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { ReportingSearchbarComponent } from './reporting-searchbar.component';
import { using } from 'app/testing/spec-helpers';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import {
ReportQueryService
} from 'app/pages/+compliance/shared/reporting';
Expand Down
Expand Up @@ -14,7 +14,7 @@ import {
debounceTime, switchMap, distinctUntilChanged
} from 'rxjs/operators';
import { FilterC } from '../types';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { Chicklet } from 'app/types/types';
import {
ReportQueryService
Expand Down
Expand Up @@ -21,7 +21,7 @@ import {
} from '../shared/reporting';
import { TelemetryService } from '../../../services/telemetry/telemetry.service';
import { FeatureFlagsService } from 'app/services/feature-flags/feature-flags.service';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { DatetimePipe } from 'app/pipes/datetime.pipe';
import { using } from 'app/testing/spec-helpers';

Expand Down
Expand Up @@ -14,7 +14,7 @@ import {
} from '@angular/core';
import { ActivatedRoute, Router, ParamMap } from '@angular/router';
import { Subject, Observable } from 'rxjs';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import {
StatsService,
SuggestionsService,
Expand Down
Expand Up @@ -4,7 +4,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { NgrxStateAtom } from '../../../../../ngrx.reducers';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { LayoutFacadeService, Sidebar } from 'app/entities/layout/layout.facade';
import * as selectors from '../../state/scanner.selectors';
import * as actions from '../../state/scanner.actions';
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';
import { Store, StoreModule } from '@ngrx/store';
import { NgrxStateAtom, ngrxReducers, runtimeChecks } from 'app/ngrx.reducers';
import * as moment from 'moment';
import * as moment from 'moment/moment';
import { ChefSessionService } from 'app/services/chef-session/chef-session.service';
import { MockChefSessionService } from 'app/testing/mock-chef-session.service';
import { JobsListComponent } from './jobs-list.component';
Expand Down

0 comments on commit 5a819f1

Please sign in to comment.