fix: fix issues caused by date-fns 3.0

This commit is contained in:
07akioni 2024-07-18 23:32:28 +08:00
parent 8651b7b402
commit 5cba49c9ad
48 changed files with 62 additions and 87 deletions

View File

@ -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

View File

@ -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

View File

@ -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\''
})
})()

View File

@ -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() {

View File

@ -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() {

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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 {
@ -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)

View File

@ -12,7 +12,7 @@ import {
startOfMonth,
startOfQuarter,
startOfSecond
} from 'date-fns/esm'
} from 'date-fns'
import type { VirtualListInst } from 'vueuc'
import {
type DateItem,

View File

@ -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'

View File

@ -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,

View File

@ -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'

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 {

View File

@ -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 = {

View File

@ -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

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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

View File

@ -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

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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'

View File

@ -1,4 +1,4 @@
import { getHours } from 'date-fns/esm'
import { getHours } from 'date-fns'
import { type MaybeArray, throwError } from '../../_utils'
export const time = {

View File

@ -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'

View File

@ -34,7 +34,7 @@ module.exports = {
'@css-render/plugin-bem',
'async-validator',
'css-render',
'date-fns/esm',
'date-fns',
'date-fns-tz/getTimezoneOffset',
'evtd',
'highlight.js',
@ -57,28 +57,7 @@ module.exports = {
'highlight.js/lib/languages/xml',
'@vicons/ionicons5',
'@vicons/ionicons4',
'@vicons/fluent/Compose16Regular.js',
'date-fns/esm/locale/nb',
'date-fns/esm/locale/fr',
'date-fns/esm/locale/id',
'date-fns/esm/locale/de',
'date-fns/esm/locale/ja',
'date-fns/esm/locale/zh-CN',
'date-fns/esm/locale/en-US',
'date-fns/esm/locale/ru',
'date-fns/esm/locale/uk',
'date-fns/esm/locale/zh-TW',
'date-fns/esm/locale/es',
'date-fns/esm/locale/it',
'date-fns/esm/locale/en-GB',
'date-fns/esm/locale/pl',
'date-fns/esm/locale/eo',
'date-fns/esm/locale/sk',
'date-fns/esm/locale/pt-BR',
'date-fns/esm/locale/th',
'date-fns/esm/locale/ko',
'date-fns/esm/locale/nl',
'date-fns/esm/locale/ar'
'@vicons/fluent/Compose16Regular.js'
],
exclude: ['__INDEX__']
},