@nuxt/module-builder 0.8.4 → 1.0.0-alpha.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 +16 -2
- package/dist/chunks/build.mjs +53 -38
- package/dist/cli.d.mts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.mjs +3 -1
- package/dist/shared/{module-builder.617a9be8.mjs → module-builder.D3Pp640p.mjs} +1 -1
- package/package.json +29 -27
package/README.md
CHANGED
|
@@ -111,7 +111,7 @@ A minimum `package.json` should look like this:
|
|
|
111
111
|
"dist"
|
|
112
112
|
],
|
|
113
113
|
"scripts": {
|
|
114
|
-
"prepack": "nuxt-module-build"
|
|
114
|
+
"prepack": "nuxt-module-build build"
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
117
|
"@nuxt/kit": "npm:@nuxt/kit-edge@latest"
|
|
@@ -122,6 +122,20 @@ A minimum `package.json` should look like this:
|
|
|
122
122
|
}
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
+
### `build.config.ts` (optional)
|
|
126
|
+
|
|
127
|
+
Module builder is essentially a preset for [unjs/unbuild](https://github.com/unjs/unbuild), check out the [build command](./src/commands/build.ts#L51) for reference.
|
|
128
|
+
|
|
129
|
+
To customize/extend the unbuild configuration you can add a `build.config.ts` in the root of your project:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { defineBuildConfig } from 'unbuild'
|
|
133
|
+
|
|
134
|
+
export default defineBuildConfig({
|
|
135
|
+
// set additional configuration or customize using hooks
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
125
139
|
## Dist files
|
|
126
140
|
|
|
127
141
|
Module builder generates dist files in `dist/` directory:
|
|
@@ -151,7 +165,7 @@ Module builder generates dist files in `dist/` directory:
|
|
|
151
165
|
[npm-version-href]: https://npmjs.com/package/@nuxt/module-builder
|
|
152
166
|
|
|
153
167
|
[npm-downloads-src]: https://img.shields.io/npm/dt/@nuxt/module-builder.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
154
|
-
[npm-downloads-href]: https://
|
|
168
|
+
[npm-downloads-href]: https://npm.chart.dev/@nuxt/module-builder
|
|
155
169
|
|
|
156
170
|
[license-src]: https://img.shields.io/github/license/nuxt/module-builder.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
157
171
|
[license-href]: https://github.com/nuxt/module-builder/blob/main/LICENSE
|
package/dist/chunks/build.mjs
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { promises, existsSync } from 'node:fs';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
|
-
import { resolve, basename, join, dirname } from 'pathe';
|
|
3
|
+
import { resolve, basename, normalize, join, dirname } from 'pathe';
|
|
4
4
|
import { filename } from 'pathe/utils';
|
|
5
5
|
import { readPackageJSON } from 'pkg-types';
|
|
6
6
|
import { parse } from 'tsconfck';
|
|
7
7
|
import { defu } from 'defu';
|
|
8
|
+
import { createJiti } from 'jiti';
|
|
8
9
|
import { createRegExp, anyOf } from 'magic-regexp';
|
|
9
10
|
import { consola } from 'consola';
|
|
10
11
|
import { resolvePath, findExports } from 'mlly';
|
|
11
12
|
import { defineCommand } from 'citty';
|
|
12
|
-
import {
|
|
13
|
+
import { convertCompilerOptionsFromJson } from 'typescript';
|
|
14
|
+
import { n as name, v as version } from '../shared/module-builder.D3Pp640p.mjs';
|
|
13
15
|
|
|
14
16
|
const build = defineCommand({
|
|
15
17
|
meta: {
|
|
@@ -39,9 +41,10 @@ const build = defineCommand({
|
|
|
39
41
|
async run(context) {
|
|
40
42
|
const { build } = await import('unbuild');
|
|
41
43
|
const cwd = resolve(context.args.cwd || context.args.rootDir || ".");
|
|
44
|
+
const jiti = createJiti(cwd);
|
|
42
45
|
const outDir = context.args.outDir || "dist";
|
|
43
46
|
await build(cwd, false, {
|
|
44
|
-
declaration:
|
|
47
|
+
declaration: "node16",
|
|
45
48
|
sourcemap: context.args.sourcemap,
|
|
46
49
|
stub: context.args.stub,
|
|
47
50
|
outDir,
|
|
@@ -52,6 +55,13 @@ const build = defineCommand({
|
|
|
52
55
|
outDir: `${outDir}/runtime`,
|
|
53
56
|
addRelativeDeclarationExtensions: true,
|
|
54
57
|
ext: "js",
|
|
58
|
+
pattern: [
|
|
59
|
+
"**",
|
|
60
|
+
"!**/*.stories.{js,cts,mts,ts,jsx,tsx}",
|
|
61
|
+
// ignore storybook files
|
|
62
|
+
"!**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}"
|
|
63
|
+
// ignore tests
|
|
64
|
+
],
|
|
55
65
|
esbuild: {
|
|
56
66
|
jsxImportSource: "vue",
|
|
57
67
|
jsx: "automatic",
|
|
@@ -64,16 +74,18 @@ const build = defineCommand({
|
|
|
64
74
|
target: "esnext"
|
|
65
75
|
},
|
|
66
76
|
emitCJS: false,
|
|
67
|
-
cjsBridge:
|
|
77
|
+
cjsBridge: false
|
|
68
78
|
},
|
|
69
79
|
externals: [
|
|
70
|
-
/dist
|
|
80
|
+
/dist[\\/]runtime[\\/]/,
|
|
71
81
|
"@nuxt/schema",
|
|
72
82
|
"@nuxt/schema-nightly",
|
|
73
83
|
"@nuxt/schema-edge",
|
|
74
84
|
"@nuxt/kit",
|
|
75
85
|
"@nuxt/kit-nightly",
|
|
76
86
|
"@nuxt/kit-edge",
|
|
87
|
+
"#app",
|
|
88
|
+
"#app/nuxt",
|
|
77
89
|
"nuxt",
|
|
78
90
|
"nuxt-nightly",
|
|
79
91
|
"nuxt-edge",
|
|
@@ -88,12 +100,20 @@ const build = defineCommand({
|
|
|
88
100
|
});
|
|
89
101
|
},
|
|
90
102
|
async "rollup:options"(ctx, options) {
|
|
91
|
-
|
|
103
|
+
const [entry] = ctx.buildEntries;
|
|
104
|
+
const mergedCompilerOptions = defu({
|
|
105
|
+
noEmit: false,
|
|
106
|
+
paths: {
|
|
107
|
+
"#app/nuxt": ["./node_modules/nuxt/dist/app/nuxt"]
|
|
108
|
+
}
|
|
109
|
+
}, ctx.options.rollup.dts.compilerOptions, await loadTSCompilerOptions(entry.path));
|
|
110
|
+
ctx.options.rollup.dts.compilerOptions = convertCompilerOptionsFromJson(mergedCompilerOptions, entry.path).options;
|
|
111
|
+
options.plugins ||= [];
|
|
92
112
|
if (!Array.isArray(options.plugins))
|
|
93
113
|
options.plugins = [options.plugins];
|
|
94
|
-
const runtimeEntries = ctx.options.entries.filter((
|
|
95
|
-
const runtimeDirs = runtimeEntries.map((
|
|
96
|
-
const RUNTIME_RE = createRegExp(anyOf(...runtimeDirs).and("/"));
|
|
114
|
+
const runtimeEntries = ctx.options.entries.filter((entry2) => entry2.builder === "mkdist");
|
|
115
|
+
const runtimeDirs = runtimeEntries.map((entry2) => basename(entry2.input));
|
|
116
|
+
const RUNTIME_RE = createRegExp(anyOf(...runtimeDirs).and(anyOf("/", "\\")));
|
|
97
117
|
options.plugins.unshift({
|
|
98
118
|
name: "nuxt-module-builder:runtime-externals",
|
|
99
119
|
async resolveId(id, importer) {
|
|
@@ -102,10 +122,11 @@ const build = defineCommand({
|
|
|
102
122
|
const resolved = await this.resolve(id, importer, { skipSelf: true });
|
|
103
123
|
if (!resolved)
|
|
104
124
|
return;
|
|
105
|
-
|
|
106
|
-
|
|
125
|
+
const normalizedId = normalize(resolved.id);
|
|
126
|
+
for (const entry2 of runtimeEntries) {
|
|
127
|
+
if (!normalizedId.includes(entry2.input))
|
|
107
128
|
continue;
|
|
108
|
-
const distFile = await resolvePath(join(dirname(
|
|
129
|
+
const distFile = await resolvePath(join(dirname(pathToFileURL(normalizedId).href.replace(entry2.input, entry2.outDir)), filename(normalizedId)));
|
|
109
130
|
if (distFile) {
|
|
110
131
|
return {
|
|
111
132
|
external: true,
|
|
@@ -117,9 +138,8 @@ const build = defineCommand({
|
|
|
117
138
|
});
|
|
118
139
|
},
|
|
119
140
|
async "rollup:done"(ctx) {
|
|
120
|
-
await writeCJSStub(ctx.options.outDir);
|
|
121
141
|
const moduleEntryPath = resolve(ctx.options.outDir, "module.mjs");
|
|
122
|
-
const moduleFn = await import(pathToFileURL(moduleEntryPath).toString()
|
|
142
|
+
const moduleFn = await jiti.import(pathToFileURL(moduleEntryPath).toString(), { default: true }).catch((err) => {
|
|
123
143
|
consola.error(err);
|
|
124
144
|
consola.error("Cannot load module. Please check dist:", moduleEntryPath);
|
|
125
145
|
return null;
|
|
@@ -143,20 +163,32 @@ const build = defineCommand({
|
|
|
143
163
|
const metaFile = resolve(ctx.options.outDir, "module.json");
|
|
144
164
|
await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
|
|
145
165
|
await writeTypes(ctx.options.outDir, ctx.options.stub);
|
|
166
|
+
},
|
|
167
|
+
async "build:done"(ctx) {
|
|
168
|
+
const logs = [...ctx.warnings].filter((l) => l.startsWith("Potential missing package.json files:"));
|
|
169
|
+
if (logs.filter((l) => l.match(/\.d\.ts/)).length > 0) {
|
|
170
|
+
consola.warn(`\`@nuxt/module-builder\` no longer supports Node10 TypeScript module resolution and will no longer generate \`.d.ts\` declaration files. You can update these paths to use the \`.d.mts\` extension instead.`);
|
|
171
|
+
}
|
|
172
|
+
if (logs.filter((l) => l.match(/module\.cjs/)).length > 0) {
|
|
173
|
+
consola.warn(`\`@nuxt/module-builder\` will no longer generate \`module.cjs\` as this is not required for Nuxt v3+. You can safely remove replace this with \`module.mjs\` in your \`package.json\`.`);
|
|
174
|
+
}
|
|
175
|
+
const pkg = await readPackageJSON(cwd);
|
|
176
|
+
if (pkg?.types && !existsSync(resolve(cwd, pkg.types))) {
|
|
177
|
+
consola.warn(`Please remove the \`types\` field from package.json as it is no longer required for Bundler TypeScript module resolution.`);
|
|
178
|
+
}
|
|
146
179
|
}
|
|
147
180
|
}
|
|
148
181
|
});
|
|
149
182
|
}
|
|
150
183
|
});
|
|
151
184
|
async function writeTypes(distDir, isStub) {
|
|
152
|
-
const dtsFile = resolve(distDir, "types.d.
|
|
153
|
-
const dtsFileMts = resolve(distDir, "types.d.mts");
|
|
185
|
+
const dtsFile = resolve(distDir, "types.d.mts");
|
|
154
186
|
if (existsSync(dtsFile)) {
|
|
155
187
|
return;
|
|
156
188
|
}
|
|
157
189
|
const moduleReExports = [];
|
|
158
190
|
if (!isStub) {
|
|
159
|
-
const moduleTypesFile = resolve(distDir, "module.d.
|
|
191
|
+
const moduleTypesFile = resolve(distDir, "module.d.mts");
|
|
160
192
|
const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
|
|
161
193
|
const normalisedModuleTypes = moduleTypes.replace(/export\s*\{.*?\}/gs, (match) => match.replace(/\b(type|interface)\b/g, ""));
|
|
162
194
|
for (const e of findExports(normalisedModuleTypes)) {
|
|
@@ -193,7 +225,7 @@ async function writeTypes(distDir, isStub) {
|
|
|
193
225
|
const dtsContents = `
|
|
194
226
|
${schemaImports.length ? `import type { ${schemaImports.join(", ")} } from '@nuxt/schema'` : ""}
|
|
195
227
|
|
|
196
|
-
${moduleImports.length ? `import type { ${moduleImports.join(", ")} } from './module'` : ""}
|
|
228
|
+
${moduleImports.length ? `import type { ${moduleImports.join(", ")} } from './module.mjs'` : ""}
|
|
197
229
|
|
|
198
230
|
${appShims.length ? `declare module '#app' {
|
|
199
231
|
${appShims.join("\n")}
|
|
@@ -205,27 +237,11 @@ ${schemaShims.join("\n")}
|
|
|
205
237
|
` : ""}
|
|
206
238
|
${moduleExports.length ? `
|
|
207
239
|
${moduleExports.join("\n")}` : ""}
|
|
208
|
-
${isStub ? 'export * from "./module"' : ""}
|
|
240
|
+
${isStub ? 'export * from "./module.mjs"' : ""}
|
|
209
241
|
${moduleReExports[0] ? `
|
|
210
|
-
export { ${moduleReExports[0].names.map((n) => (n === "default" ? "" : "type ") + n).join(", ")} } from './module'` : ""}
|
|
242
|
+
export { ${moduleReExports[0].names.map((n) => (n === "default" ? "" : "type ") + n).join(", ")} } from './module.mjs'` : ""}
|
|
211
243
|
`.trim().replace(/[\n\r]{3,}/g, "\n\n") + "\n";
|
|
212
244
|
await promises.writeFile(dtsFile, dtsContents, "utf8");
|
|
213
|
-
if (!existsSync(dtsFileMts)) {
|
|
214
|
-
await promises.writeFile(dtsFileMts, dtsContents.replace(/\.\/module/g, "./module.js"), "utf8");
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
async function writeCJSStub(distDir) {
|
|
218
|
-
const cjsStubFile = resolve(distDir, "module.cjs");
|
|
219
|
-
if (existsSync(cjsStubFile)) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
const cjsStub = `module.exports = function(...args) {
|
|
223
|
-
return import('./module.mjs').then(m => m.default.call(this, ...args))
|
|
224
|
-
}
|
|
225
|
-
const _meta = module.exports.meta = require('./module.json')
|
|
226
|
-
module.exports.getMeta = () => Promise.resolve(_meta)
|
|
227
|
-
`;
|
|
228
|
-
await promises.writeFile(cjsStubFile, cjsStub, "utf8");
|
|
229
245
|
}
|
|
230
246
|
async function loadTSCompilerOptions(path) {
|
|
231
247
|
const config = await parse(path);
|
|
@@ -233,8 +249,7 @@ async function loadTSCompilerOptions(path) {
|
|
|
233
249
|
for (const { tsconfig, tsconfigFile } of config.extended || []) {
|
|
234
250
|
for (const alias in tsconfig.compilerOptions?.paths || {}) {
|
|
235
251
|
resolvedCompilerOptions.paths[alias] = resolvedCompilerOptions.paths[alias].map((p) => {
|
|
236
|
-
if (!/^\.{1,2}(?:\/|$)/.test(p))
|
|
237
|
-
return p;
|
|
252
|
+
if (!/^\.{1,2}(?:\/|$)/.test(p)) return p;
|
|
238
253
|
return resolve(dirname(tsconfigFile), p);
|
|
239
254
|
});
|
|
240
255
|
}
|
package/dist/cli.d.mts
CHANGED
package/dist/cli.d.ts
CHANGED
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.D3Pp640p.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
|
@@ -7,8 +7,10 @@ import 'pathe/utils';
|
|
|
7
7
|
import 'pkg-types';
|
|
8
8
|
import 'tsconfck';
|
|
9
9
|
import 'defu';
|
|
10
|
+
import 'jiti';
|
|
10
11
|
import 'magic-regexp';
|
|
11
12
|
import 'consola';
|
|
12
13
|
import 'mlly';
|
|
13
14
|
import 'citty';
|
|
14
|
-
import '
|
|
15
|
+
import 'typescript';
|
|
16
|
+
import './shared/module-builder.D3Pp640p.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/module-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
4
|
"repository": "nuxt/module-builder",
|
|
5
5
|
"description": "Complete solution for building Nuxt modules",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,39 +21,41 @@
|
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"citty": "^0.1.6",
|
|
24
|
-
"consola": "^3.
|
|
24
|
+
"consola": "^3.3.3",
|
|
25
25
|
"defu": "^6.1.4",
|
|
26
|
+
"jiti": "^2.4.2",
|
|
26
27
|
"magic-regexp": "^0.8.0",
|
|
27
|
-
"mlly": "^1.7.
|
|
28
|
-
"pathe": "^
|
|
29
|
-
"pkg-types": "^1.
|
|
30
|
-
"tsconfck": "^3.1.
|
|
31
|
-
"unbuild": "^2.0
|
|
28
|
+
"mlly": "^1.7.3",
|
|
29
|
+
"pathe": "^2.0.0",
|
|
30
|
+
"pkg-types": "^1.3.0",
|
|
31
|
+
"tsconfck": "^3.1.4",
|
|
32
|
+
"unbuild": "^3.2.0"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
35
|
+
"nuxi": "^3.18.2",
|
|
36
|
+
"typescript": "^5.7.2"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@nuxt/eslint-config": "^0.
|
|
39
|
-
"@nuxt/
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"vue": "^
|
|
51
|
-
"vue-tsc": "^2.1.6"
|
|
39
|
+
"@nuxt/eslint-config": "^0.7.4",
|
|
40
|
+
"@nuxt/schema": "^3.15.1",
|
|
41
|
+
"@types/node": "^22.10.5",
|
|
42
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
43
|
+
"changelogen": "^0.5.7",
|
|
44
|
+
"eslint": "^9.17.0",
|
|
45
|
+
"nuxi": "^3.18.2",
|
|
46
|
+
"nuxt": "^3.15.1",
|
|
47
|
+
"tinyexec": "^0.3.2",
|
|
48
|
+
"typescript": "~5.7.2",
|
|
49
|
+
"vitest": "^2.1.8",
|
|
50
|
+
"vue": "^3.5.13",
|
|
51
|
+
"vue-tsc": "^2.2.0"
|
|
52
52
|
},
|
|
53
53
|
"resolutions": {
|
|
54
|
-
"@nuxt/kit": "^3.
|
|
55
|
-
"@nuxt/schema": "^3.
|
|
56
|
-
"
|
|
54
|
+
"@nuxt/kit": "^3.15.1",
|
|
55
|
+
"@nuxt/schema": "^3.15.1",
|
|
56
|
+
"typescript": "^5.7.2",
|
|
57
|
+
"vue": "^3.5.13",
|
|
58
|
+
"vue-tsc": "^2.2.0"
|
|
57
59
|
},
|
|
58
60
|
"scripts": {
|
|
59
61
|
"build": "unbuild",
|
|
@@ -62,7 +64,7 @@
|
|
|
62
64
|
"lint": "eslint .",
|
|
63
65
|
"nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
|
|
64
66
|
"release": "pnpm vitest run && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
|
|
65
|
-
"test": "pnpm vitest",
|
|
67
|
+
"test": "pnpm vitest --coverage",
|
|
66
68
|
"test:types": "vue-tsc --noEmit && pnpm -r test:types"
|
|
67
69
|
}
|
|
68
70
|
}
|