Skip to content

Commit 62c1039

Browse files
authored
"moduleResolution": "nodenext" (#187)
* Configuration changes * Add .js extension to all imports * Fix rollup config * Fix mistake * Switch from Jest to Vitest for ESM compatibility * tweak * Bump version to 3.3.0
1 parent b258aa1 commit 62c1039

22 files changed

+597
-1365
lines changed

.config/jest.config.cjs

-12
This file was deleted.

.eslintrc.cjs

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ module.exports = {
66
'airbnb',
77
'airbnb-typescript',
88
'airbnb/hooks',
9-
'plugin:jest/recommended',
10-
'plugin:jest-dom/recommended',
119
'plugin:testing-library/react',
1210
'plugin:@typescript-eslint/recommended',
1311
'plugin:@typescript-eslint/recommended-requiring-type-checking',
1412
'prettier',
1513
],
16-
plugins: ['@typescript-eslint', 'jest', 'jest-dom', 'testing-library'],
14+
plugins: ['@typescript-eslint', 'testing-library'],
1715
ignorePatterns: ['*.js', '*.cjs', 'dist/', 'vite.config.ts'],
1816
settings: {
1917
'testing-library/custom-renders': 'off',

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
- name: Test
1919
run: yarn test
2020
- name: Lint
21-
run: yarn run lint
21+
run: yarn lint

CHANGELOG.md

+18-26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 3.3.0
2+
3+
### Features
4+
5+
- The library is now compatible with TypeScript's `"moduleResolution": "nodenext"` compiler option. (#187)
6+
17
## 3.2.1
28

39
### Bug Fixes
@@ -12,8 +18,7 @@
1218

1319
### Features
1420

15-
- The skeleton animation no longer plays for users who have enabled the
16-
`prefers-reduced-motion` accessibility setting.
21+
- The skeleton animation no longer plays for users who have enabled the `prefers-reduced-motion` accessibility setting.
1722

1823
### Thanks!
1924

@@ -23,8 +28,7 @@
2328

2429
### Chores
2530

26-
- Add the `'use client'` directive to make the library compatible with React
27-
Server Components and Next.js 13. (#162)
31+
- Add the `'use client'` directive to make the library compatible with React Server Components and Next.js 13. (#162)
2832

2933
### Thanks!
3034

@@ -34,8 +38,7 @@
3438

3539
### Features
3640

37-
- If `count` is set to a decimal number like 3.5, the component will display 3
38-
full-width skeletons followed by 1 half-width skeleton. (#136)
41+
- If `count` is set to a decimal number like 3.5, the component will display 3 full-width skeletons followed by 1 half-width skeleton. (#136)
3942

4043
## 3.0.3
4144

@@ -53,10 +56,7 @@
5356

5457
- Fix explicitly setting a `Skeleton` prop to undefined, like `<Skeleton highlightColor={undefined}>`, blocking style options from the `SkeletonTheme`
5558
(#128)
56-
- If you were relying on this behavior to block values from the
57-
`SkeletonTheme`, you can render a nested `SkeletonTheme` to override a
58-
theme defined higher up in the component tree, OR explicitly set one or
59-
more `Skeleton` props back to their default values e.g. `<Skeleton baseColor="#ebebeb" />`
59+
- If you were relying on this behavior to block values from the `SkeletonTheme`, you can render a nested `SkeletonTheme` to override a theme defined higher up in the component tree, OR explicitly set one or more `Skeleton` props back to their default values e.g. `<Skeleton baseColor="#ebebeb" />`
6060

6161
## 3.0.1
6262

@@ -81,21 +81,17 @@
8181
### Breaking Changes
8282

8383
- Drop Emotion dependency, add CSS file that must be imported
84-
- Dropping Emotion avoids conflicts when multiple Emotion versions are used
85-
on one page and reduces bundle size
84+
- Dropping Emotion avoids conflicts when multiple Emotion versions are used on one page and reduces bundle size
8685
- Reimplement `SkeletonTheme` using React context
87-
- The old `SkeletonTheme` rendered a `<div>` which was undesirable in many
88-
cases. The new `SkeletonTheme` does not render any DOM elements.
89-
- The old `SkeletonTheme` did not work if the `Skeleton` was rendered in a
90-
portal. The new `SkeletonTheme` does work in this case.
86+
- The old `SkeletonTheme` rendered a `<div>` which was undesirable in many cases. The new `SkeletonTheme` does not render any DOM elements.
87+
- The old `SkeletonTheme` did not work if the `Skeleton` was rendered in a portal. The new `SkeletonTheme` does work in this case.
9188
- `SkeletonTheme`: rename the `color` prop to `baseColor`
9289
- Convert to TypeScript
9390
- Publish code as ES2018 to reduce bundle size
9491
- Require React >= 16.8.0
9592
- Drop Internet Explorer support
9693

97-
If you need to support Internet Explorer or use an old version of React, please
98-
continue to use `react-loading-skeleton` v2.
94+
If you need to support Internet Explorer or use an old version of React, please continue to use `react-loading-skeleton` v2.
9995

10096
### Features
10197

@@ -111,15 +107,11 @@ continue to use `react-loading-skeleton` v2.
111107
### Other Changes
112108

113109
- Optimize animation performance:
114-
- The old animation animated the `background-position` property which made
115-
the browser repaint the gradient on every frame.
116-
- The new animation animates the `transform` of a pseudoelement. This
117-
avoids repaints and results in an observable decrease in CPU usage.
118-
- No longer require `width` and `height` to be set for the `circle` prop to
119-
work
110+
- The old animation animated the `background-position` property which made the browser repaint the gradient on every frame.
111+
- The new animation animates the `transform` of a pseudoelement. This avoids repaints and results in an observable decrease in CPU usage.
112+
- No longer require `width` and `height` to be set for the `circle` prop to work
120113
- Change the default `duration` from 1.2 s to 1.5 s
121-
- Make the default `Skeleton` base color a _tiny_ bit darker so that the
122-
animation is more visible
114+
- Make the default `Skeleton` base color a _tiny_ bit darker so that the animation is more visible
123115

124116
### Bug Fixes
125117

package.json

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-loading-skeleton",
3-
"version": "3.2.1",
3+
"version": "3.3.0",
44
"description": "Make beautiful, animated loading skeletons that automatically adapt to your app.",
55
"keywords": [
66
"react",
@@ -18,22 +18,31 @@
1818
"sideEffects": [
1919
"**/*.css"
2020
],
21+
"type": "module",
22+
"exports": {
23+
".": {
24+
"types": "./dist/index.d.ts",
25+
"require": "./dist/index.cjs",
26+
"import": "./dist/index.js"
27+
},
28+
"./dist/skeleton.css": "./dist/skeleton.css"
29+
},
2130
"main": "dist/index.js",
2231
"module": "dist/index.mjs",
2332
"types": "dist/index.d.ts",
2433
"files": [
2534
"dist/"
2635
],
2736
"scripts": {
28-
"build": "yarn clean && tsc && rollup -c .config/rollup.config.mjs",
37+
"build": "yarn clean && tsc && rollup -c",
2938
"clean": "rimraf dist",
3039
"lint": "eslint .",
3140
"lint-staged": "lint-staged --no-stash",
3241
"prepack": "yarn run build",
3342
"prettier-all": "prettier . --write",
3443
"setup": "husky install",
3544
"storybook": "storybook dev -p 8080",
36-
"test": "jest --config .config/jest.config.cjs"
45+
"test": "vitest"
3746
},
3847
"lint-staged": {
3948
"src/**/*.ts?(x)": [
@@ -53,11 +62,11 @@
5362
"@storybook/react": "^7.0.7",
5463
"@storybook/react-vite": "^7.0.7",
5564
"@swc/core": "^1.3.56",
56-
"@swc/jest": "^0.2.26",
5765
"@testing-library/jest-dom": "^5.16.5",
5866
"@testing-library/react": "^12.1.5",
5967
"@types/react": "^18.2.0",
6068
"@types/react-dom": "^18.2.1",
69+
"@types/testing-library__jest-dom": "^5.14.5",
6170
"@typescript-eslint/eslint-plugin": "^5.59.1",
6271
"@typescript-eslint/parser": "^5.59.1",
6372
"@vitejs/plugin-react-swc": "^3.3.0",
@@ -66,15 +75,12 @@
6675
"eslint-config-airbnb-typescript": "^17.0.0",
6776
"eslint-config-prettier": "^8.8.0",
6877
"eslint-plugin-import": "^2.27.5",
69-
"eslint-plugin-jest": "^27.2.1",
70-
"eslint-plugin-jest-dom": "^4.0.3",
7178
"eslint-plugin-jsx-a11y": "^6.7.1",
7279
"eslint-plugin-react": "^7.32.2",
7380
"eslint-plugin-react-hooks": "^4.6.0",
7481
"eslint-plugin-testing-library": "^5.10.3",
7582
"husky": "^8.0.3",
76-
"jest": "^29.5.0",
77-
"jest-environment-jsdom": "^29.5.0",
83+
"jsdom": "^21.1.1",
7884
"lint-staged": "^13.2.2",
7985
"prettier": "^2.8.8",
8086
"prettier-plugin-packagejson": "^2.4.3",
@@ -88,7 +94,8 @@
8894
"tslib": "^2.5.0",
8995
"typescript": "^5.0.4",
9096
"vite": "^4.3.3",
91-
"vite-plugin-checker": "^0.5.6"
97+
"vite-plugin-checker": "^0.5.6",
98+
"vitest": "^0.30.1"
9299
},
93100
"peerDependencies": {
94101
"react": ">=16.8.0"

.config/rollup.config.mjs rollup.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
external: ['react'],
77
output: [
88
{
9-
file: 'dist/index.mjs',
9+
dir: 'dist',
1010
format: 'es',
1111

1212
// This disables the warning "Mixing named and default exports"
@@ -51,7 +51,7 @@ export default {
5151
banner: "'use client';",
5252
},
5353
{
54-
dir: 'dist',
54+
file: 'dist/index.cjs',
5555
format: 'cjs',
5656
exports: 'named',
5757
banner: "'use client';",

src/Skeleton.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable react/no-array-index-key */
22
import React, { CSSProperties, PropsWithChildren, ReactElement } from 'react';
3-
import { SkeletonThemeContext } from './SkeletonThemeContext';
4-
import { SkeletonStyleProps } from './SkeletonStyleProps';
3+
import { SkeletonThemeContext } from './SkeletonThemeContext.js';
4+
import { SkeletonStyleProps } from './SkeletonStyleProps.js';
55

66
const defaultEnableAnimation = true;
77

src/SkeletonTheme.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { ReactElement, PropsWithChildren } from 'react';
2-
import { SkeletonStyleProps } from './SkeletonStyleProps';
3-
import { SkeletonThemeContext } from './SkeletonThemeContext';
2+
import { SkeletonStyleProps } from './SkeletonStyleProps.js';
3+
import { SkeletonThemeContext } from './SkeletonThemeContext.js';
44

55
export type SkeletonThemeProps = PropsWithChildren<SkeletonStyleProps>;
66

src/SkeletonThemeContext.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { SkeletonStyleProps } from './SkeletonStyleProps';
2+
import { SkeletonStyleProps } from './SkeletonStyleProps.js';
33

44
/**
55
* @internal

src/__stories__/Post.stories.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22
import { Meta } from '@storybook/react';
3-
import { SideBySide, Post } from './components';
3+
import { SideBySide, Post } from './components/index.js';
44

55
export default {
66
component: Post,
77
title: 'Post',
8-
} as Meta;
8+
} satisfies Meta;
99

1010
export const Default: React.FC = () => (
1111
<SideBySide>

src/__stories__/Skeleton.stories.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import React, {
77
} from 'react';
88
import ReactDOM from 'react-dom';
99
import { Meta } from '@storybook/react';
10-
import { SideBySide, Box } from './components';
11-
import { Skeleton } from '../Skeleton';
10+
import { SideBySide, Box } from './components/index.js';
11+
import { Skeleton } from '../Skeleton.js';
1212
import './styles/Skeleton.stories.css';
1313

1414
export default {
1515
component: Skeleton,
1616
title: 'Skeleton',
17-
} as Meta;
17+
} satisfies Meta;
1818

1919
export const Basic: React.FC = () => <Skeleton count={5} width={400} />;
2020

@@ -345,32 +345,32 @@ export const ShadowDOM: React.FC = () => {
345345
background-position: calc(200px + 100%) 0;
346346
}
347347
}
348-
348+
349349
.react-loading-skeleton {
350350
/* If either color is changed, Skeleton.tsx must be updated as well */
351351
--base-color: #ebebeb;
352352
--highlight-color: #f5f5f5;
353-
353+
354354
background-color: var(--base-color);
355355
background-image: linear-gradient(
356356
90deg,
357357
var(--base-color),
358358
var(--highlight-color),
359359
var(--base-color)
360360
);
361-
361+
362362
width: 100%;
363363
background-size: 200px 100%;
364364
background-repeat: no-repeat;
365365
border-radius: 0.25rem;
366366
display: inline-block;
367367
line-height: 1;
368-
368+
369369
animation-name: react-loading-skeleton;
370370
animation-duration: 1.5s;
371371
animation-timing-function: ease-in-out;
372372
animation-iteration-count: infinite;
373-
}
373+
}
374374
`;
375375

376376
const shadowContent = (

src/__stories__/SkeletonTheme.stories.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from 'react';
22
import { Meta } from '@storybook/react';
3-
import { Post, SideBySide, Box } from './components';
4-
import { SkeletonTheme } from '../SkeletonTheme';
5-
import { Skeleton } from '../Skeleton';
3+
import { Post, SideBySide, Box } from './components/index.js';
4+
import { SkeletonTheme } from '../SkeletonTheme.js';
5+
import { Skeleton } from '../Skeleton.js';
66

77
export default {
88
component: SkeletonTheme,
99
title: 'SkeletonTheme',
10-
} as Meta;
10+
} satisfies Meta;
1111

1212
const darkBaseColor = '#333';
1313
const darkHighlightColor = '#999';

src/__stories__/components/Post.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { PropsWithChildren, ReactElement } from 'react';
2-
import { Skeleton } from '../../Skeleton';
2+
import { Skeleton } from '../../Skeleton.js';
33

44
export const postContent =
55
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' +

src/__stories__/components/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './SideBySide';
2-
export * from './Post';
3-
export * from './Box';
1+
export * from './SideBySide.js';
2+
export * from './Post.js';
3+
export * from './Box.js';

src/__tests__/Skeleton.test.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import React, { PropsWithChildren } from 'react';
2-
import { render, screen } from '@testing-library/react';
3-
import { Skeleton } from '../Skeleton';
2+
import { it, expect, afterEach } from 'vitest';
3+
import { cleanup, render, screen } from '@testing-library/react';
4+
import { Skeleton } from '../Skeleton.js';
45
import {
56
getAllSkeletons,
67
getSkeleton,
78
hasLineBreak,
89
skeletonSelector,
9-
} from './__helpers__';
10+
} from './__helpers__/index.js';
11+
12+
afterEach(cleanup);
1013

1114
it('renders a skeleton', () => {
1215
render(<Skeleton />);

src/__tests__/SkeletonTheme.test.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import '@testing-library/jest-dom';
21
import React from 'react';
32
import ReactDOM from 'react-dom';
4-
import { render, screen } from '@testing-library/react';
5-
import { SkeletonTheme } from '../SkeletonTheme';
6-
import { Skeleton } from '../Skeleton';
7-
import { getSkeleton } from './__helpers__';
3+
import { it, expect, afterEach } from 'vitest';
4+
import { cleanup, render, screen } from '@testing-library/react';
5+
import { SkeletonTheme } from '../SkeletonTheme.js';
6+
import { Skeleton } from '../Skeleton.js';
7+
import { getSkeleton } from './__helpers__/index.js';
8+
9+
afterEach(cleanup);
810

911
it('does not render anything', () => {
1012
render(

0 commit comments

Comments
 (0)