Skip to content

Commit

Permalink
fix: only import Config if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Nov 8, 2023
1 parent 2a1e5cf commit 587c588
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/hooks/init/load_config_meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/

import type { Hook } from '@oclif/core';
import { Config, ConfigPropertyMeta } from '@salesforce/core';
import { isObject, get } from '@salesforce/ts-types';
import type { ConfigPropertyMeta } from '@salesforce/core';
import { ModuleLoader } from '@oclif/core';

const OCLIF_META_PJSON_KEY = 'configMeta';
Expand All @@ -16,11 +15,9 @@ const hook: Hook<'init'> = async ({ config, context }): Promise<void> => {
const flattenedConfigMetas = (
await Promise.all(
(config.getPluginsList() || []).flatMap(async (plugin) => {
const configMetaPath = get(plugin, `pjson.oclif.${OCLIF_META_PJSON_KEY}`, null);

if (typeof configMetaPath !== 'string') {
return;
}
const oclif = (plugin.pjson.oclif ?? {}) as { [OCLIF_META_PJSON_KEY]?: string };
const configMetaPath = oclif[OCLIF_META_PJSON_KEY];
if (!configMetaPath) return;

const module = await ModuleLoader.load<{ default?: ConfigPropertyMeta[] }>(plugin, configMetaPath);
const configMeta = module.default;
Expand All @@ -33,9 +30,10 @@ const hook: Hook<'init'> = async ({ config, context }): Promise<void> => {
)
)
.flatMap((d) => d)
.filter<ConfigPropertyMeta>(isObject);
.filter((d): d is ConfigPropertyMeta => !!d);

if (flattenedConfigMetas.length) {
const { Config } = await import('@salesforce/core/lib/config/config.js');
Config.addAllowedProperties(flattenedConfigMetas);
}
return Promise.resolve();
Expand Down

0 comments on commit 587c588

Please sign in to comment.