Skip to content

Commit 1bf113a

Browse files
authored
fix: move to mocked-exports rather than implicit unenv dep (#3232)
1 parent 5623f87 commit 1bf113a

File tree

8 files changed

+43
-14
lines changed

8 files changed

+43
-14
lines changed

mocks/prosemirror.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import proxy from 'unenv/runtime/mock/proxy'
1+
import proxy from 'mocked-exports/proxy'
22

33
export const Plugin = proxy
44
export const PluginKey = proxy

mocks/semver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import proxy from 'unenv/runtime/mock/proxy'
1+
import proxy from 'mocked-exports/proxy'
22

33
export const lt = proxy
44
export const gt = proxy

mocks/tiptap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import proxy from 'unenv/runtime/mock/proxy'
1+
import proxy from 'mocked-exports/proxy'
22

33
export const Extension = proxy
44
export const useEditor = proxy

modules/tauri/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { rm } from 'node:fs/promises'
22
import { addImports, addImportsSources, addPlugin, createResolver, defineNuxtModule, useNuxt } from '@nuxt/kit'
3+
import { resolveModulePath } from 'exsolve'
4+
5+
const mockProxy = resolveModulePath('mocked-exports/proxy', { from: import.meta.url })
36

47
export default defineNuxtModule({
58
meta: {
@@ -20,8 +23,8 @@ export default defineNuxtModule({
2023

2124
nuxt.options.alias = {
2225
...nuxt.options.alias,
23-
'unstorage/drivers/fs': 'unenv/runtime/mock/proxy',
24-
'unstorage/drivers/cloudflare-kv-http': 'unenv/runtime/mock/proxy',
26+
'unstorage/drivers/fs': mockProxy,
27+
'unstorage/drivers/cloudflare-kv-http': mockProxy,
2528
'#storage-config': resolve('./runtime/storage-config'),
2629
'node:events': 'unenv/runtime/node/events/index',
2730
'#build-info': resolve('./runtime/build-info'),

modules/tauri/runtime/nitro.client.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import {
55
defineLazyEventHandler,
66
toNodeListener,
77
} from 'h3'
8+
import { fetchNodeRequestHandler } from 'node-mock-http'
89
import { createFetch } from 'ofetch'
9-
import {
10-
createCall,
11-
createFetch as createLocalFetch,
12-
} from 'unenv/runtime/fetch/index'
1310

1411
const handlers = [
1512
{
@@ -52,12 +49,16 @@ export default defineNuxtPlugin(async () => {
5249
// @ts-expect-error TODO: fix
5350
h3App.use(config.app.baseURL, router)
5451

55-
const localCall = createCall(toNodeListener(h3App) as any)
56-
const localFetch = createLocalFetch(localCall, globalThis.fetch)
52+
const nodeHandler = toNodeListener(h3App)
53+
const localFetch: typeof fetch = async (input, init) => {
54+
if (!input.toString().startsWith('/')) {
55+
return globalThis.fetch(input.toString(), init)
56+
}
57+
return await fetchNodeRequestHandler(nodeHandler, input.toString(), init)
58+
}
5759

5860
// @ts-expect-error error types are subtly different here in a future nitro version
5961
globalThis.$fetch = createFetch({
60-
// @ts-expect-error slight differences in api
6162
fetch: localFetch,
6263
Headers,
6364
defaults: { baseURL: config.app.baseURL },

nuxt.config.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import type { BuildInfo } from './types'
22
import { createResolver, useNuxt } from '@nuxt/kit'
3+
import { resolveModulePath } from 'exsolve'
34
import { isCI, isDevelopment, isWindows } from 'std-env'
45
import { isPreview } from './config/env'
56
import { currentLocales } from './config/i18n'
67
import { pwa } from './config/pwa'
78

89
const { resolve } = createResolver(import.meta.url)
910

11+
const mockProxy = resolveModulePath('mocked-exports/proxy', { from: import.meta.url })
12+
1013
export default defineNuxtConfig({
1114
compatibilityDate: '2024-09-11',
1215
typescript: {
@@ -186,7 +189,7 @@ export default defineNuxtConfig({
186189
},
187190
nitro: {
188191
alias: {
189-
'isomorphic-ws': 'unenv/runtime/mock/proxy',
192+
'isomorphic-ws': mockProxy,
190193
},
191194
esbuild: {
192195
options: {
@@ -230,7 +233,7 @@ export default defineNuxtConfig({
230233
for (const dep of ['eventemitter3', 'isomorphic-ws'])
231234
alias[dep] = resolve('./mocks/class')
232235
for (const dep of ['fuse.js'])
233-
alias[dep] = 'unenv/runtime/mock/proxy'
236+
alias[dep] = mockProxy
234237
const resolver = createResolver(import.meta.url)
235238

236239
config.plugins!.unshift({

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"cheerio": "^1.0.0",
7373
"chroma-js": "^3.0.0",
7474
"emoji-mart": "^5.5.2",
75+
"exsolve": "^1.0.4",
7576
"file-saver": "^2.0.5",
7677
"floating-vue": "^5.2.2",
7778
"focus-trap": "^7.5.1",
@@ -85,7 +86,9 @@
8586
"js-yaml": "^4.1.0",
8687
"lru-cache": "^11.0.0",
8788
"masto": "^6.10.1",
89+
"mocked-exports": "^0.1.1",
8890
"node-emoji": "^2.1.3",
91+
"node-mock-http": "^1.0.0",
8992
"nuxt-security": "^2.0.0",
9093
"page-lifecycle": "^0.1.2",
9194
"pinia": "^2.2.6",

pnpm-lock.yaml

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)