Skip to content

Commit

Permalink
fix: fix issues caused by date-fns 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Jul 18, 2024
1 parent 8651b7b commit 5cba49c
Show file tree
Hide file tree
Showing 48 changed files with 62 additions and 87 deletions.
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ module.exports = {

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
'^lodash-es$': 'lodash',
'^date-fns/esm(.*)$': 'date-fns$1'
'^lodash-es$': 'lodash'
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand Down
4 changes: 1 addition & 3 deletions scripts/post-build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const { completePath } = require('./complete-path')
})
await replaceDefine([srcDir], {
// the sequence is crucial
'\'lodash\'': '\'lodash-es\'',
'\'date-fns/(.*)\'//': '\'date-fns/esm/$1\'',
'\'date-fns\'//': '\'date-fns/esm\''
'\'lodash\'': '\'lodash-es\''
})

// complete require and import source path
Expand Down
3 changes: 1 addition & 2 deletions scripts/pre-build/pre-cjs-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const { replaceDefine, srcDir } = require('../utils')

(async () => {
await replaceDefine([srcDir], {
'\'lodash-es\'': '\'lodash\'',
'\'date-fns/esm(.*)\'': '\'date-fns$1\'//'
'\'lodash-es\'': '\'lodash\''
})
})()
2 changes: 1 addition & 1 deletion src/calendar/demos/enUS/basic.demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A basic calender.
<script lang="ts">
import { defineComponent, ref } from 'vue'
import { useMessage } from 'naive-ui'
import { addDays, isYesterday } from 'date-fns/esm'
import { addDays, isYesterday } from 'date-fns'
export default defineComponent({
setup() {
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/demos/zhCN/basic.demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script lang="ts">
import { defineComponent, ref } from 'vue'
import { useMessage } from 'naive-ui'
import { addDays, isYesterday } from 'date-fns/esm'
import { addDays, isYesterday } from 'date-fns'
export default defineComponent({
setup() {
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/src/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getYear,
startOfDay,
startOfMonth
} from 'date-fns/esm'
} from 'date-fns'
import { useMergedState } from 'vooks'
import { dateArray } from '../../date-picker/src/utils'
import { ChevronLeftIcon, ChevronRightIcon } from '../../_internal/icons'
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/tests/Calendar.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable unused-imports/no-unused-vars */
import { h } from 'vue'
import { mount } from '@vue/test-utils'
import { addMonths, format, getYear, isYesterday } from 'date-fns/esm'
import { addMonths, format, getYear, isYesterday } from 'date-fns'
import { NCalendar } from '../index'
import { NButton } from '../../button'

Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/demos/enUS/disabled-time.demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<script lang="ts">
import { defineComponent } from 'vue'
import { startOfDay } from 'date-fns/esm'
import { startOfDay } from 'date-fns'
const d = 86400000
const h = 3600000
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/demos/zhCN/disabled-time.demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<script lang="ts">
import { defineComponent } from 'vue'
import { startOfDay } from 'date-fns/esm'
import { startOfDay } from 'date-fns'
const d = 86400000
const h = 3600000
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from 'vue'
import { type FollowerPlacement, VBinder, VFollower, VTarget } from 'vueuc'
import { clickoutside } from 'vdirs'
import { format, getTime, isValid } from 'date-fns/esm'
import { format, getTime, isValid } from 'date-fns'
import { useIsMounted, useMergedState } from 'vooks'
import { getPreciseEventTarget, happensIn } from 'seemly'
import type { Size as TimePickerSize } from '../../time-picker/src/interface'
Expand Down
4 changes: 2 additions & 2 deletions src/date-picker/src/panel/use-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
startOfSecond,
startOfWeek,
startOfYear
} from 'date-fns/esm'
} from 'date-fns'
import type { VirtualListInst } from 'vueuc'
import type { ScrollbarInst } from '../../../_internal'
import {
Expand Down Expand Up @@ -99,7 +99,7 @@ function useCalendar(
)
const calendarValueRef = ref(
props.value === null || Array.isArray(props.value)
? props.defaultCalendarStartTime ?? Date.now()
? (props.defaultCalendarStartTime ?? Date.now())
: props.value
)
const yearVlRef = ref<VirtualListInst | null>(null)
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/src/panel/use-dual-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
startOfMonth,
startOfQuarter,
startOfSecond
} from 'date-fns/esm'
} from 'date-fns'
import type { VirtualListInst } from 'vueuc'
import {
type DateItem,
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
parse,
startOfMonth,
startOfYear
} from 'date-fns/esm'
} from 'date-fns'
import type { NDateLocale } from '../../locales'
import { START_YEAR } from './config'
import type { FirstDayOfWeek, Value } from './interface'
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/src/validation-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Ref, computed } from 'vue'
import { getHours, getMinutes, getSeconds } from 'date-fns/esm'
import { getHours, getMinutes, getSeconds } from 'date-fns'
import type { DatePickerSetupProps } from './DatePicker'
import type {
IsRangeDateDisabled,
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/tests/DatePicker.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ref } from 'vue'
import { mount } from '@vue/test-utils'
import { format } from 'date-fns/esm'
import { format } from 'date-fns'
import { NDatePicker } from '../index'
import type { Value } from '../src/interface'
import { dateEnUS } from '../../locales'
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/arDZ.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import arDZ from 'date-fns/esm/locale/ar'
import { arDZ } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateArDZ: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/azAZ.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import az from 'date-fns/esm/locale/az'
import { az } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateAzAZ: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/csCZ.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cs from 'date-fns/esm/locale/cs'
import { cs } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateCsCZ: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/deDE.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import de from 'date-fns/esm/locale/de'
import { de } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateDeDE: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/enGB.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import enGB from 'date-fns/esm/locale/en-GB'
import { enGB } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateEnGB: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/enUS.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import enUS from 'date-fns/esm/locale/en-US'
import { enUS } from 'date-fns/locale'
import type { Locale } from 'date-fns'

interface NDateLocale {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/eo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import eo from 'date-fns/esm/locale/eo'
import { eo } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateEo: NDateLocale = {
Expand Down
4 changes: 2 additions & 2 deletions src/locales/date/esAR.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import esAR from 'date-fns/esm/locale/es'
import { es } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateEsAR: NDateLocale = {
name: 'es-AR',
locale: esAR
locale: es
}

export default dateEsAR
2 changes: 1 addition & 1 deletion src/locales/date/etEE.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import et from 'date-fns/esm/locale/et'
import { et } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateEtEE: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/faIR.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import faIR from 'date-fns/esm/locale/zh-CN'
import { faIR } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateFaIR: NDateLocale = {
Expand Down
4 changes: 2 additions & 2 deletions src/locales/date/frFR.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import frFR from 'date-fns/esm/locale/fr'
import { fr } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateFrFR: NDateLocale = {
name: 'fr-FR',
locale: frFR
locale: fr
}

export default dateFrFR
4 changes: 2 additions & 2 deletions src/locales/date/idID.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import idID from 'date-fns/esm/locale/id'
import { id } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateIdID: NDateLocale = {
name: 'id-ID',
locale: idID
locale: id
}

export default dateIdID
4 changes: 2 additions & 2 deletions src/locales/date/itIT.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import itIT from 'date-fns/esm/locale/it'
import { it } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateItIT: NDateLocale = {
name: 'it-IT',
locale: itIT
locale: it
}

export default dateItIT
2 changes: 1 addition & 1 deletion src/locales/date/jaJP.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ja from 'date-fns/esm/locale/ja'
import { ja } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateJaJP: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/koKR.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ko from 'date-fns/esm/locale/ko'
import { ko } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateKoKR: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/nbNO.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nb from 'date-fns/esm/locale/nb'
import { nb } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateNbNO: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/nlNL.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nl from 'date-fns/esm/locale/nl'
import { nl } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateNlNL: NDateLocale = {
Expand Down
4 changes: 2 additions & 2 deletions src/locales/date/plPL.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import plPL from 'date-fns/esm/locale/pl'
import { pl } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const datePlPL: NDateLocale = {
name: 'pl-PL',
locale: plPL
locale: pl
}

export default datePlPL
2 changes: 1 addition & 1 deletion src/locales/date/ptBR.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ptBR from 'date-fns/esm/locale/pt-BR'
import { ptBR } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const datePtBr: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/ruRU.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ru from 'date-fns/esm/locale/ru'
import { ru } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateRuRU: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/skSK.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sk from 'date-fns/esm/locale/sk'
import { sk } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateSkSK: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/svSE.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sv from 'date-fns/esm/locale/sv'
import { sv } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateSvSE: NDateLocale = {
Expand Down
6 changes: 3 additions & 3 deletions src/locales/date/thTH.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import thTH from 'date-fns/esm/locale/th'
import { th } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateThTH: NDateLocale = {
name: 'thTH',
locale: thTH
name: 'th-TH',
locale: th
}

export default dateThTH
6 changes: 3 additions & 3 deletions src/locales/date/trTR.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import trTR from 'date-fns/esm/locale/tr'
import { tr } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateTrTR: NDateLocale = {
name: 'zh-CN',
locale: trTR
name: 'tr-TR',
locale: tr
}

export default dateTrTR
2 changes: 1 addition & 1 deletion src/locales/date/ukUA.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import uk from 'date-fns/esm/locale/uk'
import { uk } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateUkUA: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/uzUZ.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import uz from 'date-fns/esm/locale/uz'
import { uz } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateUzUZ: NDateLocale = {
Expand Down
4 changes: 2 additions & 2 deletions src/locales/date/viVN.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import viVN from 'date-fns/esm/locale/vi'
import { vi } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateVi: NDateLocale = {
name: 'vi-VN',
locale: viVN
locale: vi
}

export default dateVi
2 changes: 1 addition & 1 deletion src/locales/date/zhCN.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import zhCN from 'date-fns/esm/locale/zh-CN'
import { zhCN } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const dateZhCN: NDateLocale = {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/date/zhTW.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import zhTW from 'date-fns/esm/locale/zh-TW'
import { zhTW } from 'date-fns/locale'
import type { NDateLocale } from './enUS'

const datezhTW: NDateLocale = {
Expand Down
4 changes: 2 additions & 2 deletions src/time-picker/src/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import {
startOfHour,
startOfMinute,
startOfSecond
} from 'date-fns/esm'
import formatInTimeZone from 'date-fns-tz/formatInTimeZone'
} from 'date-fns'
import { formatInTimeZone } from 'date-fns-tz'
import type { Locale } from 'date-fns'
import type { FormValidationStatus } from '../../form/src/interface'
import { strictParse } from '../../date-picker/src/utils'
Expand Down
2 changes: 1 addition & 1 deletion src/time-picker/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getHours } from 'date-fns/esm'
import { getHours } from 'date-fns'
import { type MaybeArray, throwError } from '../../_utils'

export const time = {
Expand Down
4 changes: 2 additions & 2 deletions src/time/src/Time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
defineComponent,
h
} from 'vue'
import { format, formatDistanceStrict, fromUnixTime } from 'date-fns/esm'
import { format, formatDistanceStrict, fromUnixTime } from 'date-fns'
import type { Locale } from 'date-fns'
import formatInTimeZone from 'date-fns-tz/formatInTimeZone'
import { formatInTimeZone } from 'date-fns-tz'
import { useLocale } from '../../_mixins'
import type { ExtractPublicPropTypes } from '../../_utils'

Expand Down
Loading

0 comments on commit 5cba49c

Please sign in to comment.