File tree Expand file tree Collapse file tree
tests/__snapshots__/tsnapi/@devframes/nuxt Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // only to resolve runtime plugin types on local, not shipped
2+ declare module '#imports' {
3+ export { defineNuxtPlugin , useRuntimeConfig } from 'nuxt/app'
4+ }
Original file line number Diff line number Diff line change 2020 "sideEffects" : false ,
2121 "exports" : {
2222 "." : " ./dist/index.mjs" ,
23- "./runtime/plugin.client" : " ./dist/runtime/plugin.client.mjs" ,
2423 "./package.json" : " ./package.json"
2524 },
26- "types" : " ./dist/index.d.ts " ,
25+ "types" : " ./dist/index.d.mts " ,
2726 "files" : [
2827 " dist"
2928 ],
3332 "prepack" : " pnpm run build"
3433 },
3534 "peerDependencies" : {
36- "@nuxt/kit" : " ^3.0.0 || ^4.0.0" ,
35+ "@nuxt/kit" : " ^3.0.0 || ^4.0.0 || ^5.0.0-0 " ,
3736 "devframe" : " workspace:*"
3837 },
3938 "devDependencies" : {
4039 "@nuxt/kit" : " catalog:build" ,
40+ "@types/node" : " catalog:types" ,
41+ "devframe" : " workspace:*" ,
42+ "nuxt" : " catalog:build" ,
4143 "tsdown" : " catalog:build"
4244 }
4345}
Original file line number Diff line number Diff line change @@ -113,8 +113,14 @@ export default defineNuxtModule<DevframeNuxtModuleOptions>({
113113 baseURL : options . baseURL ,
114114 }
115115
116+ const runtimeDir = resolve ( './runtime' )
117+
118+ nuxt . hook ( 'prepare:types' , ( { references } ) => {
119+ references . push ( { path : resolve ( runtimeDir , 'types' ) } )
120+ } )
121+
116122 addPlugin ( {
117- src : resolve ( './runtime/ plugin.client') ,
123+ src : resolve ( runtimeDir , ' plugin.client') ,
118124 mode : 'client' ,
119125 } )
120126
Original file line number Diff line number Diff line change 1- import type { DevToolsRpcClient } from 'devframe/client'
21import { connectDevframe } from 'devframe/client'
3- // `#app` is a Nuxt virtual module; types resolve via `@nuxt/schema`.
4- import { defineNuxtPlugin , useRuntimeConfig } from '#app'
2+ import { defineNuxtPlugin , useRuntimeConfig } from '#imports'
53
64/**
75 * Nuxt client plugin that calls `connectDevframe()` once on the client
86 * and provides the RPC client as `$rpc` / `useNuxtApp().$rpc`.
97 */
10- export default defineNuxtPlugin ( async ( ) => {
11- const config = useRuntimeConfig ( )
12- const baseURL = ( config . public as any ) ?. devframe ?. baseURL ?? './'
13- const rpc = await connectDevframe ( { baseURL } )
14- return {
15- provide : {
16- rpc : rpc as DevToolsRpcClient ,
17- } ,
18- }
8+ export default defineNuxtPlugin ( {
9+ async setup ( ) {
10+ const config = useRuntimeConfig ( )
11+ const baseURL = ( config . public as any ) ?. devframe ?. baseURL ?? './'
12+ const rpc = await connectDevframe ( { baseURL } )
13+ return {
14+ provide : {
15+ rpc : rpc as import ( 'devframe/client' ) . DevToolsRpcClient ,
16+ } ,
17+ }
18+ } ,
1919} )
Original file line number Diff line number Diff line change 22 "extends" : " ../../tsconfig.base.json" ,
33 "compilerOptions" : {
44 "composite" : true ,
5- "lib" : [" esnext" , " dom" ]
6- }
5+ "lib" : [" esnext" , " dom" ],
6+ "types" : [" node" ]
7+ },
8+ "include" : [" nuxt.d.ts" , " src/**/*.ts" , " ../devframe/src/**/*.ts" ]
79}
Original file line number Diff line number Diff line change 1+ import fs from 'node:fs/promises'
12import { defineConfig } from 'tsdown'
23
3- export default defineConfig ( {
4- entry : {
5- 'index' : 'src/index.ts' ,
6- 'runtime/plugin.client' : 'src/runtime/plugin.client.ts' ,
7- } ,
8- tsconfig : '../../tsconfig.base.json' ,
4+ export default defineConfig ( [ {
5+ entry : './src/index.ts' ,
6+ // tsconfig: '../../tsconfig.base.json',
97 clean : true ,
108 dts : true ,
119 exports : true ,
@@ -21,4 +19,37 @@ export default defineConfig({
2119 'scule' ,
2220 ] ,
2321 } ,
24- } )
22+ } , {
23+ // just transpile the plugin to esm: we don't need the runtime at subpackage exports
24+ entry : {
25+ 'runtime/plugin.client' : 'src/runtime/plugin.client.ts' ,
26+ } ,
27+ outExtensions : ( ) => ( {
28+ js : '.js' ,
29+ } ) ,
30+ platform : 'browser' ,
31+ clean : false ,
32+ dts : false ,
33+ exports : false ,
34+ deps : {
35+ neverBundle : [
36+ '#imports' ,
37+ 'nuxt/app' ,
38+ ] ,
39+ } ,
40+ hooks : {
41+ 'build:done' : async ( ) => {
42+ // copy types and generate plugin dts
43+ await Promise . all ( [
44+ fs . cp ( 'src/runtime/types.d.ts' , 'dist/runtime/types.d.ts' ) ,
45+ fs . writeFile ( 'dist/runtime/plugin.client.d.ts' , `import type { Plugin } from '#app';
46+ import type { DevToolsRpcClient } from 'devframe/client';
47+ declare const plugin: Plugin<{
48+ rpc: DevToolsRpcClient;
49+ }>;
50+ export default plugin;
51+ ` , 'utf-8' ) ,
52+ ] )
53+ } ,
54+ } ,
55+ } ] )
You can’t perform that action at this time.
0 commit comments