@artus/core
Advanced tools
Comparing version 2.2.1 to 2.2.2-alpha.0
import { ManifestItem } from '../loader'; | ||
export type ConfigObject = Record<string, any>; | ||
export type FrameworkObject = { | ||
path: string; | ||
env: string; | ||
}; | ||
export type PackageObject = ConfigObject; | ||
export type FrameworkOptions = { | ||
env: string; | ||
unitName: string; | ||
}; | ||
export default class ConfigurationHandler { | ||
static getEnvFromFilename(filename: string): string; | ||
configStore: Map<string, ConfigObject>; | ||
configStore: Record<string, ConfigObject>; | ||
private container; | ||
getMergedConfig(): ConfigObject; | ||
mergeConfigByStore(store: Record<string, ConfigObject>): ConfigObject; | ||
clearStore(): void; | ||
@@ -18,0 +11,0 @@ setConfig(env: string, config: ConfigObject): void; |
@@ -11,3 +11,3 @@ "use strict"; | ||
constructor() { | ||
this.configStore = new Map(); | ||
this.configStore = {}; | ||
} | ||
@@ -22,2 +22,5 @@ static getEnvFromFilename(filename) { | ||
getMergedConfig() { | ||
return this.mergeConfigByStore(this.configStore); | ||
} | ||
mergeConfigByStore(store) { | ||
var _a; | ||
@@ -28,13 +31,13 @@ let envList = this.container.get(constant_1.ArtusInjectEnum.EnvList, { noThrow: true }); | ||
} | ||
const defaultConfig = (_a = this.configStore.get(constant_1.ARTUS_DEFAULT_CONFIG_ENV.DEFAULT)) !== null && _a !== void 0 ? _a : {}; | ||
const envConfigList = envList.map(currentEnv => { var _a; return ((_a = this.configStore.get(currentEnv)) !== null && _a !== void 0 ? _a : {}); }); | ||
const defaultConfig = (_a = store[constant_1.ARTUS_DEFAULT_CONFIG_ENV.DEFAULT]) !== null && _a !== void 0 ? _a : {}; | ||
const envConfigList = envList.map(currentEnv => { var _a; return ((_a = store[currentEnv]) !== null && _a !== void 0 ? _a : {}); }); | ||
return (0, merge_1.mergeConfig)(defaultConfig, ...envConfigList); | ||
} | ||
clearStore() { | ||
this.configStore.clear(); | ||
this.configStore = {}; | ||
} | ||
setConfig(env, config) { | ||
var _a; | ||
const storedConfig = (_a = this.configStore.get(env)) !== null && _a !== void 0 ? _a : {}; | ||
this.configStore.set(env, (0, merge_1.mergeConfig)(storedConfig, config)); | ||
const storedConfig = (_a = this.configStore[env]) !== null && _a !== void 0 ? _a : {}; | ||
this.configStore[env] = (0, merge_1.mergeConfig)(storedConfig, config); | ||
} | ||
@@ -41,0 +44,0 @@ async setConfigByFile(fileItem) { |
@@ -52,3 +52,2 @@ "use strict"; | ||
'plugin-meta', | ||
'framework-config', | ||
'package-json', | ||
@@ -55,0 +54,0 @@ 'module', |
@@ -14,2 +14,3 @@ "use strict"; | ||
const logger_1 = require("../logger"); | ||
const merge_1 = require("./utils/merge"); | ||
let LoaderFactory = LoaderFactory_1 = class LoaderFactory { | ||
@@ -48,3 +49,3 @@ constructor() { | ||
async loadManifest(manifest, root = process.cwd()) { | ||
var _a, _b, _c; | ||
var _a, _b; | ||
if (!('version' in manifest) || manifest.version !== '2') { | ||
@@ -55,8 +56,14 @@ throw new Error(`invalid manifest, @artus/core@2.x only support manifest version 2.`); | ||
// Merge plugin config with ref | ||
for (const [env, pluginConfig] of Object.entries((_a = manifest.pluginConfig) !== null && _a !== void 0 ? _a : {})) { | ||
this.configurationHandler.setConfig(env, { | ||
plugin: pluginConfig, | ||
}); | ||
} | ||
const mergedPluginConfig = Object.assign({}, (_c = (_b = this.configurationHandler.getMergedConfig()) === null || _b === void 0 ? void 0 : _b.plugin) !== null && _c !== void 0 ? _c : {}); // shallow copy to avoid side effect of writing metadata | ||
const mergeRef = (refName) => { | ||
var _a, _b; | ||
if (!refName || !((_a = manifest.refMap) === null || _a === void 0 ? void 0 : _a[refName])) { | ||
return {}; | ||
} | ||
const pluginConfig = this.configurationHandler.mergeConfigByStore((_b = manifest.refMap[refName].pluginConfig) !== null && _b !== void 0 ? _b : {}); | ||
return (0, merge_1.mergeConfig)(...Object.values(pluginConfig).map(({ refName }) => mergeRef(refName)).concat(pluginConfig)); | ||
}; | ||
const mergedPluginConfig = (0, merge_1.mergeConfig)((_a = manifest.extraPluginConfig) !== null && _a !== void 0 ? _a : {}, ...[ | ||
...Object.values((_b = manifest.extraPluginConfig) !== null && _b !== void 0 ? _b : {}).map(({ refName }) => refName), | ||
constant_1.DEFAULT_APP_REF, | ||
].map(mergeRef)); | ||
for (const [pluginName, pluginConfigItem] of Object.entries(mergedPluginConfig)) { | ||
@@ -63,0 +70,0 @@ const refItem = manifest.refMap[pluginConfigItem.refName]; |
@@ -33,7 +33,2 @@ "use strict"; | ||
let configObj = await this.loadConfigFile(item); | ||
// if (namespace === 'plugin') { | ||
// configObj = { | ||
// plugin: await PluginFactory.formatPluginConfig(configObj, item), | ||
// }; | ||
// } else | ||
if (namespace) { | ||
@@ -40,0 +35,0 @@ configObj = { |
@@ -9,2 +9,3 @@ import { Container } from '@artus/injection'; | ||
pluginMetadata?: PluginMetadata; | ||
pluginConfig: PluginConfigEnvMap; | ||
items: ManifestItem[]; | ||
@@ -15,4 +16,4 @@ } | ||
version: '2'; | ||
pluginConfig: PluginConfigEnvMap; | ||
refMap: RefMap; | ||
extraPluginConfig?: PluginConfig; | ||
} | ||
@@ -19,0 +20,0 @@ export interface ManifestItem<LoaderState = unknown> extends Record<string, any> { |
@@ -9,3 +9,3 @@ import { ScannerOptions, ScanTaskItem } from './types'; | ||
private enabledPluginSet; | ||
private pluginConfigMap; | ||
private extraPluginConfig; | ||
private refMap; | ||
@@ -16,3 +16,3 @@ private taskQueue; | ||
private walk; | ||
handlePluginConfig(pluginConfig: PluginConfig, basePath: string, env?: string): Promise<void>; | ||
handlePluginConfig(pluginConfig: PluginConfig, basePath: string): Promise<PluginConfig>; | ||
/** | ||
@@ -19,0 +19,0 @@ * Handler of single scan task(only a ref) |
@@ -9,3 +9,2 @@ "use strict"; | ||
const loader_1 = require("../loader"); | ||
const merge_1 = require("../loader/utils/merge"); | ||
const load_meta_file_1 = require("../utils/load_meta_file"); | ||
@@ -21,3 +20,3 @@ const constant_1 = require("../constant"); | ||
this.enabledPluginSet = new Set(); // Key is pluginName | ||
this.pluginConfigMap = {}; | ||
this.extraPluginConfig = {}; | ||
this.refMap = {}; | ||
@@ -97,11 +96,7 @@ this.taskQueue = []; | ||
*/ | ||
async handlePluginConfig(pluginConfig, basePath, env = constant_1.ARTUS_DEFAULT_CONFIG_ENV.DEFAULT) { | ||
var _a, _b; | ||
const tPluginConfig = {}; | ||
async handlePluginConfig(pluginConfig, basePath) { | ||
var _a; | ||
const res = {}; | ||
for (const [pluginName, pluginConfigItem] of Object.entries(pluginConfig)) { | ||
// Set temp pluginConfig in manifest | ||
tPluginConfig[pluginName] = {}; | ||
if (pluginConfigItem.enable !== undefined) { | ||
tPluginConfig[pluginName].enable = pluginConfigItem.enable; | ||
} | ||
if (pluginConfigItem.enable) { | ||
@@ -116,3 +111,5 @@ this.enabledPluginSet.add(pluginName); | ||
} | ||
tPluginConfig[pluginName].refName = ref.name; | ||
res[pluginName] = Object.assign(Object.assign({}, pluginConfigItem), { refName: ref.name }); | ||
if (ref.path.includes('@artus/injection')) | ||
console.log(pluginConfigItem, basePath, ref); | ||
// Generate and push scan task | ||
@@ -140,5 +137,3 @@ const curRefTask = { | ||
} | ||
// Reverse Merge, The prior of top-level(exists) is higher | ||
const existsPluginConfig = (_b = this.pluginConfigMap[env]) !== null && _b !== void 0 ? _b : {}; | ||
this.pluginConfigMap[env] = (0, merge_1.mergeConfig)(tPluginConfig, existsPluginConfig); | ||
return res; | ||
} | ||
@@ -190,2 +185,3 @@ /** | ||
packageVersion, | ||
pluginConfig: {}, | ||
items: [], | ||
@@ -209,3 +205,3 @@ }; | ||
} | ||
await this.handlePluginConfig(pluginConfig, basePath, env); | ||
refItem.pluginConfig[env] = await this.handlePluginConfig(pluginConfig, basePath); | ||
} | ||
@@ -220,3 +216,3 @@ if (this.options.useRelativePath) { | ||
if (this.options.plugin) { | ||
await this.handlePluginConfig(this.options.plugin, this.root); | ||
this.extraPluginConfig = await this.handlePluginConfig(this.options.plugin, this.root); | ||
} | ||
@@ -238,4 +234,4 @@ // Add Root Task(make it as top/start) | ||
version: '2', | ||
pluginConfig: this.pluginConfigMap, | ||
refMap: this.refMap, | ||
extraPluginConfig: this.extraPluginConfig, | ||
}; | ||
@@ -242,0 +238,0 @@ } |
@@ -54,3 +54,3 @@ "use strict"; | ||
// Use temp Map to store config | ||
const configEnvMap = new Map(); | ||
const configEnvMap = {}; | ||
const stashedConfigStore = app.configurationHandler.configStore; | ||
@@ -65,3 +65,3 @@ app.configurationHandler.configStore = configEnvMap; | ||
app.configurationHandler.configStore = stashedConfigStore; | ||
return Object.fromEntries(configEnvMap.entries()); | ||
return configEnvMap; | ||
}; | ||
@@ -68,0 +68,0 @@ exports.loadConfigItemList = loadConfigItemList; |
{ | ||
"name": "@artus/core", | ||
"version": "2.2.1", | ||
"version": "2.2.2-alpha.0", | ||
"description": "Core package of Artus", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120198
117
2902
1
12