Skip to content

Commit

Permalink
Fix type imports, use vue-tsc for typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
dulnan committed Oct 19, 2024
1 parent ac19511 commit 0914312
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 11 deletions.
113 changes: 112 additions & 1 deletion package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"dev:serve": "node playground/.output/server/index.mjs",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground-disk && nuxi prepare playground-nuxt3 && nuxi prepare playground",
"dev:inspect": "nuxi dev playground --inspect",
"typecheck": "nuxi typecheck",
"typecheck": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
"docs:dev": "vitepress dev docs --port 5000",
"docs:build": "vitepress build docs",
"docs:serve": "vitepress serve docs --port 5000",
Expand Down Expand Up @@ -89,6 +89,7 @@
"prettier": "^3.3.2",
"vitepress": "^1.2.3",
"vitest": "^1.6.0",
"vue-json-pretty": "^2.4.0"
"vue-json-pretty": "^2.4.0",
"vue-tsc": "^2.1.6"
}
}
3 changes: 3 additions & 0 deletions playground/app/components/apiPlayground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ getCache()
const getData = (data: string) => {
const cacheItem = data.split('<CACHE_ITEM>')
const headers = cacheItem[0]
if (!headers) {
return
}
try {
return JSON.parse(headers)
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion playground/app/multiCache.serverOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const customDriver = defineDriver(() => {
if (key.includes('static_item_for_test')) {
return JSON.stringify({ data: 'just_an_example_value' })
}
return cache[key]
return cache[key] || null
},
setItem(key, value) {
cache[key] = value
Expand Down
4 changes: 2 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
DEFAULT_CDN_CONTROL_HEADER,
DEFAULT_CDN_TAG_HEADER,
} from './runtime/settings'
import { logger, fileExists } from './utils'
import { logger, fileExists, nonNullable } from './utils'

// Nuxt needs this.
export type ModuleOptions = NuxtMultiCacheOptions
Expand Down Expand Up @@ -175,7 +175,7 @@ export default defineNuxtModule<ModuleOptions>({
.replace(/^(~|@)/, nuxt.options.srcDir)
})
.map((fullPath) => fileExists(fullPath))
.filter(Boolean)
.filter(nonNullable)

const resolvedPath = candidates[0] as string | undefined

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/RenderCacheable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default defineComponent({
// removed from the client bundles.
if (isServer && !props.noCache) {
const { debug } = useRuntimeConfig().multiCache || {}
const cacheKey = getCacheKey(props as any, first, debug)
const cacheKey = getCacheKey(props as any, first as any, debug)

// Return if no cache key found.
if (!cacheKey) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/helpers/routeCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setResponseHeaders, setResponseStatus, type H3Event } from 'h3'
import { RouteCacheItem } from '../types'
import type { RouteCacheItem } from '../types'

export function setCachedResponse(event: H3Event, decoded: RouteCacheItem) {
// Set the cached headers. The name suggests otherwise, but this appends
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/handler/serveCachedRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
decodeRouteCacheItem,
handleRawCacheData,
} from '../../helpers/cacheItem'
import { RouteCacheItem } from '../../types'
import type { RouteCacheItem } from '../../types'
import { MultiCacheState } from '../../helpers/MultiCacheState'
import { logger } from '../../helpers/logger'
import { setCachedResponse } from '../../helpers/routeCache'
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/hooks/beforeResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { format } from '@tusbar/cache-control'
import { setResponseHeader, type H3Event } from 'h3'
import { getMultiCacheCDNHelper, onlyUnique } from '../../helpers/server'
import { useMultiCacheApp } from '../utils/useMultiCacheApp'
import { MultiCacheApp } from '../../types'
import type { MultiCacheApp } from '../../types'

function handleCDN(app: MultiCacheApp, event: H3Event) {
const cdnHelper = getMultiCacheCDNHelper(event)
Expand Down
4 changes: 4 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ export const fileExists = (

return extension ? `${path}.${extension}` : null
}

export function nonNullable<T>(value: T): value is NonNullable<T> {
return value !== null && value !== undefined
}
9 changes: 8 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"extends": "./.nuxt/tsconfig.json",
"exclude": ["dist", "node_modules", "playground"]
"exclude": [
"dist",
"test",
"node_modules",
"playground",
"playground-disk",
"playground-nuxt3"
]
}

0 comments on commit 0914312

Please sign in to comment.