@rudderhq/cli 0.2.10-canary.23 → 0.2.10-canary.25

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/index.js CHANGED
@@ -4291,10 +4291,10 @@ var init_install = __esm({
4291
4291
  init_home();
4292
4292
  RUNTIME_NPM_PACKAGE_NAME = "@rudderhq/server";
4293
4293
  RUNTIME_METADATA_FILE = "runtime.json";
4294
- DEFAULT_RUNTIME_CACHE_MAX_ENTRIES = 5;
4294
+ DEFAULT_RUNTIME_CACHE_MAX_ENTRIES = 2;
4295
4295
  DEFAULT_RUNTIME_CACHE_MAX_AGE_MS = 14 * 24 * 60 * 60 * 1e3;
4296
4296
  DEFAULT_RUNTIME_CACHE_MAX_BYTES = 2 * 1024 * 1024 * 1024;
4297
- DEFAULT_RUNTIME_CACHE_KEEP_PREVIOUS = 1;
4297
+ DEFAULT_RUNTIME_CACHE_KEEP_PREVIOUS = 0;
4298
4298
  RUNTIME_NPM_INSTALL_FLAGS = ["--omit=dev", "--include=optional", "--no-audit", "--no-fund"];
4299
4299
  RuntimeInstallError = class extends Error {
4300
4300
  cacheDir;
@@ -6546,7 +6546,7 @@ init_install();
6546
6546
  import { spawn, spawnSync as spawnSync3 } from "node:child_process";
6547
6547
  import { createHash } from "node:crypto";
6548
6548
  import { constants as fsConstants, createWriteStream, mkdirSync, readFileSync as readFileSync2 } from "node:fs";
6549
- import { access, chmod, copyFile, cp, mkdtemp, mkdir as mkdir2, readFile as readFile2, readdir as readdir2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
6549
+ import { access, chmod, copyFile, cp, mkdtemp, mkdir as mkdir2, readFile as readFile2, readdir as readdir2, rm as rm2, stat as stat2, utimes, writeFile as writeFile2 } from "node:fs/promises";
6550
6550
  import { homedir, tmpdir } from "node:os";
6551
6551
  import path11 from "node:path";
6552
6552
  import { Readable, Transform } from "node:stream";
@@ -6677,6 +6677,10 @@ var DESKTOP_METADATA_FILE = ".rudder-desktop-install.json";
6677
6677
  var DESKTOP_CHECKSUM_ASSET_NAME = "SHASUMS256.txt";
6678
6678
  var DESKTOP_ASSET_CACHE_DIR = "desktop-assets";
6679
6679
  var GITHUB_ASSET_DOWNLOAD_ACCEPT = "application/octet-stream";
6680
+ var DEFAULT_DESKTOP_ASSET_CACHE_MAX_ENTRIES = 2;
6681
+ var DEFAULT_DESKTOP_ASSET_CACHE_MAX_AGE_MS = 14 * 24 * 60 * 60 * 1e3;
6682
+ var DEFAULT_DESKTOP_ASSET_CACHE_MAX_BYTES = 768 * 1024 * 1024;
6683
+ var DEFAULT_DESKTOP_ASSET_CACHE_KEEP_PREVIOUS = 1;
6680
6684
  function normalizeProgressTotal(totalBytes) {
6681
6685
  return typeof totalBytes === "number" && Number.isFinite(totalBytes) && totalBytes > 0 ? totalBytes : null;
6682
6686
  }
@@ -7141,12 +7145,158 @@ function resolveDesktopAssetCacheDir(assetChecksum, homeDir = resolveRudderHomeD
7141
7145
  function resolveDesktopCachedAssetPath(assetName, assetChecksum, homeDir = resolveRudderHomeDir()) {
7142
7146
  return path11.join(resolveDesktopAssetCacheDir(assetChecksum, homeDir), path11.basename(assetName));
7143
7147
  }
7148
+ async function pruneDesktopAssetCache(options = {}) {
7149
+ const homeDir = options.homeDir ?? resolveRudderHomeDir();
7150
+ const entries = await scanDesktopAssetCacheEntries(homeDir);
7151
+ const protectedChecksums = resolveProtectedDesktopAssetChecksums(entries, {
7152
+ protectedChecksums: options.protectedChecksums ?? [],
7153
+ keepPreviousEntries: options.keepPreviousEntries ?? DEFAULT_DESKTOP_ASSET_CACHE_KEEP_PREVIOUS
7154
+ });
7155
+ const protectedSet = new Set(protectedChecksums);
7156
+ const deletions = planDesktopAssetCacheDeletions(entries, {
7157
+ nowMs: (options.now ?? /* @__PURE__ */ new Date()).getTime(),
7158
+ protectedChecksums: protectedSet,
7159
+ maxEntries: options.maxEntries ?? DEFAULT_DESKTOP_ASSET_CACHE_MAX_ENTRIES,
7160
+ maxAgeMs: options.maxAgeMs ?? DEFAULT_DESKTOP_ASSET_CACHE_MAX_AGE_MS,
7161
+ maxTotalBytes: options.maxTotalBytes ?? DEFAULT_DESKTOP_ASSET_CACHE_MAX_BYTES
7162
+ });
7163
+ const deleted = [];
7164
+ const warnings = [];
7165
+ for (const entry of deletions) {
7166
+ try {
7167
+ await rm2(entry.cacheDir, { recursive: true, force: true });
7168
+ deleted.push({
7169
+ cacheDir: entry.cacheDir,
7170
+ checksum: entry.checksum,
7171
+ sizeBytes: entry.sizeBytes
7172
+ });
7173
+ } catch (error) {
7174
+ warnings.push(
7175
+ `Failed to remove Desktop asset cache ${entry.cacheDir}: ${error instanceof Error ? error.message : String(error)}`
7176
+ );
7177
+ }
7178
+ }
7179
+ return {
7180
+ scanned: entries.length,
7181
+ deleted,
7182
+ protectedChecksums,
7183
+ freedBytes: deleted.reduce((total, entry) => total + entry.sizeBytes, 0),
7184
+ warnings
7185
+ };
7186
+ }
7187
+ async function maybePruneDesktopAssetCache(options) {
7188
+ const result = await pruneDesktopAssetCache(options);
7189
+ return result.deleted.length > 0 || result.warnings.length > 0 ? result : null;
7190
+ }
7191
+ async function scanDesktopAssetCacheEntries(homeDir) {
7192
+ const cacheRoot = path11.join(homeDir, DESKTOP_ASSET_CACHE_DIR);
7193
+ const dirents = await readdir2(cacheRoot, { withFileTypes: true }).catch(() => null);
7194
+ if (!dirents) return [];
7195
+ const entries = [];
7196
+ for (const dirent of dirents) {
7197
+ if (!dirent.isDirectory()) continue;
7198
+ let checksum;
7199
+ try {
7200
+ checksum = normalizeDesktopAssetChecksum(dirent.name);
7201
+ } catch {
7202
+ continue;
7203
+ }
7204
+ const cacheDir = path11.join(cacheRoot, dirent.name);
7205
+ const stats = await desktopCacheDirectoryStats(cacheDir);
7206
+ entries.push({
7207
+ cacheDir,
7208
+ checksum,
7209
+ lastUsedAtMs: stats.lastUsedAtMs,
7210
+ sizeBytes: stats.sizeBytes
7211
+ });
7212
+ }
7213
+ return entries;
7214
+ }
7215
+ async function desktopCacheDirectoryStats(targetPath) {
7216
+ const fallbackStat = await stat2(targetPath).catch(() => null);
7217
+ const dirents = await readdir2(targetPath, { withFileTypes: true }).catch(() => null);
7218
+ if (!dirents) {
7219
+ return {
7220
+ sizeBytes: 0,
7221
+ lastUsedAtMs: Number(fallbackStat?.mtimeMs ?? 0)
7222
+ };
7223
+ }
7224
+ let sizeBytes = 0;
7225
+ let lastUsedAtMs = Number(fallbackStat?.mtimeMs ?? 0);
7226
+ for (const dirent of dirents) {
7227
+ if (dirent.isSymbolicLink()) continue;
7228
+ const entryPath = path11.join(targetPath, dirent.name);
7229
+ const entryStat = await stat2(entryPath).catch(() => null);
7230
+ if (!entryStat) continue;
7231
+ lastUsedAtMs = Math.max(lastUsedAtMs, Number(entryStat.mtimeMs ?? 0));
7232
+ if (dirent.isDirectory()) {
7233
+ const nested = await desktopCacheDirectoryStats(entryPath);
7234
+ sizeBytes += nested.sizeBytes;
7235
+ lastUsedAtMs = Math.max(lastUsedAtMs, nested.lastUsedAtMs);
7236
+ continue;
7237
+ }
7238
+ sizeBytes += Number(entryStat.size ?? 0);
7239
+ }
7240
+ return { sizeBytes, lastUsedAtMs };
7241
+ }
7242
+ function resolveProtectedDesktopAssetChecksums(entries, options) {
7243
+ const protectedChecksums = /* @__PURE__ */ new Set();
7244
+ for (const checksum of options.protectedChecksums) {
7245
+ try {
7246
+ protectedChecksums.add(normalizeDesktopAssetChecksum(checksum));
7247
+ } catch {
7248
+ continue;
7249
+ }
7250
+ }
7251
+ const previousEntries = [...entries].filter((entry) => !protectedChecksums.has(entry.checksum)).sort((a, b) => b.lastUsedAtMs - a.lastUsedAtMs);
7252
+ for (const entry of previousEntries.slice(0, Math.max(0, options.keepPreviousEntries))) {
7253
+ protectedChecksums.add(entry.checksum);
7254
+ }
7255
+ return [...protectedChecksums].sort();
7256
+ }
7257
+ function planDesktopAssetCacheDeletions(entries, options) {
7258
+ const deletions = /* @__PURE__ */ new Set();
7259
+ const oldestFirst = [...entries].sort((a, b) => a.lastUsedAtMs - b.lastUsedAtMs);
7260
+ const canDelete = (entry) => !options.protectedChecksums.has(entry.checksum) && !deletions.has(entry.cacheDir);
7261
+ const mark = (entry) => {
7262
+ if (canDelete(entry)) deletions.add(entry.cacheDir);
7263
+ };
7264
+ if (options.maxAgeMs >= 0) {
7265
+ for (const entry of oldestFirst) {
7266
+ if (options.nowMs - entry.lastUsedAtMs > options.maxAgeMs) mark(entry);
7267
+ }
7268
+ }
7269
+ if (options.maxEntries > 0) {
7270
+ for (const entry of oldestFirst) {
7271
+ if (entries.length - deletions.size <= options.maxEntries) break;
7272
+ mark(entry);
7273
+ }
7274
+ }
7275
+ if (options.maxTotalBytes > 0) {
7276
+ let remainingBytes = entries.reduce((total, entry) => total + entry.sizeBytes, 0) - [...deletions].reduce((total, cacheDir) => total + (entries.find((entry) => entry.cacheDir === cacheDir)?.sizeBytes ?? 0), 0);
7277
+ for (const entry of oldestFirst) {
7278
+ if (remainingBytes <= options.maxTotalBytes) break;
7279
+ if (!canDelete(entry)) continue;
7280
+ deletions.add(entry.cacheDir);
7281
+ remainingBytes -= entry.sizeBytes;
7282
+ }
7283
+ }
7284
+ return entries.filter((entry) => deletions.has(entry.cacheDir));
7285
+ }
7286
+ async function touchDesktopCachedAsset(cachePath) {
7287
+ try {
7288
+ const now = /* @__PURE__ */ new Date();
7289
+ await utimes(cachePath, now, now);
7290
+ } catch {
7291
+ }
7292
+ }
7144
7293
  async function downloadDesktopAssetWithCache(asset, expectedChecksum, options = {}) {
7145
7294
  const normalizedChecksum = normalizeDesktopAssetChecksum(expectedChecksum);
7146
7295
  const cachePath = resolveDesktopCachedAssetPath(asset.name, normalizedChecksum, options.homeDir);
7147
7296
  if (await pathExists(cachePath)) {
7148
7297
  try {
7149
7298
  const checksum = assertChecksumMatch(cachePath, normalizedChecksum);
7299
+ await touchDesktopCachedAsset(cachePath);
7150
7300
  return { path: cachePath, checksum, cacheStatus: "hit" };
7151
7301
  } catch {
7152
7302
  await rm2(cachePath, { force: true });
@@ -7753,6 +7903,17 @@ async function startCommand(opts) {
7753
7903
  );
7754
7904
  await writeInstallMetadata(installPaths, releaseTag, selectedAsset.name, checksum, selectedAssetKind);
7755
7905
  }
7906
+ const desktopAssetPrune = await maybePruneDesktopAssetCache({
7907
+ protectedChecksums: [expectedChecksum]
7908
+ });
7909
+ if (desktopAssetPrune) {
7910
+ if (desktopAssetPrune.deleted.length > 0) {
7911
+ p13.log.success(
7912
+ `Pruned ${desktopAssetPrune.deleted.length} old Desktop asset cache(s), freed ${formatBytes(desktopAssetPrune.freedBytes)}.`
7913
+ );
7914
+ }
7915
+ for (const warning of desktopAssetPrune.warnings) p13.log.warn(warning);
7916
+ }
7756
7917
  if (opts.open !== false) {
7757
7918
  await runStartPhase(
7758
7919
  "Launching Rudder Desktop...",
@@ -8858,7 +9019,7 @@ function registerContextCommands(program) {
8858
9019
  }
8859
9020
 
8860
9021
  // src/commands/client/company.ts
8861
- import { mkdir as mkdir3, readdir as readdir3, readFile as readFile3, stat as stat2, writeFile as writeFile3 } from "node:fs/promises";
9022
+ import { mkdir as mkdir3, readdir as readdir3, readFile as readFile3, stat as stat3, writeFile as writeFile3 } from "node:fs/promises";
8862
9023
  import path15 from "node:path";
8863
9024
  import * as p15 from "@clack/prompts";
8864
9025
  import pc14 from "picocolors";
@@ -9593,7 +9754,7 @@ function normalizeGithubImportSource(input, refOverride) {
9593
9754
  }
9594
9755
  async function pathExists2(inputPath) {
9595
9756
  try {
9596
- await stat2(path15.resolve(inputPath));
9757
+ await stat3(path15.resolve(inputPath));
9597
9758
  return true;
9598
9759
  } catch {
9599
9760
  return false;
@@ -9616,7 +9777,7 @@ async function collectPackageFiles(root, current, files) {
9616
9777
  }
9617
9778
  async function resolveInlineSourceFromPath(inputPath) {
9618
9779
  const resolved = path15.resolve(inputPath);
9619
- const resolvedStat = await stat2(resolved);
9780
+ const resolvedStat = await stat3(resolved);
9620
9781
  if (resolvedStat.isFile() && path15.extname(resolved).toLowerCase() === ".zip") {
9621
9782
  const archive = await readZipArchive(await readFile3(resolved));
9622
9783
  const filteredFiles = Object.fromEntries(
@@ -9652,7 +9813,7 @@ async function writeExportToFolder(outDir, exported) {
9652
9813
  }
9653
9814
  async function confirmOverwriteExportDirectory(outDir) {
9654
9815
  const root = path15.resolve(outDir);
9655
- const stats = await stat2(root).catch(() => null);
9816
+ const stats = await stat3(root).catch(() => null);
9656
9817
  if (!stats) return;
9657
9818
  if (!stats.isDirectory()) {
9658
9819
  throw new Error(`Export output path ${root} exists and is not a directory.`);
@@ -10079,7 +10240,7 @@ ${organizationUrl}`);
10079
10240
 
10080
10241
  // src/commands/client/issue.ts
10081
10242
  init_dist();
10082
- import { readFile as readFile4, stat as stat3 } from "node:fs/promises";
10243
+ import { readFile as readFile4, stat as stat4 } from "node:fs/promises";
10083
10244
  import path16 from "node:path";
10084
10245
 
10085
10246
  // src/agent-v1-registry.ts
@@ -11199,7 +11360,7 @@ ${imageBlock}` : imageBlock;
11199
11360
  }
11200
11361
  async function uploadIssueCommentImage(ctx, issue, imagePath) {
11201
11362
  const resolvedPath = path16.resolve(process.cwd(), imagePath);
11202
- const stats = await stat3(resolvedPath).catch((err) => {
11363
+ const stats = await stat4(resolvedPath).catch((err) => {
11203
11364
  throw new Error(`Unable to read image ${imagePath}: ${err instanceof Error ? err.message : String(err)}`);
11204
11365
  });
11205
11366
  if (!stats.isFile()) {