Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only import Config if necessary #428

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading