Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update deps #38

Merged
merged 9 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Install Playwright Browsers
run: npx playwright install --with-deps

- name: Vitest
run: |
npm ci
npm run dev:prepare
npm run prepack
npm run test:ci
Expand Down
2 changes: 0 additions & 2 deletions .nuxtrc

This file was deleted.

30,271 changes: 13,208 additions & 17,063 deletions package-lock.json

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"./dist/runtime/serverOptions": {
"import": "./dist/runtime/serverOptions/index.mjs",
"import": "./dist/runtime/serverOptions/index.js",
"types": "./dist/runtime/serverOptions/index.d.ts"
}
},
Expand All @@ -37,20 +37,22 @@
},
"license": "MIT",
"scripts": {
"prepack": "nuxt-module-build",
"prepack": "nuxt-module-build build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:serve": "node playground/.output/server/index.mjs",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"generate": "nuxi generate",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
"typecheck": "nuxi typecheck",
"docs:dev": "vitepress dev docs --port 5000",
"docs:build": "vitepress build docs",
"docs:serve": "vitepress serve docs --port 5000",
"prettier": "prettier ./src --check",
"prettier:fix": "prettier ./src --write",
"lint": "eslint ./src",
"lint:fix": "eslint ./src --fix",
"fake-data": "node ./scripts/fakeData.js",
"test": "TZ=utc vitest",
"test:debug": "TZ=utc vitest --disable-console-intercept --reporter=json",
"test:ci": "TZ=utc vitest run",
"test:coverage": "TZ=utc vitest run --coverage"
},
Expand All @@ -62,29 +64,27 @@
"dist"
],
"dependencies": {
"@nuxt/kit": "^3.6.5",
"@tusbar/cache-control": "^1.0.1",
"consola": "3.2.3"
"@nuxt/kit": "^3.12.2",
"@tusbar/cache-control": "^1.0.2"
},
"devDependencies": {
"@faker-js/faker": "^8.0.2",
"@nuxt/module-builder": "^0.4.0",
"@nuxt/schema": "^3.6.5",
"@nuxt/test-utils": "^3.6.5",
"@nuxtjs/eslint-config-typescript": "^12.0.0",
"@types/node": "^20.4.10",
"@vitest/coverage-c8": "^0.33.0",
"@vue/test-utils": "^2.4.1",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-vue": "^9.17.0",
"happy-dom": "^10.9.0",
"nuxt": "^3.6.5",
"nuxt-vitest": "^0.10.2",
"playwright": "^1.37.0",
"prettier": "^3.0.1",
"vitepress": "^1.0.0-rc.4",
"vue-json-pretty": "^2.2.4"
"@faker-js/faker": "^8.4.1",
"@nuxt/module-builder": "^0.7.1",
"@nuxt/schema": "^3.12.2",
"@nuxt/test-utils": "^3.13.1",
"@nuxtjs/eslint-config-typescript": "^12.1.0",
"@types/node": "^20.14.2",
"@vue/test-utils": "^2.4.6",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-vue": "^9.26.0",
"happy-dom": "^14.12.0",
"nuxt": "^3.12.2",
"playwright-core": "^1.44.1",
"prettier": "^3.3.2",
"vitepress": "^1.2.3",
"vitest": "^1.6.0",
"vue-json-pretty": "^2.4.0"
}
}
4 changes: 2 additions & 2 deletions playground/app/multiCache.serverOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineDriver } from 'unstorage'
import { H3Event, getQuery, getHeader } from 'h3'
import { type H3Event, getQuery, getHeader } from 'h3'
import { defineMultiCacheOptions } from './../../src/runtime/serverOptions'

const customDriver = defineDriver(() => {
Expand Down Expand Up @@ -51,7 +51,7 @@ function getCacheKeyPrefix(event: H3Event): string {
export default defineMultiCacheOptions({
data: {
storage: {
driver: customDriver(),
driver: customDriver({}),
},
},
route: {
Expand Down
7 changes: 4 additions & 3 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export default defineNuxtConfig({
'/spaPageWithException': { ssr: false },
},
modules: [NuxtMultiCache],
imports: {
autoImport: false,
},
multiCache: {
debug: true,
component: {
Expand All @@ -31,7 +34,5 @@ export default defineNuxtConfig({
},
},

css: [
'vue-json-pretty/lib/styles.css'
],
css: ['vue-json-pretty/lib/styles.css'],
})
7 changes: 0 additions & 7 deletions playground/package.json

This file was deleted.

6 changes: 5 additions & 1 deletion playground/pages/spaPageWithException.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<template>
<div>{{ this.does.not.exist }}</div>
<div>{{ does.not.exist }}</div>
</template>

<script>
/* tslint:disable */
</script>
2 changes: 1 addition & 1 deletion playground/server/api/getUser/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { defineEventHandler } from 'h3'
import users from '~/data/users.json'

export default defineEventHandler((event) => {
const id = event.context.params.id
const id = event.context.params?.id
return users.find((v) => v.userId === id)
})
8 changes: 7 additions & 1 deletion playground/server/api/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { useCDNHeaders, useRouteCache } from '#nuxt-multi-cache/composables'
import { defineEventHandler } from 'h3'

export default defineEventHandler((event) => {
type TestResponse = {
api: string
now: Date
cacheTags: string[]
}

export default defineEventHandler<TestResponse>((event) => {
const cacheTags: string[] = [
'page:1',
'image:234',
Expand Down
3 changes: 3 additions & 0 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nuxt/tsconfig.json"
}
20 changes: 13 additions & 7 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
addImports,
addTemplate,
} from '@nuxt/kit'
import { MultiCacheServerOptions, NuxtMultiCacheOptions } from './runtime/types'
import type {
MultiCacheServerOptions,
NuxtMultiCacheOptions,
} from './runtime/types'
import {
defaultOptions,
DEFAULT_CDN_CONTROL_HEADER,
Expand Down Expand Up @@ -54,19 +57,17 @@ export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'nuxt-multi-cache',
configKey: 'multiCache',
version: '3.1.0',
compatibility: {
nuxt: '^3.5.0',
},
version: '3.10.0',
},
defaults: defaultOptions as any,
async setup(passedOptions, nuxt) {
const options = defu({}, passedOptions, {}) as ModuleOptions
checkObsoleteOptions(options)
const { resolve } = createResolver(import.meta.url)
const metaUrl = import.meta.url
const { resolve } = createResolver(metaUrl)
const rootDir = nuxt.options.rootDir

const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
const runtimeDir = fileURLToPath(new URL('./runtime', metaUrl))
nuxt.options.build.transpile.push(runtimeDir)
nuxt.options.runtimeConfig.multiCache = {
debug: !!options.debug,
Expand Down Expand Up @@ -202,6 +203,11 @@ export default defineNuxtModule<ModuleOptions>({
nuxt.options.nitro.externals.inline.push(template.dst)
nuxt.options.alias['#multi-cache-server-options'] = template.dst

nuxt.hook('nitro:config', (nitroConfig) => {
nitroConfig.alias = nitroConfig.alias || {}
nitroConfig.alias['#multi-cache-server-options'] = template.dst
})

// Add cache management API if enabled.
if (options.api?.enabled) {
// Prefix is defined in default config.
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/components/RenderCacheable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export default defineComponent({
})
}
if (e instanceof Error) {
// eslint-disable-next-line no-console
console.error(e.message)
}
}
Expand All @@ -278,6 +279,7 @@ export default defineComponent({
})
}
if (e instanceof Error) {
// eslint-disable-next-line no-console
console.error(e.message)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/runtime/composables/useDataCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export function useDataCache<T>(
} catch (e) {
if (e instanceof Error) {
// For some reason cache is not available.
// eslint-disable-next-line no-console
console.debug(e.message)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/helpers/cacheItem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentCacheItem, RouteCacheItem } from '../types'
import type { ComponentCacheItem, RouteCacheItem } from '../types'

const DELIMITER = '<CACHE_ITEM>'

Expand Down
26 changes: 15 additions & 11 deletions src/runtime/serverHandler/api/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { getMultiCacheContext } from './../../../helpers/server'
import { useRuntimeConfig } from '#imports'
import serverOptions from '#multi-cache-server-options'

const runtimeConfig = useRuntimeConfig()

const AUTH_HEADER = 'x-nuxt-multi-cache-token'

export function getCacheInstance(event: H3Event): Storage {
Expand All @@ -22,17 +20,22 @@ export function getCacheInstance(event: H3Event): Storage {
statusMessage: 'Failed to load cache context.',
})
}
const cacheName = event.context.params
.cacheName as keyof NuxtMultiCacheSSRContext
const cache = cacheContext[cacheName]
if (!cache) {
throw createError({
statusCode: 404,
statusMessage: `The given cache "${cacheName}" is not available.`,
})

const cacheName = event.context.params?.cacheName as
| keyof NuxtMultiCacheSSRContext
| undefined

if (cacheName) {
const cache = cacheContext[cacheName]
if (cache) {
return cache
}
}

return cache
throw createError({
statusCode: 404,
statusMessage: `The given cache "${cacheName}" is not available.`,
})
}

/**
Expand All @@ -45,6 +48,7 @@ export async function checkAuth(
providedRuntimeConfig?: MultiCacheRuntimeConfig,
providedServerOptions?: MultiCacheServerOptions,
) {
const runtimeConfig = useRuntimeConfig()
const { authorizationDisabled, authorizationToken } =
(providedRuntimeConfig || runtimeConfig.multiCache).api || {}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/serverHandler/api/purgeAll.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineEventHandler } from 'h3'
import { getMultiCacheContext } from './../../helpers/server'
import { NuxtMultiCacheSSRContext } from './../../types'
import type { NuxtMultiCacheSSRContext } from './../../types'
import { checkAuth } from './helpers'

export default defineEventHandler(async (event) => {
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/serverHandler/api/purgeTags.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { H3Event } from 'h3'
import { readBody, defineEventHandler, createError } from 'h3'
import {
decodeComponentCacheItem,
decodeRouteCacheItem,
} from '../../helpers/cacheItem'
import { getMultiCacheContext } from './../../helpers/server'
import { DEFAULT_CACHE_TAG_INVALIDATION_DELAY } from './../../settings'
import type { NuxtMultiCacheSSRContext } from './../../types'
import { checkAuth } from './helpers'
import { useRuntimeConfig } from '#imports'
import {
decodeComponentCacheItem,
decodeRouteCacheItem,
} from '../../helpers/cacheItem'

/**
* Get the tags to be purged from the request.
Expand Down
33 changes: 18 additions & 15 deletions src/runtime/serverHandler/helpers/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,7 @@ import type { NuxtMultiCacheSSRContext } from './../../types'
import { useRuntimeConfig } from '#imports'
import serverOptions from '#multi-cache-server-options'

const runtimeConfig = useRuntimeConfig()

const cacheContext: NuxtMultiCacheSSRContext = {}

// Initialize all enabled caches. Explicit initialization because some
// caches might need additional configuration options and/or checks.
if (runtimeConfig.multiCache.component) {
cacheContext.component = createStorage(serverOptions.component?.storage)
}
if (runtimeConfig.multiCache.data) {
cacheContext.data = createStorage(serverOptions.data?.storage)
}
if (runtimeConfig.multiCache.route) {
cacheContext.route = createStorage(serverOptions.route?.storage)
}
let cacheContext: NuxtMultiCacheSSRContext | null = null

/**
* Method to initialize the caches.
Expand All @@ -26,5 +12,22 @@ if (runtimeConfig.multiCache.route) {
* afterwards.
*/
export function loadCacheContext() {
if (!cacheContext) {
const runtimeConfig = useRuntimeConfig()

cacheContext = {}

// Initialize all enabled caches. Explicit initialization because some
// caches might need additional configuration options and/or checks.
if (runtimeConfig.multiCache.component) {
cacheContext.component = createStorage(serverOptions.component?.storage)
}
if (runtimeConfig.multiCache.data) {
cacheContext.data = createStorage(serverOptions.data?.storage)
}
if (runtimeConfig.multiCache.route) {
cacheContext.route = createStorage(serverOptions.route?.storage)
}
}
return cacheContext
}
Loading