@@ -2,9 +2,10 @@ import * as core from '@actions/core'
2
2
import { context , getOctokit } from '@actions/github'
3
3
import * as glob from '@actions/glob'
4
4
import * as io from '@actions/io'
5
+ import * as path from 'path'
5
6
import { callAsyncFunction } from './async-function'
6
7
7
- declare const __non_webpack_require__ : typeof require
8
+ declare const __non_webpack_require__ : NodeRequire
8
9
9
10
process . on ( 'unhandledRejection' , handleError )
10
11
main ( ) . catch ( handleError )
@@ -31,7 +32,14 @@ async function main(): Promise<void> {
31
32
32
33
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
33
34
const result = await callAsyncFunction (
34
- { require : __non_webpack_require__ , github, context, core, glob, io} ,
35
+ {
36
+ require : wrapRequire ,
37
+ github,
38
+ context,
39
+ core,
40
+ glob,
41
+ io
42
+ } ,
35
43
script
36
44
)
37
45
@@ -54,6 +62,19 @@ async function main(): Promise<void> {
54
62
core . setOutput ( 'result' , output )
55
63
}
56
64
65
+ const wrapRequire = new Proxy ( __non_webpack_require__ , {
66
+ apply : ( target , thisArg , [ moduleID ] ) => {
67
+ if ( moduleID . startsWith ( '.' ) ) {
68
+ moduleID = path . join ( process . cwd ( ) , moduleID )
69
+ }
70
+ return target . apply ( thisArg , [ moduleID ] )
71
+ } ,
72
+
73
+ get : ( target , prop , receiver ) => {
74
+ Reflect . get ( target , prop , receiver )
75
+ }
76
+ } )
77
+
57
78
// eslint-disable-next-line @typescript-eslint/no-explicit-any
58
79
function handleError ( err : any ) : void {
59
80
console . error ( err )
0 commit comments