refactor(nuxt): use relative imports into composables (#7487)

This commit is contained in:
Daniel Roe 2022-09-14 10:22:03 +01:00 committed by GitHub
parent 40d090745b
commit ee75b48526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 14 additions and 12 deletions

View File

@ -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)

View File

@ -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

View File

@ -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'>

View File

@ -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')

View File

@ -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.

View File

@ -1,6 +1,6 @@
import { parseURL, joinURL } from 'ufo'
import { useNuxtApp } from '../nuxt'
import { useHead } from '#app'
import { useHead } from '..'
interface LoadPayloadOptions {
fresh?: boolean

View File

@ -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.

View File

@ -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

View File

@ -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>>

View File

@ -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

View File

@ -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 }) })
}))