@nuxt/module-builder 0.5.5 → 0.7.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.
package/README.md CHANGED
@@ -100,6 +100,7 @@ A minimum `package.json` should look like this:
100
100
  "version": "1.0.0",
101
101
  "exports": {
102
102
  ".": {
103
+ "types": "./dist/types.d.ts",
103
104
  "import": "./dist/module.mjs",
104
105
  "require": "./dist/module.cjs"
105
106
  }
@@ -1,9 +1,17 @@
1
- import { promises, existsSync } from 'fs';
2
- import { pathToFileURL } from 'url';
3
- import { resolve } from 'pathe';
1
+ import { promises, existsSync } from 'node:fs';
2
+ import { pathToFileURL } from 'node:url';
3
+ import { resolve, basename, join, dirname } from 'pathe';
4
+ import { filename } from 'pathe/utils';
5
+ import { readPackageJSON } from 'pkg-types';
6
+ import { parse } from 'tsconfck';
7
+ import { defu } from 'defu';
8
+ import { createRegExp, anyOf } from 'magic-regexp';
4
9
  import { consola } from 'consola';
5
- import { findExports } from 'mlly';
10
+ import { resolvePath, findExports } from 'mlly';
11
+ import { generateTypes, resolveSchema } from 'untyped';
6
12
  import { defineCommand } from 'citty';
13
+ import { loadNuxt } from '@nuxt/kit';
14
+ import { n as name, v as version } from '../shared/module-builder.4be2741e.mjs';
7
15
 
8
16
  const build = defineCommand({
9
17
  meta: {
@@ -41,7 +49,17 @@ const build = defineCommand({
41
49
  outDir,
42
50
  entries: [
43
51
  "src/module",
44
- { input: "src/runtime/", outDir: `${outDir}/runtime`, ext: "mjs" }
52
+ {
53
+ input: "src/runtime/",
54
+ outDir: `${outDir}/runtime`,
55
+ addRelativeDeclarationExtensions: true,
56
+ ext: "js",
57
+ esbuild: {
58
+ jsxImportSource: "vue",
59
+ jsx: "automatic",
60
+ jsxFactory: "h"
61
+ }
62
+ }
45
63
  ],
46
64
  rollup: {
47
65
  esbuild: {
@@ -51,17 +69,55 @@ const build = defineCommand({
51
69
  cjsBridge: true
52
70
  },
53
71
  externals: [
72
+ /dist\/runtime\//,
54
73
  "@nuxt/schema",
74
+ "@nuxt/schema-nightly",
55
75
  "@nuxt/schema-edge",
56
76
  "@nuxt/kit",
77
+ "@nuxt/kit-nightly",
57
78
  "@nuxt/kit-edge",
58
79
  "nuxt",
80
+ "nuxt-nightly",
59
81
  "nuxt-edge",
60
82
  "nuxt3",
61
83
  "vue",
62
84
  "vue-demi"
63
85
  ],
64
86
  hooks: {
87
+ async "mkdist:entry:options"(_ctx, entry, options) {
88
+ options.typescript = defu(options.typescript, {
89
+ compilerOptions: await loadTSCompilerOptions(entry.input)
90
+ });
91
+ },
92
+ async "rollup:options"(ctx, options) {
93
+ options.plugins || (options.plugins = []);
94
+ if (!Array.isArray(options.plugins))
95
+ options.plugins = [options.plugins];
96
+ const runtimeEntries = ctx.options.entries.filter((entry) => entry.builder === "mkdist");
97
+ const runtimeDirs = runtimeEntries.map((entry) => basename(entry.input));
98
+ const RUNTIME_RE = createRegExp(anyOf(...runtimeDirs).and("/"));
99
+ options.plugins.unshift({
100
+ name: "nuxt-module-builder:runtime-externals",
101
+ async resolveId(id, importer) {
102
+ if (!RUNTIME_RE.test(id))
103
+ return;
104
+ const resolved = await this.resolve(id, importer, { skipSelf: true });
105
+ if (!resolved)
106
+ return;
107
+ for (const entry of runtimeEntries) {
108
+ if (!resolved.id.includes(entry.input))
109
+ continue;
110
+ const distFile = await resolvePath(join(dirname(resolved.id.replace(entry.input, entry.outDir)), filename(resolved.id)));
111
+ if (distFile) {
112
+ return {
113
+ external: true,
114
+ id: distFile
115
+ };
116
+ }
117
+ }
118
+ }
119
+ });
120
+ },
65
121
  async "rollup:done"(ctx) {
66
122
  await writeCJSStub(ctx.options.outDir);
67
123
  const moduleEntryPath = resolve(ctx.options.outDir, "module.mjs");
@@ -82,15 +138,29 @@ const build = defineCommand({
82
138
  moduleMeta.version = ctx.pkg.version;
83
139
  }
84
140
  }
141
+ moduleMeta.builder = {
142
+ [name]: version,
143
+ unbuild: await readPackageJSON("unbuild").then((r) => r.version).catch(() => "unknown")
144
+ };
85
145
  const metaFile = resolve(ctx.options.outDir, "module.json");
86
146
  await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
87
- await writeTypes(ctx.options.outDir, moduleMeta);
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
+ });
88
158
  }
89
159
  }
90
160
  });
91
161
  }
92
162
  });
93
- async function writeTypes(distDir, meta) {
163
+ async function writeTypes(distDir, meta, getOptions) {
94
164
  const dtsFile = resolve(distDir, "types.d.ts");
95
165
  const dtsFileMts = resolve(distDir, "types.d.mts");
96
166
  if (existsSync(dtsFile)) {
@@ -101,7 +171,7 @@ async function writeTypes(distDir, meta) {
101
171
  const typeExports = findExports(
102
172
  // Replace `export { type Foo }` with `export { Foo }`
103
173
  moduleTypes.replace(
104
- /export\s*{.*?}/sg,
174
+ /export\s*\{.*?\}/gs,
105
175
  (match) => match.replace(/\btype\b/g, "")
106
176
  )
107
177
  );
@@ -109,22 +179,20 @@ async function writeTypes(distDir, meta) {
109
179
  const appShims = [];
110
180
  const schemaShims = [];
111
181
  const moduleImports = [];
112
- const hasTypeExport = (name) => isStub || typeExports.find((exp) => exp.names.includes(name));
182
+ const hasTypeExport = (name2) => isStub || typeExports.find((exp) => exp.names.includes(name2));
113
183
  if (meta.configKey && hasTypeExport("ModuleOptions")) {
114
184
  moduleImports.push("ModuleOptions");
115
185
  schemaShims.push(` interface NuxtConfig { ['${meta.configKey}']?: Partial<ModuleOptions> }`);
116
186
  schemaShims.push(` interface NuxtOptions { ['${meta.configKey}']?: ModuleOptions }`);
187
+ } else if (meta.configKey) {
188
+ schemaShims.push(` ${generateTypes(await resolveSchema(await getOptions()), { interfaceName: "ModuleOptions" })}`);
117
189
  }
118
190
  if (hasTypeExport("ModuleHooks")) {
119
191
  moduleImports.push("ModuleHooks");
120
192
  schemaShims.push(" interface NuxtHooks extends ModuleHooks {}");
121
193
  }
122
- if (hasTypeExport("RuntimeModuleHooks") || hasTypeExport("ModuleRuntimeHooks")) {
194
+ if (hasTypeExport("ModuleRuntimeHooks")) {
123
195
  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
196
  if (hasTypeExport("ModuleRuntimeHooks")) {
129
197
  runtimeHooksInterfaces.push("ModuleRuntimeHooks");
130
198
  }
@@ -154,12 +222,12 @@ ${schemaShims.length ? `declare module 'nuxt/schema' {
154
222
  ${schemaShims.join("\n")}
155
223
  }
156
224
  ` : ""}
157
-
158
- export type { ${typeExports[0].names.join(", ")} } from './module'
225
+ ${typeExports[0] ? `
226
+ export type { ${typeExports[0].names.join(", ")} } from './module'` : ""}
159
227
  `;
160
228
  await promises.writeFile(dtsFile, dtsContents, "utf8");
161
229
  if (!existsSync(dtsFileMts)) {
162
- await promises.writeFile(dtsFileMts, dtsContents.replaceAll("./module", "./module.js"), "utf8");
230
+ await promises.writeFile(dtsFileMts, dtsContents.replace(/\.\/module/g, "./module.js"), "utf8");
163
231
  }
164
232
  }
165
233
  async function writeCJSStub(distDir) {
@@ -175,5 +243,19 @@ module.exports.getMeta = () => Promise.resolve(_meta)
175
243
  `;
176
244
  await promises.writeFile(cjsStubFile, cjsStub, "utf8");
177
245
  }
246
+ async function loadTSCompilerOptions(path) {
247
+ const config = await parse(path);
248
+ const resolvedCompilerOptions = config?.tsconfig.compilerOptions || {};
249
+ for (const { tsconfig, tsconfigFile } of config.extended || []) {
250
+ for (const alias in tsconfig.compilerOptions?.paths || {}) {
251
+ resolvedCompilerOptions.paths[alias] = resolvedCompilerOptions.paths[alias].map((p) => {
252
+ if (!/^\.{1,2}(?:\/|$)/.test(p))
253
+ return p;
254
+ return resolve(dirname(tsconfigFile), p);
255
+ });
256
+ }
257
+ }
258
+ return resolvedCompilerOptions;
259
+ }
178
260
 
179
261
  export { build as default };
package/dist/cli.mjs CHANGED
@@ -1,12 +1,9 @@
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.4be2741e.mjs';
4
5
 
5
- const name = "@nuxt/module-builder";
6
- const version = "0.5.5";
7
- const description = "Complete solution for building Nuxt modules";
8
-
9
- const _rDefault = (r) => r.default || r;
6
+ const _rDefault = (r) => r && typeof r === "object" && "default" in r ? r.default : r;
10
7
  const main = defineCommand({
11
8
  meta: {
12
9
  name,
@@ -19,7 +16,7 @@ const main = defineCommand({
19
16
  },
20
17
  setup(context) {
21
18
  const firstArg = context.rawArgs[0];
22
- if (context.cmd.subCommands && !(firstArg in context.cmd.subCommands)) {
19
+ if (context.cmd.subCommands && !(firstArg && firstArg in context.cmd.subCommands)) {
23
20
  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
21
  context.rawArgs.unshift("build");
25
22
  }
package/dist/index.mjs CHANGED
@@ -1,8 +1,16 @@
1
1
  export { default as build } from './chunks/build.mjs';
2
2
  export { default as prepare } from './chunks/prepare.mjs';
3
- import 'fs';
4
- import 'url';
3
+ import 'node:fs';
4
+ import 'node:url';
5
5
  import 'pathe';
6
+ import 'pathe/utils';
7
+ import 'pkg-types';
8
+ import 'tsconfck';
9
+ import 'defu';
10
+ import 'magic-regexp';
6
11
  import 'consola';
7
12
  import 'mlly';
13
+ import 'untyped';
8
14
  import 'citty';
15
+ import '@nuxt/kit';
16
+ import './shared/module-builder.4be2741e.mjs';
@@ -0,0 +1,5 @@
1
+ const name = "@nuxt/module-builder";
2
+ const version = "0.7.0";
3
+ const description = "Complete solution for building Nuxt modules";
4
+
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.5.5",
3
+ "version": "0.7.0",
4
4
  "repository": "nuxt/module-builder",
5
5
  "description": "Complete solution for building Nuxt modules",
6
6
  "license": "MIT",
@@ -19,38 +19,51 @@
19
19
  "files": [
20
20
  "dist"
21
21
  ],
22
- "packageManager": "pnpm@8.12.1",
23
22
  "dependencies": {
24
- "citty": "^0.1.5",
23
+ "citty": "^0.1.6",
25
24
  "consola": "^3.2.3",
26
- "mlly": "^1.4.2",
27
- "pathe": "^1.1.1",
28
- "unbuild": "^2.0.0"
25
+ "defu": "^6.1.4",
26
+ "magic-regexp": "^0.8.0",
27
+ "mlly": "^1.7.0",
28
+ "pathe": "^1.1.2",
29
+ "pkg-types": "^1.1.1",
30
+ "tsconfck": "^3.0.3",
31
+ "unbuild": "^2.0.0",
32
+ "untyped": "^1.4.2"
29
33
  },
30
34
  "peerDependencies": {
31
- "@nuxt/kit": "^3.8.2",
32
- "nuxi": "^3.10.0"
35
+ "@nuxt/kit": "^3.11.2",
36
+ "nuxi": "^3.11.1"
33
37
  },
34
38
  "devDependencies": {
35
- "@nuxt/kit": "^3.8.2",
36
- "@nuxt/schema": "^3.8.2",
37
- "@nuxtjs/eslint-config-typescript": "^12.1.0",
38
- "@types/node": "^20.10.5",
39
- "@vitest/coverage-v8": "^1.1.0",
39
+ "@nuxt/eslint-config": "^0.3.13",
40
+ "@nuxt/kit": "^3.11.2",
41
+ "@nuxt/schema": "^3.11.2",
42
+ "@types/node": "^20.12.12",
43
+ "@vitest/coverage-v8": "^1.6.0",
40
44
  "changelogen": "^0.5.5",
41
- "eslint": "^8.56.0",
45
+ "eslint": "^9.3.0",
42
46
  "jiti": "^1.21.0",
43
- "nuxi": "^3.10.0",
44
- "nuxt": "^3.8.2",
45
- "vitest": "^1.1.0"
47
+ "nuxi": "^3.11.1",
48
+ "nuxt": "^3.11.2",
49
+ "typescript": "^5.4.5",
50
+ "vitest": "^1.6.0",
51
+ "vue": "^3.4.27",
52
+ "vue-tsc": "^2.0.19"
53
+ },
54
+ "resolutions": {
55
+ "@nuxt/kit": "^3.11.2",
56
+ "@nuxt/schema": "^3.11.2",
57
+ "vue": "^3.4.27"
46
58
  },
47
59
  "scripts": {
48
60
  "build": "unbuild",
61
+ "dev:prepare": "pnpm -r dev:prepare",
49
62
  "example:build": "pnpm nuxt-module-build build ./example",
50
- "lint": "eslint --ext .ts,.js,.mjs .",
63
+ "lint": "eslint .",
51
64
  "nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
52
65
  "release": "pnpm vitest run && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
53
66
  "test": "pnpm vitest",
54
- "test:types": "tsc --noEmit && pnpm -r test:types"
67
+ "test:types": "vue-tsc --noEmit && pnpm -r test:types"
55
68
  }
56
69
  }