diff --git a/services/service-package-registry/main/default/manager/loader.js b/services/service-package-registry/main/default/manager/loader.js index 6acbf87b46..f4f2bf572a 100644 --- a/services/service-package-registry/main/default/manager/loader.js +++ b/services/service-package-registry/main/default/manager/loader.js @@ -100,6 +100,8 @@ const appendToPackagesConfig = (packageName, options, actionName)=>{ } const loadPackages = async ()=>{ + let schema = objectql.getSteedosSchema(); + let broker = schema.broker; const packages = loadPackagesConfig(); for (const packageName in packages) { const package = packages[packageName] @@ -109,10 +111,12 @@ const loadPackages = async ()=>{ const packagePath = package.path || path.dirname(require.resolve(`${packageName}/package.json`)) if(packagePath){ const packageInfo = await loadPackage(packageName, packagePath); - appendToPackagesConfig(packageInfo.name, {version: packageInfo.version, description: packageInfo.description, local: true}); + if(packageInfo){ + appendToPackagesConfig(packageInfo.name, {version: packageInfo.version, description: packageInfo.description, local: true}); + } } } catch (error) { - console.error(error) + broker.logger.error(`start package ${packageName} error: ${error.message}`) } }else if(package.local !== true){ @@ -130,7 +134,7 @@ const loadPackages = async ()=>{ const packageInfo = await loadPackage(packageName); appendToPackagesConfig(packageInfo.name, {version: packageInfo.version, description: packageInfo.description, local: false}); } catch (error) { - console.error(error) + broker.logger.error(`start package ${packageName} error: ${error.message}`) } } }else if(package.local === true && package.static != true){ @@ -139,9 +143,13 @@ const loadPackages = async ()=>{ packagePath = path.resolve(process.cwd(), packagePath) } if(packagePath){ - const packageInfo = await loadPackage(packageName, packagePath); - if(packageInfo){ - appendToPackagesConfig(packageInfo.name, {version: packageInfo.version, description: packageInfo.description, local: true}); + try { + const packageInfo = await loadPackage(packageName, packagePath); + if(packageInfo){ + appendToPackagesConfig(packageInfo.name, {version: packageInfo.version, description: packageInfo.description, local: true}); + } + } catch (error) { + broker.logger.error(`start package ${packageName} error: ${error.message}`) } } } @@ -232,7 +240,7 @@ const loadDependency = async (mainPackageInfo = {}, dependencyName, dependencyVe } const loadPackage = async (packageName, packagePath)=>{ - try { + // try { if(!packagePath){ packagePath = path.dirname(require.resolve(`${packageName}/package.json`, { paths: [path.join(userDir, 'node_modules')] @@ -246,19 +254,28 @@ const loadPackage = async (packageName, packagePath)=>{ return ; } const packageInfo = require(path.join(packagePath, 'package.json')); + const packageYml = getPackageYmlData(packagePath); + + if(packageYml && packageYml.license && _.isArray(packageYml.license) && packageYml.license.length > 0){ + const has = await broker.call('@steedos/service-license.checkProducts', {keys: packageYml.license}); + if(!has){ + throw new Error(`Software package 「${packageName}」 requires 「${packageYml.license.join(',')}」 license.`) + } + } + await destroyExistThePackageService(packageInfo); await steedos.loadPackage(packagePath); - const packageConfig = getPackageConfig(packageName); - if(packageInfo.dependencies){ - for (const dependencyName in packageInfo.dependencies) { - const dependencyVersion = packageInfo.dependencies[dependencyName]; - await loadDependency(packageConfig, dependencyName, dependencyVersion); - } - } + // const packageConfig = getPackageConfig(packageName); + // if(packageInfo.dependencies){ + // for (const dependencyName in packageInfo.dependencies) { + // const dependencyVersion = packageInfo.dependencies[dependencyName]; + // await loadDependency(packageConfig, dependencyName, dependencyVersion); + // } + // } return Object.assign({packagePath: packagePath}, packageInfo); - } catch (error) { - console.error(packageName, packagePath, error) - } + // } catch (error) { + // console.error(packageName, packagePath, error) + // } } const disablePackage = async (packageName)=>{ @@ -303,6 +320,7 @@ const removePackageConfig = (packageName)=>{ const getPackageConfig = (packageName)=>{ const packages = loadPackagesConfig(); return _.find(packages, (info, name)=>{ + info.name = name; return packageName == name }); } diff --git a/services/service-package-registry/project.package.service.js b/services/service-package-registry/project.package.service.js index fe31f46bc1..a3284b4c23 100644 --- a/services/service-package-registry/project.package.service.js +++ b/services/service-package-registry/project.package.service.js @@ -157,6 +157,10 @@ module.exports = { const { module } = ctx.params let packageConfig = await loader.getPackageConfig(module); + if(packageConfig.static){ + packageConfig = Object.assign({}, packageConfig, this.getStaticPackageInfo(packageConfig, packageConfig.name)) + } + const packageYmlData = loader.getPackageYmlData(packageConfig.path); if(packageYmlData.dependencies){ @@ -501,7 +505,7 @@ module.exports = { instanceID: this.broker.instanceID, path: _packageInfo.path, local: _packageInfo.local, - enable: _packageInfo.enable, + enable: false, version: _packageInfo.version, description: _packageInfo.description, metadata: metadata,