@nuxt/module-builder 0.5.3 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,7 +42,7 @@ The entrypoint for module definition.
42
42
 
43
43
  A default export using `defineNuxtModule` and `ModuleOptions` type export is expected.
44
44
 
45
- You could also optionally export `ModuleHooks` to annotate any custom hooks the module uses.
45
+ You could also optionally export `ModuleHooks` or `ModuleRuntimeHooks` to annotate any custom hooks the module uses.
46
46
 
47
47
  ```ts [src/module.ts]
48
48
  import { defineNuxtModule } from '@nuxt/kit'
@@ -55,14 +55,18 @@ export interface ModuleHooks {
55
55
  'my-module:init': any
56
56
  }
57
57
 
58
- export interface ModulePublicRuntimeConfig {
59
- NAME: string
58
+ export interface ModuleRuntimeHooks {
59
+ 'my-module:runtime-hook': any
60
60
  }
61
61
 
62
- export interface ModulePrivateRuntimeConfig {
62
+ export interface ModuleRuntimeConfig {
63
63
  PRIVATE_NAME: string
64
64
  }
65
65
 
66
+ export interface ModulePublicRuntimeConfig {
67
+ NAME: string
68
+ }
69
+
66
70
  export default defineNuxtModule<ModuleOptions>({
67
71
  meta: {
68
72
  name: 'my-module',
@@ -141,7 +145,6 @@ Module builder generates dist files in `dist/` directory:
141
145
 
142
146
  [MIT](./LICENSE) - Made with 💚
143
147
 
144
-
145
148
  <!-- Badges -->
146
149
  [npm-version-src]: https://img.shields.io/npm/v/@nuxt/module-builder/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
147
150
  [npm-version-href]: https://npmjs.com/package/@nuxt/module-builder
@@ -73,7 +73,7 @@ const build = defineCommand({
73
73
  if (!moduleFn) {
74
74
  return;
75
75
  }
76
- const moduleMeta = await moduleFn.getMeta();
76
+ const moduleMeta = await moduleFn.getMeta?.() || {};
77
77
  if (ctx.pkg) {
78
78
  if (!moduleMeta.name) {
79
79
  moduleMeta.name = ctx.pkg.name;
@@ -106,6 +106,7 @@ async function writeTypes(distDir, meta) {
106
106
  )
107
107
  );
108
108
  const isStub = moduleTypes.includes("export *");
109
+ const appShims = [];
109
110
  const schemaShims = [];
110
111
  const moduleImports = [];
111
112
  const hasTypeExport = (name) => isStub || typeExports.find((exp) => exp.names.includes(name));
@@ -118,6 +119,18 @@ async function writeTypes(distDir, meta) {
118
119
  moduleImports.push("ModuleHooks");
119
120
  schemaShims.push(" interface NuxtHooks extends ModuleHooks {}");
120
121
  }
122
+ if (hasTypeExport("RuntimeModuleHooks") || hasTypeExport("ModuleRuntimeHooks")) {
123
+ const runtimeHooksInterfaces = [];
124
+ if (hasTypeExport("RuntimeModuleHooks")) {
125
+ consola.warn("`RuntimeModuleHooks` is a deprecated naming and will be removed in the future. Please use `ModuleRuntimeHooks` instead.");
126
+ runtimeHooksInterfaces.push("RuntimeModuleHooks");
127
+ }
128
+ if (hasTypeExport("ModuleRuntimeHooks")) {
129
+ runtimeHooksInterfaces.push("ModuleRuntimeHooks");
130
+ }
131
+ moduleImports.push(...runtimeHooksInterfaces);
132
+ appShims.push(` interface RuntimeNuxtHooks extends ${runtimeHooksInterfaces.join(", ")} {}`);
133
+ }
121
134
  if (hasTypeExport("ModuleRuntimeConfig")) {
122
135
  moduleImports.push("ModuleRuntimeConfig");
123
136
  schemaShims.push(" interface RuntimeConfig extends ModuleRuntimeConfig {}");
@@ -127,8 +140,12 @@ async function writeTypes(distDir, meta) {
127
140
  schemaShims.push(" interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}");
128
141
  }
129
142
  const dtsContents = `
130
- import { ${moduleImports.join(", ")} } from './module'
143
+ import type { ${moduleImports.join(", ")} } from './module'
131
144
 
145
+ ${appShims.length ? `declare module '#app' {
146
+ ${appShims.join("\n")}
147
+ }
148
+ ` : ""}
132
149
  ${schemaShims.length ? `declare module '@nuxt/schema' {
133
150
  ${schemaShims.join("\n")}
134
151
  }
@@ -138,11 +155,11 @@ ${schemaShims.join("\n")}
138
155
  }
139
156
  ` : ""}
140
157
 
141
- export { ${typeExports[0].names.join(", ")} } from './module'
158
+ export type { ${typeExports[0].names.join(", ")} } from './module'
142
159
  `;
143
160
  await promises.writeFile(dtsFile, dtsContents, "utf8");
144
161
  if (!existsSync(dtsFileMts)) {
145
- await promises.writeFile(dtsFileMts, dtsContents, "utf8");
162
+ await promises.writeFile(dtsFileMts, dtsContents.replaceAll("./module", "./module.js"), "utf8");
146
163
  }
147
164
  }
148
165
  async function writeCJSStub(distDir) {
package/dist/cli.mjs CHANGED
@@ -3,7 +3,7 @@ import { defineCommand, runMain } from 'citty';
3
3
  import { consola } from 'consola';
4
4
 
5
5
  const name = "@nuxt/module-builder";
6
- const version = "0.5.3";
6
+ const version = "0.5.5";
7
7
  const description = "Complete solution for building Nuxt modules";
8
8
 
9
9
  const _rDefault = (r) => r.default || r;
@@ -19,7 +19,7 @@ const main = defineCommand({
19
19
  },
20
20
  setup(context) {
21
21
  const firstArg = context.rawArgs[0];
22
- if (!(firstArg in context.cmd.subCommands)) {
22
+ if (context.cmd.subCommands && !(firstArg in context.cmd.subCommands)) {
23
23
  consola.warn("Please specify the `build` command explicitly. In a future version of `@nuxt/module-builder`, the implicit default build command will be removed.");
24
24
  context.rawArgs.unshift("build");
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/module-builder",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "repository": "nuxt/module-builder",
5
5
  "description": "Complete solution for building Nuxt modules",
6
6
  "license": "MIT",
@@ -19,37 +19,38 @@
19
19
  "files": [
20
20
  "dist"
21
21
  ],
22
- "packageManager": "pnpm@8.10.2",
22
+ "packageManager": "pnpm@8.12.1",
23
23
  "dependencies": {
24
- "citty": "^0.1.4",
24
+ "citty": "^0.1.5",
25
25
  "consola": "^3.2.3",
26
26
  "mlly": "^1.4.2",
27
27
  "pathe": "^1.1.1",
28
28
  "unbuild": "^2.0.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "@nuxt/kit": "^3.8.0",
32
- "nuxi": "^3.9.1"
31
+ "@nuxt/kit": "^3.8.2",
32
+ "nuxi": "^3.10.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@nuxt/kit": "^3.8.0",
36
- "@nuxt/schema": "^3.8.0",
35
+ "@nuxt/kit": "^3.8.2",
36
+ "@nuxt/schema": "^3.8.2",
37
37
  "@nuxtjs/eslint-config-typescript": "^12.1.0",
38
- "@types/node": "^20.8.10",
39
- "@vitest/coverage-v8": "^0.34.6",
38
+ "@types/node": "^20.10.5",
39
+ "@vitest/coverage-v8": "^1.1.0",
40
40
  "changelogen": "^0.5.5",
41
- "eslint": "^8.53.0",
41
+ "eslint": "^8.56.0",
42
42
  "jiti": "^1.21.0",
43
- "nuxi": "^3.9.1",
44
- "nuxt": "^3.8.0",
45
- "vitest": "^0.34.6"
43
+ "nuxi": "^3.10.0",
44
+ "nuxt": "^3.8.2",
45
+ "vitest": "^1.1.0"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "unbuild",
49
- "example:build": "pnpm nuxt-module-build ./example",
49
+ "example:build": "pnpm nuxt-module-build build ./example",
50
50
  "lint": "eslint --ext .ts,.js,.mjs .",
51
51
  "nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
52
52
  "release": "pnpm vitest run && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
53
- "test": "pnpm vitest"
53
+ "test": "pnpm vitest",
54
+ "test:types": "tsc --noEmit && pnpm -r test:types"
54
55
  }
55
56
  }