@nuxt/module-builder 0.1.3 → 0.1.4
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 +6 -0
- package/dist/chunks/build.mjs +21 -5
- package/dist/cli.mjs +5 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.mjs +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ This is the entrypoint for module definition.
|
|
|
24
24
|
|
|
25
25
|
A default export using `defineNuxtModule` and `ModuleOptions` type export is expected.
|
|
26
26
|
|
|
27
|
+
You could also optionally export `ModuleHooks` to annotate any custom hooks module uses.
|
|
28
|
+
|
|
27
29
|
```js [src/module.ts]
|
|
28
30
|
import { defineNuxtModule } from '@nuxt/kit'
|
|
29
31
|
|
|
@@ -31,6 +33,10 @@ export interface ModuleOptions {
|
|
|
31
33
|
apiKey: string
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
export interface ModuleHooks {
|
|
37
|
+
'my-module:init': any
|
|
38
|
+
}
|
|
39
|
+
|
|
34
40
|
export default defineNuxtModule<ModuleOptions>({
|
|
35
41
|
meta: {
|
|
36
42
|
name: 'my-module',
|
package/dist/chunks/build.mjs
CHANGED
|
@@ -2,11 +2,13 @@ import { promises, existsSync } from 'fs';
|
|
|
2
2
|
import { pathToFileURL } from 'url';
|
|
3
3
|
import { resolve } from 'pathe';
|
|
4
4
|
import consola from 'consola';
|
|
5
|
+
import { findExports } from 'mlly';
|
|
5
6
|
|
|
6
|
-
async function buildModule(
|
|
7
|
+
async function buildModule(opts) {
|
|
7
8
|
const { build } = await import('unbuild');
|
|
8
|
-
await build(rootDir, false, {
|
|
9
|
+
await build(opts.rootDir, false, {
|
|
9
10
|
declaration: true,
|
|
11
|
+
stub: opts.stub,
|
|
10
12
|
entries: [
|
|
11
13
|
"src/module",
|
|
12
14
|
{ input: "src/runtime/", outDir: "dist/runtime", ext: "mjs" }
|
|
@@ -54,17 +56,31 @@ async function writeTypes(distDir, meta) {
|
|
|
54
56
|
if (existsSync(dtsFile)) {
|
|
55
57
|
return;
|
|
56
58
|
}
|
|
59
|
+
const moduleTypesFile = resolve(distDir, "module.d.ts");
|
|
60
|
+
const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
|
|
61
|
+
const typeExports = findExports(moduleTypes);
|
|
62
|
+
const isStub = moduleTypes.includes("export *");
|
|
63
|
+
const hasModuleOptions = isStub || typeExports.find((exp) => exp.names.includes("ModuleOptions"));
|
|
64
|
+
const hasModuleHooks = isStub || typeExports.find((exp) => exp.names.includes("ModuleHooks"));
|
|
57
65
|
const schemaShims = [];
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
const moduleImports = [];
|
|
67
|
+
if (meta.configKey && hasModuleOptions) {
|
|
68
|
+
moduleImports.push("ModuleOptions");
|
|
69
|
+
schemaShims.push(` interface NuxtConfig { ['${meta.configKey}']?: Partial<ModuleOptions> }`);
|
|
70
|
+
schemaShims.push(` interface NuxtOptions { ['${meta.configKey}']?: ModuleOptions }`);
|
|
71
|
+
}
|
|
72
|
+
if (hasModuleHooks) {
|
|
73
|
+
moduleImports.push("ModuleHooks");
|
|
74
|
+
schemaShims.push(" interface NuxtHooks extends ModuleHooks {}");
|
|
60
75
|
}
|
|
61
76
|
const dtsContents = `
|
|
62
|
-
import
|
|
77
|
+
import { ${moduleImports.join(", ")} } from './module'
|
|
63
78
|
|
|
64
79
|
${schemaShims.length ? `declare module '@nuxt/schema' {
|
|
65
80
|
${schemaShims.join("\n")}
|
|
66
81
|
}
|
|
67
82
|
` : ""}
|
|
83
|
+
|
|
68
84
|
export * from './module'
|
|
69
85
|
`;
|
|
70
86
|
await promises.writeFile(dtsFile, dtsContents, "utf8");
|
package/dist/cli.mjs
CHANGED
|
@@ -5,11 +5,15 @@ import { b as buildModule } from './chunks/build.mjs';
|
|
|
5
5
|
import 'fs';
|
|
6
6
|
import 'url';
|
|
7
7
|
import 'consola';
|
|
8
|
+
import 'mlly';
|
|
8
9
|
|
|
9
10
|
async function main() {
|
|
10
11
|
const args = mri(process.argv.slice(2));
|
|
11
12
|
const rootDir = resolve(args._[0] || ".");
|
|
12
|
-
await buildModule(
|
|
13
|
+
await buildModule({
|
|
14
|
+
rootDir,
|
|
15
|
+
stub: args.stub
|
|
16
|
+
});
|
|
13
17
|
}
|
|
14
18
|
main().catch((err) => {
|
|
15
19
|
console.error(err);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
interface BuildModuleOptions {
|
|
2
|
+
rootDir: string;
|
|
3
|
+
stub?: boolean;
|
|
4
|
+
}
|
|
5
|
+
declare function buildModule(opts: BuildModuleOptions): Promise<void>;
|
|
2
6
|
|
|
3
|
-
export { buildModule };
|
|
7
|
+
export { BuildModuleOptions, buildModule };
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/module-builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Complete solution to build Nuxt Modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"consola": "^2.15.3",
|
|
31
|
+
"mlly": "^0.3.19",
|
|
31
32
|
"mri": "^1.2.0",
|
|
32
33
|
"pathe": "^0.2.0",
|
|
33
34
|
"unbuild": "^0.6.7"
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"@nuxtjs/eslint-config-typescript": "latest",
|
|
39
40
|
"@types/mri": "latest",
|
|
40
41
|
"eslint": "latest",
|
|
41
|
-
"jiti": "
|
|
42
|
+
"jiti": "^1.12.9",
|
|
42
43
|
"standard-version": "latest"
|
|
43
44
|
}
|
|
44
45
|
}
|