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
861
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.1.1-alpha.6 to 0.1.1-alpha.7

50

dist/index.cjs.js

@@ -35,3 +35,45 @@ 'use strict';

async function loadConfig(options = {}) {
const ENV_PREFIX = "APP_CONFIG_";
const CONFIG_KEY_PART_PATTERN = /^[a-z][a-z0-9]*(?:[-_][a-z][a-z0-9]*)*$/i;
function readEnv(env) {
var _a;
let config2 = void 0;
for (const [name, value] of Object.entries(env)) {
if (!value) {
continue;
}
if (name.startsWith(ENV_PREFIX)) {
const key = name.replace(ENV_PREFIX, "");
const keyParts = key.split("_");
let obj = config2 = config2 != null ? config2 : {};
for (const [index, part] of keyParts.entries()) {
if (!CONFIG_KEY_PART_PATTERN.test(part)) {
throw new TypeError(`Invalid env config key '${key}'`);
}
if (index < keyParts.length - 1) {
obj = obj[part] = (_a = obj[part]) != null ? _a : {};
if (typeof obj !== "object" || Array.isArray(obj)) {
const subKey = keyParts.slice(0, index + 1).join("_");
throw new TypeError(`Could not nest config for key '${key}' under existing value '${subKey}'`);
}
} else {
if (part in obj) {
throw new TypeError(`Refusing to override existing config at key '${key}'`);
}
try {
const parsedValue = JSON.parse(value);
if (parsedValue === null) {
throw new Error("value may not be null");
}
obj[part] = parsedValue;
} catch (error) {
throw new TypeError(`Failed to parse JSON-serialized config value for key '${key}', ${error}`);
}
}
}
}
}
return config2 ? [config2] : [];
}
async function readStaticConfig(options) {
let {configPath} = options;

@@ -49,3 +91,9 @@ if (!configPath) {

}
async function loadConfig(options = {}) {
const configs = [];
configs.push(...readEnv(process.env));
configs.push(...await readStaticConfig(options));
return configs;
}
exports.loadConfig = loadConfig;

@@ -29,3 +29,45 @@ import fs from 'fs-extra';

async function loadConfig(options = {}) {
const ENV_PREFIX = "APP_CONFIG_";
const CONFIG_KEY_PART_PATTERN = /^[a-z][a-z0-9]*(?:[-_][a-z][a-z0-9]*)*$/i;
function readEnv(env) {
var _a;
let config2 = void 0;
for (const [name, value] of Object.entries(env)) {
if (!value) {
continue;
}
if (name.startsWith(ENV_PREFIX)) {
const key = name.replace(ENV_PREFIX, "");
const keyParts = key.split("_");
let obj = config2 = config2 != null ? config2 : {};
for (const [index, part] of keyParts.entries()) {
if (!CONFIG_KEY_PART_PATTERN.test(part)) {
throw new TypeError(`Invalid env config key '${key}'`);
}
if (index < keyParts.length - 1) {
obj = obj[part] = (_a = obj[part]) != null ? _a : {};
if (typeof obj !== "object" || Array.isArray(obj)) {
const subKey = keyParts.slice(0, index + 1).join("_");
throw new TypeError(`Could not nest config for key '${key}' under existing value '${subKey}'`);
}
} else {
if (part in obj) {
throw new TypeError(`Refusing to override existing config at key '${key}'`);
}
try {
const parsedValue = JSON.parse(value);
if (parsedValue === null) {
throw new Error("value may not be null");
}
obj[part] = parsedValue;
} catch (error) {
throw new TypeError(`Failed to parse JSON-serialized config value for key '${key}', ${error}`);
}
}
}
}
}
return config2 ? [config2] : [];
}
async function readStaticConfig(options) {
let {configPath} = options;

@@ -43,3 +85,9 @@ if (!configPath) {

}
async function loadConfig(options = {}) {
const configs = [];
configs.push(...readEnv(process.env));
configs.push(...await readStaticConfig(options));
return configs;
}
export { loadConfig };

14

package.json
{
"name": "@backstage/config-loader",
"description": "Config loading functionality used by Backstage backend, and CLI",
"version": "0.1.1-alpha.6",
"version": "0.1.1-alpha.7",
"private": false,
"publishConfig": {
"access": "public"
"access": "public",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts"
},

@@ -19,3 +22,3 @@ "homepage": "https://backstage.io",

"license": "Apache-2.0",
"main": "src/index.ts",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts",

@@ -31,3 +34,3 @@ "scripts": {

"dependencies": {
"@backstage/config": "^0.1.1-alpha.6",
"@backstage/config": "^0.1.1-alpha.7",
"fs-extra": "^9.0.0",

@@ -43,3 +46,4 @@ "yaml": "^1.9.2"

],
"gitHead": "f0ba4fb892511bc4d9d110a22ee63cfdf49f1c06"
"gitHead": "e61d09d545e4f4fa68cc204c9db0e0fd4eac84c3",
"module": "dist/index.esm.js"
}
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