Skip to content

Commit 48e9a92

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent 6fa6615 commit 48e9a92

5 files changed

Lines changed: 1709 additions & 943 deletions

File tree

eslint.config.js

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
13
import tsParser from '@typescript-eslint/parser';
24
import tsPlugin from '@typescript-eslint/eslint-plugin';
35
import reactHooksPlugin from 'eslint-plugin-react-hooks';
46

7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
59
export default [
610
{
7-
files: ['**/*.{js,jsx,ts,tsx}'],
811
ignores: [
912
'dist/**',
1013
'prettier.config.cjs',
1114
'lint-staged.config.cjs',
1215
'commitlint.config.cjs'
13-
],
16+
]
17+
},
18+
{
19+
files: ['**/*.{ts,tsx}'],
1420
languageOptions: {
1521
parser: tsParser,
1622
parserOptions: {
@@ -20,7 +26,7 @@ export default [
2026
},
2127
ecmaVersion: 'latest',
2228
sourceType: 'module',
23-
tsconfigRootDir: '.',
29+
tsconfigRootDir: __dirname,
2430
project: ['./tsconfig.json']
2531
}
2632
},
@@ -31,15 +37,32 @@ export default [
3137
rules: {
3238
'linebreak-style': 'off',
3339
'@typescript-eslint/no-explicit-any': 'warn',
34-
'@typescript-eslint/ban-types': [
35-
'error',
36-
{
37-
extendDefaults: true,
38-
types: {
39-
'{}': false
40-
}
41-
}
42-
],
40+
'react-hooks/rules-of-hooks': 'error',
41+
'react-hooks/exhaustive-deps': 'warn',
42+
'object-shorthand': 'error',
43+
'no-console': ['warn', { allow: ['warn', 'error', 'info'] }]
44+
}
45+
},
46+
{
47+
files: ['**/*.{js,jsx}'],
48+
languageOptions: {
49+
parser: tsParser,
50+
parserOptions: {
51+
ecmaFeatures: {
52+
jsx: true,
53+
modules: true
54+
},
55+
ecmaVersion: 'latest',
56+
sourceType: 'module'
57+
}
58+
},
59+
plugins: {
60+
'@typescript-eslint': tsPlugin,
61+
'react-hooks': reactHooksPlugin
62+
},
63+
rules: {
64+
'linebreak-style': 'off',
65+
'@typescript-eslint/no-explicit-any': 'warn',
4366
'react-hooks/rules-of-hooks': 'error',
4467
'react-hooks/exhaustive-deps': 'warn',
4568
'object-shorthand': 'error',

package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@
55
},
66
"description": "Enhance your React apps with advanced scroll detection using @smakss/react-scroll-direction. This powerful hook not only detects scroll direction but also provides scroll position information. Ideal for React, Remix, Next.js, and Gatsby projects, it comes with adjustable sensitivity and supports ES Modules.",
77
"devDependencies": {
8-
"@commitlint/cli": "^19.3.0",
9-
"@commitlint/config-conventional": "^19.2.2",
10-
"@rollup/plugin-node-resolve": "^15.2.3",
11-
"@rollup/plugin-typescript": "^11.1.6",
12-
"@types/react": "^18.3.3",
13-
"@typescript-eslint/eslint-plugin": "^7.17.0",
14-
"@typescript-eslint/parser": "^7.17.0",
15-
"eslint": "^9.8.0",
16-
"eslint-config-prettier": "^9.1.0",
17-
"eslint-plugin-prettier": "^5.2.1",
18-
"eslint-plugin-react-hooks": "^4.6.2",
19-
"husky": "^9.1.3",
20-
"lint-staged": "^15.2.7",
21-
"prettier": "^3.3.3",
22-
"rollup": "^4.19.1",
23-
"typescript": "^5.5.4"
8+
"@commitlint/cli": "^20.4.0",
9+
"@commitlint/config-conventional": "^20.4.0",
10+
"@types/react": "^19.2.10",
11+
"@typescript-eslint/eslint-plugin": "^8.54.0",
12+
"@typescript-eslint/parser": "^8.54.0",
13+
"eslint": "^9.39.2",
14+
"eslint-config-prettier": "^10.1.8",
15+
"eslint-plugin-prettier": "^5.5.5",
16+
"eslint-plugin-react-hooks": "^7.0.1",
17+
"husky": "^9.1.7",
18+
"lint-staged": "^16.2.7",
19+
"prettier": "^3.8.1",
20+
"typescript": "^5.9.3",
21+
"vite": "^6.3.6",
22+
"vite-plugin-dts": "^4.5.4"
2423
},
2524
"engines": {
2625
"node": ">=18.0.0"
@@ -59,7 +58,7 @@
5958
"react scroll direction and position"
6059
],
6160
"license": "MIT",
62-
"main": "dist/es/index.js",
61+
"main": "dist/index.js",
6362
"name": "@smakss/react-scroll-direction",
6463
"peerDependencies": {
6564
"react": ">=16.8.0"
@@ -71,7 +70,8 @@
7170
"scripts": {
7271
"format": "prettier --write \"**/*.+(js|jsx|json|yml|yaml|css|ts|tsx|md|gql|graphql|mdx)\"",
7372
"format:check": "prettier -l \"**/*.+(js|jsx|json|yml|yaml|css|ts|tsx|md|gql|graphql|mdx)\"",
74-
"generate": "rollup -c",
73+
"build": "vite build",
74+
"generate": "vite build",
7575
"lint": "npx eslint --cache --cache-location ./node_modules/.cache/.eslintcache --max-warnings=0 .",
7676
"lint:fix": "npx eslint --fix .",
7777
"setup": "yarn && husky install",

rollup.config.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

vite.config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineConfig } from 'vite';
2+
import dts from 'vite-plugin-dts';
3+
import packageJson from './package.json' assert { type: 'json' };
4+
5+
export default defineConfig({
6+
build: {
7+
lib: {
8+
entry: 'src/index.ts',
9+
formats: ['es'],
10+
fileName: () => 'index.js'
11+
},
12+
sourcemap: true,
13+
rollupOptions: {
14+
external: [
15+
...Object.keys(packageJson.peerDependencies || {}),
16+
'react/jsx-runtime'
17+
]
18+
}
19+
},
20+
plugins: [
21+
dts({
22+
entryRoot: 'src',
23+
outDir: 'dist'
24+
})
25+
]
26+
});

0 commit comments

Comments
 (0)