@nuxt/module-builder 0.5.1 → 0.5.3
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 +1 -1
- package/dist/chunks/build.mjs +162 -0
- package/dist/chunks/prepare.mjs +46 -0
- package/dist/cli.mjs +24 -23
- package/dist/index.d.mts +34 -12
- package/dist/index.d.ts +34 -12
- package/dist/index.mjs +8 -155
- package/package.json +16 -17
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ npx nuxi init -t module my-module
|
|
|
34
34
|
|
|
35
35
|
## Project structure
|
|
36
36
|
|
|
37
|
-
The module builder requires a special project
|
|
37
|
+
The module builder requires a special project structure. You can check out the [module template](https://github.com/nuxt/starter/tree/module).
|
|
38
38
|
|
|
39
39
|
### `src/module.ts`
|
|
40
40
|
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { promises, existsSync } from 'fs';
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
3
|
+
import { resolve } from 'pathe';
|
|
4
|
+
import { consola } from 'consola';
|
|
5
|
+
import { findExports } from 'mlly';
|
|
6
|
+
import { defineCommand } from 'citty';
|
|
7
|
+
|
|
8
|
+
const build = defineCommand({
|
|
9
|
+
meta: {
|
|
10
|
+
name: "build",
|
|
11
|
+
description: "Build module for distribution"
|
|
12
|
+
},
|
|
13
|
+
args: {
|
|
14
|
+
cwd: {
|
|
15
|
+
type: "string",
|
|
16
|
+
description: "Current working directory"
|
|
17
|
+
},
|
|
18
|
+
rootDir: {
|
|
19
|
+
type: "positional",
|
|
20
|
+
description: "Root directory",
|
|
21
|
+
required: false
|
|
22
|
+
},
|
|
23
|
+
outDir: {
|
|
24
|
+
type: "string"
|
|
25
|
+
},
|
|
26
|
+
sourcemap: {
|
|
27
|
+
type: "boolean"
|
|
28
|
+
},
|
|
29
|
+
stub: {
|
|
30
|
+
type: "boolean"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
async run(context) {
|
|
34
|
+
const { build } = await import('unbuild');
|
|
35
|
+
const cwd = resolve(context.args.cwd || context.args.rootDir || ".");
|
|
36
|
+
const outDir = context.args.outDir || "dist";
|
|
37
|
+
await build(cwd, false, {
|
|
38
|
+
declaration: true,
|
|
39
|
+
sourcemap: context.args.sourcemap,
|
|
40
|
+
stub: context.args.stub,
|
|
41
|
+
outDir,
|
|
42
|
+
entries: [
|
|
43
|
+
"src/module",
|
|
44
|
+
{ input: "src/runtime/", outDir: `${outDir}/runtime`, ext: "mjs" }
|
|
45
|
+
],
|
|
46
|
+
rollup: {
|
|
47
|
+
esbuild: {
|
|
48
|
+
target: "esnext"
|
|
49
|
+
},
|
|
50
|
+
emitCJS: false,
|
|
51
|
+
cjsBridge: true
|
|
52
|
+
},
|
|
53
|
+
externals: [
|
|
54
|
+
"@nuxt/schema",
|
|
55
|
+
"@nuxt/schema-edge",
|
|
56
|
+
"@nuxt/kit",
|
|
57
|
+
"@nuxt/kit-edge",
|
|
58
|
+
"nuxt",
|
|
59
|
+
"nuxt-edge",
|
|
60
|
+
"nuxt3",
|
|
61
|
+
"vue",
|
|
62
|
+
"vue-demi"
|
|
63
|
+
],
|
|
64
|
+
hooks: {
|
|
65
|
+
async "rollup:done"(ctx) {
|
|
66
|
+
await writeCJSStub(ctx.options.outDir);
|
|
67
|
+
const moduleEntryPath = resolve(ctx.options.outDir, "module.mjs");
|
|
68
|
+
const moduleFn = await import(pathToFileURL(moduleEntryPath).toString()).then((r) => r.default || r).catch((err) => {
|
|
69
|
+
consola.error(err);
|
|
70
|
+
consola.error("Cannot load module. Please check dist:", moduleEntryPath);
|
|
71
|
+
return null;
|
|
72
|
+
});
|
|
73
|
+
if (!moduleFn) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const moduleMeta = await moduleFn.getMeta();
|
|
77
|
+
if (ctx.pkg) {
|
|
78
|
+
if (!moduleMeta.name) {
|
|
79
|
+
moduleMeta.name = ctx.pkg.name;
|
|
80
|
+
}
|
|
81
|
+
if (!moduleMeta.version) {
|
|
82
|
+
moduleMeta.version = ctx.pkg.version;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const metaFile = resolve(ctx.options.outDir, "module.json");
|
|
86
|
+
await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
|
|
87
|
+
await writeTypes(ctx.options.outDir, moduleMeta);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
async function writeTypes(distDir, meta) {
|
|
94
|
+
const dtsFile = resolve(distDir, "types.d.ts");
|
|
95
|
+
const dtsFileMts = resolve(distDir, "types.d.mts");
|
|
96
|
+
if (existsSync(dtsFile)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const moduleTypesFile = resolve(distDir, "module.d.ts");
|
|
100
|
+
const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
|
|
101
|
+
const typeExports = findExports(
|
|
102
|
+
// Replace `export { type Foo }` with `export { Foo }`
|
|
103
|
+
moduleTypes.replace(
|
|
104
|
+
/export\s*{.*?}/sg,
|
|
105
|
+
(match) => match.replace(/\btype\b/g, "")
|
|
106
|
+
)
|
|
107
|
+
);
|
|
108
|
+
const isStub = moduleTypes.includes("export *");
|
|
109
|
+
const schemaShims = [];
|
|
110
|
+
const moduleImports = [];
|
|
111
|
+
const hasTypeExport = (name) => isStub || typeExports.find((exp) => exp.names.includes(name));
|
|
112
|
+
if (meta.configKey && hasTypeExport("ModuleOptions")) {
|
|
113
|
+
moduleImports.push("ModuleOptions");
|
|
114
|
+
schemaShims.push(` interface NuxtConfig { ['${meta.configKey}']?: Partial<ModuleOptions> }`);
|
|
115
|
+
schemaShims.push(` interface NuxtOptions { ['${meta.configKey}']?: ModuleOptions }`);
|
|
116
|
+
}
|
|
117
|
+
if (hasTypeExport("ModuleHooks")) {
|
|
118
|
+
moduleImports.push("ModuleHooks");
|
|
119
|
+
schemaShims.push(" interface NuxtHooks extends ModuleHooks {}");
|
|
120
|
+
}
|
|
121
|
+
if (hasTypeExport("ModuleRuntimeConfig")) {
|
|
122
|
+
moduleImports.push("ModuleRuntimeConfig");
|
|
123
|
+
schemaShims.push(" interface RuntimeConfig extends ModuleRuntimeConfig {}");
|
|
124
|
+
}
|
|
125
|
+
if (hasTypeExport("ModulePublicRuntimeConfig")) {
|
|
126
|
+
moduleImports.push("ModulePublicRuntimeConfig");
|
|
127
|
+
schemaShims.push(" interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}");
|
|
128
|
+
}
|
|
129
|
+
const dtsContents = `
|
|
130
|
+
import { ${moduleImports.join(", ")} } from './module'
|
|
131
|
+
|
|
132
|
+
${schemaShims.length ? `declare module '@nuxt/schema' {
|
|
133
|
+
${schemaShims.join("\n")}
|
|
134
|
+
}
|
|
135
|
+
` : ""}
|
|
136
|
+
${schemaShims.length ? `declare module 'nuxt/schema' {
|
|
137
|
+
${schemaShims.join("\n")}
|
|
138
|
+
}
|
|
139
|
+
` : ""}
|
|
140
|
+
|
|
141
|
+
export { ${typeExports[0].names.join(", ")} } from './module'
|
|
142
|
+
`;
|
|
143
|
+
await promises.writeFile(dtsFile, dtsContents, "utf8");
|
|
144
|
+
if (!existsSync(dtsFileMts)) {
|
|
145
|
+
await promises.writeFile(dtsFileMts, dtsContents, "utf8");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function writeCJSStub(distDir) {
|
|
149
|
+
const cjsStubFile = resolve(distDir, "module.cjs");
|
|
150
|
+
if (existsSync(cjsStubFile)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const cjsStub = `module.exports = function(...args) {
|
|
154
|
+
return import('./module.mjs').then(m => m.default.call(this, ...args))
|
|
155
|
+
}
|
|
156
|
+
const _meta = module.exports.meta = require('./module.json')
|
|
157
|
+
module.exports.getMeta = () => Promise.resolve(_meta)
|
|
158
|
+
`;
|
|
159
|
+
await promises.writeFile(cjsStubFile, cjsStub, "utf8");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export { build as default };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { resolve } from 'pathe';
|
|
3
|
+
|
|
4
|
+
const prepare = defineCommand({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "prepare",
|
|
7
|
+
description: "Prepare @nuxt/module-builder environment by writing types and stubs"
|
|
8
|
+
},
|
|
9
|
+
args: {
|
|
10
|
+
cwd: {
|
|
11
|
+
type: "string",
|
|
12
|
+
description: "Current working directory"
|
|
13
|
+
},
|
|
14
|
+
rootDir: {
|
|
15
|
+
type: "positional",
|
|
16
|
+
description: "Root directory",
|
|
17
|
+
required: false
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
async run(context) {
|
|
21
|
+
const { runCommand } = await import('nuxi');
|
|
22
|
+
const cwd = resolve(context.args.cwd || context.args.rootDir || ".");
|
|
23
|
+
return runCommand("prepare", [cwd], {
|
|
24
|
+
overrides: {
|
|
25
|
+
typescript: {
|
|
26
|
+
builder: "shared"
|
|
27
|
+
},
|
|
28
|
+
imports: {
|
|
29
|
+
autoImport: false
|
|
30
|
+
},
|
|
31
|
+
modules: [
|
|
32
|
+
resolve(cwd, "./src/module"),
|
|
33
|
+
function(_options, nuxt) {
|
|
34
|
+
nuxt.hooks.hook("app:templates", (app) => {
|
|
35
|
+
for (const template of app.templates) {
|
|
36
|
+
template.write = true;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export { prepare as default };
|
package/dist/cli.mjs
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { prepareModule, buildModule } from './index.mjs';
|
|
5
|
-
import 'fs';
|
|
6
|
-
import 'url';
|
|
7
|
-
import 'consola';
|
|
8
|
-
import 'mlly';
|
|
2
|
+
import { defineCommand, runMain } from 'citty';
|
|
3
|
+
import { consola } from 'consola';
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
const name = "@nuxt/module-builder";
|
|
6
|
+
const version = "0.5.3";
|
|
7
|
+
const description = "Complete solution for building Nuxt modules";
|
|
8
|
+
|
|
9
|
+
const _rDefault = (r) => r.default || r;
|
|
10
|
+
const main = defineCommand({
|
|
11
|
+
meta: {
|
|
12
|
+
name,
|
|
13
|
+
description,
|
|
14
|
+
version
|
|
15
|
+
},
|
|
16
|
+
subCommands: {
|
|
17
|
+
prepare: () => import('./chunks/prepare.mjs').then(_rDefault),
|
|
18
|
+
build: () => import('./chunks/build.mjs').then(_rDefault)
|
|
19
|
+
},
|
|
20
|
+
setup(context) {
|
|
21
|
+
const firstArg = context.rawArgs[0];
|
|
22
|
+
if (!(firstArg in context.cmd.subCommands)) {
|
|
23
|
+
consola.warn("Please specify the `build` command explicitly. In a future version of `@nuxt/module-builder`, the implicit default build command will be removed.");
|
|
24
|
+
context.rawArgs.unshift("build");
|
|
25
|
+
}
|
|
16
26
|
}
|
|
17
|
-
return buildModule({
|
|
18
|
-
rootDir: resolve(args._[0] || "."),
|
|
19
|
-
outDir: args.outDir,
|
|
20
|
-
sourcemap: args.sourcemap,
|
|
21
|
-
stub: args.stub
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
main().catch((err) => {
|
|
25
|
-
console.error(err);
|
|
26
|
-
process.exit(1);
|
|
27
27
|
});
|
|
28
|
+
runMain(main);
|
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
rootDir: string;
|
|
3
|
-
sourcemap?: boolean;
|
|
4
|
-
stub?: boolean;
|
|
5
|
-
outDir?: string;
|
|
6
|
-
}
|
|
7
|
-
declare function buildModule(opts: BuildModuleOptions): Promise<void>;
|
|
1
|
+
import * as citty from 'citty';
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
declare const _default$1: citty.CommandDef<{
|
|
4
|
+
cwd: {
|
|
5
|
+
type: "string";
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
rootDir: {
|
|
9
|
+
type: "positional";
|
|
10
|
+
description: string;
|
|
11
|
+
required: false;
|
|
12
|
+
};
|
|
13
|
+
outDir: {
|
|
14
|
+
type: "string";
|
|
15
|
+
};
|
|
16
|
+
sourcemap: {
|
|
17
|
+
type: "boolean";
|
|
18
|
+
};
|
|
19
|
+
stub: {
|
|
20
|
+
type: "boolean";
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
13
23
|
|
|
14
|
-
|
|
24
|
+
declare const _default: citty.CommandDef<{
|
|
25
|
+
cwd: {
|
|
26
|
+
type: "string";
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
rootDir: {
|
|
30
|
+
type: "positional";
|
|
31
|
+
description: string;
|
|
32
|
+
required: false;
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
|
|
36
|
+
export { _default$1 as build, _default as prepare };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
rootDir: string;
|
|
3
|
-
sourcemap?: boolean;
|
|
4
|
-
stub?: boolean;
|
|
5
|
-
outDir?: string;
|
|
6
|
-
}
|
|
7
|
-
declare function buildModule(opts: BuildModuleOptions): Promise<void>;
|
|
1
|
+
import * as citty from 'citty';
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
declare const _default$1: citty.CommandDef<{
|
|
4
|
+
cwd: {
|
|
5
|
+
type: "string";
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
rootDir: {
|
|
9
|
+
type: "positional";
|
|
10
|
+
description: string;
|
|
11
|
+
required: false;
|
|
12
|
+
};
|
|
13
|
+
outDir: {
|
|
14
|
+
type: "string";
|
|
15
|
+
};
|
|
16
|
+
sourcemap: {
|
|
17
|
+
type: "boolean";
|
|
18
|
+
};
|
|
19
|
+
stub: {
|
|
20
|
+
type: "boolean";
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
13
23
|
|
|
14
|
-
|
|
24
|
+
declare const _default: citty.CommandDef<{
|
|
25
|
+
cwd: {
|
|
26
|
+
type: "string";
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
rootDir: {
|
|
30
|
+
type: "positional";
|
|
31
|
+
description: string;
|
|
32
|
+
required: false;
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
|
|
36
|
+
export { _default$1 as build, _default as prepare };
|
package/dist/index.mjs
CHANGED
|
@@ -1,155 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const outDir = opts.outDir || "dist";
|
|
10
|
-
await build(opts.rootDir, false, {
|
|
11
|
-
declaration: true,
|
|
12
|
-
sourcemap: opts.sourcemap,
|
|
13
|
-
stub: opts.stub,
|
|
14
|
-
outDir,
|
|
15
|
-
entries: [
|
|
16
|
-
"src/module",
|
|
17
|
-
{ input: "src/runtime/", outDir: `${outDir}/runtime`, ext: "mjs" }
|
|
18
|
-
],
|
|
19
|
-
rollup: {
|
|
20
|
-
emitCJS: false,
|
|
21
|
-
cjsBridge: true
|
|
22
|
-
},
|
|
23
|
-
externals: [
|
|
24
|
-
"@nuxt/schema",
|
|
25
|
-
"@nuxt/schema-edge",
|
|
26
|
-
"@nuxt/kit",
|
|
27
|
-
"@nuxt/kit-edge",
|
|
28
|
-
"nuxt",
|
|
29
|
-
"nuxt-edge",
|
|
30
|
-
"nuxt3",
|
|
31
|
-
"vue",
|
|
32
|
-
"vue-demi"
|
|
33
|
-
],
|
|
34
|
-
hooks: {
|
|
35
|
-
async "rollup:done"(ctx) {
|
|
36
|
-
await writeCJSStub(ctx.options.outDir);
|
|
37
|
-
const moduleEntryPath = resolve(ctx.options.outDir, "module.mjs");
|
|
38
|
-
const moduleFn = await import(pathToFileURL(moduleEntryPath).toString()).then((r) => r.default || r).catch((err) => {
|
|
39
|
-
consola.error(err);
|
|
40
|
-
consola.error("Cannot load module. Please check dist:", moduleEntryPath);
|
|
41
|
-
return null;
|
|
42
|
-
});
|
|
43
|
-
if (!moduleFn) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const moduleMeta = await moduleFn.getMeta();
|
|
47
|
-
if (ctx.pkg) {
|
|
48
|
-
if (!moduleMeta.name) {
|
|
49
|
-
moduleMeta.name = ctx.pkg.name;
|
|
50
|
-
}
|
|
51
|
-
if (!moduleMeta.version) {
|
|
52
|
-
moduleMeta.version = ctx.pkg.version;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const metaFile = resolve(ctx.options.outDir, "module.json");
|
|
56
|
-
await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
|
|
57
|
-
await writeTypes(ctx.options.outDir, moduleMeta);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
async function writeTypes(distDir, meta) {
|
|
63
|
-
const dtsFile = resolve(distDir, "types.d.ts");
|
|
64
|
-
const dtsFileMts = resolve(distDir, "types.d.mts");
|
|
65
|
-
if (existsSync(dtsFile)) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const moduleTypesFile = resolve(distDir, "module.d.ts");
|
|
69
|
-
const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
|
|
70
|
-
const typeExports = findExports(
|
|
71
|
-
// Replace `export { type Foo }` with `export { Foo }`
|
|
72
|
-
moduleTypes.replace(
|
|
73
|
-
/export\s*{.*?}/sg,
|
|
74
|
-
(match) => match.replace(/\btype\b/g, "")
|
|
75
|
-
)
|
|
76
|
-
);
|
|
77
|
-
const isStub = moduleTypes.includes("export *");
|
|
78
|
-
const schemaShims = [];
|
|
79
|
-
const moduleImports = [];
|
|
80
|
-
const hasTypeExport = (name) => isStub || typeExports.find((exp) => exp.names.includes(name));
|
|
81
|
-
if (meta.configKey && hasTypeExport("ModuleOptions")) {
|
|
82
|
-
moduleImports.push("ModuleOptions");
|
|
83
|
-
schemaShims.push(` interface NuxtConfig { ['${meta.configKey}']?: Partial<ModuleOptions> }`);
|
|
84
|
-
schemaShims.push(` interface NuxtOptions { ['${meta.configKey}']?: ModuleOptions }`);
|
|
85
|
-
}
|
|
86
|
-
if (hasTypeExport("ModuleHooks")) {
|
|
87
|
-
moduleImports.push("ModuleHooks");
|
|
88
|
-
schemaShims.push(" interface NuxtHooks extends ModuleHooks {}");
|
|
89
|
-
}
|
|
90
|
-
if (hasTypeExport("ModuleRuntimeConfig")) {
|
|
91
|
-
moduleImports.push("ModuleRuntimeConfig");
|
|
92
|
-
schemaShims.push(" interface RuntimeConfig extends ModuleRuntimeConfig {}");
|
|
93
|
-
}
|
|
94
|
-
if (hasTypeExport("ModulePublicRuntimeConfig")) {
|
|
95
|
-
moduleImports.push("ModulePublicRuntimeConfig");
|
|
96
|
-
schemaShims.push(" interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}");
|
|
97
|
-
}
|
|
98
|
-
const dtsContents = `
|
|
99
|
-
import { ${moduleImports.join(", ")} } from './module'
|
|
100
|
-
|
|
101
|
-
${schemaShims.length ? `declare module '@nuxt/schema' {
|
|
102
|
-
${schemaShims.join("\n")}
|
|
103
|
-
}
|
|
104
|
-
` : ""}
|
|
105
|
-
${schemaShims.length ? `declare module 'nuxt/schema' {
|
|
106
|
-
${schemaShims.join("\n")}
|
|
107
|
-
}
|
|
108
|
-
` : ""}
|
|
109
|
-
|
|
110
|
-
export { ${typeExports[0].names.join(", ")} } from './module'
|
|
111
|
-
`;
|
|
112
|
-
await promises.writeFile(dtsFile, dtsContents, "utf8");
|
|
113
|
-
if (!existsSync(dtsFileMts)) {
|
|
114
|
-
await promises.writeFile(dtsFileMts, dtsContents, "utf8");
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
async function writeCJSStub(distDir) {
|
|
118
|
-
const cjsStubFile = resolve(distDir, "module.cjs");
|
|
119
|
-
if (existsSync(cjsStubFile)) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const cjsStub = `module.exports = function(...args) {
|
|
123
|
-
return import('./module.mjs').then(m => m.default.call(this, ...args))
|
|
124
|
-
}
|
|
125
|
-
const _meta = module.exports.meta = require('./module.json')
|
|
126
|
-
module.exports.getMeta = () => Promise.resolve(_meta)
|
|
127
|
-
`;
|
|
128
|
-
await promises.writeFile(cjsStubFile, cjsStub, "utf8");
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async function prepareModule(options) {
|
|
132
|
-
const { runCommand } = await import('nuxi');
|
|
133
|
-
return runCommand("prepare", [options.rootDir], {
|
|
134
|
-
overrides: {
|
|
135
|
-
typescript: {
|
|
136
|
-
builder: "shared"
|
|
137
|
-
},
|
|
138
|
-
imports: {
|
|
139
|
-
autoImport: false
|
|
140
|
-
},
|
|
141
|
-
modules: [
|
|
142
|
-
resolve(options.rootDir, "./src/module"),
|
|
143
|
-
function(_options, nuxt) {
|
|
144
|
-
nuxt.hooks.hook("app:templates", (app) => {
|
|
145
|
-
for (const template of app.templates) {
|
|
146
|
-
template.write = true;
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export { buildModule, prepareModule };
|
|
1
|
+
export { default as build } from './chunks/build.mjs';
|
|
2
|
+
export { default as prepare } from './chunks/prepare.mjs';
|
|
3
|
+
import 'fs';
|
|
4
|
+
import 'url';
|
|
5
|
+
import 'pathe';
|
|
6
|
+
import 'consola';
|
|
7
|
+
import 'mlly';
|
|
8
|
+
import 'citty';
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/module-builder",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"repository": "nuxt/module-builder",
|
|
5
|
-
"description": "Complete solution
|
|
5
|
+
"description": "Complete solution for building Nuxt modules",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
@@ -19,31 +19,30 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
|
-
"packageManager": "pnpm@8.
|
|
22
|
+
"packageManager": "pnpm@8.10.2",
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"citty": "^0.1.4",
|
|
24
25
|
"consola": "^3.2.3",
|
|
25
|
-
"mlly": "^1.4.
|
|
26
|
-
"mri": "^1.2.0",
|
|
26
|
+
"mlly": "^1.4.2",
|
|
27
27
|
"pathe": "^1.1.1",
|
|
28
28
|
"unbuild": "^2.0.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@nuxt/kit": "^3.
|
|
32
|
-
"nuxi": "^3.
|
|
31
|
+
"@nuxt/kit": "^3.8.0",
|
|
32
|
+
"nuxi": "^3.9.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@nuxt/kit": "^3.
|
|
36
|
-
"@nuxt/schema": "^3.
|
|
35
|
+
"@nuxt/kit": "^3.8.0",
|
|
36
|
+
"@nuxt/schema": "^3.8.0",
|
|
37
37
|
"@nuxtjs/eslint-config-typescript": "^12.1.0",
|
|
38
|
-
"@types/
|
|
39
|
-
"@
|
|
40
|
-
"@vitest/coverage-v8": "^0.34.3",
|
|
38
|
+
"@types/node": "^20.8.10",
|
|
39
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
41
40
|
"changelogen": "^0.5.5",
|
|
42
|
-
"eslint": "^8.
|
|
43
|
-
"jiti": "^1.
|
|
44
|
-
"nuxi": "^3.
|
|
45
|
-
"nuxt": "^3.
|
|
46
|
-
"vitest": "^0.34.
|
|
41
|
+
"eslint": "^8.53.0",
|
|
42
|
+
"jiti": "^1.21.0",
|
|
43
|
+
"nuxi": "^3.9.1",
|
|
44
|
+
"nuxt": "^3.8.0",
|
|
45
|
+
"vitest": "^0.34.6"
|
|
47
46
|
},
|
|
48
47
|
"scripts": {
|
|
49
48
|
"build": "unbuild",
|