ttmg-pack 0.4.3 → 0.4.4

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 (44) hide show
  1. package/dist/index.js +20 -9
  2. package/dist/index.js.map +1 -1
  3. package/dist/libs/makePkgs/addDepsToPackages.d.ts +2 -1
  4. package/package.json +1 -1
  5. package/CHANGELOG.md +0 -392
  6. package/__TEST__/tests/fixtures/check-project/non-unity/src/game.js +0 -1
  7. package/__TEST__/tests/fixtures/check-project/non-unity/src/game.json +0 -3
  8. package/__TEST__/tests/fixtures/check-project/subpackages-camel-case/src/game.js +0 -1
  9. package/__TEST__/tests/fixtures/check-project/subpackages-camel-case/src/game.json +0 -4
  10. package/__TEST__/tests/fixtures/check-project/unity-large-config-disabled/src/game.js +0 -1
  11. package/__TEST__/tests/fixtures/check-project/unity-large-config-disabled/src/game.json +0 -4
  12. package/__TEST__/tests/fixtures/check-project/unity-large-config-disabled/src/webgl-wasm-split.json +0 -3
  13. package/__TEST__/tests/fixtures/check-project/unity-large-config-enabled/src/game.js +0 -1
  14. package/__TEST__/tests/fixtures/check-project/unity-large-config-enabled/src/game.json +0 -4
  15. package/__TEST__/tests/fixtures/check-project/unity-large-config-enabled/src/webgl-wasm-split.json +0 -3
  16. package/__TEST__/tests/fixtures/check-project/unity-large-no-config/src/game.js +0 -1
  17. package/__TEST__/tests/fixtures/check-project/unity-large-no-config/src/game.json +0 -4
  18. package/__TEST__/tests/fixtures/check-project/unity-small/src/game.js +0 -1
  19. package/__TEST__/tests/fixtures/check-project/unity-small/src/game.json +0 -4
  20. package/__TEST__/tests/fixtures/game-cocos/game.json +0 -3
  21. package/__TEST__/tests/fixtures/game-invalid-json/game.json +0 -1
  22. package/__TEST__/tests/fixtures/game-no-config/game.js +0 -1
  23. package/__TEST__/tests/fixtures/game-no-engine/game.json +0 -3
  24. package/__TEST__/tests/fixtures/game-unity/game.json +0 -15
  25. package/__TEST__/tests/libs/checkProject.test.js +0 -68
  26. package/__TEST__/tests/runner-simple.js +0 -120
  27. package/__TEST__/tests/runner.js +0 -102
  28. package/__TEST__/tests/utils/Deferred.test.js +0 -69
  29. package/__TEST__/tests/utils/asyncPool.test.js +0 -48
  30. package/__TEST__/tests/utils/getCheckConfig.test.js +0 -24
  31. package/__TEST__/tests/utils/getGameEngine.test.js +0 -32
  32. package/__TEST__/tests/utils/getIndependentPackagesConfig.test.js +0 -27
  33. package/__TEST__/tests/utils/getMd5.test.js +0 -31
  34. package/__TEST__/tests/utils/getSubpackagesConfig.test.js +0 -26
  35. package/__TEST__/tests/utils/unity.test.js +0 -30
  36. package/dist/libs/checkPkgs/checkPkgPath.d.ts +0 -1
  37. package/dist/libs/extractPkgs/hasAnyNodeModulesShallow.d.ts +0 -1
  38. package/dist/libs/extractPkgs/index.d.ts +0 -6
  39. package/dist/libs/makePkgs/extract/NodeModuleExtractor.d.ts +0 -39
  40. package/dist/libs/makePkgs/extract/hasAnyNodeModulesShallow.d.ts +0 -1
  41. package/dist/libs/makePkgs/extract/index.d.ts +0 -6
  42. package/dist/libs/makePkgs/extract.d.ts +0 -4
  43. package/dist/utils/NodeModuleExtractor.d.ts +0 -38
  44. package/dist/utils/overrideConfig.d.ts +0 -8
@@ -1,102 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const tests = [];
5
- const describeStack = [];
6
- let currentDescribe = null;
7
-
8
- function describe(name, fn) {
9
- const suite = { name, tests: [], children: [] };
10
- if (currentDescribe) {
11
- currentDescribe.children.push(suite);
12
- } else {
13
- tests.push(suite);
14
- }
15
- describeStack.push(currentDescribe);
16
- currentDescribe = suite;
17
- try {
18
- fn();
19
- } finally {
20
- currentDescribe = describeStack.pop();
21
- }
22
- }
23
-
24
- function it(name, fn) {
25
- if (!currentDescribe) {
26
- throw new Error('it() must be called inside describe()');
27
- }
28
- currentDescribe.tests.push({ name, fn });
29
- }
30
-
31
- let passed = 0;
32
- let failed = 0;
33
-
34
- async function runSuite(suite, indent = 0) {
35
- console.log(`${' '.repeat(indent)}${suite.name}`);
36
- for (const test of suite.tests) {
37
- try {
38
- if (test.fn.constructor.name === 'AsyncFunction') {
39
- await test.fn();
40
- } else {
41
- test.fn();
42
- }
43
- console.log(`${' '.repeat(indent + 1)}✓ ${test.name}`);
44
- passed++;
45
- } catch (error) {
46
- console.log(`${' '.repeat(indent + 1)}✗ ${test.name}`);
47
- console.log(`${' '.repeat(indent + 2)}${error.message}`);
48
- if (error.stack) {
49
- console.log(`${' '.repeat(indent + 2)}${error.stack.split('\n').slice(1).join('\n' + ' '.repeat(indent + 2))}`);
50
- }
51
- failed++;
52
- }
53
- }
54
- for (const child of suite.children) {
55
- await runSuite(child, indent + 1);
56
- }
57
- }
58
-
59
- async function runTests() {
60
- console.log('========================================');
61
- console.log('Running unit tests');
62
- console.log('========================================\n');
63
-
64
- const testFiles = [
65
- 'utils/getMd5.test.js',
66
- 'utils/Deferred.test.js',
67
- 'utils/getGameEngine.test.js',
68
- 'utils/getSubpackagesConfig.test.js',
69
- 'utils/getIndependentPackagesConfig.test.js',
70
- 'utils/asyncPool.test.js',
71
- 'utils/unity.test.js',
72
- 'utils/getCheckConfig.test.js',
73
- 'libs/checkProject.test.js'
74
- ];
75
-
76
- for (const file of testFiles) {
77
- const testPath = path.join(__dirname, file);
78
- if (fs.existsSync(testPath)) {
79
- console.log(`Loading tests from: ${file}`);
80
- require(testPath);
81
- }
82
- }
83
-
84
- console.log('\n');
85
-
86
- for (const suite of tests) {
87
- await runSuite(suite);
88
- }
89
-
90
- console.log('\n========================================');
91
- console.log('Test Summary:');
92
- console.log(` Passed: ${passed}`);
93
- console.log(` Failed: ${failed}`);
94
- console.log('========================================');
95
-
96
- process.exit(failed > 0 ? 1 : 0);
97
- }
98
-
99
- global.describe = describe;
100
- global.it = it;
101
-
102
- runTests();
@@ -1,69 +0,0 @@
1
- const assert = require('assert');
2
- const { Deferred } = require('../../../dist/utils/Deferred');
3
-
4
- describe('Deferred', function() {
5
- it('should create a deferred object with promise', function() {
6
- const deferred = new Deferred();
7
- assert(deferred.promise instanceof Promise);
8
- assert.strictEqual(typeof deferred.resolve, 'function');
9
- assert.strictEqual(typeof deferred.reject, 'function');
10
- });
11
-
12
- it('should resolve successfully', async function() {
13
- const deferred = new Deferred();
14
- const testValue = 'success';
15
-
16
- setTimeout(() => deferred.resolve(testValue), 10);
17
-
18
- const result = await deferred.promise;
19
- assert.strictEqual(result, testValue);
20
- });
21
-
22
- it('should reject with error', async function() {
23
- const deferred = new Deferred();
24
- const testError = new Error('test error');
25
-
26
- setTimeout(() => deferred.reject(testError), 10);
27
-
28
- try {
29
- await deferred.promise;
30
- assert.fail('Promise should have rejected');
31
- } catch (error) {
32
- assert.strictEqual(error, testError);
33
- }
34
- });
35
-
36
- it('should support then method', async function() {
37
- const deferred = new Deferred();
38
- const testValue = 'test';
39
-
40
- setTimeout(() => deferred.resolve(testValue), 10);
41
-
42
- const result = await deferred.then(val => val.toUpperCase());
43
- assert.strictEqual(result, 'TEST');
44
- });
45
-
46
- it('should support catch method', async function() {
47
- const deferred = new Deferred();
48
- const testError = new Error('catch me');
49
-
50
- setTimeout(() => deferred.reject(testError), 10);
51
-
52
- const caught = await deferred.catch(err => err.message);
53
- assert.strictEqual(caught, 'catch me');
54
- });
55
-
56
- it('should handle resolve called multiple times', async function() {
57
- const deferred = new Deferred();
58
- let resolveCount = 0;
59
-
60
- deferred.promise.then(() => resolveCount++);
61
-
62
- deferred.resolve('first');
63
- deferred.resolve('second');
64
-
65
- await new Promise(resolve => setTimeout(resolve, 10));
66
-
67
- assert.strictEqual(resolveCount, 1);
68
- });
69
- });
@@ -1,48 +0,0 @@
1
- const assert = require('assert');
2
- const { asyncPool } = require('../../../dist/utils/asyncPool');
3
-
4
- describe('asyncPool', function() {
5
- it('should execute all tasks with pool limit', async function() {
6
- const tasks = [1, 2, 3, 4, 5];
7
- const results = [];
8
-
9
- const iteratorFn = async (item) => {
10
- await new Promise(resolve => setTimeout(resolve, 10));
11
- results.push(item);
12
- return item * 2;
13
- };
14
-
15
- const finalResults = await asyncPool(2, tasks, iteratorFn);
16
-
17
- assert.deepStrictEqual(finalResults, [2, 4, 6, 8, 10]);
18
- assert.strictEqual(results.length, 5);
19
- });
20
-
21
- it('should handle empty array', async function() {
22
- const results = await asyncPool(5, [], async () => {});
23
- assert.deepStrictEqual(results, []);
24
- });
25
-
26
- it('should handle pool limit larger than array length', async function() {
27
- const tasks = [1, 2, 3];
28
- const iteratorFn = async (item) => item;
29
-
30
- const results = await asyncPool(10, tasks, iteratorFn);
31
- assert.deepStrictEqual(results, [1, 2, 3]);
32
- });
33
-
34
- it('should propagate errors', async function() {
35
- const tasks = [1, 2, 3];
36
- const iteratorFn = async (item) => {
37
- if (item === 2) throw new Error('Test error');
38
- return item;
39
- };
40
-
41
- try {
42
- await asyncPool(2, tasks, iteratorFn);
43
- assert.fail('Should have thrown an error');
44
- } catch (error) {
45
- assert.strictEqual(error.message, 'Test error');
46
- }
47
- });
48
- });
@@ -1,24 +0,0 @@
1
- const assert = require('assert');
2
- const path = require('path');
3
- const { getCheckConfig } = require('../../../dist/utils/getCheckConfig');
4
- const { GAME_PKG_SIZE_LIMIT } = require('../../../dist/constants');
5
-
6
- const fixturesPath = path.join(__dirname, '../fixtures');
7
-
8
- describe('getCheckConfig', function() {
9
- it('should return unity config for unity engine', function() {
10
- const config = getCheckConfig({
11
- entry: path.join(fixturesPath, 'game-unity')
12
- });
13
- assert.strictEqual(config.pkgSizeLimit, GAME_PKG_SIZE_LIMIT.unity.project);
14
- });
15
-
16
- it('should return default config for non-unity engine', function() {
17
- const config = getCheckConfig({
18
- entry: path.join(fixturesPath, 'game-cocos')
19
- });
20
- assert.strictEqual(config.pkgSizeLimit, 30 * 1024 * 1024);
21
- assert.strictEqual(config.mainPkgSizeLimit, 4 * 1024 * 1024);
22
- assert.strictEqual(config.independentSubPkgSizeLimit, 4 * 1024 * 1024);
23
- });
24
- });
@@ -1,32 +0,0 @@
1
- const assert = require('assert');
2
- const path = require('path');
3
- const { getGameEngine } = require('../../../dist/utils/getGameEngine');
4
-
5
- const fixturesPath = path.join(__dirname, '../fixtures');
6
-
7
- describe('getGameEngine', function() {
8
- it('should return unity when gameEngine is unity', function() {
9
- const result = getGameEngine(path.join(fixturesPath, 'game-unity'));
10
- assert.strictEqual(result, 'unity');
11
- });
12
-
13
- it('should return cocos when gameEngine is cocos', function() {
14
- const result = getGameEngine(path.join(fixturesPath, 'game-cocos'));
15
- assert.strictEqual(result, 'cocos');
16
- });
17
-
18
- it('should return unknown when game.json does not exist', function() {
19
- const result = getGameEngine(path.join(fixturesPath, 'game-no-config'));
20
- assert.strictEqual(result, 'unknown');
21
- });
22
-
23
- it('should return unknown when game.json has invalid JSON', function() {
24
- const result = getGameEngine(path.join(fixturesPath, 'game-invalid-json'));
25
- assert.strictEqual(result, 'unknown');
26
- });
27
-
28
- it('should return unknown when game.json does not have gameEngine field', function() {
29
- const result = getGameEngine(path.join(fixturesPath, 'game-no-engine'));
30
- assert.strictEqual(result, 'unknown');
31
- });
32
- });
@@ -1,27 +0,0 @@
1
- const assert = require('assert');
2
- const path = require('path');
3
- const { getIndependentPackagesConfig } = require('../../../dist/utils/getIndependentPackagesConfig');
4
-
5
- const fixturesPath = path.join(__dirname, '../fixtures');
6
-
7
- describe('getIndependentPackagesConfig', function() {
8
- it('should return independent subpackages', function() {
9
- const result = getIndependentPackagesConfig(path.join(fixturesPath, 'game-unity'));
10
- assert(Array.isArray(result));
11
- assert.strictEqual(result.length, 1);
12
- assert.strictEqual(result[0].name, 'sub2');
13
- assert.strictEqual(result[0].independent, true);
14
- });
15
-
16
- it('should return empty array when game.json does not exist', function() {
17
- const result = getIndependentPackagesConfig(path.join(fixturesPath, 'game-no-config'));
18
- assert(Array.isArray(result));
19
- assert.strictEqual(result.length, 0);
20
- });
21
-
22
- it('should return empty array when game.json has invalid JSON', function() {
23
- const result = getIndependentPackagesConfig(path.join(fixturesPath, 'game-invalid-json'));
24
- assert(Array.isArray(result));
25
- assert.strictEqual(result.length, 0);
26
- });
27
- });
@@ -1,31 +0,0 @@
1
- const assert = require('assert');
2
- const path = require('path');
3
- const fs = require('fs');
4
- const { getMd5 } = require('../../../dist/utils/getMd5');
5
-
6
- describe('getMd5', function() {
7
- it('should return correct MD5 hash for string input', function() {
8
- const testStr = 'hello world';
9
- const expected = '5eb63bbbe01eeed093cb22bb8f5acdc3';
10
- const result = getMd5(testStr);
11
- assert.strictEqual(result, expected);
12
- });
13
-
14
- it('should return consistent hash for same input', function() {
15
- const testStr = 'test string';
16
- const result1 = getMd5(testStr);
17
- const result2 = getMd5(testStr);
18
- assert.strictEqual(result1, result2);
19
- });
20
-
21
- it('should return different hash for different input', function() {
22
- const result1 = getMd5('string1');
23
- const result2 = getMd5('string2');
24
- assert.notStrictEqual(result1, result2);
25
- });
26
-
27
- it('should handle empty string', function() {
28
- const result = getMd5('');
29
- assert.strictEqual(result, 'd41d8cd98f00b204e9800998ecf8427e');
30
- });
31
- });
@@ -1,26 +0,0 @@
1
- const assert = require('assert');
2
- const path = require('path');
3
- const { getSubpackagesConfig } = require('../../../dist/utils/getSubpackagesConfig');
4
-
5
- const fixturesPath = path.join(__dirname, '../fixtures');
6
-
7
- describe('getSubpackagesConfig', function() {
8
- it('should return non-independent subpackages', function() {
9
- const result = getSubpackagesConfig(path.join(fixturesPath, 'game-unity'));
10
- assert(Array.isArray(result));
11
- assert.strictEqual(result.length, 1);
12
- assert.strictEqual(result[0].name, 'sub1');
13
- });
14
-
15
- it('should return empty array when game.json does not exist', function() {
16
- const result = getSubpackagesConfig(path.join(fixturesPath, 'game-no-config'));
17
- assert(Array.isArray(result));
18
- assert.strictEqual(result.length, 0);
19
- });
20
-
21
- it('should return empty array when game.json has invalid JSON', function() {
22
- const result = getSubpackagesConfig(path.join(fixturesPath, 'game-invalid-json'));
23
- assert(Array.isArray(result));
24
- assert.strictEqual(result.length, 0);
25
- });
26
- });
@@ -1,30 +0,0 @@
1
- const assert = require('assert');
2
- const path = require('path');
3
- const { isUnityEngine } = require('../../../dist/utils/unity');
4
- const { getUnityBuildConfig } = require('../../../dist/utils/unity/getUnityBuildConfig');
5
- const { GAME_PKG_SIZE_LIMIT } = require('../../../dist/constants');
6
-
7
- const fixturesPath = path.join(__dirname, '../fixtures');
8
-
9
- describe('Unity Utils', function() {
10
- describe('isUnityEngine', function() {
11
- it('should return true for unity engine', function() {
12
- const result = isUnityEngine(path.join(fixturesPath, 'game-unity'));
13
- assert.strictEqual(result, true);
14
- });
15
-
16
- it('should return false for non-unity engine', function() {
17
- const result = isUnityEngine(path.join(fixturesPath, 'game-cocos'));
18
- assert.strictEqual(result, false);
19
- });
20
- });
21
-
22
- describe('getUnityBuildConfig', function() {
23
- it('should return unity build config', function() {
24
- const config = getUnityBuildConfig();
25
- assert.strictEqual(config.pkgSizeLimit, GAME_PKG_SIZE_LIMIT.unity.project);
26
- assert.strictEqual(config.mainPkgSizeLimit, GAME_PKG_SIZE_LIMIT.unity.main);
27
- assert.strictEqual(config.independentSubPkgSizeLimit, GAME_PKG_SIZE_LIMIT.unity.independent);
28
- });
29
- });
30
- });
@@ -1 +0,0 @@
1
- export declare function checkPkgPath(path: string): boolean;
@@ -1 +0,0 @@
1
- export declare function hasAnyNodeModulesShallow(root: string): boolean;
@@ -1,6 +0,0 @@
1
- export declare function extractPkgs(params: {
2
- entryDir: string;
3
- outputDir: string;
4
- }): Promise<{
5
- extractOutputDir: string;
6
- }>;
@@ -1,39 +0,0 @@
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>;
@@ -1 +0,0 @@
1
- export declare function hasAnyNodeModulesShallow(root: string): boolean;
@@ -1,6 +0,0 @@
1
- export declare function extract(params: {
2
- entryDir: string;
3
- outputDir: string;
4
- }): Promise<{
5
- extractOutputDir: string;
6
- }>;
@@ -1,4 +0,0 @@
1
- export declare function extract(params: {
2
- srcDir: string;
3
- distDir: string;
4
- }): Promise<void>;
@@ -1,38 +0,0 @@
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>;
@@ -1,8 +0,0 @@
1
- import { BuildConfig } from '../typings';
2
- /**
3
- * 覆盖配置,根据游戏引擎类型,设置主包和独立子包的大小限制
4
- * @param entryDir 游戏项目入口目录
5
- * @param config 原始构建配置
6
- * @returns 覆盖后的构建配置
7
- */
8
- export declare function overrideConfig(config: BuildConfig): BuildConfig;