@base44-preview/cli 0.0.32-pr.249.38b7e86 → 0.0.32-pr.249.535f2a7

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.
package/dist/cli/index.js CHANGED
@@ -178102,6 +178102,18 @@ class InvalidInputError extends UserError {
178102
178102
  code = "INVALID_INPUT";
178103
178103
  }
178104
178104
 
178105
+ class DependencyNotFoundError extends UserError {
178106
+ code = "DEPENDENCY_NOT_FOUND";
178107
+ constructor(message, options) {
178108
+ super(message, {
178109
+ hints: options?.hints ?? [
178110
+ { message: "Install the required dependency and try again" }
178111
+ ],
178112
+ cause: options?.cause
178113
+ });
178114
+ }
178115
+ }
178116
+
178105
178117
  class ApiError extends SystemError {
178106
178118
  code = "API_ERROR";
178107
178119
  statusCode;
@@ -178217,6 +178229,21 @@ class FileReadError extends SystemError {
178217
178229
  });
178218
178230
  }
178219
178231
  }
178232
+
178233
+ class InternalError extends SystemError {
178234
+ code = "INTERNAL_ERROR";
178235
+ constructor(message, options) {
178236
+ super(message, {
178237
+ hints: options?.hints ?? [
178238
+ {
178239
+ message: "This is an unexpected error. Please report it if it persists."
178240
+ }
178241
+ ],
178242
+ cause: options?.cause
178243
+ });
178244
+ }
178245
+ }
178246
+
178220
178247
  class TypeGenerationError extends SystemError {
178221
178248
  code = "TYPE_GENERATION_ERROR";
178222
178249
  entityName;
@@ -186654,7 +186681,9 @@ var theme = {
186654
186681
  styles: {
186655
186682
  header: source_default.dim,
186656
186683
  bold: source_default.bold,
186657
- dim: source_default.dim
186684
+ dim: source_default.dim,
186685
+ error: source_default.red,
186686
+ warn: source_default.yellow
186658
186687
  },
186659
186688
  format: {
186660
186689
  errorContext(ctx) {
@@ -195198,9 +195227,9 @@ function getTypesCommand(context) {
195198
195227
  }
195199
195228
 
195200
195229
  // src/cli/dev/dev-server/main.ts
195230
+ import { dirname as dirname12, join as join16 } from "node:path";
195201
195231
  var import_cors = __toESM(require_lib4(), 1);
195202
195232
  var import_express2 = __toESM(require_express(), 1);
195203
- import { dirname as dirname12, join as join16 } from "node:path";
195204
195233
 
195205
195234
  // node_modules/get-port/index.js
195206
195235
  import net from "node:net";
@@ -195327,8 +195356,8 @@ var dateTimeFormat = new Intl.DateTimeFormat([], {
195327
195356
  hour12: false
195328
195357
  });
195329
195358
  var colorByType = {
195330
- error: source_default.red,
195331
- warn: source_default.yellow,
195359
+ error: theme.styles.error,
195360
+ warn: theme.styles.warn,
195332
195361
  log: (text) => text
195333
195362
  };
195334
195363
  function createDevLogger(isPrefixed = true) {
@@ -195348,7 +195377,7 @@ function createDevLogger(isPrefixed = true) {
195348
195377
  const prefixedLog = (type, msg) => {
195349
195378
  const timestamp = dateTimeFormat.format(new Date);
195350
195379
  const colorize = colorByType[type];
195351
- console.log(`${source_default.gray(timestamp)} ${colorize(msg)}`);
195380
+ console.log(`${theme.styles.dim(timestamp)} ${colorize(msg)}`);
195352
195381
  };
195353
195382
  return isPrefixed ? {
195354
195383
  log: (msg) => prefixedLog("log", msg),
@@ -195372,7 +195401,7 @@ function createDevLogger(isPrefixed = true) {
195372
195401
  }
195373
195402
 
195374
195403
  // src/cli/dev/dev-server/function-manager.ts
195375
- import { spawn as spawn2 } from "node:child_process";
195404
+ import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
195376
195405
  import { dirname as dirname11, join as join15 } from "node:path";
195377
195406
  import { fileURLToPath as fileURLToPath7 } from "node:url";
195378
195407
  var __dirname5 = dirname11(fileURLToPath7(import.meta.url));
@@ -195382,6 +195411,7 @@ var READY_TIMEOUT = 30000;
195382
195411
  class FunctionManager {
195383
195412
  functions;
195384
195413
  running = new Map;
195414
+ starting = new Map;
195385
195415
  logger;
195386
195416
  constructor(functions, logger) {
195387
195417
  this.functions = new Map(functions.map((f7) => [f7.name, f7]));
@@ -195390,12 +195420,16 @@ class FunctionManager {
195390
195420
  functionNames() {
195391
195421
  return Array.from(this.functions.keys());
195392
195422
  }
195423
+ getFunction(name2) {
195424
+ return this.functions.get(name2);
195425
+ }
195393
195426
  verifyDenoIsInstalled() {
195394
195427
  if (this.functions.size > 0) {
195395
- try {
195396
- spawn2("deno", ["--version"]);
195397
- } catch {
195398
- throw new Error("Deno is required to run functions. Please install it from https://deno.com/download");
195428
+ const result = spawnSync2("deno", ["--version"]);
195429
+ if (result.error) {
195430
+ throw new DependencyNotFoundError("Deno is required to run functions", {
195431
+ hints: [{ message: "Install Deno from https://deno.com/download" }]
195432
+ });
195399
195433
  }
195400
195434
  }
195401
195435
  }
@@ -195404,13 +195438,25 @@ class FunctionManager {
195404
195438
  if (existing?.ready) {
195405
195439
  return existing.port;
195406
195440
  }
195441
+ const pending = this.starting.get(name2);
195442
+ if (pending) {
195443
+ return pending;
195444
+ }
195407
195445
  const backendFunction = this.functions.get(name2);
195408
195446
  if (!backendFunction) {
195409
- throw new Error(`Function "${name2}" not found`);
195447
+ throw new InvalidInputError(`Function "${name2}" not found`, {
195448
+ hints: [{ message: "Check available functions in your project" }]
195449
+ });
195410
195450
  }
195411
- if (existing && !existing.ready) {
195412
- return this.waitForReady(name2, existing);
195451
+ const promise2 = this.startFunction(name2, backendFunction);
195452
+ this.starting.set(name2, promise2);
195453
+ try {
195454
+ return await promise2;
195455
+ } finally {
195456
+ this.starting.delete(name2);
195413
195457
  }
195458
+ }
195459
+ async startFunction(name2, backendFunction) {
195414
195460
  const port = await this.allocatePort();
195415
195461
  const process21 = this.spawnFunction(backendFunction, port);
195416
195462
  const runningFunc = {
@@ -195432,6 +195478,7 @@ class FunctionManager {
195432
195478
  process21.kill();
195433
195479
  }
195434
195480
  this.running.clear();
195481
+ this.starting.clear();
195435
195482
  }
195436
195483
  stop(name2) {
195437
195484
  const running = this.running.get(name2);
@@ -195485,7 +195532,11 @@ class FunctionManager {
195485
195532
  waitForReady(name2, runningFunc) {
195486
195533
  return new Promise((resolve5, reject) => {
195487
195534
  const timeout3 = setTimeout(() => {
195488
- reject(new Error(`Function "${name2}" failed to start within timeout`));
195535
+ reject(new InternalError(`Function "${name2}" failed to start within ${READY_TIMEOUT / 1000}s timeout`, {
195536
+ hints: [
195537
+ { message: "Check the function code for startup errors" }
195538
+ ]
195539
+ }));
195489
195540
  }, READY_TIMEOUT);
195490
195541
  const onData = (data) => {
195491
195542
  const output = data.toString();
@@ -195500,7 +195551,9 @@ class FunctionManager {
195500
195551
  runningFunc.process.on("exit", (code2) => {
195501
195552
  if (!runningFunc.ready) {
195502
195553
  clearTimeout(timeout3);
195503
- reject(new Error(`Function "${name2}" exited with code ${code2}`));
195554
+ reject(new InternalError(`Function "${name2}" exited with code ${code2}`, {
195555
+ hints: [{ message: "Check the function code for errors" }]
195556
+ }));
195504
195557
  }
195505
195558
  });
195506
195559
  });
@@ -195603,12 +195656,13 @@ async function createDevServer(options8) {
195603
195656
  }
195604
195657
  next();
195605
195658
  });
195606
- const [functions] = await Promise.all([
195607
- functionResource.readAll(join16(configDir, project2.functionsDir))
195608
- ]);
195659
+ const functions = await functionResource.readAll(join16(configDir, project2.functionsDir));
195609
195660
  const devLogger = createDevLogger(false);
195610
195661
  const functionManager = new FunctionManager(functions, devLogger);
195611
195662
  functionManager.verifyDenoIsInstalled();
195663
+ if (functionManager.functionNames().length > 0) {
195664
+ M2.info(`Loaded functions: ${functionManager.functionNames().join(", ")}`);
195665
+ }
195612
195666
  const functionRoutes = createFunctionRoutes(functionManager, devLogger);
195613
195667
  app.use("/api/apps/:appId/functions", functionRoutes);
195614
195668
  app.use((req, res, next) => {
@@ -195622,12 +195676,13 @@ async function createDevServer(options8) {
195622
195676
  } else {
195623
195677
  reject(err);
195624
195678
  }
195679
+ } else {
195625
195680
  const shutdown = () => {
195626
195681
  functionManager.stopAll();
195682
+ server.close();
195627
195683
  };
195628
195684
  process.on("SIGINT", shutdown);
195629
195685
  process.on("SIGTERM", shutdown);
195630
- } else {
195631
195686
  resolve5({
195632
195687
  port,
195633
195688
  server
@@ -200032,4 +200087,4 @@ export {
200032
200087
  CLIExitError
200033
200088
  };
200034
200089
 
200035
- //# debugId=F7187C428A4270E164756E2164756E21
200090
+ //# debugId=10D47D308F001A4164756E2164756E21