chore: switch to unimport

This commit is contained in:
Ou 2024-10-31 01:12:44 +08:00
parent 55709e1420
commit 743778e757
11 changed files with 32 additions and 150 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ dist/
dev-dist dev-dist
*.tsbuildinfo *.tsbuildinfo
wrangler.toml wrangler.toml
imports.app.d.ts

95
auto-imports.app.d.ts vendored
View File

@ -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']
}

View File

@ -2,7 +2,8 @@ import { ourongxing, react } from "@ourongxing/eslint-config"
export default ourongxing({ export default ourongxing({
type: "app", type: "app",
ignores: ["**/routeTree.gen.ts"], // 貌似不能 ./ 开头,
ignores: ["src/routeTree.gen.ts", "imports.app.d.ts"],
}).append(react({ }).append(react({
files: ["src/**"], files: ["src/**"],
})) }))

View File

@ -88,8 +88,8 @@
"tsx": "^4.19.1", "tsx": "^4.19.1",
"typescript": "^5.6.3", "typescript": "^5.6.3",
"typescript-eslint": "^8.8.1", "typescript-eslint": "^8.8.1",
"unimport": "^3.13.1",
"unocss": "^0.63.4", "unocss": "^0.63.4",
"unplugin-auto-import": "^0.18.3",
"vite": "^5.4.8", "vite": "^5.4.8",
"vite-plugin-pwa": "^0.20.5", "vite-plugin-pwa": "^0.20.5",
"vite-plugin-with-nitro": "0.0.3", "vite-plugin-with-nitro": "0.0.3",

32
pnpm-lock.yaml generated
View File

@ -201,12 +201,12 @@ importers:
typescript-eslint: typescript-eslint:
specifier: ^8.8.1 specifier: ^8.8.1
version: 8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3) 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: unocss:
specifier: ^0.63.4 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)) 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: vite:
specifier: ^5.4.8 specifier: ^5.4.8
version: 5.4.10(@types/node@22.7.9)(terser@5.36.0) version: 5.4.10(@types/node@22.7.9)(terser@5.36.0)
@ -5811,18 +5811,6 @@ packages:
vite: vite:
optional: true 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: unplugin@1.14.1:
resolution: {integrity: sha512-lBlHbfSFPToDYp9pjXlUEFVxYLaue9f9T1HC+4OHlmj+HnMDdz9oZY+erXfoCe/5V/7gKUSY2jpXPb9S7f0f/w==} resolution: {integrity: sha512-lBlHbfSFPToDYp9pjXlUEFVxYLaue9f9T1HC+4OHlmj+HnMDdz9oZY+erXfoCe/5V/7gKUSY2jpXPb9S7f0f/w==}
engines: {node: '>=14.0.0'} engines: {node: '>=14.0.0'}
@ -12354,20 +12342,6 @@ snapshots:
- supports-color - supports-color
- typescript - 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: unplugin@1.14.1:
dependencies: dependencies:
acorn: 8.13.0 acorn: 8.13.0

View File

@ -3,6 +3,7 @@ import { useQuery } from "@tanstack/react-query"
import { AnimatePresence, motion, useInView } from "framer-motion" import { AnimatePresence, motion, useInView } from "framer-motion"
import type { SyntheticListenerMap } from "@dnd-kit/core/dist/hooks/utilities" import type { SyntheticListenerMap } from "@dnd-kit/core/dist/hooks/utilities"
import { useWindowSize } from "react-use" import { useWindowSize } from "react-use"
import { forwardRef, useImperativeHandle } from "react"
import { OverlayScrollbar } from "../common/overlay-scrollbar" import { OverlayScrollbar } from "../common/overlay-scrollbar"
import { refetchSourcesAtom } from "~/atoms" import { refetchSourcesAtom } from "~/atoms"
import { safeParseString } from "~/utils" import { safeParseString } from "~/utils"

View File

@ -80,7 +80,7 @@ export function Menu() {
href="https://github.com/ourongxing/newsnow" href="https://github.com/ourongxing/newsnow"
> >
<img <img
alt="GitHub forks badge" alt="GitHub stars badge"
src="https://img.shields.io/github/stars/ourongxing/newsnow?logo=github" src="https://img.shields.io/github/stars/ourongxing/newsnow?logo=github"
/> />
</a> </a>

View File

@ -1,5 +1,4 @@
import type { MaybePromise } from "@shared/type.util" import type { MaybePromise } from "@shared/type.util"
import { $fetch } from "ofetch" import { $fetch } from "ofetch"
export function safeParseString(str: any) { export function safeParseString(str: any) {

View File

@ -9,5 +9,5 @@
"@shared/*": ["shared/*"] "@shared/*": ["shared/*"]
} }
}, },
"include": ["src", "shared", "./auto-imports.app.d.ts"] "include": ["src", "shared", "imports.app.d.ts"]
} }

View File

@ -5,7 +5,7 @@ import react from "@vitejs/plugin-react-swc"
import { TanStackRouterVite } from "@tanstack/router-plugin/vite" import { TanStackRouterVite } from "@tanstack/router-plugin/vite"
import unocss from "unocss/vite" import unocss from "unocss/vite"
import dotenv from "dotenv" import dotenv from "dotenv"
import autoImport from "unplugin-auto-import/vite" import unimport from "unimport/unplugin"
import nitro from "./nitro.config" import nitro from "./nitro.config"
import { projectDir } from "./shared/dir" import { projectDir } from "./shared/dir"
import pwa from "./pwa.config" import pwa from "./pwa.config"
@ -30,17 +30,20 @@ export default defineConfig({
}, },
plugins: [ plugins: [
TanStackRouterVite({ TanStackRouterVite({
// error with unplugin-auto-import and vite-plugin-pwa // error with auto import and vite-plugin-pwa
// autoCodeSplitting: true, // autoCodeSplitting: true,
}), }),
autoImport({ unimport.vite({
dirs: ["src/hooks", "shared", "src/utils", "src/atoms"], dirs: ["src/hooks", "shared", "src/utils", "src/atoms"],
imports: ["react", "jotai", "jotai/utils", { presets: ["react", {
clsx: [ from: "jotai",
["default", "$"], 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(), unocss(),
react(), react(),

View File

@ -1,13 +1,8 @@
import { join } from "node:path" import { join } from "node:path"
import { defineConfig } from "vitest/config" import { defineConfig } from "vitest/config"
import autoImport from "unplugin-auto-import/vite" import unimport from "unimport/unplugin"
import { resolveModuleExportNames } from "mlly"
import { projectDir } from "./shared/dir" import { projectDir } from "./shared/dir"
const h3Exports = await resolveModuleExportNames("h3", {
url: import.meta.url,
})
export default defineConfig({ export default defineConfig({
test: { test: {
globals: true, globals: true,
@ -22,13 +17,16 @@ export default defineConfig({
}, },
plugins: [ plugins: [
// https://github.com/unjs/nitro/blob/v2/src/core/config/resolvers/imports.ts // https://github.com/unjs/nitro/blob/v2/src/core/config/resolvers/imports.ts
autoImport({ unimport.vite({
imports: [{ imports: [],
from: "h3", presets: [
imports: h3Exports.filter(n => !/^[A-Z]/.test(n) && n !== "use"), {
}], package: "h3",
ignore: [/^[A-Z]/, r => r === "use"],
},
],
dirs: ["server/utils", "shared"], dirs: ["server/utils", "shared"],
dts: false, // dts: false,
}), }),
], ],
}) })