Skip to content

Commit 4bb7b7d

Browse files
author
Taois
committed
feat: 优化Bundle
1 parent bdb4fb9 commit 4bb7b7d

File tree

6 files changed

+72
-7
lines changed

6 files changed

+72
-7
lines changed

drpy-node-bundle/libs/localDsCore.bundled.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379411,8 +379411,8 @@ var require_tunnel = /* @__PURE__ */ __commonJSMin(((exports, module) => {
379411379411
module.exports = require_tunnel$1();
379412379412
}));
379413379413
//#endregion
379414-
//#region ../libs_drpy/jsonpathplus.min.js
379415-
var require_jsonpathplus_min = /* @__PURE__ */ __commonJSMin(((exports, module) => {
379414+
//#region shim/original-jsonpath.js
379415+
var require_original_jsonpath = /* @__PURE__ */ __commonJSMin(((exports, module) => {
379416379416
(function(e, t) {
379417379417
"object" == typeof exports && "undefined" != typeof module ? t(exports) : "function" == typeof define && define.amd ? define(["exports"], t) : t((e = "undefined" != typeof globalThis ? globalThis : e || self).JSONPath = {});
379418379418
})(exports, function(e) {
@@ -380658,13 +380658,21 @@ var require_jsonpathplus_min = /* @__PURE__ */ __commonJSMin(((exports, module)
380658380658
});
380659380659
}));
380660380660
//#endregion
380661-
//#region ../libs_drpy/htmlParser.js
380661+
//#region shim/jsonpath-shim.js
380662380662
var import_tunnel = /* @__PURE__ */ __toESM(require_tunnel(), 1);
380663+
var import_original_jsonpath = /* @__PURE__ */ __toESM(require_original_jsonpath(), 1);
380664+
const JP = import_original_jsonpath.JSONPath || import_original_jsonpath.default?.JSONPath || import_original_jsonpath.default;
380665+
if (typeof globalThis !== "undefined") {
380666+
if (!globalThis.JSONPath) globalThis.JSONPath = {};
380667+
if (typeof JP === "function") globalThis.JSONPath.JSONPath = JP;
380668+
else if (JP && JP.JSONPath) globalThis.JSONPath = JP;
380669+
}
380670+
//#endregion
380671+
//#region ../libs_drpy/htmlParser.js
380663380672
/**
380664380673
* HTML解析器工具
380665380674
* 基于cheerio提供HTML和JSON解析功能,支持类似海阔视界的解析语法
380666380675
*/
380667-
var import_jsonpathplus_min = require_jsonpathplus_min();
380668380676
/**
380669380677
* JSONPath查询工具
380670380678
*/

drpy-node-bundle/localDsCoreTest.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// import * as localtDsCore from './localDsCore.js';
22
import * as localtDsCore from './libs/localDsCore.bundled.js';
3+
34
const start = performance.now();
45

56
console.log(getEngine)
@@ -28,10 +29,13 @@ const f = await getEngine('央视大全[官]', {
2829
do: 'ds',
2930
proxy: 1,
3031
url: '',
31-
}, {requestHost: 'http://127.0.0.1:5757',proxyPath:'https://dh5wswx02.v.cntv.cn/asp/h5e/hls/2000/0303000a/3/default/b90af013c16e44de9e4f1f56dab91f63/1.ts'})
32+
}, {
33+
requestHost: 'http://127.0.0.1:5757',
34+
proxyPath: 'https://dh5wswx02.v.cntv.cn/asp/h5e/hls/2000/0303000a/3/default/b90af013c16e44de9e4f1f56dab91f63/1.ts'
35+
})
3236

3337
const [statuCode, contentType, buffer, headers] = f;
3438
console.log('resutl: header:', headers, 'buffer length:', buffer.length);
3539

36-
const g = await getEngine('360影视[官]', {do: 'ds', ac: 'list', t: '2'})
40+
const g = await getEngine('360影视[官]', {do: 'ds', ac: 'list', t: '2', ext: 'eyLnsbvlnosiOiLoqIDmg4UifQ=='})
3741
console.log(g)

drpy-node-bundle/rolldown.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ const require = (moduleName) => {
4545
conditionNames: ['node', 'import'],
4646
alias: {
4747
'pako': path.resolve(__dirname, '../libs_drpy/pako.min.js'),
48-
'puppeteer': path.resolve(__dirname, 'puppeteer-mock.js')
48+
'puppeteer': path.resolve(__dirname, 'puppeteer-mock.js'),
49+
[path.resolve(__dirname, '../libs_drpy/jsonpathplus.min.js')]: path.resolve(__dirname, 'shim/jsonpath-shim.js')
4950
}
5051
},
5152
external: (id) => {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as lib from './original-jsonpath.js';
2+
3+
// 获取对象
4+
// Rolldown/ESM interop 可能会把 export 放在 default 或 namespace
5+
const JP = lib.JSONPath || lib.default?.JSONPath || lib.default;
6+
7+
// 确保全局挂载
8+
if (typeof globalThis !== 'undefined') {
9+
if (!globalThis.JSONPath) {
10+
globalThis.JSONPath = {}; // 初始化容器
11+
}
12+
// min.js 的逻辑是 globalThis.JSONPath.JSONPath = F
13+
// 如果 JP 是 F (构造函数)
14+
if (typeof JP === 'function') {
15+
globalThis.JSONPath.JSONPath = JP;
16+
} else if (JP && JP.JSONPath) {
17+
// 如果 JP 已经是 { JSONPath: F }
18+
globalThis.JSONPath = JP;
19+
}
20+
21+
// 如果 htmlParser.js 直接使用 JSONPath 变量而不是 globalThis.JSONPath
22+
// 在 Bundle 环境下这是不可能的,除非它是全局变量。
23+
// 但是在 Node 环境下,全局变量可以直接访问。
24+
// 我们这里只能保证 globalThis.JSONPath 存在。
25+
}
26+
27+
// 导出,虽然 htmlParser.js 没用到,但为了模块完整性
28+
export { JP as JSONPath };
29+
export default JP;

drpy-node-bundle/shim/original-jsonpath.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs_drpy/jsonpath-adapter.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as jpNamespace from './jsonpathplus.min.js';
2+
3+
let jp;
4+
5+
// Try to find JSONPath in the imported namespace (ESM/Rolldown handling of UMD)
6+
if (jpNamespace && jpNamespace.JSONPath) {
7+
jp = jpNamespace.JSONPath;
8+
} else if (jpNamespace && jpNamespace.default && jpNamespace.default.JSONPath) {
9+
jp = jpNamespace.default.JSONPath;
10+
}
11+
12+
// Fallback to globalThis (browser/legacy behavior)
13+
if (!jp && typeof globalThis !== 'undefined' && globalThis.JSONPath) {
14+
if (typeof globalThis.JSONPath.JSONPath === 'function') {
15+
jp = globalThis.JSONPath.JSONPath;
16+
} else if (typeof globalThis.JSONPath === 'function') {
17+
jp = globalThis.JSONPath;
18+
}
19+
}
20+
21+
export const JSONPath = jp;
22+
export default jp;

0 commit comments

Comments
 (0)