fix: move to mocked-exports
rather than implicit unenv
dep (#3232)
This commit is contained in:
parent
5623f87607
commit
1bf113a960
8 changed files with 43 additions and 14 deletions
|
@ -1,5 +1,8 @@
|
|||
import { rm } from 'node:fs/promises'
|
||||
import { addImports, addImportsSources, addPlugin, createResolver, defineNuxtModule, useNuxt } from '@nuxt/kit'
|
||||
import { resolveModulePath } from 'exsolve'
|
||||
|
||||
const mockProxy = resolveModulePath('mocked-exports/proxy', { from: import.meta.url })
|
||||
|
||||
export default defineNuxtModule({
|
||||
meta: {
|
||||
|
@ -20,8 +23,8 @@ export default defineNuxtModule({
|
|||
|
||||
nuxt.options.alias = {
|
||||
...nuxt.options.alias,
|
||||
'unstorage/drivers/fs': 'unenv/runtime/mock/proxy',
|
||||
'unstorage/drivers/cloudflare-kv-http': 'unenv/runtime/mock/proxy',
|
||||
'unstorage/drivers/fs': mockProxy,
|
||||
'unstorage/drivers/cloudflare-kv-http': mockProxy,
|
||||
'#storage-config': resolve('./runtime/storage-config'),
|
||||
'node:events': 'unenv/runtime/node/events/index',
|
||||
'#build-info': resolve('./runtime/build-info'),
|
||||
|
|
|
@ -5,11 +5,8 @@ import {
|
|||
defineLazyEventHandler,
|
||||
toNodeListener,
|
||||
} from 'h3'
|
||||
import { fetchNodeRequestHandler } from 'node-mock-http'
|
||||
import { createFetch } from 'ofetch'
|
||||
import {
|
||||
createCall,
|
||||
createFetch as createLocalFetch,
|
||||
} from 'unenv/runtime/fetch/index'
|
||||
|
||||
const handlers = [
|
||||
{
|
||||
|
@ -52,12 +49,16 @@ export default defineNuxtPlugin(async () => {
|
|||
// @ts-expect-error TODO: fix
|
||||
h3App.use(config.app.baseURL, router)
|
||||
|
||||
const localCall = createCall(toNodeListener(h3App) as any)
|
||||
const localFetch = createLocalFetch(localCall, globalThis.fetch)
|
||||
const nodeHandler = toNodeListener(h3App)
|
||||
const localFetch: typeof fetch = async (input, init) => {
|
||||
if (!input.toString().startsWith('/')) {
|
||||
return globalThis.fetch(input.toString(), init)
|
||||
}
|
||||
return await fetchNodeRequestHandler(nodeHandler, input.toString(), init)
|
||||
}
|
||||
|
||||
// @ts-expect-error error types are subtly different here in a future nitro version
|
||||
globalThis.$fetch = createFetch({
|
||||
// @ts-expect-error slight differences in api
|
||||
fetch: localFetch,
|
||||
Headers,
|
||||
defaults: { baseURL: config.app.baseURL },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue