@backstage/config-loader
Advanced tools
Comparing version 0.6.8 to 0.6.9
# @backstage/config-loader | ||
## 0.6.9 | ||
### Patch Changes | ||
- ee7a1a4b64: Add option to collect configuration schemas from explicit package paths in addition to by package name. | ||
- e68bd978e2: Allow collection of configuration schemas from multiple versions of the same package. | ||
## 0.6.8 | ||
@@ -4,0 +11,0 @@ |
@@ -312,22 +312,37 @@ 'use strict'; | ||
const req = typeof __non_webpack_require__ === "undefined" ? require : __non_webpack_require__; | ||
async function collectConfigSchemas(packageNames) { | ||
const visitedPackages = new Set(); | ||
const schemas = Array(); | ||
const tsSchemaPaths = Array(); | ||
async function collectConfigSchemas(packageNames, packagePaths) { | ||
const schemas = new Array(); | ||
const tsSchemaPaths = new Array(); | ||
const visitedPackageVersions = new Map(); | ||
const currentDir = await fs__default['default'].realpath(process.cwd()); | ||
async function processItem({name, parentPath}) { | ||
async function processItem(item) { | ||
var _a, _b, _c, _d; | ||
if (visitedPackages.has(name)) { | ||
let pkgPath = item.packagePath; | ||
if (pkgPath) { | ||
const pkgExists = await fs__default['default'].pathExists(pkgPath); | ||
if (!pkgExists) { | ||
return; | ||
} | ||
} else if (item.name) { | ||
const {name, parentPath} = item; | ||
try { | ||
pkgPath = req.resolve(`${name}/package.json`, parentPath && { | ||
paths: [parentPath] | ||
}); | ||
} catch { | ||
} | ||
} | ||
if (!pkgPath) { | ||
return; | ||
} | ||
visitedPackages.add(name); | ||
let pkgPath; | ||
try { | ||
pkgPath = req.resolve(`${name}/package.json`, parentPath && { | ||
paths: [parentPath] | ||
}); | ||
} catch { | ||
const pkg = await fs__default['default'].readJson(pkgPath); | ||
let versions = visitedPackageVersions.get(pkg.name); | ||
if (versions == null ? void 0 : versions.has(pkg.version)) { | ||
return; | ||
} | ||
const pkg = await fs__default['default'].readJson(pkgPath); | ||
if (!versions) { | ||
versions = new Set(); | ||
visitedPackageVersions.set(pkg.name, versions); | ||
} | ||
versions.add(pkg.version); | ||
const depNames = [ | ||
@@ -370,3 +385,6 @@ ...Object.keys((_a = pkg.dependencies) != null ? _a : {}), | ||
} | ||
await Promise.all(packageNames.map((name) => processItem({name, parentPath: currentDir}))); | ||
await Promise.all([ | ||
...packageNames.map((name) => processItem({name, parentPath: currentDir})), | ||
...packagePaths.map((path) => processItem({name: path, packagePath: path})) | ||
]); | ||
const tsSchemas = compileTsSchemas(tsSchemaPaths); | ||
@@ -468,5 +486,6 @@ return schemas.concat(tsSchemas); | ||
async function loadConfigSchema(options) { | ||
var _a; | ||
let schemas; | ||
if ("dependencies" in options) { | ||
schemas = await collectConfigSchemas(options.dependencies); | ||
schemas = await collectConfigSchemas(options.dependencies, (_a = options.packagePaths) != null ? _a : []); | ||
} else { | ||
@@ -473,0 +492,0 @@ const {serialized} = options; |
@@ -91,2 +91,3 @@ import { AppConfig, JsonObject } from '@backstage/config'; | ||
dependencies: string[]; | ||
packagePaths?: string[]; | ||
} | { | ||
@@ -93,0 +94,0 @@ serialized: JsonObject; |
@@ -300,22 +300,37 @@ import yaml from 'yaml'; | ||
const req = typeof __non_webpack_require__ === "undefined" ? require : __non_webpack_require__; | ||
async function collectConfigSchemas(packageNames) { | ||
const visitedPackages = new Set(); | ||
const schemas = Array(); | ||
const tsSchemaPaths = Array(); | ||
async function collectConfigSchemas(packageNames, packagePaths) { | ||
const schemas = new Array(); | ||
const tsSchemaPaths = new Array(); | ||
const visitedPackageVersions = new Map(); | ||
const currentDir = await fs.realpath(process.cwd()); | ||
async function processItem({name, parentPath}) { | ||
async function processItem(item) { | ||
var _a, _b, _c, _d; | ||
if (visitedPackages.has(name)) { | ||
let pkgPath = item.packagePath; | ||
if (pkgPath) { | ||
const pkgExists = await fs.pathExists(pkgPath); | ||
if (!pkgExists) { | ||
return; | ||
} | ||
} else if (item.name) { | ||
const {name, parentPath} = item; | ||
try { | ||
pkgPath = req.resolve(`${name}/package.json`, parentPath && { | ||
paths: [parentPath] | ||
}); | ||
} catch { | ||
} | ||
} | ||
if (!pkgPath) { | ||
return; | ||
} | ||
visitedPackages.add(name); | ||
let pkgPath; | ||
try { | ||
pkgPath = req.resolve(`${name}/package.json`, parentPath && { | ||
paths: [parentPath] | ||
}); | ||
} catch { | ||
const pkg = await fs.readJson(pkgPath); | ||
let versions = visitedPackageVersions.get(pkg.name); | ||
if (versions == null ? void 0 : versions.has(pkg.version)) { | ||
return; | ||
} | ||
const pkg = await fs.readJson(pkgPath); | ||
if (!versions) { | ||
versions = new Set(); | ||
visitedPackageVersions.set(pkg.name, versions); | ||
} | ||
versions.add(pkg.version); | ||
const depNames = [ | ||
@@ -358,3 +373,6 @@ ...Object.keys((_a = pkg.dependencies) != null ? _a : {}), | ||
} | ||
await Promise.all(packageNames.map((name) => processItem({name, parentPath: currentDir}))); | ||
await Promise.all([ | ||
...packageNames.map((name) => processItem({name, parentPath: currentDir})), | ||
...packagePaths.map((path) => processItem({name: path, packagePath: path})) | ||
]); | ||
const tsSchemas = compileTsSchemas(tsSchemaPaths); | ||
@@ -456,5 +474,6 @@ return schemas.concat(tsSchemas); | ||
async function loadConfigSchema(options) { | ||
var _a; | ||
let schemas; | ||
if ("dependencies" in options) { | ||
schemas = await collectConfigSchemas(options.dependencies); | ||
schemas = await collectConfigSchemas(options.dependencies, (_a = options.packagePaths) != null ? _a : []); | ||
} else { | ||
@@ -461,0 +480,0 @@ const {serialized} = options; |
{ | ||
"name": "@backstage/config-loader", | ||
"description": "Config loading functionality used by Backstage backend, and CLI", | ||
"version": "0.6.8", | ||
"version": "0.6.9", | ||
"private": false, | ||
@@ -51,3 +51,3 @@ "publishConfig": { | ||
"@types/yup": "^0.29.8", | ||
"mock-fs": "^4.13.0" | ||
"mock-fs": "^5.1.0" | ||
}, | ||
@@ -57,4 +57,4 @@ "files": [ | ||
], | ||
"gitHead": "a1ef801ab9bc07d6c51eac247a6c67301299a36f", | ||
"gitHead": "ca2905d9c6d1dd12c6d0cc64ec87f459175193a3", | ||
"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
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
162516
1273