Add a catch to support requiring installed modules

This commit is contained in:
Jonathan Clem
2021-04-21 16:58:37 -04:00
parent 3ca4cd5a00
commit c1c139b0ab
2 changed files with 40 additions and 4 deletions

36
dist/index.js vendored
View File

@@ -2427,7 +2427,7 @@ exports.request = request;
/***/ }),
/***/ 272:
/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) {
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
@@ -2455,13 +2455,20 @@ function callAsyncFunction(args, source) {
var external_path_ = __webpack_require__(622);
// CONCATENATED MODULE: ./src/wrap-require.ts
/* module decorator */ module = __webpack_require__.hmd(module);
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]);
}
try {
return target.apply(thisArg, [moduleID]);
}
catch (err) {
return target.resolve(moduleID, { paths: [...module.paths, process.cwd()] });
}
return target.apply(thisArg, [moduleID]);
},
get: (target, prop, receiver) => {
Reflect.get(target, prop, receiver);
@@ -2494,7 +2501,7 @@ async function main() {
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
const result = await callAsyncFunction({
require: wrapRequire,
nativeRequire: require,
__original_require__: require,
github,
context: lib_github.context,
core: core,
@@ -8803,5 +8810,28 @@ function regExpEscape (s) {
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/harmony module decorator */
/******/ !function() {
/******/ __webpack_require__.hmd = function(module) {
/******/ module = Object.create(module);
/******/ if (!module.children) module.children = [];
/******/ Object.defineProperty(module, 'loaded', {
/******/ enumerable: true,
/******/ get: function () { return module.l; }
/******/ });
/******/ Object.defineProperty(module, 'id', {
/******/ enumerable: true,
/******/ get: function () { return module.i; }
/******/ });
/******/ Object.defineProperty(module, 'exports', {
/******/ enumerable: true,
/******/ set: function () {
/******/ throw new Error('ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ' + module.id);
/******/ }
/******/ });
/******/ return module;
/******/ };
/******/ }();
/******/
/******/ }
);

View File

@@ -4,8 +4,14 @@ 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])
}
try {
return target.apply(thisArg, [moduleID])
} catch (err) {
return target.resolve(moduleID, {paths: [...module.paths, process.cwd()]})
}
return target.apply(thisArg, [moduleID])
},
get: (target, prop, receiver) => {