mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
refactor: dedupe plugin discovery boundary opens
This commit is contained in:
@@ -504,19 +504,9 @@ function resolvePackageEntrySource(params: {
|
||||
const source = path.resolve(params.packageDir, params.entryPath);
|
||||
const rejectHardlinks = params.rejectHardlinks ?? true;
|
||||
const candidates = [source];
|
||||
if (!rejectHardlinks) {
|
||||
const builtCandidate = source.replace(/\.[^.]+$/u, ".js");
|
||||
if (builtCandidate !== source) {
|
||||
candidates.push(builtCandidate);
|
||||
}
|
||||
}
|
||||
|
||||
for (const candidate of new Set(candidates)) {
|
||||
if (!fs.existsSync(candidate)) {
|
||||
continue;
|
||||
}
|
||||
const openCandidate = (absolutePath: string): string | null => {
|
||||
const opened = openBoundaryFileSync({
|
||||
absolutePath: candidate,
|
||||
absolutePath,
|
||||
rootPath: params.packageDir,
|
||||
boundaryLabel: "plugin package directory",
|
||||
rejectHardlinks,
|
||||
@@ -545,38 +535,22 @@ function resolvePackageEntrySource(params: {
|
||||
const safeSource = opened.path;
|
||||
fs.closeSync(opened.fd);
|
||||
return safeSource;
|
||||
};
|
||||
if (!rejectHardlinks) {
|
||||
const builtCandidate = source.replace(/\.[^.]+$/u, ".js");
|
||||
if (builtCandidate !== source) {
|
||||
candidates.push(builtCandidate);
|
||||
}
|
||||
}
|
||||
|
||||
const opened = openBoundaryFileSync({
|
||||
absolutePath: source,
|
||||
rootPath: params.packageDir,
|
||||
boundaryLabel: "plugin package directory",
|
||||
rejectHardlinks,
|
||||
});
|
||||
if (!opened.ok) {
|
||||
return matchBoundaryFileOpenFailure(opened, {
|
||||
path: () => null,
|
||||
io: () => {
|
||||
params.diagnostics.push({
|
||||
level: "warn",
|
||||
message: `extension entry unreadable (I/O error): ${params.entryPath}`,
|
||||
source: params.sourceLabel,
|
||||
});
|
||||
return null;
|
||||
},
|
||||
fallback: () => {
|
||||
params.diagnostics.push({
|
||||
level: "error",
|
||||
message: `extension entry escapes package directory: ${params.entryPath}`,
|
||||
source: params.sourceLabel,
|
||||
});
|
||||
return null;
|
||||
},
|
||||
});
|
||||
for (const candidate of new Set(candidates)) {
|
||||
if (!fs.existsSync(candidate)) {
|
||||
continue;
|
||||
}
|
||||
return openCandidate(candidate);
|
||||
}
|
||||
const safeSource = opened.path;
|
||||
fs.closeSync(opened.fd);
|
||||
return safeSource;
|
||||
|
||||
return openCandidate(source);
|
||||
}
|
||||
|
||||
function discoverInDirectory(params: {
|
||||
|
||||
Reference in New Issue
Block a user