@nuxt/module-builder 0.5.4 → 0.6.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 +6 -7
- package/dist/chunks/build.mjs +57 -12
- package/dist/cli.mjs +3 -6
- package/dist/index.mjs +5 -2
- package/dist/shared/module-builder.342fba3e.mjs +5 -0
- package/package.json +37 -24
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` or `
|
|
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,16 +55,16 @@ export interface ModuleHooks {
|
|
|
55
55
|
'my-module:init': any
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export interface
|
|
58
|
+
export interface ModuleRuntimeHooks {
|
|
59
59
|
'my-module:runtime-hook': any
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
export interface
|
|
63
|
-
|
|
62
|
+
export interface ModuleRuntimeConfig {
|
|
63
|
+
PRIVATE_NAME: string
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export interface
|
|
67
|
-
|
|
66
|
+
export interface ModulePublicRuntimeConfig {
|
|
67
|
+
NAME: string
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export default defineNuxtModule<ModuleOptions>({
|
|
@@ -145,7 +145,6 @@ Module builder generates dist files in `dist/` directory:
|
|
|
145
145
|
|
|
146
146
|
[MIT](./LICENSE) - Made with 💚
|
|
147
147
|
|
|
148
|
-
|
|
149
148
|
<!-- Badges -->
|
|
150
149
|
[npm-version-src]: https://img.shields.io/npm/v/@nuxt/module-builder/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
151
150
|
[npm-version-href]: https://npmjs.com/package/@nuxt/module-builder
|
package/dist/chunks/build.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
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, dirname } from 'pathe';
|
|
4
|
+
import { readPackageJSON, readTSConfig } from 'pkg-types';
|
|
5
|
+
import { defu } from 'defu';
|
|
4
6
|
import { consola } from 'consola';
|
|
5
7
|
import { findExports } from 'mlly';
|
|
6
8
|
import { defineCommand } from 'citty';
|
|
9
|
+
import { n as name, v as version } from '../shared/module-builder.342fba3e.mjs';
|
|
7
10
|
|
|
8
11
|
const build = defineCommand({
|
|
9
12
|
meta: {
|
|
@@ -41,7 +44,16 @@ const build = defineCommand({
|
|
|
41
44
|
outDir,
|
|
42
45
|
entries: [
|
|
43
46
|
"src/module",
|
|
44
|
-
{
|
|
47
|
+
{
|
|
48
|
+
input: "src/runtime/",
|
|
49
|
+
outDir: `${outDir}/runtime`,
|
|
50
|
+
ext: "mjs",
|
|
51
|
+
esbuild: {
|
|
52
|
+
jsxImportSource: "vue",
|
|
53
|
+
jsx: "automatic",
|
|
54
|
+
jsxFactory: "h"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
45
57
|
],
|
|
46
58
|
rollup: {
|
|
47
59
|
esbuild: {
|
|
@@ -51,17 +63,26 @@ const build = defineCommand({
|
|
|
51
63
|
cjsBridge: true
|
|
52
64
|
},
|
|
53
65
|
externals: [
|
|
66
|
+
/src\/runtime/,
|
|
54
67
|
"@nuxt/schema",
|
|
68
|
+
"@nuxt/schema-nightly",
|
|
55
69
|
"@nuxt/schema-edge",
|
|
56
70
|
"@nuxt/kit",
|
|
71
|
+
"@nuxt/kit-nightly",
|
|
57
72
|
"@nuxt/kit-edge",
|
|
58
73
|
"nuxt",
|
|
74
|
+
"nuxt-nightly",
|
|
59
75
|
"nuxt-edge",
|
|
60
76
|
"nuxt3",
|
|
61
77
|
"vue",
|
|
62
78
|
"vue-demi"
|
|
63
79
|
],
|
|
64
80
|
hooks: {
|
|
81
|
+
async "mkdist:entry:options"(_ctx, _entry, options) {
|
|
82
|
+
options.typescript = defu(options.typescript, {
|
|
83
|
+
compilerOptions: await loadTSCompilerOptions(cwd)
|
|
84
|
+
});
|
|
85
|
+
},
|
|
65
86
|
async "rollup:done"(ctx) {
|
|
66
87
|
await writeCJSStub(ctx.options.outDir);
|
|
67
88
|
const moduleEntryPath = resolve(ctx.options.outDir, "module.mjs");
|
|
@@ -73,7 +94,7 @@ const build = defineCommand({
|
|
|
73
94
|
if (!moduleFn) {
|
|
74
95
|
return;
|
|
75
96
|
}
|
|
76
|
-
const moduleMeta = await moduleFn.getMeta();
|
|
97
|
+
const moduleMeta = await moduleFn.getMeta?.() || {};
|
|
77
98
|
if (ctx.pkg) {
|
|
78
99
|
if (!moduleMeta.name) {
|
|
79
100
|
moduleMeta.name = ctx.pkg.name;
|
|
@@ -82,6 +103,10 @@ const build = defineCommand({
|
|
|
82
103
|
moduleMeta.version = ctx.pkg.version;
|
|
83
104
|
}
|
|
84
105
|
}
|
|
106
|
+
moduleMeta.builder = {
|
|
107
|
+
[name]: version,
|
|
108
|
+
unbuild: await readPackageJSON("unbuild").then((r) => r.version).catch(() => "unknown")
|
|
109
|
+
};
|
|
85
110
|
const metaFile = resolve(ctx.options.outDir, "module.json");
|
|
86
111
|
await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
|
|
87
112
|
await writeTypes(ctx.options.outDir, moduleMeta);
|
|
@@ -109,7 +134,7 @@ async function writeTypes(distDir, meta) {
|
|
|
109
134
|
const appShims = [];
|
|
110
135
|
const schemaShims = [];
|
|
111
136
|
const moduleImports = [];
|
|
112
|
-
const hasTypeExport = (
|
|
137
|
+
const hasTypeExport = (name2) => isStub || typeExports.find((exp) => exp.names.includes(name2));
|
|
113
138
|
if (meta.configKey && hasTypeExport("ModuleOptions")) {
|
|
114
139
|
moduleImports.push("ModuleOptions");
|
|
115
140
|
schemaShims.push(` interface NuxtConfig { ['${meta.configKey}']?: Partial<ModuleOptions> }`);
|
|
@@ -119,9 +144,13 @@ async function writeTypes(distDir, meta) {
|
|
|
119
144
|
moduleImports.push("ModuleHooks");
|
|
120
145
|
schemaShims.push(" interface NuxtHooks extends ModuleHooks {}");
|
|
121
146
|
}
|
|
122
|
-
if (hasTypeExport("
|
|
123
|
-
|
|
124
|
-
|
|
147
|
+
if (hasTypeExport("ModuleRuntimeHooks")) {
|
|
148
|
+
const runtimeHooksInterfaces = [];
|
|
149
|
+
if (hasTypeExport("ModuleRuntimeHooks")) {
|
|
150
|
+
runtimeHooksInterfaces.push("ModuleRuntimeHooks");
|
|
151
|
+
}
|
|
152
|
+
moduleImports.push(...runtimeHooksInterfaces);
|
|
153
|
+
appShims.push(` interface RuntimeNuxtHooks extends ${runtimeHooksInterfaces.join(", ")} {}`);
|
|
125
154
|
}
|
|
126
155
|
if (hasTypeExport("ModuleRuntimeConfig")) {
|
|
127
156
|
moduleImports.push("ModuleRuntimeConfig");
|
|
@@ -146,12 +175,12 @@ ${schemaShims.length ? `declare module 'nuxt/schema' {
|
|
|
146
175
|
${schemaShims.join("\n")}
|
|
147
176
|
}
|
|
148
177
|
` : ""}
|
|
149
|
-
|
|
150
|
-
export type { ${typeExports[0].names.join(", ")} } from './module'
|
|
178
|
+
${typeExports[0] ? `
|
|
179
|
+
export type { ${typeExports[0].names.join(", ")} } from './module'` : ""}
|
|
151
180
|
`;
|
|
152
181
|
await promises.writeFile(dtsFile, dtsContents, "utf8");
|
|
153
182
|
if (!existsSync(dtsFileMts)) {
|
|
154
|
-
await promises.writeFile(dtsFileMts, dtsContents, "utf8");
|
|
183
|
+
await promises.writeFile(dtsFileMts, dtsContents.replace(/\.\/module/g, "./module.js"), "utf8");
|
|
155
184
|
}
|
|
156
185
|
}
|
|
157
186
|
async function writeCJSStub(distDir) {
|
|
@@ -167,5 +196,21 @@ module.exports.getMeta = () => Promise.resolve(_meta)
|
|
|
167
196
|
`;
|
|
168
197
|
await promises.writeFile(cjsStubFile, cjsStub, "utf8");
|
|
169
198
|
}
|
|
199
|
+
async function loadTSCompilerOptions(path) {
|
|
200
|
+
const config = await readTSConfig(path).catch(() => {
|
|
201
|
+
});
|
|
202
|
+
if (!config)
|
|
203
|
+
return [];
|
|
204
|
+
config.compilerOptions || (config.compilerOptions = {});
|
|
205
|
+
for (const alias in config.compilerOptions.paths || {}) {
|
|
206
|
+
config.compilerOptions.paths[alias] = config.compilerOptions.paths[alias].map((p) => {
|
|
207
|
+
if (!/^\.{1,2}(\/|$)/.test(p))
|
|
208
|
+
return p;
|
|
209
|
+
return resolve(path, p);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const files = Array.isArray(config.extends) ? config.extends : config.extends ? [config.extends] : [];
|
|
213
|
+
return defu(config.compilerOptions, ...await Promise.all(files.map((file) => loadTSCompilerOptions(dirname(resolve(path, file))))));
|
|
214
|
+
}
|
|
170
215
|
|
|
171
216
|
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.342fba3e.mjs';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
const version = "0.5.4";
|
|
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 (!(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,11 @@
|
|
|
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 'pkg-types';
|
|
7
|
+
import 'defu';
|
|
6
8
|
import 'consola';
|
|
7
9
|
import 'mlly';
|
|
8
10
|
import 'citty';
|
|
11
|
+
import './shared/module-builder.342fba3e.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/module-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"repository": "nuxt/module-builder",
|
|
5
5
|
"description": "Complete solution for building Nuxt modules",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,37 +19,50 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
|
-
"
|
|
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.0.6",
|
|
23
34
|
"dependencies": {
|
|
24
|
-
"citty": "^0.1.
|
|
35
|
+
"citty": "^0.1.6",
|
|
25
36
|
"consola": "^3.2.3",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
37
|
+
"defu": "^6.1.4",
|
|
38
|
+
"mlly": "^1.6.1",
|
|
39
|
+
"pathe": "^1.1.2",
|
|
40
|
+
"pkg-types": "^1.1.0",
|
|
28
41
|
"unbuild": "^2.0.0"
|
|
29
42
|
},
|
|
30
43
|
"peerDependencies": {
|
|
31
|
-
"@nuxt/kit": "^3.
|
|
32
|
-
"nuxi": "^3.
|
|
44
|
+
"@nuxt/kit": "^3.11.2",
|
|
45
|
+
"nuxi": "^3.11.1"
|
|
33
46
|
},
|
|
34
47
|
"devDependencies": {
|
|
35
|
-
"@nuxt/
|
|
36
|
-
"@nuxt/
|
|
37
|
-
"@
|
|
38
|
-
"@types/node": "^20.
|
|
39
|
-
"@vitest/coverage-v8": "^
|
|
48
|
+
"@nuxt/eslint-config": "^0.3.10",
|
|
49
|
+
"@nuxt/kit": "^3.11.2",
|
|
50
|
+
"@nuxt/schema": "^3.11.2",
|
|
51
|
+
"@types/node": "^20.12.7",
|
|
52
|
+
"@vitest/coverage-v8": "^1.5.2",
|
|
40
53
|
"changelogen": "^0.5.5",
|
|
41
|
-
"eslint": "^
|
|
54
|
+
"eslint": "^9.1.1",
|
|
42
55
|
"jiti": "^1.21.0",
|
|
43
|
-
"nuxi": "^3.
|
|
44
|
-
"nuxt": "^3.
|
|
45
|
-
"
|
|
56
|
+
"nuxi": "^3.11.1",
|
|
57
|
+
"nuxt": "^3.11.2",
|
|
58
|
+
"typescript": "^5.4.5",
|
|
59
|
+
"vitest": "^1.5.2",
|
|
60
|
+
"vue": "^3.4.25",
|
|
61
|
+
"vue-tsc": "^2.0.14"
|
|
46
62
|
},
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
|
|
52
|
-
"release": "pnpm vitest run && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
|
|
53
|
-
"test": "pnpm vitest"
|
|
63
|
+
"resolutions": {
|
|
64
|
+
"@nuxt/kit": "^3.11.2",
|
|
65
|
+
"@nuxt/schema": "^3.11.2",
|
|
66
|
+
"vue": "^3.4.25"
|
|
54
67
|
}
|
|
55
|
-
}
|
|
68
|
+
}
|