Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@backstage/config-loader

Package Overview
Dependencies
Maintainers
4
Versions
869
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@backstage/config-loader - npm Package Compare versions

Comparing version 0.6.6 to 0.6.7

9

CHANGELOG.md
# @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 @@

47

dist/index.cjs.js

@@ -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 @@

7

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc