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(scanner): use individual store for loadConfigItemList #248

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions src/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ export default class ConfigurationHandler {
return mergeConfig(defaultConfig, ...envConfigList);
}

getAllConfig(): ConfigObject {
const defaultConfig = this.configStore.get(ARTUS_DEFAULT_CONFIG_ENV.DEFAULT) ?? {};
const keys = Array.from(this.configStore.keys()).filter(
key => key !== ARTUS_DEFAULT_CONFIG_ENV.DEFAULT,
);
return mergeConfig(defaultConfig, ...keys.map(key => this.configStore.get(key) ?? {}));
}

clearStore(): void {
this.configStore.clear();
}
Expand Down
2 changes: 0 additions & 2 deletions src/scanner/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ export class ScanTaskRunner {
const taskItem = this.taskQueue.shift();
await this.run(taskItem);
}
// Clean up
this.app.configurationHandler.clearStore();
}

public dump(): Manifest {
Expand Down
16 changes: 14 additions & 2 deletions src/scanner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PluginConfigItem } from '../plugin';
import { getInlinePackageEntryPath, getPackagePath } from '../plugin/common';
import { Application } from '../types';
import { ManifestItem } from '../loader';
import { ConfigObject } from '../configuration';

export const getPackageVersion = async (basePath: string): Promise<string | undefined> => {
try {
Expand Down Expand Up @@ -45,15 +46,26 @@ export const isPluginAsync = (basePath: string): Promise<boolean> => {
return existsAsync(path.resolve(basePath, PLUGIN_META_FILENAME));
};

export const loadConfigItemList = async <T = Record<string, any>>(configItemList: ManifestItem[], app: Application): Promise<Record<string, T>> => {
export const loadConfigItemList = async <T = ConfigObject>(configItemList: ManifestItem[], app: Application): Promise<Record<string, T>> => {
if (!configItemList.length) {
return {};
}

// Use temp Map to store config
const configEnvMap: Map<string, T> = new Map();
const stashedConfigStore = app.configurationHandler.configStore;
app.configurationHandler.configStore = configEnvMap;

// Load all config items without hook
const enabledLifecycleManager = app.lifecycleManager.enable;
app.lifecycleManager.enable = false;
await app.loaderFactory.loadItemList(configItemList);
app.lifecycleManager.enable = enabledLifecycleManager;
return Object.fromEntries(app.configurationHandler.configStore.entries()) as Record<string, T>;

// Restore config store
app.configurationHandler.configStore = stashedConfigStore;

return Object.fromEntries(configEnvMap.entries());
};

export const resolvePluginConfigItemRef = async (
Expand Down