@xlameiro/env-typegen 0.1.4 → 0.1.5

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
@@ -3,7 +3,7 @@ import path6 from 'path';
3
3
  import { pathToFileURL } from 'url';
4
4
  import { readFile, mkdir, writeFile } from 'fs/promises';
5
5
  import { format } from 'prettier';
6
- import { green, red, yellow } from 'picocolors';
6
+ import pc from 'picocolors';
7
7
  import { parseArgs } from 'util';
8
8
 
9
9
  // src/parser/comment-parser.ts
@@ -537,7 +537,15 @@ env-typegen.config.mjs for runtime loading.`
537
537
  return void 0;
538
538
  }
539
539
  async function readEnvFile(filePath) {
540
- return readFile(path6.resolve(filePath), "utf8");
540
+ const resolved = path6.resolve(filePath);
541
+ try {
542
+ return await readFile(resolved, "utf8");
543
+ } catch (err) {
544
+ if (err instanceof Error && err.code === "ENOENT") {
545
+ throw new Error(`File not found: ${filePath}`);
546
+ }
547
+ throw err;
548
+ }
541
549
  }
542
550
  async function writeOutput(filePath, content) {
543
551
  const resolved = path6.resolve(filePath);
@@ -555,6 +563,7 @@ async function formatOutput(content, parser = "typescript") {
555
563
  return content;
556
564
  }
557
565
  }
566
+ var { green, red, yellow } = pc;
558
567
  function log(message) {
559
568
  console.log(message);
560
569
  }
@@ -608,10 +617,6 @@ async function persistOutput(params) {
608
617
  }
609
618
  if (dryRun) {
610
619
  if (!silent) {
611
- if (!isSingle) {
612
- console.log(`// --- ${generator}: ${outputPath} ---`);
613
- }
614
- console.log(generated);
615
620
  success(`Dry run: would write ${outputPath}`);
616
621
  }
617
622
  return;
@@ -1023,7 +1028,15 @@ function parseProviderPayload(provider, value) {
1023
1028
  }
1024
1029
  async function loadCloudSource(options) {
1025
1030
  const resolvedPath = path6.resolve(options.filePath);
1026
- const raw = await readFile(resolvedPath, "utf8");
1031
+ let raw;
1032
+ try {
1033
+ raw = await readFile(resolvedPath, "utf8");
1034
+ } catch (err) {
1035
+ if (err instanceof Error && err.code === "ENOENT") {
1036
+ throw new Error(`File not found: ${options.filePath}`);
1037
+ }
1038
+ throw err;
1039
+ }
1027
1040
  const parsed = JSON.parse(raw);
1028
1041
  return parseProviderPayload(options.provider, parsed);
1029
1042
  }
@@ -1186,6 +1199,9 @@ function isPlugin(value) {
1186
1199
  }
1187
1200
  async function loadPluginFromPath(pluginPath, cwd) {
1188
1201
  const resolvedPath = path6.resolve(cwd, pluginPath);
1202
+ if (!existsSync(resolvedPath)) {
1203
+ throw new Error(`Plugin not found: ${pluginPath}`);
1204
+ }
1189
1205
  const moduleValue = await import(pathToFileURL(resolvedPath).href);
1190
1206
  const candidate = moduleValue.default ?? moduleValue.plugin;
1191
1207
  if (isPlugin(candidate)) return candidate;
@@ -1402,7 +1418,7 @@ function isClientSecret(variable, key) {
1402
1418
  function checkContractVariable(key, variable, context) {
1403
1419
  const { options, issues } = context;
1404
1420
  const value = options.values[key];
1405
- const hasValue = value !== void 0 && value.trim().length > 0;
1421
+ const hasValue = value !== void 0;
1406
1422
  if (variable.required && !hasValue) {
1407
1423
  issues.push(
1408
1424
  createIssue({
@@ -1583,12 +1599,8 @@ function diffEnvironmentSources(options) {
1583
1599
  sourceName,
1584
1600
  value: options.sources[sourceName]?.[key]
1585
1601
  }));
1586
- const present = valuesBySource.filter(
1587
- (entry) => entry.value !== void 0 && entry.value !== ""
1588
- );
1589
- const missing = valuesBySource.filter(
1590
- (entry) => entry.value === void 0 || entry.value === ""
1591
- );
1602
+ const present = valuesBySource.filter((entry) => entry.value !== void 0);
1603
+ const missing = valuesBySource.filter((entry) => entry.value === void 0);
1592
1604
  if (present.length === 0 && variable?.required === true) {
1593
1605
  for (const entry of missing) {
1594
1606
  issues.push(
@@ -1841,6 +1853,9 @@ async function loadCommandConfig(configPath) {
1841
1853
  return loadConfig(process.cwd());
1842
1854
  }
1843
1855
  const resolvedPath = path6.resolve(configPath);
1856
+ if (!existsSync(resolvedPath)) {
1857
+ throw new Error(`Config file not found: ${configPath}`);
1858
+ }
1844
1859
  const configDir = path6.dirname(resolvedPath);
1845
1860
  const moduleValue = await import(pathToFileURL(resolvedPath).href);
1846
1861
  if (moduleValue.default === void 0) return void 0;