@@ -2,9 +2,10 @@ import * as core from '@actions/core'
22import { context , getOctokit } from '@actions/github'
33import * as glob from '@actions/glob'
44import * as io from '@actions/io'
5+ import * as path from 'path'
56import { callAsyncFunction } from './async-function'
67
7- declare const __non_webpack_require__ : typeof require
8+ declare const __non_webpack_require__ : NodeRequire
89
910process . on ( 'unhandledRejection' , handleError )
1011main ( ) . catch ( handleError )
@@ -31,7 +32,14 @@ async function main(): Promise<void> {
3132
3233 // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
3334 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+ } ,
3543 script
3644 )
3745
@@ -54,6 +62,19 @@ async function main(): Promise<void> {
5462 core . setOutput ( 'result' , output )
5563}
5664
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+
5778// eslint-disable-next-line @typescript-eslint/no-explicit-any
5879function handleError ( err : any ) : void {
5980 console . error ( err )
0 commit comments