Skip to content

Commit c5d7fa9

Browse files
committed
fix(nuxt): generate nuxt module builder layout
1 parent 97bc45b commit c5d7fa9

6 files changed

Lines changed: 48 additions & 29 deletions

File tree

packages/nuxt/nuxt.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
// only to resolve runtime plugin types on local, not shipped
22
declare module '#imports' {
3-
export { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'
3+
export interface RuntimeConfig {
4+
public: {
5+
devframe: {
6+
baseURL: string
7+
}
8+
}
9+
}
10+
11+
export { defineNuxtPlugin } from 'nuxt/app'
12+
export const useRuntimeConfig: () => RuntimeConfig
413
}

packages/nuxt/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
],
2020
"sideEffects": false,
2121
"exports": {
22-
".": "./dist/index.mjs",
22+
".": {
23+
"types": "./dist/types.d.mts",
24+
"default": "./dist/module.mjs"
25+
},
2326
"./package.json": "./package.json"
2427
},
25-
"types": "./dist/index.d.mts",
28+
"types": "./dist/types.d.mts",
2629
"files": [
2730
"dist"
2831
],
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export interface DevframeNuxtModuleOptions {
4949
}
5050
}
5151

52+
export type ModuleOptions = DevframeNuxtModuleOptions
53+
5254
/**
5355
* Nuxt module that wires a Nuxt-built SPA up as a devframe client, and
5456
* (optionally) serves the dev-time RPC bridge alongside `nuxt dev`.
@@ -80,9 +82,9 @@ export interface DevframeNuxtModuleOptions {
8082
* }
8183
* ```
8284
*/
83-
export default defineNuxtModule<DevframeNuxtModuleOptions>({
85+
export default defineNuxtModule<ModuleOptions>({
8486
meta: {
85-
name: 'devframe',
87+
name: '@devframes/nuxt',
8688
configKey: 'devframe',
8789
},
8890
defaults: {
@@ -108,10 +110,12 @@ export default defineNuxtModule<DevframeNuxtModuleOptions>({
108110
nuxt.options.runtimeConfig ??= {} as any
109111
nuxt.options.runtimeConfig.public ??= {} as any
110112
const publicConfig = nuxt.options.runtimeConfig.public as Record<string, any>
111-
publicConfig.devframe = {
112-
...(publicConfig.devframe ?? {}),
113+
114+
// override baseURL
115+
publicConfig.devframe ??= {}
116+
Object.assign(publicConfig.devframe, publicConfig.devframe ?? {}, {
113117
baseURL: options.baseURL,
114-
}
118+
})
115119

116120
const runtimeDir = resolve('./runtime')
117121

packages/nuxt/src/runtime/plugin.client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { defineNuxtPlugin, useRuntimeConfig } from '#imports'
77
*/
88
export default defineNuxtPlugin({
99
async setup() {
10-
const config = useRuntimeConfig()
11-
const baseURL = (config.public as any)?.devframe?.baseURL ?? './'
10+
const baseURL = useRuntimeConfig().public.devframe.baseURL ?? './'
1211
const rpc = await connectDevframe({ baseURL })
1312
return {
1413
provide: {

packages/nuxt/tsdown.config.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import fs from 'node:fs/promises'
2+
import { createRequire } from 'node:module'
23
import { defineConfig } from 'tsdown'
34

5+
const require = createRequire(import.meta.url)
6+
47
export default defineConfig([{
5-
entry: './src/index.ts',
8+
entry: './src/module.ts',
69
// tsconfig: '../../tsconfig.base.json',
710
clean: true,
811
dts: true,
9-
exports: true,
12+
exports: false,
1013
// Keep transitive Nuxt/Vite type graphs out of dts bundling. Consumers
1114
// resolve these via their own node_modules at install time.
1215
deps: {
@@ -39,7 +42,8 @@ export default defineConfig([{
3942
},
4043
hooks: {
4144
'build:done': async () => {
42-
// copy types and generate plugin dts
45+
const { name, version, devDependencies } = require('./package.json')
46+
// copy types and generate plugin d.ts, module types.d.mts and module.json files
4347
await Promise.all([
4448
fs.cp('src/runtime/types.d.ts', 'dist/runtime/types.d.ts'),
4549
fs.writeFile('dist/runtime/plugin.client.d.ts', `import type { Plugin } from '#app';
@@ -48,6 +52,19 @@ declare const plugin: Plugin<{
4852
rpc: DevToolsRpcClient;
4953
}>;
5054
export default plugin;
55+
`, 'utf-8'),
56+
fs.writeFile('dist/types.d.mts', `export { default } from './module.mjs'
57+
58+
export { type ModuleOptions, type DevframeNuxtModuleOptions } from './module.mjs'
59+
`, 'utf-8'),
60+
fs.writeFile('dist/module.json', `{
61+
"name": "${name}",
62+
"configKey": "devframe",
63+
"version": "${version}",
64+
"builder": {
65+
"tsdown": "${devDependencies.tsdown}"
66+
}
67+
}
5168
`, 'utf-8'),
5269
])
5370
},
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
/**
22
* Generated by tsnapi — public API snapshot of `@devframes/nuxt`
33
*/
4-
// #region Interfaces
5-
export interface DevframeNuxtModuleOptions {
6-
baseURL?: string;
7-
skipAppDefaults?: boolean;
8-
devframe?: DevframeDefinition;
9-
devMiddleware?: boolean | {
10-
port?: number;
11-
host?: string;
12-
flags?: Record<string, unknown>;
13-
};
14-
}
15-
// #endregion
16-
17-
// #region Default Export
18-
declare const _default: _$_nuxt_schema0.NuxtModule<DevframeNuxtModuleOptions, DevframeNuxtModuleOptions, false>;
19-
export default _default
4+
// #region Re-exports
5+
export { default } from './module.mjs'
6+
export { type ModuleOptions, type DevframeNuxtModuleOptions } from './module.mjs'
207
// #endregion

0 commit comments

Comments
 (0)