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

Support installed npm modules and relative require #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use a proxy to support relative requires
  • Loading branch information
jclem committed Apr 21, 2021
commit f4e5d39c2ae1bcb0726aed39da38b49d54fd9661
4 changes: 2 additions & 2 deletions 4 src/async-function.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core'
import { Context } from '@actions/github/lib/context'
import { GitHub } from '@actions/github/lib/utils'
import {Context} from '@actions/github/lib/context'
import {GitHub} from '@actions/github/lib/utils'
import * as glob from '@actions/glob'
import * as io from '@actions/io'

Expand Down
25 changes: 23 additions & 2 deletions 25 src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import * as core from '@actions/core'
import {context, getOctokit} from '@actions/github'
import * as glob from '@actions/glob'
import * as io from '@actions/io'
import * as path from 'path'
import {callAsyncFunction} from './async-function'

declare const __non_webpack_require__: typeof require
declare const __non_webpack_require__: NodeRequire

process.on('unhandledRejection', handleError)
main().catch(handleError)
Expand All @@ -31,7 +32,14 @@ async function main(): Promise<void> {

// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
const result = await callAsyncFunction(
{require: __non_webpack_require__, github, context, core, glob, io},
{
require: wrapRequire,
github,
context,
core,
glob,
io
},
script
)

Expand All @@ -54,6 +62,19 @@ async function main(): Promise<void> {
core.setOutput('result', output)
}

const wrapRequire = new Proxy(__non_webpack_require__, {
apply: (target, thisArg, [moduleID]) => {
if (moduleID.startsWith('.')) {
moduleID = path.join(process.cwd(), moduleID)
}
return target.apply(thisArg, [moduleID])
},

get: (target, prop, receiver) => {
Reflect.get(target, prop, receiver)
}
})

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function handleError(err: any): void {
console.error(err)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.