Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4e5d39

Browse filesBrowse files
committed
Use a proxy to support relative requires
1 parent ddba1b1 commit f4e5d39
Copy full SHA for f4e5d39

File tree

2 files changed

+25
-4
lines changed
Filter options

2 files changed

+25
-4
lines changed

‎src/async-function.ts

Copy file name to clipboardExpand all lines: src/async-function.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from '@actions/core'
2-
import { Context } from '@actions/github/lib/context'
3-
import { GitHub } from '@actions/github/lib/utils'
2+
import {Context} from '@actions/github/lib/context'
3+
import {GitHub} from '@actions/github/lib/utils'
44
import * as glob from '@actions/glob'
55
import * as io from '@actions/io'
66

‎src/main.ts

Copy file name to clipboardExpand all lines: src/main.ts
+23-2Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import * as core from '@actions/core'
22
import {context, getOctokit} from '@actions/github'
33
import * as glob from '@actions/glob'
44
import * as io from '@actions/io'
5+
import * as path from 'path'
56
import {callAsyncFunction} from './async-function'
67

7-
declare const __non_webpack_require__: typeof require
8+
declare const __non_webpack_require__: NodeRequire
89

910
process.on('unhandledRejection', handleError)
1011
main().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
5879
function handleError(err: any): void {
5980
console.error(err)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.