fix: continent on error (#5740)

This commit is contained in:
chenos 2024-11-27 14:15:38 +08:00 committed by GitHub
parent f56f49d3ca
commit c825182f32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -128,7 +128,12 @@ export class PluginManagerRepository extends Repository {
}
const sorter = new Topo.Sorter<string>();
for (const pluginName of pluginNames) {
const packageJson = await PluginManager.getPackageJson(pluginName);
let packageJson: any = {};
try {
packageJson = await PluginManager.getPackageJson(pluginName);
} catch (error) {
packageJson = {};
}
const peerDependencies = Object.keys(packageJson?.peerDependencies || {});
sorter.add(pluginName, { after: peerDependencies, group: packageJson?.packageName || pluginName });
}

View File

@ -130,9 +130,11 @@ export class PluginManager {
*/
static async getPackageJson(nameOrPkg: string) {
const { packageName } = await this.parseName(nameOrPkg);
const file = await fs.realpath(resolve(process.env.NODE_MODULES_PATH, packageName, 'package.json'));
const data = await fs.readFile(file, { encoding: 'utf-8' });
return JSON.parse(data);
const packageFile = resolve(process.env.NODE_MODULES_PATH, packageName, 'package.json');
if (!(await fs.exists(packageFile))) {
throw new Error(`Cannot find plugin '${nameOrPkg}'`);
}
return fs.readJSON(packageFile);
}
/**