@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
@@ -5,33 +5,36 @@ import execa from "execa";
5
5
  import latestVersion from "latest-version";
6
6
  import { Listr } from "listr2";
7
7
  import { terminalLink } from "termi-link";
8
- import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
8
+ import { colors as c } from "@cedarjs/cli-helpers/colors";
9
+ import {
10
+ dedupe,
11
+ dedupeIsSupported,
12
+ install,
13
+ installationErrorMessage,
14
+ prettyPrintCedarCommand
15
+ } from "@cedarjs/cli-helpers/packageManager";
16
+ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
9
17
  import { getConfig } from "@cedarjs/project-config";
10
- import c from "../../lib/colors.js";
18
+ import { getPackageManager } from "@cedarjs/project-config/packageManager";
11
19
  import { generatePrismaClient } from "../../lib/generatePrismaClient.js";
12
20
  import { getPaths } from "../../lib/index.js";
13
21
  import { PLUGIN_CACHE_FILENAME } from "../../lib/plugin.js";
14
22
  import { runPreUpgradeScripts } from "./preUpgradeScripts.js";
15
23
  import { isValidCedarJSTag } from "./tags.js";
16
- const handler = async ({
17
- dryRun,
18
- tag,
19
- verbose,
20
- dedupe,
21
- yes,
22
- force
23
- }) => {
24
+ const handler = async (upgradeOptions) => {
25
+ const { dryRun, tag, verbose, dedupe: dedupe2, yes, force } = upgradeOptions;
24
26
  recordTelemetryAttributes({
25
27
  command: "upgrade",
26
28
  dryRun: !!dryRun,
27
29
  tag: tag ?? "latest",
28
30
  verbose: !!verbose,
29
- dedupe: !!dedupe,
31
+ dedupe: !!dedupe2,
30
32
  yes: !!yes,
31
33
  force: !!force
32
34
  });
33
35
  let preUpgradeMessage = "";
34
36
  let preUpgradeError = "";
37
+ const notBlockedByPreUpgradeChecks = (ctx) => force || !ctx.preUpgradeError;
35
38
  const tasks = new Listr(
36
39
  [
37
40
  {
@@ -86,51 +89,57 @@ const handler = async ({
86
89
  {
87
90
  title: "Updating your CedarJS version",
88
91
  task: (ctx) => updateCedarJSDepsForAllSides(ctx, { dryRun, verbose }),
89
- enabled: (ctx) => !!ctx.versionToUpgradeTo && !ctx.preUpgradeError
92
+ enabled: (ctx) => !!ctx.versionToUpgradeTo && notBlockedByPreUpgradeChecks(ctx)
90
93
  },
91
94
  {
92
95
  title: "Updating other packages in your package.json(s)",
93
96
  task: (ctx) => updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }),
94
- enabled: (ctx) => String(ctx.versionToUpgradeTo).includes("canary") && !ctx.preUpgradeError
97
+ // Canary only. This forces the template's dependency versions onto the
98
+ // project and adds back any the project is missing, which resurrects
99
+ // packages people have deliberately removed — a project that moved off
100
+ // SQLite gets better-sqlite3 back, for example. That's too blunt for
101
+ // regular upgrades, but people running canary are already signed up
102
+ // for rougher edges.
103
+ // https://github.com/redwoodjs/redwood/pull/8855
104
+ enabled: (ctx) => String(ctx.versionToUpgradeTo).includes("canary") && notBlockedByPreUpgradeChecks(ctx)
95
105
  },
96
106
  {
97
107
  title: "Downloading yarn patches",
98
108
  task: (ctx) => downloadYarnPatches(ctx, { dryRun, verbose }),
99
- enabled: (ctx) => String(ctx.versionToUpgradeTo).includes("canary") && !ctx.preUpgradeError
109
+ enabled: (ctx) => String(ctx.versionToUpgradeTo).includes("canary") && notBlockedByPreUpgradeChecks(ctx)
100
110
  },
101
111
  {
102
112
  title: "Removing CLI cache",
103
113
  task: () => removeCliCache({ dryRun, verbose }),
104
- enabled: (ctx) => !ctx.preUpgradeError
114
+ enabled: (ctx) => notBlockedByPreUpgradeChecks(ctx)
105
115
  },
106
116
  {
107
- title: "Running yarn install",
108
- task: () => yarnInstall({ verbose }),
109
- enabled: (ctx) => !ctx.preUpgradeError,
117
+ title: `Running ${getPackageManager()} ${install()}`,
118
+ task: () => packageManagerInstall({ verbose }),
119
+ enabled: (ctx) => notBlockedByPreUpgradeChecks(ctx),
110
120
  skip: () => !!dryRun
111
121
  },
112
122
  {
113
123
  title: "Refreshing the Prisma client",
114
124
  task: (_ctx, task) => refreshPrismaClient(task, { verbose }),
115
- enabled: (ctx) => !ctx.preUpgradeError,
125
+ enabled: (ctx) => notBlockedByPreUpgradeChecks(ctx),
116
126
  skip: () => !!dryRun
117
127
  },
118
128
  {
119
129
  title: "De-duplicating dependencies",
120
- skip: () => !!dryRun || !dedupe,
121
- enabled: (ctx) => !ctx.preUpgradeError,
130
+ skip: () => !!dryRun || !dedupe2,
131
+ enabled: (ctx) => dedupeIsSupported() && notBlockedByPreUpgradeChecks(ctx),
122
132
  task: (_ctx, task) => dedupeDeps(task, { verbose })
123
133
  },
124
134
  {
125
135
  title: "One more thing..",
126
136
  task: (ctx, task) => {
127
137
  const version = ctx.versionToUpgradeTo;
138
+ const upgradeMessage = dryRun ? `\u{1F3C3} Dry run complete. Your project would be upgraded to CedarJS ${version}.` : `\u{1F389} Your project has been upgraded to CedarJS ${version}!`;
128
139
  const messageSections = [
129
140
  `One more thing...
130
141
 
131
- ${c.warning(
132
- `\u{1F389} Your project has been upgraded to CedarJS ${version}!`
133
- )}
142
+ ${c.warning(upgradeMessage)}
134
143
 
135
144
  `
136
145
  ];
@@ -188,21 +197,18 @@ const handler = async ({
188
197
  }
189
198
  if (preUpgradeMessage) {
190
199
  console.log("");
191
- console.log(` \u{1F4E3} ${c.info("Pre-upgrade Message:")}`);
200
+ console.log(` \u{1F4E3} ${c.info("Pre-upgrade Script Messages:")}`);
192
201
  console.log(" " + preUpgradeMessage.replace(/\n/g, "\n "));
193
202
  }
194
203
  };
195
- async function yarnInstall({ verbose }) {
204
+ async function packageManagerInstall({ verbose }) {
196
205
  try {
197
- await execa("yarn install", {
198
- shell: true,
206
+ await execa(getPackageManager(), [install()], {
199
207
  stdio: verbose ? "inherit" : "pipe",
200
208
  cwd: getPaths().base
201
209
  });
202
210
  } catch {
203
- throw new Error(
204
- "Could not finish installation. Please run `yarn install` and then `yarn dedupe`, before continuing"
205
- );
211
+ throw new Error(installationErrorMessage());
206
212
  }
207
213
  }
208
214
  async function removeCliCache({
@@ -306,6 +312,22 @@ function updateCedarJSDepsForAllSides(ctx, options) {
306
312
  })
307
313
  );
308
314
  }
315
+ function mergeTemplateDependencies(field, templatePackageJson, localPackageJson, messages, { dryRun, verbose } = {}) {
316
+ const templateDeps = templatePackageJson[field];
317
+ if (!templateDeps) {
318
+ return;
319
+ }
320
+ for (const [depName, depVersion] of Object.entries(templateDeps)) {
321
+ if (depName.startsWith("@cedarjs/")) {
322
+ continue;
323
+ }
324
+ const localDeps = localPackageJson[field] ??= {};
325
+ if (verbose || dryRun) {
326
+ messages.push(` - ${depName}: ${localDeps[depName]} => ${depVersion}`);
327
+ }
328
+ localDeps[depName] = depVersion;
329
+ }
330
+ }
309
331
  async function updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }) {
310
332
  if (!ctx.versionToUpgradeTo) {
311
333
  throw new Error("Failed to upgrade");
@@ -331,35 +353,25 @@ async function updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }) {
331
353
  title: `Updating ${pkgJsonPath}`,
332
354
  task: async (_ctx, task) => {
333
355
  const res = await fetch(url);
356
+ if (!res.ok) {
357
+ throw new Error(
358
+ `Failed to fetch template package.json from ${url}: ` + res.statusText
359
+ );
360
+ }
334
361
  const text = await res.text();
335
362
  const templatePackageJson = JSON.parse(text);
336
363
  const localPackageJsonText = fs.readFileSync(pkgJsonPath, "utf-8");
337
364
  const localPackageJson = JSON.parse(localPackageJsonText);
338
365
  const messages = [];
339
- Object.entries(templatePackageJson.dependencies || {}).forEach(
340
- ([depName, depVersion]) => {
341
- if (!depName.startsWith("@cedarjs/")) {
342
- if (verbose || dryRun) {
343
- messages.push(
344
- ` - ${depName}: ${localPackageJson.dependencies[depName]} => ${depVersion}`
345
- );
346
- }
347
- localPackageJson.dependencies[depName] = depVersion;
348
- }
349
- }
350
- );
351
- Object.entries(templatePackageJson.devDependencies || {}).forEach(
352
- ([depName, depVersion]) => {
353
- if (!depName.startsWith("@cedarjs/")) {
354
- if (verbose || dryRun) {
355
- messages.push(
356
- ` - ${depName}: ${localPackageJson.devDependencies[depName]} => ${depVersion}`
357
- );
358
- }
359
- localPackageJson.devDependencies[depName] = depVersion;
360
- }
361
- }
362
- );
366
+ for (const field of ["dependencies", "devDependencies"]) {
367
+ mergeTemplateDependencies(
368
+ field,
369
+ templatePackageJson,
370
+ localPackageJson,
371
+ messages,
372
+ { dryRun, verbose }
373
+ );
374
+ }
363
375
  if (messages.length > 0) {
364
376
  task.title = task.title + "\n" + messages.join("\n");
365
377
  }
@@ -380,16 +392,19 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
380
392
  throw new Error("Failed to upgrade");
381
393
  }
382
394
  const githubToken = process.env.GH_TOKEN || process.env.GITHUB_TOKEN || process.env.REDWOOD_GITHUB_TOKEN;
383
- const res = await fetch(
384
- "https://api.github.com/repos/cedarjs/cedar/git/trees/main?recursive=1",
385
- {
386
- headers: {
387
- ...githubToken && { Authorization: `Bearer ${githubToken}` },
388
- ["X-GitHub-Api-Version"]: "2022-11-28",
389
- Accept: "application/vnd.github+json"
390
- }
395
+ const url = "https://api.github.com/repos/cedarjs/cedar/git/trees/main?recursive=1";
396
+ const res = await fetch(url, {
397
+ headers: {
398
+ ...githubToken && { Authorization: `Bearer ${githubToken}` },
399
+ ["X-GitHub-Api-Version"]: "2022-11-28",
400
+ Accept: "application/vnd.github+json"
391
401
  }
392
- );
402
+ });
403
+ if (!res.ok) {
404
+ throw new Error(
405
+ `Failed to fetch list of yarn patches from ${url}: ` + res.statusText
406
+ );
407
+ }
393
408
  const json = await res.json();
394
409
  const patches = json.tree?.filter(
395
410
  (patchInfo) => patchInfo.path.startsWith(
@@ -409,6 +424,11 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
409
424
  title: `Downloading ${patch.path}`,
410
425
  task: async () => {
411
426
  const res2 = await fetch(patch.url);
427
+ if (!res2.ok) {
428
+ throw new Error(
429
+ `Failed to fetch patch metadata from ${patch.url}: ` + res2.statusText
430
+ );
431
+ }
412
432
  const patchMeta = await res2.json();
413
433
  const patchPath = path.join(
414
434
  getPaths().base,
@@ -429,20 +449,23 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
429
449
  }
430
450
  async function refreshPrismaClient(task, { verbose }) {
431
451
  try {
432
- await generatePrismaClient({ verbose, force: false });
452
+ await generatePrismaClient({ verbose, force: true });
433
453
  } catch (e) {
434
454
  const message = e instanceof Error ? e.message : String(e);
435
455
  task.skip("Refreshing the Prisma client caused an Error.");
436
456
  console.log(
437
- "You may need to update your prisma client manually: $ yarn cedar prisma generate"
457
+ "You may need to update your prisma client manually: $ " + prettyPrintCedarCommand(["prisma", "generate"])
438
458
  );
439
459
  console.log(c.error(message));
440
460
  }
441
461
  }
442
- const dedupeDeps = async (_task, { verbose }) => {
462
+ async function dedupeDeps(_task, { verbose }) {
463
+ const dedupeCmd = dedupe();
464
+ if (!dedupeCmd) {
465
+ return;
466
+ }
443
467
  try {
444
- await execa("yarn dedupe", {
445
- shell: true,
468
+ await execa(getPackageManager(), [dedupeCmd], {
446
469
  stdio: verbose ? "inherit" : "pipe",
447
470
  cwd: getPaths().base
448
471
  });
@@ -450,11 +473,12 @@ const dedupeDeps = async (_task, { verbose }) => {
450
473
  const message = e instanceof Error ? e.message : String(e);
451
474
  console.log(c.error(message));
452
475
  throw new Error(
453
- "Could not finish de-duplication. Please run `yarn dedupe` before continuing"
476
+ `Could not finish de-duplication. Please run \`${getPackageManager()} ${dedupeCmd}\` before continuing`
454
477
  );
455
478
  }
456
- await yarnInstall({ verbose });
457
- };
479
+ await packageManagerInstall({ verbose });
480
+ }
458
481
  export {
459
- handler
482
+ handler,
483
+ mergeTemplateDependencies
460
484
  };
package/dist/index.js CHANGED
@@ -4,8 +4,10 @@ import path from "path";
4
4
  import { trace, SpanStatusCode } from "@opentelemetry/api";
5
5
  import { hideBin, Parser } from "yargs/helpers";
6
6
  import yargs from "yargs/yargs";
7
- import { loadEnvFiles, recordTelemetryAttributes } from "@cedarjs/cli-helpers";
8
- import { findUp, projectIsEsm, getConfigPath } from "@cedarjs/project-config";
7
+ import { colors as c } from "@cedarjs/cli-helpers/colors";
8
+ import { loadEnvFiles } from "@cedarjs/cli-helpers/loadEnvFiles";
9
+ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
10
+ import { findUp, getConfigPath } from "@cedarjs/project-config";
9
11
  import { telemetryMiddleware } from "@cedarjs/telemetry";
10
12
  import * as buildCommand from "./commands/build.js";
11
13
  import * as checkCommand from "./commands/check.js";
@@ -26,29 +28,31 @@ import * as serveCommand from "./commands/serve.js";
26
28
  import * as setupCommand from "./commands/setup.js";
27
29
  import * as studioCommand from "./commands/studio.js";
28
30
  import * as testCommand from "./commands/test.js";
29
- import * as testCommandEsm from "./commands/testEsm.js";
30
- import * as tstojsCommand from "./commands/ts-to-js.js";
31
31
  import * as typeCheckCommand from "./commands/type-check.js";
32
32
  import * as upgradeCommand from "./commands/upgrade/upgrade.js";
33
- import c from "./lib/colors.js";
34
33
  import { exitWithError } from "./lib/exit.js";
35
34
  import * as updateCheck from "./lib/updateCheck.js";
36
35
  import { loadPlugins } from "./plugin.js";
37
36
  import { startTelemetry, shutdownTelemetry } from "./telemetry/index.js";
38
- let { cwd, telemetry, help, version } = Parser(hideBin(process.argv), {
37
+ const {
38
+ telemetry,
39
+ help,
40
+ version,
41
+ cwd: parsedCwd
42
+ } = Parser(hideBin(process.argv), {
39
43
  // Telemetry is enabled by default, but can be disabled in two ways
40
44
  // - by passing a `--telemetry false` option
41
- // - by setting a `REDWOOD_DISABLE_TELEMETRY` env var
45
+ // - by setting a `CEDAR_DISABLE_TELEMETRY` env var
42
46
  boolean: ["telemetry"],
43
47
  default: {
44
- telemetry: process.env.REDWOOD_DISABLE_TELEMETRY === void 0 || process.env.REDWOOD_DISABLE_TELEMETRY === ""
48
+ telemetry: (process.env.CEDAR_DISABLE_TELEMETRY === void 0 || process.env.CEDAR_DISABLE_TELEMETRY === "") && (process.env.REDWOOD_DISABLE_TELEMETRY === void 0 || process.env.REDWOOD_DISABLE_TELEMETRY === "")
45
49
  }
46
50
  });
51
+ let cwd = parsedCwd;
47
52
  cwd ??= process.env.CEDAR_CWD;
48
53
  cwd ??= process.env.RWJS_CWD;
49
54
  cwd = getTomlDir(cwd);
50
55
  process.env.CEDAR_CWD = cwd;
51
- process.env.RWJS_CWD = cwd;
52
56
  if (process.argv[1]?.endsWith("redwood.js")) {
53
57
  const tomlPath = getConfigPath(cwd);
54
58
  const toml = fs.readFileSync(tomlPath, "utf8");
@@ -127,7 +131,7 @@ async function runYargs() {
127
131
  }).example(
128
132
  "yarn cedar g page home /",
129
133
  "Create a page component named 'Home' at path '/'"
130
- ).demandCommand().strict().exitProcess(false).alias("h", "help").command(buildCommand).command(checkCommand).command(consoleCommand).command(deployCommand).command(destroyCommand).command(devCommand).command(execCommand).command(experimentalCommand).command(generateCommand).command(infoCommand).command(jobsCommand).command(lintCommand).command(prerenderCommand).command(prismaCommand).command(recordCommand).command(serveCommand).command(setupCommand).command(studioCommand).command(projectIsEsm() ? testCommandEsm : testCommand).command(tstojsCommand).command(typeCheckCommand).command(upgradeCommand);
134
+ ).demandCommand().strict().exitProcess(false).alias("h", "help").command(buildCommand).command(checkCommand).command(consoleCommand).command(deployCommand).command(destroyCommand).command(devCommand).command(execCommand).command(experimentalCommand).command(generateCommand).command(infoCommand).command(jobsCommand).command(lintCommand).command(prerenderCommand).command(prismaCommand).command(recordCommand).command(serveCommand).command(setupCommand).command(studioCommand).command(testCommand).command(typeCheckCommand).command(upgradeCommand);
131
135
  await loadPlugins(yarg);
132
136
  const pkgJson = await import("../package.json", { with: { type: "json" } });
133
137
  yarg.version(pkgJson.default["version"]);
@@ -166,7 +170,7 @@ function getTomlDir(cwd2) {
166
170
  tomlDir = path.dirname(configTomlPath);
167
171
  }
168
172
  } catch (error) {
169
- console.error(error.message);
173
+ console.error(error instanceof Error ? error.message : String(error));
170
174
  process.exit(1);
171
175
  }
172
176
  return tomlDir;
@@ -3,6 +3,23 @@ import fs from "node:fs";
3
3
  import os from "os";
4
4
  import path from "path";
5
5
  import { getPaths } from "@cedarjs/project-config";
6
+ function quoteForWindowsShell(arg) {
7
+ let quoted = '"';
8
+ let backslashes = 0;
9
+ for (const char of arg) {
10
+ if (char === "\\") {
11
+ backslashes += 1;
12
+ continue;
13
+ }
14
+ if (char === '"') {
15
+ quoted += "\\".repeat(backslashes * 2 + 1) + '"';
16
+ } else {
17
+ quoted += "\\".repeat(backslashes) + char;
18
+ }
19
+ backslashes = 0;
20
+ }
21
+ return quoted + "\\".repeat(backslashes * 2) + '"';
22
+ }
6
23
  function spawnBackgroundProcess(name, cmd, args) {
7
24
  const logDirectory = path.join(getPaths().generated.base, "logs");
8
25
  fs.mkdirSync(logDirectory, { recursive: true });
@@ -37,7 +54,8 @@ function spawnBackgroundProcess(name, cmd, args) {
37
54
  shell: true,
38
55
  stdio: ["ignore", stdout, stderr]
39
56
  };
40
- const child = spawn(cmd + " " + args.join(" "), spawnOptions);
57
+ const command = [cmd, ...args].map(quoteForWindowsShell).join(" ");
58
+ const child = spawn(command, spawnOptions);
41
59
  child.unref();
42
60
  } else {
43
61
  const spawnOptions = {
@@ -47,7 +65,10 @@ function spawnBackgroundProcess(name, cmd, args) {
47
65
  const child = spawn(cmd, args, spawnOptions);
48
66
  child.unref();
49
67
  }
68
+ fs.closeSync(stdout);
69
+ fs.closeSync(stderr);
50
70
  }
51
71
  export {
72
+ quoteForWindowsShell,
52
73
  spawnBackgroundProcess
53
74
  };
@@ -10,11 +10,11 @@ import {
10
10
  } from "./merge/strategy.js";
11
11
  import { isTypeScriptProject } from "./project.js";
12
12
  import { getPaths, transformTSToJS, writeFile } from "./index.js";
13
- async function extendStorybookConfiguration(newConfigPath = void 0) {
13
+ async function extendStorybookConfiguration(newConfigPath) {
14
14
  const webPaths = getPaths().web;
15
15
  const ts = isTypeScriptProject();
16
16
  const sbPreviewConfigPath = webPaths.storybookPreviewConfig ?? `${webPaths.storybook}/preview.${ts ? "tsx" : "js"}`;
17
- const read = (path2) => fse.readFileSync(path2, { encoding: "utf-8" });
17
+ const read = (filePath) => fse.readFileSync(filePath, { encoding: "utf-8" });
18
18
  if (!fse.existsSync(sbPreviewConfigPath)) {
19
19
  const templateContent = read(
20
20
  path.resolve(
package/dist/lib/exec.js CHANGED
@@ -1,17 +1,38 @@
1
+ import { existsSync, statSync } from "node:fs";
1
2
  import path from "node:path";
2
- import { createServer, version as viteVersion } from "vite";
3
- import { ViteNodeRunner } from "vite-node/client";
4
- import { ViteNodeServer } from "vite-node/server";
5
- import { installSourcemapsSupport } from "vite-node/source-map";
3
+ import { createServer, isRunnableDevEnvironment } from "vite";
6
4
  import { getPaths, importStatementPath } from "@cedarjs/project-config";
7
5
  import {
8
6
  cedarCellTransform,
9
- cedarjsDirectoryNamedImportPlugin,
7
+ cedarjsResolveCedarStyleImportsPlugin,
10
8
  cedarjsJobPathInjectorPlugin,
11
9
  cedarSwapApolloProvider,
12
10
  cedarImportDirPlugin,
13
- cedarAutoImportsPlugin
11
+ cedarAutoImportsPlugin,
12
+ cedarCjsCompatPlugin
14
13
  } from "@cedarjs/vite";
14
+ function resolveId(id) {
15
+ if (existsSync(id) && statSync(id).isFile()) {
16
+ return id;
17
+ }
18
+ const withoutExt = /\.jsx?$/.test(id) ? id.replace(/\.jsx?$/, "") : id;
19
+ for (const ext of [".ts", ".tsx", ".js", ".jsx"]) {
20
+ if (existsSync(withoutExt + ext)) {
21
+ return withoutExt + ext;
22
+ }
23
+ }
24
+ if (existsSync(id) && statSync(id).isDirectory()) {
25
+ for (const base of ["index", path.basename(id)]) {
26
+ for (const ext of [".ts", ".tsx", ".js", ".jsx"]) {
27
+ const candidate = path.join(id, base + ext);
28
+ if (existsSync(candidate)) {
29
+ return candidate;
30
+ }
31
+ }
32
+ }
33
+ }
34
+ return id;
35
+ }
15
36
  async function runScriptFunction({
16
37
  path: scriptPath,
17
38
  functionName,
@@ -22,24 +43,27 @@ async function runScriptFunction({
22
43
  const server = await createServer({
23
44
  mode: "production",
24
45
  optimizeDeps: {
25
- // This is recommended in the vite-node readme
26
46
  noDiscovery: true,
27
47
  include: void 0
28
48
  },
49
+ server: {
50
+ hmr: false,
51
+ watch: null
52
+ },
53
+ environments: {
54
+ nodeRunnerEnv: {}
55
+ },
29
56
  resolve: {
57
+ // `$api/` and `api/` imports are handled by
58
+ // cedarjsResolveCedarStyleImportsPlugin below, which also resolves
59
+ // Cedar's directory named modules (`$api/src/services/posts` ->
60
+ // posts/posts.ts) and leaves an actual `api` npm package alone. The web
61
+ // side equivalents have no plugin support, so they stay aliases
30
62
  alias: [
31
- {
32
- find: /^\$api\//,
33
- replacement: getPaths().api.base + "/"
34
- },
35
63
  {
36
64
  find: /^\$web\//,
37
65
  replacement: getPaths().web.base + "/"
38
66
  },
39
- {
40
- find: /^api\//,
41
- replacement: getPaths().api.base + "/"
42
- },
43
67
  {
44
68
  find: /^web\//,
45
69
  replacement: getPaths().web.base + "/"
@@ -50,20 +74,14 @@ async function runScriptFunction({
50
74
  customResolver: (id, importer, _options) => {
51
75
  const apiImportBase = importStatementPath(getPaths().api.base);
52
76
  const webImportBase = importStatementPath(getPaths().web.base);
53
- if (importer.startsWith(apiImportBase)) {
77
+ if (importer?.startsWith(apiImportBase)) {
54
78
  const apiImportSrc = importStatementPath(getPaths().api.src);
55
- let resolvedId = id.replace("src", apiImportSrc);
56
- if (importer.endsWith(".ts") || importer.endsWith(".tsx")) {
57
- resolvedId = resolvedId.replace(/\.jsx?$/, "");
58
- }
59
- return { id: resolvedId };
60
- } else if (importer.startsWith(webImportBase)) {
79
+ const apiId = id.replace("src", apiImportSrc);
80
+ return { id: resolveId(apiId) };
81
+ } else if (importer?.startsWith(webImportBase)) {
61
82
  const webImportSrc = importStatementPath(getPaths().web.src);
62
- let resolvedId = id.replace("src", webImportSrc);
63
- if (importer.endsWith(".ts") || importer.endsWith(".tsx")) {
64
- resolvedId = resolvedId.replace(/\.jsx?$/, "");
65
- }
66
- return { id: resolvedId };
83
+ const webId = id.replace("src", webImportSrc);
84
+ return { id: resolveId(webId) };
67
85
  }
68
86
  return null;
69
87
  }
@@ -71,7 +89,8 @@ async function runScriptFunction({
71
89
  ]
72
90
  },
73
91
  plugins: [
74
- cedarjsDirectoryNamedImportPlugin(),
92
+ cedarCjsCompatPlugin(),
93
+ cedarjsResolveCedarStyleImportsPlugin(),
75
94
  cedarCellTransform(),
76
95
  cedarjsJobPathInjectorPlugin(),
77
96
  cedarSwapApolloProvider(),
@@ -79,47 +98,33 @@ async function runScriptFunction({
79
98
  cedarAutoImportsPlugin()
80
99
  ]
81
100
  });
82
- if (Number(viteVersion.split(".")[0]) < 6) {
83
- await server.pluginContainer.buildStart({});
101
+ const env = server.environments.nodeRunnerEnv;
102
+ if (!env || !isRunnableDevEnvironment(env)) {
103
+ await server.close();
104
+ throw new Error("Vite environment is not runnable.");
84
105
  }
85
- const node = new ViteNodeServer(server, {
86
- transformMode: {
87
- ssr: [/.*/],
88
- web: [/\/web\//]
89
- },
90
- deps: {
91
- fallbackCJS: true
92
- }
93
- });
94
- installSourcemapsSupport({
95
- getSourceMap: (source) => node.getSourceMap(source)
96
- });
97
- const runner = new ViteNodeRunner({
98
- root: server.config.root,
99
- base: server.config.base,
100
- fetchModule(id) {
101
- return node.fetchModule(id);
102
- },
103
- resolveId(id, importer) {
104
- return node.resolveId(id, importer);
105
- }
106
- });
107
106
  let returnValue;
108
107
  try {
109
- const script = await runner.executeFile(scriptPath);
110
- returnValue = script[functionName](args);
111
- } catch (error) {
112
- console.error(error);
113
- }
114
- try {
115
- const { db } = await runner.executeFile(path.join(getPaths().api.lib, "db"));
116
- db.$disconnect();
117
- } catch (e) {
108
+ const module = await env.runner.import(scriptPath);
109
+ const fn = module[functionName];
110
+ if (typeof fn !== "function") {
111
+ throw new Error(`Function '${functionName}' not found in script`);
112
+ }
113
+ returnValue = await fn(args);
114
+ } finally {
115
+ try {
116
+ const dbModule = await env.runner.import(
117
+ path.join(getPaths().api.lib, "db")
118
+ );
119
+ dbModule.db?.$disconnect?.();
120
+ } catch {
121
+ }
122
+ await server.close();
123
+ process.env.NODE_ENV = NODE_ENV;
118
124
  }
119
- await server.close();
120
- process.env.NODE_ENV = NODE_ENV;
121
125
  return returnValue;
122
126
  }
123
127
  export {
128
+ resolveId,
124
129
  runScriptFunction
125
130
  };
package/dist/lib/exit.js CHANGED
@@ -4,7 +4,7 @@ import { v4 as uuidv4 } from "uuid";
4
4
  import {
5
5
  recordTelemetryAttributes,
6
6
  recordTelemetryError
7
- } from "@cedarjs/cli-helpers";
7
+ } from "@cedarjs/cli-helpers/telemetry";
8
8
  const discordLink = terminalLink("Discord", "https://cedarjs.com/discord");
9
9
  const githubLink = terminalLink("GitHub", "https://github.com/cedarjs/cedar");
10
10
  const DEFAULT_ERROR_EPILOGUE = [
@@ -12,12 +12,27 @@ const DEFAULT_ERROR_EPILOGUE = [
12
12
  ` - Not sure about something or need advice? Reach out on our ${discordLink}`,
13
13
  ` - Think you've found a bug? Open an issue on our ${githubLink}`
14
14
  ].join("\n");
15
- function exitWithError(error, { exitCode, message, epilogue, includeEpilogue, includeReferenceCode } = {}) {
16
- exitCode ??= error?.exitCode ?? 1;
15
+ function exitWithError(error, {
16
+ exitCode,
17
+ message,
18
+ epilogue,
19
+ includeEpilogue,
20
+ includeReferenceCode
21
+ } = {}) {
22
+ if (error && typeof error === "object" && "exitCode" in error) {
23
+ exitCode ??= typeof error.exitCode === "number" ? error.exitCode : 1;
24
+ }
25
+ exitCode ??= 1;
17
26
  epilogue ??= DEFAULT_ERROR_EPILOGUE;
18
27
  includeEpilogue ??= true;
19
28
  includeReferenceCode ??= true;
20
- message ??= error.stack ?? (error.toString() || "Unknown error");
29
+ if (message === void 0) {
30
+ if (error instanceof Error && error.stack) {
31
+ message = error.stack;
32
+ } else {
33
+ message = String(error) || "Unknown error";
34
+ }
35
+ }
21
36
  const errorReferenceCode = uuidv4();
22
37
  const line = ansis.red("-".repeat(process.stderr.columns - 4));
23
38
  const content = !includeEpilogue ? message : [
@@ -31,7 +46,7 @@ ${line}`,
31
46
  line
32
47
  ].filter(Boolean).join("\n");
33
48
  console.error(content);
34
- recordTelemetryError(error ?? new Error(message));
49
+ recordTelemetryError(error ?? new Error(message ?? ""));
35
50
  recordTelemetryAttributes({ errorReferenceCode });
36
51
  process.exit(exitCode);
37
52
  }