Skip to content

Commit 6e7643e

Browse files
committed
fix: possible conflict with import ids of nuxt and nitro clients
1 parent d39b214 commit 6e7643e

3 files changed

Lines changed: 25 additions & 21 deletions

File tree

playground/app/app.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const _result2 = await useGithubFetch('/advisories/{ghsa_id}', {
2525
});
2626
2727
// check for type error
28-
const _test2: GithubComponents['schemas']['global-advisory'] | null =
28+
const _test2: GithubComponents['schemas']['global-advisory'] | undefined =
2929
_result2.data.value;
3030
3131
const _result3 = useCustomGithubFetch('/advisories/{ghsa_id}', {
@@ -36,7 +36,7 @@ const _result3 = useCustomGithubFetch('/advisories/{ghsa_id}', {
3636
useLazyCustomGithubFetch('/');
3737
3838
// check for type error
39-
const _test3: GithubComponents['schemas']['global-advisory'] | null =
39+
const _test3: GithubComponents['schemas']['global-advisory'] | undefined =
4040
_result3.data.value;
4141
4242
// test auto import

playground/tsconfig.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
{
2-
"extends": "./.nuxt/tsconfig.json"
2+
// https://nuxt.com/docs/guide/concepts/typescript
3+
"files": [],
4+
"references": [
5+
{
6+
"path": "./.nuxt/tsconfig.app.json"
7+
},
8+
{
9+
"path": "./.nuxt/tsconfig.server.json"
10+
},
11+
{
12+
"path": "./.nuxt/tsconfig.shared.json"
13+
},
14+
{
15+
"path": "./.nuxt/tsconfig.node.json"
16+
}
17+
]
318
}

src/generate.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
createResolver,
1717
} from '@nuxt/kit';
1818
import { kebabCase, pascalCase, toMerged } from 'es-toolkit';
19-
import type { Alias } from 'vite';
2019

2120
type GenerateArgs = {
2221
moduleConfig: ResolvedConfig;
@@ -302,7 +301,7 @@ declare module "${nitroClientModule}" {
302301
} from '${resolver.resolve('./runtime/server')}';
303302
export const handleFetchPathParams: typeof import('${resolver.resolve('./runtime/server')}')['handleFetchPathParams']
304303
export const ensureArray: typeof import('${resolver.resolve('./runtime/server')}')['ensureArray']
305-
${allClientExports.join('\n')}
304+
${allClientExports.join('\n ')}
306305
}`;
307306
},
308307
write: true,
@@ -406,22 +405,12 @@ const resolveClientConfig = (
406405

407406
/** only add alias to app, but not to server. this is different from `nuxt.options.alias` */
408407
const addAppAlias = (nuxt: Nuxt, alias: string, actual: string) => {
409-
nuxt.hook('prepare:types', (options) => {
410-
options.tsConfig.compilerOptions ??= {};
411-
options.tsConfig.compilerOptions.paths ??= {};
412-
options.tsConfig.compilerOptions.paths[alias] = [actual];
413-
options.tsConfig.compilerOptions.paths[`${alias}/*`] = [`${actual}/*`];
414-
});
415-
416-
nuxt.hook('vite:extendConfig', (config) => {
417-
config.resolve ??= {};
418-
419-
if (Array.isArray(config.resolve.alias)) {
420-
const array = config.resolve.alias as Alias[];
421-
array.push({ find: alias, replacement: actual });
422-
} else {
423-
config.resolve.alias ??= {};
424-
(config.resolve.alias as Record<string, string>)[alias] = actual;
408+
nuxt.options.alias ??= {};
409+
nuxt.options.alias[alias] = actual;
410+
nuxt.hook('nitro:config', (options) => {
411+
if (options.alias) {
412+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
413+
delete options.alias[alias];
425414
}
426415
});
427416
};

0 commit comments

Comments
 (0)