@cedarjs/cli 5.0.0-canary.2331 → 5.0.0-canary.2333

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.
@@ -104,12 +104,17 @@ const handler = async ({
104
104
  }
105
105
  }
106
106
  if (workspace.includes("api")) {
107
- try {
108
- await generatePrismaClient({ verbose: false, force: false });
109
- } catch (e) {
110
- const message = getErrorMessage(e);
111
- errorTelemetry(process.argv, `Error generating prisma client: ${message}`);
112
- console.error(c.error(message));
107
+ if (generate) {
108
+ try {
109
+ await generatePrismaClient({ verbose: false });
110
+ } catch (e) {
111
+ const message = getErrorMessage(e);
112
+ errorTelemetry(
113
+ process.argv,
114
+ `Error generating prisma client: ${message}`
115
+ );
116
+ console.error(c.error(message));
117
+ }
113
118
  }
114
119
  if (!ud && !serverFile) {
115
120
  try {
@@ -65,7 +65,6 @@ No script called \`${name}\` in the ./scripts folder.
65
65
  title: "Generating Prisma client",
66
66
  enabled: () => !!prisma,
67
67
  task: () => generatePrismaClient({
68
- force: false,
69
68
  verbose: !args.silent,
70
69
  silent: !!args.silent
71
70
  })
@@ -440,7 +440,7 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
440
440
  }
441
441
  async function refreshPrismaClient(task, { verbose }) {
442
442
  try {
443
- await generatePrismaClient({ verbose, force: false });
443
+ await generatePrismaClient({ verbose, force: true });
444
444
  } catch (e) {
445
445
  const message = e instanceof Error ? e.message : String(e);
446
446
  task.skip("Refreshing the Prisma client caused an Error.");
@@ -1,8 +1,11 @@
1
+ import { createHash } from "node:crypto";
1
2
  import fs from "node:fs";
2
3
  import { createRequire } from "node:module";
3
- import { resolveGeneratedPrismaClient } from "@cedarjs/project-config";
4
+ import path from "node:path";
5
+ import { getConfig, getPrismaSchemas } from "@cedarjs/project-config";
4
6
  import { runCommandTask, getPaths } from "./index.js";
5
7
  const generatePrismaCommand = async () => {
8
+ const config = getConfig();
6
9
  const createdRequire = createRequire(import.meta.url);
7
10
  const prismaIndexPath = createdRequire.resolve("prisma/build/index.js");
8
11
  return {
@@ -10,19 +13,52 @@ const generatePrismaCommand = async () => {
10
13
  args: [
11
14
  prismaIndexPath,
12
15
  "generate",
13
- `--config=${getPaths().api.prismaConfig}`
16
+ `--config=${getPaths().api.prismaConfig}`,
17
+ ...config.api.prismaGenerateArgs
14
18
  ]
15
19
  };
16
20
  };
17
- const generatePrismaClient = async ({
21
+ async function computePrismaSchemaHash() {
22
+ try {
23
+ const hash = createHash("sha256");
24
+ const configPath = getPaths().api.prismaConfig;
25
+ if (fs.existsSync(configPath)) {
26
+ hash.update(fs.readFileSync(configPath));
27
+ }
28
+ const { schemas } = await getPrismaSchemas();
29
+ for (const schema of schemas) {
30
+ hash.update(schema[1]);
31
+ }
32
+ return hash.digest("hex");
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
37
+ function getHashFilePath() {
38
+ const generatedBase = getPaths().generated.base;
39
+ return path.join(generatedBase, "prisma-schema-hash");
40
+ }
41
+ function getStoredSchemaHash() {
42
+ const hashFile = getHashFilePath();
43
+ if (fs.existsSync(hashFile)) {
44
+ return fs.readFileSync(hashFile, "utf-8").trim();
45
+ }
46
+ return null;
47
+ }
48
+ function storeSchemaHash(hash) {
49
+ const hashFile = getHashFilePath();
50
+ fs.mkdirSync(path.dirname(hashFile), { recursive: true });
51
+ fs.writeFileSync(hashFile, hash);
52
+ }
53
+ async function generatePrismaClient({
18
54
  verbose = true,
19
- force = true,
55
+ force = false,
20
56
  silent = false
21
- } = {}) => {
57
+ } = {}) {
58
+ const hash = await computePrismaSchemaHash();
22
59
  if (!force) {
23
- const { clientPath } = await resolveGeneratedPrismaClient();
24
- const prismaClientFile = clientPath && fs.existsSync(clientPath) ? fs.readFileSync(clientPath, "utf8") : "";
25
- if (!prismaClientFile.includes("@prisma/client did not initialize yet.") && prismaClientFile.includes("exports.Prisma.")) {
60
+ const storedHash = hash ? getStoredSchemaHash() : null;
61
+ if (hash !== null && hash === storedHash) {
26
62
  return;
27
63
  }
28
64
  }
@@ -38,7 +74,10 @@ const generatePrismaClient = async ({
38
74
  silent
39
75
  }
40
76
  );
41
- };
77
+ if (hash !== null) {
78
+ storeSchemaHash(hash);
79
+ }
80
+ }
42
81
  export {
43
82
  generatePrismaClient,
44
83
  generatePrismaCommand
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "5.0.0-canary.2331",
3
+ "version": "5.0.0-canary.2333",
4
4
  "description": "The CedarJS Command Line",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,17 +33,17 @@
33
33
  "dependencies": {
34
34
  "@babel/parser": "7.29.3",
35
35
  "@babel/preset-typescript": "7.28.5",
36
- "@cedarjs/api-server": "5.0.0-canary.2331",
37
- "@cedarjs/cli-helpers": "5.0.0-canary.2331",
38
- "@cedarjs/fastify-web": "5.0.0-canary.2331",
39
- "@cedarjs/internal": "5.0.0-canary.2331",
40
- "@cedarjs/prerender": "5.0.0-canary.2331",
41
- "@cedarjs/project-config": "5.0.0-canary.2331",
42
- "@cedarjs/structure": "5.0.0-canary.2331",
43
- "@cedarjs/telemetry": "5.0.0-canary.2331",
44
- "@cedarjs/utils": "5.0.0-canary.2331",
45
- "@cedarjs/vite": "5.0.0-canary.2331",
46
- "@cedarjs/web-server": "5.0.0-canary.2331",
36
+ "@cedarjs/api-server": "5.0.0-canary.2333",
37
+ "@cedarjs/cli-helpers": "5.0.0-canary.2333",
38
+ "@cedarjs/fastify-web": "5.0.0-canary.2333",
39
+ "@cedarjs/internal": "5.0.0-canary.2333",
40
+ "@cedarjs/prerender": "5.0.0-canary.2333",
41
+ "@cedarjs/project-config": "5.0.0-canary.2333",
42
+ "@cedarjs/structure": "5.0.0-canary.2333",
43
+ "@cedarjs/telemetry": "5.0.0-canary.2333",
44
+ "@cedarjs/utils": "5.0.0-canary.2333",
45
+ "@cedarjs/vite": "5.0.0-canary.2333",
46
+ "@cedarjs/web-server": "5.0.0-canary.2333",
47
47
  "@listr2/prompt-adapter-enquirer": "4.2.1",
48
48
  "@opentelemetry/api": "1.9.0",
49
49
  "@opentelemetry/core": "1.30.1",