From c1a6f636c998007b1b23bc754e57c882b6b55ee6 Mon Sep 17 00:00:00 2001 From: Andrei Zhaleznichenka Date: Fri, 31 Jan 2025 14:37:10 +0100 Subject: [PATCH] fix: Fixes date-fns imports (#3240) --- .eslintrc.js | 5 +++++ src/calendar/__tests__/calendar.test.tsx | 13 ++++++------- src/internal/utils/date-time/calendar.ts | 7 +------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 990a49ba31..6f833fb293 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -187,6 +187,11 @@ module.exports = { message: '`react-virtual` gets shipped as a bundled dependency. Use `src/internal/vendor/react-virtual` as import source.', }, + { + group: ['date-fns/*'], + message: + "Disallowed import '{{ path }}'. These imports are not allowed because are not specified as package exports in date-fns package.json.", + }, ], }, ], diff --git a/src/calendar/__tests__/calendar.test.tsx b/src/calendar/__tests__/calendar.test.tsx index 5811f4e159..54c8650c15 100644 --- a/src/calendar/__tests__/calendar.test.tsx +++ b/src/calendar/__tests__/calendar.test.tsx @@ -49,14 +49,13 @@ test('check a11y', async () => { await expect(container).toValidateA11y(); }); -const eachMonthOfTheYear = range(0, 11).map(month => addMonths(new Date('2025-01-01'), month).toISOString().split('T')[0]); -test.each(eachMonthOfTheYear)( - 'always renders 42 days, value=%s', - value => { - renderCalendar({ value }); - expect(document.querySelectorAll(`.${styles['calendar-date']}`)).toHaveLength(42); - } +const eachMonthOfTheYear = range(0, 11).map( + month => addMonths(new Date('2025-01-01'), month).toISOString().split('T')[0] ); +test.each(eachMonthOfTheYear)('always renders 42 days, value=%s', value => { + renderCalendar({ value }); + expect(document.querySelectorAll(`.${styles['calendar-date']}`)).toHaveLength(42); +}); describe('Calendar locale US', () => { beforeEach(() => { diff --git a/src/internal/utils/date-time/calendar.ts b/src/internal/utils/date-time/calendar.ts index 70df1ef59b..3f623ae442 100644 --- a/src/internal/utils/date-time/calendar.ts +++ b/src/internal/utils/date-time/calendar.ts @@ -1,12 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import addMonths from 'date-fns/addMonths'; -import isAfter from 'date-fns/isAfter'; -import isBefore from 'date-fns/isBefore'; -import isSameDay from 'date-fns/isSameDay'; -import isSameMonth from 'date-fns/isSameMonth'; -import subMonths from 'date-fns/subMonths'; +import { addMonths, isAfter, isBefore, isSameDay, isSameMonth, subMonths } from 'date-fns'; import { getCalendarMonth } from 'mnth'; import { DayIndex } from '../locale';