Skip to content

Commit

Permalink
fix(core): change moment/lodash imports so it works with ES6 module (#…
Browse files Browse the repository at this point in the history
…210)

- ES6 wants us to use `import moment` but in TypeScript it asks for `import * as moment`, if we do `const moment = moment_['default'] || moment_;` we will get either/or, whichever works first and that works on both side of the fence
  • Loading branch information
ghiscoding authored Dec 22, 2020
1 parent 6816696 commit 2d25d3b
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/editors/dateEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as moment_ from 'moment-mini';
import { BaseOptions as FlatpickrBaseOptions } from 'flatpickr/dist/types/options';
import { FlatpickrFn } from 'flatpickr/dist/types/instance';
const flatpickr: FlatpickrFn = _flatpickr as any; // patch for rollup
const moment = moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670
const moment = moment_['default'] || moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670

import { Constants } from './../constants';
import { FieldType } from '../enums/index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { mapMomentDateFormatWithFieldType } from './../services/utilities';
import { testFilterCondition } from './filterUtilities';
import * as moment_ from 'moment-mini';

const moment = moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670
const moment = moment_['default'] || moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670

export const executeMappedCondition: FilterCondition = (options: FilterConditionOption) => {
// when using a multi-select ('IN' operator) we will not use the field type but instead go directly with a collection search
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/dateRangeFilter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as flatpickr from 'flatpickr';
import * as moment_ from 'moment-mini';
const moment = moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670
const moment = moment_['default'] || moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670

import {
FieldType,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/formatters/formatterUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FieldType } from '../enums/fieldType.enum';
import { Column, Formatter, GridOption, SlickGrid } from '../interfaces/index';
import { mapMomentDateFormatWithFieldType } from '../services/utilities';
import * as moment_ from 'moment-mini';
const moment = moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670
const moment = moment_['default'] || moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670

/**
* Find the option value from the following (in order of execution)
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/services/filter.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as isequal_ from 'lodash.isequal';
const isequal = isequal_; // patch to fix rollup to work
const isequal = isequal_['default'] || isequal_; // patch to fix rollup to work

import { FilterConditions } from './../filter-conditions/index';
import { FilterFactory } from './../filters/filterFactory';
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/services/gridState.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as isequal_ from 'lodash.isequal';
const isequal = isequal_; // patch to fix rollup to work
const isequal = isequal_['default'] || isequal_; // patch to fix rollup to work

import {
ExtensionName,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/services/pagination.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as isequal_ from 'lodash.isequal';
const isequal = isequal_; // patch to fix rollup to work
const isequal = isequal_['default'] || isequal_; // patch to fix rollup to work

import {
BackendServiceApi,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/services/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as DOMPurify_ from 'dompurify';
import * as moment_ from 'moment-mini';
const DOMPurify = DOMPurify_; // patch to fix rollup to work
const moment = moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670
const moment = moment_['default'] || moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670

import { FieldType, OperatorString, OperatorType } from '../enums/index';
import { GridOption } from '../interfaces/index';
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/sortComparers/dateUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mapMomentDateFormatWithFieldType } from '../services/utilities';
import { FieldType } from '../enums/fieldType.enum';
import { Column, GridOption, SortComparer } from '../interfaces/index';
import * as moment_ from 'moment-mini';
const moment = moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670
const moment = moment_['default'] || moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670

export function compareDates(value1: any, value2: any, sortDirection: number, sortColumn: Column, gridOptions: GridOption, format: string | moment_.MomentBuiltinFormat, strict?: boolean) {
let diff = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/excel-export/src/excelExport.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ExcelBuilder from 'excel-builder-webpacker';
import * as moment_ from 'moment-mini';
const moment = moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670
const moment = moment_['default'] || moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670

import {
// utility functions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as moment_ from 'moment-mini';
const moment = moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670
const moment = moment_['default'] || moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670

import {
Constants,
Expand Down

0 comments on commit 2d25d3b

Please sign in to comment.