@@ -32,7 +32,7 @@ import process$1 from "node:process";
3232import os from "node:os";
3333import tty from "node:tty";
3434import util$1 from "node:util";
35- import { createRequire as createRequire$1 } from "module";
35+ import Module, { createRequire as createRequire$1 } from "module";
3636import { setTimeout as setTimeout$1 } from "timers";
3737import { pipeline } from "stream/promises";
3838import diagnosticsChannel from "diagnostics_channel";
@@ -14367,17 +14367,19 @@ let debounceTimers = /* @__PURE__ */ new Map();
1436714367function startJsonWatcher(ENGINES, jsonDir) {
1436814368 if (process.env.NODE_ENV !== "development") return;
1436914369 try {
14370- watch(jsonDir, { recursive: true }, (eventType, filename) => {
14370+ jsonWatcher = watch(jsonDir, { recursive: true }, (eventType, filename) => {
1437114371 if (filename && filename.endsWith(".json")) {
1437214372 if (debounceTimers.has(filename)) clearTimeout(debounceTimers.get(filename));
1437314373 const timer = setTimeout(() => {
1437414374 console.log(`[HotReload] ${filename} changed, clearing cache...`);
1437514375 ENGINES.drpyS.clearAllCache();
1437614376 debounceTimers.delete(filename);
1437714377 }, 100);
14378+ if (timer.unref) timer.unref();
1437814379 debounceTimers.set(filename, timer);
1437914380 }
1438014381 });
14382+ if (jsonWatcher.unref) jsonWatcher.unref();
1438114383 } catch (error) {
1438214384 console.error("start json file listening failed with error:", error);
1438314385 }
@@ -374920,6 +374922,20 @@ const __dirname$4 = path.dirname(fileURLToPath(import.meta.url));
374920374922const ROOT_DIR = path.resolve(__dirname$4, "../");
374921374923const LIB_ROOT = path.join(ROOT_DIR, "spider/js");
374922374924const customRequire = createRequire$1(import.meta.url);
374925+ /**
374926+ * Patch Module.prototype.require to handle bundled modules in CJS context
374927+ * This allows native CJS modules (like those loaded via require('./lib.js')) to find
374928+ * bundled dependencies (axios, iconv-lite, etc.) which are exposed on globalThis.
374929+ */
374930+ const originalRequire = Module.prototype.require;
374931+ Module.prototype.require = function(id) {
374932+ if (id === "iconv-lite" && globalThis.iconv) return globalThis.iconv;
374933+ if (id === "axios" && globalThis.axios) return globalThis.axios;
374934+ if (id === "cheerio" && globalThis.cheerio) return globalThis.cheerio;
374935+ if (id === "qs" && globalThis.qs) return globalThis.qs;
374936+ if (id === "crypto-js" && globalThis.CryptoJS) return globalThis.CryptoJS;
374937+ return originalRequire.apply(this, arguments);
374938+ };
374923374939const rootRequire = (modulePath) => {
374924374940 if (modulePath === "iconv-lite") return globalThis.iconv;
374925374941 if (modulePath === "axios") return globalThis.axios;
@@ -393934,6 +393950,11 @@ var catvod_default = {
393934393950};
393935393951//#endregion
393936393952//#region localDsCore.js
393953+ const ENGINES = {
393954+ drpyS: drpyS_exports,
393955+ php: php_default,
393956+ catvod: catvod_default
393957+ };
393937393958const __dirname$1 = path.dirname(fileURLToPath(import.meta.url));
393938393959const isBundled = __dirname$1.endsWith("dist") || __dirname$1.endsWith("libs") || __dirname$1.endsWith("dist" + path.sep) || __dirname$1.endsWith("libs" + path.sep);
393939393960const possibleRoots = [
@@ -393962,15 +393983,7 @@ const options = {
393962393983 catDir,
393963393984 catLibDir
393964393985};
393965- /**
393966- * 支持的引擎映射表
393967- * 包含drpyS、php、catvod
393968- */
393969- const ENGINES = {
393970- drpyS: drpyS_exports,
393971- php: php_default,
393972- catvod: catvod_default
393973- };
393986+ startJsonWatcher(ENGINES, jsonDir);
393974393987/**
393975393988* 创建带超时的Promise包装函数
393976393989* 为API操作添加超时控制,防止长时间阻塞
@@ -393987,9 +394000,10 @@ function withTimeout(promise, timeoutMs = null, operation = "API操作", invokeM
393987394000 else defaultTimeout = 20 * 1e3;
393988394001 const actualTimeout = timeoutMs || defaultTimeout;
393989394002 return Promise.race([promise, new Promise((_, reject) => {
393990- setTimeout(() => {
394003+ const timer = setTimeout(() => {
393991394004 reject(/* @__PURE__ */ new Error(`${operation}超时 (${actualTimeout}ms)`));
393992394005 }, actualTimeout);
394006+ if (timer.unref) timer.unref();
393993394007 })]);
393994394008}
393995394009async function getEngine(moduleName, query, inject_env) {
0 commit comments