@backstage/config-loader
Advanced tools
Comparing version 0.6.6 to 0.6.7
# @backstage/config-loader | ||
## 0.6.7 | ||
### Patch Changes | ||
- 0ade9d02b: Include `devDependencies` and `optionalDependencies` in the detection of Backstage packages when collecting configuration schema. | ||
- 9b8cec063: Add support for config file watching through a new group of `watch` options to `loadConfig`. | ||
- Updated dependencies | ||
- @backstage/config@0.1.7 | ||
## 0.6.6 | ||
@@ -4,0 +13,0 @@ |
@@ -12,2 +12,3 @@ 'use strict'; | ||
var typescriptJsonSchema = require('typescript-json-schema'); | ||
var chokidar = require('chokidar'); | ||
@@ -20,2 +21,3 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs); | ||
var chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar); | ||
@@ -318,3 +320,3 @@ const ENV_PREFIX = "APP_CONFIG_"; | ||
async function processItem({name, parentPath}) { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
if (visitedPackages.has(name)) { | ||
@@ -335,3 +337,5 @@ return; | ||
...Object.keys((_a = pkg.dependencies) != null ? _a : {}), | ||
...Object.keys((_b = pkg.peerDependencies) != null ? _b : {}) | ||
...Object.keys((_b = pkg.devDependencies) != null ? _b : {}), | ||
...Object.keys((_c = pkg.optionalDependencies) != null ? _c : {}), | ||
...Object.keys((_d = pkg.peerDependencies) != null ? _d : {}) | ||
]; | ||
@@ -509,4 +513,3 @@ const hasSchema = "configSchema" in pkg; | ||
async function loadConfig(options) { | ||
const configs = []; | ||
const {configRoot, experimentalEnvFunc: envFunc} = options; | ||
const {configRoot, experimentalEnvFunc: envFunc, watch} = options; | ||
const configPaths = options.configPaths.slice(); | ||
@@ -521,3 +524,4 @@ if (configPaths.length === 0) { | ||
const env = envFunc != null ? envFunc : async (name) => process.env[name]; | ||
try { | ||
const loadConfigFiles = async () => { | ||
const configs = []; | ||
for (const configPath of configPaths) { | ||
@@ -537,7 +541,36 @@ if (!path.isAbsolute(configPath)) { | ||
} | ||
return configs; | ||
}; | ||
let fileConfigs; | ||
try { | ||
fileConfigs = await loadConfigFiles(); | ||
} catch (error) { | ||
throw new Error(`Failed to read static configuration file, ${error.message}`); | ||
} | ||
configs.push(...readEnvConfig(process.env)); | ||
return configs; | ||
const envConfigs = await readEnvConfig(process.env); | ||
if (watch) { | ||
let currentSerializedConfig = JSON.stringify(fileConfigs); | ||
const watcher = chokidar__default['default'].watch(configPaths, { | ||
usePolling: process.env.NODE_ENV === "test" | ||
}); | ||
watcher.on("change", async () => { | ||
try { | ||
const newConfigs = await loadConfigFiles(); | ||
const newSerializedConfig = JSON.stringify(newConfigs); | ||
if (currentSerializedConfig === newSerializedConfig) { | ||
return; | ||
} | ||
currentSerializedConfig = newSerializedConfig; | ||
watch.onChange([...newConfigs, ...envConfigs]); | ||
} catch (error) { | ||
console.error(`Failed to reload configuration files, ${error}`); | ||
} | ||
}); | ||
if (watch.stopSignal) { | ||
watch.stopSignal.then(() => { | ||
watcher.close(); | ||
}); | ||
} | ||
} | ||
return [...fileConfigs, ...envConfigs]; | ||
} | ||
@@ -544,0 +577,0 @@ |
@@ -100,2 +100,15 @@ import { AppConfig, JsonObject } from '@backstage/config'; | ||
experimentalEnvFunc?: EnvFunc; | ||
/** | ||
* An optional configuration that enables watching of config files. | ||
*/ | ||
watch?: { | ||
/** | ||
* A listener that is called when a config file is changed. | ||
*/ | ||
onChange: (configs: AppConfig[]) => void; | ||
/** | ||
* An optional signal that stops the watcher once the promise resolves. | ||
*/ | ||
stopSignal?: Promise<void>; | ||
}; | ||
}; | ||
@@ -102,0 +115,0 @@ declare function loadConfig(options: LoadConfigOptions): Promise<AppConfig[]>; |
@@ -8,2 +8,3 @@ import yaml from 'yaml'; | ||
import { getProgramFromFiles, generateSchema } from 'typescript-json-schema'; | ||
import chokidar from 'chokidar'; | ||
@@ -306,3 +307,3 @@ const ENV_PREFIX = "APP_CONFIG_"; | ||
async function processItem({name, parentPath}) { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
if (visitedPackages.has(name)) { | ||
@@ -323,3 +324,5 @@ return; | ||
...Object.keys((_a = pkg.dependencies) != null ? _a : {}), | ||
...Object.keys((_b = pkg.peerDependencies) != null ? _b : {}) | ||
...Object.keys((_b = pkg.devDependencies) != null ? _b : {}), | ||
...Object.keys((_c = pkg.optionalDependencies) != null ? _c : {}), | ||
...Object.keys((_d = pkg.peerDependencies) != null ? _d : {}) | ||
]; | ||
@@ -497,4 +500,3 @@ const hasSchema = "configSchema" in pkg; | ||
async function loadConfig(options) { | ||
const configs = []; | ||
const {configRoot, experimentalEnvFunc: envFunc} = options; | ||
const {configRoot, experimentalEnvFunc: envFunc, watch} = options; | ||
const configPaths = options.configPaths.slice(); | ||
@@ -509,3 +511,4 @@ if (configPaths.length === 0) { | ||
const env = envFunc != null ? envFunc : async (name) => process.env[name]; | ||
try { | ||
const loadConfigFiles = async () => { | ||
const configs = []; | ||
for (const configPath of configPaths) { | ||
@@ -525,7 +528,36 @@ if (!isAbsolute(configPath)) { | ||
} | ||
return configs; | ||
}; | ||
let fileConfigs; | ||
try { | ||
fileConfigs = await loadConfigFiles(); | ||
} catch (error) { | ||
throw new Error(`Failed to read static configuration file, ${error.message}`); | ||
} | ||
configs.push(...readEnvConfig(process.env)); | ||
return configs; | ||
const envConfigs = await readEnvConfig(process.env); | ||
if (watch) { | ||
let currentSerializedConfig = JSON.stringify(fileConfigs); | ||
const watcher = chokidar.watch(configPaths, { | ||
usePolling: process.env.NODE_ENV === "test" | ||
}); | ||
watcher.on("change", async () => { | ||
try { | ||
const newConfigs = await loadConfigFiles(); | ||
const newSerializedConfig = JSON.stringify(newConfigs); | ||
if (currentSerializedConfig === newSerializedConfig) { | ||
return; | ||
} | ||
currentSerializedConfig = newSerializedConfig; | ||
watch.onChange([...newConfigs, ...envConfigs]); | ||
} catch (error) { | ||
console.error(`Failed to reload configuration files, ${error}`); | ||
} | ||
}); | ||
if (watch.stopSignal) { | ||
watch.stopSignal.then(() => { | ||
watcher.close(); | ||
}); | ||
} | ||
} | ||
return [...fileConfigs, ...envConfigs]; | ||
} | ||
@@ -532,0 +564,0 @@ |
{ | ||
"name": "@backstage/config-loader", | ||
"description": "Config loading functionality used by Backstage backend, and CLI", | ||
"version": "0.6.6", | ||
"version": "0.6.7", | ||
"private": false, | ||
@@ -34,5 +34,6 @@ "publishConfig": { | ||
"@backstage/cli-common": "^0.1.1", | ||
"@backstage/config": "^0.1.6", | ||
"@backstage/config": "^0.1.7", | ||
"@types/json-schema": "^7.0.6", | ||
"ajv": "^7.0.3", | ||
"chokidar": "^3.5.2", | ||
"fs-extra": "9.1.0", | ||
@@ -56,4 +57,4 @@ "json-schema": "^0.3.0", | ||
], | ||
"gitHead": "0cbbc971f3894862bf5a248603b5b997f8052da1", | ||
"gitHead": "2f291dfd04f87a6ff4d6000204d0af7067bcda10", | ||
"module": "dist/index.esm.js" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
158577
1216
11
10
5
+ Addedchokidar@^3.5.2
+ Addedanymatch@3.1.3(transitive)
+ Addedbinary-extensions@2.3.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedchokidar@3.6.0(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedis-binary-path@2.1.0(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedreaddirp@3.6.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
Updated@backstage/config@^0.1.7