@mashroom/mashroom
Advanced tools
Comparing version 2.2.3 to 2.3.0
@@ -13,2 +13,3 @@ "use strict"; | ||
var _model_utils = require("@mashroom/mashroom-utils/lib/model_utils"); | ||
var _ts_node_utils = require("@mashroom/mashroom-utils/lib/ts_node_utils"); | ||
var _ServerConfigurationError = _interopRequireDefault(require("../errors/ServerConfigurationError")); | ||
@@ -19,3 +20,3 @@ var _mashroom_default_config = _interopRequireDefault(require("./mashroom_default_config")); | ||
const HOSTNAME = _os.default.hostname() || 'localhost'; | ||
const CONFIG_FILES = ['mashroom.json', 'mashroom.js', `mashroom.${ENVIRONMENT}.json`, `mashroom.${ENVIRONMENT}.js`, `mashroom.${HOSTNAME}.json`, `mashroom.${HOSTNAME}.js`, `mashroom.${HOSTNAME}.${ENVIRONMENT}.json`, `mashroom.${HOSTNAME}.${ENVIRONMENT}.js`]; | ||
const CONFIG_FILES = ['mashroom.json', 'mashroom.js', 'mashroom.ts', `mashroom.${ENVIRONMENT}.json`, `mashroom.${ENVIRONMENT}.js`, `mashroom.${ENVIRONMENT}.ts`, `mashroom.${HOSTNAME}.json`, `mashroom.${HOSTNAME}.js`, `mashroom.${HOSTNAME}.ts`, `mashroom.${HOSTNAME}.${ENVIRONMENT}.json`, `mashroom.${HOSTNAME}.${ENVIRONMENT}.js`, `mashroom.${HOSTNAME}.${ENVIRONMENT}.ts`]; | ||
class MashroomServerConfigLoader { | ||
@@ -30,4 +31,8 @@ constructor(loggerFactory) { | ||
} | ||
this._logger.info('Considering config files:', CONFIG_FILES); | ||
const configFiles = CONFIG_FILES.map(name => `${serverRootPath}/${name}`); | ||
let possibleConfigFiles = CONFIG_FILES; | ||
if (!(0, _ts_node_utils.withinTsNode)()) { | ||
possibleConfigFiles = possibleConfigFiles.filter(p => !p.endsWith('.ts')); | ||
} | ||
this._logger.info('Considering config files (multiple possible):', possibleConfigFiles); | ||
const configFiles = possibleConfigFiles.map(name => `${serverRootPath}/${name}`); | ||
const existingConfigFiles = configFiles.filter(file => (0, _fs.existsSync)(file)); | ||
@@ -37,6 +42,7 @@ let config = _mashroom_default_config.default; | ||
for (const configFile of existingConfigFiles) { | ||
this._logger.info(`Loading config file: ${configFile}`); | ||
this._logger.info(`Using config file: ${configFile}`); | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const externalConfig = require(configFile); | ||
const externalConfigModule = require(configFile); | ||
const externalConfig = externalConfigModule.default ?? externalConfigModule; | ||
config = (0, _model_utils.deepAssign)({}, config, externalConfig); | ||
@@ -43,0 +49,0 @@ } catch (e) { |
@@ -10,2 +10,3 @@ "use strict"; | ||
var _log4js = _interopRequireDefault(require("log4js")); | ||
var _ts_node_utils = require("@mashroom/mashroom-utils/lib/ts_node_utils"); | ||
var _log4js_default_config = _interopRequireDefault(require("./log4js_default_config")); | ||
@@ -15,3 +16,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const HOSTNAME = _os.default.hostname() || 'localhost'; | ||
const CONFIG_FILES = [`log4js.${HOSTNAME}.${ENVIRONMENT}.js`, `log4js.${HOSTNAME}.${ENVIRONMENT}.json`, `log4js.${HOSTNAME}.js`, `log4js.${HOSTNAME}.json`, `log4js.${ENVIRONMENT}.js`, `log4js.${ENVIRONMENT}.json`, 'log4js.js', 'log4js.json']; | ||
const CONFIG_FILES = [`log4js.${HOSTNAME}.${ENVIRONMENT}.ts`, `log4js.${HOSTNAME}.${ENVIRONMENT}.js`, `log4js.${HOSTNAME}.${ENVIRONMENT}.json`, `log4js.${HOSTNAME}.ts`, `log4js.${HOSTNAME}.js`, `log4js.${HOSTNAME}.json`, `log4js.${ENVIRONMENT}.ts`, `log4js.${ENVIRONMENT}.js`, `log4js.${ENVIRONMENT}.json`, 'log4js.ts', 'log4js.js', 'log4js.json']; | ||
@@ -24,13 +25,18 @@ /** | ||
try { | ||
const configFiles = CONFIG_FILES.map(name => `${serverRootPath}/${name}`); | ||
let possibleConfigFiles = CONFIG_FILES; | ||
if (!(0, _ts_node_utils.withinTsNode)()) { | ||
possibleConfigFiles = possibleConfigFiles.filter(p => !p.endsWith('.ts')); | ||
} | ||
const configFiles = possibleConfigFiles.map(name => `${serverRootPath}/${name}`); | ||
const configFile = configFiles.find(file => (0, _fs.existsSync)(file)); | ||
if (configFile) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const logConfig = require(configFile); | ||
const logConfigModule = require(configFile); | ||
const logConfig = logConfigModule.default ?? logConfigModule; | ||
_log4js.default.configure(logConfig); | ||
_log4js.default.getLogger().info('Considering log config files: ', CONFIG_FILES); | ||
_log4js.default.getLogger().info('Considering log config files (take the first match): ', possibleConfigFiles); | ||
_log4js.default.getLogger().info(`log4js configured from: ${configFile}`); | ||
} else { | ||
_log4js.default.configure(_log4js_default_config.default); | ||
_log4js.default.getLogger().info('Considering log config files: ', CONFIG_FILES); | ||
_log4js.default.getLogger().info('Considering log config files: ', possibleConfigFiles); | ||
_log4js.default.getLogger().warn('No log config files found, using default config'); | ||
@@ -37,0 +43,0 @@ } |
@@ -17,2 +17,3 @@ "use strict"; | ||
var _NpmUtils = _interopRequireDefault(require("./NpmUtils")); | ||
var _NxUtils = _interopRequireDefault(require("./NxUtils")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -32,2 +33,3 @@ const readFile = (0, _util.promisify)(_fs.default.readFile); | ||
this._npmUtils = new _NpmUtils.default(loggerFactory, config.devModeNpmExecutionTimeoutSec || undefined); | ||
this._nxUtils = new _NxUtils.default(loggerFactory, config.devModeNpmExecutionTimeoutSec || undefined); | ||
this._eventEmitter = new _events.EventEmitter(); | ||
@@ -187,3 +189,7 @@ this._eventEmitter.setMaxListeners(0); | ||
this._logger.debug(`Running build script '${buildScript}': ${queueEntry.pluginPackageName}`); | ||
await this._npmUtils.runScript(queueEntry.pluginPackagePath, buildScript); | ||
if (await this._nxUtils.isNxAvailable(queueEntry.pluginPackagePath)) { | ||
await this._nxUtils.runScript(queueEntry.pluginPackagePath, buildScript); | ||
} else { | ||
await this._npmUtils.runScript(queueEntry.pluginPackagePath, buildScript); | ||
} | ||
} | ||
@@ -190,0 +196,0 @@ } |
@@ -10,4 +10,4 @@ "use strict"; | ||
/** | ||
* Encapsulate npm access | ||
/* | ||
* npm execution utils | ||
*/ | ||
@@ -20,33 +20,16 @@ class NpmUtils { | ||
/** | ||
/* | ||
* Run install in given package path | ||
* | ||
* @param {string} packagePath | ||
* @return {Promise<void>} | ||
*/ | ||
install(packagePath) { | ||
async install(packagePath) { | ||
return this._npmExecute(packagePath, 'install'); | ||
} | ||
/** | ||
* Run update in given package path | ||
* | ||
* @param {string }packagePath | ||
* @return {Promise<void>} | ||
*/ | ||
update(packagePath) { | ||
return this._npmExecute(packagePath, 'update'); | ||
} | ||
/** | ||
/* | ||
* Run a script in given package path | ||
* | ||
* @param {string} packagePath | ||
* @param {string} script | ||
* @return {Promise<void>} | ||
*/ | ||
runScript(packagePath, script) { | ||
async runScript(packagePath, script) { | ||
return this._npmExecute(packagePath, 'run', script); | ||
} | ||
_npmExecute(packagePath, command, ...args) { | ||
async _npmExecute(packagePath, command, ...args) { | ||
return new Promise((resolve, reject) => { | ||
@@ -53,0 +36,0 @@ const commandString = `npm ${command} ${args.join(' ')}`; |
@@ -122,3 +122,5 @@ "use strict"; | ||
try { | ||
return require(externalPluginConfigFile); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const pluginConfigModule = require(externalPluginConfigFile); | ||
return pluginConfigModule.default ?? pluginConfigModule; | ||
} catch (e) { | ||
@@ -125,0 +127,0 @@ this._logger.error(`Error processing plugin definition in: ${externalPluginConfigFile}: File exists but is not readable!`); |
@@ -125,3 +125,2 @@ "use strict"; | ||
await this._load(plugin, connector); | ||
await this._checkPluginsMissingRequirements(); | ||
} | ||
@@ -198,2 +197,5 @@ async _updatePlugin(plugin, updatedPluginDefinition) { | ||
}); | ||
// After loading this plugin we might be able to load other Plugins with missing requirements | ||
await this._checkPluginsMissingRequirements(); | ||
} catch (error) { | ||
@@ -258,3 +260,3 @@ this._logger.error(`Loading plugin: ${plugin.name}, type: ${plugin.type} failed!`, error); | ||
if (connector) { | ||
this._logger.info(`Re-try to load plugin with no loader: ${unloadedPlugin.name}`); | ||
this._logger.info(`Retry to load plugin with no loader: ${unloadedPlugin.name}`); | ||
await this._load(unloadedPlugin, connector); | ||
@@ -268,3 +270,3 @@ } | ||
if (this._pluginsMissingRequirements.indexOf(unloadedPlugin) === -1) { | ||
// If the re-load of a plugin takes a long time another call of | ||
// If the reload of a plugin takes a long time another call of | ||
// __checkPluginsMissingRequirements() could have loaded this already | ||
@@ -276,3 +278,3 @@ continue; | ||
if (connector) { | ||
this._logger.info(`Re-try to load plugin with missing requirements: ${unloadedPlugin.name}`); | ||
this._logger.info(`Retry to load plugin with missing requirements: ${unloadedPlugin.name}`); | ||
await this._load(unloadedPlugin, connector); | ||
@@ -279,0 +281,0 @@ } |
@@ -44,3 +44,4 @@ "use strict"; | ||
for (const serviceName in pluginContext.services[namespace]) { | ||
if (pluginContext.services[namespace].hasOwnProperty(serviceName)) { | ||
var _pluginContext$servic; | ||
if ((_pluginContext$servic = pluginContext.services[namespace]) !== null && _pluginContext$servic !== void 0 && _pluginContext$servic.hasOwnProperty(serviceName)) { | ||
services.push({ | ||
@@ -67,4 +68,5 @@ namespace, | ||
const ms = []; | ||
for (const methodName of Object.getOwnPropertyNames(Object.getPrototypeOf(pluginContext.services[namespace][serviceName]))) { | ||
if (methodName !== 'constructor' && !methodName.startsWith('_') && typeof (pluginContext.services[namespace][serviceName][methodName] === 'function')) { | ||
for (const methodName of Object.getOwnPropertyNames(Object.getPrototypeOf((_pluginContext$servic2 = pluginContext.services[namespace]) === null || _pluginContext$servic2 === void 0 ? void 0 : _pluginContext$servic2[serviceName]))) { | ||
var _pluginContext$servic2, _pluginContext$servic3; | ||
if (methodName !== 'constructor' && !methodName.startsWith('_') && typeof (((_pluginContext$servic3 = pluginContext.services[namespace]) === null || _pluginContext$servic3 === void 0 ? void 0 : _pluginContext$servic3[serviceName][methodName]) === 'function')) { | ||
ms.push(methodName); | ||
@@ -71,0 +73,0 @@ } |
@@ -35,4 +35,5 @@ "use strict"; | ||
// All plugins loaded and ready | ||
const allPluginPackagesBuild = pluginService.getPluginPackages().every(pluginPackage => pluginPackage.status === 'ready'); | ||
const allPluginsLoaded = pluginService.getPlugins().every(plugin => plugin.status === 'loaded'); | ||
if (!allPluginsLoaded) { | ||
if (!allPluginPackagesBuild || !allPluginsLoaded) { | ||
ok = false; | ||
@@ -39,0 +40,0 @@ errors.push('Not all plugins loaded'); |
@@ -10,2 +10,3 @@ "use strict"; | ||
var _model_utils = require("@mashroom/mashroom-utils/lib/model_utils"); | ||
var _ts_node_utils = require("@mashroom/mashroom-utils/lib/ts_node_utils"); | ||
const createPluginConfig = (plugin, loader, context) => { | ||
@@ -22,2 +23,5 @@ const minimumPluginConfig = loader.generateMinimumConfig(plugin); | ||
possiblePluginConfigFiles.push((0, _path.resolve)(pluginPackagePath, `${name}.js`)); | ||
if ((0, _ts_node_utils.withinTsNode)()) { | ||
possiblePluginConfigFiles.push((0, _path.resolve)(pluginPackagePath, `${name}.ts`)); | ||
} | ||
}); | ||
@@ -24,0 +28,0 @@ const existingPluginConfigFiles = possiblePluginConfigFiles.filter(path => (0, _fs.existsSync)(path)); |
@@ -7,3 +7,3 @@ { | ||
"license": "MIT", | ||
"version": "2.2.3", | ||
"version": "2.3.0", | ||
"main": "dist", | ||
@@ -21,9 +21,9 @@ "files": [ | ||
"dependencies": { | ||
"@mashroom/mashroom-utils": "2.2.3", | ||
"@types/express": "^4.17.14", | ||
"anymatch": "^3.1.2", | ||
"@mashroom/mashroom-utils": "2.3.0", | ||
"@types/express": "^4.17.15", | ||
"anymatch": "^3.1.3", | ||
"chokidar": "^3.5.3", | ||
"express": "^4.18.2", | ||
"fs-extra": "^10.1.0", | ||
"log4js": "^6.7.0", | ||
"fs-extra": "^11.1.0", | ||
"log4js": "^6.7.1", | ||
"lucy-dirsum": "^0.1.1", | ||
@@ -34,3 +34,3 @@ "minimist": "^1.2.7", | ||
"devDependencies": { | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/fs-extra": "^11.0.1", | ||
"@types/spdy": "^3.4.5" | ||
@@ -37,0 +37,0 @@ }, |
@@ -351,4 +351,8 @@ | ||
export type MashroomServices = { | ||
readonly [key: string]: any | undefined | null; | ||
export interface MashroomServicePluginNamespaces { | ||
readonly [key: string]: MashroomServicePluginServices | undefined; | ||
} | ||
export type MashroomServicePluginServices = { | ||
readonly [key: string]: any; | ||
}; | ||
@@ -474,4 +478,3 @@ | ||
readonly core: MashroomCoreServices; | ||
readonly [key: string]: MashroomServices; | ||
}; | ||
} & MashroomServicePluginNamespaces; | ||
}; | ||
@@ -540,2 +543,2 @@ | ||
contextHolder: MashroomPluginContextHolder, | ||
) => Promise<MashroomServices>; | ||
) => Promise<MashroomServicePluginServices>; |
@@ -5,3 +5,3 @@ // @flow | ||
export type ExpressRequestWithContext = $Subtype<$Request> & { | ||
export type ExpressRequestWithContext = $Request & { | ||
pluginContext: MashroomPluginContext, | ||
@@ -8,0 +8,0 @@ session?: any; |
@@ -16,3 +16,2 @@ | ||
MashroomPluginLoaderMap, | ||
MashroomServices, | ||
MashroomServerInfo, | ||
@@ -23,3 +22,3 @@ MashroomLoggerFactory, | ||
MashroomHttpUpgradeService, | ||
MashroomHealthProbe, | ||
MashroomServicePluginServices, | ||
} from './api'; | ||
@@ -182,7 +181,7 @@ | ||
readonly core: MashroomCoreServices; | ||
readonly [namespace: string]: MashroomServices | ||
readonly [namespace: string]: MashroomServicePluginServices | ||
} | ||
export interface MashroomServiceRegistry { | ||
registerServices(namespace: string, services: MashroomServices): void; | ||
registerServices(namespace: string, services: MashroomServicePluginServices): void; | ||
unregisterServices(namespace: string): void; | ||
@@ -189,0 +188,0 @@ getServiceNamespaces(): Readonly<MashroomServiceNamespaces>; |
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
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
196575
77
5167
20
4
+ Added@mashroom/mashroom-utils@2.3.0(transitive)
+ Addedfs-extra@11.2.0(transitive)
- Removed@mashroom/mashroom-utils@2.2.3(transitive)
- Removedfs-extra@10.1.0(transitive)
Updated@types/express@^4.17.15
Updatedanymatch@^3.1.3
Updatedfs-extra@^11.1.0
Updatedlog4js@^6.7.1