@cedarjs/cli 5.0.0-canary.2560 → 5.0.0-canary.2561

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.
@@ -78,7 +78,7 @@ const builder = (yargs) => {
78
78
  });
79
79
  yargs.epilogue(
80
80
  `Also see the ${terminalLink(
81
- "Redwood Baremetal Deploy Reference",
81
+ "Cedar Baremetal Deploy Reference",
82
82
  "https://cedarjs.com/docs/cli-commands#deploy"
83
83
  )}
84
84
  `
@@ -100,7 +100,10 @@ async function handler(yargs) {
100
100
  verbose: yargs.verbose,
101
101
  gitCheck: yargs.gitCheck
102
102
  });
103
- const { handler: baremetalHandler } = await import("./baremetal/baremetalHandler.js");
103
+ const { handler: baremetalHandler } = (
104
+ // @ts-expect-error - baremetalHandler.js has no type declarations yet
105
+ await import("./baremetal/baremetalHandler.js")
106
+ );
104
107
  return baremetalHandler(yargs);
105
108
  }
106
109
  export {
@@ -52,10 +52,9 @@ async function packageSingleFunction(functionFile) {
52
52
  recursive: true,
53
53
  force: true
54
54
  });
55
- return;
56
55
  }
57
56
  function nftPack() {
58
- const filesToBePacked = findApiDistFunctions();
57
+ const filesToBePacked = findApiDistFunctions({ cwd: getPaths().api.base });
59
58
  return Promise.all(filesToBePacked.map(nftPacker.packageSingleFunction));
60
59
  }
61
60
  export {
@@ -30,7 +30,9 @@ Please run ${formatAddRootPackagesCommand(["serverless"], true)}.`
30
30
  }
31
31
  }
32
32
  ];
33
- const buildCommands = ({ sides }) => {
33
+ const buildCommands = ({
34
+ sides
35
+ }) => {
34
36
  return [
35
37
  {
36
38
  title: `Building ${sides.join(" & ")}...`,
@@ -48,7 +50,12 @@ const buildCommands = ({ sides }) => {
48
50
  }
49
51
  ];
50
52
  };
51
- const deployCommands = ({ stage, sides, firstRun, packOnly }) => {
53
+ const deployCommands = ({
54
+ stage,
55
+ sides,
56
+ firstRun,
57
+ packOnly
58
+ }) => {
52
59
  const slsStage = stage ? ["--stage", stage] : [];
53
60
  return sides.map((side) => {
54
61
  return {
@@ -68,6 +75,7 @@ const deployCommands = ({ stage, sides, firstRun, packOnly }) => {
68
75
  if (packOnly) {
69
76
  return "Finishing early due to --pack-only flag. Your Redwood project is packaged and ready to deploy";
70
77
  }
78
+ return false;
71
79
  }
72
80
  };
73
81
  });
@@ -92,13 +100,13 @@ const handler = async (yargs) => {
92
100
  loadDotEnvForStage(dotEnvPath);
93
101
  const tasks = new Listr(
94
102
  [
95
- ...preRequisites(yargs).map(mapCommandsToListr),
103
+ ...preRequisites().map(mapCommandsToListr),
96
104
  ...buildCommands(yargs).map(mapCommandsToListr),
97
105
  ...deployCommands(yargs).map(mapCommandsToListr)
98
106
  ],
99
107
  {
100
108
  exitOnError: true,
101
- renderer: yargs.verbose && "verbose"
109
+ renderer: yargs.verbose ? "verbose" : void 0
102
110
  }
103
111
  );
104
112
  try {
@@ -115,7 +123,13 @@ const handler = async (yargs) => {
115
123
  cwd: getPaths().api.base
116
124
  }
117
125
  );
118
- const deployedApiUrl = slsInfo.match(/HttpApiUrl: (https:\/\/.*)/)[1];
126
+ const apiMatch = slsInfo.match(/HttpApiUrl: (https:\/\/.*)/);
127
+ if (!apiMatch) {
128
+ throw new Error(
129
+ "Could not find HttpApiUrl in serverless info output. Deploy may have failed."
130
+ );
131
+ }
132
+ const deployedApiUrl = apiMatch[1];
119
133
  console.log();
120
134
  console.log(SETUP_MARKER, `Found ${c.success(deployedApiUrl)}`);
121
135
  console.log();
@@ -139,7 +153,7 @@ const handler = async (yargs) => {
139
153
  const webDeployTasks = new Listr(
140
154
  [
141
155
  // Rebuild web with the new API_URL
142
- ...buildCommands({ ...yargs, sides: ["web"], firstRun: false }).map(
156
+ ...buildCommands({ ...yargs, sides: ["web"] }).map(
143
157
  mapCommandsToListr
144
158
  ),
145
159
  ...deployCommands({
@@ -150,11 +164,11 @@ const handler = async (yargs) => {
150
164
  ],
151
165
  {
152
166
  exitOnError: true,
153
- renderer: yargs.verbose && "verbose"
167
+ renderer: yargs.verbose ? "verbose" : void 0
154
168
  }
155
169
  );
156
170
  await webDeployTasks.run();
157
- const { stdout: slsInfo2 } = await runBin(
171
+ const { stdout: webSlsInfo } = await runBin(
158
172
  "serverless",
159
173
  ["info", "--verbose", `--stage=${yargs.stage}`],
160
174
  {
@@ -162,7 +176,13 @@ const handler = async (yargs) => {
162
176
  cwd: getPaths().web.base
163
177
  }
164
178
  );
165
- const deployedWebUrl = slsInfo2.match(/url: (https:\/\/.*)/)[1];
179
+ const webMatch = webSlsInfo.match(/url: (https:\/\/.*)/);
180
+ if (!webMatch) {
181
+ throw new Error(
182
+ "Could not find url in serverless info output. Deploy may have failed."
183
+ );
184
+ }
185
+ const deployedWebUrl = webMatch[1];
166
186
  const message = [
167
187
  c.bold("Successful first deploy!"),
168
188
  "",
@@ -184,8 +204,9 @@ const handler = async (yargs) => {
184
204
  }
185
205
  }
186
206
  } catch (e) {
187
- console.error(c.error(e.message));
188
- process.exit(e?.exitCode || 1);
207
+ console.error(c.error(e instanceof Error ? e.message : String(e)));
208
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
209
+ process.exit(exitCode);
189
210
  }
190
211
  };
191
212
  const mapCommandsToListr = ({
@@ -201,14 +222,19 @@ const mapCommandsToListr = ({
201
222
  title,
202
223
  task: task ? task : async () => {
203
224
  try {
204
- const executingCommand = execa(...command, {
225
+ if (!command) {
226
+ throw new Error(
227
+ "No command or task provided to mapCommandsToListr"
228
+ );
229
+ }
230
+ const executingCommand = execa(command[0], command[1], {
205
231
  cwd: cwd || getPaths().base,
206
232
  shell: true
207
233
  });
208
- executingCommand.stdout.pipe(process.stdout);
234
+ executingCommand.stdout?.pipe(process.stdout);
209
235
  await executingCommand;
210
236
  } catch (error) {
211
- if (errorMessage) {
237
+ if (errorMessage && error instanceof Error) {
212
238
  error.message = error.message + "\n" + errorMessage.join(" ");
213
239
  }
214
240
  throw error;
@@ -72,9 +72,11 @@ const handler = async ({ force }) => {
72
72
  try {
73
73
  await tasks.run();
74
74
  } catch (e) {
75
- errorTelemetry(process.argv, e.message);
76
- console.error(c.error(e.message));
77
- process.exit(e?.exitCode || 1);
75
+ const message = e instanceof Error ? e.message : String(e);
76
+ errorTelemetry(process.argv, message);
77
+ console.error(c.error(message));
78
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
79
+ process.exit(exitCode);
78
80
  }
79
81
  };
80
82
  export {
@@ -132,9 +132,11 @@ const handler = async ({ force }) => {
132
132
  try {
133
133
  await tasks.run();
134
134
  } catch (e) {
135
- errorTelemetry(process.argv, e.message);
136
- console.error(c.error(e.message));
137
- process.exit(e?.exitCode || 1);
135
+ const message = e instanceof Error ? e.message : String(e);
136
+ errorTelemetry(process.argv, message);
137
+ console.error(c.error(message));
138
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
139
+ process.exit(exitCode);
138
140
  }
139
141
  };
140
142
  export {
@@ -54,6 +54,7 @@ const tasks = async ({ force }) => {
54
54
  if (modelExists) {
55
55
  return "BackgroundJob model exists, skipping";
56
56
  }
57
+ return false;
57
58
  }
58
59
  },
59
60
  {
@@ -113,7 +114,7 @@ const tasks = async ({ force }) => {
113
114
  }
114
115
  }
115
116
  ],
116
- { rendererOptions: { collapseSubtasks: false }, errorOnExist: true }
117
+ { rendererOptions: { collapseSubtasks: false }, exitOnError: true }
117
118
  );
118
119
  };
119
120
  const handler = async ({ force }) => {
@@ -121,7 +122,7 @@ const handler = async ({ force }) => {
121
122
  try {
122
123
  await t.run();
123
124
  } catch (e) {
124
- console.error(c.error(e.message));
125
+ console.error(c.error(e instanceof Error ? e.message : String(e)));
125
126
  }
126
127
  };
127
128
  export {
@@ -10,7 +10,10 @@ const CHAKRA_THEME_AND_COMMENTS = `// This object will be used to override Chakr
10
10
  const theme = {}
11
11
  export default theme
12
12
  `;
13
- async function handler({ force, install }) {
13
+ async function handler({
14
+ force,
15
+ install
16
+ }) {
14
17
  recordTelemetryAttributes({
15
18
  command: "setup ui chakra-ui",
16
19
  force,
@@ -90,8 +93,9 @@ async function handler({ force, install }) {
90
93
  try {
91
94
  await tasks.run();
92
95
  } catch (e) {
93
- console.error(c.error(e.message));
94
- process.exit(e?.exitCode || 1);
96
+ console.error(c.error(e instanceof Error ? e.message : String(e)));
97
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
98
+ process.exit(exitCode);
95
99
  }
96
100
  }
97
101
  export {
@@ -30,7 +30,11 @@ const theme = {}
30
30
 
31
31
  export default createTheme(theme)
32
32
  `;
33
- async function handler({ force, install, packages }) {
33
+ async function handler({
34
+ force,
35
+ install,
36
+ packages
37
+ }) {
34
38
  recordTelemetryAttributes({
35
39
  command: "setup ui mantine",
36
40
  force,
@@ -113,7 +117,10 @@ async function handler({ force, install, packages }) {
113
117
  },
114
118
  {
115
119
  title: "Configure Storybook...",
116
- skip: () => fileIncludes(cedarPaths.web.storybookPreviewConfig, "withMantine"),
120
+ skip: () => {
121
+ const previewConfig = cedarPaths.web.storybookPreviewConfig;
122
+ return previewConfig != null ? fileIncludes(previewConfig, "withMantine") : false;
123
+ },
117
124
  task: async () => await extendStorybookConfiguration(
118
125
  path.join(
119
126
  import.meta.dirname,
@@ -129,8 +136,9 @@ async function handler({ force, install, packages }) {
129
136
  try {
130
137
  await tasks.run();
131
138
  } catch (e) {
132
- console.error(c.error(e.message));
133
- process.exit(e?.exitCode || 1);
139
+ console.error(c.error(e instanceof Error ? e.message : String(e)));
140
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
141
+ process.exit(exitCode);
134
142
  }
135
143
  }
136
144
  export {
@@ -8,9 +8,6 @@ import { forEachFunctionOn, nodeIs } from "./algorithms.js";
8
8
  import { semanticIdentity } from "./semanticIdentity.js";
9
9
  import { isOpaque } from "./strategy.js";
10
10
  function extractProperty(property, fromObject) {
11
- if (property === void 0) {
12
- return void 0;
13
- }
14
11
  const tmp = fromObject[property];
15
12
  delete fromObject[property];
16
13
  return tmp;
@@ -29,7 +26,7 @@ function getProgramPath(ast) {
29
26
  return programPath;
30
27
  }
31
28
  function skipChildren(path) {
32
- for (const key of VISITOR_KEYS[path.type]) {
29
+ for (const key of VISITOR_KEYS[path.type] ?? []) {
33
30
  path.skipKey(key);
34
31
  }
35
32
  }
@@ -46,6 +43,7 @@ function makeProxy(path) {
46
43
  if (property === "path") {
47
44
  throw new Error("You can't set a path on a proxy!");
48
45
  } else {
46
+ ;
49
47
  target.node[property] = value;
50
48
  return true;
51
49
  }
@@ -59,7 +57,7 @@ function expressionUses(exp, ...ids) {
59
57
  let result = false;
60
58
  exp.traverse({
61
59
  Identifier(path) {
62
- if (!path.parentPath.isNodeType("VariableDeclarator") && ids.includes(path.node.name)) {
60
+ if (!path.parentPath?.isNodeType("VariableDeclarator") && ids.includes(path.node.name)) {
63
61
  result = true;
64
62
  return;
65
63
  }
@@ -69,23 +67,36 @@ function expressionUses(exp, ...ids) {
69
67
  }
70
68
  function insertBeforeFirstUsage(expression, program) {
71
69
  const body = program.get("body");
72
- const pos = body.findIndex(
73
- (exp) => expressionUses(exp, ...Object.keys(expression.getBindingIdentifiers()))
70
+ const bindingIds = Object.keys(
71
+ expression.getBindingIdentifiers()
74
72
  );
75
- return pos !== -1 ? body[pos].insertBefore(expression.node) : program.pushContainer("body", expression.node);
73
+ const pos = body.findIndex((exp) => expressionUses(exp, ...bindingIds));
74
+ if (pos !== -1) {
75
+ return body[pos].insertBefore(expression.node);
76
+ } else {
77
+ return program.pushContainer("body", expression.node);
78
+ }
76
79
  }
77
80
  function insertAfterLastImport(expression, program) {
78
81
  const body = program.get("body");
79
- return body[body.findLastIndex((bodyExpr) => bodyExpr.isNodeType("ImportDeclaration"))].insertAfter(expression.node);
82
+ let lastImportIdx = -1;
83
+ for (let i = 0; i < body.length; i++) {
84
+ if (body[i].isNodeType("ImportDeclaration")) {
85
+ lastImportIdx = i;
86
+ }
87
+ }
88
+ return body[lastImportIdx].insertAfter(expression.node);
80
89
  }
81
90
  function prune(path) {
82
- switch (path.parentPath.type) {
91
+ switch (path.parentPath?.type) {
83
92
  // If pruning 'path' would yield an ill-formed parent (e.g, '{foo:}' or 'const x;'), prune it.
84
93
  case "ObjectProperty":
85
94
  case "VariableDeclarator":
86
95
  return path.parentPath.remove();
87
96
  default:
88
- console.log(`Warning: default prune strategy for ${path.parentPath.type}`);
97
+ console.log(
98
+ `Warning: default prune strategy for ${path.parentPath?.type}`
99
+ );
89
100
  // eslint-disable-next-line no-fallthrough
90
101
  case "Program":
91
102
  case "ArrayExpression":
@@ -95,6 +106,7 @@ function prune(path) {
95
106
  function stripTrailingCommentsStrategy() {
96
107
  return {
97
108
  enter(path) {
109
+ ;
98
110
  path.node.trailingComments = [];
99
111
  }
100
112
  };
@@ -104,48 +116,71 @@ function mergeAST(baseAST, extAST, strategy = {}) {
104
116
  const identities = {};
105
117
  const baseVisitor = { ...stripTrailingCommentsStrategy() };
106
118
  const extVisitor = { ...stripTrailingCommentsStrategy() };
107
- forEachFunctionOn(strategy, (typename, strat) => {
108
- extVisitor[typename] = {
109
- enter(path) {
110
- const id = identity(path);
111
- id && (identities[id] ||= []).push(path);
112
- }
113
- };
114
- baseVisitor[typename] = {
115
- enter(path) {
116
- if (isOpaque(strat)) {
117
- skipChildren(path);
119
+ forEachFunctionOn(
120
+ strategy,
121
+ (typename, strat) => {
122
+ extVisitor[typename] = {
123
+ enter(path) {
124
+ const id = identity(path);
125
+ if (id) {
126
+ ;
127
+ (identities[id] ||= []).push(path);
128
+ }
118
129
  }
119
- },
120
- exit(path) {
121
- const exts = extractProperty(identity(path), identities);
122
- if (exts) {
123
- const proxyPath = makeProxy(path);
124
- exts.map(makeProxy).forEach((ext) => {
125
- strat(proxyPath, ext);
126
- prune(ext.path);
127
- });
130
+ };
131
+ baseVisitor[typename] = {
132
+ enter(path) {
133
+ if (isOpaque(strat)) {
134
+ skipChildren(path);
135
+ }
136
+ },
137
+ exit(path) {
138
+ const exts = extractProperty(identity(path), identities);
139
+ if (exts) {
140
+ const proxyPath = makeProxy(path);
141
+ exts.map(makeProxy).forEach((ext) => {
142
+ ;
143
+ strat(proxyPath, ext);
144
+ prune(ext.path);
145
+ });
146
+ }
128
147
  }
129
- }
130
- };
131
- });
132
- traverse(extAST, extVisitor);
133
- traverse(baseAST, baseVisitor);
148
+ };
149
+ }
150
+ );
151
+ traverse(
152
+ extAST,
153
+ extVisitor
154
+ );
155
+ traverse(
156
+ baseAST,
157
+ baseVisitor
158
+ );
134
159
  const baseProgram = getProgramPath(baseAST);
160
+ const body = getProgramPath(extAST).get("body");
135
161
  const [imports, others] = partition(
136
- getProgramPath(extAST).get("body"),
137
- nodeIs("ImportDeclaration")
162
+ body,
163
+ // nodeIs returns (node: Node) => boolean; here we have NodePaths, so we
164
+ // check path.node to stay type-safe.
165
+ (path) => nodeIs("ImportDeclaration")(path.node)
138
166
  );
139
167
  imports.forEach((exp) => insertAfterLastImport(exp, baseProgram));
140
- forEachRight(others, (exp) => insertBeforeFirstUsage(exp, baseProgram));
168
+ forEachRight(
169
+ others,
170
+ (exp) => insertBeforeFirstUsage(exp, baseProgram)
171
+ );
141
172
  }
142
173
  async function merge(base, extension, strategy) {
143
174
  function parseReact(code2) {
144
- return parse(code2, {
145
- filename: "merged.tsx",
175
+ const result = parse(code2, {
146
176
  // required to prevent babel error. The .tsx is relevant
177
+ filename: "merged.tsx",
147
178
  presets: ["@babel/preset-typescript"]
148
179
  });
180
+ if (result === null) {
181
+ throw new Error("Failed to parse code");
182
+ }
183
+ return result;
149
184
  }
150
185
  const baseAST = parseReact(base);
151
186
  const extAST = parseReact(extension);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "5.0.0-canary.2560",
3
+ "version": "5.0.0-canary.2561",
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.7",
35
35
  "@babel/preset-typescript": "7.29.7",
36
- "@cedarjs/api-server": "5.0.0-canary.2560",
37
- "@cedarjs/cli-helpers": "5.0.0-canary.2560",
38
- "@cedarjs/fastify-web": "5.0.0-canary.2560",
39
- "@cedarjs/internal": "5.0.0-canary.2560",
40
- "@cedarjs/prerender": "5.0.0-canary.2560",
41
- "@cedarjs/project-config": "5.0.0-canary.2560",
42
- "@cedarjs/structure": "5.0.0-canary.2560",
43
- "@cedarjs/telemetry": "5.0.0-canary.2560",
44
- "@cedarjs/utils": "5.0.0-canary.2560",
45
- "@cedarjs/vite": "5.0.0-canary.2560",
46
- "@cedarjs/web-server": "5.0.0-canary.2560",
36
+ "@cedarjs/api-server": "5.0.0-canary.2561",
37
+ "@cedarjs/cli-helpers": "5.0.0-canary.2561",
38
+ "@cedarjs/fastify-web": "5.0.0-canary.2561",
39
+ "@cedarjs/internal": "5.0.0-canary.2561",
40
+ "@cedarjs/prerender": "5.0.0-canary.2561",
41
+ "@cedarjs/project-config": "5.0.0-canary.2561",
42
+ "@cedarjs/structure": "5.0.0-canary.2561",
43
+ "@cedarjs/telemetry": "5.0.0-canary.2561",
44
+ "@cedarjs/utils": "5.0.0-canary.2561",
45
+ "@cedarjs/vite": "5.0.0-canary.2561",
46
+ "@cedarjs/web-server": "5.0.0-canary.2561",
47
47
  "@listr2/prompt-adapter-enquirer": "4.2.1",
48
48
  "@opentelemetry/api": "1.9.1",
49
49
  "@opentelemetry/core": "1.30.1",