@kezh/my-custom-js-converter 1.8.0 → 1.9.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 +10 -5
- package/core/util/ast.js +10 -10
- package/package.json +1 -1
package/core/decode/index.js
CHANGED
|
@@ -96,19 +96,24 @@ 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 之前:有不一致方法的依赖不生成 require(方案B:自包含)
|
|
101
101
|
const mismatches = (0, ast_1.auditModMethods)(srcAst, mapContext);
|
|
102
|
-
const
|
|
102
|
+
const skipDepNames = new Set();
|
|
103
103
|
if (mismatches.length) {
|
|
104
|
-
|
|
104
|
+
// 推导出有不一致方法的依赖名集合:该依赖所有方法都保留内联,不 require
|
|
105
|
+
mismatches.forEach((m) => skipDepNames.add(m.modName));
|
|
106
|
+
logger.warn(`检测到 ${mismatches.length} 个内联工具方法与源文件不一致,涉及依赖: ${[
|
|
107
|
+
...skipDepNames
|
|
108
|
+
].join(", ")}`);
|
|
109
|
+
logger.warn(`以下依赖的所有方法将保留内联形态不还原(不生成 require,decoded.js 自包含):`);
|
|
105
110
|
mismatches.forEach((m) => {
|
|
106
111
|
logger.warn(` - ${m.methodKey}(源文件: ${m.srcPath})`);
|
|
107
|
-
skipMethodKeys.add(m.methodKey);
|
|
108
112
|
});
|
|
109
113
|
logger.warn(`请检查上述方法,确认 coded.js 与源文件差异后手动处理或重新 encode。`);
|
|
110
114
|
}
|
|
111
|
-
(0, ast_1.
|
|
115
|
+
(0, ast_1.importMods)(path_1.default.dirname(outPath), srcAst, mapContext, config.encode.useAlias, skipDepNames);
|
|
116
|
+
(0, ast_1.deleteModMethods)(srcAst, mapContext, skipDepNames);
|
|
112
117
|
// 从onFormReady方法中提取版本日志并移除
|
|
113
118
|
extractAndRemoveVersionLog(srcAst, settingDir);
|
|
114
119
|
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}`, "");
|