wexts 4.1.5 → 4.1.6

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.
Files changed (185) hide show
  1. package/README.md +49 -49
  2. package/bin/wexts.cjs +2 -2
  3. package/dist/chunk-27NEYQD2.mjs +222 -0
  4. package/dist/chunk-27NEYQD2.mjs.map +1 -0
  5. package/dist/chunk-2LJVUMXW.js +228 -0
  6. package/dist/chunk-2LJVUMXW.js.map +1 -0
  7. package/dist/chunk-5DBFN65W.mjs +183 -0
  8. package/dist/chunk-5DBFN65W.mjs.map +1 -0
  9. package/dist/chunk-75HBI2XG.js +504 -0
  10. package/dist/chunk-75HBI2XG.js.map +1 -0
  11. package/dist/chunk-AVMQJWYD.js +95 -0
  12. package/dist/chunk-AVMQJWYD.js.map +1 -0
  13. package/dist/chunk-C2AG7Q3C.mjs +65 -0
  14. package/dist/chunk-C2AG7Q3C.mjs.map +1 -0
  15. package/dist/chunk-DS5KVVWJ.mjs +95 -0
  16. package/dist/chunk-DS5KVVWJ.mjs.map +1 -0
  17. package/dist/chunk-FUPLZMSR.mjs +228 -0
  18. package/dist/chunk-FUPLZMSR.mjs.map +1 -0
  19. package/dist/chunk-HLT3IHJY.js +183 -0
  20. package/dist/chunk-HLT3IHJY.js.map +1 -0
  21. package/dist/chunk-L77ANWWT.mjs +22 -0
  22. package/dist/chunk-L77ANWWT.mjs.map +1 -0
  23. package/dist/chunk-P3Q4I5FD.js +222 -0
  24. package/dist/chunk-P3Q4I5FD.js.map +1 -0
  25. package/dist/chunk-VBIQGUDI.mjs +504 -0
  26. package/dist/chunk-VBIQGUDI.mjs.map +1 -0
  27. package/dist/chunk-WCKSKU3C.js +65 -0
  28. package/dist/chunk-WCKSKU3C.js.map +1 -0
  29. package/dist/chunk-XE4OXN2W.js +12 -0
  30. package/dist/chunk-XE4OXN2W.js.map +1 -0
  31. package/dist/cli/index.d.mts +23 -0
  32. package/dist/cli/index.d.ts +23 -0
  33. package/dist/cli/index.js +745 -0
  34. package/dist/cli/index.js.map +1 -0
  35. package/dist/cli/index.mjs +747 -0
  36. package/dist/cli/index.mjs.map +1 -0
  37. package/dist/client/index.d.mts +43 -0
  38. package/dist/client/index.d.ts +43 -0
  39. package/dist/client/index.js +187 -0
  40. package/dist/client/index.js.map +1 -0
  41. package/dist/client/index.mjs +166 -0
  42. package/dist/client/index.mjs.map +1 -0
  43. package/dist/codegen/index.d.mts +2 -0
  44. package/dist/codegen/index.d.ts +2 -0
  45. package/dist/codegen/index.js +16 -0
  46. package/dist/codegen/index.js.map +1 -0
  47. package/dist/codegen/index.mjs +16 -0
  48. package/dist/codegen/index.mjs.map +1 -0
  49. package/dist/decorators-BiQtOHuF.d.ts +60 -0
  50. package/dist/decorators-vBopODtr.d.mts +60 -0
  51. package/dist/dev-server/index.d.mts +1 -0
  52. package/dist/dev-server/index.d.ts +1 -0
  53. package/dist/dev-server/index.js +13 -0
  54. package/dist/dev-server/index.js.map +1 -0
  55. package/dist/dev-server/index.mjs +13 -0
  56. package/dist/dev-server/index.mjs.map +1 -0
  57. package/dist/errors-D545UvXf.d.mts +37 -0
  58. package/dist/errors-D545UvXf.d.ts +37 -0
  59. package/dist/index-7RvU-jGE.d.mts +66 -0
  60. package/dist/index-7RvU-jGE.d.ts +66 -0
  61. package/dist/index-CJKs4wtN.d.ts +92 -0
  62. package/dist/index-CUR6CnLk.d.ts +27 -0
  63. package/dist/index-h66Vq9dK.d.mts +92 -0
  64. package/dist/index-tqmYsTUn.d.mts +27 -0
  65. package/dist/index.d.mts +289 -0
  66. package/dist/index.d.ts +289 -0
  67. package/dist/index.js +544 -0
  68. package/dist/index.js.map +1 -0
  69. package/dist/index.mjs +544 -0
  70. package/dist/index.mjs.map +1 -0
  71. package/dist/nest/index.d.mts +2 -0
  72. package/dist/nest/index.d.ts +2 -0
  73. package/dist/nest/index.js +36 -0
  74. package/dist/nest/index.js.map +1 -0
  75. package/dist/nest/index.mjs +36 -0
  76. package/dist/nest/index.mjs.map +1 -0
  77. package/dist/next/index.d.mts +66 -0
  78. package/dist/next/index.d.ts +66 -0
  79. package/dist/next/index.js +282 -0
  80. package/dist/next/index.js.map +1 -0
  81. package/dist/next/index.mjs +251 -0
  82. package/dist/next/index.mjs.map +1 -0
  83. package/dist/rpc/index.d.mts +32 -0
  84. package/dist/rpc/index.d.ts +32 -0
  85. package/dist/rpc/index.js +19 -0
  86. package/dist/rpc/index.js.map +1 -0
  87. package/dist/rpc/index.mjs +1 -0
  88. package/dist/rpc/index.mjs.map +1 -0
  89. package/dist/runtime/index.d.mts +55 -0
  90. package/dist/runtime/index.d.ts +55 -0
  91. package/dist/runtime/index.js +15 -0
  92. package/dist/runtime/index.js.map +1 -0
  93. package/dist/runtime/index.mjs +15 -0
  94. package/dist/runtime/index.mjs.map +1 -0
  95. package/dist/server/index.d.mts +7 -0
  96. package/dist/server/index.d.ts +7 -0
  97. package/dist/server/index.js +58 -0
  98. package/dist/server/index.js.map +1 -0
  99. package/dist/server/index.mjs +58 -0
  100. package/dist/server/index.mjs.map +1 -0
  101. package/dist/types/index.d.mts +12 -0
  102. package/dist/types/index.d.ts +12 -0
  103. package/dist/types/index.js +19 -0
  104. package/dist/types/index.js.map +1 -0
  105. package/dist/types/index.mjs +1 -0
  106. package/dist/types/index.mjs.map +1 -0
  107. package/dist/types-CQ_aexOX.d.mts +32 -0
  108. package/dist/types-CQ_aexOX.d.ts +32 -0
  109. package/dist/vercel-builder/index.d.mts +58 -0
  110. package/dist/vercel-builder/index.d.ts +58 -0
  111. package/dist/vercel-builder/index.js +330 -0
  112. package/dist/vercel-builder/index.js.map +1 -0
  113. package/dist/vercel-builder/index.mjs +330 -0
  114. package/dist/vercel-builder/index.mjs.map +1 -0
  115. package/package.json +153 -153
  116. package/templates/.dockerignore +43 -43
  117. package/templates/.env.example +17 -17
  118. package/templates/Dockerfile +60 -60
  119. package/templates/Procfile +1 -1
  120. package/templates/README.md +67 -67
  121. package/templates/api-sdk.ts +115 -115
  122. package/templates/docker-compose.yml +34 -34
  123. package/templates/nestjs-api/.env.example +3 -3
  124. package/templates/nestjs-api/README.md +87 -87
  125. package/templates/nestjs-api/nest-cli.json +6 -6
  126. package/templates/nestjs-api/package.json +40 -40
  127. package/templates/nestjs-api/prisma/migrations/20251123205437_init/migration.sql +24 -24
  128. package/templates/nestjs-api/prisma/migrations/migration_lock.toml +3 -3
  129. package/templates/nestjs-api/prisma/schema.prisma +29 -29
  130. package/templates/nestjs-api/src/app.module.ts +17 -17
  131. package/templates/nestjs-api/src/auth/auth.controller.ts +27 -27
  132. package/templates/nestjs-api/src/auth/auth.module.ts +37 -37
  133. package/templates/nestjs-api/src/auth/auth.service.ts +86 -86
  134. package/templates/nestjs-api/src/auth/dto/auth.dto.ts +22 -22
  135. package/templates/nestjs-api/src/auth/guards/jwt-auth.guard.ts +5 -5
  136. package/templates/nestjs-api/src/auth/strategies/jwt.strategy.ts +27 -27
  137. package/templates/nestjs-api/src/main.ts +32 -32
  138. package/templates/nestjs-api/src/prisma/prisma.module.ts +9 -9
  139. package/templates/nestjs-api/src/prisma/prisma.service.ts +14 -14
  140. package/templates/nestjs-api/src/todos/dto/todo.dto.ts +24 -24
  141. package/templates/nestjs-api/src/todos/todos.controller.ts +39 -39
  142. package/templates/nestjs-api/src/todos/todos.module.ts +11 -11
  143. package/templates/nestjs-api/src/todos/todos.service.ts +53 -53
  144. package/templates/nestjs-api/src/users/users.controller.ts +14 -14
  145. package/templates/nestjs-api/src/users/users.module.ts +12 -12
  146. package/templates/nestjs-api/src/users/users.service.ts +19 -19
  147. package/templates/nestjs-api/tsconfig.json +39 -39
  148. package/templates/nextjs-web/README.md +76 -76
  149. package/templates/nextjs-web/app/actions/auth.ts +108 -108
  150. package/templates/nextjs-web/app/dashboard/error.tsx +39 -39
  151. package/templates/nextjs-web/app/dashboard/loading.tsx +14 -14
  152. package/templates/nextjs-web/app/dashboard/page.tsx +5 -5
  153. package/templates/nextjs-web/app/globals.css +93 -93
  154. package/templates/nextjs-web/app/layout.tsx +29 -29
  155. package/templates/nextjs-web/app/login/page.tsx +5 -5
  156. package/templates/nextjs-web/app/page.tsx +28 -28
  157. package/templates/nextjs-web/app/register/page.tsx +5 -5
  158. package/templates/nextjs-web/components/ui/button.tsx +56 -56
  159. package/templates/nextjs-web/components/ui/card.tsx +79 -79
  160. package/templates/nextjs-web/components/ui/input.tsx +25 -25
  161. package/templates/nextjs-web/components/ui/label.tsx +24 -24
  162. package/templates/nextjs-web/features/auth/LoginForm.tsx +140 -140
  163. package/templates/nextjs-web/features/auth/RegisterForm.tsx +159 -159
  164. package/templates/nextjs-web/features/auth/api.ts +35 -35
  165. package/templates/nextjs-web/features/auth/index.ts +3 -3
  166. package/templates/nextjs-web/features/dashboard/DashboardView.tsx +204 -204
  167. package/templates/nextjs-web/features/dashboard/api.ts +9 -9
  168. package/templates/nextjs-web/features/dashboard/components.tsx +74 -74
  169. package/templates/nextjs-web/features/dashboard/index.ts +3 -3
  170. package/templates/nextjs-web/hooks/index.ts +4 -4
  171. package/templates/nextjs-web/lib/api-client.ts +89 -89
  172. package/templates/nextjs-web/lib/api.ts +115 -115
  173. package/templates/nextjs-web/lib/axios-global-config.ts +17 -17
  174. package/templates/nextjs-web/lib/utils.ts +6 -6
  175. package/templates/nextjs-web/lib/wexts-client.ts +4 -4
  176. package/templates/nextjs-web/next-env.d.ts +6 -6
  177. package/templates/nextjs-web/next.config.ts +20 -20
  178. package/templates/nextjs-web/package.json +37 -37
  179. package/templates/nextjs-web/postcss.config.js +6 -6
  180. package/templates/nextjs-web/tailwind.config.ts +69 -69
  181. package/templates/nextjs-web/tsconfig.json +41 -41
  182. package/templates/nixpacks.toml +11 -11
  183. package/templates/root-package.json +31 -31
  184. package/templates/server.ts +66 -66
  185. package/templates/tsconfig.json +30 -30
@@ -0,0 +1,747 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ WextsError,
4
+ formatWextsError
5
+ } from "../chunk-DS5KVVWJ.mjs";
6
+ import {
7
+ logger
8
+ } from "../chunk-C2AG7Q3C.mjs";
9
+ import {
10
+ __dirname,
11
+ __filename,
12
+ __name
13
+ } from "../chunk-L77ANWWT.mjs";
14
+
15
+ // src/cli/index.ts
16
+ import { Command } from "commander";
17
+ import * as fs from "fs";
18
+ import * as path from "path";
19
+ import { spawnSync } from "child_process";
20
+ import { createRequire } from "module";
21
+ function createCliProgram() {
22
+ const program = new Command();
23
+ program.name("wexts").description("Wexts - production-focused single-runtime Next.js + NestJS toolkit").version(readPackageVersion());
24
+ program.command("create <project-name>").description("Create a verified Wexts starter").option("-t, --template <template>", "Template to use (starter|legacy)", "starter").option("--skip-install", "Skip dependency installation", false).action(async (projectName, options) => {
25
+ await createProject(projectName, options.template, {
26
+ skipInstall: options.skipInstall
27
+ });
28
+ });
29
+ program.command("dev").description("Start local development processes").option("-a, --api <path>", "Path to API project", "./apps/api").option("-w, --web <path>", "Path to Web project", "./apps/web").option("-p, --port <port>", "Port for web server", "3000").option("--api-port <port>", "Port for API server", "5050").option("--proxy", "Enable development proxy on a separate proxy port", false).action(async (options) => {
30
+ const { FusionDevServer } = await import("../dev-server/index.mjs");
31
+ const server = new FusionDevServer();
32
+ await server.start({
33
+ apiPath: options.api,
34
+ webPath: options.web,
35
+ webPort: Number(options.port),
36
+ apiPort: Number(options.apiPort),
37
+ useProxy: options.proxy
38
+ });
39
+ });
40
+ program.command("generate [type] [name]").alias("g").description("Generate RPC manifest/client, or scaffold a minimal RPC service").option("-p, --project <path>", "Path to NestJS project", "./apps/api").option("-o, --output <path>", "Output directory for generated RPC client", "./apps/web/lib/wexts").option("--force", "Overwrite generated files if they already exist", false).action(async (type, name, options) => {
41
+ if (!type || type === "rpc" && !name) {
42
+ const { generateRpcClient } = await import("../codegen/index.mjs");
43
+ const manifest = await generateRpcClient({
44
+ projectPath: path.resolve(options.project),
45
+ outputPath: path.resolve(options.output)
46
+ });
47
+ logger.success(`Generated Wexts RPC client for ${manifest.services.length} service(s).`);
48
+ return;
49
+ }
50
+ if (isScaffoldGenerator(type)) {
51
+ const targetRoot = type === "config" ? process.cwd() : path.resolve(options.project);
52
+ const changedFiles = await scaffoldGenerator({
53
+ type,
54
+ name,
55
+ targetRoot,
56
+ force: options.force
57
+ });
58
+ for (const file of changedFiles) logger.info(`created ${path.relative(process.cwd(), file)}`);
59
+ logger.success(`Generated ${type}${name ? ` ${name}` : ""}.`);
60
+ return;
61
+ }
62
+ throw new Error(`Unknown generator "${type}". Supported generators: rpc, service, module, entity, guard, config.`);
63
+ });
64
+ program.command("codegen").description("Alias for wexts generate rpc").option("-p, --project <path>", "Path to NestJS project", "./apps/api").option("-o, --output <path>", "Output directory for generated RPC client", "./apps/web/lib/wexts").action(async (options) => {
65
+ const { generateRpcClient } = await import("../codegen/index.mjs");
66
+ const manifest = await generateRpcClient({
67
+ projectPath: path.resolve(options.project),
68
+ outputPath: path.resolve(options.output)
69
+ });
70
+ logger.success(`Generated Wexts RPC client for ${manifest.services.length} service(s).`);
71
+ });
72
+ program.command("build").description("Build a Wexts project for production").option("--skip-generate", "Skip RPC generation before build", false).option("-p, --project <path>", "Path to NestJS project", "./apps/api").option("-o, --output <path>", "Output directory for generated RPC client", "./apps/web/lib/wexts").action(async (options) => {
73
+ if (!options.skipGenerate && fs.existsSync(options.project)) {
74
+ const { generateRpcClient } = await import("../codegen/index.mjs");
75
+ await generateRpcClient({
76
+ projectPath: path.resolve(options.project),
77
+ outputPath: path.resolve(options.output)
78
+ });
79
+ }
80
+ runScript("build", {
81
+ cwd: process.cwd()
82
+ });
83
+ });
84
+ program.command("start").description("Start the production Wexts runtime").option("-c, --config <path>", "Runtime config module path", "./wexts.runtime.js").option("-p, --port <port>", "Port to listen on", process.env.PORT ?? "3000").action(async (options) => {
85
+ const { startWextsRuntime } = await import("../runtime/index.mjs");
86
+ const configPath = path.resolve(options.config);
87
+ const runtimeConfig = fs.existsSync(configPath) ? await loadRuntimeConfig(configPath) : {};
88
+ await startWextsRuntime({
89
+ ...runtimeConfig,
90
+ port: Number(options.port),
91
+ dev: false
92
+ });
93
+ });
94
+ program.command("vercel-build").description("Build for Vercel using Build Output API v3").option("-p, --project <path>", "Path to NestJS project", "./apps/api").option("-o, --output <path>", "Output dir for RPC client", "./apps/web/lib/wexts").option("-c, --config <path>", "Runtime config module path", "./wexts.runtime.js").option("--skip-codegen", "Skip RPC generation", false).option("--skip-build", "Skip project build step", false).option("--node-version <version>", "Node.js version for Vercel function", "20").option("--max-duration <seconds>", "Max duration for serverless function", "30").action(async (options) => {
95
+ const { buildVercelOutput } = await import("../vercel-builder/index.mjs");
96
+ const result = await buildVercelOutput({
97
+ rootDir: process.cwd(),
98
+ apiProjectPath: options.project,
99
+ rpcOutputPath: options.output,
100
+ runtimeConfigPath: options.config,
101
+ skipCodegen: options.skipCodegen,
102
+ skipBuild: options.skipBuild,
103
+ nodeVersion: options.nodeVersion,
104
+ maxDuration: Number(options.maxDuration)
105
+ });
106
+ if (result.warnings.length > 0) {
107
+ for (const warning of result.warnings) logger.warn(warning);
108
+ }
109
+ if (result.errors.length > 0) {
110
+ for (const error of result.errors) logger.error(error);
111
+ process.exit(1);
112
+ }
113
+ logger.success("Vercel build output ready at .vercel/output");
114
+ });
115
+ program.command("doctor").description("Validate Wexts project configuration").option("--security", "Run security-specific checks", false).action(async (options) => {
116
+ const result = runDoctor(process.cwd(), options.security);
117
+ for (const warning of result.warnings) logger.warn(warning);
118
+ for (const error of result.errors) logger.error(error);
119
+ if (result.errors.length > 0) process.exit(1);
120
+ logger.success(options.security ? "Security doctor passed." : "Doctor passed.");
121
+ });
122
+ return program;
123
+ }
124
+ __name(createCliProgram, "createCliProgram");
125
+ function runDoctor(cwd, security = false) {
126
+ const result = {
127
+ errors: [],
128
+ warnings: []
129
+ };
130
+ const pkgPath = path.join(cwd, "package.json");
131
+ if (!fs.existsSync(pkgPath)) {
132
+ result.errors.push("package.json not found.");
133
+ return result;
134
+ }
135
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
136
+ if (!pkg.packageManager?.startsWith("pnpm@")) {
137
+ result.warnings.push("packageManager should pin pnpm.");
138
+ }
139
+ for (const dir of [
140
+ "apps/api",
141
+ "apps/web"
142
+ ]) {
143
+ if (!fs.existsSync(path.join(cwd, dir))) {
144
+ result.warnings.push(`${dir} not found; some Wexts commands may need explicit paths.`);
145
+ }
146
+ }
147
+ if (fs.existsSync(path.join(cwd, "apps/api")) && fs.existsSync(path.join(cwd, "apps/web"))) {
148
+ result.warnings.push("Development mode starts separate web/API processes. Single-port serving is the production `wexts start` runtime path.");
149
+ }
150
+ if (security) {
151
+ const source = readAllText(cwd, [
152
+ "apps/api/src",
153
+ "packages/templates/nestjs-api/src"
154
+ ]);
155
+ if (source.includes("default-secret")) {
156
+ result.errors.push('JWT fallback "default-secret" found. Production apps must fail without a strong JWT_SECRET.');
157
+ }
158
+ if (/origin:\s*['"]\*['"]/.test(source)) {
159
+ result.errors.push("Wildcard CORS origin found. Use an explicit origin allowlist.");
160
+ }
161
+ }
162
+ return result;
163
+ }
164
+ __name(runDoctor, "runDoctor");
165
+ async function createProject(projectName, template, options) {
166
+ const projectPath = path.join(process.cwd(), projectName);
167
+ if (fs.existsSync(projectPath)) {
168
+ throw new Error(`Directory already exists: ${projectName}`);
169
+ }
170
+ fs.mkdirSync(projectPath, {
171
+ recursive: true
172
+ });
173
+ if (template === "starter") {
174
+ await createVerifiedStarter(projectPath, projectName, options.wextsDependency ?? resolveCreateWextsDependency(projectPath));
175
+ } else if (template === "legacy") {
176
+ createLegacyProject(projectPath, projectName);
177
+ } else {
178
+ throw new Error(`Unknown template "${template}". Supported templates: starter, legacy.`);
179
+ }
180
+ if (!options.skipInstall) {
181
+ runCommand(detectPackageManager(projectPath), [
182
+ "install"
183
+ ], projectPath);
184
+ }
185
+ }
186
+ __name(createProject, "createProject");
187
+ async function createVerifiedStarter(projectPath, projectName, wextsDependency) {
188
+ const files = {
189
+ "pnpm-workspace.yaml": "packages:\n - 'apps/*'\n",
190
+ "package.json": JSON.stringify({
191
+ name: projectName,
192
+ version: "0.1.0",
193
+ private: true,
194
+ packageManager: "pnpm@10.22.0",
195
+ scripts: {
196
+ dev: "wexts dev",
197
+ generate: "wexts generate -p apps/api -o apps/web/lib/wexts",
198
+ build: "pnpm run generate && tsc -p apps/api/tsconfig.json && next build apps/web",
199
+ start: "wexts start -c ./wexts.runtime.js",
200
+ "vercel-build": "wexts vercel-build -p apps/api -o apps/web/lib/wexts -c ./wexts.runtime.js",
201
+ doctor: "wexts doctor",
202
+ "doctor:security": "wexts doctor --security"
203
+ },
204
+ dependencies: {
205
+ "@nestjs/common": "^11.1.19",
206
+ "@nestjs/core": "^11.1.19",
207
+ "@nestjs/platform-fastify": "^11.1.19",
208
+ next: "16.2.4",
209
+ react: "^19.2.5",
210
+ "react-dom": "^19.2.5",
211
+ "reflect-metadata": "^0.2.2",
212
+ rxjs: "^7.8.1",
213
+ wexts: wextsDependency
214
+ },
215
+ devDependencies: {
216
+ "@types/node": "^22.19.1",
217
+ "@types/react": "^19.2.14",
218
+ "@types/react-dom": "^19.2.3",
219
+ typescript: "^5.9.3"
220
+ }
221
+ }, null, 2),
222
+ "apps/api/package.json": JSON.stringify({
223
+ name: `${projectName}-api`,
224
+ private: true,
225
+ scripts: {
226
+ "start:dev": "tsc -w -p tsconfig.json"
227
+ }
228
+ }, null, 2),
229
+ "apps/api/tsconfig.json": JSON.stringify({
230
+ compilerOptions: {
231
+ target: "ES2023",
232
+ module: "NodeNext",
233
+ moduleResolution: "NodeNext",
234
+ experimentalDecorators: true,
235
+ emitDecoratorMetadata: true,
236
+ strict: true,
237
+ esModuleInterop: true,
238
+ skipLibCheck: true,
239
+ outDir: "dist",
240
+ rootDir: "src"
241
+ },
242
+ include: [
243
+ "src/**/*.ts"
244
+ ]
245
+ }, null, 2),
246
+ "apps/api/src/hello.service.ts": `import { Injectable } from '@nestjs/common';
247
+ import { RpcMethod, RpcService } from 'wexts/nest';
248
+
249
+ @Injectable()
250
+ @RpcService({ name: 'hello', requireAuth: false })
251
+ export class HelloService {
252
+ @RpcMethod()
253
+ async sayHello(name: string): Promise<string> {
254
+ return \`Hello, \${name}!\`;
255
+ }
256
+ }
257
+ `,
258
+ "apps/web/package.json": JSON.stringify({
259
+ name: `${projectName}-web`,
260
+ private: true,
261
+ scripts: {
262
+ dev: "next dev -p 3000"
263
+ }
264
+ }, null, 2),
265
+ "apps/web/tsconfig.json": JSON.stringify({
266
+ compilerOptions: {
267
+ target: "ES2022",
268
+ lib: [
269
+ "dom",
270
+ "dom.iterable",
271
+ "es2022"
272
+ ],
273
+ allowJs: false,
274
+ skipLibCheck: true,
275
+ strict: true,
276
+ noEmit: true,
277
+ esModuleInterop: true,
278
+ module: "esnext",
279
+ moduleResolution: "bundler",
280
+ resolveJsonModule: true,
281
+ isolatedModules: true,
282
+ jsx: "react-jsx",
283
+ incremental: true,
284
+ plugins: [
285
+ {
286
+ name: "next"
287
+ }
288
+ ]
289
+ },
290
+ include: [
291
+ "next-env.d.ts",
292
+ "**/*.ts",
293
+ "**/*.tsx",
294
+ ".next/types/**/*.ts",
295
+ ".next/dev/types/**/*.ts"
296
+ ],
297
+ exclude: [
298
+ "node_modules"
299
+ ]
300
+ }, null, 2),
301
+ "apps/web/next-env.d.ts": `/// <reference types="next" />
302
+ /// <reference types="next/image-types/global" />
303
+
304
+ // This file is generated by Next.js. Do not edit.
305
+ `,
306
+ "apps/web/next.config.ts": `import type { NextConfig } from 'next';
307
+
308
+ const nextConfig: NextConfig = {
309
+ output: 'standalone',
310
+ };
311
+
312
+ export default nextConfig;
313
+ `,
314
+ "apps/web/app/layout.tsx": `import type { ReactNode } from 'react';
315
+ import { WextsProvider } from '../lib/wexts-provider';
316
+
317
+ export default function RootLayout({ children }: { children: ReactNode }) {
318
+ return (
319
+ <html lang="en">
320
+ <body>
321
+ <WextsProvider>{children}</WextsProvider>
322
+ </body>
323
+ </html>
324
+ );
325
+ }
326
+ `,
327
+ "apps/web/app/page.tsx": `'use client';
328
+
329
+ import { useState } from 'react';
330
+ import { useWexts } from '../lib/wexts-provider';
331
+
332
+ export default function Page() {
333
+ const wexts = useWexts();
334
+ const [message, setMessage] = useState('Not called yet');
335
+
336
+ return (
337
+ <main>
338
+ <h1>Wexts Hello RPC</h1>
339
+ <button
340
+ type="button"
341
+ onClick={async () => {
342
+ setMessage(await wexts.hello.sayHello('Bob'));
343
+ }}
344
+ >
345
+ Call RPC
346
+ </button>
347
+ <p>{message}</p>
348
+ </main>
349
+ );
350
+ }
351
+ `,
352
+ "apps/web/lib/wexts-provider.tsx": `'use client';
353
+
354
+ import { FusionProvider, useWexts as useGeneratedWexts } from 'wexts/next';
355
+ import { createWextsClient, type WextsClient } from './wexts/client';
356
+
357
+ export function WextsProvider({ children }: { children: React.ReactNode }) {
358
+ return (
359
+ <FusionProvider rpcClient={createWextsClient({ baseUrl: '/rpc' })}>
360
+ {children}
361
+ </FusionProvider>
362
+ );
363
+ }
364
+
365
+ export function useWexts(): WextsClient {
366
+ return useGeneratedWexts<WextsClient>();
367
+ }
368
+ `,
369
+ "wexts.runtime.js": `const { HelloService } = require('./apps/api/dist/hello.service.js');
370
+
371
+ module.exports = {
372
+ nextDir: './apps/web',
373
+ rpcManifestPath: './apps/web/lib/wexts/wexts.rpc.manifest.json',
374
+ rpcServices: {
375
+ hello: new HelloService(),
376
+ },
377
+ security: {
378
+ allowedOrigins: ['http://localhost:3000'],
379
+ },
380
+ };
381
+ `,
382
+ "README.md": `# ${projectName}
383
+
384
+ Verified Wexts starter with a generated Hello RPC client.
385
+
386
+ \`\`\`bash
387
+ pnpm install
388
+ pnpm run generate
389
+ pnpm run build
390
+ pnpm run doctor
391
+ pnpm run doctor:security
392
+ pnpm start
393
+ \`\`\`
394
+ `,
395
+ ".cursorrules": `# Wexts Project AI Rules
396
+
397
+ You are an expert full-stack developer working on a Wexts application.
398
+ Wexts is a unified single-runtime toolkit that combines Next.js (frontend) and NestJS (backend) using a highly typed RPC bridge.
399
+
400
+ ## Project Structure
401
+ - \`apps/api/\`: The NestJS backend. Contains business logic, database models, and RPC services.
402
+ - \`apps/web/\`: The Next.js frontend. Contains UI components, pages, and consumes the RPC client.
403
+ - \`apps/web/lib/wexts\`: The auto-generated typed RPC client (DO NOT EDIT MANUALLY).
404
+
405
+ ## Backend Guidelines (NestJS)
406
+ 1. **RPC Services**: To create an API endpoint, create a NestJS provider decorated with \`@RpcService({ name: 'serviceName' })\` and methods decorated with \`@RpcMethod()\`.
407
+ 2. **Imports**: Import \`@RpcService\` and \`@RpcMethod\` from \`wexts/nest\`.
408
+ 3. Do NOT manually create REST controllers unless explicitly needed for webhooks. Use the RPC bridge for all internal frontend-backend communication.
409
+ 4. **Auth**: If a service requires authentication, set \`@RpcService({ requireAuth: true })\`.
410
+
411
+ ## Frontend Guidelines (Next.js)
412
+ 1. **RPC Usage**: To call the backend, import the \`api\` client from \`@/lib/wexts\` or your designated Wexts client file (e.g., \`useWexts()\`).
413
+ 2. **Syntax**: \`const data = await api.serviceName.methodName(args);\`
414
+ 3. The \`api\` object is fully type-safe. Rely on TypeScript autocomplete rather than guessing endpoints.
415
+
416
+ ## Development Workflow
417
+ - When asked to add a new full-stack feature:
418
+ 1. Add the database model (Prisma).
419
+ 2. Create/update the NestJS RPC service in \`apps/api\`.
420
+ 3. Remind the user to run \`wexts generate\` (or \`pnpm generate\`) so the types sync.
421
+ 4. Build the UI in Next.js using the new \`api\` methods.
422
+ - **Never** hardcode \`fetch('http://localhost:3000/...')\`. ALWAYS use the generated \`api\` SDK.
423
+ `
424
+ };
425
+ for (const [relativePath, content] of Object.entries(files)) {
426
+ const absolutePath = path.join(projectPath, relativePath);
427
+ fs.mkdirSync(path.dirname(absolutePath), {
428
+ recursive: true
429
+ });
430
+ fs.writeFileSync(absolutePath, content);
431
+ }
432
+ const { generateRpcClient } = await import("../codegen/index.mjs");
433
+ await generateRpcClient({
434
+ projectPath: path.join(projectPath, "apps/api"),
435
+ outputPath: path.join(projectPath, "apps/web/lib/wexts")
436
+ });
437
+ }
438
+ __name(createVerifiedStarter, "createVerifiedStarter");
439
+ function createLegacyProject(projectPath, projectName) {
440
+ const templatePath = findTemplatePath();
441
+ if (!templatePath) {
442
+ throw new Error("Template directory not found in package.");
443
+ }
444
+ fs.mkdirSync(path.join(projectPath, "apps"), {
445
+ recursive: true
446
+ });
447
+ fs.cpSync(path.join(templatePath, "nestjs-api"), path.join(projectPath, "apps/api"), {
448
+ recursive: true
449
+ });
450
+ fs.cpSync(path.join(templatePath, "nextjs-web"), path.join(projectPath, "apps/web"), {
451
+ recursive: true
452
+ });
453
+ fs.rmSync(path.join(projectPath, "apps/web/package-lock.json"), {
454
+ force: true
455
+ });
456
+ fs.rmSync(path.join(projectPath, "apps/api/package-lock.json"), {
457
+ force: true
458
+ });
459
+ fs.writeFileSync(path.join(projectPath, "pnpm-workspace.yaml"), "packages:\n - 'apps/*'\n");
460
+ fs.writeFileSync(path.join(projectPath, "package.json"), JSON.stringify({
461
+ name: projectName,
462
+ private: true,
463
+ packageManager: "pnpm@10.22.0",
464
+ scripts: {
465
+ dev: "wexts dev",
466
+ generate: "wexts generate",
467
+ build: "wexts build",
468
+ start: "wexts start",
469
+ doctor: "wexts doctor"
470
+ },
471
+ devDependencies: {
472
+ wexts: `^${readPackageVersion()}`
473
+ }
474
+ }, null, 2));
475
+ }
476
+ __name(createLegacyProject, "createLegacyProject");
477
+ function resolveCreateWextsDependency(projectPath) {
478
+ const packageRoot = path.resolve(__dirname, "../..");
479
+ const cwdLocalPackage = path.join(process.cwd(), "node_modules/wexts");
480
+ try {
481
+ if (fs.existsSync(cwdLocalPackage) && fs.realpathSync(cwdLocalPackage) === fs.realpathSync(packageRoot)) {
482
+ return `file:${path.relative(projectPath, cwdLocalPackage)}`;
483
+ }
484
+ } catch {
485
+ }
486
+ return `^${readPackageVersion()}`;
487
+ }
488
+ __name(resolveCreateWextsDependency, "resolveCreateWextsDependency");
489
+ async function scaffoldGenerator(options) {
490
+ if (options.type !== "config" && !options.name) {
491
+ throw new WextsError({
492
+ code: "WEXTS_CLI_GENERATOR_NAME_REQUIRED",
493
+ message: `Generator "${options.type}" requires a name.`,
494
+ suggestedFix: `Run \`wexts generate ${options.type} hello\` or use \`wexts generate config\`.`,
495
+ docsSlug: "cli"
496
+ });
497
+ }
498
+ if (options.type === "config") {
499
+ return writeGeneratedFiles(options.targetRoot, [
500
+ {
501
+ relativePath: "wexts.runtime.js",
502
+ content: `/** @type {import('wexts/runtime').WextsRuntimeConfig} */
503
+ module.exports = {
504
+ rootDir: __dirname,
505
+ port: Number(process.env.PORT || 3000),
506
+ rpcManifestPath: 'apps/web/lib/wexts/wexts.rpc.manifest.json',
507
+ security: {
508
+ enabled: true,
509
+ production: process.env.NODE_ENV === 'production',
510
+ allowedOrigins: process.env.WEXTS_ALLOWED_ORIGINS?.split(',').filter(Boolean) || [],
511
+ },
512
+ };
513
+ `
514
+ }
515
+ ], Boolean(options.force));
516
+ }
517
+ const rawName = options.name;
518
+ const name = toKebabCase(rawName);
519
+ const classBase = toPascalCase(name);
520
+ const srcRoot = path.join(options.targetRoot, "src");
521
+ const filesByType = {
522
+ rpc: rpcServiceFiles(name, classBase),
523
+ service: [
524
+ {
525
+ relativePath: path.join("src", name, `${name}.service.ts`),
526
+ content: `import { Injectable } from '@nestjs/common';
527
+
528
+ @Injectable()
529
+ export class ${classBase}Service {
530
+ async execute(): Promise<string> {
531
+ return '${toCamelCase(name)}';
532
+ }
533
+ }
534
+ `
535
+ }
536
+ ],
537
+ module: [
538
+ {
539
+ relativePath: path.join("src", name, `${name}.module.ts`),
540
+ content: `import { Module } from '@nestjs/common';
541
+
542
+ @Module({})
543
+ export class ${classBase}Module {}
544
+ `
545
+ }
546
+ ],
547
+ entity: [
548
+ {
549
+ relativePath: path.join("src", name, `${name}.entity.ts`),
550
+ content: `export interface ${classBase}Entity {
551
+ id: string;
552
+ createdAt: Date;
553
+ updatedAt: Date;
554
+ }
555
+ `
556
+ }
557
+ ],
558
+ guard: [
559
+ {
560
+ relativePath: path.join("src", name, `${name}.guard.ts`),
561
+ content: `import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
562
+
563
+ @Injectable()
564
+ export class ${classBase}Guard implements CanActivate {
565
+ canActivate(_context: ExecutionContext): boolean {
566
+ return true;
567
+ }
568
+ }
569
+ `
570
+ }
571
+ ]
572
+ };
573
+ fs.mkdirSync(srcRoot, {
574
+ recursive: true
575
+ });
576
+ return writeGeneratedFiles(options.targetRoot, filesByType[options.type], Boolean(options.force));
577
+ }
578
+ __name(scaffoldGenerator, "scaffoldGenerator");
579
+ function isScaffoldGenerator(type) {
580
+ return [
581
+ "rpc",
582
+ "service",
583
+ "module",
584
+ "entity",
585
+ "guard",
586
+ "config"
587
+ ].includes(type);
588
+ }
589
+ __name(isScaffoldGenerator, "isScaffoldGenerator");
590
+ function rpcServiceFiles(serviceName, classBase) {
591
+ return [
592
+ {
593
+ relativePath: path.join("src", serviceName, `${serviceName}.service.ts`),
594
+ content: `import { Injectable } from '@nestjs/common';
595
+ import { RpcMethod, RpcService } from 'wexts/nest';
596
+
597
+ @Injectable()
598
+ @RpcService({ name: '${toCamelCase(serviceName)}', requireAuth: false })
599
+ export class ${classBase}Service {
600
+ @RpcMethod()
601
+ async sayHello(name: string): Promise<string> {
602
+ return \`Hello, \${name}!\`;
603
+ }
604
+ }
605
+ `
606
+ }
607
+ ];
608
+ }
609
+ __name(rpcServiceFiles, "rpcServiceFiles");
610
+ function writeGeneratedFiles(root, files, force) {
611
+ const changedFiles = [];
612
+ for (const file of files) {
613
+ const absolutePath = path.join(root, file.relativePath);
614
+ if (fs.existsSync(absolutePath) && !force) {
615
+ throw new WextsError({
616
+ code: "WEXTS_CLI_GENERATOR_FILE_EXISTS",
617
+ message: `Refusing to overwrite existing file: ${absolutePath}`,
618
+ suggestedFix: "Review the file, then rerun with --force if overwriting is intentional.",
619
+ docsSlug: "cli"
620
+ });
621
+ }
622
+ fs.mkdirSync(path.dirname(absolutePath), {
623
+ recursive: true
624
+ });
625
+ fs.writeFileSync(absolutePath, file.content);
626
+ changedFiles.push(absolutePath);
627
+ }
628
+ return changedFiles;
629
+ }
630
+ __name(writeGeneratedFiles, "writeGeneratedFiles");
631
+ function runScript(script, options) {
632
+ const cwd = options.cwd ?? process.cwd();
633
+ const packageManager = detectPackageManager(cwd);
634
+ const args = packageManager === "npm" ? [
635
+ "run",
636
+ script
637
+ ] : [
638
+ "run",
639
+ script
640
+ ];
641
+ runCommand(packageManager, args, cwd);
642
+ }
643
+ __name(runScript, "runScript");
644
+ function runCommand(command, args, cwd) {
645
+ const result = spawnSync(command, args, {
646
+ cwd,
647
+ stdio: "inherit",
648
+ shell: process.platform === "win32"
649
+ });
650
+ if (result.status !== 0) {
651
+ throw new Error(`${command} ${args.join(" ")} failed with exit code ${result.status}`);
652
+ }
653
+ }
654
+ __name(runCommand, "runCommand");
655
+ function detectPackageManager(cwd) {
656
+ const packageJsonPath = path.join(cwd, "package.json");
657
+ if (fs.existsSync(packageJsonPath)) {
658
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
659
+ if (pkg.packageManager?.startsWith("pnpm@")) return "pnpm";
660
+ }
661
+ if (fs.existsSync(path.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
662
+ if (fs.existsSync(path.join(cwd, "pnpm-workspace.yaml"))) return "pnpm";
663
+ return "npm";
664
+ }
665
+ __name(detectPackageManager, "detectPackageManager");
666
+ function findTemplatePath() {
667
+ const candidates = [
668
+ path.resolve(__dirname, "../../templates"),
669
+ path.resolve(__dirname, "../templates"),
670
+ path.resolve(process.cwd(), "packages/templates")
671
+ ];
672
+ return candidates.find((candidate) => fs.existsSync(candidate));
673
+ }
674
+ __name(findTemplatePath, "findTemplatePath");
675
+ function readPackageVersion() {
676
+ const packageJsonPath = path.resolve(__dirname, "../../package.json");
677
+ if (!fs.existsSync(packageJsonPath)) return "0.0.0";
678
+ return JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).version;
679
+ }
680
+ __name(readPackageVersion, "readPackageVersion");
681
+ function readAllText(cwd, dirs) {
682
+ let text = "";
683
+ for (const dir of dirs) {
684
+ const absolute = path.join(cwd, dir);
685
+ if (!fs.existsSync(absolute)) continue;
686
+ for (const file of walk(absolute)) {
687
+ if (file.endsWith(".ts") || file.endsWith(".tsx") || file.endsWith(".js")) {
688
+ text += fs.readFileSync(file, "utf8");
689
+ }
690
+ }
691
+ }
692
+ return text;
693
+ }
694
+ __name(readAllText, "readAllText");
695
+ function walk(dir) {
696
+ return fs.readdirSync(dir, {
697
+ withFileTypes: true
698
+ }).flatMap((entry) => {
699
+ const absolute = path.join(dir, entry.name);
700
+ if (entry.isDirectory()) return walk(absolute);
701
+ return [
702
+ absolute
703
+ ];
704
+ });
705
+ }
706
+ __name(walk, "walk");
707
+ function toKebabCase(value) {
708
+ return value.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
709
+ }
710
+ __name(toKebabCase, "toKebabCase");
711
+ function toPascalCase(value) {
712
+ return toKebabCase(value).split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
713
+ }
714
+ __name(toPascalCase, "toPascalCase");
715
+ function toCamelCase(value) {
716
+ const pascal = toPascalCase(value);
717
+ return pascal.charAt(0).toLowerCase() + pascal.slice(1);
718
+ }
719
+ __name(toCamelCase, "toCamelCase");
720
+ function pathToFileUrl(filePath) {
721
+ return `file://${filePath}`;
722
+ }
723
+ __name(pathToFileUrl, "pathToFileUrl");
724
+ async function loadRuntimeConfig(configPath) {
725
+ if (configPath.endsWith(".mjs")) {
726
+ const mod2 = await import(pathToFileUrl(configPath));
727
+ return mod2.default ?? mod2;
728
+ }
729
+ const require2 = createRequire(__filename);
730
+ const mod = require2(configPath);
731
+ return mod.default ?? mod;
732
+ }
733
+ __name(loadRuntimeConfig, "loadRuntimeConfig");
734
+ var invokedAsCli = process.argv[1] && (path.basename(process.argv[1]) === "wexts" || path.basename(process.argv[1]) === "wexts.cjs" || path.resolve(process.argv[1]).includes(`${path.sep}dist${path.sep}cli${path.sep}index`));
735
+ if (invokedAsCli && !process.env.VITEST) {
736
+ createCliProgram().parseAsync(process.argv).catch((error) => {
737
+ logger.error(formatWextsError(error));
738
+ process.exit(1);
739
+ });
740
+ }
741
+ export {
742
+ createCliProgram,
743
+ createProject,
744
+ runDoctor,
745
+ scaffoldGenerator
746
+ };
747
+ //# sourceMappingURL=index.mjs.map