@platformatic/foundation 3.19.0 → 3.20.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.
- package/lib/configuration.js +30 -20
- package/lib/schema.js +3 -2
- package/package.json +1 -1
package/lib/configuration.js
CHANGED
|
@@ -340,33 +340,42 @@ export function validate (schema, config, validationOptions = {}, fixPaths = tru
|
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
export async function loadEnv (root, ignoreProcessEnv = false, additionalEnv = {}) {
|
|
343
|
+
export async function loadEnv (root, ignoreProcessEnv = false, additionalEnv = {}, customEnvFile = null) {
|
|
344
344
|
if (!isAbsolute(root)) {
|
|
345
345
|
root = resolve(process.cwd(), root)
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
let
|
|
349
|
-
const rootPath = parse(root).root
|
|
348
|
+
let envFile = customEnvFile
|
|
350
349
|
|
|
351
|
-
//
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (await isFileAccessible(candidate)) {
|
|
357
|
-
envFile = candidate
|
|
358
|
-
break
|
|
350
|
+
// If a custom env file is provided, resolve it and check if it exists
|
|
351
|
+
if (customEnvFile) {
|
|
352
|
+
envFile = isAbsolute(customEnvFile) ? customEnvFile : resolve(root, customEnvFile)
|
|
353
|
+
if (!(await isFileAccessible(envFile))) {
|
|
354
|
+
throw new Error(`Custom env file not found: ${envFile}`)
|
|
359
355
|
}
|
|
356
|
+
} else {
|
|
357
|
+
// Default behavior: search for .env file in the current directory and its parents
|
|
358
|
+
let currentPath = root
|
|
359
|
+
const rootPath = parse(root).root
|
|
360
360
|
|
|
361
|
-
currentPath
|
|
362
|
-
|
|
361
|
+
while (currentPath !== rootPath) {
|
|
362
|
+
const candidate = resolve(currentPath, '.env')
|
|
363
363
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
364
|
+
if (await isFileAccessible(candidate)) {
|
|
365
|
+
envFile = candidate
|
|
366
|
+
break
|
|
367
|
+
}
|
|
367
368
|
|
|
368
|
-
|
|
369
|
-
|
|
369
|
+
currentPath = dirname(currentPath)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// If not found, check the current working directory
|
|
373
|
+
if (!envFile) {
|
|
374
|
+
const cwdCandidate = resolve(process.cwd(), '.env')
|
|
375
|
+
|
|
376
|
+
if (await isFileAccessible(cwdCandidate)) {
|
|
377
|
+
envFile = cwdCandidate
|
|
378
|
+
}
|
|
370
379
|
}
|
|
371
380
|
}
|
|
372
381
|
|
|
@@ -446,7 +455,8 @@ export async function loadConfiguration (source, schema, options = {}) {
|
|
|
446
455
|
onMissingEnv,
|
|
447
456
|
fixPaths,
|
|
448
457
|
logger,
|
|
449
|
-
skipMetadata
|
|
458
|
+
skipMetadata,
|
|
459
|
+
envFile: customEnvFile
|
|
450
460
|
} = {
|
|
451
461
|
validate: !!schema,
|
|
452
462
|
validationOptions: {},
|
|
@@ -473,7 +483,7 @@ export async function loadConfiguration (source, schema, options = {}) {
|
|
|
473
483
|
throw new RootMissingError()
|
|
474
484
|
}
|
|
475
485
|
|
|
476
|
-
const env = await loadEnv(root, ignoreProcessEnv, additionalEnv)
|
|
486
|
+
const env = await loadEnv(root, ignoreProcessEnv, additionalEnv, customEnvFile)
|
|
477
487
|
env.PLT_ROOT = root
|
|
478
488
|
|
|
479
489
|
if (shouldReplaceEnv) {
|
package/lib/schema.js
CHANGED
|
@@ -599,8 +599,9 @@ export const health = {
|
|
|
599
599
|
maxUnhealthyChecks: overridableValue({ type: 'number', minimum: 1 }, 10),
|
|
600
600
|
maxELU: overridableValue({ type: 'number', minimum: 0, maximum: 1 }, 0.99),
|
|
601
601
|
maxHeapUsed: overridableValue({ type: 'number', minimum: 0, maximum: 1 }, 0.99),
|
|
602
|
-
maxHeapTotal: overridableValue({ type: 'number', minimum: 0 }),
|
|
603
|
-
maxYoungGeneration: overridableValue({ type: 'number', minimum: 0 })
|
|
602
|
+
maxHeapTotal: overridableValue({ type: 'number', minimum: 0 }, 4 * Math.pow(1024, 3)), // 4GB
|
|
603
|
+
maxYoungGeneration: overridableValue({ type: 'number', minimum: 0 }, 128 * Math.pow(1024, 2)), // 128MB,
|
|
604
|
+
codeRangeSize: overridableValue({ type: 'number', minimum: 0 }, 268435456)
|
|
604
605
|
},
|
|
605
606
|
additionalProperties: false
|
|
606
607
|
}
|