@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
@@ -8,9 +8,6 @@ import { forEachFunctionOn, nodeIs } from "./algorithms.js";
8
8
  import { semanticIdentity } from "./semanticIdentity.js";
9
9
  import { isOpaque } from "./strategy.js";
10
10
  function extractProperty(property, fromObject) {
11
- if (property === void 0) {
12
- return void 0;
13
- }
14
11
  const tmp = fromObject[property];
15
12
  delete fromObject[property];
16
13
  return tmp;
@@ -29,7 +26,7 @@ function getProgramPath(ast) {
29
26
  return programPath;
30
27
  }
31
28
  function skipChildren(path) {
32
- for (const key of VISITOR_KEYS[path.type]) {
29
+ for (const key of VISITOR_KEYS[path.type] ?? []) {
33
30
  path.skipKey(key);
34
31
  }
35
32
  }
@@ -46,6 +43,7 @@ function makeProxy(path) {
46
43
  if (property === "path") {
47
44
  throw new Error("You can't set a path on a proxy!");
48
45
  } else {
46
+ ;
49
47
  target.node[property] = value;
50
48
  return true;
51
49
  }
@@ -59,7 +57,7 @@ function expressionUses(exp, ...ids) {
59
57
  let result = false;
60
58
  exp.traverse({
61
59
  Identifier(path) {
62
- if (!path.parentPath.isNodeType("VariableDeclarator") && ids.includes(path.node.name)) {
60
+ if (!path.parentPath?.isNodeType("VariableDeclarator") && ids.includes(path.node.name)) {
63
61
  result = true;
64
62
  return;
65
63
  }
@@ -69,22 +67,37 @@ function expressionUses(exp, ...ids) {
69
67
  }
70
68
  function insertBeforeFirstUsage(expression, program) {
71
69
  const body = program.get("body");
72
- const pos = body.findIndex(
73
- (exp) => expressionUses(exp, ...Object.keys(expression.getBindingIdentifiers()))
70
+ const bindingIds = Object.keys(
71
+ expression.getBindingIdentifiers()
74
72
  );
75
- return pos !== -1 ? body[pos].insertBefore(expression.node) : program.pushContainer("body", expression.node);
73
+ const pos = body.findIndex((exp) => expressionUses(exp, ...bindingIds));
74
+ if (pos !== -1) {
75
+ return body[pos].insertBefore(expression.node);
76
+ } else {
77
+ return program.pushContainer("body", expression.node);
78
+ }
76
79
  }
77
80
  function insertAfterLastImport(expression, program) {
78
81
  const body = program.get("body");
79
- return body[body.findLastIndex((bodyExpr) => bodyExpr.isNodeType("ImportDeclaration"))].insertAfter(expression.node);
82
+ let lastImportIdx = -1;
83
+ for (let i = 0; i < body.length; i++) {
84
+ if (body[i].isNodeType("ImportDeclaration")) {
85
+ lastImportIdx = i;
86
+ }
87
+ }
88
+ return body[lastImportIdx].insertAfter(expression.node);
80
89
  }
81
90
  function prune(path) {
82
- switch (path.parentPath.type) {
91
+ switch (path.parentPath?.type) {
92
+ // If pruning 'path' would yield an ill-formed parent (e.g, '{foo:}' or 'const x;'), prune it.
83
93
  case "ObjectProperty":
84
94
  case "VariableDeclarator":
85
95
  return path.parentPath.remove();
86
96
  default:
87
- console.log(`Warning: default prune strategy for ${path.parentPath.type}`);
97
+ console.log(
98
+ `Warning: default prune strategy for ${path.parentPath?.type}`
99
+ );
100
+ // eslint-disable-next-line no-fallthrough
88
101
  case "Program":
89
102
  case "ArrayExpression":
90
103
  return path.remove();
@@ -93,6 +106,7 @@ function prune(path) {
93
106
  function stripTrailingCommentsStrategy() {
94
107
  return {
95
108
  enter(path) {
109
+ ;
96
110
  path.node.trailingComments = [];
97
111
  }
98
112
  };
@@ -102,48 +116,71 @@ function mergeAST(baseAST, extAST, strategy = {}) {
102
116
  const identities = {};
103
117
  const baseVisitor = { ...stripTrailingCommentsStrategy() };
104
118
  const extVisitor = { ...stripTrailingCommentsStrategy() };
105
- forEachFunctionOn(strategy, (typename, strat) => {
106
- extVisitor[typename] = {
107
- enter(path) {
108
- const id = identity(path);
109
- id && (identities[id] ||= []).push(path);
110
- }
111
- };
112
- baseVisitor[typename] = {
113
- enter(path) {
114
- if (isOpaque(strat)) {
115
- skipChildren(path);
119
+ forEachFunctionOn(
120
+ strategy,
121
+ (typename, strat) => {
122
+ extVisitor[typename] = {
123
+ enter(path) {
124
+ const id = identity(path);
125
+ if (id) {
126
+ ;
127
+ (identities[id] ||= []).push(path);
128
+ }
116
129
  }
117
- },
118
- exit(path) {
119
- const exts = extractProperty(identity(path), identities);
120
- if (exts) {
121
- const proxyPath = makeProxy(path);
122
- exts.map(makeProxy).forEach((ext) => {
123
- strat(proxyPath, ext);
124
- prune(ext.path);
125
- });
130
+ };
131
+ baseVisitor[typename] = {
132
+ enter(path) {
133
+ if (isOpaque(strat)) {
134
+ skipChildren(path);
135
+ }
136
+ },
137
+ exit(path) {
138
+ const exts = extractProperty(identity(path), identities);
139
+ if (exts) {
140
+ const proxyPath = makeProxy(path);
141
+ exts.map(makeProxy).forEach((ext) => {
142
+ ;
143
+ strat(proxyPath, ext);
144
+ prune(ext.path);
145
+ });
146
+ }
126
147
  }
127
- }
128
- };
129
- });
130
- traverse(extAST, extVisitor);
131
- traverse(baseAST, baseVisitor);
148
+ };
149
+ }
150
+ );
151
+ traverse(
152
+ extAST,
153
+ extVisitor
154
+ );
155
+ traverse(
156
+ baseAST,
157
+ baseVisitor
158
+ );
132
159
  const baseProgram = getProgramPath(baseAST);
160
+ const body = getProgramPath(extAST).get("body");
133
161
  const [imports, others] = partition(
134
- getProgramPath(extAST).get("body"),
135
- nodeIs("ImportDeclaration")
162
+ body,
163
+ // nodeIs returns (node: Node) => boolean; here we have NodePaths, so we
164
+ // check path.node to stay type-safe.
165
+ (path) => nodeIs("ImportDeclaration")(path.node)
136
166
  );
137
167
  imports.forEach((exp) => insertAfterLastImport(exp, baseProgram));
138
- forEachRight(others, (exp) => insertBeforeFirstUsage(exp, baseProgram));
168
+ forEachRight(
169
+ others,
170
+ (exp) => insertBeforeFirstUsage(exp, baseProgram)
171
+ );
139
172
  }
140
173
  async function merge(base, extension, strategy) {
141
174
  function parseReact(code2) {
142
- return parse(code2, {
143
- filename: "merged.tsx",
175
+ const result = parse(code2, {
144
176
  // required to prevent babel error. The .tsx is relevant
177
+ filename: "merged.tsx",
145
178
  presets: ["@babel/preset-typescript"]
146
179
  });
180
+ if (result === null) {
181
+ throw new Error("Failed to parse code");
182
+ }
183
+ return result;
147
184
  }
148
185
  const baseAST = parseReact(base);
149
186
  const extAST = parseReact(extension);
@@ -1,14 +1,26 @@
1
1
  function semanticIdentity(path) {
2
2
  const identity = {
3
- get(path2) {
4
- return path2.type in this ? this[path2.type](path2) : [path2.type];
3
+ get(p) {
4
+ return p.type in this ? this[p.type](p) : [p.type ?? "unknown"];
5
5
  },
6
- ObjectProperty: (path2) => [path2.node.key.name],
7
- VariableDeclarator: (path2) => [path2.node.id.name],
8
- ImportDeclaration: (path2) => [
6
+ ObjectProperty: (p) => {
7
+ const key = p.node.key;
8
+ if (key.type !== "Identifier") {
9
+ return [p.type];
10
+ }
11
+ return [key.name];
12
+ },
13
+ VariableDeclarator: (p) => {
14
+ const id = p.node.id;
15
+ if (id.type !== "Identifier") {
16
+ return [p.type];
17
+ }
18
+ return [id.name];
19
+ },
20
+ ImportDeclaration: (p) => [
9
21
  "ImportDeclaration",
10
22
  "source",
11
- path2.node.source.value
23
+ p.node.source.value
12
24
  ]
13
25
  };
14
26
  return path.getAncestry().reduce((acc, i) => [...identity.get(i), ...acc], []).join(".");
@@ -1,7 +1,7 @@
1
1
  import * as t from "@babel/types";
2
2
  import uniqWith from "lodash/uniqWith.js";
3
3
  import { nodeIs, sieve } from "./algorithms.js";
4
- const OPAQUE_UID_TAG = "RW_MERGE_OPAQUE_UID_Q2xldmVyIHlvdSEgSGF2ZSBhIGNvb2tpZS4=";
4
+ const OPAQUE_UID_TAG = "CEDAR_MERGE_OPAQUE_UID_Q2xldmVyIHlvdSEgSGF2ZSBhIGNvb2tpZS4=";
5
5
  function requireSameType(base, ext) {
6
6
  if (base.path.type !== ext.path.type) {
7
7
  throw new Error(
@@ -17,9 +17,21 @@ function requireStrategyExists(base, _ext, strategy, strategyName) {
17
17
  }
18
18
  }
19
19
  const strictEquality = (lhs, rhs) => lhs === rhs;
20
- const byName = (lhs, rhs) => lhs.name === rhs.name;
21
- const byKeyName = (lhs, rhs) => lhs.key.name === rhs.key.name;
22
- const byValue = (lhs, rhs) => lhs.value === rhs.value;
20
+ function hasName(v) {
21
+ return typeof v === "object" && v !== null && "name" in v;
22
+ }
23
+ function hasKey(v) {
24
+ return typeof v === "object" && v !== null && "key" in v;
25
+ }
26
+ function hasKeyName(v) {
27
+ return hasKey(v) && hasName(v.key);
28
+ }
29
+ function hasValue(v) {
30
+ return typeof v === "object" && v !== null && "value" in v;
31
+ }
32
+ const byName = (lhs, rhs) => hasName(lhs) && hasName(rhs) && lhs.name === rhs.name;
33
+ const byKeyName = (lhs, rhs) => hasKeyName(lhs) && hasKeyName(rhs) && lhs.key.name === rhs.key.name;
34
+ const byValue = (lhs, rhs) => hasValue(lhs) && hasValue(rhs) && lhs.value === rhs.value;
23
35
  function defaultEquality(baseContainer, extContainer) {
24
36
  const sample = baseContainer.length && baseContainer[0] || extContainer.length && extContainer[0];
25
37
  const defaults = {
@@ -30,14 +42,13 @@ function defaultEquality(baseContainer, extContainer) {
30
42
  ObjectProperty: byKeyName,
31
43
  StringLiteral: byValue
32
44
  };
33
- return sample && sample.type in defaults ? defaults[sample.type] : strictEquality;
45
+ return sample && typeof sample === "object" && "type" in sample && typeof sample.type === "string" && sample.type in defaults ? defaults[sample.type] : strictEquality;
34
46
  }
35
- function opaquely(strategy) {
36
- strategy[OPAQUE_UID_TAG] = true;
37
- return strategy;
47
+ function opaquely(reducer) {
48
+ return Object.assign(reducer, { [OPAQUE_UID_TAG]: true });
38
49
  }
39
- function isOpaque(strategy) {
40
- return strategy[OPAQUE_UID_TAG] === true;
50
+ function isOpaque(fn) {
51
+ return OPAQUE_UID_TAG in fn && fn[OPAQUE_UID_TAG] === true;
41
52
  }
42
53
  const keepBase = opaquely(() => {
43
54
  });
@@ -47,20 +58,36 @@ const keepBoth = opaquely((base, ext) => {
47
58
  const keepExtension = opaquely((base, ext) => {
48
59
  base.path.replaceWith(ext.path);
49
60
  });
50
- const keepBothStatementParents = opaquely((base, ext) => {
51
- base.path.getStatementParent().insertAfter(ext.path.getStatementParent().node);
52
- });
61
+ const keepBothStatementParents = opaquely(
62
+ (base, ext) => {
63
+ const extParent = ext.path.getStatementParent();
64
+ if (extParent) {
65
+ base.path.getStatementParent()?.insertAfter(extParent.node);
66
+ }
67
+ }
68
+ );
53
69
  const interleaveStrategy = {
54
- ImportDeclaration(baseImport, extImport) {
55
- const baseSpecs = baseImport.specifiers;
56
- const extSpecs = extImport.specifiers;
57
- const importSpecifierEquality = (lhs, rhs) => lhs.type === rhs.type && lhs.imported?.name === rhs.imported?.name && lhs.local?.name == rhs.local?.name;
70
+ ImportDeclaration(base, ext) {
71
+ if (!t.isImportDeclaration(base) || !t.isImportDeclaration(ext)) {
72
+ return;
73
+ }
74
+ const baseSpecs = base.specifiers;
75
+ const extSpecs = ext.specifiers;
76
+ const importSpecifierEquality = (lhs, rhs) => {
77
+ if (lhs.type !== rhs.type) {
78
+ return false;
79
+ }
80
+ if (lhs.type === "ImportSpecifier" && rhs.type === "ImportSpecifier") {
81
+ return lhs.imported.type === "Identifier" && rhs.imported.type === "Identifier" && lhs.imported.name === rhs.imported.name && lhs.local?.name === rhs.local?.name;
82
+ }
83
+ return lhs.local?.name === rhs.local?.name;
84
+ };
58
85
  const uniqueSpecifiersOfType = (type) => uniqWith(
59
86
  [...baseSpecs, ...extSpecs].filter(nodeIs(type)),
60
87
  importSpecifierEquality
61
88
  );
62
89
  if (!baseSpecs.length !== !extSpecs.length) {
63
- return keepBothStatementParents(baseImport, extImport);
90
+ return keepBothStatementParents(base, ext);
64
91
  }
65
92
  const defaultPosition = (specs) => specs.some(nodeIs("ImportDefaultSpecifier")) ? -1 : 0;
66
93
  const namespacePosition = (specs) => specs.some(nodeIs("ImportNamespaceSpecifier")) || specs.some(nodeIs("ImportSpecifier")) ? -1 : specs.length;
@@ -70,10 +97,10 @@ const interleaveStrategy = {
70
97
  [uniqueSpecifiersOfType("ImportNamespaceSpecifier"), namespacePosition],
71
98
  [uniqueSpecifiersOfType("ImportSpecifier"), importPosition]
72
99
  );
73
- baseImport.specifiers = firstSpecifierList;
100
+ base.specifiers = firstSpecifierList;
74
101
  if (rest.length) {
75
- baseImport.path.insertAfter(
76
- rest.map((specs) => t.importDeclaration(specs, baseImport.source))
102
+ base.path.insertAfter(
103
+ rest.map((specs) => t.importDeclaration(specs, base.source))
77
104
  );
78
105
  }
79
106
  }
@@ -81,47 +108,70 @@ const interleaveStrategy = {
81
108
  function interleave(base, ext) {
82
109
  requireSameType(base, ext);
83
110
  requireStrategyExists(base, ext, interleaveStrategy, "interleave");
84
- return interleaveStrategy[base.path.type](base, ext);
111
+ interleaveStrategy[base.path.type]?.(base, ext);
85
112
  }
86
113
  const concatStrategy = {
87
114
  ArrayExpression(base, ext) {
115
+ if (!t.isArrayExpression(base) || !t.isArrayExpression(ext)) {
116
+ return;
117
+ }
88
118
  base.elements = [...base.elements, ...ext.elements];
89
119
  },
90
120
  ObjectExpression(base, ext) {
121
+ if (!t.isObjectExpression(base) || !t.isObjectExpression(ext)) {
122
+ return;
123
+ }
91
124
  base.properties = [...base.properties, ...ext.properties];
92
125
  },
93
126
  StringLiteral(base, ext) {
127
+ if (!t.isStringLiteral(base) || !t.isStringLiteral(ext)) {
128
+ return;
129
+ }
94
130
  base.value = base.value.concat(ext.value);
95
131
  }
96
132
  };
97
133
  function concat(base, ext) {
98
134
  requireSameType(base, ext);
99
135
  requireStrategyExists(base, ext, concatStrategy, "concat");
100
- return concatStrategy[base.path.type](base, ext);
136
+ concatStrategy[base.path.type]?.(base, ext);
101
137
  }
102
138
  const concatUniqueStrategy = {
103
139
  ArrayExpression(base, ext, eq) {
104
- eq ||= defaultEquality(base.elements, ext.elements);
105
- base.elements = uniqWith([...base.elements, ...ext.elements], eq);
140
+ if (!t.isArrayExpression(base) || !t.isArrayExpression(ext)) {
141
+ return;
142
+ }
143
+ const equalFn = eq ?? defaultEquality(base.elements, ext.elements);
144
+ base.elements = uniqWith([...base.elements, ...ext.elements], equalFn);
106
145
  },
107
146
  ObjectExpression(base, ext, eq) {
108
- eq ||= defaultEquality(base.properties, ext.properties);
109
- base.properties = uniqWith([...base.properties, ...ext.properties], eq);
147
+ if (!t.isObjectExpression(base) || !t.isObjectExpression(ext)) {
148
+ return;
149
+ }
150
+ const equalFn = eq ?? defaultEquality(base.properties, ext.properties);
151
+ base.properties = uniqWith([...base.properties, ...ext.properties], equalFn);
110
152
  }
111
153
  };
112
154
  function concatUnique(baseOrEq, ext) {
113
- if (arguments.length === 1) {
114
- return (base, ext2) => {
115
- requireSameType(base, ext2);
116
- requireStrategyExists(base, ext2, concatUniqueStrategy, "concatUnique");
117
- return concatUniqueStrategy[base.path.type](base, ext2, baseOrEq);
155
+ if (typeof baseOrEq === "function") {
156
+ const eq = baseOrEq;
157
+ return (base2, innerExt) => {
158
+ requireSameType(base2, innerExt);
159
+ requireStrategyExists(
160
+ base2,
161
+ innerExt,
162
+ concatUniqueStrategy,
163
+ "concatUnique"
164
+ );
165
+ concatUniqueStrategy[base2.path.type]?.(base2, innerExt, eq);
118
166
  };
119
167
  }
120
- if (arguments.length === 2) {
121
- requireSameType(baseOrEq, ext);
122
- requireStrategyExists(baseOrEq, ext, concatUniqueStrategy, "concatUnique");
123
- return concatUniqueStrategy[baseOrEq.path.type](baseOrEq, ext);
168
+ const base = baseOrEq;
169
+ if (!ext) {
170
+ return;
124
171
  }
172
+ requireSameType(base, ext);
173
+ requireStrategyExists(base, ext, concatUniqueStrategy, "concatUnique");
174
+ concatUniqueStrategy[base.path.type]?.(base, ext);
125
175
  }
126
176
  export {
127
177
  concat,
@@ -2,22 +2,26 @@ import fs from "node:fs";
2
2
  import { createRequire } from "node:module";
3
3
  import path from "node:path";
4
4
  import execa from "execa";
5
+ import { dedupe } from "@cedarjs/cli-helpers/packageManager";
6
+ import { addRootPackages } from "@cedarjs/cli-helpers/packageManager/packages";
7
+ import { getPackageManager } from "@cedarjs/project-config/packageManager";
5
8
  import { getPaths } from "./index.js";
6
9
  async function installModule(name, version = void 0) {
7
10
  if (isModuleInstalled(name)) {
8
11
  return false;
9
12
  }
10
13
  if (version === void 0) {
11
- return installRedwoodModule(name);
14
+ return installCedarModule(name);
12
15
  } else {
13
- await execa.command(`yarn add -D ${name}@${version}`, {
16
+ await addRootPackages([`${name}@${version}`], {
17
+ dev: true,
14
18
  stdio: "inherit",
15
19
  cwd: getPaths().base
16
20
  });
17
21
  }
18
22
  return true;
19
23
  }
20
- async function installRedwoodModule(module) {
24
+ async function installCedarModule(module) {
21
25
  const packageJson = await import("@cedarjs/cli/package.json", { with: { type: "json" } });
22
26
  let version = packageJson.default.version;
23
27
  if (!isModuleInstalled(module)) {
@@ -35,21 +39,27 @@ async function installRedwoodModule(module) {
35
39
  }
36
40
  } catch (error) {
37
41
  throw new Error(
38
- `Couldn't fetch packument for ${module}: ${error.message}`
42
+ `Couldn't fetch packument for ${module}: ${error instanceof Error ? error.message : String(error)}`
39
43
  );
40
44
  }
41
- const versionIsPublished = Object.keys(packument.versions).includes(version);
45
+ const versionIsPublished = Object.keys(packument.versions ?? {}).includes(
46
+ version
47
+ );
42
48
  if (!versionIsPublished) {
43
49
  version = "canary";
44
50
  }
45
- await execa.command(`yarn add -D ${module}@${version}`, {
46
- stdio: "inherit",
47
- cwd: getPaths().base
48
- });
49
- await execa.command(`yarn dedupe`, {
51
+ await addRootPackages([`${module}@${version}`], {
52
+ dev: true,
50
53
  stdio: "inherit",
51
54
  cwd: getPaths().base
52
55
  });
56
+ const dedupeCommand = dedupe();
57
+ if (dedupeCommand) {
58
+ await execa(getPackageManager(), [dedupeCommand], {
59
+ stdio: "inherit",
60
+ cwd: getPaths().base
61
+ });
62
+ }
53
63
  return true;
54
64
  }
55
65
  return false;
@@ -66,12 +76,12 @@ function isModuleInstalled(module) {
66
76
  return true;
67
77
  }
68
78
  const createdRequire = createRequire(import.meta.url);
69
- return createdRequire.resolve.paths(`${module}/package.json`).some((requireResolvePath) => {
79
+ return createdRequire.resolve.paths(`${module}/package.json`)?.some((requireResolvePath) => {
70
80
  return fs.existsSync(path.join(requireResolvePath, module));
71
- });
81
+ }) ?? false;
72
82
  }
73
83
  export {
84
+ installCedarModule,
74
85
  installModule,
75
- installRedwoodModule,
76
86
  isModuleInstalled
77
87
  };
@@ -2,7 +2,7 @@ import fs from "node:fs";
2
2
  import path from "path";
3
3
  import ansis from "ansis";
4
4
  import enquirer from "enquirer";
5
- import { getCompatibilityData } from "@cedarjs/cli-helpers";
5
+ import { getCompatibilityData } from "@cedarjs/cli-helpers/version";
6
6
  import { installModule, isModuleInstalled } from "./packages.js";
7
7
  import { getPaths } from "./index.js";
8
8
  const { Select } = enquirer;
@@ -45,22 +45,28 @@ const PLUGIN_CACHE_BUILTIN = [
45
45
  "serve",
46
46
  "setup",
47
47
  "test",
48
- "ts-to-js",
49
48
  "type-check",
50
49
  "tsc",
51
50
  "tc",
52
51
  "upgrade"
53
52
  ];
53
+ function isErrorWithCode(error, code) {
54
+ return typeof error === "object" && error !== null && "code" in error && error.code === code;
55
+ }
54
56
  function loadCommandCache() {
55
- let pluginCommandCache = PLUGIN_CACHE_DEFAULT;
57
+ let pluginCommandCache = { ...PLUGIN_CACHE_DEFAULT };
56
58
  const commandCachePath = path.join(
57
59
  getPaths().generated.base,
58
60
  PLUGIN_CACHE_FILENAME
59
61
  );
60
62
  try {
61
- const localCommandCache = JSON.parse(fs.readFileSync(commandCachePath));
63
+ const localCommandCache = JSON.parse(
64
+ fs.readFileSync(commandCachePath, "utf8")
65
+ );
62
66
  let valid = true;
63
- for (const [key, value] of Object.entries(localCommandCache)) {
67
+ for (const [key, value] of Object.entries(
68
+ localCommandCache
69
+ )) {
64
70
  if (key === "_builtin") {
65
71
  continue;
66
72
  }
@@ -73,7 +79,7 @@ function loadCommandCache() {
73
79
  };
74
80
  }
75
81
  } catch (error) {
76
- if (error.code !== "ENOENT") {
82
+ if (!isErrorWithCode(error, "ENOENT")) {
77
83
  console.error(`Error loading plugin command cache at ${commandCachePath}`);
78
84
  console.error(error);
79
85
  }
@@ -162,7 +168,7 @@ async function installPluginPackage(packageName, packageVersion) {
162
168
  console.log(
163
169
  "The following error occurred while checking plugin compatibility for automatic installation:"
164
170
  );
165
- const errorMessage = error.message ?? error;
171
+ const errorMessage = error instanceof Error ? error.message : String(error);
166
172
  console.log(errorMessage);
167
173
  if (errorMessage.includes("does not have a tag") || errorMessage.includes("does not have a version")) {
168
174
  process.exit(1);
@@ -1,5 +1,9 @@
1
1
  import prompts from "prompts";
2
- import { isSingular, isPlural, addSingularPlural } from "./cedarPluralize.js";
2
+ import {
3
+ isSingular,
4
+ isPlural,
5
+ addSingularPlural
6
+ } from "@cedarjs/utils/cedarPluralize";
3
7
  const isWordPluralizable = (word) => {
4
8
  return isPlural(word) !== isSingular(word);
5
9
  };
@@ -29,7 +33,7 @@ To continue, the generator requires a unique plural form:`;
29
33
  const destroyMessage = `Cannot determine the plural of "${model}" originally used to generate the files.
30
34
  To continue, the destroy command requires the plural form:`;
31
35
  const promptMessage = isDestroyer ? destroyMessage : generateMessage;
32
- const initialPlural = model.slice(-1) === "s" ? `${model}es` : `${model}s`;
36
+ const initialPlural = model.endsWith("s") ? `${model}es` : `${model}s`;
33
37
  const promptResult = await prompts({
34
38
  type: "text",
35
39
  name: "plural",
@@ -5,7 +5,9 @@ const isTypeScriptProject = () => {
5
5
  const paths = getPaths();
6
6
  return fs.existsSync(path.join(paths.web.base, "tsconfig.json")) || fs.existsSync(path.join(paths.api.base, "tsconfig.json"));
7
7
  };
8
- function workspaces({ includePackages = false } = {}) {
8
+ function workspaces({
9
+ includePackages = false
10
+ } = {}) {
9
11
  const cedarPaths = getPaths();
10
12
  let workspaces2 = [];
11
13
  if (fs.existsSync(path.join(cedarPaths.web.base, "package.json"))) {
@@ -1,6 +1,6 @@
1
1
  import fs from "node:fs";
2
2
  import path from "path";
3
- let rollback = [];
3
+ const rollback = [];
4
4
  function addFunctionToRollback(func, atEnd = false) {
5
5
  const step = { type: "func", func };
6
6
  if (atEnd) {
@@ -9,11 +9,11 @@ function addFunctionToRollback(func, atEnd = false) {
9
9
  rollback.push(step);
10
10
  }
11
11
  }
12
- function addFileToRollback(path2, atEnd = false) {
12
+ function addFileToRollback(filePath, atEnd = false) {
13
13
  const step = {
14
14
  type: "file",
15
- path: path2,
16
- content: fs.existsSync(path2) ? fs.readFileSync(path2) : null
15
+ path: filePath,
16
+ content: fs.existsSync(filePath) ? fs.readFileSync(filePath) : null
17
17
  };
18
18
  if (atEnd) {
19
19
  rollback.unshift(step);
@@ -21,7 +21,7 @@ function addFileToRollback(path2, atEnd = false) {
21
21
  rollback.push(step);
22
22
  }
23
23
  }
24
- async function executeRollback(_ = null, task = null) {
24
+ const executeRollback = async (_, task) => {
25
25
  if (task) {
26
26
  task.title = "Reverting generator actions...";
27
27
  }
@@ -51,9 +51,9 @@ async function executeRollback(_ = null, task = null) {
51
51
  }
52
52
  }
53
53
  if (task) {
54
- task.title = `Reverted because: ${task.task.message.error}`;
54
+ task.title = `Reverted because: ${task.task.message?.error ?? "unknown error"}`;
55
55
  }
56
- }
56
+ };
57
57
  function resetRollback() {
58
58
  rollback.length = 0;
59
59
  }