@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
@@ -5,6 +5,12 @@ import execa from "execa";
5
5
  import { Listr } from "listr2";
6
6
  import { terminalLink } from "termi-link";
7
7
  import { recordTelemetryAttributes, colors as c } from "@cedarjs/cli-helpers";
8
+ import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
9
+ import { runBin } from "@cedarjs/cli-helpers/packageManager/exec";
10
+ import {
11
+ addRootPackages,
12
+ addWorkspacePackages
13
+ } from "@cedarjs/cli-helpers/packageManager/packages";
8
14
  import { errorTelemetry } from "@cedarjs/telemetry";
9
15
  import { getPaths, usingVSCode } from "../../../../lib/index.js";
10
16
  const tailwindDirectives = [
@@ -19,7 +25,7 @@ const tailwindImportsAndNotes = [
19
25
  "/**",
20
26
  " * START --- SETUP TAILWINDCSS EDIT",
21
27
  " *",
22
- " * `yarn cedar setup ui tailwindcss` placed these directives here",
28
+ ` * \`${formatCedarCommand(["setup", "ui", "tailwindcss"])}\` placed these directives here`,
23
29
  " * to inject Tailwind's styles into your CSS.",
24
30
  " * For more information, see: https://tailwindcss.com/docs/installation",
25
31
  " */",
@@ -68,14 +74,17 @@ async function recommendExtensionsToInstall() {
68
74
  });
69
75
  }
70
76
  }
71
- const handler = async ({ force, install }) => {
77
+ const handler = async ({
78
+ force,
79
+ install
80
+ }) => {
72
81
  recordTelemetryAttributes({
73
82
  command: "setup ui tailwindcss",
74
83
  force,
75
84
  install
76
85
  });
77
86
  const rwPaths = getPaths();
78
- const projectPackages = ["prettier-plugin-tailwindcss@^0.7.0"];
87
+ const projectPackages = ["prettier-plugin-tailwindcss@^0.8.0"];
79
88
  const webWorkspacePackages = [
80
89
  "postcss",
81
90
  "postcss-loader",
@@ -93,8 +102,9 @@ const handler = async ({ force, install }) => {
93
102
  {
94
103
  title: `Install ${projectPackages.join(", ")}`,
95
104
  task: async () => {
96
- await execa("yarn", ["add", "-D", ...projectPackages], {
97
- cwd: rwPaths.base
105
+ await addRootPackages(projectPackages, {
106
+ cwd: rwPaths.base,
107
+ dev: true
98
108
  });
99
109
  }
100
110
  }
@@ -112,19 +122,16 @@ const handler = async ({ force, install }) => {
112
122
  {
113
123
  title: `Install ${webWorkspacePackages.join(", ")}`,
114
124
  task: async () => {
115
- await execa(
116
- "yarn",
117
- ["workspace", "web", "add", "-D", ...webWorkspacePackages],
118
- {
119
- cwd: rwPaths.base,
120
- env: {
121
- // For some reason yarn started installing deprecated
122
- // typescript types when installing tailwind. This
123
- // prevents it from happening.
124
- YARN_TS_ENABLE_AUTO_TYPES: "false"
125
- }
126
- }
127
- );
125
+ await addWorkspacePackages("web", webWorkspacePackages, {
126
+ cwd: rwPaths.base,
127
+ env: {
128
+ // For some reason yarn started installing deprecated
129
+ // typescript types when installing tailwind. This
130
+ // prevents it from happening. (yarn-only env var.)
131
+ YARN_TS_ENABLE_AUTO_TYPES: "false"
132
+ },
133
+ dev: true
134
+ });
128
135
  }
129
136
  }
130
137
  ],
@@ -169,7 +176,7 @@ const handler = async ({ force, install }) => {
169
176
  );
170
177
  }
171
178
  }
172
- await execa("yarn", ["tailwindcss", "init", tailwindConfigPath], {
179
+ await runBin("tailwindcss", ["init", tailwindConfigPath], {
173
180
  cwd: rwPaths.web.base
174
181
  });
175
182
  const tailwindConfig = fs.readFileSync(tailwindConfigPath, "utf-8");
@@ -234,7 +241,7 @@ const handler = async ({ force, install }) => {
234
241
  rwPaths.base,
235
242
  ".vscode/extensions.json"
236
243
  );
237
- let originalExtensionsJson = { recommendations: [] };
244
+ let originalExtensionsJson = {};
238
245
  if (fs.existsSync(VS_CODE_EXTENSIONS_PATH)) {
239
246
  const originalExtensionsFile = fs.readFileSync(
240
247
  VS_CODE_EXTENSIONS_PATH,
@@ -245,7 +252,7 @@ const handler = async ({ force, install }) => {
245
252
  const newExtensionsJson = {
246
253
  ...originalExtensionsJson,
247
254
  recommendations: [
248
- ...originalExtensionsJson.recommendations,
255
+ ...originalExtensionsJson.recommendations ?? [],
249
256
  ...recommendedVSCodeExtensions
250
257
  ]
251
258
  };
@@ -280,7 +287,10 @@ const handler = async ({ force, install }) => {
280
287
  const originalSettingsJson = JSON.parse(
281
288
  originalSettingsFile || "{}"
282
289
  );
283
- const originalTwClassAttributesJson = originalSettingsJson["tailwindCSS.classAttributes"] || [];
290
+ const existingAttributes = originalSettingsJson["tailwindCSS.classAttributes"];
291
+ const originalTwClassAttributesJson = Array.isArray(
292
+ existingAttributes
293
+ ) ? existingAttributes : [];
284
294
  const mergedClassAttributes = Array.from(
285
295
  /* @__PURE__ */ new Set([...classAttributes, ...originalTwClassAttributesJson])
286
296
  );
@@ -342,7 +352,7 @@ const handler = async ({ force, install }) => {
342
352
  const pluginsMatch = newPrettierConfig.match(
343
353
  /plugins: \[[\sa-z\(\)'\-,]*]/
344
354
  );
345
- const matched = pluginsMatch && pluginsMatch[0];
355
+ const matched = pluginsMatch != null ? pluginsMatch[0] : void 0;
346
356
  if (matched && (matched.includes("'prettier-plugin-tailwindcss'") || matched.includes('"prettier-plugin-tailwindcss"'))) {
347
357
  task.skip(
348
358
  "tailwindcss-plugin-prettier already required in plugins"
@@ -370,9 +380,11 @@ const handler = async ({ force, install }) => {
370
380
  await tasks.run();
371
381
  await recommendExtensionsToInstall();
372
382
  } catch (e) {
373
- errorTelemetry(process.argv, e.message);
374
- console.error(c.error(e.message));
375
- process.exit(e?.exitCode || 1);
383
+ const msg = e instanceof Error ? e.message : String(e);
384
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
385
+ errorTelemetry(process.argv, msg);
386
+ console.error(c.error(msg));
387
+ process.exit(exitCode);
376
388
  }
377
389
  };
378
390
  export {
@@ -8,6 +8,7 @@ import {
8
8
  getPrettierOptions,
9
9
  colors as c
10
10
  } from "@cedarjs/cli-helpers";
11
+ import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
11
12
  import { errorTelemetry } from "@cedarjs/telemetry";
12
13
  import { getPaths, transformTSToJS, writeFile } from "../../../lib/index.js";
13
14
  import { isTypeScriptProject } from "../../../lib/project.js";
@@ -124,7 +125,7 @@ const handler = async ({ force }) => {
124
125
 
125
126
  ${c.success("\nUploads and storage configured!\n")}
126
127
 
127
- Remember to add UPLOADS_SECRET to your .env file. You can generate one with ${c.highlight("yarn cedar generate secret")}
128
+ Remember to add UPLOADS_SECRET to your .env file. You can generate one with ${c.highlight(formatCedarCommand(["generate", "secret"]))}
128
129
 
129
130
  Check out the docs for more info:
130
131
  ${terminalLink("", "https://cedarjs.com/docs/uploads")}
@@ -140,9 +141,11 @@ const handler = async ({ force }) => {
140
141
  try {
141
142
  await tasks.run();
142
143
  } catch (e) {
143
- errorTelemetry(process.argv, e.message);
144
- console.error(c.error(e.message));
145
- process.exit(e?.exitCode || 1);
144
+ const message = e instanceof Error ? e.message : String(e);
145
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
146
+ errorTelemetry(process.argv, message);
147
+ console.error(c.error(message));
148
+ process.exit(exitCode);
146
149
  }
147
150
  };
148
151
  export {
@@ -18,10 +18,9 @@ import * as setupServerFile from "./setup/server-file/serverFile.js";
18
18
  import * as setupTsconfig from "./setup/tsconfig/tsconfig.js";
19
19
  import * as setupUi from "./setup/ui/ui.js";
20
20
  import * as setupUploads from "./setup/uploads/uploads.js";
21
- import * as setupVite from "./setup/vite/vite.js";
22
21
  const command = "setup <command>";
23
22
  const description = "Initialize project config and install packages";
24
- const builder = (yargs) => yargs.command(setupAuth).command(setupCache).command(setupDeploy).command(setupDocker).command(setupGenerator).command(setupGraphql).command(setupI18n).command(setupJobs).command(setupMailer).command(setupMiddleware).command(setupMonitoring).command(setupNeon).command(setupPackage).command(setupRealtime).command(setupServerFile).command(setupTsconfig).command(setupUi).command(setupUploads).command(setupVite).demandCommand().middleware(detectCedarVersion).epilogue(
23
+ const builder = (yargs) => yargs.command(setupAuth).command(setupCache).command(setupDeploy).command(setupDocker).command(setupGenerator).command(setupGraphql).command(setupI18n).command(setupJobs).command(setupMailer).command(setupMiddleware).command(setupMonitoring).command(setupNeon).command(setupPackage).command(setupRealtime).command(setupServerFile).command(setupTsconfig).command(setupUi).command(setupUploads).demandCommand().middleware(detectCedarVersion).epilogue(
25
24
  `Also see the ${terminalLink(
26
25
  "CedarJS CLI Reference",
27
26
  "https://cedarjs.com/docs/cli-commands#setup"
@@ -2,6 +2,7 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import execa from "execa";
4
4
  import { recordTelemetryAttributes, colors as c } from "@cedarjs/cli-helpers";
5
+ import { runBin } from "@cedarjs/cli-helpers/packageManager/exec";
5
6
  import { ensurePosixPath } from "@cedarjs/project-config";
6
7
  import { errorTelemetry, timedTelemetry } from "@cedarjs/telemetry";
7
8
  import { getPaths } from "../../lib/index.js";
@@ -125,7 +126,7 @@ const handler = async ({
125
126
  await warnIfNonStandardDatasourceUrl({ force });
126
127
  }
127
128
  const runCommand = async () => {
128
- await execa("yarn", ["jest", ...jestArgs], {
129
+ await runBin("jest", jestArgs, {
129
130
  cwd: rwjsPaths.base,
130
131
  stdio: "inherit",
131
132
  env: { ...process.env, DATABASE_URL }
@@ -1,5 +1,5 @@
1
- import execa from "execa";
2
1
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
2
+ import { runBin } from "@cedarjs/cli-helpers/packageManager/exec";
3
3
  import { ensurePosixPath } from "@cedarjs/project-config";
4
4
  import { errorTelemetry, timedTelemetry } from "@cedarjs/telemetry";
5
5
  import { getPaths } from "../../lib/index.js";
@@ -76,7 +76,7 @@ const handler = async ({
76
76
  await warnIfNonStandardDatasourceUrl({ force });
77
77
  }
78
78
  const runCommand = async () => {
79
- await execa("yarn", ["vitest", ...vitestArgs], {
79
+ await runBin("vitest", vitestArgs, {
80
80
  cwd: rwjsPaths.base,
81
81
  stdio: "inherit",
82
82
  env: { ...process.env, DATABASE_URL }
@@ -1,8 +1,9 @@
1
1
  import path from "node:path";
2
2
  import concurrently from "concurrently";
3
- import execa from "execa";
4
3
  import { Listr } from "listr2";
5
4
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
5
+ import { formatRunBinCommand } from "@cedarjs/cli-helpers/packageManager/display";
6
+ import { runBin } from "@cedarjs/cli-helpers/packageManager/exec";
6
7
  import { generatePrismaClient } from "../lib/generatePrismaClient.js";
7
8
  import { getPaths } from "../lib/index.js";
8
9
  const isConcurrentlyErrorArray = (value) => {
@@ -30,7 +31,7 @@ const handler = async ({
30
31
  const projectDir = path.join(getPaths().base, side);
31
32
  return {
32
33
  cwd: projectDir,
33
- command: "yarn tsc --noEmit --skipLibCheck"
34
+ command: formatRunBinCommand("tsc", ["--noEmit", "--skipLibCheck"])
34
35
  };
35
36
  });
36
37
  const { result } = concurrently(tscForAllSides, {
@@ -55,10 +56,7 @@ const handler = async ({
55
56
  [
56
57
  {
57
58
  title: "Generating types",
58
- task: () => execa("yarn cedar-gen", {
59
- shell: true,
60
- stdio: verbose ? "inherit" : "ignore"
61
- })
59
+ task: () => runBin("cedar-gen", [], { stdio: verbose ? "inherit" : "ignore" })
62
60
  }
63
61
  ],
64
62
  {
@@ -194,8 +194,7 @@ const handler = async (upgradeOptions) => {
194
194
  };
195
195
  async function packageManagerInstall({ verbose }) {
196
196
  try {
197
- await execa(`${getPackageManager()} ${install()}`, {
198
- shell: true,
197
+ await execa(getPackageManager(), [install()], {
199
198
  stdio: verbose ? "inherit" : "pipe",
200
199
  cwd: getPaths().base
201
200
  });
@@ -456,8 +455,7 @@ async function dedupeDeps(_task, { verbose }) {
456
455
  return;
457
456
  }
458
457
  try {
459
- await execa(`${getPackageManager()} ${dedupeCmd}`, {
460
- shell: true,
458
+ await execa(getPackageManager(), [dedupeCmd], {
461
459
  stdio: verbose ? "inherit" : "pipe",
462
460
  cwd: getPaths().base
463
461
  });
package/dist/index.js CHANGED
@@ -38,15 +38,21 @@ import { exitWithError } from "./lib/exit.js";
38
38
  import * as updateCheck from "./lib/updateCheck.js";
39
39
  import { loadPlugins } from "./plugin.js";
40
40
  import { startTelemetry, shutdownTelemetry } from "./telemetry/index.js";
41
- let { cwd, telemetry, help, version } = Parser(hideBin(process.argv), {
41
+ const {
42
+ telemetry,
43
+ help,
44
+ version,
45
+ cwd: parsedCwd
46
+ } = Parser(hideBin(process.argv), {
42
47
  // Telemetry is enabled by default, but can be disabled in two ways
43
48
  // - by passing a `--telemetry false` option
44
- // - by setting a `REDWOOD_DISABLE_TELEMETRY` env var
49
+ // - by setting a `CEDAR_DISABLE_TELEMETRY` env var
45
50
  boolean: ["telemetry"],
46
51
  default: {
47
- telemetry: process.env.REDWOOD_DISABLE_TELEMETRY === void 0 || process.env.REDWOOD_DISABLE_TELEMETRY === ""
52
+ 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 === "")
48
53
  }
49
54
  });
55
+ let cwd = parsedCwd;
50
56
  cwd ??= process.env.CEDAR_CWD;
51
57
  cwd ??= process.env.RWJS_CWD;
52
58
  cwd = getTomlDir(cwd);
@@ -168,7 +174,7 @@ function getTomlDir(cwd2) {
168
174
  tomlDir = path.dirname(configTomlPath);
169
175
  }
170
176
  } catch (error) {
171
- console.error(error.message);
177
+ console.error(error instanceof Error ? error.message : String(error));
172
178
  process.exit(1);
173
179
  }
174
180
  return tomlDir;
@@ -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,4 +1,4 @@
1
- import { existsSync } from "node:fs";
1
+ import { existsSync, statSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { createServer, isRunnableDevEnvironment } from "vite";
4
4
  import { getPaths, importStatementPath } from "@cedarjs/project-config";
@@ -11,8 +11,8 @@ import {
11
11
  cedarAutoImportsPlugin,
12
12
  cedarCjsCompatPlugin
13
13
  } from "@cedarjs/vite";
14
- function resolveExtension(id) {
15
- if (existsSync(id)) {
14
+ function resolveId(id) {
15
+ if (existsSync(id) && statSync(id).isFile()) {
16
16
  return id;
17
17
  }
18
18
  const withoutExt = /\.jsx?$/.test(id) ? id.replace(/\.jsx?$/, "") : id;
@@ -21,6 +21,16 @@ function resolveExtension(id) {
21
21
  return withoutExt + ext;
22
22
  }
23
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
+ }
24
34
  return id;
25
35
  }
26
36
  async function runScriptFunction({
@@ -67,14 +77,14 @@ async function runScriptFunction({
67
77
  customResolver: (id, importer, _options) => {
68
78
  const apiImportBase = importStatementPath(getPaths().api.base);
69
79
  const webImportBase = importStatementPath(getPaths().web.base);
70
- if (importer.startsWith(apiImportBase)) {
80
+ if (importer?.startsWith(apiImportBase)) {
71
81
  const apiImportSrc = importStatementPath(getPaths().api.src);
72
- const resolvedId = id.replace("src", apiImportSrc);
73
- return { id: resolveExtension(resolvedId) };
74
- } else if (importer.startsWith(webImportBase)) {
82
+ const apiId = id.replace("src", apiImportSrc);
83
+ return { id: resolveId(apiId) };
84
+ } else if (importer?.startsWith(webImportBase)) {
75
85
  const webImportSrc = importStatementPath(getPaths().web.src);
76
- const resolvedId = id.replace("src", webImportSrc);
77
- return { id: resolveExtension(resolvedId) };
86
+ const webId = id.replace("src", webImportSrc);
87
+ return { id: resolveId(webId) };
78
88
  }
79
89
  return null;
80
90
  }
@@ -97,25 +107,27 @@ async function runScriptFunction({
97
107
  throw new Error("Vite environment is not runnable.");
98
108
  }
99
109
  let returnValue;
100
- let scriptError = null;
101
- try {
102
- const script = await env.runner.import(scriptPath);
103
- returnValue = await script[functionName](args);
104
- } catch (error) {
105
- scriptError = error;
106
- }
107
110
  try {
108
- const { db } = await env.runner.import(path.join(getPaths().api.lib, "db"));
109
- db.$disconnect();
110
- } catch (e) {
111
- }
112
- await server.close();
113
- process.env.NODE_ENV = NODE_ENV;
114
- if (scriptError) {
115
- throw scriptError;
111
+ const module = await env.runner.import(scriptPath);
112
+ const fn = module[functionName];
113
+ if (typeof fn !== "function") {
114
+ throw new Error(`Function '${functionName}' not found in script`);
115
+ }
116
+ returnValue = await fn(args);
117
+ } finally {
118
+ try {
119
+ const dbModule = await env.runner.import(
120
+ path.join(getPaths().api.lib, "db")
121
+ );
122
+ dbModule.db?.$disconnect?.();
123
+ } catch {
124
+ }
125
+ await server.close();
126
+ process.env.NODE_ENV = NODE_ENV;
116
127
  }
117
128
  return returnValue;
118
129
  }
119
130
  export {
131
+ resolveId,
120
132
  runScriptFunction
121
133
  };
package/dist/lib/exit.js CHANGED
@@ -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
  }
@@ -1,8 +1,8 @@
1
1
  import fs from "node:fs";
2
- function fileIncludes(path, str) {
3
- return fs.existsSync(path) && fs.readFileSync(path).toString().includes(str);
2
+ function fileIncludes(filePath, str) {
3
+ return fs.existsSync(filePath) && fs.readFileSync(filePath).toString().includes(str);
4
4
  }
5
- function extendJSXFile(path, {
5
+ function extendJSXFile(filePath, {
6
6
  insertComponent: {
7
7
  name = void 0,
8
8
  props = void 0,
@@ -14,7 +14,7 @@ function extendJSXFile(path, {
14
14
  imports = [],
15
15
  moduleScopeLines = []
16
16
  }) {
17
- const content = fs.readFileSync(path).toString().split("\n");
17
+ const content = fs.readFileSync(filePath).toString().split("\n");
18
18
  if (moduleScopeLines?.length) {
19
19
  content.splice(
20
20
  content.findLastIndex((l) => l.trimStart().startsWith("import")) + 1,
@@ -41,9 +41,16 @@ function extendJSXFile(path, {
41
41
  insertAfter
42
42
  });
43
43
  }
44
- fs.writeFileSync(path, content.filter((e) => e !== void 0).join("\n"));
44
+ fs.writeFileSync(filePath, content.join("\n"));
45
45
  }
46
- function insertComponent(content, { component, props, around, within, insertBefore, insertAfter }) {
46
+ function insertComponent(content, {
47
+ component,
48
+ props,
49
+ around,
50
+ within,
51
+ insertBefore,
52
+ insertAfter
53
+ }) {
47
54
  if (around && within || !(around || within)) {
48
55
  throw new Error(
49
56
  "Exactly one of (around | within) must be defined. Choose one."
@@ -62,16 +69,16 @@ function insertComponent(content, { component, props, around, within, insertBefo
62
69
  open++;
63
70
  close--;
64
71
  }
65
- const [, componentDepth] = content[open].match(/([^\S\r\n]*).*/);
72
+ const depthMatch = content[open].match(/([^\S\r\n]*).*/);
73
+ const componentDepth = depthMatch?.[1] ?? "";
66
74
  content.splice(
67
75
  open,
68
76
  close - open,
69
- // "Delete" the wrapped component contents. We put it back below.
70
- insertBefore && componentDepth + insertBefore,
77
+ ...insertBefore ? [componentDepth + insertBefore] : [],
71
78
  componentDepth + buildOpeningTag(component, props),
72
79
  ...content.slice(open, close).map((line) => " " + line),
73
80
  componentDepth + `</${component}>`,
74
- insertAfter && componentDepth + insertAfter
81
+ ...insertAfter ? [componentDepth + insertAfter] : []
75
82
  );
76
83
  }
77
84
  function buildOpeningTag(componentName, props) {
@@ -92,11 +99,14 @@ function buildOpeningTag(componentName, props) {
92
99
  const possibleSpace = propsString.length ? " " : "";
93
100
  return `<${componentName}${possibleSpace}${propsString}>`;
94
101
  }
95
- function objectToComponentProps(obj, options = { exclude: [], raw: false }) {
102
+ function objectToComponentProps(obj, options = {
103
+ exclude: [],
104
+ raw: false
105
+ }) {
96
106
  const props = [];
97
107
  const doRaw = (key) => options.raw === true || Array.isArray(options.raw) && options.raw.includes(key);
98
108
  for (const [key, value] of Object.entries(obj)) {
99
- if (options.exclude && options.exclude.includes(key)) {
109
+ if (options.exclude?.includes(key)) {
100
110
  continue;
101
111
  }
102
112
  if (doRaw(key)) {