mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
refactor(nuxt): use relative imports into composables (#7487)
This commit is contained in:
parent
40d090745b
commit
ee75b48526
@ -2,7 +2,8 @@ import { defineComponent, h, ref, resolveComponent, PropType, computed, DefineCo
|
|||||||
import { RouteLocationRaw, Router } from 'vue-router'
|
import { RouteLocationRaw, Router } from 'vue-router'
|
||||||
import { hasProtocol } from 'ufo'
|
import { hasProtocol } from 'ufo'
|
||||||
|
|
||||||
import { navigateTo, useRouter, useNuxtApp } from '#app'
|
import { navigateTo, useRouter } from '../composables/router'
|
||||||
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
const firstNonUndefined = <T>(...args: (T | undefined)[]) => args.find(arg => arg !== undefined)
|
const firstNonUndefined = <T>(...args: (T | undefined)[]) => args.find(arg => arg !== undefined)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { onBeforeMount, onServerPrefetch, onUnmounted, ref, getCurrentInstance, watch, unref } from 'vue'
|
import { onBeforeMount, onServerPrefetch, onUnmounted, ref, getCurrentInstance, watch, unref } from 'vue'
|
||||||
import type { Ref, WatchSource } from 'vue'
|
import type { Ref, WatchSource } from 'vue'
|
||||||
import { NuxtApp, useNuxtApp } from '#app'
|
import { NuxtApp, useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
export type _Transform<Input = any, Output = any> = (input: Input) => Output
|
export type _Transform<Input = any, Output = any> = (input: Input) => Output
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ import { appendHeader } from 'h3'
|
|||||||
import type { CompatibilityEvent } from 'h3'
|
import type { CompatibilityEvent } from 'h3'
|
||||||
import destr from 'destr'
|
import destr from 'destr'
|
||||||
import { isEqual } from 'ohash'
|
import { isEqual } from 'ohash'
|
||||||
|
import { useNuxtApp } from '../nuxt'
|
||||||
import { useRequestEvent } from './ssr'
|
import { useRequestEvent } from './ssr'
|
||||||
import { useNuxtApp } from '#app'
|
|
||||||
|
|
||||||
type _CookieOptions = Omit<CookieSerializeOptions & CookieParseOptions, 'decode' | 'encode'>
|
type _CookieOptions = Omit<CookieSerializeOptions & CookieParseOptions, 'decode' | 'encode'>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { createError as _createError, H3Error } from 'h3'
|
import { createError as _createError, H3Error } from 'h3'
|
||||||
import { toRef } from 'vue'
|
import { toRef } from 'vue'
|
||||||
import { useNuxtApp } from '#app'
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
export const useError = () => toRef(useNuxtApp().payload, 'error')
|
export const useError = () => toRef(useNuxtApp().payload, 'error')
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useNuxtApp } from '#app'
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows full control of the hydration cycle to set and receive data from the server.
|
* Allows full control of the hydration cycle to set and receive data from the server.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { parseURL, joinURL } from 'ufo'
|
import { parseURL, joinURL } from 'ufo'
|
||||||
import { useNuxtApp } from '../nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
import { useHead } from '#app'
|
import { useHead } from '..'
|
||||||
|
|
||||||
interface LoadPayloadOptions {
|
interface LoadPayloadOptions {
|
||||||
fresh?: boolean
|
fresh?: boolean
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import type { Component } from 'vue'
|
import type { Component } from 'vue'
|
||||||
import { useNuxtApp } from '#app'
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preload a component or components that have been globally registered.
|
* Preload a component or components that have been globally registered.
|
||||||
|
@ -2,7 +2,9 @@ import { getCurrentInstance, inject } from 'vue'
|
|||||||
import type { Router, RouteLocationNormalizedLoaded, NavigationGuard, RouteLocationNormalized, RouteLocationRaw, NavigationFailure, RouteLocationPathRaw } from 'vue-router'
|
import type { Router, RouteLocationNormalizedLoaded, NavigationGuard, RouteLocationNormalized, RouteLocationRaw, NavigationFailure, RouteLocationPathRaw } from 'vue-router'
|
||||||
import { sendRedirect } from 'h3'
|
import { sendRedirect } from 'h3'
|
||||||
import { hasProtocol, joinURL, parseURL } from 'ufo'
|
import { hasProtocol, joinURL, parseURL } from 'ufo'
|
||||||
import { useNuxtApp, useRuntimeConfig, useState, createError, NuxtError } from '#app'
|
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
||||||
|
import { createError, NuxtError } from './error'
|
||||||
|
import { useState } from './state'
|
||||||
|
|
||||||
export const useRouter = () => {
|
export const useRouter = () => {
|
||||||
return useNuxtApp()?.$router as Router
|
return useNuxtApp()?.$router as Router
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
/* eslint-disable no-redeclare */
|
/* eslint-disable no-redeclare */
|
||||||
import type { CompatibilityEvent } from 'h3'
|
import type { CompatibilityEvent } from 'h3'
|
||||||
import { useNuxtApp } from '#app'
|
import { useNuxtApp, NuxtApp } from '../nuxt'
|
||||||
import { NuxtApp } from '#app/nuxt'
|
|
||||||
|
|
||||||
export function useRequestHeaders<K extends string = string> (include: K[]): Record<K, string | undefined>
|
export function useRequestHeaders<K extends string = string> (include: K[]): Record<K, string | undefined>
|
||||||
export function useRequestHeaders (): Readonly<Record<string, string | undefined>>
|
export function useRequestHeaders (): Readonly<Record<string, string | undefined>>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { isRef, toRef } from 'vue'
|
import { isRef, toRef } from 'vue'
|
||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
import { useNuxtApp } from '#app'
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a global reactive ref that will be hydrated but not shared across ssr requests
|
* Create a global reactive ref that will be hydrated but not shared across ssr requests
|
||||||
|
@ -13,7 +13,7 @@ vi.mock('vue', async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Mocks Nuxt `useRouter()`
|
// Mocks Nuxt `useRouter()`
|
||||||
vi.mock('#app', () => ({
|
vi.mock('../src/app/composables/router', () => ({
|
||||||
useRouter: () => ({ resolve: ({ to }: { to: string }) => ({ href: to }) })
|
useRouter: () => ({ resolve: ({ to }: { to: string }) => ({ href: to }) })
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user