@nuxt/module-builder 0.6.0 → 0.7.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.
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
|
}
|
|
@@ -130,7 +131,7 @@ Module builder generates dist files in `dist/` directory:
|
|
|
130
131
|
- `module.cjs`: ESM proxy to allow require module in CommonJS context
|
|
131
132
|
- `types.d.ts`: Exported types in addition to shims for `nuxt.config` auto completion.
|
|
132
133
|
- `runtime/*`: Individually transformed files using [unjs/mkdist](https://github.com/unjs/mkdist)
|
|
133
|
-
- 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
|
|
134
135
|
- `.vue` files will be transformed with extracted `.d.ts` file
|
|
135
136
|
- Other files will be copied as is
|
|
136
137
|
|
package/dist/chunks/build.mjs
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { promises, existsSync } from 'node:fs';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
|
-
import { resolve, dirname } from 'pathe';
|
|
4
|
-
import {
|
|
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';
|
|
5
7
|
import { defu } from 'defu';
|
|
8
|
+
import { createRegExp, anyOf } from 'magic-regexp';
|
|
6
9
|
import { consola } from 'consola';
|
|
7
|
-
import { findExports } from 'mlly';
|
|
10
|
+
import { resolvePath, findExports } from 'mlly';
|
|
11
|
+
import { generateTypes, resolveSchema } from 'untyped';
|
|
8
12
|
import { defineCommand } from 'citty';
|
|
9
|
-
import {
|
|
13
|
+
import { loadNuxt } from '@nuxt/kit';
|
|
14
|
+
import { n as name, v as version } from '../shared/module-builder.832f08b1.mjs';
|
|
10
15
|
|
|
11
16
|
const build = defineCommand({
|
|
12
17
|
meta: {
|
|
@@ -47,7 +52,8 @@ const build = defineCommand({
|
|
|
47
52
|
{
|
|
48
53
|
input: "src/runtime/",
|
|
49
54
|
outDir: `${outDir}/runtime`,
|
|
50
|
-
|
|
55
|
+
addRelativeDeclarationExtensions: true,
|
|
56
|
+
ext: "js",
|
|
51
57
|
esbuild: {
|
|
52
58
|
jsxImportSource: "vue",
|
|
53
59
|
jsx: "automatic",
|
|
@@ -63,7 +69,7 @@ const build = defineCommand({
|
|
|
63
69
|
cjsBridge: true
|
|
64
70
|
},
|
|
65
71
|
externals: [
|
|
66
|
-
/
|
|
72
|
+
/dist\/runtime\//,
|
|
67
73
|
"@nuxt/schema",
|
|
68
74
|
"@nuxt/schema-nightly",
|
|
69
75
|
"@nuxt/schema-edge",
|
|
@@ -78,9 +84,38 @@ const build = defineCommand({
|
|
|
78
84
|
"vue-demi"
|
|
79
85
|
],
|
|
80
86
|
hooks: {
|
|
81
|
-
async "mkdist:entry:options"(_ctx,
|
|
87
|
+
async "mkdist:entry:options"(_ctx, entry, options) {
|
|
82
88
|
options.typescript = defu(options.typescript, {
|
|
83
|
-
compilerOptions: await loadTSCompilerOptions(
|
|
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
|
+
}
|
|
84
119
|
});
|
|
85
120
|
},
|
|
86
121
|
async "rollup:done"(ctx) {
|
|
@@ -109,13 +144,23 @@ const build = defineCommand({
|
|
|
109
144
|
};
|
|
110
145
|
const metaFile = resolve(ctx.options.outDir, "module.json");
|
|
111
146
|
await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
|
|
112
|
-
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
|
+
});
|
|
113
158
|
}
|
|
114
159
|
}
|
|
115
160
|
});
|
|
116
161
|
}
|
|
117
162
|
});
|
|
118
|
-
async function writeTypes(distDir, meta) {
|
|
163
|
+
async function writeTypes(distDir, meta, getOptions) {
|
|
119
164
|
const dtsFile = resolve(distDir, "types.d.ts");
|
|
120
165
|
const dtsFileMts = resolve(distDir, "types.d.mts");
|
|
121
166
|
if (existsSync(dtsFile)) {
|
|
@@ -126,7 +171,7 @@ async function writeTypes(distDir, meta) {
|
|
|
126
171
|
const typeExports = findExports(
|
|
127
172
|
// Replace `export { type Foo }` with `export { Foo }`
|
|
128
173
|
moduleTypes.replace(
|
|
129
|
-
/export\s
|
|
174
|
+
/export\s*\{.*?\}/gs,
|
|
130
175
|
(match) => match.replace(/\btype\b/g, "")
|
|
131
176
|
)
|
|
132
177
|
);
|
|
@@ -134,11 +179,16 @@ async function writeTypes(distDir, meta) {
|
|
|
134
179
|
const appShims = [];
|
|
135
180
|
const schemaShims = [];
|
|
136
181
|
const moduleImports = [];
|
|
182
|
+
const moduleDeclarations = [];
|
|
137
183
|
const hasTypeExport = (name2) => isStub || typeExports.find((exp) => exp.names.includes(name2));
|
|
138
|
-
if (meta.configKey
|
|
139
|
-
moduleImports.push("ModuleOptions");
|
|
184
|
+
if (meta.configKey) {
|
|
140
185
|
schemaShims.push(` interface NuxtConfig { ['${meta.configKey}']?: Partial<ModuleOptions> }`);
|
|
141
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
|
+
}
|
|
142
192
|
}
|
|
143
193
|
if (hasTypeExport("ModuleHooks")) {
|
|
144
194
|
moduleImports.push("ModuleHooks");
|
|
@@ -163,6 +213,7 @@ async function writeTypes(distDir, meta) {
|
|
|
163
213
|
const dtsContents = `
|
|
164
214
|
import type { ${moduleImports.join(", ")} } from './module'
|
|
165
215
|
|
|
216
|
+
${moduleDeclarations.join("\n")}
|
|
166
217
|
${appShims.length ? `declare module '#app' {
|
|
167
218
|
${appShims.join("\n")}
|
|
168
219
|
}
|
|
@@ -197,20 +248,18 @@ module.exports.getMeta = () => Promise.resolve(_meta)
|
|
|
197
248
|
await promises.writeFile(cjsStubFile, cjsStub, "utf8");
|
|
198
249
|
}
|
|
199
250
|
async function loadTSCompilerOptions(path) {
|
|
200
|
-
const config = await
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
251
|
+
const config = await parse(path);
|
|
252
|
+
const resolvedCompilerOptions = config?.tsconfig.compilerOptions || {};
|
|
253
|
+
for (const { tsconfig, tsconfigFile } of config.extended || []) {
|
|
254
|
+
for (const alias in tsconfig.compilerOptions?.paths || {}) {
|
|
255
|
+
resolvedCompilerOptions.paths[alias] = resolvedCompilerOptions.paths[alias].map((p) => {
|
|
256
|
+
if (!/^\.{1,2}(?:\/|$)/.test(p))
|
|
257
|
+
return p;
|
|
258
|
+
return resolve(dirname(tsconfigFile), p);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
211
261
|
}
|
|
212
|
-
|
|
213
|
-
return defu(config.compilerOptions, ...await Promise.all(files.map((file) => loadTSCompilerOptions(dirname(resolve(path, file))))));
|
|
262
|
+
return resolvedCompilerOptions;
|
|
214
263
|
}
|
|
215
264
|
|
|
216
265
|
export { build as default };
|
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.832f08b1.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
|
@@ -3,9 +3,14 @@ export { default as prepare } from './chunks/prepare.mjs';
|
|
|
3
3
|
import 'node:fs';
|
|
4
4
|
import 'node:url';
|
|
5
5
|
import 'pathe';
|
|
6
|
+
import 'pathe/utils';
|
|
6
7
|
import 'pkg-types';
|
|
8
|
+
import 'tsconfck';
|
|
7
9
|
import 'defu';
|
|
10
|
+
import 'magic-regexp';
|
|
8
11
|
import 'consola';
|
|
9
12
|
import 'mlly';
|
|
13
|
+
import 'untyped';
|
|
10
14
|
import 'citty';
|
|
11
|
-
import '
|
|
15
|
+
import '@nuxt/kit';
|
|
16
|
+
import './shared/module-builder.832f08b1.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/module-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"repository": "nuxt/module-builder",
|
|
5
5
|
"description": "Complete solution for building Nuxt modules",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,50 +19,51 @@
|
|
|
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.0.6",
|
|
34
22
|
"dependencies": {
|
|
35
23
|
"citty": "^0.1.6",
|
|
36
24
|
"consola": "^3.2.3",
|
|
37
25
|
"defu": "^6.1.4",
|
|
38
|
-
"
|
|
26
|
+
"magic-regexp": "^0.8.0",
|
|
27
|
+
"mlly": "^1.7.1",
|
|
39
28
|
"pathe": "^1.1.2",
|
|
40
|
-
"pkg-types": "^1.1.
|
|
41
|
-
"
|
|
29
|
+
"pkg-types": "^1.1.1",
|
|
30
|
+
"tsconfck": "^3.1.0",
|
|
31
|
+
"unbuild": "^2.0.0",
|
|
32
|
+
"untyped": "^1.4.2"
|
|
42
33
|
},
|
|
43
34
|
"peerDependencies": {
|
|
44
|
-
"@nuxt/kit": "^3.
|
|
45
|
-
"nuxi": "^3.
|
|
35
|
+
"@nuxt/kit": "^3.12.1",
|
|
36
|
+
"nuxi": "^3.12.0"
|
|
46
37
|
},
|
|
47
38
|
"devDependencies": {
|
|
48
|
-
"@nuxt/eslint-config": "^0.3.
|
|
49
|
-
"@nuxt/kit": "^3.
|
|
50
|
-
"@nuxt/schema": "^3.
|
|
51
|
-
"@types/node": "^20.
|
|
52
|
-
"@vitest/coverage-v8": "^1.
|
|
39
|
+
"@nuxt/eslint-config": "^0.3.13",
|
|
40
|
+
"@nuxt/kit": "^3.12.1",
|
|
41
|
+
"@nuxt/schema": "^3.12.1",
|
|
42
|
+
"@types/node": "^20.14.2",
|
|
43
|
+
"@vitest/coverage-v8": "^1.6.0",
|
|
53
44
|
"changelogen": "^0.5.5",
|
|
54
|
-
"eslint": "^9.
|
|
55
|
-
"jiti": "^1.21.
|
|
56
|
-
"nuxi": "^3.
|
|
57
|
-
"nuxt": "^3.
|
|
45
|
+
"eslint": "^9.4.0",
|
|
46
|
+
"jiti": "^1.21.6",
|
|
47
|
+
"nuxi": "^3.12.0",
|
|
48
|
+
"nuxt": "^3.12.1",
|
|
58
49
|
"typescript": "^5.4.5",
|
|
59
|
-
"vitest": "^1.
|
|
60
|
-
"vue": "^3.4.
|
|
61
|
-
"vue-tsc": "^2.0.
|
|
50
|
+
"vitest": "^1.6.0",
|
|
51
|
+
"vue": "^3.4.27",
|
|
52
|
+
"vue-tsc": "^2.0.19"
|
|
62
53
|
},
|
|
63
54
|
"resolutions": {
|
|
64
|
-
"@nuxt/kit": "^3.
|
|
65
|
-
"@nuxt/schema": "^3.
|
|
66
|
-
"vue": "^3.4.
|
|
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"
|
|
67
68
|
}
|
|
68
|
-
}
|
|
69
|
+
}
|