mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
Add packagePath to plugin info
Provide the absolute path to the package.json file in the resolved plugin info to simplify the logic around loading files from it.
This commit is contained in:
1 parent
d6dce12acc
commit
30083b96c1
8 files changed
+20
-18
No files matched your search
@@ -26,11 +26,15 @@ export async function loadPluginInfos(pluginList: Map<string, string>) {
|
||||
for (let [pluginName, pluginPath] of pluginList) {
|
||||
let pluginInfo: libPlugin.PluginNodeEnvInfo;
|
||||
let pluginPackage: { name?: string, version: string, main?: string, private?: boolean };
|
||||
let packagePath;
|
||||
|
||||
// Check if plugin path exists, otherwise remove it
|
||||
// Check if plugin has a package.json file, otherwise remove it
|
||||
try {
|
||||
require.resolve(pluginPath);
|
||||
} catch {
|
||||
const absolute = path.isAbsolute(pluginPath);
|
||||
const packageImport = path.posix.join(pluginPath, "package.json");
|
||||
packagePath = require.resolve(packageImport);
|
||||
await fs.access(packagePath, fs.constants.F_OK);
|
||||
} catch (err) {
|
||||
let errMsg = `Plugin path ${pluginPath} does not exist`;
|
||||
try {
|
||||
await fs.access(pluginPath, fs.constants.F_OK);
|
||||
@@ -43,7 +47,7 @@ export async function loadPluginInfos(pluginList: Map<string, string>) {
|
||||
|
||||
try {
|
||||
pluginInfo = require(pluginPath).plugin;
|
||||
pluginPackage = require(path.posix.join(pluginPath, "package.json"));
|
||||
pluginPackage = require(packagePath);
|
||||
} catch (err: any) {
|
||||
if (err.code === "InstallationError") {
|
||||
throw err;
|
||||
@@ -69,12 +73,8 @@ export async function loadPluginInfos(pluginList: Map<string, string>) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pluginInfo.webStaticPath = path.join(
|
||||
path.dirname(
|
||||
require.resolve(path.posix.join(pluginPath, "package.json"))
|
||||
),
|
||||
"dist", "web", "static",
|
||||
);
|
||||
pluginInfo.webStaticPath = path.join(path.dirname(packagePath), "dist", "web", "static");
|
||||
pluginInfo.packagePath = packagePath;
|
||||
pluginInfo.requirePath = pluginPath;
|
||||
pluginInfo.version = pluginPackage.version;
|
||||
pluginInfo.npmPackage = !pluginPackage.private && pluginPath === pluginPackage.name ? pluginPath : undefined;
|
||||
|
||||
Reference in new issue
Block a user