Skip to content

Commit

Permalink
Fix import path for win32 platform (#151)
Browse files Browse the repository at this point in the history
This PR fixes an incorrect import path for win32-based systems to ensure
the correct, absolute path is provided to the action import logic.

Closes #123
  • Loading branch information
ncalteen authored Feb 6, 2025
2 parents fda69c9 + aa4943a commit 9d60787
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@github/local-action",
"description": "Local Debugging for GitHub Actions",
"version": "2.6.0",
"version": "2.6.1",
"type": "module",
"author": "Nick Alteen <[email protected]>",
"private": false,
Expand Down
13 changes: 11 additions & 2 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ export async function action(): Promise<void> {
if (dirs.length === 0)
throw new Error('Could not find node_modules directory')

// The entrypoint is OS-specific. On Windows, it has to start with a leading
// slash, then the drive letter, followed by the rest of the path. In both
// cases, the path separators are converted to forward slashes.
/* istanbul ignore next */
const osEntrypoint =
process.platform !== 'win32'
? path.resolve(EnvMeta.entrypoint)
: '/' + path.resolve(EnvMeta.entrypoint.replaceAll(path.sep, '/'))

// Stub the `@actions/toolkit` libraries and run the action. Quibble and
// local-action require a different approach depending on if the called action
// is written in ESM.
Expand Down Expand Up @@ -167,7 +176,7 @@ export async function action(): Promise<void> {
)

// ESM actions need to be imported, not required.
const { run } = await import(path.resolve(EnvMeta.entrypoint))
const { run } = await import(osEntrypoint)

// Check if the required path is a function.
if (typeof run !== 'function')
Expand Down Expand Up @@ -218,7 +227,7 @@ export async function action(): Promise<void> {
)

// CJS actions need to be required, not imported.
const { run } = require(path.resolve(EnvMeta.entrypoint))
const { run } = require(osEntrypoint)

// Check if the required path is a function.
if (typeof run !== 'function')
Expand Down

0 comments on commit 9d60787

Please sign in to comment.