@insforge/cli 0.1.67 → 0.1.68

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/index.js CHANGED
@@ -1901,6 +1901,33 @@ function extractEnvKeys(content) {
1901
1901
  }
1902
1902
  return keys;
1903
1903
  }
1904
+ function extractEnvPairs(content) {
1905
+ const out = /* @__PURE__ */ new Map();
1906
+ for (const line of content.split("\n")) {
1907
+ const trimmed = line.replace(/^\s*export\s+/, "").trimStart();
1908
+ if (!trimmed || trimmed.startsWith("#")) continue;
1909
+ const m = trimmed.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/);
1910
+ if (m) out.set(m[1], m[2]);
1911
+ }
1912
+ return out;
1913
+ }
1914
+ function refreshStaleEnvDefaults(existing, manifestDefaults, platformValues) {
1915
+ const refreshed = [];
1916
+ const lines = existing.split("\n").map((line) => {
1917
+ const m = line.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/);
1918
+ if (!m) return line;
1919
+ const key = m[1];
1920
+ const userValue = m[2];
1921
+ const def = manifestDefaults.get(key);
1922
+ const real = platformValues.get(key);
1923
+ if (def !== void 0 && real !== void 0 && userValue === def && real !== def) {
1924
+ refreshed.push(key);
1925
+ return `${key}=${real}`;
1926
+ }
1927
+ return line;
1928
+ });
1929
+ return { updated: lines.join("\n"), refreshed };
1930
+ }
1904
1931
  function filterCollidingEnvLines(append, existingKeys) {
1905
1932
  const dropped = [];
1906
1933
  const out = [];
@@ -1995,6 +2022,7 @@ async function applyAuthProvider(provider, cwd, projectConfig, json) {
1995
2022
  envExampleAppended: false,
1996
2023
  envLocalWritten: false,
1997
2024
  envKeysSkipped: [],
2025
+ envKeysRefreshed: [],
1998
2026
  nextSteps: manifest.nextSteps
1999
2027
  };
2000
2028
  const allFiles = (await walkFiles(providerDir)).filter((rel) => !PROVIDER_META_FILES.has(rel));
@@ -2063,13 +2091,20 @@ async function applyAuthProvider(provider, cwd, projectConfig, json) {
2063
2091
  await fs.writeFile(envLocalPath, filled + "\n");
2064
2092
  result.envLocalWritten = true;
2065
2093
  } else {
2066
- const { filtered, dropped } = filterCollidingEnvLines(filled, existingLocalKeys);
2094
+ const manifestDefaults = extractEnvPairs(manifest.envExampleAppend);
2095
+ const platformValues = extractEnvPairs(filled);
2096
+ const { updated, refreshed } = refreshStaleEnvDefaults(existingLocal, manifestDefaults, platformValues);
2097
+ const refreshedSet = new Set(refreshed);
2098
+ const keysAfterRefresh = /* @__PURE__ */ new Set([...existingLocalKeys, ...refreshedSet]);
2099
+ const { filtered, dropped } = filterCollidingEnvLines(filled, keysAfterRefresh);
2067
2100
  const hasNewKey = filtered.split("\n").some((l) => /^[A-Z][A-Z0-9_]*=/.test(l));
2068
- if (hasNewKey) {
2069
- await fs.writeFile(envLocalPath, existingLocal.replace(/\n*$/, "\n\n") + filtered + "\n");
2101
+ if (refreshed.length > 0 || hasNewKey) {
2102
+ const base = hasNewKey ? updated.replace(/\n*$/, "\n\n") + filtered + "\n" : updated;
2103
+ await fs.writeFile(envLocalPath, base);
2070
2104
  result.envLocalWritten = true;
2071
2105
  }
2072
2106
  result.envKeysSkipped = Array.from(/* @__PURE__ */ new Set([...result.envKeysSkipped, ...dropped]));
2107
+ result.envKeysRefreshed = Array.from(/* @__PURE__ */ new Set([...result.envKeysRefreshed, ...refreshed]));
2073
2108
  }
2074
2109
  if (!jwtSecret && !json) {
2075
2110
  clack9.log.warn("Could not auto-fill JWT_SECRET \u2014 run `npx @insforge/cli secrets get JWT_SECRET` and paste it into .env.local.");
@@ -2079,6 +2114,11 @@ async function applyAuthProvider(provider, cwd, projectConfig, json) {
2079
2114
  `Kept your existing values for: ${result.envKeysSkipped.join(", ")}. If any of these need the auth-provider's defaults, see .env.example for reference.`
2080
2115
  );
2081
2116
  }
2117
+ if (result.envKeysRefreshed.length > 0 && !json) {
2118
+ clack9.log.info(
2119
+ `Refreshed stale platform defaults: ${result.envKeysRefreshed.join(", ")}. Your value matched the manifest's default, so we replaced it with the live one.`
2120
+ );
2121
+ }
2082
2122
  return result;
2083
2123
  } finally {
2084
2124
  await cleanup();
@@ -6789,7 +6829,7 @@ function registerDiagnoseCommands(diagnoseCmd2) {
6789
6829
  const s = !json ? clack14.spinner() : null;
6790
6830
  s?.start("Collecting diagnostic data...");
6791
6831
  const data2 = await collectDiagnosticData(projectId, ossMode, apiUrl);
6792
- const cliVersion = "0.1.67";
6832
+ const cliVersion = "0.1.68";
6793
6833
  s?.stop("Data collected");
6794
6834
  if (!json) {
6795
6835
  console.log(`