@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.js CHANGED
@@ -1841,6 +1841,49 @@ var Params = class _Params {
1841
1841
  module: moduleName ?? this._currentModule
1842
1842
  });
1843
1843
  }
1844
+ /**
1845
+ * Report a param value that a component RESOLVED ON ITS OWN — outside
1846
+ * Params.get() — e.g. discovered by combining its config files (the way
1847
+ * blueprints merge defaults/aggregator/feed data). Without this, every
1848
+ * key such a component probed for an override shows up in the
1849
+ * --showUsedParams dump as "undefined (default)"; reporting upgrades the
1850
+ * entry to the value the component actually works with.
1851
+ *
1852
+ * Attribution rules:
1853
+ * - entries figured from an explicit input (cli/env/options/…) are left
1854
+ * untouched — the component merely confirmed them, the origin stands;
1855
+ * - "default" entries (Params had nothing) and earlier reports are
1856
+ * replaced by the report;
1857
+ * - keys never seen by Params are appended as new entries.
1858
+ * The LATEST report wins — a component may resolve the same key several
1859
+ * times with increasing specificity (e.g. a blueprint re-merged for a
1860
+ * concrete resource) and the dump should show what it settled on.
1861
+ * Later params.get() probes that find nothing ("default") never shadow a
1862
+ * reported value — see {@link getFiguredByModule}.
1863
+ *
1864
+ * @param {string} key
1865
+ * @param {*} value - the value the component actually uses
1866
+ * @param {string} [source="discovered"] - short origin label, e.g. "blueprint"
1867
+ * @param {string} [moduleName] - dump section; defaults to the current module
1868
+ */
1869
+ reportResolved(key, value, source = "discovered", moduleName) {
1870
+ const mod = moduleName ?? this._currentModule;
1871
+ const mine = this.trackedParams.filter((e) => e.key === key && e.module === mod);
1872
+ if (mine.some((e) => e.source !== "default" && !e.reported)) {
1873
+ return;
1874
+ }
1875
+ this.trackedParams = this.trackedParams.filter(
1876
+ (e) => !(e.key === key && e.module === mod)
1877
+ );
1878
+ this.trackedParams.push({
1879
+ key,
1880
+ definition: "reported",
1881
+ value,
1882
+ source,
1883
+ module: mod,
1884
+ reported: true
1885
+ });
1886
+ }
1844
1887
  /**
1845
1888
  * Get all tracked parameters (for --stopAfter=init)
1846
1889
  */
@@ -1865,12 +1908,24 @@ var Params = class _Params {
1865
1908
  /**
1866
1909
  * Get figured parameters grouped by module name.
1867
1910
  * Same param can appear in multiple modules (e.g. source, resource).
1911
+ * Last occurrence per key wins, EXCEPT that an empty probe — a
1912
+ * params.get() that found nothing ("default", undefined) — never shadows
1913
+ * a value reported via {@link reportResolved}: components probe for
1914
+ * overrides on every resolution cycle, and those misses say nothing about
1915
+ * the value the component actually uses.
1868
1916
  */
1869
1917
  getFiguredByModule() {
1918
+ const reported = /* @__PURE__ */ new Set();
1919
+ for (const param of this.trackedParams) {
1920
+ if (param.reported) reported.add(`${param.module}\0${param.key}`);
1921
+ }
1870
1922
  const byModule = {};
1871
1923
  for (const param of this.trackedParams) {
1872
1924
  const mod = param.module;
1873
1925
  if (!byModule[mod]) byModule[mod] = {};
1926
+ if (!param.reported && param.source === "default" && reported.has(`${mod}\0${param.key}`)) {
1927
+ continue;
1928
+ }
1874
1929
  byModule[mod][param.key] = { value: param.value, source: param.source };
1875
1930
  }
1876
1931
  return byModule;