codeplay-common 4.11.35 → 4.11.37

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 (50) hide show
  1. package/CHANGELOG.md +115 -115
  2. package/LICENSE +21 -21
  3. package/README.md +380 -374
  4. package/RELEASE_NOTES.md +110 -110
  5. package/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -9
  6. package/files/buildCodeplay/add-splash-screen.js +256 -256
  7. package/files/buildCodeplay/apk-store-builder.js +97 -97
  8. package/files/buildCodeplay/codeplayBeforeBuild.js +4793 -4793
  9. package/files/buildCodeplay/disabled-ads.mjs +53 -53
  10. package/files/buildCodeplay/fix-onesignal-plugin.js +96 -96
  11. package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -31
  12. package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -28
  13. package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -9
  14. package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -30
  15. package/files/buildCodeplay/huawei-privacy.cjs +102 -92
  16. package/files/buildCodeplay/iap-alias.cjs +116 -116
  17. package/files/buildCodeplay/ios-emi-admob-modification.js +24 -24
  18. package/files/buildCodeplay/manifestModification.js +38 -38
  19. package/files/buildCodeplay/migrate-system-bars.cjs +122 -122
  20. package/files/buildCodeplay/packageidBaseModification.js +528 -528
  21. package/files/buildCodeplay/project-scripts.cjs +69 -69
  22. package/files/buildCodeplay/ruads.cjs +10 -1
  23. package/files/buildCodeplay/setSplashAnimation.js +228 -228
  24. package/files/buildCodeplay/setup-ruads.cjs +9 -2
  25. package/files/buildCodeplay/splash-setup.cjs +88 -88
  26. package/files/buildCodeplay/splashxml/codeplay_splashScreen.xml +11 -11
  27. package/files/buildCodeplay/sync-admob-nextgen.js +219 -219
  28. package/files/buildCodeplay/tests/huawei-live-reload.test.cjs +60 -0
  29. package/files/buildCodeplay/tests/huawei-multiple-entries.test.cjs +80 -0
  30. package/files/buildCodeplay/tests/huawei-vite.test.cjs +38 -35
  31. package/files/buildCodeplay/versions.json +28 -28
  32. package/files/finalrelease +1365 -1365
  33. package/files/generate-ai-promo-video.js +23 -23
  34. package/files/ionic.config.json +6 -6
  35. package/files/scripts-common/run-codeplay-sync-after.js +21 -21
  36. package/files/scripts-common/screenshot/background-decorations.js +120 -120
  37. package/files/scripts-common/screenshot/frame-samples.js +117 -117
  38. package/files/scripts-common/setup-baseline-profile.js +291 -291
  39. package/files/take-screen-video.js +644 -644
  40. package/package.json +29 -29
  41. package/runtime/splash-ready.mjs +52 -52
  42. package/scripts/iap-alias.test.cjs +117 -117
  43. package/scripts/ruads-install.test.cjs +20 -3
  44. package/scripts/splash-setup.test.cjs +142 -142
  45. package/scripts/squeezeback-config.test.cjs +78 -78
  46. package/scripts/sync-files.js +119 -119
  47. package/scripts/system-bars-package.test.cjs +38 -38
  48. package/scripts/system-bars.test.cjs +93 -93
  49. package/scripts/uninstall.js +2 -2
  50. package/scripts/vite-build-settings.test.cjs +1 -0
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "codeplay-common",
3
- "version": "4.11.35",
4
- "description": "Common build scripts and files",
5
- "scripts": {
6
- "postinstall": "node scripts/sync-files.js",
7
- "preinstall": "node scripts/uninstall.js"
8
- },
9
- "dependencies": {
10
- "adm-zip": "^0.6.1",
11
- "plist": "^3.1.0",
12
- "terser": "^5.51.4"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/merbin2012/codeplay-common.git"
17
- },
18
- "author": "Codeplay Technologies",
19
- "license": "MIT",
20
- "files": [
21
- "files/",
22
- "scripts/",
23
- "README.md",
24
- "CHANGELOG.md",
25
- "RELEASE_NOTES.md",
26
- "LICENSE",
27
- "runtime/"
28
- ]
29
- }
1
+ {
2
+ "name": "codeplay-common",
3
+ "version": "4.11.37",
4
+ "description": "Common build scripts and files",
5
+ "scripts": {
6
+ "postinstall": "node scripts/sync-files.js",
7
+ "preinstall": "node scripts/uninstall.js"
8
+ },
9
+ "dependencies": {
10
+ "adm-zip": "^0.6.1",
11
+ "plist": "^3.1.0",
12
+ "terser": "^5.51.4"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/merbin2012/codeplay-common.git"
17
+ },
18
+ "author": "Codeplay Technologies",
19
+ "license": "MIT",
20
+ "files": [
21
+ "files/",
22
+ "scripts/",
23
+ "README.md",
24
+ "CHANGELOG.md",
25
+ "RELEASE_NOTES.md",
26
+ "LICENSE",
27
+ "runtime/"
28
+ ]
29
+ }
@@ -1,52 +1,52 @@
1
- // Framework7 and Capacitor stay owned by the consuming app; no extra dependency.
2
- const registrations = new WeakMap();
3
-
4
- export function hideSplashWhenReady({ f7, hide, imageSelector = '[data-splash-ready], .t-film-art img', timeout = 8000 }) {
5
- if (!f7 || typeof f7.on !== 'function' || typeof f7.off !== 'function' || typeof hide !== 'function') {
6
- throw new TypeError('Splash readiness requires Framework7 and a hide callback.');
7
- }
8
- if (!Number.isInteger(timeout) || timeout < 1 || timeout > 60000) throw new TypeError('Invalid splash readiness timeout.');
9
- if (typeof imageSelector !== 'string') throw new TypeError('Invalid splash image selector.');
10
- if (registrations.has(f7)) return registrations.get(f7);
11
- let finished = false;
12
- let preparing = false;
13
- let image;
14
- const detachImage = () => {
15
- image?.removeEventListener('load', onImageReady);
16
- image?.removeEventListener('error', onImageReady);
17
- };
18
- const finish = () => {
19
- if (finished) return;
20
- finished = true;
21
- clearTimeout(fallback);
22
- f7.off('pageAfterIn', onPageReady);
23
- detachImage();
24
- // Plugin availability differs by platform; failed native hiding must not
25
- // create an unhandled rejection. The native launch timeout is the backup.
26
- try { Promise.resolve(hide()).catch(() => {}); } catch {}
27
- };
28
- const onImageReady = () => {
29
- if (finished) return;
30
- detachImage();
31
- if (image.naturalWidth > 0 && typeof image.decode === 'function') {
32
- Promise.resolve().then(() => image.decode()).catch(() => {}).then(finish);
33
- } else finish();
34
- };
35
- const onPageReady = page => {
36
- if (finished || preparing || !page?.el?.closest('.view-main')) return;
37
- preparing = true;
38
- try { image = imageSelector ? page.el.querySelector(imageSelector) : null; } catch { finish(); return; }
39
- if (!image) finish();
40
- else if (image.complete) onImageReady();
41
- else {
42
- image.addEventListener('load', onImageReady, { once: true });
43
- image.addEventListener('error', onImageReady, { once: true });
44
- }
45
- };
46
- const fallback = setTimeout(finish, timeout);
47
- registrations.set(f7, finish);
48
- f7.on('pageAfterIn', onPageReady);
49
- const currentPage = f7.views?.main?.router?.currentPageEl;
50
- if (currentPage) onPageReady({ el: currentPage });
51
- return finish;
52
- }
1
+ // Framework7 and Capacitor stay owned by the consuming app; no extra dependency.
2
+ const registrations = new WeakMap();
3
+
4
+ export function hideSplashWhenReady({ f7, hide, imageSelector = '[data-splash-ready], .t-film-art img', timeout = 8000 }) {
5
+ if (!f7 || typeof f7.on !== 'function' || typeof f7.off !== 'function' || typeof hide !== 'function') {
6
+ throw new TypeError('Splash readiness requires Framework7 and a hide callback.');
7
+ }
8
+ if (!Number.isInteger(timeout) || timeout < 1 || timeout > 60000) throw new TypeError('Invalid splash readiness timeout.');
9
+ if (typeof imageSelector !== 'string') throw new TypeError('Invalid splash image selector.');
10
+ if (registrations.has(f7)) return registrations.get(f7);
11
+ let finished = false;
12
+ let preparing = false;
13
+ let image;
14
+ const detachImage = () => {
15
+ image?.removeEventListener('load', onImageReady);
16
+ image?.removeEventListener('error', onImageReady);
17
+ };
18
+ const finish = () => {
19
+ if (finished) return;
20
+ finished = true;
21
+ clearTimeout(fallback);
22
+ f7.off('pageAfterIn', onPageReady);
23
+ detachImage();
24
+ // Plugin availability differs by platform; failed native hiding must not
25
+ // create an unhandled rejection. The native launch timeout is the backup.
26
+ try { Promise.resolve(hide()).catch(() => {}); } catch {}
27
+ };
28
+ const onImageReady = () => {
29
+ if (finished) return;
30
+ detachImage();
31
+ if (image.naturalWidth > 0 && typeof image.decode === 'function') {
32
+ Promise.resolve().then(() => image.decode()).catch(() => {}).then(finish);
33
+ } else finish();
34
+ };
35
+ const onPageReady = page => {
36
+ if (finished || preparing || !page?.el?.closest('.view-main')) return;
37
+ preparing = true;
38
+ try { image = imageSelector ? page.el.querySelector(imageSelector) : null; } catch { finish(); return; }
39
+ if (!image) finish();
40
+ else if (image.complete) onImageReady();
41
+ else {
42
+ image.addEventListener('load', onImageReady, { once: true });
43
+ image.addEventListener('error', onImageReady, { once: true });
44
+ }
45
+ };
46
+ const fallback = setTimeout(finish, timeout);
47
+ registrations.set(f7, finish);
48
+ f7.on('pageAfterIn', onPageReady);
49
+ const currentPage = f7.views?.main?.router?.currentPageEl;
50
+ if (currentPage) onPageReady({ el: currentPage });
51
+ return finish;
52
+ }
@@ -1,117 +1,117 @@
1
- const { test } = require('node:test');
2
- const assert = require('node:assert/strict');
3
- const fs = require('node:fs');
4
- const path = require('node:path');
5
- const { pathToFileURL } = require('node:url');
6
- const { syncIapAliases, findLatestIapDirectory, legacyIapPlugin } = require('../files/buildCodeplay/iap-alias.cjs');
7
-
8
- function fixture(alias = '{}') {
9
- const base = path.resolve(process.env.CODEPLAY_TEST_ROOT || path.join(__dirname, '../agent-temp'));
10
- fs.mkdirSync(base, { recursive: true });
11
- const root = fs.mkdtempSync(path.join(base, 'iap-alias-'));
12
- const write = (name, value) => { const file = path.join(root, name); fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, value); return file; };
13
- write('buildCodeplay/iap-alias.cjs', fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/iap-alias.cjs')));
14
- write('src/js/Ads/IAP-4.8/IAP-state.js', 'export const shouldBlockIapAds = () => false;');
15
- write('src/js/Ads/IAP-4.8/IAP-bootstrap.js', 'export const initIAP = () => {};');
16
- write('vite.config.mjs', `export default async () => ({ resolve: { alias: ${alias} }, define: { preserved: true } });`);
17
- return { root, write };
18
- }
19
-
20
- test('migrates imports and re-exports without changing comments, text or F7 templates; repeat is stable', () => {
21
- const f = fixture();
22
- const file = f.write('src/pages/home.f7', `<template><div>import '../IAP-4.9/IAP-state.js'</div></template>\n<script>\n// import '../IAP-4.9/IAP-state.js'\nconst text = "../IAP-4.9/IAP-state.js";\nimport { shouldBlockIapAds } from '../js/Ads/IAP-4.9/IAP-state.js';\nconst module = import('@/js/Ads/IAP-4.9/IAP-bootstrap.js');\nexport { initIAP } from '../js/Ads/IAP-4.9/IAP-bootstrap.js';\n</script>`);
23
- assert.equal(syncIapAliases(f.root, [file]).length, 2);
24
- const result = fs.readFileSync(file, 'utf8');
25
- assert.ok(result.includes("from '@iap/IAP-state.js'"));
26
- assert.ok(result.includes("import('@iap/IAP-bootstrap.js')"));
27
- assert.ok(result.includes("from '@iap/IAP-bootstrap.js'"));
28
- assert.ok(result.includes('// import \'../IAP-4.9/IAP-state.js\''));
29
- assert.ok(result.includes('const text = "../IAP-4.9/IAP-state.js"'));
30
- assert.ok(result.includes('<div>import \'../IAP-4.9/IAP-state.js\'</div>'));
31
- assert.deepEqual(syncIapAliases(f.root, [file]), []);
32
- });
33
-
34
- test('Vite object and array aliases resolve IAP 4.8 and change automatically when a newer folder appears', async () => {
35
- const previous = process.cwd();
36
- try {
37
- for (const aliases of ["{'@existing':'/unchanged'}", "[{ find: '@existing', replacement: '/unchanged' }]"]) {
38
- const f = fixture(aliases); syncIapAliases(f.root); process.chdir(f.root);
39
- const { default: configure } = await import(pathToFileURL(path.join(f.root, 'vite.config.mjs')).href);
40
- const selected = config => Array.isArray(config.resolve.alias) ? config.resolve.alias.find(a => a.find === '@iap').replacement : config.resolve.alias['@iap'];
41
- assert.equal(selected(await configure({})), path.join(f.root, 'src/js/Ads/IAP-4.8'));
42
- f.write('src/js/Ads/IAP-4.10/IAP-state.js', '// newest state');
43
- f.write('src/js/Ads/IAP-5.0/README.txt', 'incomplete');
44
- assert.equal(selected(await configure({})), path.join(f.root, 'src/js/Ads/IAP-4.10'));
45
- assert.equal((await configure({})).define.preserved, true);
46
- assert.equal(findLatestIapDirectory(f.root), path.join(f.root, 'src/js/Ads/IAP-4.10'));
47
- }
48
- } finally { process.chdir(previous); }
49
- });
50
-
51
- test('missing IAP modules fail before any source or Vite changes', () => {
52
- const f = fixture();
53
- const source = "import { x } from '../IAP-4.9/missing.js';";
54
- const file = f.write('src/caller.js', source);
55
- const vite = fs.readFileSync(path.join(f.root, 'vite.config.mjs'), 'utf8');
56
- assert.throws(() => syncIapAliases(f.root, [file]), /Missing @iap\/missing.js/);
57
- assert.equal(fs.readFileSync(file, 'utf8'), source);
58
- assert.equal(fs.readFileSync(path.join(f.root, 'vite.config.mjs'), 'utf8'), vite);
59
- });
60
-
61
- test('existing standard versioned aliases migrate for object and array configurations', async () => {
62
- const previous = process.cwd();
63
- try {
64
- for (const aliases of [
65
- "{'@iap': path.resolve(__dirname, './src/js/Ads/IAP-5.2'), '@existing': '/unchanged'}",
66
- "[{ find: '@iap', replacement: path.resolve(__dirname, './src/js/Ads/IAP-5.2') }, { find: '@existing', replacement: '/unchanged' }]",
67
- ]) {
68
- const f = fixture(aliases);
69
- const vite = path.join(f.root, 'vite.config.mjs');
70
- fs.writeFileSync(vite, "import path from 'node:path';\nconst __dirname = '/old';\n" + fs.readFileSync(vite, 'utf8'));
71
- assert.deepEqual(syncIapAliases(f.root), ['vite.config.mjs']);
72
- process.chdir(f.root);
73
- const { default: configure } = await import(pathToFileURL(vite).href);
74
- const config = await configure();
75
- const entries = Array.isArray(config.resolve.alias) ? Object.fromEntries(config.resolve.alias.map(a => [a.find, a.replacement])) : config.resolve.alias;
76
- assert.equal(entries['@iap'], path.join(f.root, 'src/js/Ads/IAP-4.8'));
77
- assert.equal(entries['@existing'], '/unchanged');
78
- assert.ok(config.plugins.some(plugin => plugin.name === 'codeplay-legacy-iap-imports'));
79
- assert.deepEqual(syncIapAliases(f.root), []);
80
- }
81
- } finally { process.chdir(previous); }
82
- });
83
-
84
- test('custom IAP aliases fail without changing source or Vite configuration', () => {
85
- for (const aliases of [
86
- "{'@iap': path.resolve(__dirname, './custom/IAP-5.2')}",
87
- "[{ find: '@iap', replacement: customIapDirectory() }]",
88
- ]) {
89
- const f = fixture(aliases);
90
- const source = "import { x } from '../IAP-4.9/IAP-state.js';";
91
- const file = f.write('src/caller.js', source);
92
- const vite = path.join(f.root, 'vite.config.mjs');
93
- const original = fs.readFileSync(vite, 'utf8');
94
- assert.throws(() => syncIapAliases(f.root, [file]), /Cannot replace a custom @iap alias/);
95
- assert.equal(fs.readFileSync(vite, 'utf8'), original);
96
- assert.equal(fs.readFileSync(file, 'utf8'), source);
97
- }
98
- });
99
-
100
- test('apps without IAP are left unchanged', () => {
101
- const f = fixture(); fs.unlinkSync(path.join(f.root, 'src/js/Ads/IAP-4.8/IAP-state.js'));
102
- assert.equal(findLatestIapDirectory(f.root), null);
103
- assert.deepEqual(syncIapAliases(f.root), []);
104
- });
105
-
106
- test('protected AdMob source stays unchanged and legacy imports resolve to installed IAP', async () => {
107
- const f = fixture();
108
- const original = "import { shouldBlockIapAds } from '../IAP-4.9/IAP-state.js';";
109
- const file = f.write('src/js/Ads/admob-nextgen-4.7/admob-emi-nextgen.js', original);
110
- syncIapAliases(f.root, [file]);
111
- assert.equal(fs.readFileSync(file, 'utf8'), original);
112
- const plugin = legacyIapPlugin(f.root);
113
- const resolver = { resolve: async target => ({ id: target }) };
114
- const result = await plugin.resolveId.call(resolver, '../IAP-4.9/IAP-state.js', file);
115
- assert.equal(result.id, path.join(f.root, 'src/js/Ads/IAP-4.8/IAP-state.js'));
116
- assert.equal(await plugin.resolveId.call(resolver, '@capacitor/core', file), null);
117
- });
1
+ const { test } = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const { pathToFileURL } = require('node:url');
6
+ const { syncIapAliases, findLatestIapDirectory, legacyIapPlugin } = require('../files/buildCodeplay/iap-alias.cjs');
7
+
8
+ function fixture(alias = '{}') {
9
+ const base = path.resolve(process.env.CODEPLAY_TEST_ROOT || path.join(__dirname, '../agent-temp'));
10
+ fs.mkdirSync(base, { recursive: true });
11
+ const root = fs.mkdtempSync(path.join(base, 'iap-alias-'));
12
+ const write = (name, value) => { const file = path.join(root, name); fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, value); return file; };
13
+ write('buildCodeplay/iap-alias.cjs', fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/iap-alias.cjs')));
14
+ write('src/js/Ads/IAP-4.8/IAP-state.js', 'export const shouldBlockIapAds = () => false;');
15
+ write('src/js/Ads/IAP-4.8/IAP-bootstrap.js', 'export const initIAP = () => {};');
16
+ write('vite.config.mjs', `export default async () => ({ resolve: { alias: ${alias} }, define: { preserved: true } });`);
17
+ return { root, write };
18
+ }
19
+
20
+ test('migrates imports and re-exports without changing comments, text or F7 templates; repeat is stable', () => {
21
+ const f = fixture();
22
+ const file = f.write('src/pages/home.f7', `<template><div>import '../IAP-4.9/IAP-state.js'</div></template>\n<script>\n// import '../IAP-4.9/IAP-state.js'\nconst text = "../IAP-4.9/IAP-state.js";\nimport { shouldBlockIapAds } from '../js/Ads/IAP-4.9/IAP-state.js';\nconst module = import('@/js/Ads/IAP-4.9/IAP-bootstrap.js');\nexport { initIAP } from '../js/Ads/IAP-4.9/IAP-bootstrap.js';\n</script>`);
23
+ assert.equal(syncIapAliases(f.root, [file]).length, 2);
24
+ const result = fs.readFileSync(file, 'utf8');
25
+ assert.ok(result.includes("from '@iap/IAP-state.js'"));
26
+ assert.ok(result.includes("import('@iap/IAP-bootstrap.js')"));
27
+ assert.ok(result.includes("from '@iap/IAP-bootstrap.js'"));
28
+ assert.ok(result.includes('// import \'../IAP-4.9/IAP-state.js\''));
29
+ assert.ok(result.includes('const text = "../IAP-4.9/IAP-state.js"'));
30
+ assert.ok(result.includes('<div>import \'../IAP-4.9/IAP-state.js\'</div>'));
31
+ assert.deepEqual(syncIapAliases(f.root, [file]), []);
32
+ });
33
+
34
+ test('Vite object and array aliases resolve IAP 4.8 and change automatically when a newer folder appears', async () => {
35
+ const previous = process.cwd();
36
+ try {
37
+ for (const aliases of ["{'@existing':'/unchanged'}", "[{ find: '@existing', replacement: '/unchanged' }]"]) {
38
+ const f = fixture(aliases); syncIapAliases(f.root); process.chdir(f.root);
39
+ const { default: configure } = await import(pathToFileURL(path.join(f.root, 'vite.config.mjs')).href);
40
+ const selected = config => Array.isArray(config.resolve.alias) ? config.resolve.alias.find(a => a.find === '@iap').replacement : config.resolve.alias['@iap'];
41
+ assert.equal(selected(await configure({})), path.join(f.root, 'src/js/Ads/IAP-4.8'));
42
+ f.write('src/js/Ads/IAP-4.10/IAP-state.js', '// newest state');
43
+ f.write('src/js/Ads/IAP-5.0/README.txt', 'incomplete');
44
+ assert.equal(selected(await configure({})), path.join(f.root, 'src/js/Ads/IAP-4.10'));
45
+ assert.equal((await configure({})).define.preserved, true);
46
+ assert.equal(findLatestIapDirectory(f.root), path.join(f.root, 'src/js/Ads/IAP-4.10'));
47
+ }
48
+ } finally { process.chdir(previous); }
49
+ });
50
+
51
+ test('missing IAP modules fail before any source or Vite changes', () => {
52
+ const f = fixture();
53
+ const source = "import { x } from '../IAP-4.9/missing.js';";
54
+ const file = f.write('src/caller.js', source);
55
+ const vite = fs.readFileSync(path.join(f.root, 'vite.config.mjs'), 'utf8');
56
+ assert.throws(() => syncIapAliases(f.root, [file]), /Missing @iap\/missing.js/);
57
+ assert.equal(fs.readFileSync(file, 'utf8'), source);
58
+ assert.equal(fs.readFileSync(path.join(f.root, 'vite.config.mjs'), 'utf8'), vite);
59
+ });
60
+
61
+ test('existing standard versioned aliases migrate for object and array configurations', async () => {
62
+ const previous = process.cwd();
63
+ try {
64
+ for (const aliases of [
65
+ "{'@iap': path.resolve(__dirname, './src/js/Ads/IAP-5.2'), '@existing': '/unchanged'}",
66
+ "[{ find: '@iap', replacement: path.resolve(__dirname, './src/js/Ads/IAP-5.2') }, { find: '@existing', replacement: '/unchanged' }]",
67
+ ]) {
68
+ const f = fixture(aliases);
69
+ const vite = path.join(f.root, 'vite.config.mjs');
70
+ fs.writeFileSync(vite, "import path from 'node:path';\nconst __dirname = '/old';\n" + fs.readFileSync(vite, 'utf8'));
71
+ assert.deepEqual(syncIapAliases(f.root), ['vite.config.mjs']);
72
+ process.chdir(f.root);
73
+ const { default: configure } = await import(pathToFileURL(vite).href);
74
+ const config = await configure();
75
+ const entries = Array.isArray(config.resolve.alias) ? Object.fromEntries(config.resolve.alias.map(a => [a.find, a.replacement])) : config.resolve.alias;
76
+ assert.equal(entries['@iap'], path.join(f.root, 'src/js/Ads/IAP-4.8'));
77
+ assert.equal(entries['@existing'], '/unchanged');
78
+ assert.ok(config.plugins.some(plugin => plugin.name === 'codeplay-legacy-iap-imports'));
79
+ assert.deepEqual(syncIapAliases(f.root), []);
80
+ }
81
+ } finally { process.chdir(previous); }
82
+ });
83
+
84
+ test('custom IAP aliases fail without changing source or Vite configuration', () => {
85
+ for (const aliases of [
86
+ "{'@iap': path.resolve(__dirname, './custom/IAP-5.2')}",
87
+ "[{ find: '@iap', replacement: customIapDirectory() }]",
88
+ ]) {
89
+ const f = fixture(aliases);
90
+ const source = "import { x } from '../IAP-4.9/IAP-state.js';";
91
+ const file = f.write('src/caller.js', source);
92
+ const vite = path.join(f.root, 'vite.config.mjs');
93
+ const original = fs.readFileSync(vite, 'utf8');
94
+ assert.throws(() => syncIapAliases(f.root, [file]), /Cannot replace a custom @iap alias/);
95
+ assert.equal(fs.readFileSync(vite, 'utf8'), original);
96
+ assert.equal(fs.readFileSync(file, 'utf8'), source);
97
+ }
98
+ });
99
+
100
+ test('apps without IAP are left unchanged', () => {
101
+ const f = fixture(); fs.unlinkSync(path.join(f.root, 'src/js/Ads/IAP-4.8/IAP-state.js'));
102
+ assert.equal(findLatestIapDirectory(f.root), null);
103
+ assert.deepEqual(syncIapAliases(f.root), []);
104
+ });
105
+
106
+ test('protected AdMob source stays unchanged and legacy imports resolve to installed IAP', async () => {
107
+ const f = fixture();
108
+ const original = "import { shouldBlockIapAds } from '../IAP-4.9/IAP-state.js';";
109
+ const file = f.write('src/js/Ads/admob-nextgen-4.7/admob-emi-nextgen.js', original);
110
+ syncIapAliases(f.root, [file]);
111
+ assert.equal(fs.readFileSync(file, 'utf8'), original);
112
+ const plugin = legacyIapPlugin(f.root);
113
+ const resolver = { resolve: async target => ({ id: target }) };
114
+ const result = await plugin.resolveId.call(resolver, '../IAP-4.9/IAP-state.js', file);
115
+ assert.equal(result.id, path.join(f.root, 'src/js/Ads/IAP-4.8/IAP-state.js'));
116
+ assert.equal(await plugin.resolveId.call(resolver, '@capacitor/core', file), null);
117
+ });
@@ -4,7 +4,7 @@ const fs = require('node:fs');
4
4
  const path = require('node:path');
5
5
  const { pathToFileURL } = require('node:url');
6
6
  const { syncRuAdsSetup } = require('../files/buildCodeplay/setup-ruads.cjs');
7
- const { syncAdProviderPackages } = require('../files/buildCodeplay/ruads.cjs');
7
+ const { syncAdProviderPackages, withBuildCodeplayAlias } = require('../files/buildCodeplay/ruads.cjs');
8
8
  const runtimeRoot = path.resolve(__dirname, '../runtime/vk-ads');
9
9
 
10
10
  function fixture(alias = "{'@admob':'/fixture/admob.js'}") {
@@ -81,6 +81,10 @@ test('Vite selects one store/provider for object and array aliases', async () =>
81
81
  process.env.VITE_STORE_ID = id;
82
82
  const config = await configure({ mode: 'development' });
83
83
  const selected = Array.isArray(config.resolve.alias) ? config.resolve.alias[0].replacement : config.resolve.alias['@admob'];
84
+ const buildAlias = Array.isArray(config.resolve.alias)
85
+ ? config.resolve.alias.find(item => item.find === '/buildCodeplay')?.replacement
86
+ : config.resolve.alias['/buildCodeplay'];
87
+ assert.equal(buildAlias, path.join(f.root, 'buildCodeplay'));
84
88
  assert.equal(config.define['import.meta.env.VITE_STORE_ID'], JSON.stringify(id));
85
89
  assert.equal(config.define['import.meta.env.VITE_RUADS_ENABLED'], JSON.stringify(['4', '10'].includes(id)));
86
90
  assert.equal(selected, ['4', '10'].includes(id) ? path.resolve(f.root, 'src/js/Ads/vk-ads-1.10/vk-ads.js') : '/fixture/admob.js');
@@ -105,12 +109,13 @@ test('Vite selects one store/provider for object and array aliases', async () =>
105
109
  }
106
110
  });
107
111
 
108
- test('existing generated Vite wrapper gains AdMob ID filtering without repeated changes', () => {
112
+ test('existing generated Vite wrapper gains filtering and Huawei path mapping without repeated changes', () => {
109
113
  const f = fixture();
110
114
  syncRuAdsSetup(f.root, { runtimeRoot });
111
115
  const file = path.join(f.root, 'vite.config.mjs');
112
116
  const current = fs.readFileSync(file, 'utf8');
113
- const old = current.replace('plugins: [...(base.plugins || []), ruAdsBuild.admobConfigPlugin(provider)], ', '');
117
+ const old = current.replace('plugins: [...(base.plugins || []), ruAdsBuild.admobConfigPlugin(provider)], ', '')
118
+ .replace("ruAdsBuild.withBuildCodeplayAlias(base.resolve?.alias || {}, codeplayResolve('buildCodeplay'))", 'base.resolve?.alias || {}');
114
119
  assert.notEqual(old, current);
115
120
  fs.writeFileSync(file, old);
116
121
  syncRuAdsSetup(f.root, { runtimeRoot });
@@ -119,6 +124,18 @@ test('existing generated Vite wrapper gains AdMob ID filtering without repeated
119
124
  assert.equal(fs.readFileSync(file, 'utf8'), current);
120
125
  });
121
126
 
127
+ test('Huawei path mapping preserves explicit aliases and does not mutate or duplicate alias arrays', () => {
128
+ const custom = { '/buildCodeplay': '/custom/build', '@app': '/custom/src' };
129
+ assert.deepEqual(withBuildCodeplayAlias(custom, '/default/build'), custom);
130
+ const aliases = [{ find: '@app', replacement: '/custom/src' }];
131
+ const updated = withBuildCodeplayAlias(aliases, '/default/build');
132
+ assert.equal(aliases.length, 1);
133
+ assert.deepEqual(updated, [...aliases, { find: '/buildCodeplay', replacement: '/default/build' }]);
134
+ assert.deepEqual(withBuildCodeplayAlias(updated, '/default/build'), updated);
135
+ const customArray = [{ find: '/buildCodeplay', replacement: '/custom/build' }];
136
+ assert.deepEqual(withBuildCodeplayAlias(customArray, '/default/build'), customArray);
137
+ });
138
+
122
139
  test('installer distributes all RuStore helpers and preserves release credentials', () => {
123
140
  const f = fixture();
124
141
  f.write('buildCodeplay/release-sync.config.json', { token: 'consumer-owned' });