mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +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 { 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)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { onBeforeMount, onServerPrefetch, onUnmounted, ref, getCurrentInstance, watch, unref } 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
|
||||
|
||||
|
@ -4,8 +4,8 @@ import { appendHeader } from 'h3'
|
||||
import type { CompatibilityEvent } from 'h3'
|
||||
import destr from 'destr'
|
||||
import { isEqual } from 'ohash'
|
||||
import { useNuxtApp } from '../nuxt'
|
||||
import { useRequestEvent } from './ssr'
|
||||
import { useNuxtApp } from '#app'
|
||||
|
||||
type _CookieOptions = Omit<CookieSerializeOptions & CookieParseOptions, 'decode' | 'encode'>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { createError as _createError, H3Error } from 'h3'
|
||||
import { toRef } from 'vue'
|
||||
import { useNuxtApp } from '#app'
|
||||
import { useNuxtApp } from '../nuxt'
|
||||
|
||||
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.
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { parseURL, joinURL } from 'ufo'
|
||||
import { useNuxtApp } from '../nuxt'
|
||||
import { useHead } from '#app'
|
||||
import { useHead } from '..'
|
||||
|
||||
interface LoadPayloadOptions {
|
||||
fresh?: boolean
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { Component } from 'vue'
|
||||
import { useNuxtApp } from '#app'
|
||||
import { useNuxtApp } from '../nuxt'
|
||||
|
||||
/**
|
||||
* 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 { sendRedirect } from 'h3'
|
||||
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 = () => {
|
||||
return useNuxtApp()?.$router as Router
|
||||
|
@ -1,7 +1,6 @@
|
||||
/* eslint-disable no-redeclare */
|
||||
import type { CompatibilityEvent } from 'h3'
|
||||
import { useNuxtApp } from '#app'
|
||||
import { NuxtApp } from '#app/nuxt'
|
||||
import { useNuxtApp, NuxtApp } from '../nuxt'
|
||||
|
||||
export function useRequestHeaders<K extends string = string> (include: K[]): Record<K, string | undefined>
|
||||
export function useRequestHeaders (): Readonly<Record<string, string | undefined>>
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { isRef, toRef } 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
|
||||
|
@ -13,7 +13,7 @@ vi.mock('vue', async () => {
|
||||
})
|
||||
|
||||
// Mocks Nuxt `useRouter()`
|
||||
vi.mock('#app', () => ({
|
||||
vi.mock('../src/app/composables/router', () => ({
|
||||
useRouter: () => ({ resolve: ({ to }: { to: string }) => ({ href: to }) })
|
||||
}))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user