@nuxt/module-builder 0.7.0 → 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.
package/README.md
CHANGED
|
@@ -131,7 +131,7 @@ Module builder generates dist files in `dist/` directory:
|
|
|
131
131
|
- `module.cjs`: ESM proxy to allow require module in CommonJS context
|
|
132
132
|
- `types.d.ts`: Exported types in addition to shims for `nuxt.config` auto completion.
|
|
133
133
|
- `runtime/*`: Individually transformed files using [unjs/mkdist](https://github.com/unjs/mkdist)
|
|
134
|
-
- Javascript and `.ts` files will be transformed to `.
|
|
134
|
+
- Javascript and `.ts` files will be transformed to `.js` with extracted types on `.d.ts` file with same name
|
|
135
135
|
- `.vue` files will be transformed with extracted `.d.ts` file
|
|
136
136
|
- Other files will be copied as is
|
|
137
137
|
|
package/dist/chunks/build.mjs
CHANGED
|
@@ -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 {
|
|
14
|
-
import { n as name, v as version } from '../shared/module-builder.4be2741e.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
|
|
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
|
|
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,24 +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
|
|
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(/\
|
|
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
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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>`);
|
|
189
177
|
}
|
|
190
178
|
if (hasTypeExport("ModuleHooks")) {
|
|
191
179
|
moduleImports.push("ModuleHooks");
|
|
@@ -208,7 +196,9 @@ async function writeTypes(distDir, meta, getOptions) {
|
|
|
208
196
|
schemaShims.push(" interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}");
|
|
209
197
|
}
|
|
210
198
|
const dtsContents = `
|
|
211
|
-
import type { ${
|
|
199
|
+
${schemaImports.length ? `import type { ${schemaImports.join(", ")} } from '@nuxt/schema'` : ""}
|
|
200
|
+
|
|
201
|
+
${moduleImports.length ? `import type { ${moduleImports.join(", ")} } from './module'` : ""}
|
|
212
202
|
|
|
213
203
|
${appShims.length ? `declare module '#app' {
|
|
214
204
|
${appShims.join("\n")}
|
|
@@ -222,9 +212,11 @@ ${schemaShims.length ? `declare module 'nuxt/schema' {
|
|
|
222
212
|
${schemaShims.join("\n")}
|
|
223
213
|
}
|
|
224
214
|
` : ""}
|
|
225
|
-
${
|
|
226
|
-
|
|
227
|
-
|
|
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";
|
|
228
220
|
await promises.writeFile(dtsFile, dtsContents, "utf8");
|
|
229
221
|
if (!existsSync(dtsFileMts)) {
|
|
230
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.
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/module-builder",
|
|
3
|
-
"version": "0.
|
|
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,51 +19,52 @@
|
|
|
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",
|
|
25
37
|
"defu": "^6.1.4",
|
|
26
38
|
"magic-regexp": "^0.8.0",
|
|
27
|
-
"mlly": "^1.7.
|
|
39
|
+
"mlly": "^1.7.1",
|
|
28
40
|
"pathe": "^1.1.2",
|
|
29
41
|
"pkg-types": "^1.1.1",
|
|
30
|
-
"tsconfck": "^3.0
|
|
31
|
-
"unbuild": "^2.0.0"
|
|
32
|
-
"untyped": "^1.4.2"
|
|
42
|
+
"tsconfck": "^3.1.0",
|
|
43
|
+
"unbuild": "^2.0.0"
|
|
33
44
|
},
|
|
34
45
|
"peerDependencies": {
|
|
35
|
-
"@nuxt/kit": "^3.
|
|
36
|
-
"nuxi": "^3.
|
|
46
|
+
"@nuxt/kit": "^3.12.2",
|
|
47
|
+
"nuxi": "^3.12.0"
|
|
37
48
|
},
|
|
38
49
|
"devDependencies": {
|
|
39
50
|
"@nuxt/eslint-config": "^0.3.13",
|
|
40
|
-
"@nuxt/kit": "^3.
|
|
41
|
-
"@nuxt/schema": "^3.
|
|
42
|
-
"@types/node": "^20.
|
|
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.
|
|
46
|
-
"jiti": "^1.21.
|
|
47
|
-
"nuxi": "^3.
|
|
48
|
-
"nuxt": "^3.
|
|
56
|
+
"eslint": "^9.5.0",
|
|
57
|
+
"jiti": "^1.21.6",
|
|
58
|
+
"nuxi": "^3.12.0",
|
|
59
|
+
"nuxt": "^3.12.2",
|
|
49
60
|
"typescript": "^5.4.5",
|
|
50
61
|
"vitest": "^1.6.0",
|
|
51
|
-
"vue": "^3.4.
|
|
52
|
-
"vue-tsc": "^2.0.
|
|
62
|
+
"vue": "^3.4.29",
|
|
63
|
+
"vue-tsc": "^2.0.21"
|
|
53
64
|
},
|
|
54
65
|
"resolutions": {
|
|
55
|
-
"@nuxt/kit": "^3.
|
|
56
|
-
"@nuxt/schema": "^3.
|
|
57
|
-
"vue": "^3.4.
|
|
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
|
+
}
|