@buildinternet/releases-lib 0.42.0 → 0.44.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildinternet/releases-lib",
3
- "version": "0.42.0",
3
+ "version": "0.44.0",
4
4
  "description": "Runtime-neutral helpers for the Releases CLI — logger, errors, config.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -11,6 +11,7 @@
11
11
  },
12
12
  "exports": {
13
13
  "./config": "./src/config.ts",
14
+ "./legacy-env": "./src/legacy-env.ts",
14
15
  "./logger": "./src/logger.ts"
15
16
  },
16
17
  "files": [
package/src/config.ts CHANGED
@@ -1,12 +1,21 @@
1
1
  import { mkdirSync } from "fs";
2
2
  import { join } from "path";
3
3
  import { homedir } from "os";
4
+ import { legacyEnv } from "./legacy-env";
4
5
 
5
6
  let _dataDir: string | null = null;
7
+ let _dataDirEnv: string | undefined;
6
8
 
7
9
  export function getDataDir(): string {
8
- if (!_dataDir) {
9
- _dataDir = process.env.RELEASED_DATA_DIR || join(homedir(), ".releases");
10
+ // Cache the resolved dir, but invalidate when the env var changes. In prod
11
+ // the env is fixed at startup so this stays memoized (mkdir runs once); in
12
+ // tests, each file points RELEASED_DATA_DIR at its own temp dir, and the
13
+ // comparison re-resolves instead of returning a stale dir cached by another
14
+ // file. (This is what `bun test --isolate` used to paper over — see #211.)
15
+ const env = legacyEnv("RELEASES_DATA_DIR", "RELEASED_DATA_DIR");
16
+ if (_dataDir === null || env !== _dataDirEnv) {
17
+ _dataDirEnv = env;
18
+ _dataDir = env || join(homedir(), ".releases");
10
19
  mkdirSync(_dataDir, { recursive: true });
11
20
  }
12
21
  return _dataDir;
@@ -0,0 +1,35 @@
1
+ import { logger } from "./logger";
2
+
3
+ const warned = new Set<string>();
4
+
5
+ /** Reset warn-once state. Test-only. */
6
+ export function __resetLegacyEnvWarnings(): void {
7
+ warned.clear();
8
+ }
9
+
10
+ /**
11
+ * Resolve an env var migrating from a legacy name to a canonical one. Prefers
12
+ * `canonical`; falls back to `legacy` with a one-time deprecation warning.
13
+ * Empty string counts as unset. Returns `undefined` when neither is set.
14
+ *
15
+ * `warn` is injectable for tests; defaults to the shared logger.
16
+ */
17
+ export function legacyEnv(
18
+ canonical: string,
19
+ legacy: string,
20
+ warn: (msg: string) => void = (msg) => logger.warn(msg),
21
+ ): string | undefined {
22
+ const next = process.env[canonical];
23
+ if (next) return next;
24
+ const old = process.env[legacy];
25
+ if (old) {
26
+ if (!warned.has(legacy)) {
27
+ warned.add(legacy);
28
+ warn(
29
+ `${legacy} is deprecated; rename it to ${canonical}. The legacy name still works for now but will be removed.`,
30
+ );
31
+ }
32
+ return old;
33
+ }
34
+ return undefined;
35
+ }