ttmg-pack 0.4.4 → 0.4.6

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +403 -0
  2. package/__TEST__/tests/fixtures/check-project/non-unity/src/game.js +1 -0
  3. package/__TEST__/tests/fixtures/check-project/non-unity/src/game.json +3 -0
  4. package/__TEST__/tests/fixtures/check-project/subpackages-camel-case/src/game.js +1 -0
  5. package/__TEST__/tests/fixtures/check-project/subpackages-camel-case/src/game.json +4 -0
  6. package/__TEST__/tests/fixtures/check-project/unity-large-config-disabled/src/game.js +1 -0
  7. package/__TEST__/tests/fixtures/check-project/unity-large-config-disabled/src/game.json +4 -0
  8. package/__TEST__/tests/fixtures/check-project/unity-large-config-disabled/src/webgl-wasm-split.json +3 -0
  9. package/__TEST__/tests/fixtures/check-project/unity-large-config-enabled/src/game.js +1 -0
  10. package/__TEST__/tests/fixtures/check-project/unity-large-config-enabled/src/game.json +4 -0
  11. package/__TEST__/tests/fixtures/check-project/unity-large-config-enabled/src/webgl-wasm-split.json +3 -0
  12. package/__TEST__/tests/fixtures/check-project/unity-large-no-config/src/game.js +1 -0
  13. package/__TEST__/tests/fixtures/check-project/unity-large-no-config/src/game.json +4 -0
  14. package/__TEST__/tests/fixtures/check-project/unity-small/src/game.js +1 -0
  15. package/__TEST__/tests/fixtures/check-project/unity-small/src/game.json +4 -0
  16. package/__TEST__/tests/fixtures/game-cocos/game.json +3 -0
  17. package/__TEST__/tests/fixtures/game-invalid-json/game.json +1 -0
  18. package/__TEST__/tests/fixtures/game-no-config/game.js +1 -0
  19. package/__TEST__/tests/fixtures/game-no-engine/game.json +3 -0
  20. package/__TEST__/tests/fixtures/game-unity/game.json +15 -0
  21. package/__TEST__/tests/libs/checkProject.test.js +68 -0
  22. package/__TEST__/tests/runner-simple.js +120 -0
  23. package/__TEST__/tests/runner.js +102 -0
  24. package/__TEST__/tests/utils/Deferred.test.js +69 -0
  25. package/__TEST__/tests/utils/asyncPool.test.js +48 -0
  26. package/__TEST__/tests/utils/getCheckConfig.test.js +24 -0
  27. package/__TEST__/tests/utils/getGameEngine.test.js +32 -0
  28. package/__TEST__/tests/utils/getIndependentPackagesConfig.test.js +27 -0
  29. package/__TEST__/tests/utils/getMd5.test.js +31 -0
  30. package/__TEST__/tests/utils/getSubpackagesConfig.test.js +26 -0
  31. package/__TEST__/tests/utils/unity.test.js +30 -0
  32. package/dist/index.js +19 -11
  33. package/dist/index.js.map +1 -1
  34. package/dist/libs/checkPkgs/checkPkgPath.d.ts +1 -0
  35. package/dist/libs/extractPkgs/hasAnyNodeModulesShallow.d.ts +1 -0
  36. package/dist/libs/extractPkgs/index.d.ts +6 -0
  37. package/dist/libs/makePkgs/extract/NodeModuleExtractor.d.ts +39 -0
  38. package/dist/libs/makePkgs/extract/hasAnyNodeModulesShallow.d.ts +1 -0
  39. package/dist/libs/makePkgs/extract/index.d.ts +6 -0
  40. package/dist/libs/makePkgs/extract.d.ts +4 -0
  41. package/dist/typings/index.d.ts +14 -0
  42. package/dist/utils/NodeModuleExtractor.d.ts +38 -0
  43. package/dist/utils/i18n.d.ts +2 -0
  44. package/dist/utils/overrideConfig.d.ts +8 -0
  45. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ export declare function checkPkgPath(path: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function hasAnyNodeModulesShallow(root: string): boolean;
@@ -0,0 +1,6 @@
1
+ export declare function extractPkgs(params: {
2
+ entryDir: string;
3
+ outputDir: string;
4
+ }): Promise<{
5
+ extractOutputDir: string;
6
+ }>;
@@ -0,0 +1,39 @@
1
+ export declare class NodeModuleExtractor {
2
+ srcDir: string;
3
+ distDir: string;
4
+ miniprogramNpmDir: string;
5
+ addedFiles: Set<string>;
6
+ pendingTransforms: Array<{
7
+ srcRelativePath: string;
8
+ distRelativePath: string;
9
+ isNodeModuleFile: boolean;
10
+ }>;
11
+ sourceMaps: Map<string, any>;
12
+ enableReport: boolean;
13
+ constructor(srcDir: any, distDir: any);
14
+ customRequireHook(modulePath: any, relativePath: any): Promise<boolean>;
15
+ findInNodeModules(moduleName: any, relativePath: any): string;
16
+ transformModulePath(originalPath: any): any;
17
+ transformRequirePath(moduleName: any, srcRelativePath: any, srcModuleRelativePath: any, distModuleRelativePath: any): string;
18
+ isCodeFile(filePath: any): boolean;
19
+ ensureDirForFile(filePath: any): void;
20
+ processCodeFile(srcRelativePath: any, distRelativePath: any, isNodeModuleFile: any): Promise<void>;
21
+ copyNonCodeFile(srcRelativePath: any, distRelativePath: any): void;
22
+ collectFiles(rootDir: any, relativeDir?: any): void;
23
+ addTransform(srcRelativePath: any, distRelativePath: any, isNodeModuleFile: any): void;
24
+ processTransforms(): Promise<void>;
25
+ generateReport(): {
26
+ srcDir: string;
27
+ distDir: string;
28
+ processedFiles: string[];
29
+ sourceMaps: [string, any][];
30
+ totalFiles: number;
31
+ totalSourceMaps: number;
32
+ timestamp: string;
33
+ };
34
+ extract(): Promise<void>;
35
+ }
36
+ export declare function extract(params: {
37
+ srcDir: string;
38
+ distDir: string;
39
+ }): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function hasAnyNodeModulesShallow(root: string): boolean;
@@ -0,0 +1,6 @@
1
+ export declare function extract(params: {
2
+ entryDir: string;
3
+ outputDir: string;
4
+ }): Promise<{
5
+ extractOutputDir: string;
6
+ }>;
@@ -0,0 +1,4 @@
1
+ export declare function extract(params: {
2
+ srcDir: string;
3
+ distDir: string;
4
+ }): Promise<void>;
@@ -40,11 +40,22 @@ export type PackLang = 'en-US' | 'zh-CN';
40
40
  export interface PackContext {
41
41
  lang?: PackLang;
42
42
  }
43
+ export interface CheckDetail {
44
+ /**
45
+ * 可选的文档/指南链接,用于在 IDE/CLI 中透出更多信息。
46
+ */
47
+ link?: string;
48
+ /**
49
+ * 可选的展示文案(如“查看分包文档”),若缺省则由上层决定展示方式。
50
+ */
51
+ text?: string;
52
+ }
43
53
  export interface CheckSizeResult {
44
54
  passed: boolean;
45
55
  msg: string;
46
56
  type: 'size';
47
57
  level?: 'error' | 'warning' | 'info';
58
+ detail?: CheckDetail;
48
59
  size: number;
49
60
  name: string;
50
61
  required: boolean;
@@ -55,6 +66,7 @@ export interface CheckConfigResult {
55
66
  msg: string;
56
67
  type: 'config';
57
68
  level?: 'error' | 'warning' | 'info';
69
+ detail?: CheckDetail;
58
70
  file: string;
59
71
  name: string;
60
72
  required: boolean;
@@ -67,6 +79,7 @@ export interface CheckAPIResult {
67
79
  msg: string;
68
80
  type: 'api';
69
81
  level?: 'error' | 'warning' | 'info';
82
+ detail?: CheckDetail;
70
83
  name: string;
71
84
  required: boolean;
72
85
  dimension: CheckDimension;
@@ -87,6 +100,7 @@ export interface CheckPerfResult {
87
100
  msg: string;
88
101
  type: 'performance';
89
102
  level?: 'error' | 'warning' | 'info';
103
+ detail?: CheckDetail;
90
104
  name: string;
91
105
  required: boolean;
92
106
  dimension: CheckDimension;
@@ -0,0 +1,38 @@
1
+ export declare class NodeModuleExtractor {
2
+ srcDir: string;
3
+ distDir: string;
4
+ miniprogramNpmDir: string;
5
+ addedFiles: Set<string>;
6
+ pendingTransforms: Array<{
7
+ srcRelativePath: string;
8
+ distRelativePath: string;
9
+ isNodeModuleFile: boolean;
10
+ }>;
11
+ sourceMaps: Map<string, any>;
12
+ constructor(srcDir: any, distDir: any);
13
+ customRequireHook(modulePath: any, relativePath: any): Promise<boolean>;
14
+ findInNodeModules(moduleName: any, relativePath: any): string;
15
+ transformModulePath(originalPath: any): any;
16
+ transformRequirePath(moduleName: any, srcRelativePath: any, srcModuleRelativePath: any, distModuleRelativePath: any): string;
17
+ isCodeFile(filePath: any): boolean;
18
+ ensureDirForFile(filePath: any): void;
19
+ processCodeFile(srcRelativePath: any, distRelativePath: any, isNodeModuleFile: any): Promise<void>;
20
+ copyNonCodeFile(srcRelativePath: any, distRelativePath: any): void;
21
+ collectFiles(rootDir: any, relativeDir?: any): void;
22
+ addTransform(srcRelativePath: any, distRelativePath: any, isNodeModuleFile: any): void;
23
+ processTransforms(): Promise<void>;
24
+ generateReport(): {
25
+ srcDir: string;
26
+ distDir: string;
27
+ processedFiles: string[];
28
+ sourceMaps: [string, any][];
29
+ totalFiles: number;
30
+ totalSourceMaps: number;
31
+ timestamp: string;
32
+ };
33
+ extract(): Promise<void>;
34
+ }
35
+ export declare function extract(params: {
36
+ srcDir: string;
37
+ distDir: string;
38
+ }): Promise<void>;
@@ -55,6 +55,7 @@ declare const messages: {
55
55
  readonly 'check.project.size.success': "Project size check passed: {sizeMB}MB.";
56
56
  readonly 'check.project.perf.noSplitNeeded': "wasmFuncCount < {limit}. No wasm code splitting is needed.";
57
57
  readonly 'check.project.perf.needSplit': "The Wasm function count in wasmcode/ exceeds {limit}. Please enable code splitting to optimize performance.";
58
+ readonly 'check.project.perf.doc': "View wasm split guide";
58
59
  readonly 'check.project.perf.splitEnabled': "wasmFuncCount >= {limit}, and wasm split is enabled.";
59
60
  readonly 'check.main.size.failed': "Main package size check failed: {sizeMB}MB. It must not exceed {limitMB}MB.";
60
61
  readonly 'check.main.size.success': "Main package size check passed: {sizeMB}MB.";
@@ -128,6 +129,7 @@ declare const messages: {
128
129
  readonly 'check.project.size.success': "项目大小检查通过:当前 {sizeMB}MB。";
129
130
  readonly 'check.project.perf.noSplitNeeded': "wasmFuncCount < {limit},无需进行 wasm 代码拆分。";
130
131
  readonly 'check.project.perf.needSplit': "wasmcode/ 中的 Wasm 函数数量超过 {limit},请开启代码拆分以优化性能。";
132
+ readonly 'check.project.perf.doc': "查看分包文档";
131
133
  readonly 'check.project.perf.splitEnabled': "wasmFuncCount >= {limit},且已开启 wasm 拆分。";
132
134
  readonly 'check.main.size.failed': "主包大小检查失败:当前 {sizeMB}MB,不能超过 {limitMB}MB。";
133
135
  readonly 'check.main.size.success': "主包大小检查通过:当前 {sizeMB}MB。";
@@ -0,0 +1,8 @@
1
+ import { BuildConfig } from '../typings';
2
+ /**
3
+ * 覆盖配置,根据游戏引擎类型,设置主包和独立子包的大小限制
4
+ * @param entryDir 游戏项目入口目录
5
+ * @param config 原始构建配置
6
+ * @returns 覆盖后的构建配置
7
+ */
8
+ export declare function overrideConfig(config: BuildConfig): BuildConfig;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ttmg-pack",
3
3
  "author": "ttmg",
4
- "version": "0.4.4",
4
+ "version": "0.4.6",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {