@backstage/config-loader 1.10.8-next.0 → 1.10.9-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @backstage/config-loader
2
2
 
3
+ ## 1.10.9-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 70fc178: Migrated from deprecated `findPaths` to `targetPaths` and `findOwnPaths` from `@backstage/cli-common`.
8
+ - Updated dependencies
9
+ - @backstage/cli-common@0.2.0-next.0
10
+ - @backstage/config@1.3.6
11
+ - @backstage/errors@1.2.7
12
+ - @backstage/types@1.2.2
13
+
14
+ ## 1.10.8
15
+
16
+ ### Patch Changes
17
+
18
+ - 7455dae: Use node prefix on native imports
19
+ - Updated dependencies
20
+ - @backstage/cli-common@0.1.18
21
+
3
22
  ## 1.10.8-next.0
4
23
 
5
24
  ### Patch Changes
@@ -53,7 +53,7 @@ class ConfigSources {
53
53
  * @returns A config source for the provided targets
54
54
  */
55
55
  static defaultForTargets(options) {
56
- const rootDir = options.rootDir ?? cliCommon.findPaths(process.cwd()).targetRoot;
56
+ const rootDir = options.rootDir ?? cliCommon.targetPaths.rootDir;
57
57
  const argSources = options.targets.map((arg) => {
58
58
  if (arg.type === "url") {
59
59
  if (!options.remote) {
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigSources.cjs.js","sources":["../../src/sources/ConfigSources.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { resolve as resolvePath } from 'node:path';\nimport fs from 'fs-extra';\nimport { Config, ConfigReader } from '@backstage/config';\nimport parseArgs from 'minimist';\nimport { EnvConfigSource } from './EnvConfigSource';\nimport { FileConfigSource } from './FileConfigSource';\nimport { MergedConfigSource } from './MergedConfigSource';\nimport {\n RemoteConfigSource,\n RemoteConfigSourceOptions,\n} from './RemoteConfigSource';\nimport { ConfigSource, SubstitutionFunc } from './types';\nimport { ObservableConfigProxy } from './ObservableConfigProxy';\nimport { findPaths } from '@backstage/cli-common';\n\n/**\n * A target to read configuration from.\n *\n * @public\n */\nexport type ConfigSourceTarget =\n | {\n type: 'path';\n target: string;\n }\n | {\n type: 'url';\n target: string;\n };\n\n/**\n * A config implementation that can be closed.\n *\n * @remarks\n *\n * Closing the configuration instance will stop the reading from the underlying source.\n *\n * @public\n */\nexport interface ClosableConfig extends Config {\n /**\n * Closes the configuration instance.\n *\n * @remarks\n *\n * The configuration instance will still be usable after closing, but it will\n * no longer be updated with new values from the underlying source.\n */\n close(): void;\n}\n\n/**\n * Common options for the default Backstage configuration sources.\n *\n * @public\n */\nexport interface BaseConfigSourcesOptions {\n watch?: boolean;\n rootDir?: string;\n remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;\n /**\n * Allow the default app-config.yaml to be missing, in which case the source\n * will not be created.\n */\n allowMissingDefaultConfig?: boolean;\n\n /**\n * A custom substitution function that overrides the default one.\n *\n * @remarks\n * The substitution function handles syntax like `${MY_ENV_VAR}` in configuration values.\n * The default substitution will read the value from the environment and trim whitespace.\n */\n substitutionFunc?: SubstitutionFunc;\n}\n\n/**\n * Options for {@link ConfigSources.defaultForTargets}.\n *\n * @public\n */\nexport interface ConfigSourcesDefaultForTargetsOptions\n extends BaseConfigSourcesOptions {\n targets: ConfigSourceTarget[];\n}\n\n/**\n * Options for {@link ConfigSources.default}.\n *\n * @public\n */\nexport interface ConfigSourcesDefaultOptions extends BaseConfigSourcesOptions {\n argv?: string[];\n env?: Record<string, string | undefined>;\n}\n\n/**\n * A collection of utilities for working with and creating {@link ConfigSource}s.\n *\n * @public\n */\nexport class ConfigSources {\n /**\n * Parses command line arguments and returns the config targets.\n *\n * @param argv - The command line arguments to parse. Defaults to `process.argv`\n * @returns A list of config targets\n */\n static parseArgs(argv: string[] = process.argv): ConfigSourceTarget[] {\n const args: string[] = [parseArgs(argv).config].flat().filter(Boolean);\n return args.map(target => {\n try {\n const url = new URL(target);\n\n // Some file paths are valid relative URLs, so check if the host is empty too\n if (!url.host) {\n return { type: 'path', target };\n }\n return { type: 'url', target };\n } catch {\n return { type: 'path', target };\n }\n });\n }\n\n /**\n * Creates the default config sources for the provided targets.\n *\n * @remarks\n *\n * This will create {@link FileConfigSource}s and {@link RemoteConfigSource}s\n * for the provided targets, and merge them together to a single source.\n * If no targets are provided it will fall back to `app-config.yaml` and\n * `app-config.local.yaml`.\n *\n * URL targets are only supported if the `remote` option is provided.\n *\n * @param options - Options\n * @returns A config source for the provided targets\n */\n static defaultForTargets(\n options: ConfigSourcesDefaultForTargetsOptions,\n ): ConfigSource {\n const rootDir = options.rootDir ?? findPaths(process.cwd()).targetRoot;\n\n const argSources = options.targets.map(arg => {\n if (arg.type === 'url') {\n if (!options.remote) {\n throw new Error(\n `Config argument \"${arg.target}\" looks like a URL but remote configuration is not enabled. Enable it by passing the \\`remote\\` option`,\n );\n }\n return RemoteConfigSource.create({\n url: arg.target,\n substitutionFunc: options.substitutionFunc,\n reloadInterval: options.remote.reloadInterval,\n });\n }\n return FileConfigSource.create({\n watch: options.watch,\n path: resolvePath(arg.target),\n substitutionFunc: options.substitutionFunc,\n });\n });\n\n if (argSources.length === 0) {\n const defaultPath = resolvePath(rootDir, 'app-config.yaml');\n const localPath = resolvePath(rootDir, 'app-config.local.yaml');\n const envPath = resolvePath(\n rootDir,\n `app-config.${process.env.BACKSTAGE_ENV}.yaml`,\n );\n const envLocalPath = resolvePath(\n rootDir,\n `app-config.${process.env.BACKSTAGE_ENV}.local.yaml`,\n );\n const alwaysIncludeDefaultConfigSource =\n !options.allowMissingDefaultConfig;\n\n if (alwaysIncludeDefaultConfigSource || fs.pathExistsSync(defaultPath)) {\n argSources.push(\n FileConfigSource.create({\n watch: options.watch,\n path: defaultPath,\n substitutionFunc: options.substitutionFunc,\n }),\n );\n }\n\n if (process.env.BACKSTAGE_ENV && fs.pathExistsSync(envPath)) {\n argSources.push(\n FileConfigSource.create({\n watch: options.watch,\n path: envPath,\n substitutionFunc: options.substitutionFunc,\n }),\n );\n }\n\n if (fs.pathExistsSync(localPath)) {\n argSources.push(\n FileConfigSource.create({\n watch: options.watch,\n path: localPath,\n substitutionFunc: options.substitutionFunc,\n }),\n );\n }\n\n if (process.env.BACKSTAGE_ENV && fs.pathExistsSync(envLocalPath)) {\n argSources.push(\n FileConfigSource.create({\n watch: options.watch,\n path: envLocalPath,\n substitutionFunc: options.substitutionFunc,\n }),\n );\n }\n }\n\n return this.merge(argSources);\n }\n\n /**\n * Creates the default config source for Backstage.\n *\n * @remarks\n *\n * This will read from `app-config.yaml` and `app-config.local.yaml` by\n * default, as well as environment variables prefixed with `APP_CONFIG_`.\n * If `--config <path|url>` command line arguments are passed, these will\n * override the default configuration file paths. URLs are only supported\n * if the `remote` option is provided.\n *\n * @param options - Options\n * @returns The default Backstage config source\n */\n static default(options: ConfigSourcesDefaultOptions): ConfigSource {\n const argSource = this.defaultForTargets({\n ...options,\n targets: this.parseArgs(options.argv),\n });\n\n const envSource = EnvConfigSource.create({\n env: options.env,\n });\n\n return this.merge([argSource, envSource]);\n }\n\n /**\n * Merges multiple config sources into a single source that reads from all\n * sources and concatenates the result.\n *\n * @param sources - The config sources to merge\n * @returns A single config source that concatenates the data from the given sources\n */\n static merge(sources: ConfigSource[]): ConfigSource {\n return MergedConfigSource.from(sources);\n }\n\n /**\n * Creates an observable {@link @backstage/config#Config} implementation from a {@link ConfigSource}.\n *\n * @remarks\n *\n * If you only want to read the config once you can close the returned config immediately.\n *\n * @example\n *\n * ```ts\n * const sources = ConfigSources.default(...)\n * const config = await ConfigSources.toConfig(source)\n * config.close()\n * const example = config.getString(...)\n * ```\n *\n * @param source - The config source to read from\n * @returns A promise that resolves to a closable config\n */\n static toConfig(source: ConfigSource): Promise<ClosableConfig> {\n return new Promise(async (resolve, reject) => {\n let config: ObservableConfigProxy | undefined = undefined;\n try {\n const abortController = new AbortController();\n for await (const { configs } of source.readConfigData({\n signal: abortController.signal,\n })) {\n if (config) {\n config.setConfig(ConfigReader.fromConfigs(configs));\n } else {\n config = ObservableConfigProxy.create(abortController);\n config!.setConfig(ConfigReader.fromConfigs(configs));\n resolve(config);\n }\n }\n } catch (error) {\n reject(error);\n }\n });\n }\n}\n"],"names":["parseArgs","findPaths","RemoteConfigSource","FileConfigSource","resolvePath","fs","EnvConfigSource","MergedConfigSource","config","ConfigReader","ObservableConfigProxy"],"mappings":";;;;;;;;;;;;;;;;;;AAqHO,MAAM,aAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzB,OAAO,SAAA,CAAU,IAAA,GAAiB,OAAA,CAAQ,IAAA,EAA4B;AACpE,IAAA,MAAM,IAAA,GAAiB,CAACA,0BAAA,CAAU,IAAI,CAAA,CAAE,MAAM,CAAA,CAAE,IAAA,EAAK,CAAE,MAAA,CAAO,OAAO,CAAA;AACrE,IAAA,OAAO,IAAA,CAAK,IAAI,CAAA,MAAA,KAAU;AACxB,MAAA,IAAI;AACF,QAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,MAAM,CAAA;AAG1B,QAAA,IAAI,CAAC,IAAI,IAAA,EAAM;AACb,UAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAA,EAAO;AAAA,QAChC;AACA,QAAA,OAAO,EAAE,IAAA,EAAM,KAAA,EAAO,MAAA,EAAO;AAAA,MAC/B,CAAA,CAAA,MAAQ;AACN,QAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAA,EAAO;AAAA,MAChC;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;A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F,UAAA,IAAIA,QAAA,EAAQ;AACV,YAAAA,QAAA,CAAO,SAAA,CAAUC,mBAAA,CAAa,WAAA,CAAY,OAAO,CAAC,CAAA;AAAA,UACpD,CAAA,MAAO;AACL,YAAAD,QAAA,GAASE,2CAAA,CAAsB,OAAO,eAAe,CAAA;AACrD,YAAAF,QAAA,CAAQ,SAAA,CAAUC,mBAAA,CAAa,WAAA,CAAY,OAAO,CAAC,CAAA;AACnD,YAAA,OAAA,CAAQD,QAAM,CAAA;AAAA,UAChB;AAAA,QACF;AAAA,MACF,SAAS,KAAA,EAAO;AACd,QAAA,MAAA,CAAO,KAAK,CAAA;AAAA,MACd;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AACF;;;;"}
1
+ {"version":3,"file":"ConfigSources.cjs.js","sources":["../../src/sources/ConfigSources.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { resolve as resolvePath } from 'node:path';\nimport fs from 'fs-extra';\nimport { Config, ConfigReader } from '@backstage/config';\nimport parseArgs from 'minimist';\nimport { EnvConfigSource } from './EnvConfigSource';\nimport { FileConfigSource } from './FileConfigSource';\nimport { MergedConfigSource } from './MergedConfigSource';\nimport {\n RemoteConfigSource,\n RemoteConfigSourceOptions,\n} from './RemoteConfigSource';\nimport { ConfigSource, SubstitutionFunc } from './types';\nimport { ObservableConfigProxy } from './ObservableConfigProxy';\nimport { targetPaths } from '@backstage/cli-common';\n\n/**\n * A target to read configuration from.\n *\n * @public\n */\nexport type ConfigSourceTarget =\n | {\n type: 'path';\n target: string;\n }\n | {\n type: 'url';\n target: string;\n };\n\n/**\n * A config implementation that can be closed.\n *\n * @remarks\n *\n * Closing the configuration instance will stop the reading from the underlying source.\n *\n * @public\n */\nexport interface ClosableConfig extends Config {\n /**\n * Closes the configuration instance.\n *\n * @remarks\n *\n * The configuration instance will still be usable after closing, but it will\n * no longer be updated with new values from the underlying source.\n */\n close(): void;\n}\n\n/**\n * Common options for the default Backstage configuration sources.\n *\n * @public\n */\nexport interface BaseConfigSourcesOptions {\n watch?: boolean;\n rootDir?: string;\n remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;\n /**\n * Allow the default app-config.yaml to be missing, in which case the source\n * will not be created.\n */\n allowMissingDefaultConfig?: boolean;\n\n /**\n * A custom substitution function that overrides the default one.\n *\n * @remarks\n * The substitution function handles syntax like `${MY_ENV_VAR}` in configuration values.\n * The default substitution will read the value from the environment and trim whitespace.\n */\n substitutionFunc?: SubstitutionFunc;\n}\n\n/**\n * Options for {@link ConfigSources.defaultForTargets}.\n *\n * @public\n */\nexport interface ConfigSourcesDefaultForTargetsOptions\n extends BaseConfigSourcesOptions {\n targets: ConfigSourceTarget[];\n}\n\n/**\n * Options for {@link ConfigSources.default}.\n *\n * @public\n */\nexport interface ConfigSourcesDefaultOptions extends BaseConfigSourcesOptions {\n argv?: string[];\n env?: Record<string, string | undefined>;\n}\n\n/**\n * A collection of utilities for working with and creating {@link ConfigSource}s.\n *\n * @public\n */\nexport class ConfigSources {\n /**\n * Parses command line arguments and returns the config targets.\n *\n * @param argv - The command line arguments to parse. Defaults to `process.argv`\n * @returns A list of config targets\n */\n static parseArgs(argv: string[] = process.argv): ConfigSourceTarget[] {\n const args: string[] = [parseArgs(argv).config].flat().filter(Boolean);\n return args.map(target => {\n try {\n const url = new URL(target);\n\n // Some file paths are valid relative URLs, so check if the host is empty too\n if (!url.host) {\n return { type: 'path', target };\n }\n return { type: 'url', target };\n } catch {\n return { type: 'path', target };\n }\n });\n }\n\n /**\n * Creates the default config sources for the provided targets.\n *\n * @remarks\n *\n * This will create {@link FileConfigSource}s and {@link RemoteConfigSource}s\n * for the provided targets, and merge them together to a single source.\n * If no targets are provided it will fall back to `app-config.yaml` and\n * `app-config.local.yaml`.\n *\n * URL targets are only supported if the `remote` option is provided.\n *\n * @param options - Options\n * @returns A config source for the provided targets\n */\n static defaultForTargets(\n options: ConfigSourcesDefaultForTargetsOptions,\n ): ConfigSource {\n const rootDir = options.rootDir ?? targetPaths.rootDir;\n\n const argSources = options.targets.map(arg => {\n if (arg.type === 'url') {\n if (!options.remote) {\n throw new Error(\n `Config argument \"${arg.target}\" looks like a URL but remote configuration is not enabled. Enable it by passing the \\`remote\\` option`,\n );\n }\n return RemoteConfigSource.create({\n url: arg.target,\n substitutionFunc: options.substitutionFunc,\n reloadInterval: options.remote.reloadInterval,\n });\n }\n return FileConfigSource.create({\n watch: options.watch,\n path: resolvePath(arg.target),\n substitutionFunc: options.substitutionFunc,\n });\n });\n\n if (argSources.length === 0) {\n const defaultPath = resolvePath(rootDir, 'app-config.yaml');\n const localPath = resolvePath(rootDir, 'app-config.local.yaml');\n const envPath = resolvePath(\n rootDir,\n `app-config.${process.env.BACKSTAGE_ENV}.yaml`,\n );\n const envLocalPath = resolvePath(\n rootDir,\n `app-config.${process.env.BACKSTAGE_ENV}.local.yaml`,\n );\n const alwaysIncludeDefaultConfigSource =\n !options.allowMissingDefaultConfig;\n\n if (alwaysIncludeDefaultConfigSource || fs.pathExistsSync(defaultPath)) {\n argSources.push(\n FileConfigSource.create({\n watch: options.watch,\n path: defaultPath,\n substitutionFunc: options.substitutionFunc,\n }),\n );\n }\n\n if (process.env.BACKSTAGE_ENV && fs.pathExistsSync(envPath)) {\n argSources.push(\n FileConfigSource.create({\n watch: options.watch,\n path: envPath,\n substitutionFunc: options.substitutionFunc,\n }),\n );\n }\n\n if (fs.pathExistsSync(localPath)) {\n argSources.push(\n FileConfigSource.create({\n watch: options.watch,\n path: localPath,\n substitutionFunc: options.substitutionFunc,\n }),\n );\n }\n\n if (process.env.BACKSTAGE_ENV && fs.pathExistsSync(envLocalPath)) {\n argSources.push(\n FileConfigSource.create({\n watch: options.watch,\n path: envLocalPath,\n substitutionFunc: options.substitutionFunc,\n }),\n );\n }\n }\n\n return this.merge(argSources);\n }\n\n /**\n * Creates the default config source for Backstage.\n *\n * @remarks\n *\n * This will read from `app-config.yaml` and `app-config.local.yaml` by\n * default, as well as environment variables prefixed with `APP_CONFIG_`.\n * If `--config <path|url>` command line arguments are passed, these will\n * override the default configuration file paths. URLs are only supported\n * if the `remote` option is provided.\n *\n * @param options - Options\n * @returns The default Backstage config source\n */\n static default(options: ConfigSourcesDefaultOptions): ConfigSource {\n const argSource = this.defaultForTargets({\n ...options,\n targets: this.parseArgs(options.argv),\n });\n\n const envSource = EnvConfigSource.create({\n env: options.env,\n });\n\n return this.merge([argSource, envSource]);\n }\n\n /**\n * Merges multiple config sources into a single source that reads from all\n * sources and concatenates the result.\n *\n * @param sources - The config sources to merge\n * @returns A single config source that concatenates the data from the given sources\n */\n static merge(sources: ConfigSource[]): ConfigSource {\n return MergedConfigSource.from(sources);\n }\n\n /**\n * Creates an observable {@link @backstage/config#Config} implementation from a {@link ConfigSource}.\n *\n * @remarks\n *\n * If you only want to read the config once you can close the returned config immediately.\n *\n * @example\n *\n * ```ts\n * const sources = ConfigSources.default(...)\n * const config = await ConfigSources.toConfig(source)\n * config.close()\n * const example = config.getString(...)\n * ```\n *\n * @param source - The config source to read from\n * @returns A promise that resolves to a closable config\n */\n static toConfig(source: ConfigSource): Promise<ClosableConfig> {\n return new Promise(async (resolve, reject) => {\n let config: ObservableConfigProxy | undefined = undefined;\n try {\n const abortController = new AbortController();\n for await (const { configs } of source.readConfigData({\n signal: abortController.signal,\n })) {\n if (config) {\n config.setConfig(ConfigReader.fromConfigs(configs));\n } else {\n config = ObservableConfigProxy.create(abortController);\n config!.setConfig(ConfigReader.fromConfigs(configs));\n resolve(config);\n }\n }\n } catch (error) {\n reject(error);\n }\n });\n }\n}\n"],"names":["parseArgs","targetPaths","RemoteConfigSource","FileConfigSource","resolvePath","fs","EnvConfigSource","MergedConfigSource","config","ConfigReader","ObservableConfigProxy"],"mappings":";;;;;;;;;;;;;;;;;;AAqHO,MAAM,aAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzB,OAAO,SAAA,CAAU,IAAA,GAAiB,OAAA,CAAQ,IAAA,EAA4B;AACpE,IAAA,MAAM,IAAA,GAAiB,CAACA,0BAAA,CAAU,IAAI,CAAA,CAAE,MAAM,CAAA,CAAE,IAAA,EAAK,CAAE,MAAA,CAAO,OAAO,CAAA;AACrE,IAAA,OAAO,IAAA,CAAK,IAAI,CAAA,MAAA,KAAU;AACxB,MAAA,IAAI;AACF,QAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,MAAM,CAAA;AAG1B,QAAA,IAAI,CAAC,IAAI,IAAA,EAAM;AACb,UAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAA,EAAO;AAAA,QAChC;AACA,QAAA,OAAO,EAAE,IAAA,EAAM,KAAA,EAAO,MAAA,EAAO;AAAA,MAC/B,CAAA,CAAA,MAAQ;AACN,QAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAA,EAAO;AAAA,MAChC;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,OAAO,kBACL,OAAA,EACc;AACd,IAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,OAAA,IAAWC,qBAAA,CAAY,OAAA;AAE/C,IAAA,MAAM,UAAA,GAAa,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,CAAA,GAAA,KAAO;AAC5C,MAAA,IAAI,GAAA,CAAI,SAAS,KAAA,EAAO;AACtB,QAAA,IAAI,CAAC,QAAQ,MAAA,EAAQ;AACnB,UAAA,MAAM,IAAI,KA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ACF,CAAC,CAAA;AAAA,EACH;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/config-loader",
3
- "version": "1.10.8-next.0",
3
+ "version": "1.10.9-next.0",
4
4
  "description": "Config loading functionality used by Backstage backend, and CLI",
5
5
  "backstage": {
6
6
  "role": "node-library"
@@ -36,7 +36,7 @@
36
36
  "test": "backstage-cli package test"
37
37
  },
38
38
  "dependencies": {
39
- "@backstage/cli-common": "0.1.18-next.0",
39
+ "@backstage/cli-common": "0.2.0-next.0",
40
40
  "@backstage/config": "1.3.6",
41
41
  "@backstage/errors": "1.2.7",
42
42
  "@backstage/types": "1.2.2",
@@ -53,8 +53,8 @@
53
53
  "yaml": "^2.0.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@backstage/backend-test-utils": "1.10.4-next.0",
57
- "@backstage/cli": "0.35.3-next.0",
56
+ "@backstage/backend-test-utils": "1.11.1-next.0",
57
+ "@backstage/cli": "0.35.5-next.0",
58
58
  "@types/json-schema-merge-allof": "^0.6.0",
59
59
  "@types/minimist": "^1.2.5",
60
60
  "msw": "^2.0.0",