@thenewlabs/entangle-utils 2.11.1 → 2.11.2

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/version.d.ts CHANGED
@@ -1,4 +1,10 @@
1
- export declare const VERSION = "2.11.1";
2
- export declare const BUILD_TIME: string;
3
- export declare function getVersionInfo(): string;
1
+ /**
2
+ * The CALLING package's version. Pass the entry module's `import.meta.url`; the manifest is
3
+ * expected one level up (`src/index.ts` and `dist/index.js` both sit directly under the package
4
+ * root). Returns 'unknown' rather than throwing — a binary that cannot find its manifest should
5
+ * still start, just visibly unversioned.
6
+ */
7
+ export declare function packageVersion(entryModuleUrl: string): string;
8
+ /** Human-facing version string for banners and `--version`: `v<package version>`. */
9
+ export declare function getVersionInfo(entryModuleUrl: string): string;
4
10
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAC;AAChC,eAAO,MAAM,UAAU,QAA2B,CAAC;AAEnD,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAuBA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAU7D;AAED,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAE7D"}
package/dist/version.js CHANGED
@@ -1,6 +1,40 @@
1
- export const VERSION = '2.11.1';
2
- export const BUILD_TIME = new Date().toISOString();
3
- export function getVersionInfo() {
4
- return `v${VERSION} (built: ${BUILD_TIME})`;
1
+ /**
2
+ * Per-package version reporting with ONE source of truth: the package's own package.json.
3
+ *
4
+ * There is deliberately NO version constant in this module. A shared hardcoded string is how
5
+ * every entangle binary ended up announcing utils' stale version instead of its own (serve
6
+ * 2.12.0 shipped reporting "v2.11.1"); a drift-guard test can only pin such a constant to
7
+ * THIS package's manifest, never to the caller's. Instead each CLI entry module calls
8
+ * `getVersionInfo(import.meta.url)`:
9
+ *
10
+ * - workspace / tsc builds: the version is read at runtime from `../package.json` relative to
11
+ * the calling entry module — which is that package's OWN manifest for `src/` (tsx dev) and
12
+ * `dist/` (tsc output) alike;
13
+ * - standalone bundles (main/dist/*.js are CJS/IIFE where `import.meta.url` is gone and a
14
+ * relative manifest lookup would find the wrong package.json): the bundling script injects
15
+ * the right version at build time via esbuild `define` (`ENTANGLE_BUILD_VERSION` — see
16
+ * scripts/build-dist.js and locus-server's build.mjs), which wins over the runtime read.
17
+ */
18
+ import { readFileSync } from 'fs';
19
+ /**
20
+ * The CALLING package's version. Pass the entry module's `import.meta.url`; the manifest is
21
+ * expected one level up (`src/index.ts` and `dist/index.js` both sit directly under the package
22
+ * root). Returns 'unknown' rather than throwing — a binary that cannot find its manifest should
23
+ * still start, just visibly unversioned.
24
+ */
25
+ export function packageVersion(entryModuleUrl) {
26
+ if (typeof ENTANGLE_BUILD_VERSION === 'string')
27
+ return ENTANGLE_BUILD_VERSION;
28
+ try {
29
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', entryModuleUrl), 'utf8'));
30
+ return typeof pkg.version === 'string' ? pkg.version : 'unknown';
31
+ }
32
+ catch {
33
+ return 'unknown';
34
+ }
35
+ }
36
+ /** Human-facing version string for banners and `--version`: `v<package version>`. */
37
+ export function getVersionInfo(entryModuleUrl) {
38
+ return `v${packageVersion(entryModuleUrl)}`;
5
39
  }
6
40
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;AAChC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAEnD,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,OAAO,YAAY,UAAU,GAAG,CAAC;AAC9C,CAAC"}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAMlC;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,cAAsB;IACnD,IAAI,OAAO,sBAAsB,KAAK,QAAQ;QAAE,OAAO,sBAAsB,CAAC;IAC9E,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAEtF,CAAC;QACF,OAAO,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,cAAc,CAAC,cAAsB;IACnD,OAAO,IAAI,cAAc,CAAC,cAAc,CAAC,EAAE,CAAC;AAC9C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thenewlabs/entangle-utils",
3
- "version": "2.11.1",
3
+ "version": "2.11.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",