@xlameiro/env-typegen 0.1.6 → 0.1.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.8
4
+
5
+ ### Patch Changes
6
+
7
+ - c339449: ## Fuzzy Dancers Find — env-typegen QA deficiency fixes (D1-D12)
8
+
9
+ ## 0.1.7
10
+
11
+ ### Patch Changes
12
+
13
+ - 97738bd: ## Fuzzy Dancers Find — env-typegen QA deficiency fixes (D1-D12)
14
+
3
15
  ## 0.1.6
4
16
 
5
17
  ### Patch Changes
package/dist/cli.js CHANGED
@@ -559,6 +559,27 @@ function buildParsedVar(params, commentBlock, options) {
559
559
  }
560
560
  return parsedVar;
561
561
  }
562
+ function deduplicateVars(vars) {
563
+ const seenKeys = /* @__PURE__ */ new Set();
564
+ const deduped = [];
565
+ const warnings = [];
566
+ for (let i = vars.length - 1; i >= 0; i--) {
567
+ const variable = vars[i];
568
+ if (variable === void 0) continue;
569
+ if (seenKeys.has(variable.key)) {
570
+ warnings.push({
571
+ code: "ENV_DUPLICATE_KEY",
572
+ message: `Duplicate key "${variable.key}" at line ${variable.lineNumber} \u2014 last occurrence wins.`,
573
+ line: variable.lineNumber,
574
+ key: variable.key
575
+ });
576
+ } else {
577
+ seenKeys.add(variable.key);
578
+ deduped.unshift(variable);
579
+ }
580
+ }
581
+ return { deduped, warnings };
582
+ }
562
583
  function parseEnvFileContent(content, filePath, options) {
563
584
  const lines = content.split("\n");
564
585
  const vars = [];
@@ -601,16 +622,13 @@ function parseEnvFileContent(content, filePath, options) {
601
622
  );
602
623
  commentBlock = [];
603
624
  }
604
- const seenKeys = /* @__PURE__ */ new Set();
605
- const deduped = [];
606
- for (let i = vars.length - 1; i >= 0; i--) {
607
- const variable = vars[i];
608
- if (variable !== void 0 && !seenKeys.has(variable.key)) {
609
- seenKeys.add(variable.key);
610
- deduped.unshift(variable);
611
- }
612
- }
613
- return { filePath, vars: deduped, groups };
625
+ const { deduped, warnings } = deduplicateVars(vars);
626
+ return {
627
+ filePath,
628
+ vars: deduped,
629
+ groups,
630
+ ...warnings.length > 0 && { warnings }
631
+ };
614
632
  }
615
633
  function parseEnvFile(filePath) {
616
634
  const content = readFileSync(filePath, "utf8");
@@ -626,7 +644,8 @@ async function readEnvFile(filePath) {
626
644
  return await readFile(resolved, "utf8");
627
645
  } catch (err) {
628
646
  if (err instanceof Error && err.code === "ENOENT") {
629
- throw new Error(`File not found: ${filePath}`);
647
+ const displayPath = path4.isAbsolute(filePath) ? filePath : `${filePath} (resolved: ${resolved})`;
648
+ throw new Error(`File not found: ${displayPath}`);
630
649
  }
631
650
  throw err;
632
651
  }
@@ -686,7 +705,8 @@ function deriveOutputPath(base, generator, isSingle) {
686
705
  function deriveOutputBaseForInput(output, inputPath) {
687
706
  const dir = path5.dirname(output);
688
707
  const ext = path5.extname(output);
689
- const stem = path5.basename(inputPath, path5.extname(inputPath));
708
+ const rawBasename = path5.basename(inputPath);
709
+ const stem = rawBasename.startsWith(".") ? rawBasename.slice(1).replaceAll(".", "-") : path5.basename(inputPath, path5.extname(inputPath));
690
710
  return path5.join(dir, `${stem}${ext}`);
691
711
  }
692
712
  function buildOutput(generator, parsed) {
@@ -723,6 +743,12 @@ async function persistOutput(params) {
723
743
  success(`Generated ${outputPath}`);
724
744
  }
725
745
  }
746
+ function emitParserWarnings(parsed) {
747
+ if (parsed.warnings === void 0) return;
748
+ for (const w of parsed.warnings) {
749
+ warn(`[${w.code}] ${w.message}`);
750
+ }
751
+ }
726
752
  async function runGenerate(options) {
727
753
  const {
728
754
  input,
@@ -745,6 +771,7 @@ async function runGenerate(options) {
745
771
  inputPath,
746
772
  inferenceRules2 === void 0 ? void 0 : { inferenceRules: inferenceRules2 }
747
773
  );
774
+ emitParserWarnings(parsed);
748
775
  for (const generator of generators) {
749
776
  let generated = buildOutput(generator, parsed);
750
777
  if (shouldFormat && !dryRun) {
@@ -842,7 +869,8 @@ async function loadCloudSource(options) {
842
869
  raw = await readFile2(resolvedPath, "utf8");
843
870
  } catch (err) {
844
871
  if (err instanceof Error && err.code === "ENOENT") {
845
- throw new Error(`File not found: ${options.filePath}`);
872
+ const displayPath = path6.isAbsolute(options.filePath) ? options.filePath : `${options.filePath} (resolved: ${resolvedPath})`;
873
+ throw new Error(`File not found: ${displayPath}`);
846
874
  }
847
875
  throw err;
848
876
  }
@@ -1692,7 +1720,8 @@ async function loadCommandConfig(configPath) {
1692
1720
  }
1693
1721
  const resolvedPath = path11.resolve(configPath);
1694
1722
  if (!existsSync4(resolvedPath)) {
1695
- throw new Error(`Config file not found: ${configPath}`);
1723
+ const displayPath = path11.isAbsolute(configPath) ? configPath : `${configPath} (resolved: ${resolvedPath})`;
1724
+ throw new Error(`Config file not found: ${displayPath}`);
1696
1725
  }
1697
1726
  const configDir = path11.dirname(resolvedPath);
1698
1727
  const moduleValue = await import(pathToFileURL4(resolvedPath).href);
@@ -2120,7 +2149,8 @@ async function runValidationSubcommand(subcommand, argv) {
2120
2149
  }
2121
2150
  async function loadExplicitConfig(configPath, userPath) {
2122
2151
  if (!existsSync6(configPath)) {
2123
- throw new Error(`Config file not found: ${userPath}`);
2152
+ const displayPath = path13.isAbsolute(userPath) ? userPath : `${userPath} (resolved: ${configPath})`;
2153
+ throw new Error(`Config file not found: ${displayPath}`);
2124
2154
  }
2125
2155
  const configDir = path13.dirname(configPath);
2126
2156
  const mod = await import(pathToFileURL5(configPath).href);
@@ -2128,6 +2158,9 @@ async function loadExplicitConfig(configPath, userPath) {
2128
2158
  return rawConfig ? applyConfigPaths2(rawConfig, configDir) : void 0;
2129
2159
  }
2130
2160
  async function runCli(argv = process.argv.slice(2)) {
2161
+ if (argv[0] === "generate") {
2162
+ argv = argv.slice(1);
2163
+ }
2131
2164
  const maybeSubcommand = argv[0];
2132
2165
  if (maybeSubcommand !== void 0 && VALIDATION_SUBCOMMANDS.has(maybeSubcommand)) {
2133
2166
  await runValidationSubcommand(maybeSubcommand, argv.slice(1));