@base44-preview/cli 0.0.25-pr.156.f6042c0 → 0.0.25-pr.157.1cf4abc

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 (3) hide show
  1. package/bin/run.js +2 -23
  2. package/dist/index.js +117 -92
  3. package/package.json +1 -4
package/bin/run.js CHANGED
@@ -1,40 +1,19 @@
1
1
  #!/usr/bin/env node
2
- import { program, CLIExitError, errorReporter } from "../dist/index.js";
3
2
 
4
3
  // Disable Clack spinners and animations in non-interactive environments.
5
4
  // Clack only checks the CI env var, so we set it when stdin/stdout aren't TTYs.
6
5
  if (!process.stdin.isTTY || !process.stdout.isTTY) {
7
- process.env.CI = "true";
6
+ process.env.CI = 'true';
8
7
  }
9
8
 
10
- // Initialize error reporter
11
- // The API key should be provided via environment variable
12
- const posthogApiKey = process.env.POSTHOG_API_KEY;
13
- if (posthogApiKey) {
14
- errorReporter.initialize(posthogApiKey, process.env.POSTHOG_HOST);
15
- }
9
+ import { program, CLIExitError } from "../dist/index.js";
16
10
 
17
11
  try {
18
12
  await program.parseAsync();
19
13
  } catch (error) {
20
- // Report the error to PostHog if it's not a controlled exit
21
- if (!(error instanceof CLIExitError)) {
22
- await errorReporter.captureException(error, {
23
- command: process.argv.slice(2).join(" "),
24
- node_version: process.version,
25
- platform: process.platform,
26
- });
27
- }
28
-
29
- // Ensure PostHog events are sent before exiting
30
- await errorReporter.shutdown();
31
-
32
14
  if (error instanceof CLIExitError) {
33
15
  process.exit(error.code);
34
16
  }
35
17
  console.error(error);
36
18
  process.exit(1);
37
- } finally {
38
- // Always shutdown error reporter on normal exit too
39
- await errorReporter.shutdown();
40
19
  }
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
2
2
  import { EventEmitter, addAbortListener, on, once, setMaxListeners } from "node:events";
3
3
  import childProcess, { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
4
4
  import path, { basename, dirname, join, posix, resolve, win32 } from "node:path";
5
- import fs, { appendFileSync, createReadStream, createWriteStream, readFileSync, statSync, writeFileSync } from "node:fs";
5
+ import fs, { appendFileSync, createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
6
6
  import y, { execArgv, execPath, hrtime, platform, stdin, stdout } from "node:process";
7
7
  import { aborted, callbackify, debuglog, inspect, promisify, stripVTControlCharacters } from "node:util";
8
8
  import * as g from "node:readline";
@@ -26,7 +26,6 @@ import tty from "node:tty";
26
26
  import { scheduler, setImmediate as setImmediate$1, setTimeout as setTimeout$1 } from "node:timers/promises";
27
27
  import { serialize } from "node:v8";
28
28
  import { Buffer as Buffer$2 } from "node:buffer";
29
- import { PostHog } from "posthog-node";
30
29
 
31
30
  //#region rolldown:runtime
32
31
  var __create = Object.create;
@@ -29636,7 +29635,7 @@ const checkCwdSync = (dir) => {
29636
29635
  if (!ok) throw new CwdError(dir, code$1 ?? "ENOTDIR");
29637
29636
  }
29638
29637
  };
29639
- const mkdirSync = (dir, opt) => {
29638
+ const mkdirSync$1 = (dir, opt) => {
29640
29639
  dir = normalizeWindowsPath(dir);
29641
29640
  /* c8 ignore next */
29642
29641
  const umask = opt.umask ?? 18;
@@ -30371,7 +30370,7 @@ var UnpackSync = class extends Unpack {
30371
30370
  }
30372
30371
  [MKDIR](dir, mode) {
30373
30372
  try {
30374
- return mkdirSync(normalizeWindowsPath(dir), {
30373
+ return mkdirSync$1(normalizeWindowsPath(dir), {
30375
30374
  uid: this.uid,
30376
30375
  gid: this.gid,
30377
30376
  processUid: this.processUid,
@@ -31401,6 +31400,118 @@ async function printBanner() {
31401
31400
  else console.log(theme.colors.base44Orange(BANNER_LINES.join("\n")));
31402
31401
  }
31403
31402
 
31403
+ //#endregion
31404
+ //#region package.json
31405
+ var version = "0.0.25";
31406
+
31407
+ //#endregion
31408
+ //#region src/core/utils/version-check.ts
31409
+ const NPM_REGISTRY_URL = "https://registry.npmjs.org/base44";
31410
+ const CACHE_FILE_NAME = "version-check.json";
31411
+ const CHECK_INTERVAL_MS = 1440 * 60 * 1e3;
31412
+ function getCacheDir() {
31413
+ return join(getBase44GlobalDir(), "cache");
31414
+ }
31415
+ function getCacheFilePath() {
31416
+ return join(getCacheDir(), CACHE_FILE_NAME);
31417
+ }
31418
+ function readCache() {
31419
+ const cachePath = getCacheFilePath();
31420
+ if (!existsSync(cachePath)) return null;
31421
+ try {
31422
+ const data = readFileSync(cachePath, "utf-8");
31423
+ return JSON.parse(data);
31424
+ } catch {
31425
+ return null;
31426
+ }
31427
+ }
31428
+ function writeCache(cache$2) {
31429
+ const cacheDir = getCacheDir();
31430
+ if (!existsSync(cacheDir)) mkdirSync(cacheDir, { recursive: true });
31431
+ writeFileSync(getCacheFilePath(), JSON.stringify(cache$2, null, 2));
31432
+ }
31433
+ function isCacheValid(cache$2) {
31434
+ return Date.now() - cache$2.lastChecked < CHECK_INTERVAL_MS;
31435
+ }
31436
+ /**
31437
+ * Compares two semver version strings.
31438
+ * Returns true if version2 is greater than version1.
31439
+ */
31440
+ function isNewerVersion(current, latest) {
31441
+ const parseVersion = (v$1) => {
31442
+ return v$1.replace(/^v/, "").split(".").map(Number);
31443
+ };
31444
+ const currentParts = parseVersion(current);
31445
+ const latestParts = parseVersion(latest);
31446
+ for (let i$1 = 0; i$1 < Math.max(currentParts.length, latestParts.length); i$1++) {
31447
+ const currentPart = currentParts[i$1] ?? 0;
31448
+ const latestPart = latestParts[i$1] ?? 0;
31449
+ if (latestPart > currentPart) return true;
31450
+ if (latestPart < currentPart) return false;
31451
+ }
31452
+ return false;
31453
+ }
31454
+ async function fetchLatestVersion() {
31455
+ try {
31456
+ return (await distribution_default.get(NPM_REGISTRY_URL, {
31457
+ timeout: 5e3,
31458
+ retry: 0
31459
+ }).json())["dist-tags"].latest;
31460
+ } catch {
31461
+ return null;
31462
+ }
31463
+ }
31464
+ /**
31465
+ * Checks if a newer version of the CLI is available.
31466
+ * Uses caching to avoid hitting npm registry on every command.
31467
+ * Returns null if check fails or is skipped (non-blocking).
31468
+ */
31469
+ async function checkForUpgrade() {
31470
+ const currentVersion = version;
31471
+ const cache$2 = readCache();
31472
+ if (cache$2 && isCacheValid(cache$2)) return {
31473
+ currentVersion,
31474
+ latestVersion: cache$2.latestVersion,
31475
+ updateAvailable: isNewerVersion(currentVersion, cache$2.latestVersion)
31476
+ };
31477
+ const latestVersion = await fetchLatestVersion();
31478
+ if (!latestVersion) return null;
31479
+ writeCache({
31480
+ latestVersion,
31481
+ lastChecked: Date.now()
31482
+ });
31483
+ return {
31484
+ currentVersion,
31485
+ latestVersion,
31486
+ updateAvailable: isNewerVersion(currentVersion, latestVersion)
31487
+ };
31488
+ }
31489
+
31490
+ //#endregion
31491
+ //#region src/cli/utils/upgradeNotification.ts
31492
+ /**
31493
+ * Formats the upgrade notification message with styling.
31494
+ * Uses the existing shinyOrange theme color.
31495
+ */
31496
+ function formatUpgradeMessage(info) {
31497
+ const { shinyOrange } = theme.colors;
31498
+ const { bold: bold$1 } = theme.styles;
31499
+ return `${shinyOrange("Update available!")} ${shinyOrange(`${info.currentVersion} → ${info.latestVersion}`)} ${shinyOrange("Run:")} ${bold$1(shinyOrange("npm update -g base44"))}`;
31500
+ }
31501
+ /**
31502
+ * Checks for available upgrades and prints a notification if one exists.
31503
+ * This function is non-blocking and will not throw errors.
31504
+ */
31505
+ async function printUpgradeNotificationIfAvailable() {
31506
+ try {
31507
+ const upgradeInfo = await checkForUpgrade();
31508
+ if (upgradeInfo?.updateAvailable) {
31509
+ console.log();
31510
+ console.log(formatUpgradeMessage(upgradeInfo));
31511
+ }
31512
+ } catch {}
31513
+ }
31514
+
31404
31515
  //#endregion
31405
31516
  //#region src/cli/utils/runCommand.ts
31406
31517
  /**
@@ -31449,6 +31560,7 @@ async function runCommand(commandFn, options) {
31449
31560
  if (options?.requireAppConfig !== false) await initAppConfig();
31450
31561
  const { outroMessage } = await commandFn();
31451
31562
  Se(outroMessage || "");
31563
+ await printUpgradeNotificationIfAvailable();
31452
31564
  } catch (e$1) {
31453
31565
  if (e$1 instanceof CLIExitError) throw e$1;
31454
31566
  if (e$1 instanceof Error) M.error(e$1.stack ?? e$1.message);
@@ -39265,10 +39377,6 @@ const siteDeployCommand = new Command("site").description("Manage site deploymen
39265
39377
  await runCommand(() => deployAction(options), { requireAuth: true });
39266
39378
  }));
39267
39379
 
39268
- //#endregion
39269
- //#region package.json
39270
- var version = "0.0.25";
39271
-
39272
39380
  //#endregion
39273
39381
  //#region src/cli/program.ts
39274
39382
  const program = new Command();
@@ -39287,87 +39395,4 @@ program.addCommand(functionsDeployCommand);
39287
39395
  program.addCommand(siteDeployCommand);
39288
39396
 
39289
39397
  //#endregion
39290
- //#region src/cli/error-reporter.ts
39291
- /**
39292
- * Error reporter using PostHog for CLI executions.
39293
- * Designed for short-running CLI tools with proper shutdown handling.
39294
- */
39295
- var ErrorReporter = class {
39296
- client = null;
39297
- isEnabled = false;
39298
- shutdownPromise = null;
39299
- /**
39300
- * Initialize the error reporter with PostHog configuration.
39301
- * @param apiKey - PostHog API key
39302
- * @param host - PostHog host URL (optional, defaults to PostHog cloud)
39303
- */
39304
- initialize(apiKey, host) {
39305
- if (!apiKey) {
39306
- console.warn("PostHog API key not provided. Error reporting disabled.");
39307
- return;
39308
- }
39309
- try {
39310
- this.client = new PostHog(apiKey, {
39311
- host: host || "https://us.i.posthog.com",
39312
- flushAt: 1,
39313
- flushInterval: 0
39314
- });
39315
- this.isEnabled = true;
39316
- } catch (error) {
39317
- console.error("Failed to initialize PostHog client:", error);
39318
- this.isEnabled = false;
39319
- }
39320
- }
39321
- /**
39322
- * Capture an exception and report it to PostHog.
39323
- * @param error - The error to capture
39324
- * @param context - Optional additional context about the error
39325
- */
39326
- async captureException(error, context) {
39327
- if (!this.isEnabled || !this.client) return;
39328
- try {
39329
- const properties = {
39330
- error_name: error.name,
39331
- error_message: error.message,
39332
- error_stack: error.stack,
39333
- ...context
39334
- };
39335
- this.client.capture({
39336
- distinctId: "cli-user",
39337
- event: "cli_error",
39338
- properties
39339
- });
39340
- await this.client.flush();
39341
- } catch (captureError) {
39342
- console.error("Failed to capture exception:", captureError);
39343
- }
39344
- }
39345
- /**
39346
- * Shutdown the error reporter and ensure all events are sent.
39347
- * MUST be called before CLI exits to ensure events are flushed.
39348
- */
39349
- async shutdown() {
39350
- if (!this.client || this.shutdownPromise) return this.shutdownPromise || Promise.resolve();
39351
- this.shutdownPromise = (async () => {
39352
- try {
39353
- await this.client.shutdown();
39354
- } catch (error) {
39355
- console.error("Error during PostHog shutdown:", error);
39356
- } finally {
39357
- this.isEnabled = false;
39358
- this.client = null;
39359
- }
39360
- })();
39361
- return this.shutdownPromise;
39362
- }
39363
- /**
39364
- * Check if error reporting is enabled.
39365
- */
39366
- get enabled() {
39367
- return this.isEnabled;
39368
- }
39369
- };
39370
- const errorReporter = new ErrorReporter();
39371
-
39372
- //#endregion
39373
- export { CLIExitError, errorReporter, program };
39398
+ export { CLIExitError, program };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/cli",
3
- "version": "0.0.25-pr.156.f6042c0",
3
+ "version": "0.0.25-pr.157.1cf4abc",
4
4
  "description": "Base44 CLI - Unified interface for managing Base44 applications",
5
5
  "type": "module",
6
6
  "bin": {
@@ -31,9 +31,6 @@
31
31
  "type": "git",
32
32
  "url": "https://github.com/base44/cli"
33
33
  },
34
- "dependencies": {
35
- "posthog-node": "^4.2.1"
36
- },
37
34
  "devDependencies": {
38
35
  "@clack/prompts": "^0.11.0",
39
36
  "@stylistic/eslint-plugin": "^5.6.1",