Skip to content

Commit

Permalink
fix lame cjs interop problems with Typescript 4.8.4 and moduleResolut…
Browse files Browse the repository at this point in the history
…ion:node16
  • Loading branch information
arshaw committed Nov 20, 2022
1 parent 3d54a54 commit fdd89cc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
14 changes: 11 additions & 3 deletions scripts/src/pkg/utils/rollup-presets.ts
Expand Up @@ -5,9 +5,9 @@ import handlebars from 'handlebars'
import nodeResolvePlugin from '@rollup/plugin-node-resolve'
import dtsPlugin from 'rollup-plugin-dts'
import sourcemapsPlugin from 'rollup-plugin-sourcemaps'
import { default as commonjsPlugin } from '@rollup/plugin-commonjs'
import { default as jsonPlugin } from '@rollup/plugin-json'
import { default as postcssPlugin } from 'rollup-plugin-postcss'
import commonjsPluginLib from '@rollup/plugin-commonjs'
import jsonPluginLib from '@rollup/plugin-json'
import postcssPluginLib from 'rollup-plugin-postcss'
import { mapProps } from '../../utils/lang.js'
import { MonorepoStruct } from '../../utils/monorepo-struct.js'
import { analyzePkg } from '../../utils/pkg-analysis.js'
Expand Down Expand Up @@ -35,6 +35,10 @@ import {
rerootPlugin,
} from './rollup-plugins.js'

const commonjsPlugin = cjsInterop(commonjsPluginLib)
const jsonPlugin = cjsInterop(jsonPluginLib)
const postcssPlugin = cjsInterop(postcssPluginLib)

const assetExtensions = ['.css']

export function buildModuleOptions(
Expand Down Expand Up @@ -336,3 +340,7 @@ function onwarn(warning: RollupWarning) {
console.error(warning)
}
}

function cjsInterop<DefaultExport>(namespace: { default: DefaultExport }): DefaultExport {
return namespace.default || (namespace as DefaultExport)
}
5 changes: 4 additions & 1 deletion tests/src/icalendar/day-view.ts
@@ -1,4 +1,4 @@
import { default as XHRMock, once } from 'xhr-mock'
import XHRMockLib, { once } from 'xhr-mock'
import { default as timeGridPlugin } from '@fullcalendar/timegrid'
import { EventSourceInput } from '@fullcalendar/core'
import { default as iCalendarPlugin } from '@fullcalendar/icalendar'
Expand All @@ -12,6 +12,9 @@ import { default as timedMeetingWithDuration } from './data/timedMeetingWithDura
import { default as dataWithRecurrenceId } from './data/recurrenceId.js'
import { CalendarWrapper } from '../lib/wrappers/CalendarWrapper.js'
import { TimeGridViewWrapper } from '../lib/wrappers/TimeGridViewWrapper.js'
import { cjsInterop } from '../lib/cjs.js'

const XHRMock = cjsInterop(XHRMockLib)

describe('addICalEventSource with day view', () => {
const ICAL_MIME_TYPE = 'text/calendar'
Expand Down
5 changes: 4 additions & 1 deletion tests/src/icalendar/month-view.ts
@@ -1,4 +1,4 @@
import { default as XHRMock } from 'xhr-mock'
import XHRMockLib from 'xhr-mock'
import { default as dayGridMonth } from '@fullcalendar/daygrid'
import { EventSourceInput } from '@fullcalendar/core'
import { default as iCalendarPlugin } from '@fullcalendar/icalendar'
Expand All @@ -12,6 +12,9 @@ import { default as recurringWeekly } from './data/recurringWeekly.js'
import { default as recurringWeeklyWithoutEnd } from './data/recurringWeeklyWithoutEnd.js'
import { default as recurringWeeklyWithCount } from './data/recurringWeeklyWithCount.js'
import { default as mungedOneHourMeeting } from './data/mungedOneHourMeeting.js'
import { cjsInterop } from '../lib/cjs.js'

const XHRMock = cjsInterop(XHRMockLib)

describe('addICalEventSource with month view', () => {
const ICAL_MIME_TYPE = 'text/calendar'
Expand Down
5 changes: 4 additions & 1 deletion tests/src/legacy/event-feed-param.ts
@@ -1,4 +1,7 @@
import { default as XHRMock } from 'xhr-mock'
import XHRMockLib from 'xhr-mock'
import { cjsInterop } from '../lib/cjs.js'

const XHRMock = cjsInterop(XHRMockLib)

describe('event feed params', () => {
pushOptions({
Expand Down
5 changes: 4 additions & 1 deletion tests/src/legacy/events-json-feed.ts
@@ -1,6 +1,9 @@
import { default as XHRMock } from 'xhr-mock'
import XHRMockLib from 'xhr-mock'
import { cjsInterop } from '../lib/cjs.js'
import { formatIsoTimeZoneOffset } from '../lib/datelib-utils.js'

const XHRMock = cjsInterop(XHRMockLib)

describe('events as a json feed', () => {
pushOptions({
initialDate: '2014-05-01',
Expand Down
4 changes: 4 additions & 0 deletions tests/src/lib/cjs.ts
@@ -0,0 +1,4 @@

export function cjsInterop<DefaultExport>(namespace: { default: DefaultExport }): DefaultExport {
return namespace.default || (namespace as DefaultExport)
}

0 comments on commit fdd89cc

Please sign in to comment.