Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/nuxt/nuxt.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
// only to resolve runtime plugin types on local, not shipped
declare module '#imports' {
export { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'
export interface RuntimeConfig {
public: {
devframe: {
baseURL: string
}
}
}

export { defineNuxtPlugin } from 'nuxt/app'
export const useRuntimeConfig: () => RuntimeConfig
}
7 changes: 5 additions & 2 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
],
"sideEffects": false,
"exports": {
".": "./dist/index.mjs",
".": {
"types": "./dist/types.d.mts",
"default": "./dist/module.mjs"
},
"./package.json": "./package.json"
},
"types": "./dist/index.d.mts",
"types": "./dist/types.d.mts",
"files": [
"dist"
],
Expand Down
14 changes: 9 additions & 5 deletions packages/nuxt/src/index.ts → packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface DevframeNuxtModuleOptions {
}
}

export type ModuleOptions = DevframeNuxtModuleOptions

/**
* Nuxt module that wires a Nuxt-built SPA up as a devframe client, and
* (optionally) serves the dev-time RPC bridge alongside `nuxt dev`.
Expand Down Expand Up @@ -80,9 +82,9 @@ export interface DevframeNuxtModuleOptions {
* }
* ```
*/
export default defineNuxtModule<DevframeNuxtModuleOptions>({
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'devframe',
name: '@devframes/nuxt',
configKey: 'devframe',
},
defaults: {
Expand All @@ -108,10 +110,12 @@ export default defineNuxtModule<DevframeNuxtModuleOptions>({
nuxt.options.runtimeConfig ??= {} as any
nuxt.options.runtimeConfig.public ??= {} as any
const publicConfig = nuxt.options.runtimeConfig.public as Record<string, any>
publicConfig.devframe = {
...(publicConfig.devframe ?? {}),

// override baseURL
publicConfig.devframe ??= {}
Object.assign(publicConfig.devframe, publicConfig.devframe ?? {}, {
baseURL: options.baseURL,
}
})

const runtimeDir = resolve('./runtime')

Expand Down
3 changes: 1 addition & 2 deletions packages/nuxt/src/runtime/plugin.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { defineNuxtPlugin, useRuntimeConfig } from '#imports'
*/
export default defineNuxtPlugin({
async setup() {
const config = useRuntimeConfig()
const baseURL = (config.public as any)?.devframe?.baseURL ?? './'
const baseURL = useRuntimeConfig().public.devframe.baseURL ?? './'
const rpc = await connectDevframe({ baseURL })
return {
provide: {
Expand Down
23 changes: 20 additions & 3 deletions packages/nuxt/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import fs from 'node:fs/promises'
import { createRequire } from 'node:module'
import { defineConfig } from 'tsdown'

const require = createRequire(import.meta.url)

export default defineConfig([{
entry: './src/index.ts',
entry: './src/module.ts',
// tsconfig: '../../tsconfig.base.json',
clean: true,
dts: true,
exports: true,
exports: false,
// Keep transitive Nuxt/Vite type graphs out of dts bundling. Consumers
// resolve these via their own node_modules at install time.
deps: {
Expand Down Expand Up @@ -39,7 +42,8 @@ export default defineConfig([{
},
hooks: {
'build:done': async () => {
// copy types and generate plugin dts
const { name, version, devDependencies } = require('./package.json')
// copy types and generate plugin d.ts, module types.d.mts and module.json files
await Promise.all([
fs.cp('src/runtime/types.d.ts', 'dist/runtime/types.d.ts'),
fs.writeFile('dist/runtime/plugin.client.d.ts', `import type { Plugin } from '#app';
Expand All @@ -48,6 +52,19 @@ declare const plugin: Plugin<{
rpc: DevToolsRpcClient;
}>;
export default plugin;
`, 'utf-8'),
fs.writeFile('dist/types.d.mts', `export { default } from './module.mjs';

export { type ModuleOptions, type DevframeNuxtModuleOptions } from './module.mjs';
`, 'utf-8'),
fs.writeFile('dist/module.json', `{
"name": "${name}",
"configKey": "devframe",
"version": "${version}",
"builder": {
"tsdown": "${devDependencies.tsdown}"
Copy link
Copy Markdown
Contributor Author

@userquin userquin May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should remove the ^ if present

Copy link
Copy Markdown
Contributor Author

@userquin userquin May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to review the version, maybe we need to load pnpm workspace and find the tsdown version in the correspoding catalog

}
}
`, 'utf-8'),
])
},
Expand Down
19 changes: 3 additions & 16 deletions tests/__snapshots__/tsnapi/@devframes/nuxt/index.snapshot.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
/**
* Generated by tsnapi — public API snapshot of `@devframes/nuxt`
*/
// #region Interfaces
export interface DevframeNuxtModuleOptions {
baseURL?: string;
skipAppDefaults?: boolean;
devframe?: DevframeDefinition;
devMiddleware?: boolean | {
port?: number;
host?: string;
flags?: Record<string, unknown>;
};
}
// #endregion

// #region Default Export
declare const _default: _$_nuxt_schema0.NuxtModule<DevframeNuxtModuleOptions, DevframeNuxtModuleOptions, false>;
export default _default
// #region Re-exports
export { default } from './module.mjs';
export { type ModuleOptions, type DevframeNuxtModuleOptions } from './module.mjs';
// #endregion
Loading