@platformatic/config
Advanced tools
Comparing version 1.50.0 to 2.0.0-alpha.1
@@ -55,2 +55,3 @@ 'use strict' | ||
this._originalEnv = opts.env || {} | ||
this.context = opts.context || {} | ||
this.env = { ...this._originalEnv } | ||
@@ -98,3 +99,12 @@ this._onMissingEnv = opts.onMissingEnv | ||
const value = config[key] | ||
config[key] = await this.replaceEnv(value, { env, escapeJSON: false }) | ||
config[key] = await this.replaceEnv( | ||
value, | ||
{ | ||
env, | ||
context: opts.context, | ||
escapeJSON: false, | ||
parent: config, | ||
tree: [...opts.tree ?? [], config] | ||
} | ||
) | ||
} | ||
@@ -106,3 +116,3 @@ return config | ||
if (!value && this._onMissingEnv) { | ||
value = this._onMissingEnv(key) | ||
value = this._onMissingEnv(key, opts) | ||
} | ||
@@ -138,3 +148,4 @@ | ||
escapeJSON: false, | ||
ignore: this._replaceEnvIgnore | ||
ignore: this._replaceEnvIgnore, | ||
context: this.context | ||
}) | ||
@@ -141,0 +152,0 @@ } |
@@ -15,2 +15,8 @@ 'use strict' | ||
const defaultTypes = [ | ||
'service', | ||
'db', | ||
'composer' | ||
] | ||
class Store { | ||
@@ -71,31 +77,26 @@ #map = new Map() | ||
// try to load module | ||
if (!app && extendedModule) { | ||
try { | ||
app = require(extendedModule) | ||
} catch (err) { | ||
if (err.code === 'ERR_REQUIRE_ESM') { | ||
const toLoad = require.resolve(extendedModule) | ||
app = (await import('file://' + toLoad)).default | ||
} else { | ||
throw err | ||
} | ||
const match = $schema?.match(/\/schemas\/(.*)\/(.*)/) | ||
let type = match?.[2] | ||
// Legacy Platformatic apps | ||
if (!app && !type && $schema?.indexOf('./') === 0 && !extendedModule) { | ||
if (core || db) { | ||
type = 'db' | ||
} else { | ||
type = 'service' | ||
} | ||
} | ||
const match = $schema?.match(/\/schemas\/(.*)\/(.*)/) | ||
if (!app && match) { | ||
const type = match[2] | ||
if (!app && type) { | ||
const toLoad = `https://platformatic.dev/schemas/v${pltVersion}/${type}` | ||
app = this.#map.get(toLoad) | ||
if (!app && defaultTypes.includes(type)) { | ||
app = await loadModule(require, `@platformatic/${type}`) | ||
this.add(app) | ||
} | ||
} | ||
// Legacy Platformatic apps | ||
if (!app && $schema?.indexOf('./') === 0) { | ||
if (core || db) { | ||
app = this.#map.get(`https://platformatic.dev/schemas/v${pltVersion}/db`) | ||
} else { | ||
app = this.#map.get(`https://platformatic.dev/schemas/v${pltVersion}/service`) | ||
} | ||
// try to load module | ||
if (!app && extendedModule) { | ||
app = await loadModule(require, extendedModule) | ||
} | ||
@@ -143,4 +144,7 @@ | ||
const typeSet = new Set() | ||
for (const _ of types) { | ||
const type = _.configType | ||
typeSet.add(type) | ||
_.filenames = [ | ||
@@ -156,2 +160,21 @@ `platformatic.${type}.json`, | ||
for (const type of defaultTypes) { | ||
if (typeSet.has(type)) { | ||
continue | ||
} | ||
const _ = { | ||
configType: type, | ||
filenames: [ | ||
`platformatic.${type}.json`, | ||
`platformatic.${type}.json5`, | ||
`platformatic.${type}.yaml`, | ||
`platformatic.${type}.yml`, | ||
`platformatic.${type}.toml`, | ||
`platformatic.${type}.tml` | ||
] | ||
} | ||
types.push(_) | ||
} | ||
types.push({ | ||
@@ -247,2 +270,15 @@ filenames: [ | ||
async function loadModule (require, extendedModule) { | ||
try { | ||
return require(extendedModule) | ||
} catch (err) { | ||
if (err.code === 'ERR_REQUIRE_ESM') { | ||
const toLoad = require.resolve(extendedModule) | ||
return (await import('file://' + toLoad)).default | ||
} else { | ||
throw err | ||
} | ||
} | ||
} | ||
module.exports.Store = Store |
{ | ||
"name": "@platformatic/config", | ||
"version": "1.50.0", | ||
"version": "2.0.0-alpha.1", | ||
"description": "Platformatic DB Config Manager", | ||
@@ -40,3 +40,3 @@ "main": "index.js", | ||
"undici": "^6.9.0", | ||
"@platformatic/utils": "1.50.0" | ||
"@platformatic/utils": "2.0.0-alpha.1" | ||
}, | ||
@@ -43,0 +43,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43024
871
1
+ Added@platformatic/utils@2.0.0-alpha.1(transitive)
- Removed@platformatic/utils@1.50.0(transitive)