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

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 -13
  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
@@ -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
  };
@@ -51,16 +51,23 @@ const PLUGIN_CACHE_BUILTIN = [
51
51
  "tc",
52
52
  "upgrade"
53
53
  ];
54
+ function isErrorWithCode(error, code) {
55
+ return typeof error === "object" && error !== null && "code" in error && error.code === code;
56
+ }
54
57
  function loadCommandCache() {
55
- let pluginCommandCache = PLUGIN_CACHE_DEFAULT;
58
+ let pluginCommandCache = { ...PLUGIN_CACHE_DEFAULT };
56
59
  const commandCachePath = path.join(
57
60
  getPaths().generated.base,
58
61
  PLUGIN_CACHE_FILENAME
59
62
  );
60
63
  try {
61
- const localCommandCache = JSON.parse(fs.readFileSync(commandCachePath));
64
+ const localCommandCache = JSON.parse(
65
+ fs.readFileSync(commandCachePath, "utf8")
66
+ );
62
67
  let valid = true;
63
- for (const [key, value] of Object.entries(localCommandCache)) {
68
+ for (const [key, value] of Object.entries(
69
+ localCommandCache
70
+ )) {
64
71
  if (key === "_builtin") {
65
72
  continue;
66
73
  }
@@ -73,7 +80,7 @@ function loadCommandCache() {
73
80
  };
74
81
  }
75
82
  } catch (error) {
76
- if (error.code !== "ENOENT") {
83
+ if (!isErrorWithCode(error, "ENOENT")) {
77
84
  console.error(`Error loading plugin command cache at ${commandCachePath}`);
78
85
  console.error(error);
79
86
  }
@@ -162,7 +169,7 @@ async function installPluginPackage(packageName, packageVersion) {
162
169
  console.log(
163
170
  "The following error occurred while checking plugin compatibility for automatic installation:"
164
171
  );
165
- const errorMessage = error.message ?? error;
172
+ const errorMessage = error instanceof Error ? error.message : String(error);
166
173
  console.log(errorMessage);
167
174
  if (errorMessage.includes("does not have a tag") || errorMessage.includes("does not have a version")) {
168
175
  process.exit(1);
@@ -33,7 +33,7 @@ To continue, the generator requires a unique plural form:`;
33
33
  const destroyMessage = `Cannot determine the plural of "${model}" originally used to generate the files.
34
34
  To continue, the destroy command requires the plural form:`;
35
35
  const promptMessage = isDestroyer ? destroyMessage : generateMessage;
36
- const initialPlural = model.slice(-1) === "s" ? `${model}es` : `${model}s`;
36
+ const initialPlural = model.endsWith("s") ? `${model}es` : `${model}s`;
37
37
  const promptResult = await prompts({
38
38
  type: "text",
39
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
  }
@@ -9,13 +9,13 @@ const getExistingModelName = async (name) => {
9
9
  return void 0;
10
10
  }
11
11
  const modelName = name.replace(/[_-]/g, "").toLowerCase();
12
- for (let model of Object.values(schemaMemo)) {
12
+ for (const model of Object.values(schemaMemo)) {
13
13
  if (model.name.toLowerCase() === modelName) {
14
14
  return model.name;
15
15
  }
16
16
  }
17
17
  const schema = (await getSchemaDefinitions()).datamodel;
18
- for (let model of schema.models) {
18
+ for (const model of schema.models) {
19
19
  if (model.name.toLowerCase() === modelName) {
20
20
  return model.name;
21
21
  }
@@ -36,25 +36,24 @@ const getSchema = async (name) => {
36
36
  if (schemaMemo[modelName]) {
37
37
  return schemaMemo[modelName];
38
38
  }
39
- const model = schema.models.find((model2) => model2.name === modelName);
39
+ const model = schema.models.find((m) => m.name === modelName);
40
40
  if (!model) {
41
41
  return void 0;
42
42
  }
43
- model.fields.forEach((field) => {
43
+ const enrichedFields = model.fields.map((field) => {
44
44
  const fieldEnum = schema.enums.find((e) => field.type === e.name);
45
- if (fieldEnum) {
46
- field.enumValues = fieldEnum.values;
47
- }
45
+ return fieldEnum ? { ...field, enumValues: fieldEnum.values } : { ...field };
48
46
  });
49
- schemaMemo[modelName] = model;
50
- return model;
47
+ const enrichedModel = { ...model, fields: enrichedFields };
48
+ schemaMemo[modelName] = enrichedModel;
49
+ return enrichedModel;
51
50
  };
52
51
  const getEnum = async (name) => {
53
52
  const schema = await getSchemaDefinitions();
54
53
  if (!name) {
55
- return schema.metadata.datamodel.enums;
54
+ return [...schema.metadata.datamodel.enums];
56
55
  }
57
- const model = schema.datamodel.enums.find((model2) => model2.name === name);
56
+ const model = schema.datamodel.enums.find((e) => e.name === name);
58
57
  if (!model) {
59
58
  throw new Error(
60
59
  `No enum schema definition found for \`${name}\` in schema.prisma file`
@@ -67,7 +66,8 @@ const getDataModel = async () => {
67
66
  return result.schemas;
68
67
  };
69
68
  const getSchemaDefinitions = async () => {
70
- return getDMMF({ datamodel: await getDataModel() });
69
+ const document = await getDMMF({ datamodel: await getDataModel() });
70
+ return document;
71
71
  };
72
72
  const getSchemaConfig = async () => {
73
73
  return getConfig({
package/dist/lib/test.js CHANGED
@@ -76,6 +76,10 @@ vi.mock("@cedarjs/project-config", async (importOriginal) => {
76
76
  }
77
77
  };
78
78
  });
79
+ vi.mock("@cedarjs/project-config/packageManager", () => ({
80
+ getPackageManager: vi.fn(() => "yarn"),
81
+ resetPackageManagerCache: vi.fn()
82
+ }));
79
83
  vi.mock("@cedarjs/cli-helpers", async (importOriginal) => {
80
84
  const originalCliHelpers = await importOriginal();
81
85
  return {
@@ -4,6 +4,8 @@ import ansis from "ansis";
4
4
  import boxen from "boxen";
5
5
  import latestVersion from "latest-version";
6
6
  import semver from "semver";
7
+ import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
8
+ import { getNodeRunnerArgs } from "@cedarjs/cli-helpers/packageManager/exec";
7
9
  import { getConfig } from "@cedarjs/project-config";
8
10
  import { spawnBackgroundProcess } from "./background.js";
9
11
  import { isLockSet, setLock, unsetLock } from "./locking.js";
@@ -88,7 +90,7 @@ function getUpdateMessage() {
88
90
  const data = readUpdateDataFile();
89
91
  const localTag = extractTagFromVersion(data.localVersion) || "latest";
90
92
  let updateCount = 0;
91
- let message = " New updates to Cedar are available via `yarn cedar upgrade#REPLACEME#` ";
93
+ let message = ` New updates to Cedar are available via \`${formatCedarCommand(["upgrade#REPLACEME#"])}\` `;
92
94
  data.remoteVersions.forEach((version, tag) => {
93
95
  if (semver.gt(version, data.localVersion)) {
94
96
  updateCount += 1;
@@ -182,10 +184,10 @@ function updateCheckMiddleware(argv) {
182
184
  }
183
185
  if (shouldCheck()) {
184
186
  setLock(CHECK_LOCK_IDENTIFIER);
185
- spawnBackgroundProcess("updateCheck", "yarn", [
186
- "node",
187
+ const [bgCmd, bgCmdArgs] = getNodeRunnerArgs(
187
188
  path.join(import.meta.dirname, "updateCheckExecute.js")
188
- ]);
189
+ );
190
+ spawnBackgroundProcess("updateCheck", bgCmd, bgCmdArgs);
189
191
  } else if (shouldShow()) {
190
192
  setLock(SHOW_LOCK_IDENTIFIER);
191
193
  process.on("exit", () => {
@@ -5,6 +5,11 @@ function checkNodeVersion() {
5
5
  const pVersion = process.version;
6
6
  const pVersionC = semver.clean(pVersion);
7
7
  const LOWER_BOUND = "v24.0.0";
8
+ if (!pVersionC) {
9
+ checks.ok = false;
10
+ checks.message = `Invalid Node.js version: ${pVersion}`;
11
+ return checks;
12
+ }
8
13
  if (semver.gte(pVersionC, LOWER_BOUND)) {
9
14
  return checks;
10
15
  }
package/dist/plugin.js CHANGED
@@ -59,8 +59,6 @@ async function loadPlugins(yargs) {
59
59
  yargs.command({
60
60
  command: `${namespace} <command>`,
61
61
  describe: `Commands from ${namespace}`,
62
- builder: () => {
63
- },
64
62
  handler: () => {
65
63
  }
66
64
  });
@@ -97,6 +95,7 @@ async function loadPlugins(yargs) {
97
95
  describe: `Commands from ${namespaceInUse}`,
98
96
  builder: (yargs2) => {
99
97
  yargs2.command(commands).demandCommand();
98
+ return yargs2;
100
99
  },
101
100
  handler: () => {
102
101
  }
@@ -108,7 +107,7 @@ async function loadPlugins(yargs) {
108
107
  }
109
108
  const packagesToLoad = /* @__PURE__ */ new Set();
110
109
  for (const [packageName, cacheEntry] of Object.entries(pluginCommandCache)) {
111
- if (packageName === "_builtin") {
110
+ if (packageName === "_builtin" || Array.isArray(cacheEntry)) {
112
111
  continue;
113
112
  }
114
113
  const commandFirstWords = [];
@@ -134,6 +133,9 @@ async function loadPlugins(yargs) {
134
133
  const commandsToRegister = [];
135
134
  if (foundMatchingPackage) {
136
135
  const packageToLoad = packagesToLoad.values().next().value;
136
+ if (!packageToLoad) {
137
+ throw new Error(`Invalid first value in ${packagesToLoad}`);
138
+ }
137
139
  const commands = await loadCommandsFromCacheOrPackage(
138
140
  packageToLoad,
139
141
  pluginCommandCache,
@@ -160,6 +162,7 @@ async function loadPlugins(yargs) {
160
162
  describe: `Commands from ${namespaceInUse}`,
161
163
  builder: (yargs2) => {
162
164
  yargs2.command(commandsToRegister).demandCommand();
165
+ return yargs2;
163
166
  },
164
167
  handler: () => {
165
168
  }
@@ -173,8 +176,6 @@ async function loadPlugins(yargs) {
173
176
  yargs.command({
174
177
  command: `${namespace} <command>`,
175
178
  describe: `Commands from ${namespace}`,
176
- builder: () => {
177
- },
178
179
  handler: () => {
179
180
  }
180
181
  });
@@ -185,24 +186,29 @@ async function loadPlugins(yargs) {
185
186
  }
186
187
  async function loadCommandsFromCacheOrPackage(packageName, cache, autoInstall, readFromCache) {
187
188
  let cacheEntry = void 0;
188
- if (readFromCache) {
189
- cacheEntry = cache !== void 0 ? cache[packageName] : void 0;
189
+ if (readFromCache && cache) {
190
+ const entry = cache[packageName];
191
+ if (entry && !Array.isArray(entry)) {
192
+ cacheEntry = entry;
193
+ }
190
194
  }
191
195
  if (cacheEntry !== void 0) {
192
196
  const commands = Object.entries(cacheEntry).map(([command, info]) => {
193
197
  return {
194
198
  command,
195
199
  describe: info.description,
196
- aliases: info.aliases
200
+ aliases: info.aliases,
201
+ handler: () => {
202
+ }
197
203
  };
198
204
  });
199
205
  return commands;
200
206
  }
201
207
  const plugin = await loadPluginPackage(packageName, void 0, autoInstall);
202
208
  if (plugin) {
203
- const commands = plugin.commands ?? [];
209
+ const rawCommands = plugin.commands ?? [];
204
210
  const cacheUpdate = {};
205
- for (const command of commands) {
211
+ for (const command of rawCommands) {
206
212
  const info = {
207
213
  aliases: command.aliases,
208
214
  description: command.description
@@ -211,10 +217,10 @@ async function loadCommandsFromCacheOrPackage(packageName, cache, autoInstall, r
211
217
  cacheUpdate[command.command] = info;
212
218
  }
213
219
  }
214
- if (Object.keys(cacheUpdate).length > 0) {
220
+ if (cache && Object.keys(cacheUpdate).length > 0) {
215
221
  cache[packageName] = cacheUpdate;
216
222
  }
217
- return commands;
223
+ return plugin.commands ?? [];
218
224
  }
219
225
  return [];
220
226
  }
@@ -32,19 +32,26 @@ class CustomFileExporter {
32
32
  * @param spans the list of sampled Spans to be exported.
33
33
  */
34
34
  export(spans, resultCallback) {
35
- for (let i = 0; i < spans.length; i++) {
36
- const span = spans[i];
37
- delete span["_spanProcessor"];
35
+ for (const span of spans) {
38
36
  fs.appendFileSync(
39
37
  this.#storageFilePath,
40
- JSON.stringify(span, void 0, 2)
38
+ JSON.stringify(
39
+ span,
40
+ (key, value) => {
41
+ if (key === "_spanProcessor") {
42
+ return void 0;
43
+ }
44
+ return value;
45
+ },
46
+ 2
47
+ )
41
48
  );
42
49
  fs.appendFileSync(this.#storageFilePath, ",");
43
50
  }
44
51
  resultCallback({ code: 0 });
45
52
  }
46
53
  /** Stops the exporter. */
47
- shutdown() {
54
+ async shutdown() {
48
55
  if (!this.#isShutdown) {
49
56
  fs.truncateSync(
50
57
  this.#storageFilePath,
@@ -7,6 +7,7 @@ import {
7
7
  SamplingDecision
8
8
  } from "@opentelemetry/sdk-trace-node";
9
9
  import { hideBin } from "yargs/helpers";
10
+ import { getNodeRunnerArgs } from "@cedarjs/cli-helpers/packageManager/exec";
10
11
  import { spawnBackgroundProcess } from "../lib/background.js";
11
12
  import { CustomFileExporter } from "./exporter.js";
12
13
  let traceProvider;
@@ -69,10 +70,10 @@ function shutdownTelemetry() {
69
70
  opentelemetry.trace.getActiveSpan()?.end();
70
71
  }
71
72
  traceExporter?.shutdown();
72
- spawnBackgroundProcess("telemetry", "yarn", [
73
- "node",
73
+ const [cmd, args] = getNodeRunnerArgs(
74
74
  path.join(import.meta.dirname, "send.js")
75
- ]);
75
+ );
76
+ spawnBackgroundProcess("telemetry", cmd, args);
76
77
  } catch (error) {
77
78
  console.error("Telemetry error");
78
79
  console.error(error);