@nuxt/module-builder 0.6.0 → 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
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.4be2741e.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
|
);
|
|
@@ -139,6 +184,8 @@ async function writeTypes(distDir, meta) {
|
|
|
139
184
|
moduleImports.push("ModuleOptions");
|
|
140
185
|
schemaShims.push(` interface NuxtConfig { ['${meta.configKey}']?: Partial<ModuleOptions> }`);
|
|
141
186
|
schemaShims.push(` interface NuxtOptions { ['${meta.configKey}']?: ModuleOptions }`);
|
|
187
|
+
} else if (meta.configKey) {
|
|
188
|
+
schemaShims.push(` ${generateTypes(await resolveSchema(await getOptions()), { interfaceName: "ModuleOptions" })}`);
|
|
142
189
|
}
|
|
143
190
|
if (hasTypeExport("ModuleHooks")) {
|
|
144
191
|
moduleImports.push("ModuleHooks");
|
|
@@ -197,20 +244,18 @@ module.exports.getMeta = () => Promise.resolve(_meta)
|
|
|
197
244
|
await promises.writeFile(cjsStubFile, cjsStub, "utf8");
|
|
198
245
|
}
|
|
199
246
|
async function loadTSCompilerOptions(path) {
|
|
200
|
-
const config = await
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
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
|
+
}
|
|
211
257
|
}
|
|
212
|
-
|
|
213
|
-
return defu(config.compilerOptions, ...await Promise.all(files.map((file) => loadTSCompilerOptions(dirname(resolve(path, file))))));
|
|
258
|
+
return resolvedCompilerOptions;
|
|
214
259
|
}
|
|
215
260
|
|
|
216
261
|
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.4be2741e.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.4be2741e.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/module-builder",
|
|
3
|
-
"version": "0.
|
|
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,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.0",
|
|
39
28
|
"pathe": "^1.1.2",
|
|
40
|
-
"pkg-types": "^1.1.
|
|
41
|
-
"
|
|
29
|
+
"pkg-types": "^1.1.1",
|
|
30
|
+
"tsconfck": "^3.0.3",
|
|
31
|
+
"unbuild": "^2.0.0",
|
|
32
|
+
"untyped": "^1.4.2"
|
|
42
33
|
},
|
|
43
34
|
"peerDependencies": {
|
|
44
35
|
"@nuxt/kit": "^3.11.2",
|
|
45
36
|
"nuxi": "^3.11.1"
|
|
46
37
|
},
|
|
47
38
|
"devDependencies": {
|
|
48
|
-
"@nuxt/eslint-config": "^0.3.
|
|
39
|
+
"@nuxt/eslint-config": "^0.3.13",
|
|
49
40
|
"@nuxt/kit": "^3.11.2",
|
|
50
41
|
"@nuxt/schema": "^3.11.2",
|
|
51
|
-
"@types/node": "^20.12.
|
|
52
|
-
"@vitest/coverage-v8": "^1.
|
|
42
|
+
"@types/node": "^20.12.12",
|
|
43
|
+
"@vitest/coverage-v8": "^1.6.0",
|
|
53
44
|
"changelogen": "^0.5.5",
|
|
54
|
-
"eslint": "^9.
|
|
45
|
+
"eslint": "^9.3.0",
|
|
55
46
|
"jiti": "^1.21.0",
|
|
56
47
|
"nuxi": "^3.11.1",
|
|
57
48
|
"nuxt": "^3.11.2",
|
|
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
55
|
"@nuxt/kit": "^3.11.2",
|
|
65
56
|
"@nuxt/schema": "^3.11.2",
|
|
66
|
-
"vue": "^3.4.
|
|
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
|
+
}
|