Skip to content

Commit 75e3a5b

Browse files
committed
Move wrapRequire to its own module
1 parent e853490 commit 75e3a5b

File tree

3 files changed

+116
-112
lines changed

3 files changed

+116
-112
lines changed

dist/index.js

Lines changed: 99 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports =
4040
/******/ // the startup function
4141
/******/ function startup() {
4242
/******/ // Load entry module and return exports
43-
/******/ return __webpack_require__(720);
43+
/******/ return __webpack_require__(272);
4444
/******/ };
4545
/******/ // initialize runtime
4646
/******/ runtime(__webpack_require__);
@@ -2424,6 +2424,104 @@ exports.request = request;
24242424
//# sourceMappingURL=index.js.map
24252425

24262426

2427+
/***/ }),
2428+
2429+
/***/ 272:
2430+
/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) {
2431+
2432+
"use strict";
2433+
__webpack_require__.r(__webpack_exports__);
2434+
2435+
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
2436+
var core = __webpack_require__(186);
2437+
2438+
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
2439+
var lib_github = __webpack_require__(438);
2440+
2441+
// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js
2442+
var glob = __webpack_require__(90);
2443+
2444+
// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js
2445+
var io = __webpack_require__(436);
2446+
2447+
// CONCATENATED MODULE: ./src/async-function.ts
2448+
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor;
2449+
function callAsyncFunction(args, source) {
2450+
const fn = new AsyncFunction(...Object.keys(args), source);
2451+
return fn(...Object.values(args));
2452+
}
2453+
2454+
// EXTERNAL MODULE: external "path"
2455+
var external_path_ = __webpack_require__(622);
2456+
2457+
// CONCATENATED MODULE: ./src/wrap-require.ts
2458+
2459+
const wrapRequire = new Proxy(require, {
2460+
apply: (target, thisArg, [moduleID]) => {
2461+
if (moduleID.startsWith('.')) {
2462+
moduleID = Object(external_path_.join)(process.cwd(), moduleID);
2463+
}
2464+
return target.apply(thisArg, [moduleID]);
2465+
},
2466+
get: (target, prop, receiver) => {
2467+
Reflect.get(target, prop, receiver);
2468+
}
2469+
});
2470+
2471+
// CONCATENATED MODULE: ./src/main.ts
2472+
2473+
2474+
2475+
2476+
2477+
2478+
process.on('unhandledRejection', handleError);
2479+
main().catch(handleError);
2480+
async function main() {
2481+
const token = Object(core.getInput)('github-token', { required: true });
2482+
const debug = Object(core.getInput)('debug');
2483+
const userAgent = Object(core.getInput)('user-agent');
2484+
const previews = Object(core.getInput)('previews');
2485+
const opts = {};
2486+
if (debug === 'true')
2487+
opts.log = console;
2488+
if (userAgent != null)
2489+
opts.userAgent = userAgent;
2490+
if (previews != null)
2491+
opts.previews = previews.split(',');
2492+
const github = Object(lib_github.getOctokit)(token, opts);
2493+
const script = Object(core.getInput)('script', { required: true });
2494+
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
2495+
const result = await callAsyncFunction({
2496+
require: wrapRequire,
2497+
github,
2498+
context: lib_github.context,
2499+
core: core,
2500+
glob: glob,
2501+
io: io
2502+
}, script);
2503+
let encoding = Object(core.getInput)('result-encoding');
2504+
encoding = encoding ? encoding : 'json';
2505+
let output;
2506+
switch (encoding) {
2507+
case 'json':
2508+
output = JSON.stringify(result);
2509+
break;
2510+
case 'string':
2511+
output = String(result);
2512+
break;
2513+
default:
2514+
throw new Error('"result-encoding" must be either "string" or "json"');
2515+
}
2516+
Object(core.setOutput)('result', output);
2517+
}
2518+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2519+
function handleError(err) {
2520+
console.error(err);
2521+
Object(core.setFailed)(`Unhandled error: ${err}`);
2522+
}
2523+
2524+
24272525
/***/ }),
24282526

24292527
/***/ 278:
@@ -6094,101 +6192,6 @@ function issueCommand(command, message) {
60946192
exports.issueCommand = issueCommand;
60956193
//# sourceMappingURL=file-command.js.map
60966194

6097-
/***/ }),
6098-
6099-
/***/ 720:
6100-
/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) {
6101-
6102-
"use strict";
6103-
__webpack_require__.r(__webpack_exports__);
6104-
6105-
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
6106-
var core = __webpack_require__(186);
6107-
6108-
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
6109-
var lib_github = __webpack_require__(438);
6110-
6111-
// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js
6112-
var glob = __webpack_require__(90);
6113-
6114-
// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js
6115-
var io = __webpack_require__(436);
6116-
6117-
// EXTERNAL MODULE: external "path"
6118-
var external_path_ = __webpack_require__(622);
6119-
6120-
// CONCATENATED MODULE: ./src/async-function.ts
6121-
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor;
6122-
function callAsyncFunction(args, source) {
6123-
const fn = new AsyncFunction(...Object.keys(args), source);
6124-
return fn(...Object.values(args));
6125-
}
6126-
6127-
// CONCATENATED MODULE: ./src/main.ts
6128-
6129-
6130-
6131-
6132-
6133-
6134-
process.on('unhandledRejection', handleError);
6135-
main().catch(handleError);
6136-
async function main() {
6137-
const token = Object(core.getInput)('github-token', { required: true });
6138-
const debug = Object(core.getInput)('debug');
6139-
const userAgent = Object(core.getInput)('user-agent');
6140-
const previews = Object(core.getInput)('previews');
6141-
const opts = {};
6142-
if (debug === 'true')
6143-
opts.log = console;
6144-
if (userAgent != null)
6145-
opts.userAgent = userAgent;
6146-
if (previews != null)
6147-
opts.previews = previews.split(',');
6148-
const github = Object(lib_github.getOctokit)(token, opts);
6149-
const script = Object(core.getInput)('script', { required: true });
6150-
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
6151-
const result = await callAsyncFunction({
6152-
require: wrapRequire,
6153-
github,
6154-
context: lib_github.context,
6155-
core: core,
6156-
glob: glob,
6157-
io: io
6158-
}, script);
6159-
let encoding = Object(core.getInput)('result-encoding');
6160-
encoding = encoding ? encoding : 'json';
6161-
let output;
6162-
switch (encoding) {
6163-
case 'json':
6164-
output = JSON.stringify(result);
6165-
break;
6166-
case 'string':
6167-
output = String(result);
6168-
break;
6169-
default:
6170-
throw new Error('"result-encoding" must be either "string" or "json"');
6171-
}
6172-
Object(core.setOutput)('result', output);
6173-
}
6174-
const wrapRequire = new Proxy(require, {
6175-
apply: (target, thisArg, [moduleID]) => {
6176-
if (moduleID.startsWith('.')) {
6177-
moduleID = Object(external_path_.join)(process.cwd(), moduleID);
6178-
}
6179-
return target.apply(thisArg, [moduleID]);
6180-
},
6181-
get: (target, prop, receiver) => {
6182-
Reflect.get(target, prop, receiver);
6183-
}
6184-
});
6185-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6186-
function handleError(err) {
6187-
console.error(err);
6188-
Object(core.setFailed)(`Unhandled error: ${err}`);
6189-
}
6190-
6191-
61926195
/***/ }),
61936196

61946197
/***/ 747:

src/main.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ 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'
65
import {callAsyncFunction} from './async-function'
7-
8-
declare const __non_webpack_require__: NodeRequire
6+
import {wrapRequire} from './wrap-require'
97

108
process.on('unhandledRejection', handleError)
119
main().catch(handleError)
@@ -62,19 +60,6 @@ async function main(): Promise<void> {
6260
core.setOutput('result', output)
6361
}
6462

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-
7863
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7964
function handleError(err: any): void {
8065
console.error(err)

src/wrap-require.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as path from 'path'
2+
3+
declare const __non_webpack_require__: NodeRequire
4+
5+
export const wrapRequire = new Proxy(__non_webpack_require__, {
6+
apply: (target, thisArg, [moduleID]) => {
7+
if (moduleID.startsWith('.')) {
8+
moduleID = path.join(process.cwd(), moduleID)
9+
}
10+
return target.apply(thisArg, [moduleID])
11+
},
12+
13+
get: (target, prop, receiver) => {
14+
Reflect.get(target, prop, receiver)
15+
}
16+
})

0 commit comments

Comments
 (0)