diff --git a/src/plugins/discovery.ts b/src/plugins/discovery.ts index 47a09c85fef..3e7b7dd7cdc 100644 --- a/src/plugins/discovery.ts +++ b/src/plugins/discovery.ts @@ -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: {