@nuxt/module-builder 0.7.1 → 0.8.0

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.
@@ -8,10 +8,8 @@ import { defu } from 'defu';
8
8
  import { createRegExp, anyOf } from 'magic-regexp';
9
9
  import { consola } from 'consola';
10
10
  import { resolvePath, findExports } from 'mlly';
11
- import { generateTypes, resolveSchema } from 'untyped';
12
11
  import { defineCommand } from 'citty';
13
- import { loadNuxt } from '@nuxt/kit';
14
- import { n as name, v as version } from '../shared/module-builder.832f08b1.mjs';
12
+ import { n as name, v as version } from '../shared/module-builder.297ff45d.mjs';
15
13
 
16
14
  const build = defineCommand({
17
15
  meta: {
@@ -144,23 +142,13 @@ const build = defineCommand({
144
142
  };
145
143
  const metaFile = resolve(ctx.options.outDir, "module.json");
146
144
  await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
147
- await writeTypes(ctx.options.outDir, moduleMeta, async () => {
148
- const nuxt = await loadNuxt({
149
- cwd,
150
- overrides: {
151
- modules: [resolve(cwd, "./src/module")]
152
- }
153
- });
154
- const moduleOptions = await moduleFn.getOptions?.({}, nuxt) || {};
155
- await nuxt.close();
156
- return moduleOptions;
157
- });
145
+ await writeTypes(ctx.options.outDir);
158
146
  }
159
147
  }
160
148
  });
161
149
  }
162
150
  });
163
- async function writeTypes(distDir, meta, getOptions) {
151
+ async function writeTypes(distDir) {
164
152
  const dtsFile = resolve(distDir, "types.d.ts");
165
153
  const dtsFileMts = resolve(distDir, "types.d.mts");
166
154
  if (existsSync(dtsFile)) {
@@ -168,27 +156,24 @@ async function writeTypes(distDir, meta, getOptions) {
168
156
  }
169
157
  const moduleTypesFile = resolve(distDir, "module.d.ts");
170
158
  const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
171
- const typeExports = findExports(
159
+ const moduleReExports = findExports(
172
160
  // Replace `export { type Foo }` with `export { Foo }`
173
161
  moduleTypes.replace(
174
162
  /export\s*\{.*?\}/gs,
175
- (match) => match.replace(/\btype\b/g, "")
163
+ (match) => match.replace(/\b(type|interface)\b/g, "")
176
164
  )
177
165
  );
178
166
  const isStub = moduleTypes.includes("export *");
179
167
  const appShims = [];
180
168
  const schemaShims = [];
181
169
  const moduleImports = [];
182
- const moduleDeclarations = [];
183
- const hasTypeExport = (name2) => isStub || typeExports.find((exp) => exp.names.includes(name2));
184
- if (meta.configKey) {
185
- schemaShims.push(` interface NuxtConfig { ['${meta.configKey}']?: Partial<ModuleOptions> }`);
186
- schemaShims.push(` interface NuxtOptions { ['${meta.configKey}']?: ModuleOptions }`);
187
- if (hasTypeExport("ModuleOptions")) {
188
- moduleImports.push("ModuleOptions");
189
- } else {
190
- moduleDeclarations.push(` ${generateTypes(await resolveSchema(await getOptions()), { interfaceName: "ModuleOptions" })}`);
191
- }
170
+ const schemaImports = [];
171
+ const moduleExports = [];
172
+ const hasTypeExport = (name2) => isStub || moduleReExports.find((exp) => exp.names.includes(name2));
173
+ if (!hasTypeExport("ModuleOptions")) {
174
+ schemaImports.push("NuxtModule");
175
+ moduleImports.push("default as Module");
176
+ moduleExports.push(`export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>`);
192
177
  }
193
178
  if (hasTypeExport("ModuleHooks")) {
194
179
  moduleImports.push("ModuleHooks");
@@ -211,9 +196,10 @@ async function writeTypes(distDir, meta, getOptions) {
211
196
  schemaShims.push(" interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}");
212
197
  }
213
198
  const dtsContents = `
214
- import type { ${moduleImports.join(", ")} } from './module'
199
+ ${schemaImports.length ? `import type { ${schemaImports.join(", ")} } from '@nuxt/schema'` : ""}
200
+
201
+ ${moduleImports.length ? `import type { ${moduleImports.join(", ")} } from './module'` : ""}
215
202
 
216
- ${moduleDeclarations.join("\n")}
217
203
  ${appShims.length ? `declare module '#app' {
218
204
  ${appShims.join("\n")}
219
205
  }
@@ -226,9 +212,11 @@ ${schemaShims.length ? `declare module 'nuxt/schema' {
226
212
  ${schemaShims.join("\n")}
227
213
  }
228
214
  ` : ""}
229
- ${typeExports[0] ? `
230
- export type { ${typeExports[0].names.join(", ")} } from './module'` : ""}
231
- `;
215
+ ${moduleExports.length ? `
216
+ ${moduleExports.join("\n")}` : ""}
217
+ ${moduleReExports[0] ? `
218
+ export { ${moduleReExports[0].names.map((n) => (n === "default" ? "" : "type ") + n).join(", ")} } from './module'` : ""}
219
+ `.trim().replace(/[\n\r]{3,}/g, "\n\n") + "\n";
232
220
  await promises.writeFile(dtsFile, dtsContents, "utf8");
233
221
  if (!existsSync(dtsFileMts)) {
234
222
  await promises.writeFile(dtsFileMts, dtsContents.replace(/\.\/module/g, "./module.js"), "utf8");
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
  import { consola } from 'consola';
4
- import { n as name, d as description, v as version } from './shared/module-builder.832f08b1.mjs';
4
+ import { n as name, d as description, v as version } from './shared/module-builder.297ff45d.mjs';
5
5
 
6
6
  const _rDefault = (r) => r && typeof r === "object" && "default" in r ? r.default : r;
7
7
  const main = defineCommand({
package/dist/index.mjs CHANGED
@@ -10,7 +10,5 @@ import 'defu';
10
10
  import 'magic-regexp';
11
11
  import 'consola';
12
12
  import 'mlly';
13
- import 'untyped';
14
13
  import 'citty';
15
- import '@nuxt/kit';
16
- import './shared/module-builder.832f08b1.mjs';
14
+ import './shared/module-builder.297ff45d.mjs';
@@ -1,5 +1,5 @@
1
1
  const name = "@nuxt/module-builder";
2
- const version = "0.7.1";
2
+ const version = "0.8.0";
3
3
  const description = "Complete solution for building Nuxt modules";
4
4
 
5
5
  export { description as d, name as n, version as v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/module-builder",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "repository": "nuxt/module-builder",
5
5
  "description": "Complete solution for building Nuxt modules",
6
6
  "license": "MIT",
@@ -19,6 +19,18 @@
19
19
  "files": [
20
20
  "dist"
21
21
  ],
22
+ "scripts": {
23
+ "build": "unbuild",
24
+ "dev:prepare": "pnpm -r dev:prepare",
25
+ "example:build": "pnpm nuxt-module-build build ./example",
26
+ "lint": "eslint .",
27
+ "nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
28
+ "prepack": "pnpm build",
29
+ "release": "pnpm vitest run && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
30
+ "test": "pnpm vitest",
31
+ "test:types": "vue-tsc --noEmit && pnpm -r test:types"
32
+ },
33
+ "packageManager": "pnpm@9.4.0",
22
34
  "dependencies": {
23
35
  "citty": "^0.1.6",
24
36
  "consola": "^3.2.3",
@@ -28,42 +40,31 @@
28
40
  "pathe": "^1.1.2",
29
41
  "pkg-types": "^1.1.1",
30
42
  "tsconfck": "^3.1.0",
31
- "unbuild": "^2.0.0",
32
- "untyped": "^1.4.2"
43
+ "unbuild": "^2.0.0"
33
44
  },
34
45
  "peerDependencies": {
35
- "@nuxt/kit": "^3.12.1",
46
+ "@nuxt/kit": "^3.12.2",
36
47
  "nuxi": "^3.12.0"
37
48
  },
38
49
  "devDependencies": {
39
50
  "@nuxt/eslint-config": "^0.3.13",
40
- "@nuxt/kit": "^3.12.1",
41
- "@nuxt/schema": "^3.12.1",
42
- "@types/node": "^20.14.2",
51
+ "@nuxt/kit": "^3.12.2",
52
+ "@nuxt/schema": "^3.12.2",
53
+ "@types/node": "^20.14.5",
43
54
  "@vitest/coverage-v8": "^1.6.0",
44
55
  "changelogen": "^0.5.5",
45
- "eslint": "^9.4.0",
56
+ "eslint": "^9.5.0",
46
57
  "jiti": "^1.21.6",
47
58
  "nuxi": "^3.12.0",
48
- "nuxt": "^3.12.1",
59
+ "nuxt": "^3.12.2",
49
60
  "typescript": "^5.4.5",
50
61
  "vitest": "^1.6.0",
51
- "vue": "^3.4.27",
52
- "vue-tsc": "^2.0.19"
62
+ "vue": "^3.4.29",
63
+ "vue-tsc": "^2.0.21"
53
64
  },
54
65
  "resolutions": {
55
- "@nuxt/kit": "^3.12.1",
56
- "@nuxt/schema": "^3.12.1",
57
- "vue": "^3.4.27"
58
- },
59
- "scripts": {
60
- "build": "unbuild",
61
- "dev:prepare": "pnpm -r dev:prepare",
62
- "example:build": "pnpm nuxt-module-build build ./example",
63
- "lint": "eslint .",
64
- "nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
65
- "release": "pnpm vitest run && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
66
- "test": "pnpm vitest",
67
- "test:types": "vue-tsc --noEmit && pnpm -r test:types"
66
+ "@nuxt/kit": "^3.12.2",
67
+ "@nuxt/schema": "^3.12.2",
68
+ "vue": "^3.4.29"
68
69
  }
69
- }
70
+ }