@nuxt/module-builder 0.7.1 → 0.8.1

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.78aa584a.mjs';
15
13
 
16
14
  const build = defineCommand({
17
15
  meta: {
@@ -144,51 +142,37 @@ 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, ctx.options.stub);
158
146
  }
159
147
  }
160
148
  });
161
149
  }
162
150
  });
163
- async function writeTypes(distDir, meta, getOptions) {
151
+ async function writeTypes(distDir, isStub) {
164
152
  const dtsFile = resolve(distDir, "types.d.ts");
165
153
  const dtsFileMts = resolve(distDir, "types.d.mts");
166
154
  if (existsSync(dtsFile)) {
167
155
  return;
168
156
  }
169
- const moduleTypesFile = resolve(distDir, "module.d.ts");
170
- const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
171
- const typeExports = findExports(
172
- // Replace `export { type Foo }` with `export { Foo }`
173
- moduleTypes.replace(
174
- /export\s*\{.*?\}/gs,
175
- (match) => match.replace(/\btype\b/g, "")
176
- )
177
- );
178
- const isStub = moduleTypes.includes("export *");
157
+ const moduleReExports = [];
158
+ if (!isStub) {
159
+ const moduleTypesFile = resolve(distDir, "module.d.ts");
160
+ const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
161
+ const normalisedModuleTypes = moduleTypes.replace(/export\s*\{.*?\}/gs, (match) => match.replace(/\b(type|interface)\b/g, ""));
162
+ for (const e of findExports(normalisedModuleTypes)) {
163
+ moduleReExports.push(e);
164
+ }
165
+ }
179
166
  const appShims = [];
180
167
  const schemaShims = [];
181
168
  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
- }
169
+ const schemaImports = [];
170
+ const moduleExports = [];
171
+ const hasTypeExport = (name2) => isStub || moduleReExports.find((exp) => exp.names.includes(name2));
172
+ if (!hasTypeExport("ModuleOptions")) {
173
+ schemaImports.push("NuxtModule");
174
+ moduleImports.push("default as Module");
175
+ moduleExports.push(`export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>`);
192
176
  }
193
177
  if (hasTypeExport("ModuleHooks")) {
194
178
  moduleImports.push("ModuleHooks");
@@ -211,9 +195,10 @@ async function writeTypes(distDir, meta, getOptions) {
211
195
  schemaShims.push(" interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}");
212
196
  }
213
197
  const dtsContents = `
214
- import type { ${moduleImports.join(", ")} } from './module'
198
+ ${schemaImports.length ? `import type { ${schemaImports.join(", ")} } from '@nuxt/schema'` : ""}
199
+
200
+ ${moduleImports.length ? `import type { ${moduleImports.join(", ")} } from './module'` : ""}
215
201
 
216
- ${moduleDeclarations.join("\n")}
217
202
  ${appShims.length ? `declare module '#app' {
218
203
  ${appShims.join("\n")}
219
204
  }
@@ -226,9 +211,12 @@ ${schemaShims.length ? `declare module 'nuxt/schema' {
226
211
  ${schemaShims.join("\n")}
227
212
  }
228
213
  ` : ""}
229
- ${typeExports[0] ? `
230
- export type { ${typeExports[0].names.join(", ")} } from './module'` : ""}
231
- `;
214
+ ${moduleExports.length ? `
215
+ ${moduleExports.join("\n")}` : ""}
216
+ ${isStub ? 'export * from "./module"' : ""}
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.78aa584a.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.78aa584a.mjs';
@@ -1,5 +1,5 @@
1
1
  const name = "@nuxt/module-builder";
2
- const version = "0.7.1";
2
+ const version = "0.8.1";
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.1",
4
4
  "repository": "nuxt/module-builder",
5
5
  "description": "Complete solution for building Nuxt modules",
6
6
  "license": "MIT",
@@ -27,34 +27,33 @@
27
27
  "mlly": "^1.7.1",
28
28
  "pathe": "^1.1.2",
29
29
  "pkg-types": "^1.1.1",
30
- "tsconfck": "^3.1.0",
31
- "unbuild": "^2.0.0",
32
- "untyped": "^1.4.2"
30
+ "tsconfck": "^3.1.1",
31
+ "unbuild": "^2.0.0"
33
32
  },
34
33
  "peerDependencies": {
35
- "@nuxt/kit": "^3.12.1",
34
+ "@nuxt/kit": "^3.12.2",
36
35
  "nuxi": "^3.12.0"
37
36
  },
38
37
  "devDependencies": {
39
38
  "@nuxt/eslint-config": "^0.3.13",
40
- "@nuxt/kit": "^3.12.1",
41
- "@nuxt/schema": "^3.12.1",
42
- "@types/node": "^20.14.2",
39
+ "@nuxt/kit": "^3.12.2",
40
+ "@nuxt/schema": "^3.12.2",
41
+ "@types/node": "^20.14.9",
43
42
  "@vitest/coverage-v8": "^1.6.0",
44
43
  "changelogen": "^0.5.5",
45
- "eslint": "^9.4.0",
44
+ "eslint": "^9.5.0",
46
45
  "jiti": "^1.21.6",
47
46
  "nuxi": "^3.12.0",
48
- "nuxt": "^3.12.1",
49
- "typescript": "^5.4.5",
47
+ "nuxt": "^3.12.2",
48
+ "typescript": "^5.5.2",
50
49
  "vitest": "^1.6.0",
51
- "vue": "^3.4.27",
52
- "vue-tsc": "^2.0.19"
50
+ "vue": "^3.4.31",
51
+ "vue-tsc": "^2.0.22"
53
52
  },
54
53
  "resolutions": {
55
- "@nuxt/kit": "^3.12.1",
56
- "@nuxt/schema": "^3.12.1",
57
- "vue": "^3.4.27"
54
+ "@nuxt/kit": "^3.12.2",
55
+ "@nuxt/schema": "^3.12.2",
56
+ "vue": "^3.4.31"
58
57
  },
59
58
  "scripts": {
60
59
  "build": "unbuild",