From 7296b99a16e5c17b023b67ac6ac02c29bab32b79 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Wed, 27 Nov 2024 12:19:21 +0300 Subject: [PATCH] Fixed relative imports --- .eslintrc.js | 9 ++ .estlintignore | 3 + apps/charterafrica/eslint.config.js | 2 +- apps/civicsignalblog/eslint.config.js | 27 ++-- apps/civicsignalblog/tsconfig.json | 3 +- apps/climatemappedafrica/eslint.config.js | 2 +- apps/codeforafrica/eslint.config.js | 2 +- apps/codeforafrica/eslint.webpack.config.js | 47 +++--- apps/promisetracker/eslint.config.js | 2 +- apps/roboshield/eslint.config.js | 27 ++-- apps/vpnmanager/eslint.config.js | 20 +++ apps/vpnmanager/eslint.webpack.config.js | 30 ++++ apps/vpnmanager/package.json | 2 +- .../DesktopNavBar/DesktopNavBar.tsx | 3 +- .../components/MobileNavBar/MobileNavBar.tsx | 4 +- .../NavBarNavList/NavBarNavList.tsx | 1 + .../src/components/Statistics/Statistics.tsx | 12 +- .../src/components/UserAvatar/UserAvatar.tsx | 3 +- apps/vpnmanager/src/lib/data/database.ts | 5 +- apps/vpnmanager/src/lib/outline.ts | 6 +- apps/vpnmanager/src/lib/processUsers.ts | 8 +- apps/vpnmanager/src/lib/statistics.ts | 4 +- apps/vpnmanager/src/middleware.ts | 2 +- apps/vpnmanager/src/pages/_app.tsx | 2 +- apps/vpnmanager/src/pages/api/statistics.ts | 1 + apps/vpnmanager/src/pages/api/users.ts | 1 + apps/vpnmanager/src/pages/index.tsx | 5 +- apps/vpnmanager/src/pages/login.tsx | 5 +- apps/vpnmanager/src/utils/fetchJson.ts | 2 + apps/vpnmanager/src/utils/index.ts | 2 +- packages/eslint-config-commons-ui/index.js | 6 - .../eslint-config-commons-ui/package.json | 3 +- pnpm-lock.yaml | 139 ++++++++++++------ pnpm-workspace.yaml | 3 +- 34 files changed, 254 insertions(+), 139 deletions(-) create mode 100644 .eslintrc.js create mode 100644 .estlintignore create mode 100644 apps/vpnmanager/eslint.webpack.config.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..22a366d7d --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,9 @@ +module.exports = { + root: true, + extends: ["eslint-config-commons-ui/next"], + settings: { + next: { + rootDir: "apps/*/", + }, + }, +}; diff --git a/.estlintignore b/.estlintignore new file mode 100644 index 000000000..0a81bc3e3 --- /dev/null +++ b/.estlintignore @@ -0,0 +1,3 @@ +build +node_modules +.github diff --git a/apps/charterafrica/eslint.config.js b/apps/charterafrica/eslint.config.js index 5bd32d6f6..255f17bc4 100644 --- a/apps/charterafrica/eslint.config.js +++ b/apps/charterafrica/eslint.config.js @@ -25,7 +25,6 @@ module.exports = [ "**/public/", ], }, - ...eslintConfig, { settings: { "import/resolver": { @@ -35,4 +34,5 @@ module.exports = [ }, }, }, + ...eslintConfig, ]; diff --git a/apps/civicsignalblog/eslint.config.js b/apps/civicsignalblog/eslint.config.js index 742fe812a..23e9e9432 100644 --- a/apps/civicsignalblog/eslint.config.js +++ b/apps/civicsignalblog/eslint.config.js @@ -24,20 +24,23 @@ module.exports = [ "**/playwright-report/", ], }, - ...eslintConfig, - { - settings: { - "import/resolver": { - webpack: { - config: "./eslint.webpack.config.js", - }, - typescript: { - alwaysTryTypes: false, // we mostly have JS thus we don't need types automatically resolved - project: "./tsconfig.json", + ...eslintConfig.map((config) => { + return { + ...config, + settings: { + ...config.settings, + "import/resolver": { + webpack: { + config: "./eslint.webpack.config.js", + }, + typescript: { + alwaysTryTypes: false, + project: "./tsconfig.json", + }, }, }, - }, - }, + }; + }), { rules: { "react/jsx-filename-extension": [1, { extensions: [".js", ".tsx"] }], // This rule allows JSX syntax in both .js and tsx files diff --git a/apps/civicsignalblog/tsconfig.json b/apps/civicsignalblog/tsconfig.json index 7f5e2fa58..d76ccc173 100644 --- a/apps/civicsignalblog/tsconfig.json +++ b/apps/civicsignalblog/tsconfig.json @@ -20,7 +20,8 @@ "@/commons-ui/next/*": ["../../packages/commons-ui-next/src/*"], "@/commons-ui/payload/*": ["../../packages/commons-ui-payload/src/*"], "#civicsignalblog*": ["./src/*"] - } + }, + "target": "ES2017" }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], "exclude": ["build", "dist", "node_modules"] diff --git a/apps/climatemappedafrica/eslint.config.js b/apps/climatemappedafrica/eslint.config.js index 809505b98..93c93643b 100644 --- a/apps/climatemappedafrica/eslint.config.js +++ b/apps/climatemappedafrica/eslint.config.js @@ -24,7 +24,6 @@ module.exports = [ "**/playwright-report/", ], }, - ...eslintConfig, { settings: { "import/resolver": { @@ -34,4 +33,5 @@ module.exports = [ }, }, }, + ...eslintConfig, ]; diff --git a/apps/codeforafrica/eslint.config.js b/apps/codeforafrica/eslint.config.js index 809505b98..93c93643b 100644 --- a/apps/codeforafrica/eslint.config.js +++ b/apps/codeforafrica/eslint.config.js @@ -24,7 +24,6 @@ module.exports = [ "**/playwright-report/", ], }, - ...eslintConfig, { settings: { "import/resolver": { @@ -34,4 +33,5 @@ module.exports = [ }, }, }, + ...eslintConfig, ]; diff --git a/apps/codeforafrica/eslint.webpack.config.js b/apps/codeforafrica/eslint.webpack.config.js index 5397c40ac..c6b8a9496 100644 --- a/apps/codeforafrica/eslint.webpack.config.js +++ b/apps/codeforafrica/eslint.webpack.config.js @@ -1,25 +1,26 @@ -module.exports = [ - { - ignores: [ - "**/node_modules", - "**/.pnp", - "**/.pnp.js", - "**/.pnpm-debug.log", - "**/dist/", - "**/coverage", - "**/.next/", - "**/out/", - "**/build/", - "**/.DS_Store", - "**/*.pem", - "**/npm-debug.log*", - "**/yarn-debug.log*", - "**/yarn-error.log*", - "**/.vercel", - "**/.now", - "**/.turbo", - "**/test-results/", - "**/playwright-report/", +const path = require("path"); + +module.exports = { + module: { + rules: [ + { + test: /\.svg$/i, + type: "asset", + resourceQuery: /url/, // *.svg?url + }, + { + test: /\.svg$/i, + issuer: /\.[jt]sx?$/, + resourceQuery: { not: [/url/] }, // exclude react component if *.svg?url + use: ["@svgr/webpack"], + }, ], }, -]; + resolve: { + alias: { + "@/codeforafrica": path.resolve(__dirname, "src/"), + content: path.resolve(__dirname, "content/"), + }, + extensions: [".js"], + }, +}; diff --git a/apps/promisetracker/eslint.config.js b/apps/promisetracker/eslint.config.js index 809505b98..93c93643b 100644 --- a/apps/promisetracker/eslint.config.js +++ b/apps/promisetracker/eslint.config.js @@ -24,7 +24,6 @@ module.exports = [ "**/playwright-report/", ], }, - ...eslintConfig, { settings: { "import/resolver": { @@ -34,4 +33,5 @@ module.exports = [ }, }, }, + ...eslintConfig, ]; diff --git a/apps/roboshield/eslint.config.js b/apps/roboshield/eslint.config.js index 94bf9e453..bc5e6ec35 100644 --- a/apps/roboshield/eslint.config.js +++ b/apps/roboshield/eslint.config.js @@ -23,23 +23,19 @@ module.exports = [ "**/dist/", ], }, - ...eslintConfig.map((config) => { - return { - ...config, - settings: { - ...config.settings, - "import/resolver": { - webpack: { - config: "./eslint.webpack.config.js", - }, - typescript: { - alwaysTryTypes: false, - project: "./tsconfig.json", - }, + { + settings: { + "import/resolver": { + webpack: { + config: "./eslint.webpack.config.js", + }, + typescript: { + alwaysTryTypes: false, + project: "./tsconfig.json", }, }, - }; - }), + }, + }, { rules: { "react/jsx-filename-extension": [1, { extensions: [".js", ".tsx"] }], // This rule allows JSX syntax in both .js and tsx files @@ -54,4 +50,5 @@ module.exports = [ ], }, }, + ...eslintConfig, ]; diff --git a/apps/vpnmanager/eslint.config.js b/apps/vpnmanager/eslint.config.js index 3f3d5a15e..e4a5031dd 100644 --- a/apps/vpnmanager/eslint.config.js +++ b/apps/vpnmanager/eslint.config.js @@ -28,13 +28,33 @@ module.exports = [ ...config, settings: { ...config.settings, + "import/extensions": [".js", ".jsx", ".ts", ".tsx"], "import/resolver": { + webpack: { + config: "./eslint.webpack.config.js", + }, typescript: { alwaysTryTypes: false, project: "./tsconfig.json", }, }, + "import/parsers": { + "@typescript-eslint/parser": [".ts", ".tsx"], + }, }, }; }), + { + rules: { + "react/jsx-filename-extension": [1, { extensions: [".js", ".tsx"] }], // This rule allows JSX syntax in both .js and tsx files + "import/extensions": [ + "error", + "ignorePackages", + { + js: "never", + tsx: "never", + }, + ], + }, + }, ]; diff --git a/apps/vpnmanager/eslint.webpack.config.js b/apps/vpnmanager/eslint.webpack.config.js new file mode 100644 index 000000000..1fb392566 --- /dev/null +++ b/apps/vpnmanager/eslint.webpack.config.js @@ -0,0 +1,30 @@ +const path = require("path"); + +module.exports = { + module: { + rules: [ + { + test: /\.svg$/i, + type: "asset", + resourceQuery: /url/, // *.svg?url + }, + { + test: /\.svg$/i, + issuer: /\.[jt]sx?$/, + resourceQuery: { not: [/url/] }, // exclude react component if *.svg?url + use: ["@svgr/webpack"], + }, + ], + }, + resolve: { + alias: { + "@/vpnmanager": path.resolve(__dirname, "src/"), + content: path.resolve(__dirname, "content/"), + }, + extensions: [".js"], + }, + typescript: { + alwaysTryTypes: false, + project: "./tsconfig.json", + }, +}; diff --git a/apps/vpnmanager/package.json b/apps/vpnmanager/package.json index 671974e1a..0cc1c7e12 100644 --- a/apps/vpnmanager/package.json +++ b/apps/vpnmanager/package.json @@ -7,7 +7,7 @@ "build": "next build", "start": "next start", "lint-check": "TIMING=1 next lint './'", - "lint": "TIMING=1 next lint --fix './'", + "lint": "TIMING=1 eslint --fix './'", "clean": "rm -rf .next .turbo node_modules", "jest": "jest --passWithNoTests", "playwright": "npx playwright test" diff --git a/apps/vpnmanager/src/components/DesktopNavBar/DesktopNavBar.tsx b/apps/vpnmanager/src/components/DesktopNavBar/DesktopNavBar.tsx index c5fc49f1e..493e59e3d 100644 --- a/apps/vpnmanager/src/components/DesktopNavBar/DesktopNavBar.tsx +++ b/apps/vpnmanager/src/components/DesktopNavBar/DesktopNavBar.tsx @@ -1,6 +1,5 @@ -import React, { ForwardedRef } from "react"; - import { Box, Grid, Grid2Props, SxProps } from "@mui/material"; +import React, { ForwardedRef } from "react"; import type { Menu, diff --git a/apps/vpnmanager/src/components/MobileNavBar/MobileNavBar.tsx b/apps/vpnmanager/src/components/MobileNavBar/MobileNavBar.tsx index d894b71f9..d83812839 100644 --- a/apps/vpnmanager/src/components/MobileNavBar/MobileNavBar.tsx +++ b/apps/vpnmanager/src/components/MobileNavBar/MobileNavBar.tsx @@ -11,12 +11,12 @@ import { import { SxProps, styled } from "@mui/material/styles"; import React, { ForwardedRef } from "react"; +import menuIcon from "@/vpnmanager/assets/icons/menu-icon.svg"; +import CloseIcon from "@/vpnmanager/assets/icons/Type=x, Size=24, Color=CurrentColor.svg"; import type { Menu, SocialMediaLink, } from "@/vpnmanager/components/NavBarNavList"; -import menuIcon from "@/vpnmanager/assets/icons/menu-icon.svg"; -import CloseIcon from "@/vpnmanager/assets/icons/Type=x, Size=24, Color=CurrentColor.svg"; import NavBarNavList from "@/vpnmanager/components/NavBarNavList"; import NextImageButton from "@/vpnmanager/components/NextImageButton"; diff --git a/apps/vpnmanager/src/components/NavBarNavList/NavBarNavList.tsx b/apps/vpnmanager/src/components/NavBarNavList/NavBarNavList.tsx index ae1576878..8d6770e75 100644 --- a/apps/vpnmanager/src/components/NavBarNavList/NavBarNavList.tsx +++ b/apps/vpnmanager/src/components/NavBarNavList/NavBarNavList.tsx @@ -2,6 +2,7 @@ import { NavList, NavListItem, SocialMediaIconLink } from "@commons-ui/core"; import { Link } from "@commons-ui/next"; import type { LinkProps } from "@mui/material"; import React from "react"; + import UserAvatar from "@/vpnmanager/components/UserAvatar"; interface NavListItemProps extends LinkProps {} diff --git a/apps/vpnmanager/src/components/Statistics/Statistics.tsx b/apps/vpnmanager/src/components/Statistics/Statistics.tsx index 8bf56b1dc..1169ca07b 100644 --- a/apps/vpnmanager/src/components/Statistics/Statistics.tsx +++ b/apps/vpnmanager/src/components/Statistics/Statistics.tsx @@ -1,4 +1,5 @@ -import React, { useEffect, useRef, useState } from "react"; +import { Section } from "@commons-ui/core"; +import { Link } from "@commons-ui/next"; import { Box, Table, @@ -13,12 +14,11 @@ import { Button, TablePagination, } from "@mui/material"; -import { Section } from "@commons-ui/core"; +import { format, startOfYesterday } from "date-fns"; import { useRouter } from "next/router"; +import React, { useEffect, useRef, useState } from "react"; import { fetchJson, formatBytes } from "@/vpnmanager/utils"; -import { Link } from "@commons-ui/next"; -import { format, startOfYesterday } from "date-fns"; export interface Data { ID: number; @@ -152,7 +152,7 @@ const Statistics: React.FC = ({ data: result }) => { name="date" type="date" variant="outlined" - value={filters["date"]} + value={filters.date} onChange={handleFilterChange} placeholder="Date Start" size="small" @@ -234,7 +234,7 @@ const Statistics: React.FC = ({ data: result }) => {