@platformatic/foundation 3.65.0 → 3.66.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.
@@ -513,6 +513,7 @@ export async function loadConfiguration (source, schema, options = {}) {
513
513
 
514
514
  if (shouldReplaceEnv) {
515
515
  const missingEnv = new Set()
516
+ const fallbackEnv = new Set()
516
517
 
517
518
  config = replaceEnv(
518
519
  config,
@@ -522,6 +523,11 @@ export async function loadConfiguration (source, schema, options = {}) {
522
523
 
523
524
  if (typeof value === 'undefined' || value === null) {
524
525
  missingEnv.add(key)
526
+ } else {
527
+ // The variable is not set: it only has a value because onMissingEnv provided a fallback.
528
+ // Track it separately so that strictEnv can still report it, as a fallback can silently
529
+ // mask a misconfiguration.
530
+ fallbackEnv.add(key)
525
531
  }
526
532
 
527
533
  return value
@@ -533,17 +539,31 @@ export async function loadConfiguration (source, schema, options = {}) {
533
539
  // (runtime configurations) or in the runtime property (capabilities configurations).
534
540
  const strictEnv = normalizeStrictEnv(strictEnvOption ?? config.strictEnv ?? config.runtime?.strictEnv)
535
541
 
542
+ function warn (message) {
543
+ if (logger) {
544
+ logger.warn(message)
545
+ } else {
546
+ process.emitWarning(message)
547
+ }
548
+ }
549
+
550
+ // Variables resolved by a fallback are always reported as a warning, never as an error: they did
551
+ // resolve to a value, so failing on them would change which configurations are able to boot.
552
+ // This is emitted before handling the missing ones so that a throw does not swallow it.
553
+ if (strictEnv && fallbackEnv.size > 0) {
554
+ const keys = Array.from(fallbackEnv).sort().join(', ')
555
+
556
+ warn(
557
+ 'The configuration references the following environment variables which are not set ' +
558
+ `and have been replaced by a fallback value: ${keys}`
559
+ )
560
+ }
561
+
536
562
  if (strictEnv && missingEnv.size > 0) {
537
563
  const keys = Array.from(missingEnv).sort().join(', ')
538
564
 
539
565
  if (strictEnv === 'warn') {
540
- const message = `The configuration references the following environment variables which are not set: ${keys}`
541
-
542
- if (logger) {
543
- logger.warn(message)
544
- } else {
545
- process.emitWarning(message)
546
- }
566
+ warn(`The configuration references the following environment variables which are not set: ${keys}`)
547
567
  } else {
548
568
  throw new MissingEnvVariablesError(keys)
549
569
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/foundation",
3
- "version": "3.65.0",
3
+ "version": "3.66.0",
4
4
  "description": "Platformatic Foundation",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -50,6 +50,7 @@
50
50
  "scripts": {
51
51
  "test": "npm run test:types && node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/**/*.test.js",
52
52
  "test:types": "tstyche",
53
- "lint": "eslint"
53
+ "lint": "eslint",
54
+ "lint:fix": "eslint --fix"
54
55
  }
55
56
  }