@nuxt/module-builder 0.8.4 → 1.0.0-alpha.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 +16 -2
- package/dist/chunks/build.mjs +32 -35
- package/dist/cli.d.mts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.mjs +2 -1
- package/dist/shared/{module-builder.617a9be8.mjs → module-builder.B6wMX_h6.mjs} +1 -1
- package/package.json +37 -35
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,16 @@
|
|
|
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 { n as name, v as version } from '../shared/module-builder.
|
|
13
|
+
import { n as name, v as version } from '../shared/module-builder.B6wMX_h6.mjs';
|
|
13
14
|
|
|
14
15
|
const build = defineCommand({
|
|
15
16
|
meta: {
|
|
@@ -39,9 +40,10 @@ const build = defineCommand({
|
|
|
39
40
|
async run(context) {
|
|
40
41
|
const { build } = await import('unbuild');
|
|
41
42
|
const cwd = resolve(context.args.cwd || context.args.rootDir || ".");
|
|
43
|
+
const jiti = createJiti(cwd);
|
|
42
44
|
const outDir = context.args.outDir || "dist";
|
|
43
45
|
await build(cwd, false, {
|
|
44
|
-
declaration:
|
|
46
|
+
declaration: "node16",
|
|
45
47
|
sourcemap: context.args.sourcemap,
|
|
46
48
|
stub: context.args.stub,
|
|
47
49
|
outDir,
|
|
@@ -64,10 +66,10 @@ const build = defineCommand({
|
|
|
64
66
|
target: "esnext"
|
|
65
67
|
},
|
|
66
68
|
emitCJS: false,
|
|
67
|
-
cjsBridge:
|
|
69
|
+
cjsBridge: false
|
|
68
70
|
},
|
|
69
71
|
externals: [
|
|
70
|
-
/dist
|
|
72
|
+
/dist[\\/]runtime[\\/]/,
|
|
71
73
|
"@nuxt/schema",
|
|
72
74
|
"@nuxt/schema-nightly",
|
|
73
75
|
"@nuxt/schema-edge",
|
|
@@ -88,12 +90,12 @@ const build = defineCommand({
|
|
|
88
90
|
});
|
|
89
91
|
},
|
|
90
92
|
async "rollup:options"(ctx, options) {
|
|
91
|
-
options.plugins
|
|
93
|
+
options.plugins ||= [];
|
|
92
94
|
if (!Array.isArray(options.plugins))
|
|
93
95
|
options.plugins = [options.plugins];
|
|
94
96
|
const runtimeEntries = ctx.options.entries.filter((entry) => entry.builder === "mkdist");
|
|
95
97
|
const runtimeDirs = runtimeEntries.map((entry) => basename(entry.input));
|
|
96
|
-
const RUNTIME_RE = createRegExp(anyOf(...runtimeDirs).and("/"));
|
|
98
|
+
const RUNTIME_RE = createRegExp(anyOf(...runtimeDirs).and(anyOf("/", "\\")));
|
|
97
99
|
options.plugins.unshift({
|
|
98
100
|
name: "nuxt-module-builder:runtime-externals",
|
|
99
101
|
async resolveId(id, importer) {
|
|
@@ -102,10 +104,11 @@ const build = defineCommand({
|
|
|
102
104
|
const resolved = await this.resolve(id, importer, { skipSelf: true });
|
|
103
105
|
if (!resolved)
|
|
104
106
|
return;
|
|
107
|
+
const normalizedId = normalize(resolved.id);
|
|
105
108
|
for (const entry of runtimeEntries) {
|
|
106
|
-
if (!
|
|
109
|
+
if (!normalizedId.includes(entry.input))
|
|
107
110
|
continue;
|
|
108
|
-
const distFile = await resolvePath(join(dirname(
|
|
111
|
+
const distFile = await resolvePath(join(dirname(pathToFileURL(normalizedId).href.replace(entry.input, entry.outDir)), filename(normalizedId)));
|
|
109
112
|
if (distFile) {
|
|
110
113
|
return {
|
|
111
114
|
external: true,
|
|
@@ -117,9 +120,8 @@ const build = defineCommand({
|
|
|
117
120
|
});
|
|
118
121
|
},
|
|
119
122
|
async "rollup:done"(ctx) {
|
|
120
|
-
await writeCJSStub(ctx.options.outDir);
|
|
121
123
|
const moduleEntryPath = resolve(ctx.options.outDir, "module.mjs");
|
|
122
|
-
const moduleFn = await import(pathToFileURL(moduleEntryPath).toString()
|
|
124
|
+
const moduleFn = await jiti.import(pathToFileURL(moduleEntryPath).toString(), { default: true }).catch((err) => {
|
|
123
125
|
consola.error(err);
|
|
124
126
|
consola.error("Cannot load module. Please check dist:", moduleEntryPath);
|
|
125
127
|
return null;
|
|
@@ -143,20 +145,32 @@ const build = defineCommand({
|
|
|
143
145
|
const metaFile = resolve(ctx.options.outDir, "module.json");
|
|
144
146
|
await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
|
|
145
147
|
await writeTypes(ctx.options.outDir, ctx.options.stub);
|
|
148
|
+
},
|
|
149
|
+
async "build:done"(ctx) {
|
|
150
|
+
const logs = [...ctx.warnings].filter((l) => l.startsWith("Potential missing package.json files:"));
|
|
151
|
+
if (logs.filter((l) => l.match(/\.d\.ts/)).length > 0) {
|
|
152
|
+
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.`);
|
|
153
|
+
}
|
|
154
|
+
if (logs.filter((l) => l.match(/module\.cjs/)).length > 0) {
|
|
155
|
+
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\`.`);
|
|
156
|
+
}
|
|
157
|
+
const pkg = await readPackageJSON(cwd);
|
|
158
|
+
if (pkg?.types && !existsSync(resolve(cwd, pkg.types))) {
|
|
159
|
+
consola.warn(`Please remove the \`types\` field from package.json as it is no longer required for Bundler TypeScript module resolution.`);
|
|
160
|
+
}
|
|
146
161
|
}
|
|
147
162
|
}
|
|
148
163
|
});
|
|
149
164
|
}
|
|
150
165
|
});
|
|
151
166
|
async function writeTypes(distDir, isStub) {
|
|
152
|
-
const dtsFile = resolve(distDir, "types.d.
|
|
153
|
-
const dtsFileMts = resolve(distDir, "types.d.mts");
|
|
167
|
+
const dtsFile = resolve(distDir, "types.d.mts");
|
|
154
168
|
if (existsSync(dtsFile)) {
|
|
155
169
|
return;
|
|
156
170
|
}
|
|
157
171
|
const moduleReExports = [];
|
|
158
172
|
if (!isStub) {
|
|
159
|
-
const moduleTypesFile = resolve(distDir, "module.d.
|
|
173
|
+
const moduleTypesFile = resolve(distDir, "module.d.mts");
|
|
160
174
|
const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
|
|
161
175
|
const normalisedModuleTypes = moduleTypes.replace(/export\s*\{.*?\}/gs, (match) => match.replace(/\b(type|interface)\b/g, ""));
|
|
162
176
|
for (const e of findExports(normalisedModuleTypes)) {
|
|
@@ -193,7 +207,7 @@ async function writeTypes(distDir, isStub) {
|
|
|
193
207
|
const dtsContents = `
|
|
194
208
|
${schemaImports.length ? `import type { ${schemaImports.join(", ")} } from '@nuxt/schema'` : ""}
|
|
195
209
|
|
|
196
|
-
${moduleImports.length ? `import type { ${moduleImports.join(", ")} } from './module'` : ""}
|
|
210
|
+
${moduleImports.length ? `import type { ${moduleImports.join(", ")} } from './module.mjs'` : ""}
|
|
197
211
|
|
|
198
212
|
${appShims.length ? `declare module '#app' {
|
|
199
213
|
${appShims.join("\n")}
|
|
@@ -205,27 +219,11 @@ ${schemaShims.join("\n")}
|
|
|
205
219
|
` : ""}
|
|
206
220
|
${moduleExports.length ? `
|
|
207
221
|
${moduleExports.join("\n")}` : ""}
|
|
208
|
-
${isStub ? 'export * from "./module"' : ""}
|
|
222
|
+
${isStub ? 'export * from "./module.mjs"' : ""}
|
|
209
223
|
${moduleReExports[0] ? `
|
|
210
|
-
export { ${moduleReExports[0].names.map((n) => (n === "default" ? "" : "type ") + n).join(", ")} } from './module'` : ""}
|
|
224
|
+
export { ${moduleReExports[0].names.map((n) => (n === "default" ? "" : "type ") + n).join(", ")} } from './module.mjs'` : ""}
|
|
211
225
|
`.trim().replace(/[\n\r]{3,}/g, "\n\n") + "\n";
|
|
212
226
|
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
227
|
}
|
|
230
228
|
async function loadTSCompilerOptions(path) {
|
|
231
229
|
const config = await parse(path);
|
|
@@ -233,8 +231,7 @@ async function loadTSCompilerOptions(path) {
|
|
|
233
231
|
for (const { tsconfig, tsconfigFile } of config.extended || []) {
|
|
234
232
|
for (const alias in tsconfig.compilerOptions?.paths || {}) {
|
|
235
233
|
resolvedCompilerOptions.paths[alias] = resolvedCompilerOptions.paths[alias].map((p) => {
|
|
236
|
-
if (!/^\.{1,2}(?:\/|$)/.test(p))
|
|
237
|
-
return p;
|
|
234
|
+
if (!/^\.{1,2}(?:\/|$)/.test(p)) return p;
|
|
238
235
|
return resolve(dirname(tsconfigFile), p);
|
|
239
236
|
});
|
|
240
237
|
}
|
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.B6wMX_h6.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,9 @@ 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 './shared/module-builder.
|
|
15
|
+
import './shared/module-builder.B6wMX_h6.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.0",
|
|
4
4
|
"repository": "nuxt/module-builder",
|
|
5
5
|
"description": "Complete solution for building Nuxt modules",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,50 +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 --coverage",
|
|
31
|
+
"test:types": "vue-tsc --noEmit && pnpm -r test:types"
|
|
32
|
+
},
|
|
33
|
+
"packageManager": "pnpm@9.15.0",
|
|
22
34
|
"dependencies": {
|
|
23
35
|
"citty": "^0.1.6",
|
|
24
36
|
"consola": "^3.2.3",
|
|
25
37
|
"defu": "^6.1.4",
|
|
38
|
+
"jiti": "^2.4.1",
|
|
26
39
|
"magic-regexp": "^0.8.0",
|
|
27
|
-
"mlly": "^1.7.
|
|
40
|
+
"mlly": "^1.7.3",
|
|
28
41
|
"pathe": "^1.1.2",
|
|
29
|
-
"pkg-types": "^1.2.
|
|
30
|
-
"tsconfck": "^3.1.
|
|
31
|
-
"unbuild": "^
|
|
42
|
+
"pkg-types": "^1.2.1",
|
|
43
|
+
"tsconfck": "^3.1.4",
|
|
44
|
+
"unbuild": "^3.0.0"
|
|
32
45
|
},
|
|
33
46
|
"peerDependencies": {
|
|
34
|
-
"
|
|
35
|
-
"nuxi": "^3.13.1"
|
|
47
|
+
"nuxi": "^3.16.0"
|
|
36
48
|
},
|
|
37
49
|
"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"
|
|
50
|
+
"@nuxt/eslint-config": "^0.7.3",
|
|
51
|
+
"@nuxt/schema": "^3.14.1592",
|
|
52
|
+
"@types/node": "^22.10.2",
|
|
53
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
54
|
+
"changelogen": "^0.5.7",
|
|
55
|
+
"eslint": "^9.16.0",
|
|
56
|
+
"nuxi": "^3.16.0",
|
|
57
|
+
"nuxt": "^3.14.1592",
|
|
58
|
+
"tinyexec": "^0.3.1",
|
|
59
|
+
"typescript": "~5.6.3",
|
|
60
|
+
"vitest": "^2.1.8",
|
|
61
|
+
"vue": "^3.5.13",
|
|
62
|
+
"vue-tsc": "^2.1.10"
|
|
52
63
|
},
|
|
53
64
|
"resolutions": {
|
|
54
|
-
"@nuxt/kit": "^3.
|
|
55
|
-
"@nuxt/schema": "^3.
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
"scripts": {
|
|
59
|
-
"build": "unbuild",
|
|
60
|
-
"dev:prepare": "pnpm -r dev:prepare",
|
|
61
|
-
"example:build": "pnpm nuxt-module-build build ./example",
|
|
62
|
-
"lint": "eslint .",
|
|
63
|
-
"nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
|
|
64
|
-
"release": "pnpm vitest run && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
|
|
65
|
-
"test": "pnpm vitest",
|
|
66
|
-
"test:types": "vue-tsc --noEmit && pnpm -r test:types"
|
|
65
|
+
"@nuxt/kit": "^3.14.1592",
|
|
66
|
+
"@nuxt/schema": "^3.14.1592",
|
|
67
|
+
"typescript": "~5.6.3",
|
|
68
|
+
"vue": "^3.5.13"
|
|
67
69
|
}
|
|
68
|
-
}
|
|
70
|
+
}
|