@cedarjs/cli 4.2.1-next.0 → 4.2.1-next.258

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 (153) hide show
  1. package/dist/cfw.js +8 -6
  2. package/dist/commands/build/buildHandler.js +43 -42
  3. package/dist/commands/build/buildPackagesTask.js +6 -6
  4. package/dist/commands/build.js +7 -1
  5. package/dist/commands/deploy/baremetal/SshExecutor.js +13 -4
  6. package/dist/commands/deploy/baremetal/baremetalHandler.js +117 -65
  7. package/dist/commands/deploy/baremetal.js +24 -3
  8. package/dist/commands/deploy/flightcontrolHandler.js +16 -14
  9. package/dist/commands/deploy/helpers/deployHandler.js +10 -5
  10. package/dist/commands/deploy/packing/nft.js +1 -2
  11. package/dist/commands/deploy/render.js +1 -1
  12. package/dist/commands/deploy/renderHandler.js +22 -12
  13. package/dist/commands/deploy/serverlessHandler.js +67 -25
  14. package/dist/commands/destroy/component/component.js +2 -3
  15. package/dist/commands/destroy/directive/directive.js +1 -3
  16. package/dist/commands/destroy/directive/directiveHandler.js +2 -4
  17. package/dist/commands/destroy/function/function.js +1 -3
  18. package/dist/commands/destroy/handlerHelpers.js +16 -16
  19. package/dist/commands/destroy/helpers.js +8 -2
  20. package/dist/commands/destroy/layout/layout.js +1 -2
  21. package/dist/commands/destroy/page/pageHandler.js +1 -1
  22. package/dist/commands/destroy/scaffold/scaffoldHandler.js +28 -9
  23. package/dist/commands/destroy/sdl/sdlHandler.js +1 -1
  24. package/dist/commands/dev/devHandler.js +25 -25
  25. package/dist/commands/dev.js +3 -0
  26. package/dist/commands/experimental/live-queries/liveQueriesHandler.js +110 -4
  27. package/dist/commands/experimental/setupInngest.js +1 -1
  28. package/dist/commands/experimental/setupInngestHandler.js +12 -11
  29. package/dist/commands/experimental/setupOpentelemetry.js +1 -1
  30. package/dist/commands/experimental/setupOpentelemetryHandler.js +11 -7
  31. package/dist/commands/experimental/setupReactCompiler.js +1 -1
  32. package/dist/commands/experimental/setupReactCompilerHandler.js +45 -30
  33. package/dist/commands/experimental/setupRscHandler.js +14 -11
  34. package/dist/commands/experimental/setupStreamingSsr.js +1 -1
  35. package/dist/commands/experimental/setupStreamingSsrHandler.js +46 -31
  36. package/dist/commands/experimental/templates/rsc/Document.tsx.template +1 -1
  37. package/dist/commands/experimental/templates/rsc/entry.client.tsx.template +8 -8
  38. package/dist/commands/experimental/templates/streamingSsr/Document.tsx.template +1 -1
  39. package/dist/commands/experimental/templates/streamingSsr/entry.client.tsx.template +6 -6
  40. package/dist/commands/experimental/util.js +3 -2
  41. package/dist/commands/generate/cell/cellHandler.js +22 -21
  42. package/dist/commands/generate/component/componentHandler.js +14 -16
  43. package/dist/commands/generate/dataMigration/dataMigration.js +24 -13
  44. package/dist/commands/generate/dbAuth/dbAuth.js +1 -0
  45. package/dist/commands/generate/dbAuth/dbAuthHandler.js +40 -30
  46. package/dist/commands/generate/directive/directiveHandler.js +12 -14
  47. package/dist/commands/generate/function/function.js +1 -0
  48. package/dist/commands/generate/function/functionHandler.js +12 -17
  49. package/dist/commands/generate/helpers.js +17 -17
  50. package/dist/commands/generate/job/job.js +1 -0
  51. package/dist/commands/generate/job/jobHandler.js +15 -17
  52. package/dist/commands/generate/layout/layoutHandler.js +13 -16
  53. package/dist/commands/generate/model/model.js +1 -0
  54. package/dist/commands/generate/model/modelHandler.js +9 -3
  55. package/dist/commands/generate/ogImage/ogImage.js +1 -0
  56. package/dist/commands/generate/ogImage/ogImageHandler.js +16 -9
  57. package/dist/commands/generate/package/packageHandler.js +32 -49
  58. package/dist/commands/generate/page/pageHandler.js +25 -22
  59. package/dist/commands/generate/realtime/realtime.js +1 -1
  60. package/dist/commands/generate/realtime/realtimeHandler.js +46 -20
  61. package/dist/commands/generate/scaffold/scaffold.js +1 -0
  62. package/dist/commands/generate/scaffold/scaffoldHandler.js +35 -27
  63. package/dist/commands/generate/script/script.js +1 -0
  64. package/dist/commands/generate/script/templates/tsconfig.json.template +14 -0
  65. package/dist/commands/generate/sdl/sdl.js +4 -3
  66. package/dist/commands/generate/sdl/sdlHandler.js +38 -18
  67. package/dist/commands/generate/secret/secret.js +19 -19
  68. package/dist/commands/generate/service/service.js +5 -5
  69. package/dist/commands/generate/service/serviceHandler.js +59 -22
  70. package/dist/commands/generate/yargsCommandHelpers.js +6 -1
  71. package/dist/commands/generate/yargsHandlerHelpers.js +18 -10
  72. package/dist/commands/generate.js +3 -10
  73. package/dist/commands/jobsHandler.js +3 -2
  74. package/dist/commands/prismaHandler.js +10 -9
  75. package/dist/commands/serve.js +84 -137
  76. package/dist/commands/serveApiHandler.js +5 -5
  77. package/dist/commands/serveBothHandler.js +10 -7
  78. package/dist/commands/serveWebHandler.js +2 -2
  79. package/dist/commands/setup/auth/auth.js +12 -6
  80. package/dist/commands/setup/cache/cacheHandler.js +11 -6
  81. package/dist/commands/setup/deploy/deploy.js +4 -3
  82. package/dist/commands/setup/deploy/helpers/helpers.js +5 -1
  83. package/dist/commands/setup/deploy/helpers/index.js +157 -5
  84. package/dist/commands/setup/deploy/providers/baremetalHandler.js +26 -4
  85. package/dist/commands/setup/deploy/providers/coherenceHandler.js +53 -25
  86. package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +33 -23
  87. package/dist/commands/setup/deploy/providers/netlify.js +6 -0
  88. package/dist/commands/setup/deploy/providers/netlifyHandler.js +112 -11
  89. package/dist/commands/setup/deploy/providers/renderHandler.js +10 -5
  90. package/dist/commands/setup/deploy/providers/serverlessHandler.js +5 -3
  91. package/dist/commands/setup/deploy/providers/universal-deploy.js +11 -0
  92. package/dist/commands/setup/deploy/providers/universalDeployHandler.js +188 -0
  93. package/dist/commands/setup/deploy/providers/vercel.js +6 -0
  94. package/dist/commands/setup/deploy/providers/vercelHandler.js +113 -12
  95. package/dist/commands/setup/deploy/templates/baremetal.js +3 -2
  96. package/dist/commands/setup/deploy/templates/flightcontrol.js +60 -49
  97. package/dist/commands/setup/deploy/templates/netlify.js +2 -1
  98. package/dist/commands/setup/deploy/templates/netlifyUD.js +31 -0
  99. package/dist/commands/setup/docker/docker.js +1 -1
  100. package/dist/commands/setup/docker/dockerHandler.js +72 -37
  101. package/dist/commands/setup/docker/templates/Dockerfile.npm +119 -0
  102. package/dist/commands/setup/docker/templates/Dockerfile.pnpm +112 -0
  103. package/dist/commands/setup/docker/templates/{Dockerfile → Dockerfile.yarn} +1 -1
  104. package/dist/commands/setup/docker/templates/docker-compose.dev.yml +2 -2
  105. package/dist/commands/setup/generator/generatorHandler.js +4 -3
  106. package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +2 -2
  107. package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +2 -2
  108. package/dist/commands/setup/i18n/i18nHandler.js +18 -15
  109. package/dist/commands/setup/jobs/jobsHandler.js +10 -5
  110. package/dist/commands/setup/mailer/mailerHandler.js +11 -9
  111. package/dist/commands/setup/package/packageHandler.js +14 -10
  112. package/dist/commands/setup/realtime/realtimeHandler.js +22 -20
  113. package/dist/commands/setup/server-file/serverFileHandler.js +16 -8
  114. package/dist/commands/setup/tsconfig/tsconfigHandler.js +5 -3
  115. package/dist/commands/setup/ui/helpers/helpers.js +5 -1
  116. package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +11 -5
  117. package/dist/commands/setup/ui/libraries/mantineHandler.js +21 -13
  118. package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +38 -26
  119. package/dist/commands/setup/uploads/uploadsHandler.js +7 -4
  120. package/dist/commands/setup.js +1 -2
  121. package/dist/commands/test/testHandler.js +2 -1
  122. package/dist/commands/test/testHandlerEsm.js +2 -2
  123. package/dist/commands/type-checkHandler.js +4 -6
  124. package/dist/commands/upgrade/upgradeHandler.js +2 -4
  125. package/dist/index.js +10 -4
  126. package/dist/lib/configureStorybook.js +2 -2
  127. package/dist/lib/exec.js +36 -24
  128. package/dist/lib/exit.js +19 -4
  129. package/dist/lib/extendFile.js +22 -12
  130. package/dist/lib/index.js +119 -85
  131. package/dist/lib/merge/algorithms.js +4 -1
  132. package/dist/lib/merge/index.js +76 -41
  133. package/dist/lib/merge/semanticIdentity.js +18 -6
  134. package/dist/lib/merge/strategy.js +86 -36
  135. package/dist/lib/packages.js +23 -13
  136. package/dist/lib/plugin.js +12 -5
  137. package/dist/lib/pluralHelpers.js +1 -1
  138. package/dist/lib/project.js +3 -1
  139. package/dist/lib/rollback.js +7 -7
  140. package/dist/lib/schemaHelpers.js +12 -12
  141. package/dist/lib/test.js +4 -0
  142. package/dist/lib/updateCheck.js +6 -4
  143. package/dist/middleware/checkNodeVersion.js +5 -0
  144. package/dist/plugin.js +18 -12
  145. package/dist/telemetry/exporter.js +12 -5
  146. package/dist/telemetry/index.js +4 -3
  147. package/dist/telemetry/resource.js +9 -5
  148. package/dist/telemetry/send.js +14 -10
  149. package/package.json +15 -12
  150. package/dist/commands/setup/vite/templates/vite.config.ts.template +0 -19
  151. package/dist/commands/setup/vite/vite.js +0 -38
  152. package/dist/commands/setup/vite/viteHandler.js +0 -82
  153. /package/dist/{index.d.js → global.d.js} +0 -0
package/dist/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import https from "https";
2
1
  import fs from "node:fs";
3
- import path from "path";
2
+ import https from "node:https";
3
+ import path from "node:path";
4
4
  import * as babel from "@babel/core";
5
5
  import boxen from "boxen";
6
6
  import camelcase from "camelcase";
@@ -14,14 +14,18 @@ import pascalcase from "pascalcase";
14
14
  import { format } from "prettier";
15
15
  import { colors as c } from "@cedarjs/cli-helpers";
16
16
  import {
17
- getConfig as getRedwoodConfig,
18
- getPaths as getRedwoodPaths,
17
+ addRootPackages,
18
+ addWorkspacePackages
19
+ } from "@cedarjs/cli-helpers/packageManager/packages";
20
+ import {
21
+ getConfig as getCedarConfig,
22
+ getPaths as getCedarPaths,
19
23
  resolveFile as internalResolveFile,
20
24
  findUp
21
25
  } from "@cedarjs/project-config";
22
26
  import { pluralize, singularize } from "@cedarjs/utils/cedarPluralize";
23
27
  import { addFileToRollback } from "./rollback.js";
24
- const nameVariants = (name) => {
28
+ function nameVariants(name) {
25
29
  const normalizedName = pascalcase(paramCase(singularize(name)));
26
30
  return {
27
31
  pascalName: pascalcase(paramCase(name)),
@@ -35,8 +39,8 @@ const nameVariants = (name) => {
35
39
  singularConstantName: decamelize(normalizedName).toUpperCase(),
36
40
  pluralConstantName: decamelize(pluralize(normalizedName)).toUpperCase()
37
41
  };
38
- };
39
- const generateTemplate = (templateFilename, { name, ...rest }) => {
42
+ }
43
+ function generateTemplate(templateFilename, { name, ...rest }) {
40
44
  try {
41
45
  const templateFn = template(readFile(templateFilename).toString());
42
46
  const renderedTemplate = templateFn({
@@ -46,18 +50,22 @@ const generateTemplate = (templateFilename, { name, ...rest }) => {
46
50
  });
47
51
  return prettify(templateFilename, renderedTemplate);
48
52
  } catch (error) {
49
- error.message = `Error applying template at ${templateFilename} for ${name}: ${error.message}`;
50
- throw error;
53
+ const originalMessage = error instanceof Error ? error.message : String(error);
54
+ const wrappedError = new Error(
55
+ `Error applying template at ${templateFilename} for ${name}: ` + originalMessage
56
+ );
57
+ throw wrappedError;
51
58
  }
52
- };
59
+ }
53
60
  const prettify = async (templateFilename, renderedTemplate) => {
54
- const parser = {
61
+ const parserMap = {
55
62
  ".css": "css",
56
63
  ".js": "babel",
57
64
  ".jsx": "babel",
58
65
  ".ts": "babel-ts",
59
66
  ".tsx": "babel-ts"
60
- }[path.extname(templateFilename.replace(".template", ""))];
67
+ };
68
+ const parser = parserMap[path.extname(templateFilename.replace(".template", ""))];
61
69
  if (typeof parser === "undefined") {
62
70
  return renderedTemplate;
63
71
  }
@@ -128,30 +136,43 @@ async function getInstalledCedarVersion() {
128
136
  const packageJson = await import("../../package.json", { with: { type: "json" } });
129
137
  return packageJson.default.version;
130
138
  } catch (e) {
139
+ const message = e instanceof Error ? e.message : String(e);
131
140
  console.error(c.error("Could not find installed Cedar version"));
141
+ console.error(c.error(message));
132
142
  process.exit(1);
133
143
  }
134
144
  }
135
- const bytes = (contents) => Buffer.byteLength(contents, "utf8");
136
145
  const _getPaths = () => {
137
146
  try {
138
- return getRedwoodPaths();
147
+ return getCedarPaths();
139
148
  } catch (e) {
140
- console.error(c.error(e.message));
149
+ const message = e instanceof Error ? e.message : String(e);
150
+ console.error(c.error(message));
141
151
  process.exit(1);
142
152
  }
143
153
  };
144
154
  const getPaths = memoize(_getPaths);
145
155
  const resolveFile = internalResolveFile;
146
- const getGraphqlPath = () => resolveFile(path.join(getPaths().api.functions, "graphql"));
156
+ const getGraphqlPath = () => {
157
+ const functionsDir = getPaths().api.functions;
158
+ if (!functionsDir) {
159
+ throw new Error("Could not resolve the API functions directory");
160
+ }
161
+ return resolveFile(path.join(functionsDir, "graphql"));
162
+ };
147
163
  const graphFunctionDoesExist = () => {
148
- return fs.existsSync(getGraphqlPath());
164
+ const graphqlPath = getGraphqlPath();
165
+ if (!graphqlPath) {
166
+ return false;
167
+ }
168
+ return fs.existsSync(graphqlPath);
149
169
  };
150
170
  const getConfig = () => {
151
171
  try {
152
- return getRedwoodConfig();
172
+ return getCedarConfig();
153
173
  } catch (e) {
154
- console.error(c.error(e.message));
174
+ const message = e instanceof Error ? e.message : String(e);
175
+ console.error(c.error(message));
155
176
  process.exit(1);
156
177
  }
157
178
  };
@@ -162,7 +183,7 @@ const getPrettierOptions = async () => {
162
183
  const prettierConfigPath = fs.existsSync(cjsPath) ? cjsPath : mjsPath;
163
184
  const { default: prettierOptions } = await import(`file://${prettierConfigPath}`);
164
185
  return prettierOptions;
165
- } catch (e) {
186
+ } catch {
166
187
  if (process.env.VITEST_POOL_ID !== void 0) {
167
188
  return {
168
189
  trailingComma: "es5",
@@ -185,10 +206,10 @@ const getPrettierOptions = async () => {
185
206
  }
186
207
  };
187
208
  const transformTSToJS = async (filename, content) => {
188
- const { code } = babel.transform(content, {
209
+ const result = babel.transform(content, {
189
210
  filename,
190
- // If you ran `yarn cedar generate` in `./web` transformSync would import the `.babelrc.js` file,
191
- // in `./web`? despite us setting `configFile: false`.
211
+ // If you ran `yarn cedar generate` in `./web` transformSync would import
212
+ // the `.babelrc.js` file, in `./web` despite us setting `configFile: false`
192
213
  cwd: process.env.NODE_ENV === "test" ? void 0 : getPaths().base,
193
214
  configFile: false,
194
215
  plugins: [
@@ -202,16 +223,34 @@ const transformTSToJS = async (filename, content) => {
202
223
  ],
203
224
  retainLines: true
204
225
  });
205
- return prettify(filename.replace(/\.ts(x)?$/, ".js$1"), code);
226
+ if (result?.code == null) {
227
+ throw new Error(
228
+ `Could not transform ${filename} from TypeScript to JavaScript`
229
+ );
230
+ }
231
+ return prettify(filename.replace(/\.ts(x)?$/, ".js$1"), result.code);
232
+ };
233
+ const transformTSToJSMap = async (files, typescript) => {
234
+ return files.reduce(
235
+ async (accP, [outputPath, content]) => {
236
+ const acc = await accP;
237
+ const template2 = typescript ? content : await transformTSToJS(outputPath, content);
238
+ return {
239
+ [outputPath]: template2,
240
+ ...acc
241
+ };
242
+ },
243
+ Promise.resolve({})
244
+ );
206
245
  };
207
- const writeFilesTask = (files, options) => {
246
+ const writeFilesTask = (files, options = {}) => {
208
247
  const { base } = getPaths();
209
248
  return new Listr(
210
249
  Object.keys(files).map((file) => {
211
250
  const contents = files[file];
212
251
  return {
213
252
  title: `...waiting to write file \`./${path.relative(base, file)}\`...`,
214
- task: (ctx, task) => writeFile(file, contents, options, task)
253
+ task: (_ctx, task) => writeFile(file, contents, options, task)
215
254
  };
216
255
  })
217
256
  );
@@ -266,10 +305,10 @@ const cleanupEmptyDirsTask = (files) => {
266
305
  })
267
306
  );
268
307
  };
269
- const wrapWithSet = (routesContent, layout, routes, newLineAndIndent, props = {}) => {
308
+ function wrapWithSet(routesContent, layout, routes, newLineAndIndent, props = {}) {
270
309
  const [_, indentOne, indentTwo] = routesContent.match(
271
310
  /([ \t]*)<Router.*?>[^<]*[\r\n]+([ \t]+)/
272
- ) || ["", 0, 2];
311
+ ) || ["", "", ""];
273
312
  const oneLevelIndent = indentTwo.slice(0, indentTwo.length - indentOne.length);
274
313
  const newRoutesWithExtraIndent = routes.map((route) => oneLevelIndent + route);
275
314
  const propsString = Object.entries(props).map((values) => `${values[0]}="${values[1]}"`).join(" ");
@@ -278,15 +317,17 @@ const wrapWithSet = (routesContent, layout, routes, newLineAndIndent, props = {}
278
317
  ...newRoutesWithExtraIndent,
279
318
  `</Set>`
280
319
  ].join(newLineAndIndent);
281
- };
282
- const addRoutesToRouterTask = (routes, layout, setProps = {}) => {
283
- const redwoodPaths = getPaths();
284
- const routesContent = readFile(redwoodPaths.web.routes).toString();
320
+ }
321
+ function addRoutesToRouterTask(routes, layout, setProps = {}) {
322
+ const cedarPaths = getPaths();
323
+ const routesContent = readFile(cedarPaths.web.routes).toString();
285
324
  let newRoutes = routes.filter((route) => !routesContent.match(route));
286
325
  if (newRoutes.length) {
287
- const [routerStart, routerParams, newLineAndIndent] = routesContent.match(
288
- /\s*<Router(.*?)>(\s*)/s
289
- );
326
+ const routerMatch = routesContent.match(/\s*<Router(.*?)>(\s*)/s);
327
+ if (!routerMatch) {
328
+ throw new Error("Could not find a <Router> element in the routes file");
329
+ }
330
+ const [routerStart, routerParams, newLineAndIndent] = routerMatch;
290
331
  if (/trailingSlashes={?(["'])always\1}?/.test(routerParams)) {
291
332
  newRoutes = newRoutes.map((route) => {
292
333
  if (route.length > 2e3) {
@@ -307,11 +348,11 @@ ${route}`);
307
348
  routerStart,
308
349
  `${routerStart + routesBatch + newLineAndIndent}`
309
350
  );
310
- writeFile(redwoodPaths.web.routes, newRoutesContent, {
351
+ writeFile(cedarPaths.web.routes, newRoutesContent, {
311
352
  overwriteExisting: true
312
353
  });
313
354
  }
314
- };
355
+ }
315
356
  const addScaffoldImport = () => {
316
357
  const appJsPath = getPaths().web.app;
317
358
  let appJsContents = readFile(appJsPath).toString();
@@ -325,11 +366,13 @@ const addScaffoldImport = () => {
325
366
  writeFile(appJsPath, appJsContents, { overwriteExisting: true });
326
367
  return "Added scaffold import to App.{jsx,tsx}";
327
368
  };
328
- const removeEmtpySet = (routesContent, layout) => {
369
+ function removeEmtpySet(routesContent, layout) {
329
370
  const setWithLayoutReg = new RegExp(
330
371
  `\\s*<Set[^>]*wrap={${layout}}[^<]*>([^<]*)</Set>`
331
372
  );
332
- const [matchedSet, childContent] = routesContent.match(setWithLayoutReg) || [];
373
+ const match = routesContent.match(setWithLayoutReg);
374
+ const matchedSet = match?.[0] ?? "";
375
+ const childContent = match?.[1] ?? "";
333
376
  if (!matchedSet) {
334
377
  return routesContent;
335
378
  }
@@ -338,19 +381,19 @@ const removeEmtpySet = (routesContent, layout) => {
338
381
  return routesContent;
339
382
  }
340
383
  return routesContent.replace(setWithLayoutReg, "");
341
- };
342
- const removeRoutesFromRouterTask = (routes, layout) => {
343
- const redwoodPaths = getPaths();
344
- const routesContent = readFile(redwoodPaths.web.routes).toString();
384
+ }
385
+ function removeRoutesFromRouterTask(routes, layout) {
386
+ const cedarPaths = getPaths();
387
+ const routesContent = readFile(cedarPaths.web.routes).toString();
345
388
  const newRoutesContent = routes.reduce((content, route) => {
346
389
  const matchRouteByName = new RegExp(`\\s*<Route[^>]*name="${route}"[^>]*/>`);
347
390
  return content.replace(matchRouteByName, "");
348
391
  }, routesContent);
349
392
  const routesWithoutEmptySet = layout ? removeEmtpySet(newRoutesContent, layout) : newRoutesContent;
350
- writeFile(redwoodPaths.web.routes, routesWithoutEmptySet, {
393
+ writeFile(cedarPaths.web.routes, routesWithoutEmptySet, {
351
394
  overwriteExisting: true
352
395
  });
353
- };
396
+ }
354
397
  const addPackagesTask = async ({
355
398
  packages,
356
399
  side = "project",
@@ -364,57 +407,48 @@ const addPackagesTask = async ({
364
407
  return pkg;
365
408
  }
366
409
  });
367
- let installCommand;
368
- if (side !== "project") {
369
- installCommand = [
370
- "yarn",
371
- [
372
- "workspace",
373
- side,
374
- "add",
375
- devDependency && "--dev",
376
- ...packagesWithSameRWVersion
377
- ].filter(Boolean)
378
- ];
379
- } else {
380
- installCommand = [
381
- "yarn",
382
- ["add", devDependency && "--dev", ...packagesWithSameRWVersion].filter(
383
- Boolean
384
- )
385
- ];
386
- }
387
410
  return {
388
411
  title: `Adding dependencies to ${side}`,
389
412
  task: async () => {
390
- await execa(...installCommand);
413
+ if (side !== "project") {
414
+ await addWorkspacePackages(side, packagesWithSameRWVersion, {
415
+ dev: devDependency
416
+ });
417
+ } else {
418
+ await addRootPackages(packagesWithSameRWVersion, {
419
+ dev: devDependency
420
+ });
421
+ }
391
422
  }
392
423
  };
393
424
  };
394
- const runCommandTask = async (commands, { verbose, silent }) => {
425
+ const runCommandTask = async (commands, { verbose, silent } = {}) => {
395
426
  const tasks = new Listr(
396
- commands.map(({ title, cmd, args, opts = {}, cwd = getPaths().base }) => ({
397
- title,
398
- task: async () => {
399
- return execa(cmd, args, {
400
- cwd,
401
- stdio: verbose && !silent ? "inherit" : "pipe",
402
- extendEnv: true,
403
- cleanup: true,
404
- ...opts
405
- });
406
- }
407
- })),
427
+ commands.map(
428
+ ({ title, cmd, args = [], opts = {}, cwd = getPaths().base }) => ({
429
+ title,
430
+ task: async () => {
431
+ return execa(cmd, args, {
432
+ cwd,
433
+ stdio: verbose && !silent ? "inherit" : "pipe",
434
+ extendEnv: true,
435
+ cleanup: true,
436
+ ...opts
437
+ });
438
+ }
439
+ })
440
+ ),
408
441
  {
409
442
  renderer: silent ? "silent" : verbose ? "verbose" : "default",
410
- rendererOptions: { collapseSubtasks: false, dateFormat: false }
443
+ rendererOptions: { collapseSubtasks: false }
411
444
  }
412
445
  );
413
446
  try {
414
447
  await tasks.run();
415
448
  return true;
416
449
  } catch (e) {
417
- console.log(c.error(e.message));
450
+ const message = e instanceof Error ? e.message : String(e);
451
+ console.log(c.error(message));
418
452
  return false;
419
453
  }
420
454
  };
@@ -428,8 +462,8 @@ const getDefaultArgs = (builder) => {
428
462
  );
429
463
  };
430
464
  const usingVSCode = () => {
431
- const redwoodPaths = getPaths();
432
- const VS_CODE_PATH = path.join(redwoodPaths.base, ".vscode");
465
+ const cedarPaths = getPaths();
466
+ const VS_CODE_PATH = path.join(cedarPaths.base, ".vscode");
433
467
  return fs.existsSync(VS_CODE_PATH);
434
468
  };
435
469
  const printSetupNotes = (notes) => {
@@ -441,7 +475,7 @@ const printSetupNotes = (notes) => {
441
475
  ${boxen(notes.join("\n"), {
442
476
  padding: { top: 1, bottom: 1, right: 1, left: 1 },
443
477
  margin: 1,
444
- borderColour: "gray"
478
+ borderColor: "gray"
445
479
  })}
446
480
  `;
447
481
  }
@@ -452,7 +486,6 @@ export {
452
486
  addPackagesTask,
453
487
  addRoutesToRouterTask,
454
488
  addScaffoldImport,
455
- bytes,
456
489
  cleanupEmptyDirsTask,
457
490
  deleteFile,
458
491
  deleteFilesTask,
@@ -475,6 +508,7 @@ export {
475
508
  runCommandTask,
476
509
  saveRemoteFileToDisk,
477
510
  transformTSToJS,
511
+ transformTSToJSMap,
478
512
  usingVSCode,
479
513
  writeFile,
480
514
  writeFilesTask
@@ -16,9 +16,12 @@ function sieve(...listRulePairs) {
16
16
  }
17
17
  return result;
18
18
  }
19
+ function isAnyFn(value) {
20
+ return typeof value === "function";
21
+ }
19
22
  function forEachFunctionOn(object, callback) {
20
23
  forOwn(object, (value, key) => {
21
- if (typeof value === "function") {
24
+ if (isAnyFn(value)) {
22
25
  callback(key, value);
23
26
  }
24
27
  });
@@ -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,23 +67,36 @@ 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) {
83
92
  // If pruning 'path' would yield an ill-formed parent (e.g, '{foo:}' or 'const x;'), prune it.
84
93
  case "ObjectProperty":
85
94
  case "VariableDeclarator":
86
95
  return path.parentPath.remove();
87
96
  default:
88
- console.log(`Warning: default prune strategy for ${path.parentPath.type}`);
97
+ console.log(
98
+ `Warning: default prune strategy for ${path.parentPath?.type}`
99
+ );
89
100
  // eslint-disable-next-line no-fallthrough
90
101
  case "Program":
91
102
  case "ArrayExpression":
@@ -95,6 +106,7 @@ function prune(path) {
95
106
  function stripTrailingCommentsStrategy() {
96
107
  return {
97
108
  enter(path) {
109
+ ;
98
110
  path.node.trailingComments = [];
99
111
  }
100
112
  };
@@ -104,48 +116,71 @@ function mergeAST(baseAST, extAST, strategy = {}) {
104
116
  const identities = {};
105
117
  const baseVisitor = { ...stripTrailingCommentsStrategy() };
106
118
  const extVisitor = { ...stripTrailingCommentsStrategy() };
107
- forEachFunctionOn(strategy, (typename, strat) => {
108
- extVisitor[typename] = {
109
- enter(path) {
110
- const id = identity(path);
111
- id && (identities[id] ||= []).push(path);
112
- }
113
- };
114
- baseVisitor[typename] = {
115
- enter(path) {
116
- if (isOpaque(strat)) {
117
- 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
+ }
118
129
  }
119
- },
120
- exit(path) {
121
- const exts = extractProperty(identity(path), identities);
122
- if (exts) {
123
- const proxyPath = makeProxy(path);
124
- exts.map(makeProxy).forEach((ext) => {
125
- strat(proxyPath, ext);
126
- prune(ext.path);
127
- });
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
+ }
128
147
  }
129
- }
130
- };
131
- });
132
- traverse(extAST, extVisitor);
133
- traverse(baseAST, baseVisitor);
148
+ };
149
+ }
150
+ );
151
+ traverse(
152
+ extAST,
153
+ extVisitor
154
+ );
155
+ traverse(
156
+ baseAST,
157
+ baseVisitor
158
+ );
134
159
  const baseProgram = getProgramPath(baseAST);
160
+ const body = getProgramPath(extAST).get("body");
135
161
  const [imports, others] = partition(
136
- getProgramPath(extAST).get("body"),
137
- 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)
138
166
  );
139
167
  imports.forEach((exp) => insertAfterLastImport(exp, baseProgram));
140
- forEachRight(others, (exp) => insertBeforeFirstUsage(exp, baseProgram));
168
+ forEachRight(
169
+ others,
170
+ (exp) => insertBeforeFirstUsage(exp, baseProgram)
171
+ );
141
172
  }
142
173
  async function merge(base, extension, strategy) {
143
174
  function parseReact(code2) {
144
- return parse(code2, {
145
- filename: "merged.tsx",
175
+ const result = parse(code2, {
146
176
  // required to prevent babel error. The .tsx is relevant
177
+ filename: "merged.tsx",
147
178
  presets: ["@babel/preset-typescript"]
148
179
  });
180
+ if (result === null) {
181
+ throw new Error("Failed to parse code");
182
+ }
183
+ return result;
149
184
  }
150
185
  const baseAST = parseReact(base);
151
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(".");