@kezh/my-custom-js-converter 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/decode/index.js +9 -5
- package/core/util/ast.js +10 -10
- package/package.json +1 -1
package/core/decode/index.js
CHANGED
|
@@ -96,19 +96,23 @@ function decoding$0(inPath, outPath, config, settingDir, libDirs, conflicts) {
|
|
|
96
96
|
// 有补充则先写回 mod.map,确保后续 importMods/deleteModMethods 能用到
|
|
97
97
|
mapContext.writeToLocalDir(settingDir);
|
|
98
98
|
}
|
|
99
|
-
(0, ast_1.importMods)(path_1.default.dirname(outPath), srcAst, mapContext, config.encode.useAlias);
|
|
100
99
|
// 稽核内联工具方法体是否与源文件一致(忽略注释)
|
|
100
|
+
// 必须在 importMods/deleteModMethods 之前:若存在任一不一致方法,
|
|
101
|
+
// 则 decoded.js 原样包裹 coded.js(不 require、不删除内联方法、不还原调用)
|
|
101
102
|
const mismatches = (0, ast_1.auditModMethods)(srcAst, mapContext);
|
|
102
|
-
const skipMethodKeys = new Set();
|
|
103
103
|
if (mismatches.length) {
|
|
104
|
-
logger.warn(`检测到 ${mismatches.length}
|
|
104
|
+
logger.warn(`检测到 ${mismatches.length} 个内联工具方法与源文件不一致,decoded.js 将原样保留 coded.js(不还原、不 require):`);
|
|
105
105
|
mismatches.forEach((m) => {
|
|
106
106
|
logger.warn(` - ${m.methodKey}(源文件: ${m.srcPath})`);
|
|
107
|
-
skipMethodKeys.add(m.methodKey);
|
|
108
107
|
});
|
|
109
108
|
logger.warn(`请检查上述方法,确认 coded.js 与源文件差异后手动处理或重新 encode。`);
|
|
109
|
+
// 跳过 importMods 和 deleteModMethods:保留 coded.js 原样形态
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// 全部一致:正常还原(生成 require、删除内联方法、还原调用)
|
|
113
|
+
(0, ast_1.importMods)(path_1.default.dirname(outPath), srcAst, mapContext, config.encode.useAlias);
|
|
114
|
+
(0, ast_1.deleteModMethods)(srcAst, mapContext);
|
|
110
115
|
}
|
|
111
|
-
(0, ast_1.deleteModMethods)(srcAst, mapContext, skipMethodKeys);
|
|
112
116
|
// 从onFormReady方法中提取版本日志并移除
|
|
113
117
|
extractAndRemoveVersionLog(srcAst, settingDir);
|
|
114
118
|
let { code: dist } = (0, generator_1.default)(srcAst, { compact: true });
|
package/core/util/ast.js
CHANGED
|
@@ -362,8 +362,8 @@ function getDependentMethodNames(srcAst, methodNames, depNames) {
|
|
|
362
362
|
* @param mapContext
|
|
363
363
|
* @param useAlias - 是否使用 @ 别名路径
|
|
364
364
|
*/
|
|
365
|
-
function importMods(outDir, srcAst, mapContext, useAlias = false) {
|
|
366
|
-
const depNames = mapContext.getDependencyNameByMod("self");
|
|
365
|
+
function importMods(outDir, srcAst, mapContext, useAlias = false, skipDepNames = new Set()) {
|
|
366
|
+
const depNames = mapContext.getDependencyNameByMod("self").filter((name) => !skipDepNames.has(name));
|
|
367
367
|
const rootDir = (0, parent_path_1.getParentRootDir)() || config_1.config.baseDir;
|
|
368
368
|
const importMods = depNames.map((name) => {
|
|
369
369
|
const srcPath = mapContext.getAbsoluteSrcPathByMod(name);
|
|
@@ -402,11 +402,11 @@ function importMods(outDir, srcAst, mapContext, useAlias = false) {
|
|
|
402
402
|
* 去除第三方模块方法
|
|
403
403
|
* @param srcAst - 源码AST
|
|
404
404
|
* @param mapContext
|
|
405
|
-
* @param
|
|
406
|
-
*
|
|
407
|
-
*
|
|
405
|
+
* @param skipDepNames - 需要跳过(不删除定义、不还原调用、不生成 require)的依赖名集合。
|
|
406
|
+
* 用于稽核出方法体不一致的依赖:该依赖任一方法与源文件不一致时,共所有方法
|
|
407
|
+
* 都保留内联形态(包括一致方法),实现 decoded.js 自包含,不 require 源文件。
|
|
408
408
|
*/
|
|
409
|
-
function deleteModMethods(srcAst, mapContext,
|
|
409
|
+
function deleteModMethods(srcAst, mapContext, skipDepNames = new Set()) {
|
|
410
410
|
const deps = new Set();
|
|
411
411
|
mapContext
|
|
412
412
|
.getModNames()
|
|
@@ -423,8 +423,8 @@ function deleteModMethods(srcAst, mapContext, skipMethodKeys = new Set()) {
|
|
|
423
423
|
return;
|
|
424
424
|
}
|
|
425
425
|
const depName = split.length ? split[split.length - 1] : "";
|
|
426
|
-
//
|
|
427
|
-
if (
|
|
426
|
+
// 稽核不一致的依赖:保留其所有内联定义,不删除
|
|
427
|
+
if (skipDepNames.has(depName)) {
|
|
428
428
|
return;
|
|
429
429
|
}
|
|
430
430
|
deps.has(depName) && path.remove();
|
|
@@ -442,8 +442,8 @@ function deleteModMethods(srcAst, mapContext, skipMethodKeys = new Set()) {
|
|
|
442
442
|
}
|
|
443
443
|
const depName = split[split.length - 1];
|
|
444
444
|
if (deps.has(depName)) {
|
|
445
|
-
//
|
|
446
|
-
if (
|
|
445
|
+
// 稽核不一致的依赖:保留 this.method__dep 调用形态,不还原
|
|
446
|
+
if (skipDepNames.has(depName)) {
|
|
447
447
|
return;
|
|
448
448
|
}
|
|
449
449
|
path.node.property.name = methodName.replace(`__${depName}`, "");
|