Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1c139b

Browse files
committed
Add a catch to support requiring installed modules
1 parent 3ca4cd5 commit c1c139b

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

dist/index.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,7 @@ exports.request = request;
24272427
/***/ }),
24282428

24292429
/***/ 272:
2430-
/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) {
2430+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
24312431

24322432
"use strict";
24332433
__webpack_require__.r(__webpack_exports__);
@@ -2455,13 +2455,20 @@ function callAsyncFunction(args, source) {
24552455
var external_path_ = __webpack_require__(622);
24562456

24572457
// CONCATENATED MODULE: ./src/wrap-require.ts
2458+
/* module decorator */ module = __webpack_require__.hmd(module);
24582459

24592460
const wrapRequire = new Proxy(require, {
24602461
apply: (target, thisArg, [moduleID]) => {
24612462
if (moduleID.startsWith('.')) {
24622463
moduleID = Object(external_path_.join)(process.cwd(), moduleID);
2464+
return target.apply(thisArg, [moduleID]);
2465+
}
2466+
try {
2467+
return target.apply(thisArg, [moduleID]);
2468+
}
2469+
catch (err) {
2470+
return target.resolve(moduleID, { paths: [...module.paths, process.cwd()] });
24632471
}
2464-
return target.apply(thisArg, [moduleID]);
24652472
},
24662473
get: (target, prop, receiver) => {
24672474
Reflect.get(target, prop, receiver);
@@ -2494,7 +2501,7 @@ async function main() {
24942501
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
24952502
const result = await callAsyncFunction({
24962503
require: wrapRequire,
2497-
nativeRequire: require,
2504+
__original_require__: require,
24982505
github,
24992506
context: lib_github.context,
25002507
core: core,
@@ -8803,5 +8810,28 @@ function regExpEscape (s) {
88038810
/******/ };
88048811
/******/ }();
88058812
/******/
8813+
/******/ /* webpack/runtime/harmony module decorator */
8814+
/******/ !function() {
8815+
/******/ __webpack_require__.hmd = function(module) {
8816+
/******/ module = Object.create(module);
8817+
/******/ if (!module.children) module.children = [];
8818+
/******/ Object.defineProperty(module, 'loaded', {
8819+
/******/ enumerable: true,
8820+
/******/ get: function () { return module.l; }
8821+
/******/ });
8822+
/******/ Object.defineProperty(module, 'id', {
8823+
/******/ enumerable: true,
8824+
/******/ get: function () { return module.i; }
8825+
/******/ });
8826+
/******/ Object.defineProperty(module, 'exports', {
8827+
/******/ enumerable: true,
8828+
/******/ set: function () {
8829+
/******/ throw new Error('ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ' + module.id);
8830+
/******/ }
8831+
/******/ });
8832+
/******/ return module;
8833+
/******/ };
8834+
/******/ }();
8835+
/******/
88068836
/******/ }
88078837
);

src/wrap-require.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ export const wrapRequire = new Proxy(__non_webpack_require__, {
44
apply: (target, thisArg, [moduleID]) => {
55
if (moduleID.startsWith('.')) {
66
moduleID = path.join(process.cwd(), moduleID)
7+
return target.apply(thisArg, [moduleID])
8+
}
9+
10+
try {
11+
return target.apply(thisArg, [moduleID])
12+
} catch (err) {
13+
return target.resolve(moduleID, {paths: [...module.paths, process.cwd()]})
714
}
8-
return target.apply(thisArg, [moduleID])
915
},
1016

1117
get: (target, prop, receiver) => {

0 commit comments

Comments
 (0)