@kezh/my-custom-js-converter 1.6.0 → 1.6.1
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/context/map_context.js +15 -7
- package/core/decode/index.js +14 -2
- package/package.json +5 -1
- package/.claude/plan.md +0 -65
- package/CLAUDE.md +0 -51
- package/TASKS.md +0 -51
- package/core/config/index.d.ts +0 -2
- package/core/config/main_config.d.ts +0 -25
- package/core/config/map_config.d.ts +0 -15
- package/core/context/map_context.d.ts +0 -42
- package/core/decode/index.d.ts +0 -2
- package/core/encode/index.d.ts +0 -2
- package/core/scanf/index.d.ts +0 -35
- package/core/util/ast.d.ts +0 -93
- package/core/util/logger.d.ts +0 -15
- package/core/util/parent_path.d.ts +0 -5
- package/core/util/version.d.ts +0 -43
- package/test/fixtures/sample_project/config.json +0 -18
- package/test/fixtures/sample_project/util/drawer.js +0 -15
- package/test/fixtures/sample_project/util/form.js +0 -11
- package/test/manual_review.js +0 -302
- package/test/run_tests.js +0 -515
- package/tsconfig.json +0 -103
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -68,7 +68,21 @@ class MapContext {
|
|
|
68
68
|
* @param absoluteSrcPath - 依赖文件的绝对路径
|
|
69
69
|
*/
|
|
70
70
|
appendMissingDep(depName, absoluteSrcPath) {
|
|
71
|
-
|
|
71
|
+
this.referenceDep(depName);
|
|
72
|
+
// map[depName] = { src: <相对 parentRootDir 的路径>, dependencies: {} }
|
|
73
|
+
const parentRootDir = (0, parent_path_1.getParentRootDir)();
|
|
74
|
+
const src = parentRootDir
|
|
75
|
+
? path_1.default.relative(parentRootDir, absoluteSrcPath)
|
|
76
|
+
: absoluteSrcPath;
|
|
77
|
+
this.appendModMap(new map_config_1.Mod(src, new map_config_1.Dependencies()), false, depName);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 仅将已有 mod 条目引用到 self.dependencies(不新增/覆盖 mod 条目)。
|
|
81
|
+
* 用于 mod.map 中 mod 条目已存在(有 src)但未被 self 引用的情况:
|
|
82
|
+
* 只需让 importMods 生成 require、deleteModMethods 还原调用即可。
|
|
83
|
+
* @param depName - 依赖名(如 "drawer")
|
|
84
|
+
*/
|
|
85
|
+
referenceDep(depName) {
|
|
72
86
|
const selfMod = this.getMod("self");
|
|
73
87
|
if (selfMod) {
|
|
74
88
|
selfMod.dependencies[depName] = new map_config_1.Dependency([]);
|
|
@@ -78,12 +92,6 @@ class MapContext {
|
|
|
78
92
|
mod.dependencies[depName] = new map_config_1.Dependency([]);
|
|
79
93
|
this.appendModMap(mod, true);
|
|
80
94
|
}
|
|
81
|
-
// map[depName] = { src: <相对 parentRootDir 的路径>, dependencies: {} }
|
|
82
|
-
const parentRootDir = (0, parent_path_1.getParentRootDir)();
|
|
83
|
-
const src = parentRootDir
|
|
84
|
-
? path_1.default.relative(parentRootDir, absoluteSrcPath)
|
|
85
|
-
: absoluteSrcPath;
|
|
86
|
-
this.appendModMap(new map_config_1.Mod(src, new map_config_1.Dependencies()), false, depName);
|
|
87
95
|
}
|
|
88
96
|
/**
|
|
89
97
|
* 将当前 map 写入指定目录的 mod.map 文件
|
package/core/decode/index.js
CHANGED
|
@@ -121,10 +121,13 @@ function supplementMissingDeps(srcAst, mapContext, libDirs, inPath, conflicts) {
|
|
|
121
121
|
if (!libDirs.length) {
|
|
122
122
|
return false;
|
|
123
123
|
}
|
|
124
|
-
//
|
|
124
|
+
// 收集已知依赖名:所有 mod 的 dependencies 的并集。
|
|
125
|
+
// 注意判定标准必须与 deleteModMethods 一致——一个 __{mod} 后缀能被还原,
|
|
126
|
+
// 当且仅当 mod 出现在某个 mod 的 dependencies 中(而非仅仅是 mod 名存在于 map)。
|
|
127
|
+
// 否则 mod 条目存在但未被任何 mod 引用时(如 self.dependencies 缺少该依赖),
|
|
128
|
+
// 调用既不会还原也不会 require,需识别为"未知"并补充到 self.dependencies。
|
|
125
129
|
const knownDeps = new Set();
|
|
126
130
|
mapContext.getModNames().forEach((modName) => {
|
|
127
|
-
knownDeps.add(modName);
|
|
128
131
|
mapContext.getDependencyNameByMod(modName).forEach((dep) => knownDeps.add(dep));
|
|
129
132
|
});
|
|
130
133
|
const unknownDeps = (0, ast_1.getUnknownDepNames)(srcAst, knownDeps);
|
|
@@ -133,6 +136,15 @@ function supplementMissingDeps(srcAst, mapContext, libDirs, inPath, conflicts) {
|
|
|
133
136
|
}
|
|
134
137
|
let supplemented = false;
|
|
135
138
|
unknownDeps.forEach((depName) => {
|
|
139
|
+
// 若 mod.map 已有该 mod 条目且 src 有效,只需补到 self.dependencies 即可,
|
|
140
|
+
// 无需重新搜索 libs(避免重名冲突和不必要的 src 覆盖)。
|
|
141
|
+
const existingSrc = mapContext.getSrcPathByMod(depName);
|
|
142
|
+
if (existingSrc) {
|
|
143
|
+
mapContext.referenceDep(depName);
|
|
144
|
+
logger.info(`补充依赖引用: ${depName}(复用已有 src: ${existingSrc})`);
|
|
145
|
+
supplemented = true;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
136
148
|
const candidates = (0, scanf_1.scanfLibMod)(libDirs, depName);
|
|
137
149
|
if (candidates.length === 0) {
|
|
138
150
|
logger.warn(`未找到依赖文件: ${depName}(在 libs 目录中无匹配)`);
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kezh/my-custom-js-converter",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "自定义代码转换器",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"core/**/*.js",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
6
10
|
"bin": {
|
|
7
11
|
"encode": "core/encode/index.js",
|
|
8
12
|
"decode": "core/decode/index.js"
|
package/.claude/plan.md
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# 日志优化方案
|
|
2
|
-
|
|
3
|
-
## 现状问题
|
|
4
|
-
|
|
5
|
-
1. **格式不统一** — 有的用 `=>` 分隔,有的直接打印数组,风格混乱
|
|
6
|
-
2. **缺少层级结构** — 所有日志平铺输出,无法区分步骤/阶段
|
|
7
|
-
3. **信息不完整** — `scanf dirs => ` 和数组分两行打印,`the map is not found!` 没有上下文
|
|
8
|
-
4. **缺少状态标识** — 没有成功/失败/警告等视觉区分
|
|
9
|
-
5. **中英混杂** — `路径不存在[...]忽略` vs `scanf dirs` vs `the map is not found!`
|
|
10
|
-
6. **缺少汇总** — 处理完成后没有统计摘要
|
|
11
|
-
|
|
12
|
-
## 优化方案
|
|
13
|
-
|
|
14
|
-
### 1. 新建 `src/util/logger.ts` — 统一日志工具
|
|
15
|
-
|
|
16
|
-
```typescript
|
|
17
|
-
export function createLogger(scope: string) {
|
|
18
|
-
return {
|
|
19
|
-
info(msg: string) { console.log(`[${scope}] ✔ ${msg}`); },
|
|
20
|
-
warn(msg: string) { console.log(`[${scope}] ⚠ ${msg}`); },
|
|
21
|
-
error(msg: string) { console.log(`[${scope}] ✖ ${msg}`); },
|
|
22
|
-
step(title: string) {
|
|
23
|
-
console.log(`\n[${scope}] ── ${title} ${'─'.repeat(Math.max(0, 50 - title.length))}`);
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
简洁、无外部依赖、终端友好。
|
|
30
|
-
|
|
31
|
-
### 2. 日志对照表
|
|
32
|
-
|
|
33
|
-
| 原始 | 优化后 |
|
|
34
|
-
|---|---|
|
|
35
|
-
| `console.log("scanf dirs => ")` + `console.log(targetDirs)` | `logger.info('scanf dirs: ' + targetDirs.join(', '))` |
|
|
36
|
-
| `console.log(\`scanf file => ${inPath}\`)` | `logger.info(\`scanf file: ${inPath}\`)` |
|
|
37
|
-
| `console.log(\`output file => ${outPath}\`)` | `logger.info(\`output: ${outPath}\`)` |
|
|
38
|
-
| `console.log(\`output => ${outPath}\`)` | `logger.info(\`output: ${outPath}\`)` |
|
|
39
|
-
| `console.log(\`input map => ${inPath}\`)` | `logger.info(\`read map: ${inPath}\`)` |
|
|
40
|
-
| `console.log("the map is not found!")` | `logger.warn('map file not found')` |
|
|
41
|
-
| `console.log(\`output map => ${outPath}\`)` | `logger.info(\`write map: ${outPath}\`)` |
|
|
42
|
-
| `console.log(\`not found entry => ${entry}\`)` | `logger.warn(\`entry not found: ${entry}\`)` |
|
|
43
|
-
| `console.log(\`路径不存在[${dirPath}]忽略\`)` | `logger.warn(\`dir not found, skipping: ${dirPath}\`)` |
|
|
44
|
-
| `console.log(\`ignore module => ${item.id.name}\`)` | `logger.info(\`ignore module: ${item.id.name}\`)` |
|
|
45
|
-
|
|
46
|
-
### 3. 增加步骤分隔和汇总
|
|
47
|
-
|
|
48
|
-
**encode** 流程增加:
|
|
49
|
-
- 步骤标题:扫描目录 → 查找文件 → 编码处理
|
|
50
|
-
- 汇总:处理文件数、方法总数、版本号
|
|
51
|
-
|
|
52
|
-
**decode** 流程增加:
|
|
53
|
-
- 步骤标题:扫描目录 → 查找文件 → 解码处理
|
|
54
|
-
- 汇总:处理文件数
|
|
55
|
-
|
|
56
|
-
### 4. 修改文件清单
|
|
57
|
-
|
|
58
|
-
| 文件 | 变更 |
|
|
59
|
-
|---|---|
|
|
60
|
-
| `src/util/logger.ts` | **新建** — 日志工具模块 |
|
|
61
|
-
| `src/encode/index.ts` | 替换 4 处 console.log,增加步骤和汇总 |
|
|
62
|
-
| `src/decode/index.ts` | 替换 4 处 console.log,增加步骤和汇总 |
|
|
63
|
-
| `src/context/map_context.ts` | 替换 3 处 console.log |
|
|
64
|
-
| `src/scanf/index.ts` | 替换 1 处 console.log |
|
|
65
|
-
| `src/util/ast.ts` | 替换 1 处 console.log |
|
package/CLAUDE.md
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Project Overview
|
|
6
|
-
|
|
7
|
-
`@kezh/my-custom-js-converter` is a Babel-based JavaScript code transformer that **encodes** (flattens) and **decodes** (restores) CommonJS module structures. It takes JavaScript files that use `require()` + object-oriented patterns and flattens them into a single object with renamed methods, then can reverse the process.
|
|
8
|
-
|
|
9
|
-
## Build & Run
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
pnpm install # install dependencies
|
|
13
|
-
pnpm build # compile TypeScript (npx tsc --build)
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
The compiled output goes to `core/` (gitignored). Source is in `src/`.
|
|
17
|
-
|
|
18
|
-
Two CLI entry points (declared in `package.json` bin):
|
|
19
|
-
- `encode` → `core/encode/index.js` — flattens modules into a single file
|
|
20
|
-
- `decode` → `core/decode/index.js` — restores the original module structure
|
|
21
|
-
|
|
22
|
-
No test framework is configured.
|
|
23
|
-
|
|
24
|
-
## Architecture
|
|
25
|
-
|
|
26
|
-
### Data Flow
|
|
27
|
-
|
|
28
|
-
**Encode**: Scan target dirs → find entry JS files → build dependency map (`MapContext`) → extract & rename methods from all modules → output single flattened file + `mod.map`
|
|
29
|
-
|
|
30
|
-
**Decode**: Read `mod.map` → read encoded file → re-insert `require` statements → remove inlined dependency methods → restore original method names → output restored file
|
|
31
|
-
|
|
32
|
-
### Key Modules
|
|
33
|
-
|
|
34
|
-
- **`src/config/`** — Configuration loading. `MainConfig` defines encode/decode settings (entry object name, file names, ignore list). Reads `config.json` from the parent project root when installed as a dependency.
|
|
35
|
-
- **`src/context/map_context.ts`** — Core orchestration. `MapContext` builds a dependency graph by recursively walking `require()` calls, then performs **filtering** (removing invalid method references) and **tree-shaking** (removing unused methods). Serializes to `mod.map` JSON file.
|
|
36
|
-
- **`src/util/ast.ts`** — All Babel AST manipulation: parsing, traversing, extracting object methods, renaming methods (appending `__modName` suffix), generating import statements, and reversing the renaming during decode.
|
|
37
|
-
- **`src/scanf/`** — File system scanning: finding target files by name, resolving `require()` paths (handles both `dir/index.js` and `file.js` patterns).
|
|
38
|
-
- **`src/util/parent_path.ts`** — Detects whether the tool is running inside `node_modules/` and resolves the parent project root.
|
|
39
|
-
|
|
40
|
-
### Encoding Convention
|
|
41
|
-
|
|
42
|
-
Methods from dependency modules are renamed with a `__modName` suffix (e.g., `helperMethod` becomes `helperMethod__util`). `this.method()` calls in the root module stay as-is; in dependency modules, `this.method()` becomes `this.method__modName()`. The decode step reverses this convention.
|
|
43
|
-
|
|
44
|
-
### Configuration
|
|
45
|
-
|
|
46
|
-
When used as a dependency, the tool reads `config.json` from the parent project's root. Default config:
|
|
47
|
-
- `encode.file`: `"index.js"`, `encode.output`: `"coded.js"`, `encode.entry`: `"customEvent"`
|
|
48
|
-
- `decode.file`: `"coded.js"`, `decode.output`: `"decoded.js"`, `decode.mount`: `"customEvent"`
|
|
49
|
-
- `settingDir`: `".setting"` (where `mod.map` is stored)
|
|
50
|
-
- `target`: directories to scan relative to `baseDir`
|
|
51
|
-
- `libs`: dependency library search directories (used by decode to supplement missing deps in `mod.map`). Supports `@/util` alias paths (`@` = project root) and `util` paths relative to `baseDir`. When decode finds unknown `__{mod}` suffixes in `coded.js` not present in `mod.map`, it searches these directories for `modName.js` / `modName/index.js` and auto-supplements `mod.map`. Duplicate names are resolved interactively after batch processing.
|
package/TASKS.md
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# 任务
|
|
2
|
-
`npx decode`功能反编其他人的`coded.js`文件时,如果本地的`.setting/mod.map`文件没有及时更新依赖模块,会导致部分依赖无法识别,导致没有引入依赖模块:
|
|
3
|
-
1. 比如当前coded.js为:
|
|
4
|
-
```js
|
|
5
|
-
onClickPickLevel() {
|
|
6
|
-
this.pop__drawer({
|
|
7
|
-
title: "关联隐患信息",
|
|
8
|
-
size: "65%",
|
|
9
|
-
name: "storeOfHiddenDangers",
|
|
10
|
-
param: {}
|
|
11
|
-
}, resp => {
|
|
12
|
-
Object.keys(resp).forEach(key => {
|
|
13
|
-
this.setValue__form(`${key}`, resp[key]);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
```
|
|
18
|
-
2. 当时由于mod.map中没有定义`drawer`依赖,导致反编后的decoded.js为:
|
|
19
|
-
```js
|
|
20
|
-
onClickPickLevel() {
|
|
21
|
-
this.pop__drawer({
|
|
22
|
-
title: "关联隐患信息",
|
|
23
|
-
size: "65%",
|
|
24
|
-
name: "storeOfHiddenDangers",
|
|
25
|
-
param: {}
|
|
26
|
-
}, resp => {
|
|
27
|
-
Object.keys(resp).forEach(key => {
|
|
28
|
-
this.setValue__form(`${key}`, resp[key]);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
3. 但是我们期望的效果是:
|
|
34
|
-
```js
|
|
35
|
-
onClickPickLevel() {
|
|
36
|
-
drawer.pop({
|
|
37
|
-
title: "关联隐患信息",
|
|
38
|
-
size: "65%",
|
|
39
|
-
name: "storeOfHiddenDangers",
|
|
40
|
-
param: {}
|
|
41
|
-
}, resp => {
|
|
42
|
-
Object.keys(resp).forEach(key => {
|
|
43
|
-
this.setValue__form(`${key}`, resp[key]);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
我想到的解决方案是:
|
|
49
|
-
1. `npx decode`时,先要将`.setting/mod.map`文件更新,此时需要先找到coded.js中可能的依赖`__{mod}`
|
|
50
|
-
2. 扫描匹配可能得文件名称,并更新mod.map文件
|
|
51
|
-
3. 依赖文件名可能存在重名问题,所以当出现重名时,需要交给用户指定依赖的js文件
|
package/core/config/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface MainConfig {
|
|
2
|
-
encode: EncodeConfig;
|
|
3
|
-
decode: DecodeConfig;
|
|
4
|
-
baseDir: string;
|
|
5
|
-
target: string[];
|
|
6
|
-
settingDir: string;
|
|
7
|
-
customConfig: string;
|
|
8
|
-
/**
|
|
9
|
-
* 依赖库搜索目录数组,用于 decode 时补充缺失依赖。
|
|
10
|
-
* 支持 "@/util" 别名路径(@ 代表项目根目录)和 "util" 相对 baseDir 路径。
|
|
11
|
-
*/
|
|
12
|
-
libs: string[];
|
|
13
|
-
}
|
|
14
|
-
export interface EncodeConfig {
|
|
15
|
-
file: string;
|
|
16
|
-
output: string;
|
|
17
|
-
entry: string;
|
|
18
|
-
ignoreMod: string[];
|
|
19
|
-
useAlias: boolean;
|
|
20
|
-
}
|
|
21
|
-
export interface DecodeConfig {
|
|
22
|
-
file: string;
|
|
23
|
-
output: string;
|
|
24
|
-
mount: string;
|
|
25
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare class MapConfig {
|
|
2
|
-
[mod: string]: Mod;
|
|
3
|
-
}
|
|
4
|
-
export declare class Mod {
|
|
5
|
-
src: string;
|
|
6
|
-
dependencies: Dependencies;
|
|
7
|
-
constructor(src: string, dependencies?: Dependencies);
|
|
8
|
-
}
|
|
9
|
-
export declare class Dependencies {
|
|
10
|
-
[name: string]: Dependency;
|
|
11
|
-
}
|
|
12
|
-
export declare class Dependency {
|
|
13
|
-
methods: string[];
|
|
14
|
-
constructor(methods?: string[]);
|
|
15
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Mod } from "../config/map_config";
|
|
2
|
-
export declare class MapContext {
|
|
3
|
-
static SAVE_FILE: string;
|
|
4
|
-
private srcPath;
|
|
5
|
-
private entry;
|
|
6
|
-
private outDir;
|
|
7
|
-
private map;
|
|
8
|
-
constructor(srcPath?: string, entry?: string, outDir?: string, initMap?: boolean);
|
|
9
|
-
appendModMap(mod: Mod, self: boolean, name?: string): void;
|
|
10
|
-
getModNames(): string[];
|
|
11
|
-
getMod(name: string): Mod | null | undefined;
|
|
12
|
-
getMethodNamesByMod(name: string): string[];
|
|
13
|
-
getDependencyNameByMod(name: string): string[];
|
|
14
|
-
getSrcPathByMod(name: string): string | undefined;
|
|
15
|
-
getAbsoluteSrcPathByMod(name: string): string | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* 补充缺失的依赖到 mod.map
|
|
18
|
-
* 在 self.dependencies 下新增该依赖(让 importMods 生成 require),
|
|
19
|
-
* 并新增独立的 mod 条目(让 getAbsoluteSrcPathByMod 拿到源文件路径)。
|
|
20
|
-
* methods 留空数组,后续 npx encode 会自动补全。
|
|
21
|
-
* @param depName - 依赖名(如 "drawer")
|
|
22
|
-
* @param absoluteSrcPath - 依赖文件的绝对路径
|
|
23
|
-
*/
|
|
24
|
-
appendMissingDep(depName: string, absoluteSrcPath: string): void;
|
|
25
|
-
/**
|
|
26
|
-
* 将当前 map 写入指定目录的 mod.map 文件
|
|
27
|
-
* @param outDir - 输出目录
|
|
28
|
-
*/
|
|
29
|
-
writeToLocalDir(outDir: string): void;
|
|
30
|
-
static readFromLocal(inDir: string): MapContext;
|
|
31
|
-
private init;
|
|
32
|
-
private writeToLocal;
|
|
33
|
-
private buildMapContext;
|
|
34
|
-
/**
|
|
35
|
-
* 过滤self的dependencies中无效方法
|
|
36
|
-
*/
|
|
37
|
-
private filtering;
|
|
38
|
-
/**
|
|
39
|
-
* 去除dependencies中未使用方法
|
|
40
|
-
*/
|
|
41
|
-
private shaking;
|
|
42
|
-
}
|
package/core/decode/index.d.ts
DELETED
package/core/encode/index.d.ts
DELETED
package/core/scanf/index.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export declare function scanfCodeFiles(dirPaths: string | string[], filterName?: string): string[];
|
|
2
|
-
export declare function scanfCodeDirs(baseDir: string, targetDirs: string[]): string[];
|
|
3
|
-
/**
|
|
4
|
-
* 将 libs 配置解析为绝对路径数组
|
|
5
|
-
* 支持 "@/util" 别名路径(@ 代表项目根目录 rootDir)和 "util" 相对 baseDir 路径
|
|
6
|
-
* @param libs - libs 配置数组
|
|
7
|
-
* @param baseDir - 基础目录(相对路径的基准)
|
|
8
|
-
* @param rootDir - 项目根目录(@ 别名的基准,未提供时 @ 路径会被跳过并警告)
|
|
9
|
-
* @returns 绝对路径数组
|
|
10
|
-
*/
|
|
11
|
-
export declare function resolveLibDirs(libs: string[], baseDir: string, rootDir?: string): string[];
|
|
12
|
-
/**
|
|
13
|
-
* 在 libs 目录下搜索依赖模块文件
|
|
14
|
-
* 查找 modName.js(文件)和 modName/index.js(目录下入口)
|
|
15
|
-
* @param libDirs - 已解析的绝对路径目录数组
|
|
16
|
-
* @param modName - 依赖模块名(如 "drawer")
|
|
17
|
-
* @returns 所有匹配的绝对路径数组
|
|
18
|
-
*/
|
|
19
|
-
export declare function scanfLibMod(libDirs: string[], modName: string): string[];
|
|
20
|
-
/**
|
|
21
|
-
* 扫描引入路径
|
|
22
|
-
* require('../../util')
|
|
23
|
-
* - is dir ../../util/index.js
|
|
24
|
-
* - is file ../../util.js
|
|
25
|
-
* require('@/util')
|
|
26
|
-
* - @ 代表项目根目录(rootDir),解析为 rootDir/util
|
|
27
|
-
* - is dir rootDir/util/index.js
|
|
28
|
-
* - is file rootDir/util.js
|
|
29
|
-
* - throw err
|
|
30
|
-
* @param baseDir - 基础目录(当前文件所在目录,用于相对路径解析)
|
|
31
|
-
* @param modPath - 引入路径
|
|
32
|
-
* @param rootDir - 项目根目录(用于 @ 别名解析,若未提供则 @ 路径无法解析)
|
|
33
|
-
* @returns
|
|
34
|
-
*/
|
|
35
|
-
export declare function scanfRequieMod(baseDir: string, modPath: string, rootDir?: string): string;
|
package/core/util/ast.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Node } from "@babel/core";
|
|
2
|
-
import { ObjectMethod } from "@babel/types";
|
|
3
|
-
import { Mod } from "../config/map_config";
|
|
4
|
-
import { MapContext } from "../context/map_context";
|
|
5
|
-
export type AstType = Node | Node[] | null | undefined;
|
|
6
|
-
export declare function parseSrcAst(srcPath?: string): AstType;
|
|
7
|
-
export declare function outputObjectMethods(outPath: string, methods: ObjectMethod[]): void;
|
|
8
|
-
/**
|
|
9
|
-
* 获取所有依赖第三方模块路径(仅导入program下一级的require)
|
|
10
|
-
* val xx = require('path') => [xx, absolute path]
|
|
11
|
-
* @param baseDir - 源码所在文件夹目录
|
|
12
|
-
* @param srcAst - 源码AST
|
|
13
|
-
* @param ignoreMod - 忽略模块
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export declare function getRequireModPaths(baseDir: string, srcAst: AstType, ignoreMod?: string[], rootDir?: string): Map<string, string>;
|
|
17
|
-
/**
|
|
18
|
-
* 获取源码方法中引用的第三方模块方法名和自身模块方法名
|
|
19
|
-
* @param mod - 依赖模块
|
|
20
|
-
* @param entry - 入口对象
|
|
21
|
-
* @param srcAst - 源码AST
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
export declare function getRequireMethodNames(srcAst: AstType, entry: string, mod: string[]): Map<string, string[]>;
|
|
25
|
-
/**
|
|
26
|
-
* 获取方法名
|
|
27
|
-
* @param methods
|
|
28
|
-
* @returns
|
|
29
|
-
*/
|
|
30
|
-
export declare function getObjectMethodNames(methods: ObjectMethod[]): string[];
|
|
31
|
-
/**
|
|
32
|
-
* 获取源码入口对象所有方法
|
|
33
|
-
* @param srcAst - 源码Ast
|
|
34
|
-
* @param entry - 入口对象
|
|
35
|
-
* @param methodNames - 需要获取方法的方法名
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
|
-
export declare function getObjectMethodsByEntryAndMethodNames(srcAst: AstType, entry: string, methodNames?: string[]): ObjectMethod[];
|
|
39
|
-
/**
|
|
40
|
-
* 获取方法和内部调用的方法(仅包含自身模块方法,不包含第三方依赖)
|
|
41
|
-
* @param srcAst
|
|
42
|
-
* @param entry
|
|
43
|
-
* @param methods
|
|
44
|
-
*/
|
|
45
|
-
export declare function getObjectMehtodsByMehtodNamesAndInsideOwnMethods(srcAst: AstType, entry: string, methodNames: string[]): ObjectMethod[];
|
|
46
|
-
/**
|
|
47
|
-
* 修改依赖方法调用者
|
|
48
|
-
* @param srcAst
|
|
49
|
-
* @param entry
|
|
50
|
-
* @param mod
|
|
51
|
-
* @param methods
|
|
52
|
-
* @param root
|
|
53
|
-
*/
|
|
54
|
-
export declare function modifyObjectMethods(srcAst: AstType, entry: string, mod: Mod, methods: ObjectMethod[], root?: boolean): void;
|
|
55
|
-
/**
|
|
56
|
-
* 获取调用方法中所依赖第三方模块方法名
|
|
57
|
-
* @param srcAst
|
|
58
|
-
* @param methodNames - 调用方法名
|
|
59
|
-
* @param depNames - 依赖模块名
|
|
60
|
-
* @returns
|
|
61
|
-
*/
|
|
62
|
-
export declare function getDependentMethodNames(srcAst: AstType, methodNames: string[], depNames: string[]): Map<string, string[]>;
|
|
63
|
-
/**
|
|
64
|
-
* 生成导入语句
|
|
65
|
-
* const mod = require($modPath);
|
|
66
|
-
* @param outDir
|
|
67
|
-
* @param srcAst
|
|
68
|
-
* @param mapContext
|
|
69
|
-
* @param useAlias - 是否使用 @ 别名路径
|
|
70
|
-
*/
|
|
71
|
-
export declare function importMods(outDir: string, srcAst: AstType, mapContext: MapContext, useAlias?: boolean): void;
|
|
72
|
-
/**
|
|
73
|
-
* 去除第三方模块方法
|
|
74
|
-
* @param srcAst - 源码AST
|
|
75
|
-
*/
|
|
76
|
-
export declare function deleteModMethods(srcAst: AstType, mapContext: MapContext): void;
|
|
77
|
-
/**
|
|
78
|
-
* 获取方法内部调用的方法名
|
|
79
|
-
* @param srcAst - 源码AST
|
|
80
|
-
* @param entry - 入口
|
|
81
|
-
* @param methodName - 方法名
|
|
82
|
-
* @param mapContext
|
|
83
|
-
*/
|
|
84
|
-
export declare function getInlineMethodsByMethodName(srcAst: AstType, entry: string, methodName: string, useMethodNameMap: Map<string, string[]>): string[];
|
|
85
|
-
/**
|
|
86
|
-
* 从 coded.js 的 AST 中提取未知的依赖名(__{mod} 后缀中的 mod)
|
|
87
|
-
* 扫描 ObjectMethod 的 key 和 MemberExpression 的 property,提取 xxx__yyy 中的 yyy,
|
|
88
|
-
* 排除已知依赖名(mod.map 中已有的依赖)。
|
|
89
|
-
* @param srcAst - 源码AST
|
|
90
|
-
* @param knownDeps - 已知依赖名集合
|
|
91
|
-
* @returns 未知依赖名数组(去重)
|
|
92
|
-
*/
|
|
93
|
-
export declare function getUnknownDepNames(srcAst: AstType, knownDeps: Set<string>): string[];
|
package/core/util/logger.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 统一日志工具模块
|
|
3
|
-
* 提供带 scope 前缀和状态图标的日志函数
|
|
4
|
-
*/
|
|
5
|
-
export interface Logger {
|
|
6
|
-
info(msg: string): void;
|
|
7
|
-
warn(msg: string): void;
|
|
8
|
-
error(msg: string): void;
|
|
9
|
-
step(title: string): void;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* 创建带 scope 前缀的 logger
|
|
13
|
-
* @param scope - 日志前缀,如 'encode' / 'decode'
|
|
14
|
-
*/
|
|
15
|
-
export declare function createLogger(scope: string): Logger;
|
package/core/util/version.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 读取版本号,若版本文件不存在则创建并写入初始版本
|
|
3
|
-
* @param settingDir - setting目录路径
|
|
4
|
-
* @returns 当前版本号字符串
|
|
5
|
-
*/
|
|
6
|
-
export declare function readOrCreateVersion(settingDir: string): string;
|
|
7
|
-
/**
|
|
8
|
-
* 递增版本号并写入版本文件
|
|
9
|
-
* @param settingDir - setting目录路径
|
|
10
|
-
*/
|
|
11
|
-
export declare function incrementVersion(settingDir: string): void;
|
|
12
|
-
/**
|
|
13
|
-
* 写入版本号到版本文件
|
|
14
|
-
* @param settingDir - setting目录路径
|
|
15
|
-
* @param version - 版本号字符串
|
|
16
|
-
*/
|
|
17
|
-
export declare function writeVersion(settingDir: string, version: string): void;
|
|
18
|
-
/**
|
|
19
|
-
* 生成版本日志语句
|
|
20
|
-
* @param version - 版本号
|
|
21
|
-
* @returns console.log("__version__: 00000001")
|
|
22
|
-
*/
|
|
23
|
-
export declare function versionLogStatement(version: string): string;
|
|
24
|
-
/**
|
|
25
|
-
* 从代码文本中提取版本日志中的版本号
|
|
26
|
-
* @param code - 代码文本
|
|
27
|
-
* @returns 版本号字符串,若不存在则返回null
|
|
28
|
-
*/
|
|
29
|
-
export declare function extractVersionFromCode(code: string): string | null;
|
|
30
|
-
/**
|
|
31
|
-
* 从代码文本中移除版本日志行
|
|
32
|
-
* @param code - 代码文本
|
|
33
|
-
* @returns 移除版本日志后的代码
|
|
34
|
-
*/
|
|
35
|
-
export declare function removeVersionLogFromCode(code: string): string;
|
|
36
|
-
/**
|
|
37
|
-
* 获取版本方法名
|
|
38
|
-
*/
|
|
39
|
-
export declare function getVersionMethodName(): string;
|
|
40
|
-
/**
|
|
41
|
-
* 获取版本日志前缀
|
|
42
|
-
*/
|
|
43
|
-
export declare function getVersionLogPrefix(): string;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"encode": {
|
|
3
|
-
"file": "index.js",
|
|
4
|
-
"output": "coded.js",
|
|
5
|
-
"entry": "customEvent",
|
|
6
|
-
"ignoreMod": [],
|
|
7
|
-
"useAlias": true
|
|
8
|
-
},
|
|
9
|
-
"decode": {
|
|
10
|
-
"file": "coded.js",
|
|
11
|
-
"output": "decoded.js",
|
|
12
|
-
"mount": "customEvent"
|
|
13
|
-
},
|
|
14
|
-
"target": ["src"],
|
|
15
|
-
"settingDir": ".setting",
|
|
16
|
-
"customConfig": "config.json",
|
|
17
|
-
"libs": ["@/util"]
|
|
18
|
-
}
|