@cedarjs/cli 9.0.0-canary.1784 → 9.0.0-canary.3124

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 (277) hide show
  1. package/README.md +7 -10
  2. package/dist/cfw.js +10 -6
  3. package/dist/commands/build/buildHandler.js +220 -45
  4. package/dist/commands/build/buildPackagesTask.js +21 -20
  5. package/dist/commands/build.js +13 -2
  6. package/dist/commands/check.js +4 -6
  7. package/dist/commands/console.js +6 -4
  8. package/dist/commands/deploy/baremetal/SshExecutor.js +13 -4
  9. package/dist/commands/deploy/baremetal/baremetalHandler.js +116 -50
  10. package/dist/commands/deploy/baremetal.js +11 -4
  11. package/dist/commands/deploy/flightcontrolHandler.js +28 -15
  12. package/dist/commands/deploy/helpers/deployHandler.js +11 -6
  13. package/dist/commands/deploy/netlify.js +1 -1
  14. package/dist/commands/deploy/packing/nft.js +1 -2
  15. package/dist/commands/deploy/render.js +1 -1
  16. package/dist/commands/deploy/renderHandler.js +24 -13
  17. package/dist/commands/deploy/serverlessHandler.js +69 -27
  18. package/dist/commands/deploy/vercel.js +1 -1
  19. package/dist/commands/destroy/component/component.js +2 -3
  20. package/dist/commands/destroy/directive/directive.js +1 -3
  21. package/dist/commands/destroy/directive/directiveHandler.js +2 -4
  22. package/dist/commands/destroy/function/function.js +1 -3
  23. package/dist/commands/destroy/handlerHelpers.js +17 -17
  24. package/dist/commands/destroy/helpers.js +8 -2
  25. package/dist/commands/destroy/layout/layout.js +1 -2
  26. package/dist/commands/destroy/page/pageHandler.js +3 -3
  27. package/dist/commands/destroy/scaffold/scaffoldHandler.js +31 -12
  28. package/dist/commands/destroy/sdl/sdlHandler.js +3 -3
  29. package/dist/commands/dev/apiDebugFlag.js +5 -4
  30. package/dist/commands/dev/devHandler.js +219 -68
  31. package/dist/commands/dev/packageWatchCommands.js +8 -3
  32. package/dist/commands/dev.js +16 -6
  33. package/dist/commands/execHandler.js +49 -29
  34. package/dist/commands/experimental/live-queries/liveQueries.js +32 -0
  35. package/dist/commands/experimental/live-queries/liveQueriesHandler.js +448 -0
  36. package/dist/commands/experimental/live-queries/templates/liveQueriesListener.ts.template +153 -0
  37. package/dist/commands/experimental/live-queries/templates/migration.sql.template +100 -0
  38. package/dist/commands/experimental/setupInngest.js +2 -2
  39. package/dist/commands/experimental/setupInngestHandler.js +13 -12
  40. package/dist/commands/experimental/setupOpentelemetry.js +2 -2
  41. package/dist/commands/experimental/setupOpentelemetryHandler.js +14 -10
  42. package/dist/commands/experimental/setupReactCompiler.js +2 -2
  43. package/dist/commands/experimental/setupReactCompilerHandler.js +48 -33
  44. package/dist/commands/experimental/setupRsc.js +1 -1
  45. package/dist/commands/experimental/setupRscHandler.js +20 -16
  46. package/dist/commands/experimental/setupStreamingSsr.js +2 -2
  47. package/dist/commands/experimental/setupStreamingSsrHandler.js +49 -34
  48. package/dist/commands/experimental/templates/opentelemetry.ts.template +2 -1
  49. package/dist/commands/experimental/templates/rsc/Document.tsx.template +1 -1
  50. package/dist/commands/experimental/templates/rsc/entry.client.tsx.template +8 -8
  51. package/dist/commands/experimental/templates/streamingSsr/Document.tsx.template +1 -1
  52. package/dist/commands/experimental/templates/streamingSsr/entry.client.tsx.template +6 -6
  53. package/dist/commands/experimental/templates/streamingSsr/tsconfig.json.template +6 -6
  54. package/dist/commands/experimental/util.js +27 -25
  55. package/dist/commands/experimental.js +3 -2
  56. package/dist/commands/generate/cell/cell.js +20 -0
  57. package/dist/commands/generate/cell/cellHandler.js +89 -40
  58. package/dist/commands/generate/cell/templates/cell.tsx.template +21 -2
  59. package/dist/commands/generate/cell/templates/cellFragment.tsx.template +43 -0
  60. package/dist/commands/generate/cell/templates/cellList.tsx.template +21 -2
  61. package/dist/commands/generate/cell/templates/storiesFragment.tsx.template +23 -0
  62. package/dist/commands/generate/cell/templates/test.js.template +1 -1
  63. package/dist/commands/generate/cell/templates/testFragment.js.template +30 -0
  64. package/dist/commands/generate/component/componentHandler.js +14 -16
  65. package/dist/commands/generate/dataMigration/dataMigration.js +36 -18
  66. package/dist/commands/generate/dataMigration/templates/dataMigration.js.template +1 -1
  67. package/dist/commands/generate/dataMigration/templates/dataMigration.ts.template +1 -1
  68. package/dist/commands/generate/dbAuth/dbAuth.js +1 -0
  69. package/dist/commands/generate/dbAuth/dbAuthHandler.js +63 -34
  70. package/dist/commands/generate/dbAuth/templates/login.oauth.tsx.template +164 -0
  71. package/dist/commands/generate/dbAuth/templates/signup.oauth.tsx.template +147 -0
  72. package/dist/commands/generate/directive/directiveHandler.js +14 -16
  73. package/dist/commands/generate/function/function.js +1 -0
  74. package/dist/commands/generate/function/functionHandler.js +14 -19
  75. package/dist/commands/generate/helpers.js +34 -18
  76. package/dist/commands/generate/job/job.js +1 -0
  77. package/dist/commands/generate/job/jobHandler.js +20 -24
  78. package/dist/commands/generate/layout/layoutHandler.js +13 -16
  79. package/dist/commands/generate/model/model.js +1 -0
  80. package/dist/commands/generate/model/modelHandler.js +11 -5
  81. package/dist/commands/generate/ogImage/ogImage.js +1 -0
  82. package/dist/commands/generate/ogImage/ogImageHandler.js +18 -11
  83. package/dist/commands/generate/package/filesTask.js +9 -0
  84. package/dist/commands/generate/package/packageHandler.js +50 -61
  85. package/dist/commands/generate/package/templates/test.ts.template +2 -2
  86. package/dist/commands/generate/package/templates/vitest.config.ts.template +9 -0
  87. package/dist/commands/generate/page/pageHandler.js +27 -24
  88. package/dist/commands/generate/realtime/realtime.js +2 -2
  89. package/dist/commands/generate/realtime/realtimeHandler.js +51 -32
  90. package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.ts.template +1 -1
  91. package/dist/commands/generate/scaffold/scaffold.js +1 -0
  92. package/dist/commands/generate/scaffold/scaffoldHandler.js +176 -49
  93. package/dist/commands/generate/scaffold/templates/lib/formatters.tsx.template +1 -1
  94. package/dist/commands/generate/script/script.js +1 -0
  95. package/dist/commands/generate/script/scriptHandler.js +10 -6
  96. package/dist/commands/generate/script/templates/script.ts.template +9 -4
  97. package/dist/commands/generate/script/templates/tsconfig.json.template +16 -2
  98. package/dist/commands/generate/sdl/sdl.js +4 -3
  99. package/dist/commands/generate/sdl/sdlHandler.js +135 -46
  100. package/dist/commands/generate/sdl/stubFiles.js +132 -0
  101. package/dist/commands/generate/sdl/templates/sdl.js.template +2 -1
  102. package/dist/commands/generate/sdl/templates/sdl.ts.template +2 -1
  103. package/dist/commands/generate/secret/secret.js +20 -20
  104. package/dist/commands/generate/service/service.js +5 -5
  105. package/dist/commands/generate/service/serviceHandler.js +126 -61
  106. package/dist/commands/generate/service/templates/scenarios.ts.template +4 -2
  107. package/dist/commands/generate/service/templates/service.ts.template +22 -8
  108. package/dist/commands/generate/service/templates/test.ts.template +2 -2
  109. package/dist/commands/generate/yargsCommandHelpers.js +7 -2
  110. package/dist/commands/generate/yargsHandlerHelpers.js +20 -18
  111. package/dist/commands/generate.js +4 -4
  112. package/dist/commands/info.js +2 -2
  113. package/dist/commands/jobsHandler.js +7 -4
  114. package/dist/commands/lint.js +26 -69
  115. package/dist/commands/prerenderHandler.js +95 -58
  116. package/dist/commands/prismaHandler.js +51 -26
  117. package/dist/commands/record/init.js +2 -2
  118. package/dist/commands/record.js +4 -3
  119. package/dist/commands/serve.js +245 -31
  120. package/dist/commands/serveApiHandler.js +7 -6
  121. package/dist/commands/serveBothHandler.js +22 -13
  122. package/dist/commands/serveWebHandler.js +3 -2
  123. package/dist/commands/setup/auth/auth.js +15 -11
  124. package/dist/commands/setup/cache/cache.js +1 -1
  125. package/dist/commands/setup/cache/cacheHandler.js +15 -9
  126. package/dist/commands/setup/database/database.js +15 -0
  127. package/dist/commands/setup/database/postgres.js +19 -0
  128. package/dist/commands/setup/database/postgresHandler.js +196 -0
  129. package/dist/commands/setup/database/templates/db.ts.template +32 -0
  130. package/dist/commands/setup/deploy/deploy.js +4 -3
  131. package/dist/commands/setup/deploy/helpers/helpers.js +5 -1
  132. package/dist/commands/setup/deploy/helpers/index.js +132 -6
  133. package/dist/commands/setup/deploy/providers/baremetalHandler.js +28 -6
  134. package/dist/commands/setup/deploy/providers/coherence.js +1 -1
  135. package/dist/commands/setup/deploy/providers/coherenceHandler.js +60 -31
  136. package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +69 -51
  137. package/dist/commands/setup/deploy/providers/netlify.js +6 -0
  138. package/dist/commands/setup/deploy/providers/netlifyHandler.js +114 -13
  139. package/dist/commands/setup/deploy/providers/renderHandler.js +44 -41
  140. package/dist/commands/setup/deploy/providers/serverlessHandler.js +7 -5
  141. package/dist/commands/setup/deploy/providers/universal-deploy.js +11 -0
  142. package/dist/commands/setup/deploy/providers/universalDeployHandler.js +186 -0
  143. package/dist/commands/setup/deploy/providers/vercel.js +6 -0
  144. package/dist/commands/setup/deploy/providers/vercelHandler.js +115 -14
  145. package/dist/commands/setup/deploy/templates/baremetal.js +3 -2
  146. package/dist/commands/setup/deploy/templates/flightcontrol.js +60 -49
  147. package/dist/commands/setup/deploy/templates/netlify.js +2 -1
  148. package/dist/commands/setup/deploy/templates/netlifyUD.js +31 -0
  149. package/dist/commands/setup/deploy/templates/render.js +32 -17
  150. package/dist/commands/setup/docker/docker.js +2 -2
  151. package/dist/commands/setup/docker/dockerHandler.js +74 -39
  152. package/dist/commands/setup/docker/templates/Dockerfile.npm +119 -0
  153. package/dist/commands/setup/docker/templates/Dockerfile.pnpm +112 -0
  154. package/dist/commands/setup/docker/templates/{Dockerfile → Dockerfile.yarn} +4 -7
  155. package/dist/commands/setup/docker/templates/docker-compose.dev.yml +3 -3
  156. package/dist/commands/setup/docker/templates/docker-compose.prod.yml +2 -5
  157. package/dist/commands/setup/docker/templates/dockerignore +1 -0
  158. package/dist/commands/setup/generator/generator.js +1 -1
  159. package/dist/commands/setup/generator/generatorHandler.js +5 -4
  160. package/dist/commands/setup/graphql/features/fragments/appGqlConfigTransform.js +6 -3
  161. package/dist/commands/setup/graphql/features/fragments/fragments.js +1 -1
  162. package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +5 -7
  163. package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocuments.js +1 -1
  164. package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +4 -3
  165. package/dist/commands/setup/i18n/i18n.js +1 -1
  166. package/dist/commands/setup/i18n/i18nHandler.js +21 -17
  167. package/dist/commands/setup/jobs/jobs.js +1 -1
  168. package/dist/commands/setup/jobs/jobsHandler.js +17 -12
  169. package/dist/commands/setup/mailer/mailer.js +1 -1
  170. package/dist/commands/setup/mailer/mailerHandler.js +13 -11
  171. package/dist/commands/setup/middleware/ogImage/ogImage.js +1 -1
  172. package/dist/commands/setup/middleware/ogImage/ogImageHandler.js +2 -1
  173. package/dist/commands/setup/monitoring/sentry/sentry.js +1 -1
  174. package/dist/commands/setup/monitoring/sentry/sentryHandler.js +18 -12
  175. package/dist/commands/setup/neon/neon.js +35 -0
  176. package/dist/commands/setup/neon/neonHandler.js +264 -0
  177. package/dist/commands/setup/package/package.js +1 -1
  178. package/dist/commands/setup/package/packageHandler.js +18 -14
  179. package/dist/commands/setup/realtime/addRealtimeToGraphql.js +1 -1
  180. package/dist/commands/setup/realtime/realtime.js +1 -1
  181. package/dist/commands/setup/realtime/realtimeHandler.js +26 -37
  182. package/dist/commands/setup/realtime/templates/realtime.ts.template +1 -1
  183. package/dist/commands/setup/realtime/templates/subscriptions/countdown/countdown.ts.template +1 -1
  184. package/dist/commands/setup/realtime/templates/subscriptions/newMessage/newMessage.ts.template +1 -1
  185. package/dist/commands/setup/server-file/serverFile.js +1 -1
  186. package/dist/commands/setup/server-file/serverFileHandler.js +18 -10
  187. package/dist/commands/setup/tenancy/authCodemod.js +66 -0
  188. package/dist/commands/setup/tenancy/dbCodemod.js +64 -0
  189. package/dist/commands/setup/tenancy/graphqlCodemod.js +88 -0
  190. package/dist/commands/setup/tenancy/preflight.js +49 -0
  191. package/dist/commands/setup/tenancy/schemaPrisma.js +81 -0
  192. package/dist/commands/setup/tenancy/signupCodemod.js +153 -0
  193. package/dist/commands/setup/tenancy/templates/InvitePage.tsx.template +63 -0
  194. package/dist/commands/setup/tenancy/templates/OrgScope.tsx.template +40 -0
  195. package/dist/commands/setup/tenancy/templates/ensureDefaultOrganizations.dataMigration.ts.template +39 -0
  196. package/dist/commands/setup/tenancy/templates/organizations.scenarios.ts.template +59 -0
  197. package/dist/commands/setup/tenancy/templates/organizations.sdl.ts.template +89 -0
  198. package/dist/commands/setup/tenancy/templates/organizations.test.ts.template +389 -0
  199. package/dist/commands/setup/tenancy/templates/organizations.ts.template +394 -0
  200. package/dist/commands/setup/tenancy/templates/requireMembership.test.ts.template +35 -0
  201. package/dist/commands/setup/tenancy/templates/requireMembership.ts.template +25 -0
  202. package/dist/commands/setup/tenancy/tenancy.js +30 -0
  203. package/dist/commands/setup/tenancy/tenancyHandler.js +425 -0
  204. package/dist/commands/setup/ui/helpers/helpers.js +5 -1
  205. package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +16 -8
  206. package/dist/commands/setup/ui/libraries/mantineHandler.js +26 -16
  207. package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +40 -29
  208. package/dist/commands/setup/uploads/schemaPrisma.js +41 -0
  209. package/dist/commands/setup/uploads/serverFile.js +151 -0
  210. package/dist/commands/setup/uploads/templates/requireUploadToken.ts.template +15 -0
  211. package/dist/commands/setup/uploads/templates/srcLibUploads.ts.template +23 -24
  212. package/dist/commands/setup/uploads/templates/uploads.sdl.ts.template +79 -0
  213. package/dist/commands/setup/uploads/templates/uploads.ts.template +89 -0
  214. package/dist/commands/setup/uploads/templates/withDataUri.ts.template +14 -0
  215. package/dist/commands/setup/uploads/templates/withSignedUrl.ts.template +16 -0
  216. package/dist/commands/setup/uploads/uploads.js +49 -7
  217. package/dist/commands/setup/uploads/uploadsHandler.js +266 -72
  218. package/dist/commands/setup.js +5 -4
  219. package/dist/commands/studio.js +1 -1
  220. package/dist/commands/studioHandler.js +2 -2
  221. package/dist/commands/test/datasourceWarning.js +42 -0
  222. package/dist/commands/test/testHandler.js +104 -0
  223. package/dist/commands/test/viteVersionCheck.js +75 -0
  224. package/dist/commands/test.js +16 -19
  225. package/dist/commands/type-check.js +2 -1
  226. package/dist/commands/type-checkHandler.js +25 -18
  227. package/dist/commands/upgrade/preUpgradeScripts.js +11 -11
  228. package/dist/commands/upgrade/upgrade.js +4 -2
  229. package/dist/commands/upgrade/upgradeHandler.js +97 -73
  230. package/dist/index.js +15 -11
  231. package/dist/lib/background.js +22 -1
  232. package/dist/lib/configureStorybook.js +2 -2
  233. package/dist/lib/exec.js +68 -63
  234. package/dist/lib/exit.js +20 -5
  235. package/dist/lib/extendFile.js +23 -13
  236. package/dist/lib/generatePrismaClient.js +48 -12
  237. package/dist/lib/index.js +137 -106
  238. package/dist/lib/loadEnvFiles.js +1 -1
  239. package/dist/lib/locking.js +8 -4
  240. package/dist/lib/merge/algorithms.js +4 -1
  241. package/dist/lib/merge/index.js +78 -41
  242. package/dist/lib/merge/semanticIdentity.js +18 -6
  243. package/dist/lib/merge/strategy.js +86 -36
  244. package/dist/lib/packages.js +23 -13
  245. package/dist/lib/plugin.js +13 -7
  246. package/dist/lib/pluralHelpers.js +6 -2
  247. package/dist/lib/project.js +3 -1
  248. package/dist/lib/rollback.js +7 -7
  249. package/dist/lib/schemaHelpers.js +16 -19
  250. package/dist/lib/test.js +20 -5
  251. package/dist/lib/updateCheck.js +47 -18
  252. package/dist/middleware/checkNodeVersion.js +9 -4
  253. package/dist/middleware/{detectProjectRxVersion.js → detectProjectCedarVersion.js} +2 -2
  254. package/dist/plugin.js +18 -12
  255. package/dist/telemetry/exporter.js +12 -5
  256. package/dist/telemetry/index.js +4 -3
  257. package/dist/telemetry/resource.js +9 -12
  258. package/dist/telemetry/send.js +14 -10
  259. package/dist/testLib/cells.js +5 -3
  260. package/package.json +44 -41
  261. package/LICENSE +0 -21
  262. package/dist/commands/consoleHandler.js +0 -68
  263. package/dist/commands/setup/tsconfig/tsconfig.js +0 -25
  264. package/dist/commands/setup/tsconfig/tsconfigHandler.js +0 -59
  265. package/dist/commands/setup/uploads/dbCodemod.js +0 -28
  266. package/dist/commands/setup/uploads/templates/signedUrl.ts.template +0 -21
  267. package/dist/commands/setup/vite/templates/vite.config.ts.template +0 -19
  268. package/dist/commands/setup/vite/vite.js +0 -38
  269. package/dist/commands/setup/vite/viteHandler.js +0 -83
  270. package/dist/commands/testEsm.js +0 -36
  271. package/dist/commands/testHandler.js +0 -137
  272. package/dist/commands/testHandlerEsm.js +0 -85
  273. package/dist/commands/ts-to-js.js +0 -20
  274. package/dist/lib/cedarPluralize.js +0 -56
  275. package/dist/lib/colors.js +0 -18
  276. package/dist/testLib/getFilesWithPattern.js +0 -21
  277. /package/dist/{index.d.js → global.d.js} +0 -0
@@ -2,17 +2,21 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { ListrEnquirerPromptAdapter } from "@listr2/prompt-adapter-enquirer";
4
4
  import { paramCase, camelCase } from "change-case";
5
- import execa from "execa";
6
5
  import { modify, applyEdits } from "jsonc-parser";
7
6
  import { Listr } from "listr2";
8
7
  import { terminalLink } from "termi-link";
9
8
  import ts from "typescript";
10
- import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
9
+ import { colors as c } from "@cedarjs/cli-helpers/colors";
10
+ import { workspacePackageSpecifier } from "@cedarjs/cli-helpers/packageManager";
11
+ import { runScript, runBinSync } from "@cedarjs/cli-helpers/packageManager/exec";
12
+ import { installPackages } from "@cedarjs/cli-helpers/packageManager/packages";
13
+ import { addWorkspaceDir } from "@cedarjs/cli-helpers/packageManager/workspaces";
14
+ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
11
15
  import { getConfig } from "@cedarjs/project-config";
16
+ import { getPackageManager } from "@cedarjs/project-config/packageManager";
12
17
  import { errorTelemetry } from "@cedarjs/telemetry";
13
- import c from "../../../lib/colors.js";
14
18
  import { getPaths, writeFilesTask } from "../../../lib/index.js";
15
- import { prepareForRollback } from "../../../lib/rollback.js";
19
+ import { addFileToRollback, prepareForRollback } from "../../../lib/rollback.js";
16
20
  import { files } from "./filesTask.js";
17
21
  function nameVariants(nameArg) {
18
22
  const base = path.basename(getPaths().base);
@@ -29,8 +33,10 @@ async function updateTsconfig(task) {
29
33
  path: path.join(getPaths().api.base, "tsconfig.json"),
30
34
  expectedModule: "node20",
31
35
  // While Cedar doesn't officially endorse NodeNext, it will still work
32
- // here, so we'll keep it
33
- acceptable: ["node20", "nodenext"]
36
+ // here, so we'll keep it. ESNext is also acceptable: it's the current
37
+ // create-cedar-app default, paired with `moduleResolution: bundler` so
38
+ // extensionless scaffold/generator imports resolve correctly.
39
+ acceptable: ["node20", "nodenext", "esnext"]
34
40
  },
35
41
  {
36
42
  name: "web",
@@ -60,7 +66,7 @@ async function updateTsconfig(task) {
60
66
  "Failed to parse tsconfig: " + JSON.stringify(error, null, 2)
61
67
  );
62
68
  }
63
- if (!tsconfig?.compilerOptions || typeof tsconfig.compilerOptions.module === "undefined") {
69
+ if (tsconfig.compilerOptions?.module === void 0) {
64
70
  continue;
65
71
  }
66
72
  const currentModule = typeof tsconfig.compilerOptions.module === "string" ? tsconfig.compilerOptions.module.toLowerCase() : String(tsconfig.compilerOptions.module).toLowerCase();
@@ -126,14 +132,12 @@ async function addDependencyToPackageJson(task, packageJsonPath, packageName) {
126
132
  const packageJson = JSON.parse(
127
133
  await fs.promises.readFile(packageJsonPath, "utf8")
128
134
  );
129
- if (!packageJson.dependencies) {
130
- packageJson.dependencies = {};
131
- }
132
- if (packageJson.dependencies[packageName]) {
135
+ packageJson.dependencies ??= {};
136
+ if (packageJson?.dependencies[packageName]) {
133
137
  task.skip("Dependency already exists");
134
138
  return;
135
139
  }
136
- packageJson.dependencies[packageName] = "workspace:*";
140
+ packageJson.dependencies[packageName] = workspacePackageSpecifier();
137
141
  await fs.promises.writeFile(
138
142
  packageJsonPath,
139
143
  JSON.stringify(packageJson, null, 2)
@@ -200,7 +204,7 @@ function updateWorkspaceTsconfigReferences(task, folderName, targetWorkspaces) {
200
204
  readFile: (p) => {
201
205
  try {
202
206
  return fs.readFileSync(p, "utf8");
203
- } catch (e) {
207
+ } catch {
204
208
  return ts.sys.readFile(p);
205
209
  }
206
210
  },
@@ -213,21 +217,21 @@ function updateWorkspaceTsconfigReferences(task, folderName, targetWorkspaces) {
213
217
  },
214
218
  path.dirname(ws.tsconfigPath)
215
219
  );
216
- if (configParseResult.errors && configParseResult.errors.length) {
220
+ if (configParseResult.errors?.length) {
217
221
  console.error("Parse errors:", configParseResult.errors);
218
222
  }
219
223
  if (!Array.isArray(tsconfig.references)) {
220
224
  tsconfig.references = [];
221
225
  }
222
- const packageDir2 = ws.packageDir || path.join(getPaths().base, "packages", folderName);
223
- const referencePath = path.relative(path.dirname(ws.tsconfigPath), packageDir2).split(path.sep).join("/");
226
+ const wsPackageDir = ws.packageDir || path.join(getPaths().base, "packages", folderName);
227
+ const referencePath = path.relative(path.dirname(ws.tsconfigPath), wsPackageDir).split(path.sep).join("/");
224
228
  const references = tsconfig.references;
225
- if (references.some((ref) => ref && ref.path === referencePath)) {
229
+ if (references.some((ref) => ref?.path === referencePath)) {
226
230
  subtask.skip("tsconfig already up to date");
227
231
  return;
228
232
  }
229
233
  const newReferences = references.concat([{ path: referencePath }]);
230
- let text = await fs.promises.readFile(ws.tsconfigPath, "utf8");
234
+ const text = await fs.promises.readFile(ws.tsconfigPath, "utf8");
231
235
  const edits = modify(text, ["references"], newReferences, {
232
236
  formattingOptions: { insertSpaces: true, tabSize: 2 }
233
237
  });
@@ -244,14 +248,21 @@ function updateWorkspaceTsconfigReferences(task, folderName, targetWorkspaces) {
244
248
  }
245
249
  async function installAndBuild(folderName) {
246
250
  const packagePath = path.join("packages", folderName);
247
- await execa("yarn", ["install"], { stdio: "inherit", cwd: getPaths().base });
248
- await execa("yarn", ["build"], { stdio: "inherit", cwd: packagePath });
251
+ await installPackages({ stdio: "inherit", cwd: getPaths().base });
252
+ addFileToRollback(
253
+ path.join(getPaths().base, packagePath, "tsconfig.tsbuildinfo")
254
+ );
255
+ await runScript("build", [], { stdio: "inherit", cwd: packagePath });
249
256
  }
250
- const handler = async ({ name, force, ...rest }) => {
257
+ const handler = async ({
258
+ name,
259
+ force,
260
+ ...rest
261
+ }) => {
251
262
  recordTelemetryAttributes({
252
263
  command: "generate package",
253
264
  force,
254
- rollback: rest.rollback
265
+ rollback: typeof rest.rollback === "boolean" ? rest.rollback : void 0
255
266
  });
256
267
  if (name.replaceAll("/", "").length < name.length - 1) {
257
268
  throw new Error(
@@ -272,7 +283,6 @@ const handler = async ({ name, force, ...rest }) => {
272
283
  }
273
284
  let packageFiles = {};
274
285
  const tasks = new Listr(
275
- /** @type {import('listr2').ListrTask<ListrContext>[]} */
276
286
  [
277
287
  {
278
288
  title: "Parsing package name...",
@@ -282,34 +292,12 @@ const handler = async ({ name, force, ...rest }) => {
282
292
  },
283
293
  {
284
294
  title: "Updating workspace config...",
285
- task: async (ctx, task) => {
286
- const rootPackageJsonPath = path.join(getPaths().base, "package.json");
287
- const packageJson = JSON.parse(
288
- await fs.promises.readFile(rootPackageJsonPath, "utf8")
289
- );
290
- if (!Array.isArray(packageJson.workspaces)) {
291
- throw new Error(
292
- "Invalid workspace config in " + rootPackageJsonPath
293
- );
294
- }
295
+ task: (ctx, task) => {
296
+ const pm = getPackageManager();
295
297
  const packagePath = `packages/${ctx.nameVariants.folderName}`;
296
- const hasWildcardPackagesWorkspace = packageJson.workspaces.includes("packages/*");
297
- const hasNamedPackagesWorkspace = packageJson.workspaces.includes(packagePath);
298
- const hasOtherNamedPackages = packageJson.workspaces.some(
299
- (workspace) => workspace.startsWith("packages/") && workspace !== packagePath
300
- );
301
- if (hasWildcardPackagesWorkspace || hasNamedPackagesWorkspace) {
298
+ const result = addWorkspaceDir(getPaths().base, packagePath, pm);
299
+ if (result === "exists") {
302
300
  task.skip("Workspaces already configured");
303
- } else {
304
- if (hasOtherNamedPackages) {
305
- packageJson.workspaces.push(packagePath);
306
- } else {
307
- packageJson.workspaces.push("packages/*");
308
- }
309
- await fs.promises.writeFile(
310
- rootPackageJsonPath,
311
- JSON.stringify(packageJson, null, 2)
312
- );
313
301
  }
314
302
  }
315
303
  },
@@ -326,7 +314,7 @@ const handler = async ({ name, force, ...rest }) => {
326
314
  return;
327
315
  }
328
316
  } catch (e) {
329
- throw new Error(e.message);
317
+ throw new Error(e instanceof Error ? e.message : String(e));
330
318
  }
331
319
  const prompt = task.prompt(ListrEnquirerPromptAdapter);
332
320
  const response = await prompt.run({
@@ -353,7 +341,10 @@ const handler = async ({ name, force, ...rest }) => {
353
341
  {
354
342
  title: "Generating package files...",
355
343
  task: async (ctx) => {
356
- packageFiles = await files({ ...ctx.nameVariants, ...rest });
344
+ packageFiles = await files({
345
+ ...ctx.nameVariants,
346
+ ...rest
347
+ });
357
348
  return writeFilesTask(packageFiles, { overwriteExisting: force });
358
349
  }
359
350
  },
@@ -425,13 +416,9 @@ const handler = async ({ name, force, ...rest }) => {
425
416
  {
426
417
  title: "Cleaning up...",
427
418
  task: () => {
428
- execa.sync("yarn", [
429
- "eslint",
430
- "--fix",
431
- "--config",
432
- `${getPaths().base}/node_modules/@cedarjs/eslint-config/index.js`,
433
- ...Object.keys(packageFiles)
434
- ]);
419
+ runBinSync("eslint", ["--fix", ...Object.keys(packageFiles)], {
420
+ cwd: getPaths().base
421
+ });
435
422
  }
436
423
  }
437
424
  ],
@@ -443,9 +430,11 @@ const handler = async ({ name, force, ...rest }) => {
443
430
  }
444
431
  await tasks.run();
445
432
  } catch (e) {
446
- errorTelemetry(process.argv, e.message);
447
- console.error(c.error(e.message));
448
- process.exit(e?.exitCode || 1);
433
+ const msg = e instanceof Error ? e.message : String(e);
434
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
435
+ errorTelemetry(process.argv, msg);
436
+ console.error(c.error(msg));
437
+ process.exit(exitCode);
449
438
  }
450
439
  };
451
440
  export {
@@ -1,7 +1,7 @@
1
1
  import { ${camelName} } from './index.js'
2
2
 
3
3
  describe('${camelName}', () => {
4
- it('should not throw any errors', async () => {
5
- expect(${camelName}()).not.toThrow()
4
+ it('should not throw any errors', () => {
5
+ expect(() => ${camelName}()).not.toThrow()
6
6
  })
7
7
  })
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ name: '${folderName}',
6
+ // Enables global test APIs like describe, it, expect
7
+ globals: true,
8
+ },
9
+ })
@@ -2,14 +2,14 @@ import { execSync } from "child_process";
2
2
  import camelcase from "camelcase";
3
3
  import { Listr } from "listr2";
4
4
  import pascalcase from "pascalcase";
5
- import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
5
+ import { colors as c } from "@cedarjs/cli-helpers/colors";
6
+ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
6
7
  import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
7
8
  import { getConfig } from "@cedarjs/project-config";
8
9
  import { errorTelemetry } from "@cedarjs/telemetry";
9
- import c from "../../../lib/colors.js";
10
10
  import {
11
11
  addRoutesToRouterTask,
12
- transformTSToJS,
12
+ transformTSToJSMap,
13
13
  writeFilesTask
14
14
  } from "../../../lib/index.js";
15
15
  import {
@@ -24,8 +24,8 @@ import {
24
24
  } from "../helpers.js";
25
25
  import { templateForComponentFile } from "../yargsHandlerHelpers.js";
26
26
  const COMPONENT_SUFFIX = "Page";
27
- const REDWOOD_WEB_PATH_NAME = "pages";
28
- const mapRouteParamTypeToDefaultValue = (paramType) => {
27
+ const CEDAR_WEB_PATH_NAME = "pages";
28
+ function mapRouteParamTypeToDefaultValue(paramType) {
29
29
  switch (paramType) {
30
30
  case "Int":
31
31
  return 42;
@@ -36,7 +36,7 @@ const mapRouteParamTypeToDefaultValue = (paramType) => {
36
36
  default:
37
37
  return "42";
38
38
  }
39
- };
39
+ }
40
40
  const paramVariants = (path) => {
41
41
  const param = path?.match(/(\{[\w:]+\})/)?.[1];
42
42
  const paramName = param?.replace(/:[^}]+/, "").slice(1, -1);
@@ -63,13 +63,19 @@ const paramVariants = (path) => {
63
63
  paramType: mapRouteParamTypeToTsType(routeParamType)
64
64
  };
65
65
  };
66
- const files = async ({ name, tests, stories, typescript, ...rest }) => {
66
+ const files = async ({
67
+ name,
68
+ tests,
69
+ stories,
70
+ typescript = false,
71
+ ...rest
72
+ }) => {
67
73
  const extension = typescript ? ".tsx" : ".jsx";
68
74
  const pageFile = await templateForComponentFile({
69
75
  name,
70
76
  suffix: COMPONENT_SUFFIX,
71
77
  extension,
72
- webPathSection: REDWOOD_WEB_PATH_NAME,
78
+ webPathSection: CEDAR_WEB_PATH_NAME,
73
79
  generator: "page",
74
80
  templatePath: "page.tsx.template",
75
81
  templateVars: {
@@ -81,7 +87,7 @@ const files = async ({ name, tests, stories, typescript, ...rest }) => {
81
87
  name,
82
88
  suffix: COMPONENT_SUFFIX,
83
89
  extension: `.test${extension}`,
84
- webPathSection: REDWOOD_WEB_PATH_NAME,
90
+ webPathSection: CEDAR_WEB_PATH_NAME,
85
91
  generator: "page",
86
92
  templatePath: "test.tsx.template",
87
93
  templateVars: rest
@@ -90,7 +96,7 @@ const files = async ({ name, tests, stories, typescript, ...rest }) => {
90
96
  name,
91
97
  suffix: COMPONENT_SUFFIX,
92
98
  extension: `.stories${extension}`,
93
- webPathSection: REDWOOD_WEB_PATH_NAME,
99
+ webPathSection: CEDAR_WEB_PATH_NAME,
94
100
  generator: "page",
95
101
  templatePath: rest.paramName !== "" ? "stories.tsx.parameters.template" : "stories.tsx.template",
96
102
  templateVars: rest
@@ -102,16 +108,12 @@ const files = async ({ name, tests, stories, typescript, ...rest }) => {
102
108
  if (stories) {
103
109
  files2.push(storiesFile);
104
110
  }
105
- return files2.reduce(async (accP, [outputPath, content]) => {
106
- const acc = await accP;
107
- const template = typescript ? content : await transformTSToJS(outputPath, content);
108
- return {
109
- [outputPath]: template,
110
- ...acc
111
- };
112
- }, Promise.resolve({}));
111
+ return transformTSToJSMap(files2, typescript);
113
112
  };
114
- const routes = ({ name, path }) => {
113
+ const routes = ({
114
+ name,
115
+ path
116
+ }) => {
115
117
  return [
116
118
  `<Route path="${path}" page={${pascalcase(name)}Page} name="${camelcase(
117
119
  name
@@ -160,7 +162,6 @@ const handler = async ({
160
162
  path = pathName(path, pageName);
161
163
  const f = await files({
162
164
  name: pageName,
163
- path,
164
165
  tests,
165
166
  stories,
166
167
  typescript,
@@ -192,7 +193,7 @@ const handler = async ({
192
193
  },
193
194
  {
194
195
  title: "One more thing...",
195
- task: (ctx, task) => {
196
+ task: (_ctx, task) => {
196
197
  task.title = `One more thing...
197
198
 
198
199
  ${c.warning("Page created! A note about <Metadata>:")}
@@ -214,9 +215,11 @@ const handler = async ({
214
215
  }
215
216
  await tasks.run();
216
217
  } catch (e) {
217
- errorTelemetry(process.argv, e.message);
218
- console.error(c.error(e.message));
219
- process.exit(e?.exitCode || 1);
218
+ const message = e instanceof Error ? e.message : String(e);
219
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
220
+ errorTelemetry(process.argv, message);
221
+ console.error(c.error(message));
222
+ process.exit(exitCode);
220
223
  }
221
224
  };
222
225
  export {
@@ -1,8 +1,8 @@
1
- import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
1
+ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
2
2
  const command = "realtime <name>";
3
3
  const description = "Generate a subscription or live query used with RedwoodJS Realtime";
4
4
  function builder(yargs) {
5
- yargs.positional("name", {
5
+ return yargs.positional("name", {
6
6
  type: "string",
7
7
  description: "Name of the realtime event to setup. This should be a type or model name like: Widget, Sprocket, etc.",
8
8
  demandOption: true
@@ -2,12 +2,11 @@ import path from "path";
2
2
  import camelcase from "camelcase";
3
3
  import { Listr } from "listr2";
4
4
  import pascalcase from "pascalcase";
5
- import pluralize, { singular } from "pluralize";
5
+ import pluralize from "pluralize";
6
6
  import prompts from "prompts";
7
+ import { colors as c } from "@cedarjs/cli-helpers/colors";
7
8
  import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
8
- import { projectIsEsm } from "@cedarjs/project-config";
9
9
  import { errorTelemetry } from "@cedarjs/telemetry";
10
- import c from "../../../lib/colors.js";
11
10
  import {
12
11
  generateTemplate,
13
12
  getPaths,
@@ -17,7 +16,7 @@ import {
17
16
  import { isTypeScriptProject } from "../../../lib/project.js";
18
17
  import { isRealtimeSetup, isServerFileSetup } from "../../experimental/util.js";
19
18
  const templateVariables = (name) => {
20
- name = singular(name.toLowerCase());
19
+ name = pluralize.singular(name.toLowerCase());
21
20
  return {
22
21
  name,
23
22
  collectionName: pluralize(name),
@@ -35,10 +34,16 @@ const templateVariables = (name) => {
35
34
  subscriptionServiceResolver: `publishTo${pascalcase(name)}Channel`
36
35
  };
37
36
  };
38
- async function handler({ name, type, force, verbose, silent }) {
39
- const redwoodPaths = getPaths();
37
+ async function handler({
38
+ name,
39
+ type,
40
+ force,
41
+ verbose,
42
+ silent
43
+ }) {
44
+ const cedarPaths = getPaths();
40
45
  const ts = isTypeScriptProject();
41
- name = singular(name.toLowerCase());
46
+ name = pluralize.singular(name.toLowerCase());
42
47
  let functionType = type;
43
48
  if (!functionType) {
44
49
  const response = await prompts({
@@ -60,12 +65,13 @@ async function handler({ name, type, force, verbose, silent }) {
60
65
  });
61
66
  functionType = response.functionType;
62
67
  }
63
- const tasks = new Listr(
64
- [
68
+ function buildTaskData() {
69
+ return [
65
70
  {
66
71
  title: "Checking for realtime environment prerequisites ...",
67
72
  task: () => {
68
- isServerFileSetup() && isRealtimeSetup();
73
+ isServerFileSetup();
74
+ isRealtimeSetup();
69
75
  }
70
76
  },
71
77
  {
@@ -80,7 +86,7 @@ async function handler({ name, type, force, verbose, silent }) {
80
86
  `blank.sdl.ts.template`
81
87
  );
82
88
  const sdlFile = path.join(
83
- redwoodPaths.api.graphql,
89
+ cedarPaths.api.graphql,
84
90
  `${name}.sdl.${isTypeScriptProject() ? "ts" : "js"}`
85
91
  );
86
92
  const sdlContent = ts ? exampleSdlTemplateContent : await transformTSToJS(sdlFile, exampleSdlTemplateContent);
@@ -92,7 +98,7 @@ async function handler({ name, type, force, verbose, silent }) {
92
98
  `blank.service.ts.template`
93
99
  );
94
100
  const serviceFile = path.join(
95
- redwoodPaths.api.services,
101
+ cedarPaths.api.services,
96
102
  `${name}`,
97
103
  `${name}.${isTypeScriptProject() ? "ts" : "js"}`
98
104
  );
@@ -105,7 +111,7 @@ async function handler({ name, type, force, verbose, silent }) {
105
111
  `blank.ts.template`
106
112
  );
107
113
  const exampleFile = path.join(
108
- redwoodPaths.api.subscriptions,
114
+ cedarPaths.api.subscriptions,
109
115
  `${name}`,
110
116
  `${name}.${isTypeScriptProject() ? "ts" : "js"}`
111
117
  );
@@ -113,16 +119,10 @@ async function handler({ name, type, force, verbose, silent }) {
113
119
  exampleFile,
114
120
  exampleSubscriptionTemplateContent
115
121
  );
116
- let blankTemplateContent = await generateTemplate(
122
+ const blankTemplateContent = await generateTemplate(
117
123
  setupScriptContent,
118
124
  templateVariables(name)
119
125
  );
120
- if (projectIsEsm()) {
121
- blankTemplateContent = blankTemplateContent.replace(
122
- "import gql from 'graphql-tag'",
123
- "import { gql } from 'graphql-tag'"
124
- );
125
- }
126
126
  return [
127
127
  writeFile(
128
128
  sdlFile,
@@ -156,7 +156,7 @@ async function handler({ name, type, force, verbose, silent }) {
156
156
  `blank.sdl.ts.template`
157
157
  );
158
158
  const sdlFile = path.join(
159
- redwoodPaths.api.graphql,
159
+ cedarPaths.api.graphql,
160
160
  `${name}.sdl.${isTypeScriptProject() ? "ts" : "js"}`
161
161
  );
162
162
  const sdlContent = ts ? exampleSdlTemplateContent : await transformTSToJS(sdlFile, exampleSdlTemplateContent);
@@ -168,7 +168,7 @@ async function handler({ name, type, force, verbose, silent }) {
168
168
  "blank.service.ts.template"
169
169
  );
170
170
  const serviceFile = path.join(
171
- redwoodPaths.api.services,
171
+ cedarPaths.api.services,
172
172
  `${name}`,
173
173
  `${name}.${isTypeScriptProject() ? "ts" : "js"}`
174
174
  );
@@ -200,18 +200,37 @@ async function handler({ name, type, force, verbose, silent }) {
200
200
  );
201
201
  }
202
202
  }
203
- ],
204
- {
205
- rendererOptions: { collapseSubtasks: false, persistentOutput: true },
206
- renderer: silent ? "silent" : verbose ? "verbose" : "default"
207
- }
208
- );
203
+ ];
204
+ }
209
205
  try {
210
- await tasks.run();
206
+ if (silent) {
207
+ await new Listr(buildTaskData(), {
208
+ exitOnError: true,
209
+ renderer: "silent"
210
+ }).run();
211
+ } else if (verbose) {
212
+ await new Listr(buildTaskData(), {
213
+ exitOnError: true,
214
+ renderer: "verbose"
215
+ }).run();
216
+ } else {
217
+ await new Listr(
218
+ buildTaskData().map((t) => ({
219
+ ...t,
220
+ rendererOptions: { persistentOutput: true }
221
+ })),
222
+ {
223
+ exitOnError: true,
224
+ rendererOptions: { collapseSubtasks: false }
225
+ }
226
+ ).run();
227
+ }
211
228
  } catch (e) {
212
- errorTelemetry(process.argv, e.message);
213
- console.error(c.error(e.message));
214
- process.exit(e?.exitCode || 1);
229
+ const message = e instanceof Error ? e.message : String(e);
230
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
231
+ errorTelemetry(process.argv, message);
232
+ console.error(c.error(message));
233
+ process.exit(exitCode);
215
234
  }
216
235
  }
217
236
  export {
@@ -1,4 +1,4 @@
1
- import gql from 'graphql-tag'
1
+ import { gql } from 'graphql-tag'
2
2
 
3
3
  import type { PubSub } from '@cedarjs/realtime'
4
4
 
@@ -28,6 +28,7 @@ const builder = (yargs) => {
28
28
  Object.entries(getYargsDefaults()).forEach(([option, config]) => {
29
29
  yargs.option(option, config);
30
30
  });
31
+ return yargs;
31
32
  };
32
33
  const handler = createHandler("scaffold");
33
34
  export {