mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: easy require resolve hook
This commit is contained in:
1 parent
06faa233f8
commit
072f165f9e
3 files changed
+6
-2
No files matched your search
@@ -22,6 +22,8 @@ const fs = require('fs-extra');
|
||||
const argv = require('cac')().parse();
|
||||
const child = require('child_process');
|
||||
const esbuild = require('esbuild');
|
||||
const { default: hook } = require('require-resolve-hook');
|
||||
const { bypass } = hook(/^hydrooj/, (id) => bypass(() => require.resolve(id)));
|
||||
|
||||
const exec = (...args) => {
|
||||
console.log('Executing: ', args[0], args[1].join(' '));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "3.2.40",
|
||||
"version": "3.2.41",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
@@ -41,6 +41,7 @@
|
||||
"notp": "^2.0.3",
|
||||
"p-queue": "^7.1.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"require-resolve-hook": "^1.1.0",
|
||||
"serialize-javascript": "^6.0.0",
|
||||
"sockjs": "^0.3.24",
|
||||
"source-map-support": "^0.5.21",
|
||||
|
||||
@@ -40,7 +40,8 @@ export function registerResolver(
|
||||
const wrappedFunc = async (arg, ctx, info) => {
|
||||
const res = await func(arg, ctx, info);
|
||||
if (typeof res !== 'object') return res;
|
||||
if (handlers[value]) Object.assign(res, handlers[value]);
|
||||
const node = value.includes('!') ? value.split('!')[0] : value;
|
||||
if (handlers[node]) Object.assign(res, handlers[node]);
|
||||
ctx.parent = res;
|
||||
return res;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user