mirror of
https://github.com/actions/github-script.git
synced 2025-12-08 16:16:21 +00:00
Move wrapRequire to its own module
This commit is contained in:
195
dist/index.js
vendored
195
dist/index.js
vendored
@@ -40,7 +40,7 @@ module.exports =
|
||||
/******/ // the startup function
|
||||
/******/ function startup() {
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(720);
|
||||
/******/ return __webpack_require__(272);
|
||||
/******/ };
|
||||
/******/ // initialize runtime
|
||||
/******/ runtime(__webpack_require__);
|
||||
@@ -2424,6 +2424,104 @@ exports.request = request;
|
||||
//# sourceMappingURL=index.js.map
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 272:
|
||||
/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
|
||||
var core = __webpack_require__(186);
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
|
||||
var lib_github = __webpack_require__(438);
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js
|
||||
var glob = __webpack_require__(90);
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js
|
||||
var io = __webpack_require__(436);
|
||||
|
||||
// CONCATENATED MODULE: ./src/async-function.ts
|
||||
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor;
|
||||
function callAsyncFunction(args, source) {
|
||||
const fn = new AsyncFunction(...Object.keys(args), source);
|
||||
return fn(...Object.values(args));
|
||||
}
|
||||
|
||||
// EXTERNAL MODULE: external "path"
|
||||
var external_path_ = __webpack_require__(622);
|
||||
|
||||
// CONCATENATED MODULE: ./src/wrap-require.ts
|
||||
|
||||
const wrapRequire = new Proxy(require, {
|
||||
apply: (target, thisArg, [moduleID]) => {
|
||||
if (moduleID.startsWith('.')) {
|
||||
moduleID = Object(external_path_.join)(process.cwd(), moduleID);
|
||||
}
|
||||
return target.apply(thisArg, [moduleID]);
|
||||
},
|
||||
get: (target, prop, receiver) => {
|
||||
Reflect.get(target, prop, receiver);
|
||||
}
|
||||
});
|
||||
|
||||
// CONCATENATED MODULE: ./src/main.ts
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
process.on('unhandledRejection', handleError);
|
||||
main().catch(handleError);
|
||||
async function main() {
|
||||
const token = Object(core.getInput)('github-token', { required: true });
|
||||
const debug = Object(core.getInput)('debug');
|
||||
const userAgent = Object(core.getInput)('user-agent');
|
||||
const previews = Object(core.getInput)('previews');
|
||||
const opts = {};
|
||||
if (debug === 'true')
|
||||
opts.log = console;
|
||||
if (userAgent != null)
|
||||
opts.userAgent = userAgent;
|
||||
if (previews != null)
|
||||
opts.previews = previews.split(',');
|
||||
const github = Object(lib_github.getOctokit)(token, opts);
|
||||
const script = Object(core.getInput)('script', { required: true });
|
||||
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
||||
const result = await callAsyncFunction({
|
||||
require: wrapRequire,
|
||||
github,
|
||||
context: lib_github.context,
|
||||
core: core,
|
||||
glob: glob,
|
||||
io: io
|
||||
}, script);
|
||||
let encoding = Object(core.getInput)('result-encoding');
|
||||
encoding = encoding ? encoding : 'json';
|
||||
let output;
|
||||
switch (encoding) {
|
||||
case 'json':
|
||||
output = JSON.stringify(result);
|
||||
break;
|
||||
case 'string':
|
||||
output = String(result);
|
||||
break;
|
||||
default:
|
||||
throw new Error('"result-encoding" must be either "string" or "json"');
|
||||
}
|
||||
Object(core.setOutput)('result', output);
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function handleError(err) {
|
||||
console.error(err);
|
||||
Object(core.setFailed)(`Unhandled error: ${err}`);
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 278:
|
||||
@@ -6094,101 +6192,6 @@ function issueCommand(command, message) {
|
||||
exports.issueCommand = issueCommand;
|
||||
//# sourceMappingURL=file-command.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 720:
|
||||
/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
|
||||
var core = __webpack_require__(186);
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
|
||||
var lib_github = __webpack_require__(438);
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js
|
||||
var glob = __webpack_require__(90);
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js
|
||||
var io = __webpack_require__(436);
|
||||
|
||||
// EXTERNAL MODULE: external "path"
|
||||
var external_path_ = __webpack_require__(622);
|
||||
|
||||
// CONCATENATED MODULE: ./src/async-function.ts
|
||||
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor;
|
||||
function callAsyncFunction(args, source) {
|
||||
const fn = new AsyncFunction(...Object.keys(args), source);
|
||||
return fn(...Object.values(args));
|
||||
}
|
||||
|
||||
// CONCATENATED MODULE: ./src/main.ts
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
process.on('unhandledRejection', handleError);
|
||||
main().catch(handleError);
|
||||
async function main() {
|
||||
const token = Object(core.getInput)('github-token', { required: true });
|
||||
const debug = Object(core.getInput)('debug');
|
||||
const userAgent = Object(core.getInput)('user-agent');
|
||||
const previews = Object(core.getInput)('previews');
|
||||
const opts = {};
|
||||
if (debug === 'true')
|
||||
opts.log = console;
|
||||
if (userAgent != null)
|
||||
opts.userAgent = userAgent;
|
||||
if (previews != null)
|
||||
opts.previews = previews.split(',');
|
||||
const github = Object(lib_github.getOctokit)(token, opts);
|
||||
const script = Object(core.getInput)('script', { required: true });
|
||||
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
||||
const result = await callAsyncFunction({
|
||||
require: wrapRequire,
|
||||
github,
|
||||
context: lib_github.context,
|
||||
core: core,
|
||||
glob: glob,
|
||||
io: io
|
||||
}, script);
|
||||
let encoding = Object(core.getInput)('result-encoding');
|
||||
encoding = encoding ? encoding : 'json';
|
||||
let output;
|
||||
switch (encoding) {
|
||||
case 'json':
|
||||
output = JSON.stringify(result);
|
||||
break;
|
||||
case 'string':
|
||||
output = String(result);
|
||||
break;
|
||||
default:
|
||||
throw new Error('"result-encoding" must be either "string" or "json"');
|
||||
}
|
||||
Object(core.setOutput)('result', output);
|
||||
}
|
||||
const wrapRequire = new Proxy(require, {
|
||||
apply: (target, thisArg, [moduleID]) => {
|
||||
if (moduleID.startsWith('.')) {
|
||||
moduleID = Object(external_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) {
|
||||
console.error(err);
|
||||
Object(core.setFailed)(`Unhandled error: ${err}`);
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 747:
|
||||
|
||||
17
src/main.ts
17
src/main.ts
@@ -2,10 +2,8 @@ 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__: NodeRequire
|
||||
import {wrapRequire} from './wrap-require'
|
||||
|
||||
process.on('unhandledRejection', handleError)
|
||||
main().catch(handleError)
|
||||
@@ -62,19 +60,6 @@ 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)
|
||||
|
||||
16
src/wrap-require.ts
Normal file
16
src/wrap-require.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import * as path from 'path'
|
||||
|
||||
declare const __non_webpack_require__: NodeRequire
|
||||
|
||||
export 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)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user