From 743778e757da66ff41dc8d6b046903cedf3987dd Mon Sep 17 00:00:00 2001 From: Ou Date: Thu, 31 Oct 2024 01:12:44 +0800 Subject: [PATCH] chore: switch to unimport --- .gitignore | 3 +- auto-imports.app.d.ts | 95 ---------------------------------- eslint.config.mjs | 3 +- package.json | 2 +- pnpm-lock.yaml | 32 ++---------- src/components/column/card.tsx | 1 + src/components/header/menu.tsx | 2 +- src/utils/index.ts | 1 - tsconfig.app.json | 2 +- vite.config.ts | 19 ++++--- vitest.config.ts | 22 ++++---- 11 files changed, 32 insertions(+), 150 deletions(-) delete mode 100644 auto-imports.app.d.ts diff --git a/.gitignore b/.gitignore index 6fcaab9..902fa91 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ dist/ .env.* dev-dist *.tsbuildinfo -wrangler.toml \ No newline at end of file +wrangler.toml +imports.app.d.ts \ No newline at end of file diff --git a/auto-imports.app.d.ts b/auto-imports.app.d.ts deleted file mode 100644 index dae6ffe..0000000 --- a/auto-imports.app.d.ts +++ /dev/null @@ -1,95 +0,0 @@ -/* eslint-disable */ -/* prettier-ignore */ -// @ts-nocheck -// noinspection JSUnusedGlobalSymbols -// Generated by unplugin-auto-import -// biome-ignore lint: disable -export {} -declare global { - const $: typeof import('clsx')['default'] - const Author: typeof import('./shared/consts')['Author'] - const Homepage: typeof import('./shared/consts')['Homepage'] - const Interval: typeof import('./shared/consts')['Interval'] - const TTL: typeof import('./shared/consts')['TTL'] - const Timer: typeof import('./src/utils/index')['Timer'] - const Version: typeof import('./shared/consts')['Version'] - const atom: typeof import('jotai')['atom'] - const atomFamily: typeof import('jotai/utils')['atomFamily'] - const atomWithDefault: typeof import('jotai/utils')['atomWithDefault'] - const atomWithHash: typeof import('jotai/utils')['atomWithHash'] - const atomWithObservable: typeof import('jotai/utils')['atomWithObservable'] - const atomWithReducer: typeof import('jotai/utils')['atomWithReducer'] - const atomWithReset: typeof import('jotai/utils')['atomWithReset'] - const atomWithStorage: typeof import('jotai/utils')['atomWithStorage'] - const columns: typeof import('./shared/metadata')['columns'] - const createJSONStorage: typeof import('jotai/utils')['createJSONStorage'] - const createRef: typeof import('react')['createRef'] - const currentColumnIDAtom: typeof import('./src/atoms/index')['currentColumnIDAtom'] - const currentSourcesAtom: typeof import('./src/atoms/index')['currentSourcesAtom'] - const delay: typeof import('./shared/utils')['delay'] - const downloadMetadata: typeof import('./src/hooks/useSync')['downloadMetadata'] - const fixedColumnIds: typeof import('./shared/metadata')['fixedColumnIds'] - const focusSourcesAtom: typeof import('./src/atoms/index')['focusSourcesAtom'] - const forwardRef: typeof import('react')['forwardRef'] - const freezeAtom: typeof import('jotai/utils')['freezeAtom'] - const freezeAtomCreator: typeof import('jotai/utils')['freezeAtomCreator'] - const goToTopAtom: typeof import('./src/atoms/index')['goToTopAtom'] - const hiddenColumns: typeof import('./shared/metadata')['hiddenColumns'] - const lazy: typeof import('react')['lazy'] - const loadable: typeof import('jotai/utils')['loadable'] - const memo: typeof import('react')['memo'] - const metadata: typeof import('./shared/metadata')['metadata'] - const myFetch: typeof import('./src/utils/index')['myFetch'] - const originSources: typeof import('./shared/sources')['originSources'] - const preprocessMetadata: typeof import('./src/atoms/primitiveMetadataAtom')['preprocessMetadata'] - const primitiveMetadataAtom: typeof import('./src/atoms/primitiveMetadataAtom')['primitiveMetadataAtom'] - const projectDir: typeof import('./shared/dir')['projectDir'] - const randomItem: typeof import('./shared/utils')['randomItem'] - const randomUUID: typeof import('./shared/utils')['randomUUID'] - const refetchSourcesAtom: typeof import('./src/atoms/index')['refetchSourcesAtom'] - const relativeTime: typeof import('./shared/utils')['relativeTime'] - const safeParseString: typeof import('./src/utils/index')['safeParseString'] - const selectAtom: typeof import('jotai/utils')['selectAtom'] - const sources: typeof import('./shared/sources')['sources'] - const splitAtom: typeof import('jotai/utils')['splitAtom'] - const startTransition: typeof import('react')['startTransition'] - const toastAtom: typeof import('./src/hooks/useToast')['toastAtom'] - const typeSafeObjectEntries: typeof import('./shared/type.util')['typeSafeObjectEntries'] - const typeSafeObjectFromEntries: typeof import('./shared/type.util')['typeSafeObjectFromEntries'] - const typeSafeObjectValues: typeof import('./shared/type.util')['typeSafeObjectValues'] - const uploadMetadata: typeof import('./src/hooks/useSync')['uploadMetadata'] - const useAtom: typeof import('jotai')['useAtom'] - const useAtomCallback: typeof import('jotai/utils')['useAtomCallback'] - const useAtomValue: typeof import('jotai')['useAtomValue'] - const useCallback: typeof import('react')['useCallback'] - const useContext: typeof import('react')['useContext'] - const useDark: typeof import('./src/hooks/useDark')['useDark'] - const useDebugValue: typeof import('react')['useDebugValue'] - const useDeferredValue: typeof import('react')['useDeferredValue'] - const useEffect: typeof import('react')['useEffect'] - const useFocus: typeof import('./src/hooks/useFocus')['useFocus'] - const useFocusWith: typeof import('./src/hooks/useFocus')['useFocusWith'] - const useHydrateAtoms: typeof import('jotai/utils')['useHydrateAtoms'] - const useId: typeof import('react')['useId'] - const useImperativeHandle: typeof import('react')['useImperativeHandle'] - const useInsertionEffect: typeof import('react')['useInsertionEffect'] - const useLayoutEffect: typeof import('react')['useLayoutEffect'] - const useLogin: typeof import('./src/hooks/useLogin')['useLogin'] - const useMemo: typeof import('react')['useMemo'] - const useOnReload: typeof import('./src/hooks/useOnReload')['useOnReload'] - const usePWA: typeof import('./src/hooks/usePWA')['usePWA'] - const useReducer: typeof import('react')['useReducer'] - const useReducerAtom: typeof import('jotai/utils')['useReducerAtom'] - const useRef: typeof import('react')['useRef'] - const useRelativeTime: typeof import('./src/hooks/useRelativeTime')['useRelativeTime'] - const useResetAtom: typeof import('jotai/utils')['useResetAtom'] - const useSearchBar: typeof import('./src/hooks/useSearch')['useSearchBar'] - const useSetAtom: typeof import('jotai')['useSetAtom'] - const useState: typeof import('react')['useState'] - const useSync: typeof import('./src/hooks/useSync')['useSync'] - const useSyncExternalStore: typeof import('react')['useSyncExternalStore'] - const useToast: typeof import('./src/hooks/useToast')['useToast'] - const useTransition: typeof import('react')['useTransition'] - const verifyPrimitiveMetadata: typeof import('./shared/verify')['verifyPrimitiveMetadata'] - const waitForAll: typeof import('jotai/utils')['waitForAll'] -} diff --git a/eslint.config.mjs b/eslint.config.mjs index c6524cb..5081bc2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -2,7 +2,8 @@ import { ourongxing, react } from "@ourongxing/eslint-config" export default ourongxing({ type: "app", - ignores: ["**/routeTree.gen.ts"], + // 貌似不能 ./ 开头, + ignores: ["src/routeTree.gen.ts", "imports.app.d.ts"], }).append(react({ files: ["src/**"], })) diff --git a/package.json b/package.json index 7bba661..97b2623 100644 --- a/package.json +++ b/package.json @@ -88,8 +88,8 @@ "tsx": "^4.19.1", "typescript": "^5.6.3", "typescript-eslint": "^8.8.1", + "unimport": "^3.13.1", "unocss": "^0.63.4", - "unplugin-auto-import": "^0.18.3", "vite": "^5.4.8", "vite-plugin-pwa": "^0.20.5", "vite-plugin-with-nitro": "0.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0c69781..3934d50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -201,12 +201,12 @@ importers: typescript-eslint: specifier: ^8.8.1 version: 8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3) + unimport: + specifier: ^3.13.1 + version: 3.13.1(rollup@4.24.0) unocss: specifier: ^0.63.4 version: 0.63.6(postcss@8.4.47)(rollup@4.24.0)(typescript@5.6.3)(vite@5.4.10(@types/node@22.7.9)(terser@5.36.0)) - unplugin-auto-import: - specifier: ^0.18.3 - version: 0.18.3(rollup@4.24.0) vite: specifier: ^5.4.8 version: 5.4.10(@types/node@22.7.9)(terser@5.36.0) @@ -5811,18 +5811,6 @@ packages: vite: optional: true - unplugin-auto-import@0.18.3: - resolution: {integrity: sha512-q3FUtGQjYA2e+kb1WumyiQMjHM27MrTQ05QfVwtLRVhyYe+KF6TblBYaEX9L6Z0EibsqaXAiW+RFfkcQpfaXzg==} - engines: {node: '>=14'} - peerDependencies: - '@nuxt/kit': ^3.2.2 - '@vueuse/core': '*' - peerDependenciesMeta: - '@nuxt/kit': - optional: true - '@vueuse/core': - optional: true - unplugin@1.14.1: resolution: {integrity: sha512-lBlHbfSFPToDYp9pjXlUEFVxYLaue9f9T1HC+4OHlmj+HnMDdz9oZY+erXfoCe/5V/7gKUSY2jpXPb9S7f0f/w==} engines: {node: '>=14.0.0'} @@ -12354,20 +12342,6 @@ snapshots: - supports-color - typescript - unplugin-auto-import@0.18.3(rollup@4.24.0): - dependencies: - '@antfu/utils': 0.7.10 - '@rollup/pluginutils': 5.1.3(rollup@4.24.0) - fast-glob: 3.3.2 - local-pkg: 0.5.0 - magic-string: 0.30.12 - minimatch: 9.0.5 - unimport: 3.13.1(rollup@4.24.0) - unplugin: 1.14.1 - transitivePeerDependencies: - - rollup - - webpack-sources - unplugin@1.14.1: dependencies: acorn: 8.13.0 diff --git a/src/components/column/card.tsx b/src/components/column/card.tsx index 1bf9baf..804411b 100644 --- a/src/components/column/card.tsx +++ b/src/components/column/card.tsx @@ -3,6 +3,7 @@ import { useQuery } from "@tanstack/react-query" import { AnimatePresence, motion, useInView } from "framer-motion" import type { SyntheticListenerMap } from "@dnd-kit/core/dist/hooks/utilities" import { useWindowSize } from "react-use" +import { forwardRef, useImperativeHandle } from "react" import { OverlayScrollbar } from "../common/overlay-scrollbar" import { refetchSourcesAtom } from "~/atoms" import { safeParseString } from "~/utils" diff --git a/src/components/header/menu.tsx b/src/components/header/menu.tsx index e93b03d..b969338 100644 --- a/src/components/header/menu.tsx +++ b/src/components/header/menu.tsx @@ -80,7 +80,7 @@ export function Menu() { href="https://github.com/ourongxing/newsnow" > GitHub forks badge diff --git a/src/utils/index.ts b/src/utils/index.ts index 1983f71..1eb1040 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,4 @@ import type { MaybePromise } from "@shared/type.util" - import { $fetch } from "ofetch" export function safeParseString(str: any) { diff --git a/tsconfig.app.json b/tsconfig.app.json index 7c7d3bf..42e6c2a 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -9,5 +9,5 @@ "@shared/*": ["shared/*"] } }, - "include": ["src", "shared", "./auto-imports.app.d.ts"] + "include": ["src", "shared", "imports.app.d.ts"] } diff --git a/vite.config.ts b/vite.config.ts index 3c4baf8..5379d58 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,7 +5,7 @@ import react from "@vitejs/plugin-react-swc" import { TanStackRouterVite } from "@tanstack/router-plugin/vite" import unocss from "unocss/vite" import dotenv from "dotenv" -import autoImport from "unplugin-auto-import/vite" +import unimport from "unimport/unplugin" import nitro from "./nitro.config" import { projectDir } from "./shared/dir" import pwa from "./pwa.config" @@ -30,17 +30,20 @@ export default defineConfig({ }, plugins: [ TanStackRouterVite({ - // error with unplugin-auto-import and vite-plugin-pwa + // error with auto import and vite-plugin-pwa // autoCodeSplitting: true, }), - autoImport({ + unimport.vite({ dirs: ["src/hooks", "shared", "src/utils", "src/atoms"], - imports: ["react", "jotai", "jotai/utils", { - clsx: [ - ["default", "$"], - ], + presets: ["react", { + from: "jotai", + imports: ["atom", "useAtom", "useAtomValue", "useSetAtom"], }], - dts: "auto-imports.app.d.ts", + imports: [ + { from: "clsx", name: "default", as: "$" }, + { from: "jotai/utils", name: "atomWithStorage" }, + ], + dts: "imports.app.d.ts", }), unocss(), react(), diff --git a/vitest.config.ts b/vitest.config.ts index 7ac3450..d3dc6de 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,13 +1,8 @@ import { join } from "node:path" import { defineConfig } from "vitest/config" -import autoImport from "unplugin-auto-import/vite" -import { resolveModuleExportNames } from "mlly" +import unimport from "unimport/unplugin" import { projectDir } from "./shared/dir" -const h3Exports = await resolveModuleExportNames("h3", { - url: import.meta.url, -}) - export default defineConfig({ test: { globals: true, @@ -22,13 +17,16 @@ export default defineConfig({ }, plugins: [ // https://github.com/unjs/nitro/blob/v2/src/core/config/resolvers/imports.ts - autoImport({ - imports: [{ - from: "h3", - imports: h3Exports.filter(n => !/^[A-Z]/.test(n) && n !== "use"), - }], + unimport.vite({ + imports: [], + presets: [ + { + package: "h3", + ignore: [/^[A-Z]/, r => r === "use"], + }, + ], dirs: ["server/utils", "shared"], - dts: false, + // dts: false, }), ], })