Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix/allow-overriding-…
Browse files Browse the repository at this point in the history
…vite-sourcemap
  • Loading branch information
danielroe committed Sep 8, 2022
2 parents 36ccf5d + be77d47 commit 6af2c34
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 101 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "^11.0.0",
"@types/node": "^16.11.57",
"@types/node": "^16.11.58",
"@types/rimraf": "^3",
"@unocss/reset": "^0.45.18",
"case-police": "^0.5.10",
"changelogen": "^0.3.0",
"eslint": "^8.23.0",
"eslint-plugin-jsdoc": "^39.3.6",
"execa": "^6.1.0",
"expect-type": "^0.14.0",
"expect-type": "^0.14.2",
"globby": "^13.1.2",
"jiti": "^1.15.0",
"lerna": "^5.5.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"@nuxt/telemetry": "^2.1.5",
"@nuxt/ui-templates": "^0.3.3",
"@nuxt/vite-builder": "3.0.0-rc.9",
"@vue/reactivity": "^3.2.38",
"@vue/shared": "^3.2.38",
"@vue/reactivity": "^3.2.39",
"@vue/shared": "^3.2.39",
"@vueuse/head": "^0.7.9",
"chokidar": "^3.5.3",
"cookie-es": "^0.5.0",
Expand Down Expand Up @@ -66,7 +66,7 @@
"unimport": "^0.6.7",
"unplugin": "^0.9.2",
"untyped": "^0.4.7",
"vue": "^3.2.38",
"vue": "^3.2.39",
"vue-bundle-renderer": "^0.4.2",
"vue-devtools-stub": "^0.1.0",
"vue-router": "^4.1.5"
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt/src/app/composables/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getCurrentInstance, inject } from 'vue'
import type { Router, RouteLocationNormalizedLoaded, NavigationGuard, RouteLocationNormalized, RouteLocationRaw, NavigationFailure, RouteLocationPathRaw } from 'vue-router'
import { sendRedirect } from 'h3'
import { hasProtocol, joinURL, parseURL } from 'ufo'
import { useNuxtApp, useRuntimeConfig, useState } from '#app'
import { useNuxtApp, useRuntimeConfig, useState, createError, NuxtError } from '#app'

export const useRouter = () => {
return useNuxtApp()?.$router as Router
Expand Down Expand Up @@ -105,12 +105,12 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
}

/** This will abort navigation within a Nuxt route middleware handler. */
export const abortNavigation = (err?: Error | string) => {
export const abortNavigation = (err?: string | Partial<NuxtError>) => {
if (process.dev && !isProcessingMiddleware()) {
throw new Error('abortNavigation() is only usable inside a route middleware handler.')
}
if (err) {
throw err instanceof Error ? err : new Error(err)
throw createError(err)
}
return false
}
Expand Down
4 changes: 2 additions & 2 deletions packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"ohmyfetch": "^0.4.18"
},
"devDependencies": {
"playwright": "^1.25.1",
"playwright": "^1.25.2",
"unbuild": "latest",
"vitest": "~0.19.1"
},
"peerDependencies": {
"vue": "^3.2.38"
"vue": "^3.2.39"
},
"engines": {
"node": "^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@nuxt/schema": "3.0.0-rc.9",
"@types/cssnano": "^5",
"unbuild": "latest",
"vue": "3.2.38"
"vue": "3.2.39"
},
"dependencies": {
"@nuxt/kit": "3.0.0-rc.9",
Expand Down Expand Up @@ -54,7 +54,7 @@
"vue-bundle-renderer": "^0.4.2"
},
"peerDependencies": {
"vue": "^3.2.38"
"vue": "^3.2.39"
},
"engines": {
"node": "^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0"
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/plugins/composable-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { walk } from 'estree-walker'
import MagicString from 'magic-string'
import { hash } from 'ohash'
import type { CallExpression } from 'estree'
import { parseURL } from 'ufo'
import { parseQuery, parseURL } from 'ufo'

export interface ComposableKeysOptions {
sourcemap: boolean
Expand All @@ -22,8 +22,8 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio
name: 'nuxt:composable-keys',
enforce: 'post',
transform (code, id) {
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href))
if (!pathname.match(/\.(m?[jt]sx?|vue)/)) { return }
const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href))
if (!pathname.match(/\.(m?[jt]sx?|vue)/) || parseQuery(search).type === 'style') { return }
if (!KEYED_FUNCTIONS_RE.test(code)) { return }
const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\S\s.]*?(?=<\/script>)/) || []
const s = new MagicString(code)
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
"@types/webpack-hot-middleware": "^2.25.6",
"@types/webpack-virtual-modules": "^0",
"unbuild": "latest",
"vue": "3.2.38"
"vue": "3.2.39"
},
"peerDependencies": {
"vue": "^3.2.38"
"vue": "^3.2.39"
},
"engines": {
"node": "^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0"
Expand Down
58 changes: 33 additions & 25 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,30 @@ describe('navigate', () => {
})
})

describe('errors', () => {
it('should render a JSON error page', async () => {
const res = await fetch('/error', {
headers: {
accept: 'application/json'
}
})
expect(res.status).toBe(422)
const error = await res.json()
delete error.stack
expect(error).toMatchObject({
message: 'This is a custom error',
statusCode: 422,
statusMessage: 'This is a custom error',
url: '/error'
})
})

it('should render a HTML error page', async () => {
const res = await fetch('/error')
expect(await res.text()).toContain('This is a custom error')
})
})

describe('navigate external', () => {
it('should redirect to example.com', async () => {
const { headers } = await fetch('/navigate-to-external/', { redirect: 'manual' })
Expand All @@ -212,6 +236,15 @@ describe('middlewares', () => {
expect(html).toContain('Hello Nuxt 3!')
})

it('should allow aborting navigation on server-side', async () => {
const res = await fetch('/?abort', {
headers: {
accept: 'application/json'
}
})
expect(res.status).toEqual(401)
})

it('should inject auth', async () => {
const html = await $fetch('/auth')

Expand Down Expand Up @@ -570,28 +603,3 @@ describe('useAsyncData', () => {
await expectNoClientErrors('/useAsyncData/promise-all')
})
})

// TODO: Move back up after https://github.com/vuejs/core/issues/6110 is resolved
describe('errors', () => {
it('should render a JSON error page', async () => {
const res = await fetch('/error', {
headers: {
accept: 'application/json'
}
})
expect(res.status).toBe(422)
const error = await res.json()
delete error.stack
expect(error).toMatchObject({
message: 'This is a custom error',
statusCode: 422,
statusMessage: 'This is a custom error',
url: '/error'
})
})

it('should render a HTML error page', async () => {
const res = await fetch('/error')
expect(await res.text()).toContain('This is a custom error')
})
})
7 changes: 7 additions & 0 deletions test/fixtures/basic/middleware/abort.global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default defineNuxtRouteMiddleware((to) => {
if ('abort' in to.query) {
return abortNavigation({
statusCode: 401
})
}
})
7 changes: 7 additions & 0 deletions test/fixtures/basic/pages/keyed-composables.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ const { data: useLazyFetchTest2 } = await useLocalLazyFetch()
{{ useLazyFetchTest1 === useLazyFetchTest2 }}
</div>
</template>

<style scoped>
body {
background-color: #000;
color: #fff;
}
</style>
Loading

0 comments on commit 6af2c34

Please sign in to comment.