wexts 4.1.5 → 4.1.7

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 (192) 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-IRRJJ7KL.js +273 -0
  22. package/dist/chunk-IRRJJ7KL.js.map +1 -0
  23. package/dist/chunk-L77ANWWT.mjs +22 -0
  24. package/dist/chunk-L77ANWWT.mjs.map +1 -0
  25. package/dist/chunk-P3Q4I5FD.js +222 -0
  26. package/dist/chunk-P3Q4I5FD.js.map +1 -0
  27. package/dist/chunk-VBIQGUDI.mjs +504 -0
  28. package/dist/chunk-VBIQGUDI.mjs.map +1 -0
  29. package/dist/chunk-VJY6PHYF.mjs +273 -0
  30. package/dist/chunk-VJY6PHYF.mjs.map +1 -0
  31. package/dist/chunk-WCKSKU3C.js +65 -0
  32. package/dist/chunk-WCKSKU3C.js.map +1 -0
  33. package/dist/chunk-XE4OXN2W.js +12 -0
  34. package/dist/chunk-XE4OXN2W.js.map +1 -0
  35. package/dist/cli/index.d.mts +23 -0
  36. package/dist/cli/index.d.ts +23 -0
  37. package/dist/cli/index.js +634 -0
  38. package/dist/cli/index.js.map +1 -0
  39. package/dist/cli/index.mjs +636 -0
  40. package/dist/cli/index.mjs.map +1 -0
  41. package/dist/client/index.d.mts +43 -0
  42. package/dist/client/index.d.ts +43 -0
  43. package/dist/client/index.js +187 -0
  44. package/dist/client/index.js.map +1 -0
  45. package/dist/client/index.mjs +166 -0
  46. package/dist/client/index.mjs.map +1 -0
  47. package/dist/codegen/index.d.mts +2 -0
  48. package/dist/codegen/index.d.ts +2 -0
  49. package/dist/codegen/index.js +16 -0
  50. package/dist/codegen/index.js.map +1 -0
  51. package/dist/codegen/index.mjs +16 -0
  52. package/dist/codegen/index.mjs.map +1 -0
  53. package/dist/decorators-BiQtOHuF.d.ts +60 -0
  54. package/dist/decorators-vBopODtr.d.mts +60 -0
  55. package/dist/dev-server/index.d.mts +1 -0
  56. package/dist/dev-server/index.d.ts +1 -0
  57. package/dist/dev-server/index.js +13 -0
  58. package/dist/dev-server/index.js.map +1 -0
  59. package/dist/dev-server/index.mjs +13 -0
  60. package/dist/dev-server/index.mjs.map +1 -0
  61. package/dist/errors-D545UvXf.d.mts +37 -0
  62. package/dist/errors-D545UvXf.d.ts +37 -0
  63. package/dist/index-7RvU-jGE.d.mts +66 -0
  64. package/dist/index-7RvU-jGE.d.ts +66 -0
  65. package/dist/index-BsafLP-a.d.mts +70 -0
  66. package/dist/index-BsafLP-a.d.ts +70 -0
  67. package/dist/index-CJKs4wtN.d.ts +92 -0
  68. package/dist/index-CUR6CnLk.d.ts +27 -0
  69. package/dist/index-h66Vq9dK.d.mts +92 -0
  70. package/dist/index-tqmYsTUn.d.mts +27 -0
  71. package/dist/index.d.mts +289 -0
  72. package/dist/index.d.ts +289 -0
  73. package/dist/index.js +544 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/index.mjs +544 -0
  76. package/dist/index.mjs.map +1 -0
  77. package/dist/nest/index.d.mts +2 -0
  78. package/dist/nest/index.d.ts +2 -0
  79. package/dist/nest/index.js +36 -0
  80. package/dist/nest/index.js.map +1 -0
  81. package/dist/nest/index.mjs +36 -0
  82. package/dist/nest/index.mjs.map +1 -0
  83. package/dist/next/index.d.mts +66 -0
  84. package/dist/next/index.d.ts +66 -0
  85. package/dist/next/index.js +282 -0
  86. package/dist/next/index.js.map +1 -0
  87. package/dist/next/index.mjs +251 -0
  88. package/dist/next/index.mjs.map +1 -0
  89. package/dist/rpc/index.d.mts +32 -0
  90. package/dist/rpc/index.d.ts +32 -0
  91. package/dist/rpc/index.js +19 -0
  92. package/dist/rpc/index.js.map +1 -0
  93. package/dist/rpc/index.mjs +1 -0
  94. package/dist/rpc/index.mjs.map +1 -0
  95. package/dist/runtime/index.d.mts +55 -0
  96. package/dist/runtime/index.d.ts +55 -0
  97. package/dist/runtime/index.js +15 -0
  98. package/dist/runtime/index.js.map +1 -0
  99. package/dist/runtime/index.mjs +15 -0
  100. package/dist/runtime/index.mjs.map +1 -0
  101. package/dist/server/index.d.mts +7 -0
  102. package/dist/server/index.d.ts +7 -0
  103. package/dist/server/index.js +58 -0
  104. package/dist/server/index.js.map +1 -0
  105. package/dist/server/index.mjs +58 -0
  106. package/dist/server/index.mjs.map +1 -0
  107. package/dist/types/index.d.mts +12 -0
  108. package/dist/types/index.d.ts +12 -0
  109. package/dist/types/index.js +19 -0
  110. package/dist/types/index.js.map +1 -0
  111. package/dist/types/index.mjs +1 -0
  112. package/dist/types/index.mjs.map +1 -0
  113. package/dist/types-CQ_aexOX.d.mts +32 -0
  114. package/dist/types-CQ_aexOX.d.ts +32 -0
  115. package/dist/vercel-builder/index.d.mts +58 -0
  116. package/dist/vercel-builder/index.d.ts +58 -0
  117. package/dist/vercel-builder/index.js +330 -0
  118. package/dist/vercel-builder/index.js.map +1 -0
  119. package/dist/vercel-builder/index.mjs +330 -0
  120. package/dist/vercel-builder/index.mjs.map +1 -0
  121. package/package.json +153 -153
  122. package/templates/.dockerignore +43 -43
  123. package/templates/.env.example +17 -17
  124. package/templates/Dockerfile +60 -60
  125. package/templates/Procfile +1 -1
  126. package/templates/README.md +67 -67
  127. package/templates/api-sdk.ts +115 -115
  128. package/templates/docker-compose.yml +34 -34
  129. package/templates/nestjs-api/.env.example +3 -3
  130. package/templates/nestjs-api/README.md +87 -87
  131. package/templates/nestjs-api/nest-cli.json +6 -6
  132. package/templates/nestjs-api/package.json +40 -40
  133. package/templates/nestjs-api/prisma/migrations/20251123205437_init/migration.sql +24 -24
  134. package/templates/nestjs-api/prisma/migrations/migration_lock.toml +3 -3
  135. package/templates/nestjs-api/prisma/schema.prisma +29 -29
  136. package/templates/nestjs-api/src/app.module.ts +19 -17
  137. package/templates/nestjs-api/src/auth/auth.controller.ts +27 -27
  138. package/templates/nestjs-api/src/auth/auth.module.ts +37 -37
  139. package/templates/nestjs-api/src/auth/auth.service.ts +86 -86
  140. package/templates/nestjs-api/src/auth/dto/auth.dto.ts +22 -22
  141. package/templates/nestjs-api/src/auth/guards/jwt-auth.guard.ts +5 -5
  142. package/templates/nestjs-api/src/auth/strategies/jwt.strategy.ts +27 -27
  143. package/templates/nestjs-api/src/hello.service.ts +11 -0
  144. package/templates/nestjs-api/src/main.ts +32 -32
  145. package/templates/nestjs-api/src/prisma/prisma.module.ts +9 -9
  146. package/templates/nestjs-api/src/prisma/prisma.service.ts +14 -14
  147. package/templates/nestjs-api/src/todos/dto/todo.dto.ts +24 -24
  148. package/templates/nestjs-api/src/todos/todos.controller.ts +39 -39
  149. package/templates/nestjs-api/src/todos/todos.module.ts +11 -11
  150. package/templates/nestjs-api/src/todos/todos.service.ts +53 -53
  151. package/templates/nestjs-api/src/users/users.controller.ts +14 -14
  152. package/templates/nestjs-api/src/users/users.module.ts +12 -12
  153. package/templates/nestjs-api/src/users/users.service.ts +19 -19
  154. package/templates/nestjs-api/tsconfig.json +39 -39
  155. package/templates/nextjs-web/README.md +76 -76
  156. package/templates/nextjs-web/app/actions/auth.ts +108 -108
  157. package/templates/nextjs-web/app/dashboard/error.tsx +39 -39
  158. package/templates/nextjs-web/app/dashboard/loading.tsx +14 -14
  159. package/templates/nextjs-web/app/dashboard/page.tsx +5 -5
  160. package/templates/nextjs-web/app/globals.css +93 -93
  161. package/templates/nextjs-web/app/layout.tsx +29 -29
  162. package/templates/nextjs-web/app/login/page.tsx +5 -5
  163. package/templates/nextjs-web/app/page.tsx +138 -28
  164. package/templates/nextjs-web/app/register/page.tsx +5 -5
  165. package/templates/nextjs-web/components/ui/button.tsx +56 -56
  166. package/templates/nextjs-web/components/ui/card.tsx +79 -79
  167. package/templates/nextjs-web/components/ui/input.tsx +25 -25
  168. package/templates/nextjs-web/components/ui/label.tsx +24 -24
  169. package/templates/nextjs-web/features/auth/LoginForm.tsx +140 -140
  170. package/templates/nextjs-web/features/auth/RegisterForm.tsx +159 -159
  171. package/templates/nextjs-web/features/auth/api.ts +35 -35
  172. package/templates/nextjs-web/features/auth/index.ts +3 -3
  173. package/templates/nextjs-web/features/dashboard/DashboardView.tsx +204 -204
  174. package/templates/nextjs-web/features/dashboard/api.ts +9 -9
  175. package/templates/nextjs-web/features/dashboard/components.tsx +74 -74
  176. package/templates/nextjs-web/features/dashboard/index.ts +3 -3
  177. package/templates/nextjs-web/hooks/index.ts +4 -4
  178. package/templates/nextjs-web/lib/api-client.ts +89 -89
  179. package/templates/nextjs-web/lib/api.ts +115 -115
  180. package/templates/nextjs-web/lib/axios-global-config.ts +17 -17
  181. package/templates/nextjs-web/lib/utils.ts +6 -6
  182. package/templates/nextjs-web/lib/wexts-client.ts +4 -4
  183. package/templates/nextjs-web/next-env.d.ts +6 -6
  184. package/templates/nextjs-web/next.config.ts +20 -20
  185. package/templates/nextjs-web/package.json +37 -37
  186. package/templates/nextjs-web/postcss.config.js +6 -6
  187. package/templates/nextjs-web/tailwind.config.ts +69 -69
  188. package/templates/nextjs-web/tsconfig.json +41 -41
  189. package/templates/nixpacks.toml +11 -11
  190. package/templates/root-package.json +31 -31
  191. package/templates/server.ts +66 -66
  192. package/templates/tsconfig.json +30 -30
@@ -0,0 +1,634 @@
1
+ #!/usr/bin/env node
2
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
3
+
4
+
5
+ var _chunkAVMQJWYDjs = require('../chunk-AVMQJWYD.js');
6
+
7
+
8
+ var _chunkWCKSKU3Cjs = require('../chunk-WCKSKU3C.js');
9
+
10
+
11
+ var _chunkXE4OXN2Wjs = require('../chunk-XE4OXN2W.js');
12
+
13
+ // src/cli/index.ts
14
+ var _commander = require('commander');
15
+ var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
16
+ var _path = require('path'); var path = _interopRequireWildcard(_path);
17
+ var _child_process = require('child_process');
18
+ var _module = require('module');
19
+ function createCliProgram() {
20
+ const program = new (0, _commander.Command)();
21
+ program.name("wexts").description("Wexts - production-focused single-runtime Next.js + NestJS toolkit").version(readPackageVersion());
22
+ 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) => {
23
+ await createProject(projectName, options.template, {
24
+ skipInstall: options.skipInstall
25
+ });
26
+ });
27
+ 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).option("-c, --config <path>", "Runtime config module path", "./wexts.runtime.js").action(async (options) => {
28
+ const { FusionDevServer } = await Promise.resolve().then(() => _interopRequireWildcard(require("../dev-server/index.js")));
29
+ const server = new FusionDevServer();
30
+ await server.start({
31
+ apiPath: options.api,
32
+ webPath: options.web,
33
+ webPort: Number(options.port),
34
+ apiPort: Number(options.apiPort),
35
+ useProxy: options.proxy,
36
+ rootDir: process.cwd(),
37
+ runtimeConfigPath: options.config
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 Promise.resolve().then(() => _interopRequireWildcard(require("../codegen/index.js")));
43
+ const manifest = await generateRpcClient({
44
+ projectPath: path.resolve(options.project),
45
+ outputPath: path.resolve(options.output)
46
+ });
47
+ _chunkWCKSKU3Cjs.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) _chunkWCKSKU3Cjs.logger.info(`created ${path.relative(process.cwd(), file)}`);
59
+ _chunkWCKSKU3Cjs.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 Promise.resolve().then(() => _interopRequireWildcard(require("../codegen/index.js")));
66
+ const manifest = await generateRpcClient({
67
+ projectPath: path.resolve(options.project),
68
+ outputPath: path.resolve(options.output)
69
+ });
70
+ _chunkWCKSKU3Cjs.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 Promise.resolve().then(() => _interopRequireWildcard(require("../codegen/index.js")));
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 Wexts runtime").option("-c, --config <path>", "Runtime config module path", "./wexts.runtime.js").option("-p, --port <port>", "Port to listen on", _nullishCoalesce(process.env.PORT, () => ( "3000"))).option("--dev", "Run the runtime in development mode", false).action(async (options) => {
85
+ const { startWextsRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../runtime/index.js")));
86
+ const configPath = path.resolve(options.config);
87
+ const runtimeConfig = fs.existsSync(configPath) ? await loadRuntimeConfig(configPath, options.dev) : {};
88
+ await startWextsRuntime({
89
+ ...runtimeConfig,
90
+ port: Number(options.port),
91
+ dev: options.dev
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 Promise.resolve().then(() => _interopRequireWildcard(require("../vercel-builder/index.js")));
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) _chunkWCKSKU3Cjs.logger.warn(warning);
108
+ }
109
+ if (result.errors.length > 0) {
110
+ for (const error of result.errors) _chunkWCKSKU3Cjs.logger.error(error);
111
+ process.exit(1);
112
+ }
113
+ _chunkWCKSKU3Cjs.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) _chunkWCKSKU3Cjs.logger.warn(warning);
118
+ for (const error of result.errors) _chunkWCKSKU3Cjs.logger.error(error);
119
+ if (result.errors.length > 0) process.exit(1);
120
+ _chunkWCKSKU3Cjs.logger.success(options.security ? "Security doctor passed." : "Doctor passed.");
121
+ });
122
+ return program;
123
+ }
124
+ _chunkXE4OXN2Wjs.__name.call(void 0, 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 (!_optionalChain([pkg, 'access', _ => _.packageManager, 'optionalAccess', _2 => _2.startsWith, 'call', _3 => _3("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 an API compiler plus the Wexts runtime so `/rpc` and Next routes share the web port.");
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
+ _chunkXE4OXN2Wjs.__name.call(void 0, 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, _nullishCoalesce(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
+ _chunkXE4OXN2Wjs.__name.call(void 0, 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
+ wexts: wextsDependency
206
+ }
207
+ }, null, 2),
208
+ "wexts.runtime.js": `const { HelloService } = require('./apps/api/dist/hello.service.js');
209
+
210
+ module.exports = {
211
+ nextDir: './apps/web',
212
+ rpcManifestPath: './apps/web/lib/wexts/wexts.rpc.manifest.json',
213
+ rpcServices: {
214
+ hello: new HelloService(),
215
+ },
216
+ security: {
217
+ allowedOrigins: ['http://localhost:3000'],
218
+ },
219
+ };
220
+ `,
221
+ "README.md": `# ${projectName}
222
+
223
+ Verified Wexts starter with Next.js and NestJS.
224
+
225
+ \`\`\`bash
226
+ pnpm install
227
+ pnpm run generate
228
+ pnpm run build
229
+ pnpm run dev
230
+ \`\`\`
231
+ `,
232
+ ".cursorrules": `# Wexts Project AI Rules
233
+
234
+ You are an expert full-stack developer working on a Wexts application.
235
+ Wexts is a unified single-runtime toolkit that combines Next.js (frontend) and NestJS (backend) using a highly typed RPC bridge.
236
+
237
+ ## Project Structure
238
+ - \`apps/api/\`: The NestJS backend. Contains business logic, database models, and RPC services.
239
+ - \`apps/web/\`: The Next.js frontend. Contains UI components, pages, and consumes the RPC client.
240
+ - \`apps/web/lib/wexts\`: The auto-generated typed RPC client (DO NOT EDIT MANUALLY).
241
+
242
+ ## Backend Guidelines (NestJS)
243
+ 1. **RPC Services**: To create an API endpoint, create a NestJS provider decorated with \`@RpcService({ name: 'serviceName' })\` and methods decorated with \`@RpcMethod()\`.
244
+ 2. **Imports**: Import \`@RpcService\` and \`@RpcMethod\` from \`wexts/nest\`.
245
+ 3. Do NOT manually create REST controllers unless explicitly needed for webhooks. Use the RPC bridge for all internal frontend-backend communication.
246
+ 4. **Auth**: If a service requires authentication, set \`@RpcService({ requireAuth: true })\`.
247
+
248
+ ## Frontend Guidelines (Next.js)
249
+ 1. **RPC Usage**: To call the backend, import the \`api\` client from \`@/lib/wexts\` or your designated Wexts client file (e.g., \`useWexts()\`).
250
+ 2. **Syntax**: \`const data = await api.serviceName.methodName(args);\`
251
+ 3. The \`api\` object is fully type-safe. Rely on TypeScript autocomplete rather than guessing endpoints.
252
+ `
253
+ };
254
+ for (const [relativePath, content] of Object.entries(files)) {
255
+ const absolutePath = path.join(projectPath, relativePath);
256
+ fs.mkdirSync(path.dirname(absolutePath), {
257
+ recursive: true
258
+ });
259
+ fs.writeFileSync(absolutePath, content);
260
+ }
261
+ const templatePath = findTemplatePath();
262
+ if (!templatePath) {
263
+ throw new Error("Template directory not found in package.");
264
+ }
265
+ const apiTemplatePath = path.join(templatePath, "nestjs-api");
266
+ const apiDestPath = path.join(projectPath, "apps/api");
267
+ if (fs.existsSync(apiTemplatePath)) {
268
+ fs.cpSync(apiTemplatePath, apiDestPath, {
269
+ recursive: true,
270
+ filter: /* @__PURE__ */ _chunkXE4OXN2Wjs.__name.call(void 0, (src) => {
271
+ const basename2 = path.basename(src);
272
+ return basename2 !== "node_modules" && basename2 !== "dist" && basename2 !== "package-lock.json";
273
+ }, "filter")
274
+ });
275
+ const apiPkgPath = path.join(apiDestPath, "package.json");
276
+ if (fs.existsSync(apiPkgPath)) {
277
+ const apiPkg = JSON.parse(fs.readFileSync(apiPkgPath, "utf8"));
278
+ apiPkg.name = `${projectName}-api`;
279
+ if (_optionalChain([apiPkg, 'access', _4 => _4.dependencies, 'optionalAccess', _5 => _5.wexts])) apiPkg.dependencies.wexts = wextsDependency;
280
+ fs.writeFileSync(apiPkgPath, JSON.stringify(apiPkg, null, 2));
281
+ }
282
+ }
283
+ const webTemplatePath = path.join(templatePath, "nextjs-web");
284
+ const webDestPath = path.join(projectPath, "apps/web");
285
+ if (fs.existsSync(webTemplatePath)) {
286
+ fs.cpSync(webTemplatePath, webDestPath, {
287
+ recursive: true,
288
+ filter: /* @__PURE__ */ _chunkXE4OXN2Wjs.__name.call(void 0, (src) => {
289
+ const basename2 = path.basename(src);
290
+ return basename2 !== "node_modules" && basename2 !== ".next" && basename2 !== "package-lock.json";
291
+ }, "filter")
292
+ });
293
+ const webPkgPath = path.join(webDestPath, "package.json");
294
+ if (fs.existsSync(webPkgPath)) {
295
+ const webPkg = JSON.parse(fs.readFileSync(webPkgPath, "utf8"));
296
+ webPkg.name = `${projectName}-web`;
297
+ if (_optionalChain([webPkg, 'access', _6 => _6.dependencies, 'optionalAccess', _7 => _7.wexts])) webPkg.dependencies.wexts = wextsDependency;
298
+ fs.writeFileSync(webPkgPath, JSON.stringify(webPkg, null, 2));
299
+ }
300
+ }
301
+ if (fs.existsSync(path.join(apiDestPath, "src"))) {
302
+ try {
303
+ const { generateRpcClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("../codegen/index.js")));
304
+ await generateRpcClient({
305
+ projectPath: path.join(projectPath, "apps/api"),
306
+ outputPath: path.join(projectPath, "apps/web/lib/wexts")
307
+ });
308
+ } catch (e) {
309
+ _chunkWCKSKU3Cjs.logger.warn('Initial RPC generation failed; you may need to run "wexts generate" after setup.');
310
+ }
311
+ }
312
+ }
313
+ _chunkXE4OXN2Wjs.__name.call(void 0, createVerifiedStarter, "createVerifiedStarter");
314
+ function createLegacyProject(projectPath, projectName) {
315
+ const templatePath = findTemplatePath();
316
+ if (!templatePath) {
317
+ throw new Error("Template directory not found in package.");
318
+ }
319
+ fs.mkdirSync(path.join(projectPath, "apps"), {
320
+ recursive: true
321
+ });
322
+ fs.cpSync(path.join(templatePath, "nestjs-api"), path.join(projectPath, "apps/api"), {
323
+ recursive: true
324
+ });
325
+ fs.cpSync(path.join(templatePath, "nextjs-web"), path.join(projectPath, "apps/web"), {
326
+ recursive: true
327
+ });
328
+ fs.rmSync(path.join(projectPath, "apps/web/package-lock.json"), {
329
+ force: true
330
+ });
331
+ fs.rmSync(path.join(projectPath, "apps/api/package-lock.json"), {
332
+ force: true
333
+ });
334
+ fs.writeFileSync(path.join(projectPath, "pnpm-workspace.yaml"), "packages:\n - 'apps/*'\n");
335
+ fs.writeFileSync(path.join(projectPath, "package.json"), JSON.stringify({
336
+ name: projectName,
337
+ private: true,
338
+ packageManager: "pnpm@10.22.0",
339
+ scripts: {
340
+ dev: "wexts dev",
341
+ generate: "wexts generate",
342
+ build: "wexts build",
343
+ start: "wexts start",
344
+ doctor: "wexts doctor"
345
+ },
346
+ devDependencies: {
347
+ wexts: `^${readPackageVersion()}`
348
+ }
349
+ }, null, 2));
350
+ }
351
+ _chunkXE4OXN2Wjs.__name.call(void 0, createLegacyProject, "createLegacyProject");
352
+ function resolveCreateWextsDependency(projectPath) {
353
+ const packageRoot = path.resolve(__dirname, "../..");
354
+ const cwdLocalPackage = path.join(process.cwd(), "node_modules/wexts");
355
+ try {
356
+ if (fs.existsSync(cwdLocalPackage) && fs.realpathSync(cwdLocalPackage) === fs.realpathSync(packageRoot)) {
357
+ return `file:${path.relative(projectPath, cwdLocalPackage)}`;
358
+ }
359
+ } catch (e2) {
360
+ }
361
+ return `^${readPackageVersion()}`;
362
+ }
363
+ _chunkXE4OXN2Wjs.__name.call(void 0, resolveCreateWextsDependency, "resolveCreateWextsDependency");
364
+ async function scaffoldGenerator(options) {
365
+ if (options.type !== "config" && !options.name) {
366
+ throw new (0, _chunkAVMQJWYDjs.WextsError)({
367
+ code: "WEXTS_CLI_GENERATOR_NAME_REQUIRED",
368
+ message: `Generator "${options.type}" requires a name.`,
369
+ suggestedFix: `Run \`wexts generate ${options.type} hello\` or use \`wexts generate config\`.`,
370
+ docsSlug: "cli"
371
+ });
372
+ }
373
+ if (options.type === "config") {
374
+ return writeGeneratedFiles(options.targetRoot, [
375
+ {
376
+ relativePath: "wexts.runtime.js",
377
+ content: `/** @type {import('wexts/runtime').WextsRuntimeConfig} */
378
+ module.exports = {
379
+ rootDir: __dirname,
380
+ port: Number(process.env.PORT || 3000),
381
+ rpcManifestPath: 'apps/web/lib/wexts/wexts.rpc.manifest.json',
382
+ security: {
383
+ enabled: true,
384
+ production: process.env.NODE_ENV === 'production',
385
+ allowedOrigins: process.env.WEXTS_ALLOWED_ORIGINS?.split(',').filter(Boolean) || [],
386
+ },
387
+ };
388
+ `
389
+ }
390
+ ], Boolean(options.force));
391
+ }
392
+ const rawName = options.name;
393
+ const name = toKebabCase(rawName);
394
+ const classBase = toPascalCase(name);
395
+ const srcRoot = path.join(options.targetRoot, "src");
396
+ const filesByType = {
397
+ rpc: rpcServiceFiles(name, classBase),
398
+ service: [
399
+ {
400
+ relativePath: path.join("src", name, `${name}.service.ts`),
401
+ content: `import { Injectable } from '@nestjs/common';
402
+
403
+ @Injectable()
404
+ export class ${classBase}Service {
405
+ async execute(): Promise<string> {
406
+ return '${toCamelCase(name)}';
407
+ }
408
+ }
409
+ `
410
+ }
411
+ ],
412
+ module: [
413
+ {
414
+ relativePath: path.join("src", name, `${name}.module.ts`),
415
+ content: `import { Module } from '@nestjs/common';
416
+
417
+ @Module({})
418
+ export class ${classBase}Module {}
419
+ `
420
+ }
421
+ ],
422
+ entity: [
423
+ {
424
+ relativePath: path.join("src", name, `${name}.entity.ts`),
425
+ content: `export interface ${classBase}Entity {
426
+ id: string;
427
+ createdAt: Date;
428
+ updatedAt: Date;
429
+ }
430
+ `
431
+ }
432
+ ],
433
+ guard: [
434
+ {
435
+ relativePath: path.join("src", name, `${name}.guard.ts`),
436
+ content: `import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
437
+
438
+ @Injectable()
439
+ export class ${classBase}Guard implements CanActivate {
440
+ canActivate(_context: ExecutionContext): boolean {
441
+ return true;
442
+ }
443
+ }
444
+ `
445
+ }
446
+ ]
447
+ };
448
+ fs.mkdirSync(srcRoot, {
449
+ recursive: true
450
+ });
451
+ return writeGeneratedFiles(options.targetRoot, filesByType[options.type], Boolean(options.force));
452
+ }
453
+ _chunkXE4OXN2Wjs.__name.call(void 0, scaffoldGenerator, "scaffoldGenerator");
454
+ function isScaffoldGenerator(type) {
455
+ return [
456
+ "rpc",
457
+ "service",
458
+ "module",
459
+ "entity",
460
+ "guard",
461
+ "config"
462
+ ].includes(type);
463
+ }
464
+ _chunkXE4OXN2Wjs.__name.call(void 0, isScaffoldGenerator, "isScaffoldGenerator");
465
+ function rpcServiceFiles(serviceName, classBase) {
466
+ return [
467
+ {
468
+ relativePath: path.join("src", serviceName, `${serviceName}.service.ts`),
469
+ content: `import { Injectable } from '@nestjs/common';
470
+ import { RpcMethod, RpcService } from 'wexts/nest';
471
+
472
+ @Injectable()
473
+ @RpcService({ name: '${toCamelCase(serviceName)}', requireAuth: false })
474
+ export class ${classBase}Service {
475
+ @RpcMethod()
476
+ async sayHello(name: string): Promise<string> {
477
+ return \`Hello, \${name}!\`;
478
+ }
479
+ }
480
+ `
481
+ }
482
+ ];
483
+ }
484
+ _chunkXE4OXN2Wjs.__name.call(void 0, rpcServiceFiles, "rpcServiceFiles");
485
+ function writeGeneratedFiles(root, files, force) {
486
+ const changedFiles = [];
487
+ for (const file of files) {
488
+ const absolutePath = path.join(root, file.relativePath);
489
+ if (fs.existsSync(absolutePath) && !force) {
490
+ throw new (0, _chunkAVMQJWYDjs.WextsError)({
491
+ code: "WEXTS_CLI_GENERATOR_FILE_EXISTS",
492
+ message: `Refusing to overwrite existing file: ${absolutePath}`,
493
+ suggestedFix: "Review the file, then rerun with --force if overwriting is intentional.",
494
+ docsSlug: "cli"
495
+ });
496
+ }
497
+ fs.mkdirSync(path.dirname(absolutePath), {
498
+ recursive: true
499
+ });
500
+ fs.writeFileSync(absolutePath, file.content);
501
+ changedFiles.push(absolutePath);
502
+ }
503
+ return changedFiles;
504
+ }
505
+ _chunkXE4OXN2Wjs.__name.call(void 0, writeGeneratedFiles, "writeGeneratedFiles");
506
+ function runScript(script, options) {
507
+ const cwd = _nullishCoalesce(options.cwd, () => ( process.cwd()));
508
+ const packageManager = detectPackageManager(cwd);
509
+ const args = packageManager === "npm" ? [
510
+ "run",
511
+ script
512
+ ] : [
513
+ "run",
514
+ script
515
+ ];
516
+ runCommand(packageManager, args, cwd);
517
+ }
518
+ _chunkXE4OXN2Wjs.__name.call(void 0, runScript, "runScript");
519
+ function runCommand(command, args, cwd) {
520
+ const result = _child_process.spawnSync.call(void 0, command, args, {
521
+ cwd,
522
+ stdio: "inherit",
523
+ shell: process.platform === "win32"
524
+ });
525
+ if (result.status !== 0) {
526
+ throw new Error(`${command} ${args.join(" ")} failed with exit code ${result.status}`);
527
+ }
528
+ }
529
+ _chunkXE4OXN2Wjs.__name.call(void 0, runCommand, "runCommand");
530
+ function detectPackageManager(cwd) {
531
+ const packageJsonPath = path.join(cwd, "package.json");
532
+ if (fs.existsSync(packageJsonPath)) {
533
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
534
+ if (_optionalChain([pkg, 'access', _8 => _8.packageManager, 'optionalAccess', _9 => _9.startsWith, 'call', _10 => _10("pnpm@")])) return "pnpm";
535
+ }
536
+ if (fs.existsSync(path.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
537
+ if (fs.existsSync(path.join(cwd, "pnpm-workspace.yaml"))) return "pnpm";
538
+ return "npm";
539
+ }
540
+ _chunkXE4OXN2Wjs.__name.call(void 0, detectPackageManager, "detectPackageManager");
541
+ function findTemplatePath() {
542
+ const candidates = [
543
+ path.resolve(__dirname, "../../templates"),
544
+ path.resolve(__dirname, "../templates"),
545
+ path.resolve(process.cwd(), "packages/templates")
546
+ ];
547
+ return candidates.find((candidate) => fs.existsSync(candidate));
548
+ }
549
+ _chunkXE4OXN2Wjs.__name.call(void 0, findTemplatePath, "findTemplatePath");
550
+ function readPackageVersion() {
551
+ const packageJsonPath = path.resolve(__dirname, "../../package.json");
552
+ if (!fs.existsSync(packageJsonPath)) return "0.0.0";
553
+ return JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).version;
554
+ }
555
+ _chunkXE4OXN2Wjs.__name.call(void 0, readPackageVersion, "readPackageVersion");
556
+ function readAllText(cwd, dirs) {
557
+ let text = "";
558
+ for (const dir of dirs) {
559
+ const absolute = path.join(cwd, dir);
560
+ if (!fs.existsSync(absolute)) continue;
561
+ for (const file of walk(absolute)) {
562
+ if (file.endsWith(".ts") || file.endsWith(".tsx") || file.endsWith(".js")) {
563
+ text += fs.readFileSync(file, "utf8");
564
+ }
565
+ }
566
+ }
567
+ return text;
568
+ }
569
+ _chunkXE4OXN2Wjs.__name.call(void 0, readAllText, "readAllText");
570
+ function walk(dir) {
571
+ return fs.readdirSync(dir, {
572
+ withFileTypes: true
573
+ }).flatMap((entry) => {
574
+ const absolute = path.join(dir, entry.name);
575
+ if (entry.isDirectory()) return walk(absolute);
576
+ return [
577
+ absolute
578
+ ];
579
+ });
580
+ }
581
+ _chunkXE4OXN2Wjs.__name.call(void 0, walk, "walk");
582
+ function toKebabCase(value) {
583
+ return value.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
584
+ }
585
+ _chunkXE4OXN2Wjs.__name.call(void 0, toKebabCase, "toKebabCase");
586
+ function toPascalCase(value) {
587
+ return toKebabCase(value).split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
588
+ }
589
+ _chunkXE4OXN2Wjs.__name.call(void 0, toPascalCase, "toPascalCase");
590
+ function toCamelCase(value) {
591
+ const pascal = toPascalCase(value);
592
+ return pascal.charAt(0).toLowerCase() + pascal.slice(1);
593
+ }
594
+ _chunkXE4OXN2Wjs.__name.call(void 0, toCamelCase, "toCamelCase");
595
+ function pathToFileUrl(filePath) {
596
+ return `file://${filePath}`;
597
+ }
598
+ _chunkXE4OXN2Wjs.__name.call(void 0, pathToFileUrl, "pathToFileUrl");
599
+ async function loadRuntimeConfig(configPath, retry = false) {
600
+ const deadline = Date.now() + (retry ? 15e3 : 0);
601
+ let lastError;
602
+ do {
603
+ try {
604
+ if (configPath.endsWith(".mjs")) {
605
+ const mod2 = await Promise.resolve().then(() => _interopRequireWildcard(require(pathToFileUrl(configPath))));
606
+ return _nullishCoalesce(mod2.default, () => ( mod2));
607
+ }
608
+ const require2 = _module.createRequire.call(void 0, __filename);
609
+ delete require2.cache[require2.resolve(configPath)];
610
+ const mod = require2(configPath);
611
+ return _nullishCoalesce(mod.default, () => ( mod));
612
+ } catch (error) {
613
+ lastError = error;
614
+ if (!retry || Date.now() >= deadline) break;
615
+ await new Promise((resolve2) => setTimeout(resolve2, 500));
616
+ }
617
+ } while (retry);
618
+ throw lastError;
619
+ }
620
+ _chunkXE4OXN2Wjs.__name.call(void 0, loadRuntimeConfig, "loadRuntimeConfig");
621
+ 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`));
622
+ if (invokedAsCli && !process.env.VITEST) {
623
+ createCliProgram().parseAsync(process.argv).catch((error) => {
624
+ _chunkWCKSKU3Cjs.logger.error(_chunkAVMQJWYDjs.formatWextsError.call(void 0, error));
625
+ process.exit(1);
626
+ });
627
+ }
628
+
629
+
630
+
631
+
632
+
633
+ exports.createCliProgram = createCliProgram; exports.createProject = createProject; exports.runDoctor = runDoctor; exports.scaffoldGenerator = scaffoldGenerator;
634
+ //# sourceMappingURL=index.js.map