bun-plugin-stx 0.2.571 → 0.2.573

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/preload.d.ts CHANGED
@@ -1 +1 @@
1
-
1
+ export {};
package/dist/serve.js CHANGED
@@ -8,19 +8,19 @@ import {
8
8
 
9
9
  // src/serve.ts
10
10
  var {serve: bunServe, Glob } = globalThis.Bun;
11
- import { existsSync as existsSync2, watch as fsWatch, realpathSync, statSync as statSync3 } from "fs";
11
+ import { existsSync as existsSync2, watch as fsWatch, realpathSync as realpathSync2, statSync as statSync4 } from "fs";
12
12
  import nodeFs from "fs/promises";
13
13
  import nodePath from "path";
14
- import process19 from "process";
14
+ import process20 from "process";
15
15
 
16
16
  // ../../node_modules/bunfig/dist/index.js
17
17
  import { existsSync, statSync } from "fs";
18
18
  import { resolve } from "path";
19
19
  import process from "process";
20
- import { existsSync as existsSync13, mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync, writeFileSync as writeFileSync7 } from "fs";
20
+ import { existsSync as existsSync12, mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync2, writeFileSync as writeFileSync7 } from "fs";
21
21
  import { homedir as homedir3 } from "os";
22
22
  import { dirname as dirname4, resolve as resolve12 } from "path";
23
- import process20 from "process";
23
+ import process19 from "process";
24
24
  import { existsSync as existsSync3, statSync as statSync2 } from "fs";
25
25
  import { existsSync as existsSync8, mkdirSync as mkdirSync3, readdirSync as readdirSync3, writeFileSync as writeFileSync5 } from "fs";
26
26
  import { homedir as homedir2 } from "os";
@@ -77,9 +77,12 @@ import { createGzip as createGzip3 } from "zlib";
77
77
  import process16 from "process";
78
78
  import process15 from "process";
79
79
  import process18 from "process";
80
- import { existsSync as existsSync10 } from "fs";
80
+ import { readFileSync, realpathSync } from "fs";
81
+ import { createRequire } from "module";
82
+ import { pathToFileURL } from "url";
83
+ import { existsSync as existsSync10, statSync as statSync3 } from "fs";
81
84
  import { resolve as resolve10 } from "path";
82
- import { existsSync as existsSync12 } from "fs";
85
+ import { existsSync as existsSync11 } from "fs";
83
86
  class ConfigCache {
84
87
  cache = new Map;
85
88
  totalHits = 0;
@@ -2665,7 +2668,7 @@ class Logger2 {
2665
2668
  const errorMessage = typeof error.message === "string" ? error.message : "Unknown error";
2666
2669
  console.error(`Network error during write attempt ${retries + 1}/${maxRetries}:`, errorMessage);
2667
2670
  const delay = backoffDelay * 2 ** retries;
2668
- await new Promise((resolve522) => setTimeout(resolve522, delay));
2671
+ await new Promise((resolve52) => setTimeout(resolve52, delay));
2669
2672
  retries++;
2670
2673
  continue;
2671
2674
  }
@@ -2693,7 +2696,7 @@ class Logger2 {
2693
2696
  }
2694
2697
  retries++;
2695
2698
  const delay = backoffDelay * 2 ** (retries - 1);
2696
- await new Promise((resolve522) => setTimeout(resolve522, delay));
2699
+ await new Promise((resolve52) => setTimeout(resolve52, delay));
2697
2700
  }
2698
2701
  }
2699
2702
  })();
@@ -2823,11 +2826,11 @@ class Logger2 {
2823
2826
  };
2824
2827
  }
2825
2828
  async compressData(data) {
2826
- return new Promise((resolve522, reject) => {
2829
+ return new Promise((resolve52, reject) => {
2827
2830
  const gzip = createGzip2();
2828
2831
  const chunks = [];
2829
2832
  gzip.on("data", (chunk2) => chunks.push(chunk2));
2830
- gzip.on("end", () => resolve522(Buffer2.from(Buffer2.concat(chunks))));
2833
+ gzip.on("end", () => resolve52(Buffer2.from(Buffer2.concat(chunks))));
2831
2834
  gzip.on("error", reject);
2832
2835
  gzip.write(data);
2833
2836
  gzip.end();
@@ -3516,7 +3519,7 @@ class Logger2 {
3516
3519
  if (isBrowserProcess2()) {
3517
3520
  return Promise.resolve(true);
3518
3521
  }
3519
- return new Promise((resolve522) => {
3522
+ return new Promise((resolve52) => {
3520
3523
  console.error(`${styles2.cyan("?")} ${message} (y/n) `);
3521
3524
  const onData = (data) => {
3522
3525
  const input = data.toString().trim().toLowerCase();
@@ -3528,7 +3531,7 @@ class Logger2 {
3528
3531
  } catch {}
3529
3532
  process11.stdin.pause();
3530
3533
  console.error("");
3531
- resolve522(input === "y" || input === "yes");
3534
+ resolve52(input === "y" || input === "yes");
3532
3535
  };
3533
3536
  try {
3534
3537
  if (typeof process11.stdin.setRawMode === "function") {
@@ -3694,7 +3697,7 @@ async function withErrorRecovery(fn, options = {}) {
3694
3697
  break;
3695
3698
  }
3696
3699
  if (retryDelay > 0) {
3697
- await new Promise((resolve522) => setTimeout(resolve522, retryDelay));
3700
+ await new Promise((resolve52) => setTimeout(resolve52, retryDelay));
3698
3701
  }
3699
3702
  }
3700
3703
  }
@@ -4323,8 +4326,8 @@ class ConfigFileLoader {
4323
4326
  }
4324
4327
  async getFileModificationTime(filePath) {
4325
4328
  try {
4326
- const { statSync: statSync22 } = await import("fs");
4327
- const stats = statSync22(filePath);
4329
+ const { statSync: statSync2 } = await import("fs");
4330
+ const stats = statSync2(filePath);
4328
4331
  return stats.mtime;
4329
4332
  } catch {
4330
4333
  return null;
@@ -5538,7 +5541,7 @@ var init_dist = __esm(async () => {
5538
5541
  error: bgRed2(white2(bold2(" ERROR ")))
5539
5542
  };
5540
5543
  logger2 = new Logger2("stacks");
5541
- BunfigError = class BunfigError2 extends Error {
5544
+ BunfigError = class BunfigError extends Error {
5542
5545
  timestamp;
5543
5546
  context;
5544
5547
  constructor(message, context = {}) {
@@ -5565,7 +5568,7 @@ var init_dist = __esm(async () => {
5565
5568
  return `${this.name} [${this.code}]: ${this.message}${contextStr}`;
5566
5569
  }
5567
5570
  };
5568
- ConfigNotFoundError = class ConfigNotFoundError2 extends BunfigError {
5571
+ ConfigNotFoundError = class ConfigNotFoundError extends BunfigError {
5569
5572
  code = "CONFIG_NOT_FOUND";
5570
5573
  constructor(configName, searchPaths, alias) {
5571
5574
  const aliasStr = alias ? ` or alias "${alias}"` : "";
@@ -5577,7 +5580,7 @@ var init_dist = __esm(async () => {
5577
5580
  });
5578
5581
  }
5579
5582
  };
5580
- ConfigLoadError = class ConfigLoadError2 extends BunfigError {
5583
+ ConfigLoadError = class ConfigLoadError extends BunfigError {
5581
5584
  code = "CONFIG_LOAD_ERROR";
5582
5585
  constructor(configPath, cause, configName) {
5583
5586
  super(`Failed to load configuration from "${configPath}": ${cause.message}`, {
@@ -5589,7 +5592,7 @@ var init_dist = __esm(async () => {
5589
5592
  this.cause = cause;
5590
5593
  }
5591
5594
  };
5592
- ConfigValidationError = class ConfigValidationError2 extends BunfigError {
5595
+ ConfigValidationError = class ConfigValidationError extends BunfigError {
5593
5596
  code = "CONFIG_VALIDATION_ERROR";
5594
5597
  constructor(configPath, validationErrors, configName) {
5595
5598
  super(`Configuration validation failed for "${configPath}"`, {
@@ -5600,7 +5603,7 @@ var init_dist = __esm(async () => {
5600
5603
  });
5601
5604
  }
5602
5605
  };
5603
- ConfigMergeError = class ConfigMergeError2 extends BunfigError {
5606
+ ConfigMergeError = class ConfigMergeError extends BunfigError {
5604
5607
  code = "CONFIG_MERGE_ERROR";
5605
5608
  constructor(sourcePath, targetPath, cause, configName) {
5606
5609
  super(`Failed to merge configuration from "${sourcePath}" with "${targetPath}": ${cause.message}`, {
@@ -5613,7 +5616,7 @@ var init_dist = __esm(async () => {
5613
5616
  this.cause = cause;
5614
5617
  }
5615
5618
  };
5616
- EnvVarError = class EnvVarError2 extends BunfigError {
5619
+ EnvVarError = class EnvVarError extends BunfigError {
5617
5620
  code = "ENV_VAR_ERROR";
5618
5621
  constructor(envKey, envValue, expectedType, configName) {
5619
5622
  super(`Failed to parse environment variable "${envKey}" with value "${envValue}" as ${expectedType}`, {
@@ -5624,7 +5627,7 @@ var init_dist = __esm(async () => {
5624
5627
  });
5625
5628
  }
5626
5629
  };
5627
- FileSystemError = class FileSystemError2 extends BunfigError {
5630
+ FileSystemError = class FileSystemError extends BunfigError {
5628
5631
  code = "FILE_SYSTEM_ERROR";
5629
5632
  constructor(operation, path, cause) {
5630
5633
  super(`File system ${operation} failed for "${path}": ${cause.message}`, {
@@ -5636,7 +5639,7 @@ var init_dist = __esm(async () => {
5636
5639
  this.cause = cause;
5637
5640
  }
5638
5641
  };
5639
- TypeGenerationError = class TypeGenerationError2 extends BunfigError {
5642
+ TypeGenerationError = class TypeGenerationError extends BunfigError {
5640
5643
  code = "TYPE_GENERATION_ERROR";
5641
5644
  constructor(configDir, outputPath, cause) {
5642
5645
  super(`Failed to generate types from "${configDir}" to "${outputPath}": ${cause.message}`, {
@@ -5648,7 +5651,7 @@ var init_dist = __esm(async () => {
5648
5651
  this.cause = cause;
5649
5652
  }
5650
5653
  };
5651
- SchemaValidationError = class SchemaValidationError2 extends BunfigError {
5654
+ SchemaValidationError = class SchemaValidationError extends BunfigError {
5652
5655
  code = "SCHEMA_VALIDATION_ERROR";
5653
5656
  constructor(schemaPath, validationErrors, configName) {
5654
5657
  super(`Schema validation failed${configName ? ` for config "${configName}"` : ""}`, {
@@ -5659,7 +5662,7 @@ var init_dist = __esm(async () => {
5659
5662
  });
5660
5663
  }
5661
5664
  };
5662
- BrowserConfigError = class BrowserConfigError2 extends BunfigError {
5665
+ BrowserConfigError = class BrowserConfigError extends BunfigError {
5663
5666
  code = "BROWSER_CONFIG_ERROR";
5664
5667
  constructor(endpoint, status, statusText, configName) {
5665
5668
  super(`Failed to fetch configuration from "${endpoint}": ${status} ${statusText}`, {
@@ -5670,7 +5673,7 @@ var init_dist = __esm(async () => {
5670
5673
  });
5671
5674
  }
5672
5675
  };
5673
- PluginError = class PluginError2 extends BunfigError {
5676
+ PluginError = class PluginError extends BunfigError {
5674
5677
  code = "PLUGIN_ERROR";
5675
5678
  constructor(pluginName, operation, cause) {
5676
5679
  super(`Plugin "${pluginName}" failed during ${operation}: ${cause.message}`, {
@@ -7106,6 +7109,7 @@ class BunfigError2 extends Error {
7106
7109
  }
7107
7110
 
7108
7111
  class ConfigNotFoundError2 extends BunfigError2 {
7112
+ name = "ConfigNotFoundError";
7109
7113
  code = "CONFIG_NOT_FOUND";
7110
7114
  constructor(configName, searchPaths, alias) {
7111
7115
  const aliasList = alias === undefined ? [] : Array.isArray(alias) ? alias.filter(Boolean) : [alias];
@@ -7124,6 +7128,7 @@ class ConfigNotFoundError2 extends BunfigError2 {
7124
7128
  }
7125
7129
 
7126
7130
  class ConfigLoadError2 extends BunfigError2 {
7131
+ name = "ConfigLoadError";
7127
7132
  code = "CONFIG_LOAD_ERROR";
7128
7133
  constructor(configPath, cause, configName) {
7129
7134
  super(`Failed to load configuration from "${configPath}": ${cause.message}`, {
@@ -7137,6 +7142,7 @@ class ConfigLoadError2 extends BunfigError2 {
7137
7142
  }
7138
7143
 
7139
7144
  class ConfigValidationError2 extends BunfigError2 {
7145
+ name = "ConfigValidationError";
7140
7146
  code = "CONFIG_VALIDATION_ERROR";
7141
7147
  constructor(configPath, validationErrors, configName) {
7142
7148
  super(`Configuration validation failed for "${configPath}"`, {
@@ -7149,6 +7155,7 @@ class ConfigValidationError2 extends BunfigError2 {
7149
7155
  }
7150
7156
 
7151
7157
  class ConfigMergeError2 extends BunfigError2 {
7158
+ name = "ConfigMergeError";
7152
7159
  code = "CONFIG_MERGE_ERROR";
7153
7160
  constructor(sourcePath, targetPath, cause, configName) {
7154
7161
  super(`Failed to merge configuration from "${sourcePath}" with "${targetPath}": ${cause.message}`, {
@@ -7163,6 +7170,7 @@ class ConfigMergeError2 extends BunfigError2 {
7163
7170
  }
7164
7171
 
7165
7172
  class EnvVarError2 extends BunfigError2 {
7173
+ name = "EnvVarError";
7166
7174
  code = "ENV_VAR_ERROR";
7167
7175
  constructor(envKey, envValue, expectedType, configName) {
7168
7176
  super(`Failed to parse environment variable "${envKey}" with value "${envValue}" as ${expectedType}`, {
@@ -7175,6 +7183,7 @@ class EnvVarError2 extends BunfigError2 {
7175
7183
  }
7176
7184
 
7177
7185
  class FileSystemError2 extends BunfigError2 {
7186
+ name = "FileSystemError";
7178
7187
  code = "FILE_SYSTEM_ERROR";
7179
7188
  constructor(operation, path, cause) {
7180
7189
  super(`File system ${operation} failed for "${path}": ${cause.message}`, {
@@ -7188,6 +7197,7 @@ class FileSystemError2 extends BunfigError2 {
7188
7197
  }
7189
7198
 
7190
7199
  class TypeGenerationError2 extends BunfigError2 {
7200
+ name = "TypeGenerationError";
7191
7201
  code = "TYPE_GENERATION_ERROR";
7192
7202
  constructor(configDir, outputPath, cause) {
7193
7203
  super(`Failed to generate types from "${configDir}" to "${outputPath}": ${cause.message}`, {
@@ -7201,6 +7211,7 @@ class TypeGenerationError2 extends BunfigError2 {
7201
7211
  }
7202
7212
 
7203
7213
  class SchemaValidationError2 extends BunfigError2 {
7214
+ name = "SchemaValidationError";
7204
7215
  code = "SCHEMA_VALIDATION_ERROR";
7205
7216
  constructor(schemaPath, validationErrors, configName) {
7206
7217
  super(`Schema validation failed${configName ? ` for config "${configName}"` : ""}`, {
@@ -7213,6 +7224,7 @@ class SchemaValidationError2 extends BunfigError2 {
7213
7224
  }
7214
7225
 
7215
7226
  class BrowserConfigError2 extends BunfigError2 {
7227
+ name = "BrowserConfigError";
7216
7228
  code = "BROWSER_CONFIG_ERROR";
7217
7229
  constructor(endpoint, status, statusText, configName) {
7218
7230
  super(`Failed to fetch configuration from "${endpoint}": ${status} ${statusText}`, {
@@ -7225,6 +7237,7 @@ class BrowserConfigError2 extends BunfigError2 {
7225
7237
  }
7226
7238
 
7227
7239
  class PluginError2 extends BunfigError2 {
7240
+ name = "PluginError";
7228
7241
  code = "PLUGIN_ERROR";
7229
7242
  constructor(pluginName, operation, cause) {
7230
7243
  super(`Plugin "${pluginName}" failed during ${operation}: ${cause.message}`, {
@@ -7285,7 +7298,7 @@ async function withErrorRecovery2(fn, options = {}) {
7285
7298
  break;
7286
7299
  }
7287
7300
  if (retryDelay > 0) {
7288
- await new Promise((resolve10) => setTimeout(resolve10, retryDelay));
7301
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
7289
7302
  }
7290
7303
  }
7291
7304
  }
@@ -7343,7 +7356,7 @@ class EnvProcessor2 {
7343
7356
  }
7344
7357
  ];
7345
7358
  }
7346
- async applyEnvironmentVariables(configName, config5, options = {}) {
7359
+ async applyEnvironmentVariables(configName, config, options = {}) {
7347
7360
  const {
7348
7361
  prefix,
7349
7362
  useCamelCase = true,
@@ -7355,12 +7368,12 @@ class EnvProcessor2 {
7355
7368
  const operation = async () => {
7356
7369
  if (!configName) {
7357
7370
  return {
7358
- config: config5,
7371
+ config,
7359
7372
  source: { type: "environment", priority: 50, timestamp: new Date }
7360
7373
  };
7361
7374
  }
7362
7375
  const envPrefix = prefix || this.generateEnvPrefix(configName);
7363
- const result = { ...config5 };
7376
+ const result = { ...config };
7364
7377
  this.processObject(result, [], envPrefix, {
7365
7378
  useCamelCase,
7366
7379
  useBackwardCompatibility,
@@ -7462,11 +7475,11 @@ class EnvProcessor2 {
7462
7475
  errors
7463
7476
  };
7464
7477
  }
7465
- generateEnvVarDocs(configName, defaultConfig4, options = {}) {
7478
+ generateEnvVarDocs(configName, defaultConfig, options = {}) {
7466
7479
  const { prefix, format = "text" } = options;
7467
7480
  const envPrefix = prefix || this.generateEnvPrefix(configName);
7468
7481
  const envVars = [];
7469
- this.extractEnvVarInfo(defaultConfig4, [], envPrefix, envVars);
7482
+ this.extractEnvVarInfo(defaultConfig, [], envPrefix, envVars);
7470
7483
  switch (format) {
7471
7484
  case "markdown":
7472
7485
  return this.formatAsMarkdown(envVars, configName);
@@ -7533,6 +7546,39 @@ class EnvProcessor2 {
7533
7546
  return result;
7534
7547
  }
7535
7548
  }
7549
+ var configurationRequire = createRequire(import.meta.url);
7550
+ var pendingImports = new Map;
7551
+ var rejectedImports = new Set;
7552
+ function isMissingConfigPath(error) {
7553
+ return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
7554
+ }
7555
+ async function importFreshConfiguration(path) {
7556
+ const canonicalPath = realpathSync(path);
7557
+ const previous = pendingImports.get(canonicalPath);
7558
+ let release;
7559
+ const current = new Promise((resolve) => {
7560
+ release = resolve;
7561
+ });
7562
+ pendingImports.set(canonicalPath, current);
7563
+ await previous;
7564
+ try {
7565
+ readFileSync(canonicalPath);
7566
+ if (configurationRequire.cache[canonicalPath]?.loaded === true || rejectedImports.has(canonicalPath))
7567
+ delete configurationRequire.cache[canonicalPath];
7568
+ try {
7569
+ const imported = await import(pathToFileURL(canonicalPath).href);
7570
+ rejectedImports.delete(canonicalPath);
7571
+ return imported;
7572
+ } catch (error) {
7573
+ rejectedImports.add(canonicalPath);
7574
+ throw error;
7575
+ }
7576
+ } finally {
7577
+ release();
7578
+ if (pendingImports.get(canonicalPath) === current)
7579
+ pendingImports.delete(canonicalPath);
7580
+ }
7581
+ }
7536
7582
  function deepMerge4(target, source, options = {}) {
7537
7583
  const visited = new WeakMap;
7538
7584
  return deepMergeWithVisited2(target, source, options, visited);
@@ -7705,13 +7751,14 @@ function isObject4(item) {
7705
7751
 
7706
7752
  class ConfigFileLoader2 {
7707
7753
  extensions = CONFIG_FILE_EXTENSIONS;
7708
- async loadFromPath(configPath, defaultConfig4, options = {}) {
7754
+ async loadFromPath(configPath, defaultConfig, options = {}) {
7709
7755
  const {
7710
7756
  arrayStrategy = "replace",
7711
7757
  useCache = true,
7712
7758
  cacheTtl,
7713
7759
  trackPerformance = true,
7714
- verbose = false
7760
+ verbose = false,
7761
+ strictDiscovery = false
7715
7762
  } = options;
7716
7763
  if (useCache) {
7717
7764
  const cached = globalCache.getWithFileCheck("file", configPath);
@@ -7723,22 +7770,25 @@ class ConfigFileLoader2 {
7723
7770
  }
7724
7771
  }
7725
7772
  const loadOperation = async () => {
7726
- if (!existsSync10(configPath)) {
7727
- return null;
7728
- }
7729
7773
  try {
7730
- const cacheBuster = `?t=${Date.now()}`;
7731
- const importedConfig = await import(configPath + cacheBuster);
7732
- const loadedConfig = importedConfig.default || importedConfig;
7733
- const hasDefaultExport = "default" in importedConfig;
7774
+ try {
7775
+ statSync3(configPath);
7776
+ } catch (error) {
7777
+ if (isMissingConfigPath(error) || !strictDiscovery)
7778
+ return null;
7779
+ throw error;
7780
+ }
7781
+ const importedConfig = await importFreshConfiguration(configPath);
7782
+ const hasDefaultExport = Object.hasOwn(importedConfig, "default");
7734
7783
  const hasNamedExports = Object.keys(importedConfig).length > 0;
7784
+ const loadedConfig = hasDefaultExport ? importedConfig.default : importedConfig;
7735
7785
  if (!hasDefaultExport && !hasNamedExports) {
7736
7786
  throw new ConfigLoadError2(configPath, new Error("Configuration file is empty and exports nothing"), "unknown");
7737
7787
  }
7738
7788
  if (typeof loadedConfig !== "object" || loadedConfig === null || Array.isArray(loadedConfig)) {
7739
7789
  throw new ConfigLoadError2(configPath, new Error("Configuration must export a valid object"), "unknown");
7740
7790
  }
7741
- const mergedConfig = deepMergeWithArrayStrategy3(defaultConfig4, loadedConfig, arrayStrategy);
7791
+ const mergedConfig = deepMergeWithArrayStrategy3(defaultConfig, loadedConfig, arrayStrategy);
7742
7792
  const source = {
7743
7793
  type: "file",
7744
7794
  path: configPath,
@@ -7760,15 +7810,15 @@ class ConfigFileLoader2 {
7760
7810
  }
7761
7811
  return loadOperation();
7762
7812
  }
7763
- async tryLoadFromPaths(configPaths, defaultConfig4, options = {}) {
7813
+ async tryLoadFromPaths(configPaths, defaultConfig, options = {}) {
7764
7814
  for (const configPath of configPaths) {
7765
7815
  try {
7766
- const result = await this.loadFromPath(configPath, defaultConfig4, options);
7816
+ const result = await this.loadFromPath(configPath, defaultConfig, options);
7767
7817
  if (result) {
7768
7818
  return result;
7769
7819
  }
7770
7820
  } catch (error) {
7771
- if (error instanceof Error && error.name === "ConfigLoadError") {
7821
+ if (error instanceof ConfigLoadError2) {
7772
7822
  throw error;
7773
7823
  }
7774
7824
  if (options.verbose) {
@@ -7810,8 +7860,8 @@ class ConfigFileLoader2 {
7810
7860
  }
7811
7861
  } else {
7812
7862
  try {
7813
- const { readdirSync: readdirSync4 } = await import("fs");
7814
- const files = readdirSync4(directory);
7863
+ const { readdirSync } = await import("fs");
7864
+ const files = readdirSync(directory);
7815
7865
  for (const file of files) {
7816
7866
  if (this.looksLikeConfigFile(file)) {
7817
7867
  const filePath = resolve10(directory, file);
@@ -7842,12 +7892,12 @@ class ConfigFileLoader2 {
7842
7892
  return errors;
7843
7893
  }
7844
7894
  const imported = await import(filePath);
7845
- const config5 = imported.default || imported;
7846
- if (config5 === undefined) {
7895
+ const config = imported.default || imported;
7896
+ if (config === undefined) {
7847
7897
  errors.push("Configuration file must export a default value or named exports");
7848
- } else if (typeof config5 !== "object" || config5 === null) {
7898
+ } else if (typeof config !== "object" || config === null) {
7849
7899
  errors.push("Configuration must be an object");
7850
- } else if (Array.isArray(config5)) {
7900
+ } else if (Array.isArray(config)) {
7851
7901
  errors.push("Configuration cannot be an array at the root level");
7852
7902
  }
7853
7903
  if (filePath.endsWith(".json")) {
@@ -7866,8 +7916,8 @@ class ConfigFileLoader2 {
7866
7916
  }
7867
7917
  async getFileModificationTime(filePath) {
7868
7918
  try {
7869
- const { statSync: statSync3 } = await import("fs");
7870
- const stats = statSync3(filePath);
7919
+ const { statSync } = await import("fs");
7920
+ const stats = statSync(filePath);
7871
7921
  return stats.mtime;
7872
7922
  } catch {
7873
7923
  return null;
@@ -7893,7 +7943,7 @@ class ConfigFileLoader2 {
7893
7943
  var URL_PATTERN2 = /^https?:\/\//;
7894
7944
 
7895
7945
  class ConfigValidator2 {
7896
- async validateConfiguration(config5, schema, options = {}) {
7946
+ async validateConfiguration(config, schema, options = {}) {
7897
7947
  const {
7898
7948
  stopOnFirstError = false,
7899
7949
  validateRequired = true,
@@ -7915,11 +7965,11 @@ class ConfigValidator2 {
7915
7965
  };
7916
7966
  try {
7917
7967
  if (typeof schema === "string") {
7918
- return await this.validateWithSchemaFile(config5, schema, resolvedOptions);
7968
+ return await this.validateWithSchemaFile(config, schema, resolvedOptions);
7919
7969
  } else if (Array.isArray(schema)) {
7920
- return this.validateWithRules(config5, [...schema, ...customRules], resolvedOptions);
7970
+ return this.validateWithRules(config, [...schema, ...customRules], resolvedOptions);
7921
7971
  } else {
7922
- return this.validateWithJSONSchema(config5, schema, resolvedOptions);
7972
+ return this.validateWithJSONSchema(config, schema, resolvedOptions);
7923
7973
  }
7924
7974
  } catch (error) {
7925
7975
  errors.push({
@@ -7936,26 +7986,28 @@ class ConfigValidator2 {
7936
7986
  }
7937
7987
  return operation();
7938
7988
  }
7939
- async validateWithSchemaFile(config5, schemaPath, options) {
7989
+ async validateWithSchemaFile(config, schemaPath, options) {
7940
7990
  try {
7941
- if (!existsSync12(schemaPath)) {
7991
+ if (!existsSync11(schemaPath)) {
7942
7992
  throw new SchemaValidationError2(schemaPath, [{ path: "", message: "Schema file does not exist" }]);
7943
7993
  }
7944
- const schemaModule = await import(schemaPath);
7945
- const schema = schemaModule.default || schemaModule;
7994
+ const schemaModule = await importFreshConfiguration(schemaPath);
7995
+ const schema = Object.hasOwn(schemaModule, "default") ? schemaModule.default : schemaModule;
7946
7996
  if (Array.isArray(schema)) {
7947
- return this.validateWithRules(config5, schema, options);
7997
+ return this.validateWithRules(config, schema, options);
7948
7998
  } else {
7949
- return this.validateWithJSONSchema(config5, schema, options);
7999
+ if (typeof schema !== "object" || schema === null)
8000
+ throw new Error("Schema must export an object or validation rule array");
8001
+ return this.validateWithJSONSchema(config, schema, options);
7950
8002
  }
7951
8003
  } catch (error) {
7952
8004
  throw new SchemaValidationError2(schemaPath, [{ path: "", message: `Failed to load schema: ${error}` }]);
7953
8005
  }
7954
8006
  }
7955
- validateWithJSONSchema(config5, schema, options) {
8007
+ validateWithJSONSchema(config, schema, options) {
7956
8008
  const errors = [];
7957
8009
  const warnings = [];
7958
- this.validateObjectAgainstSchema(config5, schema, "", errors, warnings, options);
8010
+ this.validateObjectAgainstSchema(config, schema, "", errors, warnings, options);
7959
8011
  return {
7960
8012
  isValid: errors.length === 0,
7961
8013
  errors,
@@ -8089,12 +8141,12 @@ class ConfigValidator2 {
8089
8141
  }
8090
8142
  }
8091
8143
  }
8092
- validateWithRules(config5, rules, options) {
8144
+ validateWithRules(config, rules, options) {
8093
8145
  const errors = [];
8094
8146
  const warnings = [];
8095
8147
  for (const rule of rules) {
8096
8148
  try {
8097
- const value = this.getValueByPath(config5, rule.path);
8149
+ const value = this.getValueByPath(config, rule.path);
8098
8150
  const ruleErrors = this.validateWithRule(value, rule, rule.path);
8099
8151
  errors.push(...ruleErrors);
8100
8152
  if (options.stopOnFirstError && errors.length > 0) {
@@ -8286,8 +8338,9 @@ class ConfigLoader2 {
8286
8338
  validate: customValidator,
8287
8339
  ...baseOptions
8288
8340
  } = options;
8341
+ const effectiveCache = baseOptions.errorPolicy === "throw" ? { ...cache, enabled: false } : cache;
8289
8342
  try {
8290
- if (cache?.enabled) {
8343
+ if (effectiveCache?.enabled) {
8291
8344
  const cached = this.checkCache(baseOptions.name || "", baseOptions);
8292
8345
  if (cached) {
8293
8346
  return cached;
@@ -8295,13 +8348,13 @@ class ConfigLoader2 {
8295
8348
  }
8296
8349
  let result;
8297
8350
  try {
8298
- result = await this.loadConfigurationStrategies(baseOptions, true, cache);
8351
+ result = await this.loadConfigurationStrategies(baseOptions, true, effectiveCache);
8299
8352
  } catch (error) {
8300
- if (baseOptions.configFile)
8353
+ if (baseOptions.configFile || baseOptions.errorPolicy === "throw" && !(error instanceof ConfigNotFoundError2))
8301
8354
  throw error;
8302
8355
  const isStrictMode = baseOptions.__strictErrorHandling;
8303
- if (error instanceof Error && error.name === "ConfigNotFoundError") {
8304
- if (isStrictMode) {
8356
+ if (error instanceof ConfigNotFoundError2) {
8357
+ if (isStrictMode && baseOptions.errorPolicy !== "throw") {
8305
8358
  throw error;
8306
8359
  }
8307
8360
  const envResult = await this.applyEnvironmentVariables(baseOptions.name || "", baseOptions.defaultConfig, baseOptions.checkEnv !== false, baseOptions.verbose || false);
@@ -8309,7 +8362,7 @@ class ConfigLoader2 {
8309
8362
  ...envResult,
8310
8363
  warnings: [`No configuration file found for "${baseOptions.name || "config"}", using defaults with environment variables`]
8311
8364
  };
8312
- } else if (error instanceof Error && error.name === "ConfigLoadError") {
8365
+ } else if (error instanceof ConfigLoadError2) {
8313
8366
  const isPermissionError = error.message.includes("EACCES") || error.message.includes("EPERM") || error.message.includes("permission denied");
8314
8367
  const isSyntaxError = !isPermissionError && (error.message.includes("syntax") || error.message.includes("Expected") || error.message.includes("Unexpected") || error.message.includes("BuildMessage") || error.message.includes("errors building"));
8315
8368
  const isStructureError = error.message.includes("Configuration must export a valid object") || error.message.includes("Configuration file is empty and exports nothing");
@@ -8342,8 +8395,8 @@ class ConfigLoader2 {
8342
8395
  if (schema || customValidator) {
8343
8396
  await this.validateConfiguration(result.config, schema, customValidator, baseOptions.name);
8344
8397
  }
8345
- if (cache?.enabled && result) {
8346
- this.cacheResult(baseOptions.name || "", result, cache, baseOptions);
8398
+ if (effectiveCache?.enabled && result) {
8399
+ this.cacheResult(baseOptions.name || "", result, effectiveCache, baseOptions);
8347
8400
  }
8348
8401
  if (performance2?.enabled) {
8349
8402
  const metrics = {
@@ -8362,7 +8415,7 @@ class ConfigLoader2 {
8362
8415
  }
8363
8416
  return result;
8364
8417
  } catch (error) {
8365
- if (error instanceof Error && error.name === "ConfigNotFoundError")
8418
+ if (error instanceof ConfigNotFoundError2)
8366
8419
  throw error;
8367
8420
  const duration = Date.now() - startTime;
8368
8421
  log3.error(`Configuration loading failed after ${duration}ms:`, [error instanceof Error ? error : new Error(String(error))]);
@@ -8376,35 +8429,35 @@ class ConfigLoader2 {
8376
8429
  configFile,
8377
8430
  cwd,
8378
8431
  configDir,
8379
- defaultConfig: defaultConfig4,
8432
+ defaultConfig,
8380
8433
  checkEnv = true,
8381
8434
  arrayStrategy = "replace",
8382
8435
  verbose = false
8383
8436
  } = options;
8384
- const baseDir = cwd || process20.cwd();
8437
+ const baseDir = cwd || process19.cwd();
8385
8438
  const searchPaths = [];
8386
8439
  if (configFile) {
8387
8440
  const explicitPath = resolve12(baseDir, configFile);
8388
8441
  searchPaths.push(explicitPath);
8389
- const envDefaults = checkEnv ? applyEnvVarsToConfig3(name, defaultConfig4, verbose) : defaultConfig4;
8390
- const explicitResult = await this.fileLoader.tryLoadFromPaths([explicitPath], envDefaults, { arrayStrategy, verbose, cacheTtl: cacheOptions?.ttl, useCache: !cacheOptions?.ttl || cacheOptions.ttl > 100 });
8442
+ const envDefaults = checkEnv ? applyEnvVarsToConfig3(name, defaultConfig, verbose) : defaultConfig;
8443
+ const explicitResult = await this.fileLoader.tryLoadFromPaths([explicitPath], envDefaults, { arrayStrategy, verbose, cacheTtl: cacheOptions?.ttl, useCache: cacheOptions?.enabled !== false && (!cacheOptions?.ttl || cacheOptions.ttl > 100), strictDiscovery: true });
8391
8444
  if (!explicitResult)
8392
8445
  throw ErrorFactory2.configNotFound(name || configFile, searchPaths, alias);
8393
8446
  if (verbose)
8394
8447
  log3.success(`Configuration loaded from explicit path: ${explicitPath}`);
8395
8448
  return this.finalizeResult(explicitResult, searchPaths, checkEnv, name, verbose);
8396
8449
  }
8397
- const localResult = await this.loadLocalConfiguration(name, alias, baseDir, configDir, defaultConfig4, arrayStrategy, verbose, checkEnv, cacheOptions);
8450
+ const localResult = await this.loadLocalConfiguration(name, alias, baseDir, configDir, defaultConfig, arrayStrategy, verbose, checkEnv, cacheOptions, options.errorPolicy === "throw");
8398
8451
  if (localResult) {
8399
8452
  searchPaths.push(...this.getLocalSearchPaths(name, alias, baseDir, configDir));
8400
8453
  return this.finalizeResult(localResult, searchPaths, checkEnv, name, verbose);
8401
8454
  }
8402
- const homeResult = await this.loadHomeConfiguration(name, alias, defaultConfig4, arrayStrategy, verbose, checkEnv);
8455
+ const homeResult = await this.loadHomeConfiguration(name, alias, defaultConfig, arrayStrategy, verbose, checkEnv, cacheOptions, options.errorPolicy === "throw");
8403
8456
  if (homeResult) {
8404
8457
  searchPaths.push(...this.getHomeSearchPaths(name, alias));
8405
8458
  return this.finalizeResult(homeResult, searchPaths, checkEnv, name, verbose);
8406
8459
  }
8407
- const packageResult = await this.loadPackageJsonConfiguration(name, alias, baseDir, defaultConfig4, arrayStrategy, verbose, checkEnv);
8460
+ const packageResult = await this.loadPackageJsonConfiguration(name, alias, baseDir, defaultConfig, arrayStrategy, verbose, checkEnv, options.errorPolicy);
8408
8461
  if (packageResult) {
8409
8462
  searchPaths.push(resolve12(baseDir, "package.json"));
8410
8463
  return this.finalizeResult(packageResult, searchPaths, checkEnv, name, verbose);
@@ -8413,14 +8466,14 @@ class ConfigLoader2 {
8413
8466
  if (throwOnNotFound) {
8414
8467
  throw ErrorFactory2.configNotFound(name, searchPaths, alias);
8415
8468
  }
8416
- const envResult = await this.applyEnvironmentVariables(name, defaultConfig4, checkEnv, verbose);
8469
+ const envResult = await this.applyEnvironmentVariables(name, defaultConfig, checkEnv, verbose);
8417
8470
  return {
8418
8471
  ...envResult,
8419
8472
  warnings: [`No configuration file found for "${name}"${formatAliasSuffix(alias)}, using defaults with environment variables`]
8420
8473
  };
8421
8474
  }
8422
- async loadLocalConfiguration(name, alias, baseDir, configDir, defaultConfig4, arrayStrategy, verbose, checkEnv, cacheOptions) {
8423
- const envDefaultConfig = checkEnv ? applyEnvVarsToConfig3(name, defaultConfig4, verbose) : defaultConfig4;
8475
+ async loadLocalConfiguration(name, alias, baseDir, configDir, defaultConfig, arrayStrategy, verbose, checkEnv, cacheOptions, strictDiscovery = false) {
8476
+ const envDefaultConfig = checkEnv ? applyEnvVarsToConfig3(name, defaultConfig, verbose) : defaultConfig;
8424
8477
  const searchDirectories = this.getLocalDirectories(baseDir, configDir);
8425
8478
  for (const directory of searchDirectories) {
8426
8479
  if (verbose) {
@@ -8431,7 +8484,8 @@ class ConfigLoader2 {
8431
8484
  arrayStrategy,
8432
8485
  verbose,
8433
8486
  cacheTtl: cacheOptions?.ttl,
8434
- useCache: !cacheOptions?.ttl || cacheOptions.ttl > 100
8487
+ useCache: cacheOptions?.enabled !== false && (!cacheOptions?.ttl || cacheOptions.ttl > 100),
8488
+ strictDiscovery
8435
8489
  });
8436
8490
  if (result) {
8437
8491
  if (verbose) {
@@ -8442,10 +8496,10 @@ class ConfigLoader2 {
8442
8496
  }
8443
8497
  return null;
8444
8498
  }
8445
- async loadHomeConfiguration(name, alias, defaultConfig4, arrayStrategy, verbose, checkEnv) {
8499
+ async loadHomeConfiguration(name, alias, defaultConfig, arrayStrategy, verbose, checkEnv, cacheOptions, strictDiscovery = false) {
8446
8500
  if (!name)
8447
8501
  return null;
8448
- const envDefaultConfig = checkEnv ? applyEnvVarsToConfig3(name, defaultConfig4, verbose) : defaultConfig4;
8502
+ const envDefaultConfig = checkEnv ? applyEnvVarsToConfig3(name, defaultConfig, verbose) : defaultConfig;
8449
8503
  const homeDirectories = [
8450
8504
  resolve12(homedir3(), ".config", name),
8451
8505
  resolve12(homedir3(), ".config"),
@@ -8456,7 +8510,7 @@ class ConfigLoader2 {
8456
8510
  log3.info(`Checking home directory: ${directory}`);
8457
8511
  }
8458
8512
  const configPaths = this.fileLoader.generateConfigPaths(name, directory, alias);
8459
- const result = await this.fileLoader.tryLoadFromPaths(configPaths, envDefaultConfig, { arrayStrategy, verbose });
8513
+ const result = await this.fileLoader.tryLoadFromPaths(configPaths, envDefaultConfig, { arrayStrategy, verbose, cacheTtl: cacheOptions?.ttl, useCache: cacheOptions?.enabled !== false && (!cacheOptions?.ttl || cacheOptions.ttl > 100), strictDiscovery });
8460
8514
  if (result) {
8461
8515
  if (verbose) {
8462
8516
  log3.success(`Configuration loaded from home directory: ${result.source.path}`);
@@ -8466,62 +8520,48 @@ class ConfigLoader2 {
8466
8520
  }
8467
8521
  return null;
8468
8522
  }
8469
- async loadPackageJsonConfiguration(name, alias, baseDir, defaultConfig4, arrayStrategy, verbose, checkEnv) {
8470
- const envDefaultConfig = checkEnv ? applyEnvVarsToConfig3(name, defaultConfig4, verbose) : defaultConfig4;
8523
+ async loadPackageJsonConfiguration(name, alias, baseDir, defaultConfig, arrayStrategy, verbose, checkEnv, errorPolicy) {
8524
+ const envDefaultConfig = checkEnv ? applyEnvVarsToConfig3(name, defaultConfig, verbose) : defaultConfig;
8525
+ const pkgPath = resolve12(baseDir, "package.json");
8526
+ const strict = errorPolicy === "throw";
8471
8527
  try {
8472
- const pkgPath = resolve12(baseDir, "package.json");
8473
- if (!existsSync13(pkgPath)) {
8528
+ const parsed = JSON.parse(readFileSync2(pkgPath, "utf8"));
8529
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
8530
+ throw new Error("package.json must contain an object");
8531
+ const pkg = parsed;
8532
+ const aliases = alias === undefined ? [] : Array.isArray(alias) ? alias : [alias];
8533
+ const names = [name, ...aliases.filter(Boolean)];
8534
+ const usedName = names.find((candidate) => Object.hasOwn(pkg, candidate) && (strict || Boolean(pkg[candidate])));
8535
+ if (usedName === undefined)
8474
8536
  return null;
8475
- }
8476
- let pkg = {};
8477
- try {
8478
- pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
8479
- } catch (parseError) {
8480
- if (verbose) {
8481
- log3.warn(`Failed to parse package.json:`, [parseError instanceof Error ? parseError : new Error(String(parseError))]);
8482
- }
8483
- return null;
8484
- }
8485
- let pkgConfig = pkg[name];
8486
- let usedName = name;
8487
- if (!pkgConfig && alias) {
8488
- const aliases = Array.isArray(alias) ? alias : [alias];
8489
- for (const a of aliases) {
8490
- if (!a)
8491
- continue;
8492
- if (pkg[a]) {
8493
- pkgConfig = pkg[a];
8494
- usedName = a;
8495
- break;
8496
- }
8497
- }
8498
- }
8499
- if (pkgConfig && typeof pkgConfig === "object" && !Array.isArray(pkgConfig)) {
8500
- if (verbose) {
8501
- log3.success(`Configuration loaded from package.json: ${usedName}`);
8537
+ const pkgConfig = pkg[usedName];
8538
+ if (typeof pkgConfig !== "object" || pkgConfig === null || Array.isArray(pkgConfig))
8539
+ throw new Error(`Configuration field "${usedName}" must contain an object`);
8540
+ if (verbose)
8541
+ log3.success(`Configuration loaded from package.json: ${usedName}`);
8542
+ return {
8543
+ config: deepMergeWithArrayStrategy3(envDefaultConfig, pkgConfig, arrayStrategy),
8544
+ source: {
8545
+ type: "package.json",
8546
+ path: pkgPath,
8547
+ priority: 30,
8548
+ timestamp: new Date
8502
8549
  }
8503
- const mergedConfig = deepMergeWithArrayStrategy3(envDefaultConfig, pkgConfig, arrayStrategy);
8504
- return {
8505
- config: mergedConfig,
8506
- source: {
8507
- type: "package.json",
8508
- path: pkgPath,
8509
- priority: 30,
8510
- timestamp: new Date
8511
- }
8512
- };
8513
- }
8550
+ };
8514
8551
  } catch (error) {
8515
- if (verbose) {
8552
+ if (isMissingConfigPath(error))
8553
+ return null;
8554
+ if (strict)
8555
+ throw ErrorFactory2.configLoad(pkgPath, error instanceof Error ? error : new Error(String(error)));
8556
+ if (verbose)
8516
8557
  log3.warn(`Failed to load package.json:`, [error instanceof Error ? error : new Error(String(error))]);
8517
- }
8558
+ return null;
8518
8559
  }
8519
- return null;
8520
8560
  }
8521
- async applyEnvironmentVariables(name, config5, checkEnv, verbose) {
8522
- if (!checkEnv || !name || typeof config5 !== "object" || config5 === null || Array.isArray(config5)) {
8561
+ async applyEnvironmentVariables(name, config, checkEnv, verbose) {
8562
+ if (!checkEnv || !name || typeof config !== "object" || config === null || Array.isArray(config)) {
8523
8563
  return {
8524
- config: config5,
8564
+ config,
8525
8565
  source: {
8526
8566
  type: "default",
8527
8567
  priority: 10,
@@ -8529,7 +8569,7 @@ class ConfigLoader2 {
8529
8569
  }
8530
8570
  };
8531
8571
  }
8532
- const processedConfig = applyEnvVarsToConfig3(name, config5, verbose);
8572
+ const processedConfig = applyEnvVarsToConfig3(name, config, verbose);
8533
8573
  return {
8534
8574
  config: processedConfig,
8535
8575
  source: {
@@ -8546,16 +8586,16 @@ class ConfigLoader2 {
8546
8586
  path: result.source.path
8547
8587
  };
8548
8588
  }
8549
- async validateConfiguration(config5, schema, customValidator, configName) {
8589
+ async validateConfiguration(config, schema, customValidator, configName) {
8550
8590
  const errors = [];
8551
8591
  if (customValidator) {
8552
- const customErrors = customValidator(config5);
8592
+ const customErrors = customValidator(config);
8553
8593
  if (customErrors) {
8554
8594
  errors.push(...customErrors);
8555
8595
  }
8556
8596
  }
8557
8597
  if (schema) {
8558
- const validationResult = await this.validator.validateConfiguration(config5, schema);
8598
+ const validationResult = await this.validator.validateConfiguration(config, schema);
8559
8599
  if (!validationResult.isValid) {
8560
8600
  errors.push(...validationResult.errors.map((e) => e.path ? `${e.path}: ${e.message}` : e.message));
8561
8601
  }
@@ -8627,7 +8667,7 @@ class ConfigLoader2 {
8627
8667
  }
8628
8668
  var globalConfigLoader2 = new ConfigLoader2;
8629
8669
  async function loadConfig6(options) {
8630
- const defaultConfig4 = "defaultConfig" in options && options.defaultConfig !== undefined ? options.defaultConfig : {};
8670
+ const defaultConfig = "defaultConfig" in options && options.defaultConfig !== undefined ? options.defaultConfig : {};
8631
8671
  const isEnhanced = "cache" in options || "performance" in options || "schema" in options || "validate" in options;
8632
8672
  try {
8633
8673
  let result;
@@ -8636,36 +8676,35 @@ async function loadConfig6(options) {
8636
8676
  } else {
8637
8677
  result = await globalConfigLoader2.loadConfig({
8638
8678
  ...options,
8639
- defaultConfig: defaultConfig4,
8679
+ defaultConfig,
8640
8680
  cache: { enabled: true },
8641
8681
  performance: { enabled: false }
8642
8682
  });
8643
8683
  }
8644
- return result?.config ?? defaultConfig4;
8684
+ return result?.config ?? defaultConfig;
8645
8685
  } catch (error) {
8646
- if (options.configFile)
8686
+ if (options.configFile || options.errorPolicy === "throw")
8647
8687
  throw error;
8648
- const errorName = error instanceof Error ? error.name : "UnknownError";
8649
8688
  const errorMessage = error instanceof Error ? error.message : String(error);
8650
- const isConfigError = errorName === "ConfigNotFoundError" || errorName === "ConfigLoadError" || errorName === "ConfigValidationError" || errorMessage.includes("config");
8689
+ const isConfigError = error instanceof ConfigNotFoundError2 || error instanceof ConfigLoadError2 || error instanceof ConfigValidationError2 || errorMessage.includes("config");
8651
8690
  if (!isConfigError && options.verbose) {
8652
8691
  log3.warn(`Unexpected error loading config, using defaults:`, [error instanceof Error ? error : new Error(String(error))]);
8653
8692
  }
8654
- const configOptions = isEnhanced ? { ...options, defaultConfig: defaultConfig4 } : {
8693
+ const configOptions = isEnhanced ? { ...options, defaultConfig } : {
8655
8694
  ...options,
8656
- defaultConfig: defaultConfig4,
8695
+ defaultConfig,
8657
8696
  cache: { enabled: true },
8658
8697
  performance: { enabled: false }
8659
8698
  };
8660
8699
  const shouldCheckEnv = "checkEnv" in options ? options.checkEnv !== false : true;
8661
8700
  if (shouldCheckEnv) {
8662
- const envResult = await globalConfigLoader2.applyEnvironmentVariables(configOptions.name || "", defaultConfig4, true, configOptions.verbose || false);
8663
- return envResult?.config ?? defaultConfig4;
8701
+ const envResult = await globalConfigLoader2.applyEnvironmentVariables(configOptions.name || "", defaultConfig, true, configOptions.verbose || false);
8702
+ return envResult?.config ?? defaultConfig;
8664
8703
  }
8665
- return defaultConfig4;
8704
+ return defaultConfig;
8666
8705
  }
8667
8706
  }
8668
- function applyEnvVarsToConfig3(name, config6, verbose = false) {
8707
+ function applyEnvVarsToConfig3(name, config, verbose = false) {
8669
8708
  const _envProcessor = new EnvProcessor2;
8670
8709
  const envPrefix = name.toUpperCase().replace(/[^A-Z0-9]/g, "_");
8671
8710
  function processConfigLevel(obj, path = []) {
@@ -8680,7 +8719,7 @@ function applyEnvVarsToConfig3(name, config6, verbose = false) {
8680
8719
  let envValue;
8681
8720
  let usedKey;
8682
8721
  for (const envKey of envKeys) {
8683
- envValue = process20.env[envKey];
8722
+ envValue = process19.env[envKey];
8684
8723
  if (envValue !== undefined) {
8685
8724
  usedKey = envKey;
8686
8725
  break;
@@ -8710,10 +8749,10 @@ function applyEnvVarsToConfig3(name, config6, verbose = false) {
8710
8749
  }
8711
8750
  return result;
8712
8751
  }
8713
- return processConfigLevel(config6);
8752
+ return processConfigLevel(config);
8714
8753
  }
8715
- var defaultConfigDir4 = /* @__PURE__ */ resolve12(process20.cwd(), "config");
8716
- var defaultGeneratedDir4 = /* @__PURE__ */ resolve12(process20.cwd(), "src/generated");
8754
+ var defaultConfigDir4 = /* @__PURE__ */ resolve12(process19.cwd(), "config");
8755
+ var defaultGeneratedDir4 = /* @__PURE__ */ resolve12(process19.cwd(), "src/generated");
8717
8756
 
8718
8757
  // src/serve.ts
8719
8758
  import { BUILD_ID_HEADER, decodeTitleEntities, externalScriptsOutsideContainer, extractPageResponseStatus, findContainerRegion, FRAGMENT_CACHE_CONTROL, getBuildId, mergeCssConfig, readResponseHeaders, readResponseStatus, renderFontCSS, SPA_NAV_HEADER, spaNavVaryHeaders, stateDir, stateDirName } from "@stacksjs/stx";
@@ -9061,13 +9100,13 @@ function publicFileExists(requestPath, publicDir) {
9061
9100
  }
9062
9101
  if (decoded.includes("\x00"))
9063
9102
  return false;
9064
- const publicRoot = nodePath.resolve(process19.cwd(), publicDir);
9103
+ const publicRoot = nodePath.resolve(process20.cwd(), publicDir);
9065
9104
  const resolved = nodePath.resolve(publicRoot, `.${decoded}`);
9066
9105
  const inside = resolved === publicRoot || resolved.startsWith(`${publicRoot}${nodePath.sep}`);
9067
9106
  if (!inside)
9068
9107
  return false;
9069
9108
  try {
9070
- return existsSync2(resolved) && !statSync3(resolved).isDirectory();
9109
+ return existsSync2(resolved) && !statSync4(resolved).isDirectory();
9071
9110
  } catch {
9072
9111
  return false;
9073
9112
  }
@@ -9076,8 +9115,8 @@ function escapeHtml(input) {
9076
9115
  return input.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
9077
9116
  }
9078
9117
  function isProductionServe() {
9079
- const node = (process19.env.NODE_ENV || "").toLowerCase();
9080
- const app = (process19.env.APP_ENV || "").toLowerCase();
9118
+ const node = (process20.env.NODE_ENV || "").toLowerCase();
9119
+ const app = (process20.env.APP_ENV || "").toLowerCase();
9081
9120
  const devEnvs = new Set(["development", "dev", "local", "test", "testing"]);
9082
9121
  return !(devEnvs.has(node) || devEnvs.has(app));
9083
9122
  }
@@ -9215,11 +9254,11 @@ function boundedCache(limit) {
9215
9254
  }
9216
9255
  };
9217
9256
  }
9218
- function pageExcluder(exclude, cwd = process19.cwd()) {
9257
+ function pageExcluder(exclude, cwd = process20.cwd()) {
9219
9258
  const canonical = (entry) => {
9220
9259
  const resolved = nodePath.resolve(cwd, entry);
9221
9260
  try {
9222
- return realpathSync(resolved);
9261
+ return realpathSync2(resolved);
9223
9262
  } catch {
9224
9263
  return resolved;
9225
9264
  }
@@ -9372,7 +9411,7 @@ async function serve(options) {
9372
9411
  const stxConfig = await loadConfig6({
9373
9412
  name: "stx",
9374
9413
  alias: ["ui"],
9375
- cwd: process19.cwd(),
9414
+ cwd: process20.cwd(),
9376
9415
  defaultConfig: defaultStxConfig,
9377
9416
  checkEnv: false,
9378
9417
  verbose: false
@@ -9381,7 +9420,7 @@ async function serve(options) {
9381
9420
  try {
9382
9421
  const stxMod = options.stxModule ? options.stxModule : await defaultStxModule;
9383
9422
  if (stxMod && typeof stxMod.resolveStxDirectories === "function")
9384
- stxMod.resolveStxDirectories(stxConfig, process19.cwd());
9423
+ stxMod.resolveStxDirectories(stxConfig, process20.cwd());
9385
9424
  } catch {}
9386
9425
  try {
9387
9426
  const stxMod = options.stxModule ? options.stxModule : await defaultStxModule;
@@ -9429,9 +9468,9 @@ async function serve(options) {
9429
9468
  });
9430
9469
  }
9431
9470
  const stxModule = options.stxModule ? Promise.resolve(options.stxModule) : defaultStxModule;
9432
- const imageCacheDir = process19.env.STX_IMAGE_CACHE_DIR?.trim();
9433
- const imageDeliveryOutputDir = imageCacheDir ? nodePath.resolve(imageCacheDir, "image-delivery") : stateDir(process19.cwd(), "image-delivery");
9434
- const imagePlaceholderCachePath = imageCacheDir ? nodePath.resolve(imageCacheDir, "image-placeholders.json") : stateDir(process19.cwd(), "image-placeholders.json");
9471
+ const imageCacheDir = process20.env.STX_IMAGE_CACHE_DIR?.trim();
9472
+ const imageDeliveryOutputDir = imageCacheDir ? nodePath.resolve(imageCacheDir, "image-delivery") : stateDir(process20.cwd(), "image-delivery");
9473
+ const imagePlaceholderCachePath = imageCacheDir ? nodePath.resolve(imageCacheDir, "image-placeholders.json") : stateDir(process20.cwd(), "image-placeholders.json");
9435
9474
  const imageDeliveryRoot = nodePath.join(imageDeliveryOutputDir, "_stx", "images");
9436
9475
  let resolvedStxModule = null;
9437
9476
  Promise.resolve(stxModule).then((m) => {
@@ -9604,7 +9643,7 @@ function __stxOverlay(errs){
9604
9643
  const writeLayoutTypes = async () => {
9605
9644
  try {
9606
9645
  const stxMod = options.stxModule ? options.stxModule : await defaultStxModule;
9607
- stxMod?.generateLayoutTypes?.(layoutsDir, stxMod?.stateDir?.(process19.cwd()));
9646
+ stxMod?.generateLayoutTypes?.(layoutsDir, stxMod?.stateDir?.(process20.cwd()));
9608
9647
  } catch {}
9609
9648
  };
9610
9649
  await writeLayoutTypes();
@@ -9935,7 +9974,7 @@ function __stxOverlay(errs){
9935
9974
  try {
9936
9975
  const { Router } = await import("./chunk-zv29b5s3.js");
9937
9976
  const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
9938
- const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName(), exclude: options.exclude });
9977
+ const router = new Router(process20.cwd(), { pagesDirs, stateDir: stateDirName(), exclude: options.exclude });
9939
9978
  if (!options.quiet)
9940
9979
  console.log(`[stx] Generated ${router.routes.length} routes \u2192 ${nodePath.join(stateDirName(), "routes.ts")}`);
9941
9980
  } catch (e) {}
@@ -9946,7 +9985,7 @@ function __stxOverlay(errs){
9946
9985
  return;
9947
9986
  assetsInitialized = true;
9948
9987
  const assetsDir = "./resources/assets";
9949
- const targetAssetsDir = stateDir(process19.cwd(), "assets");
9988
+ const targetAssetsDir = stateDir(process20.cwd(), "assets");
9950
9989
  try {
9951
9990
  const assetsExist = await nodeFs.stat(assetsDir).then(() => true).catch(() => false);
9952
9991
  if (assetsExist) {
@@ -9981,7 +10020,7 @@ function __stxOverlay(errs){
9981
10020
  if (cssLoadAttempted)
9982
10021
  return cssModule;
9983
10022
  cssLoadAttempted = true;
9984
- let dir = process19.cwd();
10023
+ let dir = process20.cwd();
9985
10024
  while (dir !== nodePath.dirname(dir)) {
9986
10025
  for (const store of ["node_modules", "pantry"]) {
9987
10026
  for (const entry of ENGINE_PACKAGE_ENTRIES) {
@@ -10009,7 +10048,7 @@ function __stxOverlay(errs){
10009
10048
  } catch {}
10010
10049
  }
10011
10050
  try {
10012
- const localPath = nodePath.join(process19.env.HOME || "", "Code/Tools/crosswind/packages/toolkit/src/engine/index.ts");
10051
+ const localPath = nodePath.join(process20.env.HOME || "", "Code/Tools/crosswind/packages/toolkit/src/engine/index.ts");
10013
10052
  const mod = await import(localPath);
10014
10053
  cssModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
10015
10054
  return cssModule;
@@ -10052,7 +10091,7 @@ function __stxOverlay(errs){
10052
10091
  if (!cssUserConfigPromise) {
10053
10092
  cssUserConfigPromise = loadConfig6({
10054
10093
  name: "css",
10055
- cwd: process19.cwd(),
10094
+ cwd: process20.cwd(),
10056
10095
  defaultConfig: {},
10057
10096
  checkEnv: false,
10058
10097
  verbose: false
@@ -10173,7 +10212,7 @@ function __stxOverlay(errs){
10173
10212
  context.__stx_head_preset = true;
10174
10213
  const config = {
10175
10214
  ...defaultConfig,
10176
- root: process19.cwd(),
10215
+ root: process20.cwd(),
10177
10216
  ...componentsDir && { componentsDir },
10178
10217
  ...layoutsDir && { layoutsDir },
10179
10218
  ...fallbackLayoutsDir && { fallbackLayoutsDir },
@@ -10387,7 +10426,7 @@ function __stxOverlay(errs){
10387
10426
  context.__stx_head_preset = true;
10388
10427
  const config = {
10389
10428
  ...defaultConfig,
10390
- root: process19.cwd(),
10429
+ root: process20.cwd(),
10391
10430
  ...componentsDir && { componentsDir },
10392
10431
  ...layoutsDir && { layoutsDir },
10393
10432
  ...fallbackLayoutsDir && { fallbackLayoutsDir },
@@ -10557,7 +10596,7 @@ ${block}`;
10557
10596
  console.warn(`\x1B[2m${error.stack}\x1B[0m`);
10558
10597
  }
10559
10598
  async function runImageWarmup() {
10560
- const imageWarmupEnabled = imageWarmupSetting === "auto" ? await projectUsesImageBuiltins(process19.cwd()) : imageWarmupSetting !== false;
10599
+ const imageWarmupEnabled = imageWarmupSetting === "auto" ? await projectUsesImageBuiltins(process20.cwd()) : imageWarmupSetting !== false;
10561
10600
  if (!imageWarmupEnabled) {
10562
10601
  placeholdersAreReady = true;
10563
10602
  markPlaceholdersReady();
@@ -10565,7 +10604,7 @@ ${block}`;
10565
10604
  }
10566
10605
  try {
10567
10606
  const stx = await stxModule;
10568
- const publicRoot = nodePath.resolve(process19.cwd(), publicDir);
10607
+ const publicRoot = nodePath.resolve(process20.cwd(), publicDir);
10569
10608
  const [placeholderResult, deliveryResult] = await Promise.allSettled([
10570
10609
  stx.warmImagePlaceholders(publicRoot, {
10571
10610
  cachePath: imagePlaceholderCachePath,
@@ -10938,7 +10977,7 @@ ${block}`;
10938
10977
  }
10939
10978
  const body = await req.json();
10940
10979
  const { Database } = await import("bun:sqlite");
10941
- const dbPath = nodePath.resolve(process19.cwd(), "database/stacks.sqlite");
10980
+ const dbPath = nodePath.resolve(process20.cwd(), "database/stacks.sqlite");
10942
10981
  const db = new Database(dbPath);
10943
10982
  try {
10944
10983
  const tableInfo = db.query(`PRAGMA table_info("${tableName}")`).all();
@@ -11206,7 +11245,7 @@ ${trailingPageScripts.join(`
11206
11245
  }
11207
11246
  if (path.startsWith("/chunk-") || path.endsWith(".js") || path.endsWith(".css")) {
11208
11247
  try {
11209
- const buildFile = Bun.file(stateDir(process19.cwd(), path));
11248
+ const buildFile = Bun.file(stateDir(process20.cwd(), path));
11210
11249
  if (await buildFile.exists()) {
11211
11250
  const ext = path.split(".").pop()?.toLowerCase();
11212
11251
  const contentType = ext === "css" ? "text/css" : ext === "js" ? "application/javascript" : "text/plain";
@@ -11231,7 +11270,7 @@ ${trailingPageScripts.join(`
11231
11270
  return new Response("Invalid asset path", { status: 400 });
11232
11271
  for (const assetPath of assetRequestPaths(assetPathname)) {
11233
11272
  try {
11234
- const filePath = nodePath.resolve(process19.cwd(), `.${assetPath}`);
11273
+ const filePath = nodePath.resolve(process20.cwd(), `.${assetPath}`);
11235
11274
  const file = Bun.file(filePath);
11236
11275
  if (await file.exists()) {
11237
11276
  const ext = getAssetExtension(assetPath);
@@ -11250,7 +11289,7 @@ ${trailingPageScripts.join(`
11250
11289
  }
11251
11290
  }
11252
11291
  if ((req.method === "GET" || req.method === "HEAD") && path !== "/") {
11253
- const publicRoot = nodePath.resolve(process19.cwd(), publicDir);
11292
+ const publicRoot = nodePath.resolve(process20.cwd(), publicDir);
11254
11293
  let safePathname;
11255
11294
  try {
11256
11295
  safePathname = decodeURIComponent(path);
@@ -11399,10 +11438,10 @@ ${trailingPageScripts.join(`
11399
11438
  })().catch(() => {});
11400
11439
  }
11401
11440
  if (options.reusePort) {
11402
- const graceMs = Number(process19.env.SHUTDOWN_GRACE_MS) || 15000;
11403
- process19.once("SIGTERM", () => {
11404
- setTimeout(() => process19.exit(0), graceMs).unref();
11405
- Promise.resolve(_server?.stop()).then(() => process19.exit(0));
11441
+ const graceMs = Number(process20.env.SHUTDOWN_GRACE_MS) || 15000;
11442
+ process20.once("SIGTERM", () => {
11443
+ setTimeout(() => process20.exit(0), graceMs).unref();
11444
+ Promise.resolve(_server?.stop()).then(() => process20.exit(0));
11406
11445
  });
11407
11446
  }
11408
11447
  if (!options.quiet) {
@@ -11421,17 +11460,17 @@ ${trailingPageScripts.join(`
11421
11460
  console.log(` \x1B[2mPress\x1B[0m o + Enter \x1B[2mto open in browser\x1B[0m`);
11422
11461
  console.log(` \x1B[2mPress\x1B[0m q + Enter \x1B[2mto quit\x1B[0m`);
11423
11462
  console.log();
11424
- if (process19.stdin.isTTY) {
11425
- process19.stdin.setRawMode(false);
11463
+ if (process20.stdin.isTTY) {
11464
+ process20.stdin.setRawMode(false);
11426
11465
  const rl = await import("readline");
11427
- const reader = rl.createInterface({ input: process19.stdin });
11466
+ const reader = rl.createInterface({ input: process20.stdin });
11428
11467
  reader.on("line", (line) => {
11429
11468
  const cmd = line.trim().toLowerCase();
11430
11469
  if (cmd === "o") {
11431
- const openCmd = process19.platform === "darwin" ? "open" : process19.platform === "win32" ? "start" : "xdg-open";
11470
+ const openCmd = process20.platform === "darwin" ? "open" : process20.platform === "win32" ? "start" : "xdg-open";
11432
11471
  Bun.spawn([openCmd, openUrl]);
11433
11472
  } else if (cmd === "q") {
11434
- process19.exit(0);
11473
+ process20.exit(0);
11435
11474
  }
11436
11475
  });
11437
11476
  }
@@ -11439,7 +11478,7 @@ ${trailingPageScripts.join(`
11439
11478
  await Bun.sleep(Number.POSITIVE_INFINITY);
11440
11479
  }
11441
11480
  async function main() {
11442
- const args = process19.argv.slice(2);
11481
+ const args = process20.argv.slice(2);
11443
11482
  if (args[0] === "serve") {
11444
11483
  args.shift();
11445
11484
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.571",
4
+ "version": "0.2.573",
5
5
  "description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -74,7 +74,7 @@
74
74
  "typecheck": "bun tsc --noEmit"
75
75
  },
76
76
  "dependencies": {
77
- "@stacksjs/stx": "0.2.571",
78
- "stx-router": "0.2.571"
77
+ "@stacksjs/stx": "0.2.573",
78
+ "stx-router": "0.2.573"
79
79
  }
80
80
  }