@nuxt/module-builder 0.1.6 โ†’ 0.2.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
@@ -2,8 +2,6 @@
2
2
 
3
3
  > Complete solution to build Nuxt Modules.
4
4
 
5
- **๐Ÿงช This tool is still under heavy development for Nuxt3. Feedback is more than welcome!**
6
-
7
5
  ## Features
8
6
 
9
7
  - Unified build with [unjs/unbuild](https://github.com/unjs/unbuild)
@@ -14,12 +12,22 @@
14
12
  - Auto generated types and shims for `@nuxt/schema`
15
13
 
16
14
 
15
+ ## Learn More
16
+
17
+ Check the new [Guide for Nuxt Modules](https://v3.nuxtjs.org/docs/advanced/modules/) before starting with module-builder.
18
+
19
+ ### Requirements
20
+
21
+ For a user to use a module generated from module-builder, it's recommended they have:
22
+ - Node.js >= 14.x. _Latest Node LTS preferred_
23
+ - Nuxt 3 or Nuxt Bridge. _Nuxt 2 is functional but not advised_
24
+
17
25
  ## Quick start
18
26
 
19
- You can quickly get started with pre-configured [module starter](https://github.com/nuxt/starter/tree/module):
27
+ You can quickly get started with the pre-configured [module starter](https://github.com/nuxt/starter/tree/module):
20
28
 
21
29
  ```bash
22
- $ npx nuxi init -t "nuxt/starter#module" my-module
30
+ $ npx nuxi init -t module my-module
23
31
  ```
24
32
 
25
33
  ## Project structure
@@ -32,9 +40,9 @@ This is the entrypoint for module definition.
32
40
 
33
41
  A default export using `defineNuxtModule` and `ModuleOptions` type export is expected.
34
42
 
35
- You could also optionally export `ModuleHooks` to annotate any custom hooks module uses.
43
+ You could also optionally export `ModuleHooks` to annotate any custom hooks the module uses.
36
44
 
37
- ```js [src/module.ts]
45
+ ```ts [src/module.ts]
38
46
  import { defineNuxtModule } from '@nuxt/kit'
39
47
 
40
48
  export interface ModuleOptions {
@@ -45,6 +53,14 @@ export interface ModuleHooks {
45
53
  'my-module:init': any
46
54
  }
47
55
 
56
+ export interface ModulePublicRuntimeConfig {
57
+ NAME: string
58
+ }
59
+
60
+ export interface ModulePrivateRuntimeConfig {
61
+ PRIVATE_NAME: string
62
+ }
63
+
48
64
  export default defineNuxtModule<ModuleOptions>({
49
65
  meta: {
50
66
  name: 'my-module',
@@ -110,9 +126,7 @@ Module builder generates dist files in `dist/` directory:
110
126
  - `runtime/*`: Individually transformed files using [unjs/mkdist](https://github.com/unjs/mkdist)
111
127
  - Javascript and `.ts` files will be transformed to `.mjs` with extracted types on `.d.ts` file with same name
112
128
  - `.vue` files will be transformed with extracted `.d.ts` file
113
- - Other files will be copied as as
114
-
115
-
129
+ - Other files will be copied as is
116
130
 
117
131
  ## ๐Ÿ’ป Development
118
132
 
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import mri from 'mri';
3
3
  import { resolve } from 'pathe';
4
- import { b as buildModule } from './chunks/build.mjs';
4
+ import { b as buildModule } from './shared/module-builder.4bb3ed8c.mjs';
5
5
  import 'fs';
6
6
  import 'url';
7
7
  import 'consola';
@@ -12,6 +12,7 @@ async function main() {
12
12
  const rootDir = resolve(args._[0] || ".");
13
13
  await buildModule({
14
14
  rootDir,
15
+ outDir: args.outDir,
15
16
  stub: args.stub
16
17
  });
17
18
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  interface BuildModuleOptions {
2
2
  rootDir: string;
3
3
  stub?: boolean;
4
+ outDir?: string;
4
5
  }
5
6
  declare function buildModule(opts: BuildModuleOptions): Promise<void>;
6
7
 
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { b as buildModule } from './chunks/build.mjs';
1
+ export { b as buildModule } from './shared/module-builder.4bb3ed8c.mjs';
2
2
  import 'fs';
3
3
  import 'url';
4
4
  import 'pathe';
@@ -6,12 +6,14 @@ import { findExports } from 'mlly';
6
6
 
7
7
  async function buildModule(opts) {
8
8
  const { build } = await import('unbuild');
9
+ const outDir = opts.outDir || "dist";
9
10
  await build(opts.rootDir, false, {
10
11
  declaration: true,
11
12
  stub: opts.stub,
13
+ outDir,
12
14
  entries: [
13
15
  "src/module",
14
- { input: "src/runtime/", outDir: "dist/runtime", ext: "mjs" }
16
+ { input: "src/runtime/", outDir: `${outDir}/runtime`, ext: "mjs" }
15
17
  ],
16
18
  rollup: {
17
19
  emitCJS: false,
@@ -21,7 +23,12 @@ async function buildModule(opts) {
21
23
  "@nuxt/schema",
22
24
  "@nuxt/schema-edge",
23
25
  "@nuxt/kit",
24
- "@nuxt/kit-edge"
26
+ "@nuxt/kit-edge",
27
+ "nuxt",
28
+ "nuxt-edge",
29
+ "nuxt3",
30
+ "vue",
31
+ "vue-demi"
25
32
  ],
26
33
  hooks: {
27
34
  async "rollup:done"(ctx) {
@@ -60,19 +67,26 @@ async function writeTypes(distDir, meta) {
60
67
  const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
61
68
  const typeExports = findExports(moduleTypes);
62
69
  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"));
65
70
  const schemaShims = [];
66
71
  const moduleImports = [];
67
- if (meta.configKey && hasModuleOptions) {
72
+ const hasTypeExport = (name) => isStub || typeExports.find((exp) => exp.names.includes(name));
73
+ if (meta.configKey && hasTypeExport("ModuleOptions")) {
68
74
  moduleImports.push("ModuleOptions");
69
75
  schemaShims.push(` interface NuxtConfig { ['${meta.configKey}']?: Partial<ModuleOptions> }`);
70
76
  schemaShims.push(` interface NuxtOptions { ['${meta.configKey}']?: ModuleOptions }`);
71
77
  }
72
- if (hasModuleHooks) {
78
+ if (hasTypeExport("ModuleHooks")) {
73
79
  moduleImports.push("ModuleHooks");
74
80
  schemaShims.push(" interface NuxtHooks extends ModuleHooks {}");
75
81
  }
82
+ if (hasTypeExport("ModuleRuntimeConfig")) {
83
+ moduleImports.push("ModuleRuntimeConfig");
84
+ schemaShims.push(" interface RuntimeConfig extends ModuleRuntimeConfig {}");
85
+ }
86
+ if (hasTypeExport("ModulePublicRuntimeConfig")) {
87
+ moduleImports.push("ModulePublicRuntimeConfig");
88
+ schemaShims.push(" interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}");
89
+ }
76
90
  const dtsContents = `
77
91
  import { ${moduleImports.join(", ")} } from './module'
78
92
 
@@ -81,7 +95,7 @@ ${schemaShims.join("\n")}
81
95
  }
82
96
  ` : ""}
83
97
 
84
- export { default } from './module'
98
+ export { ${typeExports[0].names.join(", ")} } from './module'
85
99
  `;
86
100
  await promises.writeFile(dtsFile, dtsContents, "utf8");
87
101
  }
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@nuxt/module-builder",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "description": "Complete solution to build Nuxt Modules",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/index.mjs"
10
- }
10
+ },
11
+ "./package.json": "./package.json"
11
12
  },
12
13
  "types": "./dist/index.d.ts",
13
14
  "bin": {
@@ -28,18 +29,19 @@
28
29
  },
29
30
  "dependencies": {
30
31
  "consola": "^2.15.3",
31
- "mlly": "^0.3.19",
32
+ "mlly": "^0.5.16",
32
33
  "mri": "^1.2.0",
33
- "pathe": "^0.2.0",
34
- "unbuild": "^0.6.7"
34
+ "pathe": "^0.3.9",
35
+ "unbuild": "^0.9.4"
35
36
  },
36
37
  "devDependencies": {
37
- "@nuxt/kit": "npm:@nuxt/kit-edge@latest",
38
- "@nuxt/schema": "npm:@nuxt/schema-edge@latest",
39
- "@nuxtjs/eslint-config-typescript": "latest",
40
- "@types/mri": "latest",
41
- "eslint": "latest",
42
- "jiti": "^1.12.9",
43
- "standard-version": "latest"
38
+ "@nuxt/kit": "^3.0.0-rc.11",
39
+ "@nuxt/schema": "^3.0.0-rc.11",
40
+ "@nuxtjs/eslint-config-typescript": "^11.0.0",
41
+ "@types/mri": "^1.1.1",
42
+ "@types/node": "^18.11.0",
43
+ "eslint": "^8.25.0",
44
+ "jiti": "^1.16.0",
45
+ "standard-version": "^9.5.0"
44
46
  }
45
47
  }