Skip to content

Commit

Permalink
chore: switch to unimport
Browse files Browse the repository at this point in the history
  • Loading branch information
ourongxing committed Oct 30, 2024
1 parent 55709e1 commit 743778e
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 150 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ dist/
.env.*
dev-dist
*.tsbuildinfo
wrangler.toml
wrangler.toml
imports.app.d.ts
95 changes: 0 additions & 95 deletions auto-imports.app.d.ts

This file was deleted.

3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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/**"],
}))
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 3 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/components/column/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function Menu() {
href="https://github.com/ourongxing/newsnow"
>
<img
alt="GitHub forks badge"
alt="GitHub stars badge"
src="https://img.shields.io/github/stars/ourongxing/newsnow?logo=github"
/>
</a>
Expand Down
1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { MaybePromise } from "@shared/type.util"

import { $fetch } from "ofetch"

export function safeParseString(str: any) {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"@shared/*": ["shared/*"]
}
},
"include": ["src", "shared", "./auto-imports.app.d.ts"]
"include": ["src", "shared", "imports.app.d.ts"]
}
19 changes: 11 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(),
Expand Down
22 changes: 10 additions & 12 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
}),
],
})

0 comments on commit 743778e

Please sign in to comment.