mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Handle files not existing
This commit is contained in:
1 parent
472177bf39
commit
91cbd7a464
1 file changed
+25
-10
@@ -14,13 +14,22 @@ import * as libFileOps from "./file_ops";
|
|||||||
async function findLocalPlugins(pluginList: Map<string, string>, pluginListPath: string) {
|
async function findLocalPlugins(pluginList: Map<string, string>, pluginListPath: string) {
|
||||||
// Check folders for plugins
|
// Check folders for plugins
|
||||||
const pluginFolders = [
|
const pluginFolders = [
|
||||||
path.join(process.cwd(), "plugins"),
|
"plugins",
|
||||||
path.join(process.cwd(), "external_plugins"),
|
"external_plugins",
|
||||||
];
|
];
|
||||||
|
|
||||||
let has_changed = 0;
|
let has_changed = 0;
|
||||||
for (const pluginFolder of pluginFolders) {
|
for (const pluginFolder of pluginFolders) {
|
||||||
const pluginNames = await fs.readdir(pluginFolder);
|
let pluginNames;
|
||||||
|
try {
|
||||||
|
pluginNames = await fs.readdir(pluginFolder);
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.code === "ENOENT") {
|
||||||
|
// Skip if folder doesn't exist
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
for (const pluginName of pluginNames) {
|
for (const pluginName of pluginNames) {
|
||||||
if (pluginList.has(pluginName)) {
|
if (pluginList.has(pluginName)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -56,11 +65,17 @@ async function findLocalPlugins(pluginList: Map<string, string>, pluginListPath:
|
|||||||
* @returns Promise that resolves when plugin discovery is complete
|
* @returns Promise that resolves when plugin discovery is complete
|
||||||
*/
|
*/
|
||||||
async function findNpmPlugins(pluginList: Map<string, string>, pluginListPath: string) {
|
async function findNpmPlugins(pluginList: Map<string, string>, pluginListPath: string) {
|
||||||
const rootPackageJson = JSON.parse(await fs.readFile(path.resolve(
|
let dependencies;
|
||||||
process.cwd(),
|
try {
|
||||||
"package.json",
|
const rootPackageJson = JSON.parse(await fs.readFile(path.resolve("package.json"), { encoding: "utf8" }));
|
||||||
), { encoding: "utf8" }));
|
dependencies = rootPackageJson.dependencies;
|
||||||
const dependencies = rootPackageJson.dependencies;
|
} catch (err: any) {
|
||||||
|
if (err.code === "ENOENT") {
|
||||||
|
// Skip if package.json doesn't exist
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
let changed = 0;
|
let changed = 0;
|
||||||
for (const [pluginName, pluginVersion] of Object.entries(dependencies)) {
|
for (const [pluginName, pluginVersion] of Object.entries(dependencies)) {
|
||||||
@@ -68,12 +83,12 @@ async function findNpmPlugins(pluginList: Map<string, string>, pluginListPath: s
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Find the package in node_modules and read the package.json
|
// Find the package in node_modules and read the package.json
|
||||||
const packageJsonPath = path.resolve(process.cwd(), "node_modules", pluginName, "package.json");
|
const packageJsonPath = path.resolve("node_modules", pluginName, "package.json");
|
||||||
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: "utf8" }));
|
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: "utf8" }));
|
||||||
// Check if the package has the "clusterio-plugin" keyword
|
// Check if the package has the "clusterio-plugin" keyword
|
||||||
if (packageJson.keywords?.includes("clusterio-plugin")) {
|
if (packageJson.keywords?.includes("clusterio-plugin")) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const pluginInfo = require(path.resolve(process.cwd(), "node_modules", pluginName)).plugin;
|
const pluginInfo = require(path.resolve("node_modules", pluginName)).plugin;
|
||||||
pluginList.set(pluginInfo.name, pluginName);
|
pluginList.set(pluginInfo.name, pluginName);
|
||||||
logger.info(`Added ${pluginInfo.name} from NPM`);
|
logger.info(`Added ${pluginInfo.name} from NPM`);
|
||||||
changed += 1;
|
changed += 1;
|
||||||
|
|||||||
Reference in new issue
Block a user