From ca4c3b1dd14b853cbe26a887197af2c6a2de64ba Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 22 Oct 2024 11:33:22 +0200 Subject: [PATCH] fix(github): correctly convert `file:` URL to path --- packages/github/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/github/index.js b/packages/github/index.js index 69158da..f8a6161 100644 --- a/packages/github/index.js +++ b/packages/github/index.js @@ -1,6 +1,7 @@ 'use strict'; const path = require('node:path'); +const { fileURLToPath } = require("node:url"); const util = require('node:util'); const { EOL } = require('node:os'); const core = require('@actions/core'); @@ -12,11 +13,14 @@ const stack = new StackUtils({ cwd: WORKSPACE, internals: StackUtils.nodeInterna const isFile = (name) => name?.startsWith(WORKSPACE); -const getRelativeFilePath = (name) => (isFile(name) ? path.relative(WORKSPACE, require.resolve(name) ?? '') : null); +const getRelativeFilePath = (name) => (isFile(name) ? path.relative(WORKSPACE, name) : null); function getFilePath(fileName) { if (fileName.startsWith('file://')) { - return getRelativeFilePath(new URL(fileName).pathname); + return getRelativeFilePath(fileURLToPath(fileName)); + } + if (!path.isAbsolute(fileName)) { + return getRelativeFilePath(path.resolve(fileName) ?? ""); } return getRelativeFilePath(fileName); }