@nuxt/module-builder 0.4.0 → 0.5.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/dist/cli.d.mts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { }
package/dist/cli.mjs CHANGED
@@ -1,36 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import mri from 'mri';
3
3
  import { resolve } from 'pathe';
4
- import { buildModule } from './index.mjs';
4
+ import { prepareModule, buildModule } from './index.mjs';
5
5
  import 'fs';
6
6
  import 'url';
7
7
  import 'consola';
8
8
  import 'mlly';
9
9
 
10
- async function prepareModule(options) {
11
- const { runCommand } = await import('nuxi');
12
- return runCommand("prepare", [options.rootDir], {
13
- overrides: {
14
- typescript: {
15
- builder: "shared"
16
- },
17
- imports: {
18
- autoImport: false
19
- },
20
- modules: [
21
- resolve(options.rootDir, "./src/module"),
22
- function(_options, nuxt) {
23
- nuxt.hooks.hook("app:templates", (app) => {
24
- for (const template of app.templates) {
25
- template.write = true;
26
- }
27
- });
28
- }
29
- ]
30
- }
31
- });
32
- }
33
-
34
10
  function main() {
35
11
  const args = mri(process.argv.slice(2));
36
12
  if (args._[0] === "prepare") {
@@ -41,6 +17,7 @@ function main() {
41
17
  return buildModule({
42
18
  rootDir: resolve(args._[0] || "."),
43
19
  outDir: args.outDir,
20
+ sourcemap: args.sourcemap,
44
21
  stub: args.stub
45
22
  });
46
23
  }
@@ -0,0 +1,14 @@
1
+ interface BuildModuleOptions {
2
+ rootDir: string;
3
+ sourcemap?: boolean;
4
+ stub?: boolean;
5
+ outDir?: string;
6
+ }
7
+ declare function buildModule(opts: BuildModuleOptions): Promise<void>;
8
+
9
+ interface PrepareModuleOptions {
10
+ rootDir: string;
11
+ }
12
+ declare function prepareModule(options: PrepareModuleOptions): Promise<void>;
13
+
14
+ export { type BuildModuleOptions, type PrepareModuleOptions, buildModule, prepareModule };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  interface BuildModuleOptions {
2
2
  rootDir: string;
3
+ sourcemap?: boolean;
3
4
  stub?: boolean;
4
5
  outDir?: string;
5
6
  }
6
7
  declare function buildModule(opts: BuildModuleOptions): Promise<void>;
7
8
 
8
- export { BuildModuleOptions, buildModule };
9
+ interface PrepareModuleOptions {
10
+ rootDir: string;
11
+ }
12
+ declare function prepareModule(options: PrepareModuleOptions): Promise<void>;
13
+
14
+ export { type BuildModuleOptions, type PrepareModuleOptions, buildModule, prepareModule };
package/dist/index.mjs CHANGED
@@ -9,6 +9,7 @@ async function buildModule(opts) {
9
9
  const outDir = opts.outDir || "dist";
10
10
  await build(opts.rootDir, false, {
11
11
  declaration: true,
12
+ sourcemap: opts.sourcemap,
12
13
  stub: opts.stub,
13
14
  outDir,
14
15
  entries: [
@@ -60,12 +61,19 @@ async function buildModule(opts) {
60
61
  }
61
62
  async function writeTypes(distDir, meta) {
62
63
  const dtsFile = resolve(distDir, "types.d.ts");
64
+ const dtsFileMts = resolve(distDir, "types.d.mts");
63
65
  if (existsSync(dtsFile)) {
64
66
  return;
65
67
  }
66
68
  const moduleTypesFile = resolve(distDir, "module.d.ts");
67
69
  const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
68
- const typeExports = findExports(moduleTypes);
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
+ );
69
77
  const isStub = moduleTypes.includes("export *");
70
78
  const schemaShims = [];
71
79
  const moduleImports = [];
@@ -102,6 +110,9 @@ ${schemaShims.join("\n")}
102
110
  export { ${typeExports[0].names.join(", ")} } from './module'
103
111
  `;
104
112
  await promises.writeFile(dtsFile, dtsContents, "utf8");
113
+ if (!existsSync(dtsFileMts)) {
114
+ await promises.writeFile(dtsFileMts, dtsContents, "utf8");
115
+ }
105
116
  }
106
117
  async function writeCJSStub(distDir) {
107
118
  const cjsStubFile = resolve(distDir, "module.cjs");
@@ -117,4 +128,28 @@ module.exports.getMeta = () => Promise.resolve(_meta)
117
128
  await promises.writeFile(cjsStubFile, cjsStub, "utf8");
118
129
  }
119
130
 
120
- export { buildModule };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/module-builder",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "repository": "nuxt/module-builder",
5
5
  "description": "Complete solution to build Nuxt Modules",
6
6
  "license": "MIT",
@@ -19,39 +19,38 @@
19
19
  "files": [
20
20
  "dist"
21
21
  ],
22
- "scripts": {
23
- "build": "unbuild",
24
- "example:build": "pnpm nuxt-module-build ./example",
25
- "lint": "eslint --ext .ts,.js,.mjs .",
26
- "nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
27
- "prepack": "pnpm build",
28
- "release": "pnpm test && standard-version && git push --follow-tags && npm publish",
29
- "test": "pnpm vitest"
30
- },
31
- "packageManager": "pnpm@8.5.1",
22
+ "packageManager": "pnpm@8.7.0",
32
23
  "dependencies": {
33
- "consola": "^3.1.0",
34
- "mlly": "^1.3.0",
24
+ "consola": "^3.2.3",
25
+ "mlly": "^1.4.1",
35
26
  "mri": "^1.2.0",
36
- "pathe": "^1.1.0",
37
- "unbuild": "^1.2.1"
27
+ "pathe": "^1.1.1",
28
+ "unbuild": "^2.0.0"
38
29
  },
39
30
  "peerDependencies": {
40
- "@nuxt/kit": "^3.5.0",
41
- "nuxi": "^3.5.0"
31
+ "@nuxt/kit": "^3.7.0",
32
+ "nuxi": "^3.7.3"
42
33
  },
43
34
  "devDependencies": {
44
- "@nuxt/kit": "^3.5.1",
45
- "@nuxt/schema": "^3.5.1",
46
- "@nuxtjs/eslint-config-typescript": "^12.0.0",
35
+ "@nuxt/kit": "^3.7.0",
36
+ "@nuxt/schema": "^3.7.0",
37
+ "@nuxtjs/eslint-config-typescript": "^12.1.0",
47
38
  "@types/mri": "^1.1.1",
48
- "@types/node": "^20.1.3",
49
- "@vitest/coverage-c8": "^0.31.1",
50
- "eslint": "^8.41.0",
51
- "jiti": "^1.18.2",
52
- "nuxi": "^3.5.1",
53
- "nuxt": "^3.5.1",
54
- "standard-version": "^9.5.0",
55
- "vitest": "^0.31.1"
39
+ "@types/node": "^20.5.7",
40
+ "@vitest/coverage-v8": "^0.34.3",
41
+ "changelogen": "^0.5.5",
42
+ "eslint": "^8.48.0",
43
+ "jiti": "^1.19.3",
44
+ "nuxi": "^3.7.3",
45
+ "nuxt": "^3.7.0",
46
+ "vitest": "^0.34.3"
47
+ },
48
+ "scripts": {
49
+ "build": "unbuild",
50
+ "example:build": "pnpm nuxt-module-build ./example",
51
+ "lint": "eslint --ext .ts,.js,.mjs .",
52
+ "nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
53
+ "release": "pnpm vitest run && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
54
+ "test": "pnpm vitest"
56
55
  }
57
- }
56
+ }