@nmakarov/cli-toolkit 0.33.0 → 0.37.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/dist/init.cjs CHANGED
@@ -1866,6 +1866,49 @@ var Params = class _Params {
1866
1866
  module: moduleName ?? this._currentModule
1867
1867
  });
1868
1868
  }
1869
+ /**
1870
+ * Report a param value that a component RESOLVED ON ITS OWN — outside
1871
+ * Params.get() — e.g. discovered by combining its config files (the way
1872
+ * blueprints merge defaults/aggregator/feed data). Without this, every
1873
+ * key such a component probed for an override shows up in the
1874
+ * --showUsedParams dump as "undefined (default)"; reporting upgrades the
1875
+ * entry to the value the component actually works with.
1876
+ *
1877
+ * Attribution rules:
1878
+ * - entries figured from an explicit input (cli/env/options/…) are left
1879
+ * untouched — the component merely confirmed them, the origin stands;
1880
+ * - "default" entries (Params had nothing) and earlier reports are
1881
+ * replaced by the report;
1882
+ * - keys never seen by Params are appended as new entries.
1883
+ * The LATEST report wins — a component may resolve the same key several
1884
+ * times with increasing specificity (e.g. a blueprint re-merged for a
1885
+ * concrete resource) and the dump should show what it settled on.
1886
+ * Later params.get() probes that find nothing ("default") never shadow a
1887
+ * reported value — see {@link getFiguredByModule}.
1888
+ *
1889
+ * @param {string} key
1890
+ * @param {*} value - the value the component actually uses
1891
+ * @param {string} [source="discovered"] - short origin label, e.g. "blueprint"
1892
+ * @param {string} [moduleName] - dump section; defaults to the current module
1893
+ */
1894
+ reportResolved(key, value, source = "discovered", moduleName) {
1895
+ const mod = moduleName ?? this._currentModule;
1896
+ const mine = this.trackedParams.filter((e) => e.key === key && e.module === mod);
1897
+ if (mine.some((e) => e.source !== "default" && !e.reported)) {
1898
+ return;
1899
+ }
1900
+ this.trackedParams = this.trackedParams.filter(
1901
+ (e) => !(e.key === key && e.module === mod)
1902
+ );
1903
+ this.trackedParams.push({
1904
+ key,
1905
+ definition: "reported",
1906
+ value,
1907
+ source,
1908
+ module: mod,
1909
+ reported: true
1910
+ });
1911
+ }
1869
1912
  /**
1870
1913
  * Get all tracked parameters (for --stopAfter=init)
1871
1914
  */
@@ -1890,12 +1933,24 @@ var Params = class _Params {
1890
1933
  /**
1891
1934
  * Get figured parameters grouped by module name.
1892
1935
  * Same param can appear in multiple modules (e.g. source, resource).
1936
+ * Last occurrence per key wins, EXCEPT that an empty probe — a
1937
+ * params.get() that found nothing ("default", undefined) — never shadows
1938
+ * a value reported via {@link reportResolved}: components probe for
1939
+ * overrides on every resolution cycle, and those misses say nothing about
1940
+ * the value the component actually uses.
1893
1941
  */
1894
1942
  getFiguredByModule() {
1943
+ const reported = /* @__PURE__ */ new Set();
1944
+ for (const param of this.trackedParams) {
1945
+ if (param.reported) reported.add(`${param.module}\0${param.key}`);
1946
+ }
1895
1947
  const byModule = {};
1896
1948
  for (const param of this.trackedParams) {
1897
1949
  const mod = param.module;
1898
1950
  if (!byModule[mod]) byModule[mod] = {};
1951
+ if (!param.reported && param.source === "default" && reported.has(`${mod}\0${param.key}`)) {
1952
+ continue;
1953
+ }
1899
1954
  byModule[mod][param.key] = { value: param.value, source: param.source };
1900
1955
  }
1901
1956
  return byModule;