@boxes-dev/dvb 1.0.482 → 1.0.483

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.
@@ -3050,6 +3050,12 @@ var FETCH_TIMEOUT_MS = 1e4;
3050
3050
  var VALIDATION_TIMEOUT_MS = 5e3;
3051
3051
  var UPDATER_INTERVAL_MS = 15 * 60 * 1e3;
3052
3052
  var MAX_UPDATER_ERROR_LENGTH = 2e3;
3053
+ var runtimeManagerTestHooks = {
3054
+ ensureBundledRuntimeStaged: void 0,
3055
+ listLiveRuntimeVersions: void 0,
3056
+ startBackgroundUpdater: void 0,
3057
+ runRuntimeChild: void 0
3058
+ };
3053
3059
  var assertNodeVersion = () => {
3054
3060
  const version = process.versions.node;
3055
3061
  const major = Number(version.split(".")[0]);
@@ -3099,6 +3105,15 @@ var readStageVersion = async (runtimeDir) => {
3099
3105
  }
3100
3106
  };
3101
3107
  var resolveRuntimeBinPath = (runtimeDir, kind) => import_node_path11.default.join(runtimeDir, "dist", "bin", `${kind}.cjs`);
3108
+ var readLinkedRuntimeVersion = async (linkPath) => {
3109
+ try {
3110
+ const runtimeDir = await import_promises2.default.realpath(linkPath);
3111
+ const version = import_node_path11.default.basename(runtimeDir).trim();
3112
+ return version.length > 0 ? version : null;
3113
+ } catch {
3114
+ return null;
3115
+ }
3116
+ };
3102
3117
  var readCurrentRuntime = async (homeDir = import_node_os2.default.homedir()) => {
3103
3118
  const currentLink = resolveCurrentRuntimeLink(homeDir);
3104
3119
  try {
@@ -3115,6 +3130,74 @@ var readCurrentRuntime = async (homeDir = import_node_os2.default.homedir()) =>
3115
3130
  return null;
3116
3131
  }
3117
3132
  };
3133
+ var listLiveRuntimeVersions = async (homeDir = import_node_os2.default.homedir()) => {
3134
+ const releasesDir = resolveRuntimeReleasesDir(homeDir);
3135
+ const ps2 = (0, import_node_child_process.spawnSync)("ps", ["eww", "-Ao", "command="], {
3136
+ encoding: "utf8"
3137
+ });
3138
+ if (ps2.error || ps2.status !== 0 || typeof ps2.stdout !== "string") {
3139
+ return [];
3140
+ }
3141
+ const versions = /* @__PURE__ */ new Set();
3142
+ const runtimePattern = new RegExp(
3143
+ `${escapeRegExp(releasesDir)}/([^/\\s]+)/dist/bin/dvb(?:d)?\\.cjs(?=\\s|$)`,
3144
+ "g"
3145
+ );
3146
+ for (const line of ps2.stdout.split(/\r?\n/)) {
3147
+ runtimePattern.lastIndex = 0;
3148
+ for (let match = runtimePattern.exec(line); match; match = runtimePattern.exec(line)) {
3149
+ const version = match[1]?.trim();
3150
+ if (version) {
3151
+ versions.add(version);
3152
+ }
3153
+ }
3154
+ }
3155
+ return [...versions];
3156
+ };
3157
+ var pruneRuntimeReleases = async (homeDir = import_node_os2.default.homedir()) => {
3158
+ const releasesDir = resolveRuntimeReleasesDir(homeDir);
3159
+ const keep = /* @__PURE__ */ new Set();
3160
+ const current = await readCurrentRuntime(homeDir);
3161
+ if (current) {
3162
+ keep.add(current.version);
3163
+ }
3164
+ const previous = await readLinkedRuntimeVersion(
3165
+ resolvePreviousRuntimeLink(homeDir)
3166
+ );
3167
+ if (previous) {
3168
+ keep.add(previous);
3169
+ }
3170
+ const listLiveRuntimeVersionsFn = runtimeManagerTestHooks.listLiveRuntimeVersions ?? listLiveRuntimeVersions;
3171
+ for (const version of await listLiveRuntimeVersionsFn(homeDir)) {
3172
+ const normalized = version.trim();
3173
+ if (normalized.length > 0) {
3174
+ keep.add(normalized);
3175
+ }
3176
+ }
3177
+ try {
3178
+ const entries = await import_promises2.default.readdir(releasesDir, { withFileTypes: true });
3179
+ for (const entry of entries) {
3180
+ if (!entry.isDirectory()) {
3181
+ continue;
3182
+ }
3183
+ if (entry.name.startsWith(".tmp-")) {
3184
+ continue;
3185
+ }
3186
+ if (keep.has(entry.name)) {
3187
+ continue;
3188
+ }
3189
+ await import_promises2.default.rm(import_node_path11.default.join(releasesDir, entry.name), {
3190
+ recursive: true,
3191
+ force: true
3192
+ });
3193
+ }
3194
+ } catch (error) {
3195
+ const code = error?.code;
3196
+ if (code !== "ENOENT") {
3197
+ throw error;
3198
+ }
3199
+ }
3200
+ };
3118
3201
  var resolveBundledRuntimeRoot = () => {
3119
3202
  const require2 = (0, import_node_module.createRequire)(resolveBasePath());
3120
3203
  const manifestPath = require2.resolve(`${RUNTIME_PACKAGE_NAME}/package.json`);
@@ -3150,6 +3233,7 @@ var trimUpdaterError = (error) => {
3150
3233
  const message = error instanceof Error ? error.message : String(error);
3151
3234
  return message.length > MAX_UPDATER_ERROR_LENGTH ? `${message.slice(0, MAX_UPDATER_ERROR_LENGTH)}...` : message;
3152
3235
  };
3236
+ var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3153
3237
  var isProcessAlive = (pid) => {
3154
3238
  if (!Number.isInteger(pid) || pid <= 0) {
3155
3239
  return false;
@@ -3513,6 +3597,10 @@ var promoteRuntimeStage = async (stageDir, version, homeDir = import_node_os2.de
3513
3597
  );
3514
3598
  }
3515
3599
  await writeSymlinkAtomic(resolveCurrentRuntimeLink(homeDir), version);
3600
+ try {
3601
+ await pruneRuntimeReleases(homeDir);
3602
+ } catch {
3603
+ }
3516
3604
  };
3517
3605
  var installBundledRuntime = async (bundled, homeDir = import_node_os2.default.homedir()) => {
3518
3606
  const stageDir = await createStageDir(bundled.version, homeDir);