From 0727cf9c36b122131e8b6625d4cc4f3c76b457d1 Mon Sep 17 00:00:00 2001 From: Jason Morse <35609178+JasonVMo@users.noreply.github.com> Date: Thu, 23 Jan 2025 12:25:19 -0800 Subject: [PATCH] feat(config): add helper for loading kit config in the case where package.json has been parsed already (#3492) * add helper for loading kit config when package.json has already been parsed * docs(changeset): Add helper to load the kit config from an already parsed package.json file * add export for new helper (missed when xferring change over) * renamed getKitConfigFromPackageJson to getKitConfigFromPackageManifest --- .changeset/cuddly-carrots-carry.md | 5 +++++ packages/config/src/getKitConfig.ts | 13 +++++++++++++ packages/config/src/index.ts | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .changeset/cuddly-carrots-carry.md diff --git a/.changeset/cuddly-carrots-carry.md b/.changeset/cuddly-carrots-carry.md new file mode 100644 index 000000000..173af038b --- /dev/null +++ b/.changeset/cuddly-carrots-carry.md @@ -0,0 +1,5 @@ +--- +"@rnx-kit/config": patch +--- + +Add helper to load the kit config from an already parsed package.json file diff --git a/packages/config/src/getKitConfig.ts b/packages/config/src/getKitConfig.ts index 041ba3095..001372c08 100644 --- a/packages/config/src/getKitConfig.ts +++ b/packages/config/src/getKitConfig.ts @@ -69,3 +69,16 @@ export function getKitConfig( return undefined; } } + +/** + * Helper for loading the KitConfig for cases where the package.json has already been loaded for other reasons. + * @param packageJson The loaded and parsed package.json file for this package. + * @param packageDir The directory containing the package.json file. + * @returns The rnx-kit configuration for this package, merged with any base configuration. + */ +export function getKitConfigFromPackageManifest( + packageJson: PackageManifest, + packageDir: string +): KitConfig | undefined { + return loadBaseConfig(packageJson["rnx-kit"], packageDir); +} diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index da377262a..1114b053c 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -11,7 +11,7 @@ export { getBundleConfig, getPlatformBundleConfig } from "./getBundleConfig"; export { getKitCapabilities } from "./getKitCapabilities"; export type { KitCapabilities } from "./getKitCapabilities"; -export { getKitConfig } from "./getKitConfig"; +export { getKitConfig, getKitConfigFromPackageManifest } from "./getKitConfig"; export type { GetKitConfigOptions } from "./getKitConfig"; export type {