@cedarjs/cli 3.0.0-canary.13612 → 3.0.0-canary.13614

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.
@@ -29,7 +29,9 @@ function checkWorkspacePackageEntryPoints(cedarPaths) {
29
29
  if (!fs.existsSync(pkgJsonPath)) {
30
30
  continue;
31
31
  }
32
- const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
32
+ const pkgJson = JSON.parse(
33
+ fs.readFileSync(pkgJsonPath, "utf8")
34
+ );
33
35
  const pkgName = pkgJson.name || entry.name;
34
36
  const pkgDir = path.join(packagesDir, entry.name);
35
37
  const entryFiles = /* @__PURE__ */ new Set();
@@ -82,7 +84,9 @@ const handler = async ({
82
84
  const prerenderRoutes = prerender && workspace.includes("web") ? detectPrerenderRoutes() : [];
83
85
  const shouldGeneratePrismaClient = prisma && prismaSchemaExists && (workspace.includes("api") || prerenderRoutes.length > 0);
84
86
  const packageJsonPath = path.join(cedarPaths.base, "package.json");
85
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
87
+ const packageJson = JSON.parse(
88
+ fs.readFileSync(packageJsonPath, "utf8")
89
+ );
86
90
  const packageJsonWorkspaces = packageJson.workspaces;
87
91
  const nonApiWebWorkspaces = Array.isArray(packageJsonWorkspaces) && packageJsonWorkspaces.length > 2 ? workspace.filter((w) => w !== "api" && w !== "web") : [];
88
92
  const gqlFeaturesTaskTitle = `Generating types needed for ${[
@@ -176,7 +180,7 @@ Run ` + c.info("yarn cedar build") + " (without specifying a workspace) to build
176
180
  }
177
181
  }
178
182
  }
179
- ].filter(Boolean);
183
+ ].filter((t) => Boolean(t));
180
184
  const triggerPrerender = async () => {
181
185
  console.log("Starting prerendering...");
182
186
  if (prerenderRoutes.length === 0) {
@@ -1,9 +1,9 @@
1
1
  const command = "console";
2
2
  const aliases = ["c"];
3
3
  const description = "Launch an interactive Redwood shell (experimental)";
4
- const handler = async (options) => {
4
+ const handler = async () => {
5
5
  const { handler: handler2 } = await import("./consoleHandler.js");
6
- return handler2(options);
6
+ return handler2();
7
7
  };
8
8
  export {
9
9
  aliases,
@@ -6,6 +6,9 @@ import { registerApiSideBabelHook } from "@cedarjs/babel-config";
6
6
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
7
7
  import { getPaths } from "../lib/index.js";
8
8
  const paths = getPaths();
9
+ function isREPLServerWithHistory(replServer) {
10
+ return "history" in replServer && "lines" in replServer;
11
+ }
9
12
  const loadPrismaClient = (replContext) => {
10
13
  const createdRequire = createRequire(import.meta.url);
11
14
  const { db } = createdRequire(path.join(paths.api.lib, "db"));
@@ -14,16 +17,19 @@ const loadPrismaClient = (replContext) => {
14
17
  };
15
18
  const consoleHistoryFile = path.join(paths.generated.base, "console_history");
16
19
  const persistConsoleHistory = (r) => {
20
+ const lines = isREPLServerWithHistory(r) ? r.lines : [];
17
21
  fs.appendFileSync(
18
22
  consoleHistoryFile,
19
- r.lines.filter((line) => line.trim()).join("\n") + "\n",
23
+ lines.filter((line) => line.trim()).join("\n") + "\n",
20
24
  "utf8"
21
25
  );
22
26
  };
23
27
  const loadConsoleHistory = async (r) => {
24
28
  try {
25
29
  const history = await fs.promises.readFile(consoleHistoryFile, "utf8");
26
- history.split("\n").reverse().map((line) => r.history.push(line));
30
+ if (isREPLServerWithHistory(r)) {
31
+ history.split("\n").reverse().map((line) => r.history.push(line));
32
+ }
27
33
  } catch {
28
34
  }
29
35
  };
@@ -53,8 +59,8 @@ const handler = (_options) => {
53
59
  } else {
54
60
  try {
55
61
  callback(null, await Promise.resolve(result));
56
- } catch (error) {
57
- callback(error, null);
62
+ } catch (err2) {
63
+ callback(err2 instanceof Error ? err2 : new Error(String(err2)), null);
58
64
  }
59
65
  }
60
66
  });
@@ -83,10 +83,7 @@ const handler = async ({
83
83
  }
84
84
  if (workspace.includes("api")) {
85
85
  try {
86
- await generatePrismaClient({
87
- verbose: false,
88
- force: false
89
- });
86
+ await generatePrismaClient({ verbose: false, force: false });
90
87
  } catch (e) {
91
88
  const message = getErrorMessage(e);
92
89
  errorTelemetry(process.argv, `Error generating prisma client: ${message}`);
@@ -36,15 +36,17 @@ const printAvailableScriptsToConsole = () => {
36
36
  const handler = async (args) => {
37
37
  recordTelemetryAttributes({
38
38
  command: "exec",
39
- prisma: args.prisma,
40
- list: args.list
39
+ prisma: !!args.prisma,
40
+ list: !!args.list
41
41
  });
42
42
  const { name, prisma, list, ...scriptArgs } = args;
43
43
  if (list || !name) {
44
44
  printAvailableScriptsToConsole();
45
45
  return;
46
46
  }
47
- scriptArgs._ = (Array.isArray(scriptArgs._) ? scriptArgs._ : []).slice(1);
47
+ if (Array.isArray(scriptArgs._)) {
48
+ scriptArgs._ = scriptArgs._.slice(1);
49
+ }
48
50
  delete scriptArgs.$0;
49
51
  delete scriptArgs.l;
50
52
  delete scriptArgs.s;
@@ -62,11 +64,11 @@ No script called \`${name}\` in the ./scripts folder.
62
64
  const scriptTasks = [
63
65
  {
64
66
  title: "Generating Prisma client",
65
- enabled: () => Boolean(prisma),
67
+ enabled: () => !!prisma,
66
68
  task: () => generatePrismaClient({
67
69
  force: false,
68
70
  verbose: !args.silent,
69
- silent: args.silent
71
+ silent: !!args.silent
70
72
  })
71
73
  },
72
74
  {
@@ -3,7 +3,6 @@ import { paramCase } from "change-case";
3
3
  import { Listr } from "listr2";
4
4
  import { terminalLink } from "termi-link";
5
5
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
6
- import { dbReexportsPrismaClient } from "@cedarjs/internal/dist/project";
7
6
  import { getDataMigrationsPath } from "@cedarjs/project-config";
8
7
  import c from "../../../lib/colors.js";
9
8
  import {
@@ -44,7 +43,7 @@ const files = async ({ name, typescript }) => {
44
43
  getPaths().api.prismaConfig
45
44
  );
46
45
  const outputPath = path.join(dataMigrationsPath, outputFilename);
47
- const prismaImportSource = dbReexportsPrismaClient() ? "src/lib/db" : "@prisma/client";
46
+ const prismaImportSource = "src/lib/db";
48
47
  return {
49
48
  [outputPath]: await generateTemplate(TEMPLATE_PATHS[extension], {
50
49
  name,
@@ -1,6 +1,5 @@
1
1
  import path from "node:path";
2
2
  import camelcase from "camelcase";
3
- import { dbReexportsPrismaClient } from "@cedarjs/internal/dist/project";
4
3
  import { pluralize, singularize } from "@cedarjs/utils/cedarPluralize";
5
4
  import { transformTSToJS } from "../../../lib/index.js";
6
5
  import { getSchema, verifyModelName } from "../../../lib/schemaHelpers.js";
@@ -223,7 +222,7 @@ const files = async ({
223
222
  const componentName = camelcase(pluralize(name));
224
223
  const model = name;
225
224
  const idName = await getIdName(model);
226
- const prismaImportSource = dbReexportsPrismaClient() ? "src/lib/db" : "@prisma/client";
225
+ const prismaImportSource = "src/lib/db";
227
226
  const modelRelations = relations || relationsForModel(await getSchema(model));
228
227
  const serviceFile = await templateForFile({
229
228
  name,
@@ -3,7 +3,7 @@ import path from "node:path";
3
3
  import execa from "execa";
4
4
  import { terminalLink } from "termi-link";
5
5
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
6
- import { getPaths, getConfig } from "../lib/index.js";
6
+ import { getPaths, getConfig } from "@cedarjs/project-config";
7
7
  function detectLegacyEslintConfig() {
8
8
  const projectRoot = getPaths().base;
9
9
  const legacyConfigFiles = [
@@ -88,7 +88,7 @@ const handler = async ({
88
88
  recordTelemetryAttributes({ command: "lint", fix, format });
89
89
  const config = getConfig();
90
90
  const legacyConfigFiles = detectLegacyEslintConfig();
91
- if (legacyConfigFiles.length > 0 && config.eslintLegacyConfigWarning) {
91
+ if (legacyConfigFiles.length > 0 && config instanceof Object && "eslintLegacyConfigWarning" in config && config.eslintLegacyConfigWarning) {
92
92
  showLegacyEslintDeprecationWarning(legacyConfigFiles);
93
93
  }
94
94
  try {
@@ -96,7 +96,6 @@ const getTasks = async (dryrun, routerPathFilter = null) => {
96
96
  const detector = projectIsEsm() ? await import("@cedarjs/prerender/detection") : await import("@cedarjs/prerender/cjs/detection");
97
97
  const detectedRoutes = detector.detectPrerenderRoutes();
98
98
  const prerenderRoutes = detectedRoutes.filter(hasPath).map(normalizeRoute);
99
- const indexHtmlPath = path.join(getPaths().web.dist, "index.html");
100
99
  if (prerenderRoutes.length === 0) {
101
100
  console.log("\nSkipping prerender...");
102
101
  console.log(
@@ -106,6 +105,7 @@ const getTasks = async (dryrun, routerPathFilter = null) => {
106
105
  );
107
106
  return [];
108
107
  }
108
+ const indexHtmlPath = path.join(getPaths().web.dist, "index.html");
109
109
  if (!fs.existsSync(indexHtmlPath)) {
110
110
  console.error(
111
111
  "You must run `yarn cedar build web` before trying to prerender."
@@ -129,7 +129,7 @@ const getTasks = async (dryrun, routerPathFilter = null) => {
129
129
  return [
130
130
  {
131
131
  title: title(0),
132
- task: async (_ctx, task) => {
132
+ task: async (_, task) => {
133
133
  for (let i = 0; i < routesToPrerender.length; i++) {
134
134
  const routeToPrerender = routesToPrerender[i];
135
135
  if (routerPathFilter && routeToPrerender.path !== routerPathFilter) {
@@ -216,8 +216,11 @@ const diagnosticCheck = () => {
216
216
  console.log("\u2714 Diagnostics checks passed \n");
217
217
  }
218
218
  };
219
+ const hasUnexpandedPathParams = (routePath) => {
220
+ return /\{.*}/.test(routePath);
221
+ };
219
222
  const prerenderRoute = async (prerenderer, queryCache, routeToPrerender, dryrun, outputHtmlPath) => {
220
- if (/\{.*}/.test(routeToPrerender.path)) {
223
+ if (hasUnexpandedPathParams(routeToPrerender.path)) {
221
224
  throw new PathParamError(
222
225
  `Could not retrieve route parameters for ${routeToPrerender.path}`
223
226
  );
@@ -227,7 +230,7 @@ const prerenderRoute = async (prerenderer, queryCache, routeToPrerender, dryrun,
227
230
  queryCache,
228
231
  renderPath: routeToPrerender.path
229
232
  });
230
- if (!dryrun) {
233
+ if (!dryrun && typeof prerenderedHtml === "string") {
231
234
  prerenderer.writePrerenderedHtmlFile(outputHtmlPath, prerenderedHtml);
232
235
  }
233
236
  } catch (error) {
@@ -236,9 +239,8 @@ const prerenderRoute = async (prerenderer, queryCache, routeToPrerender, dryrun,
236
239
  c.warning("You can use `yarn cedar prerender --dry-run` to debug")
237
240
  );
238
241
  console.log();
239
- console.log(
240
- `${c.info("-".repeat(10))} Error rendering path "${routeToPrerender.path}" ${c.info("-".repeat(10))}`
241
- );
242
+ const sep = c.info("-".repeat(10));
243
+ console.log(`${sep} Error rendering path "${routeToPrerender.path}" ${sep}`);
242
244
  errorTelemetry(
243
245
  process.argv,
244
246
  `Error prerendering: ${getErrorMessage(error)}`
@@ -269,6 +271,7 @@ const handler = async ({
269
271
  const listrTasks = await getTasks(dryRun, routerPath ?? null);
270
272
  const tasks = new Listr(listrTasks, {
271
273
  renderer: verbose ? "verbose" : "default",
274
+ rendererOptions: { collapseSubtasks: false },
272
275
  concurrent: false
273
276
  });
274
277
  try {
@@ -289,7 +292,7 @@ const handler = async ({
289
292
  } else {
290
293
  console.log(
291
294
  c.info(
292
- `- This could mean that a library you're using does not support SSR.`
295
+ "- This could mean that a library you're using does not support SSR."
293
296
  )
294
297
  );
295
298
  console.log(
@@ -308,5 +311,7 @@ const handler = async ({
308
311
  }
309
312
  };
310
313
  export {
311
- handler
314
+ getTasks,
315
+ handler,
316
+ hasUnexpandedPathParams
312
317
  };
@@ -1,4 +1,4 @@
1
- import path from "path";
1
+ import path from "node:path";
2
2
  import concurrently from "concurrently";
3
3
  import execa from "execa";
4
4
  import { Listr } from "listr2";
@@ -48,9 +48,7 @@ const handler = async ({
48
48
  return conclusiveExitCode;
49
49
  };
50
50
  if (generate && prisma) {
51
- await generatePrismaClient({
52
- verbose
53
- });
51
+ await generatePrismaClient({ verbose });
54
52
  }
55
53
  if (generate) {
56
54
  await new Listr(
@@ -64,7 +62,8 @@ const handler = async ({
64
62
  }
65
63
  ],
66
64
  {
67
- renderer: verbose ? "verbose" : void 0
65
+ renderer: verbose ? "verbose" : "default",
66
+ rendererOptions: { collapseSubtasks: false }
68
67
  }
69
68
  ).run();
70
69
  }
@@ -331,6 +331,11 @@ async function updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }) {
331
331
  title: `Updating ${pkgJsonPath}`,
332
332
  task: async (_ctx, task) => {
333
333
  const res = await fetch(url);
334
+ if (!res.ok) {
335
+ throw new Error(
336
+ `Failed to fetch template package.json from ${url}: ` + res.statusText
337
+ );
338
+ }
334
339
  const text = await res.text();
335
340
  const templatePackageJson = JSON.parse(text);
336
341
  const localPackageJsonText = fs.readFileSync(pkgJsonPath, "utf-8");
@@ -380,16 +385,19 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
380
385
  throw new Error("Failed to upgrade");
381
386
  }
382
387
  const githubToken = process.env.GH_TOKEN || process.env.GITHUB_TOKEN || process.env.REDWOOD_GITHUB_TOKEN;
383
- const res = await fetch(
384
- "https://api.github.com/repos/cedarjs/cedar/git/trees/main?recursive=1",
385
- {
386
- headers: {
387
- ...githubToken && { Authorization: `Bearer ${githubToken}` },
388
- ["X-GitHub-Api-Version"]: "2022-11-28",
389
- Accept: "application/vnd.github+json"
390
- }
388
+ const url = "https://api.github.com/repos/cedarjs/cedar/git/trees/main?recursive=1";
389
+ const res = await fetch(url, {
390
+ headers: {
391
+ ...githubToken && { Authorization: `Bearer ${githubToken}` },
392
+ ["X-GitHub-Api-Version"]: "2022-11-28",
393
+ Accept: "application/vnd.github+json"
391
394
  }
392
- );
395
+ });
396
+ if (!res.ok) {
397
+ throw new Error(
398
+ `Failed to fetch list of yarn patches from ${url}: ` + res.statusText
399
+ );
400
+ }
393
401
  const json = await res.json();
394
402
  const patches = json.tree?.filter(
395
403
  (patchInfo) => patchInfo.path.startsWith(
@@ -409,6 +417,11 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
409
417
  title: `Downloading ${patch.path}`,
410
418
  task: async () => {
411
419
  const res2 = await fetch(patch.url);
420
+ if (!res2.ok) {
421
+ throw new Error(
422
+ `Failed to fetch patch metadata from ${patch.url}: ` + res2.statusText
423
+ );
424
+ }
412
425
  const patchMeta = await res2.json();
413
426
  const patchPath = path.join(
414
427
  getPaths().base,
@@ -20,8 +20,8 @@ const generatePrismaClient = async ({
20
20
  silent = false
21
21
  } = {}) => {
22
22
  if (!force) {
23
- const prismaClientPath = await resolveGeneratedPrismaClient();
24
- const prismaClientFile = prismaClientPath && fs.existsSync(prismaClientPath) ? fs.readFileSync(prismaClientPath, "utf8") : "";
23
+ const { clientPath } = await resolveGeneratedPrismaClient();
24
+ const prismaClientFile = clientPath && fs.existsSync(clientPath) ? fs.readFileSync(clientPath, "utf8") : "";
25
25
  if (!prismaClientFile.includes("@prisma/client did not initialize yet.") && prismaClientFile.includes("exports.Prisma.")) {
26
26
  return;
27
27
  }
@@ -117,9 +117,11 @@ const getCellGqlQuery = (ast) => {
117
117
  traverse(ast, {
118
118
  ExportNamedDeclaration({ node }) {
119
119
  if (node.exportKind === "value" && types.isVariableDeclaration(node.declaration)) {
120
- const exportedQueryNode = node.declaration.declarations.find((d) => {
121
- return types.isIdentifier(d.id) && d.id.name === "QUERY" && types.isTaggedTemplateExpression(d.init);
122
- });
120
+ const exportedQueryNode = node.declaration.declarations.find(
121
+ (d) => {
122
+ return types.isIdentifier(d.id) && d.id.name === "QUERY" && types.isTaggedTemplateExpression(d.init);
123
+ }
124
+ );
123
125
  if (exportedQueryNode) {
124
126
  const templateExpression = exportedQueryNode.init;
125
127
  cellQuery = templateExpression.quasi.quasis[0].value.raw;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "3.0.0-canary.13612+d0187ae49",
3
+ "version": "3.0.0-canary.13614+99cf90d23",
4
4
  "description": "The CedarJS Command Line",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,16 +33,16 @@
33
33
  "dependencies": {
34
34
  "@babel/parser": "7.29.0",
35
35
  "@babel/preset-typescript": "7.28.5",
36
- "@cedarjs/api-server": "3.0.0-canary.13612",
37
- "@cedarjs/cli-helpers": "3.0.0-canary.13612",
38
- "@cedarjs/fastify-web": "3.0.0-canary.13612",
39
- "@cedarjs/internal": "3.0.0-canary.13612",
40
- "@cedarjs/prerender": "3.0.0-canary.13612",
41
- "@cedarjs/project-config": "3.0.0-canary.13612",
42
- "@cedarjs/structure": "3.0.0-canary.13612",
43
- "@cedarjs/telemetry": "3.0.0-canary.13612",
44
- "@cedarjs/utils": "3.0.0-canary.13612",
45
- "@cedarjs/web-server": "3.0.0-canary.13612",
36
+ "@cedarjs/api-server": "3.0.0-canary.13614",
37
+ "@cedarjs/cli-helpers": "3.0.0-canary.13614",
38
+ "@cedarjs/fastify-web": "3.0.0-canary.13614",
39
+ "@cedarjs/internal": "3.0.0-canary.13614",
40
+ "@cedarjs/prerender": "3.0.0-canary.13614",
41
+ "@cedarjs/project-config": "3.0.0-canary.13614",
42
+ "@cedarjs/structure": "3.0.0-canary.13614",
43
+ "@cedarjs/telemetry": "3.0.0-canary.13614",
44
+ "@cedarjs/utils": "3.0.0-canary.13614",
45
+ "@cedarjs/web-server": "3.0.0-canary.13614",
46
46
  "@listr2/prompt-adapter-enquirer": "4.2.1",
47
47
  "@opentelemetry/api": "1.9.0",
48
48
  "@opentelemetry/core": "1.30.1",
@@ -105,5 +105,5 @@
105
105
  "publishConfig": {
106
106
  "access": "public"
107
107
  },
108
- "gitHead": "d0187ae49d6230bf844cb017d87bce7c49b9140c"
108
+ "gitHead": "99cf90d2348c5ba8f3f2f6883bfb629566114ad5"
109
109
  }