wexts 4.1.0 → 4.1.5

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