codeplay-common 4.11.35 → 4.11.38
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/CHANGELOG.md +115 -115
- package/LICENSE +21 -21
- package/README.md +408 -374
- package/RELEASE_NOTES.md +97 -97
- package/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -9
- package/files/buildCodeplay/add-splash-screen.js +255 -255
- package/files/buildCodeplay/apk-store-builder.js +97 -97
- package/files/buildCodeplay/codeplayBeforeBuild.js +4793 -4793
- package/files/buildCodeplay/disabled-ads.mjs +53 -53
- package/files/buildCodeplay/ensure-current-build.cjs +42 -42
- package/files/buildCodeplay/fix-onesignal-plugin.js +96 -96
- package/files/buildCodeplay/huawei-privacy-entry.js +135 -135
- package/files/buildCodeplay/huawei-privacy.cjs +102 -92
- package/files/buildCodeplay/huawei-privacy.css +22 -22
- package/files/buildCodeplay/iap-alias.cjs +116 -116
- package/files/buildCodeplay/ios-ad-consent.cjs +56 -56
- package/files/buildCodeplay/ios-emi-admob-modification.js +49 -49
- package/files/buildCodeplay/manifestModification.js +38 -38
- package/files/buildCodeplay/migrate-system-bars.cjs +122 -122
- package/files/buildCodeplay/newly added.txt +89 -89
- package/files/buildCodeplay/non-google-billing.pro +3 -3
- package/files/buildCodeplay/packageidBaseModification.js +528 -528
- package/files/buildCodeplay/project-scripts.cjs +69 -69
- package/files/buildCodeplay/release-sync.config.json +4 -4
- package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
- package/files/buildCodeplay/ruads.cjs +220 -211
- package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -21
- package/files/buildCodeplay/setSplashAnimation.js +226 -226
- package/files/buildCodeplay/setup-ruads.cjs +62 -55
- package/files/buildCodeplay/splashxml/codeplay_splashScreen.xml +11 -11
- package/files/buildCodeplay/store-billing.cjs +43 -43
- package/files/buildCodeplay/sync-admob-nextgen.js +219 -219
- package/files/buildCodeplay/tests/huawei-live-reload.test.cjs +60 -0
- package/files/buildCodeplay/tests/huawei-multiple-entries.test.cjs +80 -0
- package/files/buildCodeplay/tests/huawei-privacy.test.cjs +49 -49
- package/files/buildCodeplay/tests/huawei-vite.test.cjs +38 -35
- package/files/buildCodeplay/versions.json +28 -28
- package/files/finalrelease +1365 -1365
- package/files/generate-ai-promo-video.js +23 -23
- package/files/ionic.config.json +6 -6
- package/files/scripts-common/collect-startup-profile.js +134 -0
- package/files/scripts-common/generate-baseline-profile.js +194 -22
- package/files/scripts-common/run-codeplay-sync-after.js +21 -21
- package/files/scripts-common/screenshot/background-decorations.js +120 -120
- package/files/scripts-common/screenshot/frame-samples.js +117 -117
- package/files/scripts-common/setup-baseline-profile.js +291 -291
- package/files/take-screen-image.js +4414 -4414
- package/files/take-screen-video.js +644 -644
- package/package.json +29 -29
- package/runtime/vk-ads/vk-ad-configuration.json +39 -39
- package/scripts/baseline-profile.test.cjs +189 -0
- package/scripts/ensure-current-build.test.cjs +76 -76
- package/scripts/iap-alias.test.cjs +117 -117
- package/scripts/ios-ad-consent.test.cjs +99 -99
- package/scripts/ruads-install.test.cjs +197 -180
- package/scripts/ruads-policy.test.cjs +174 -174
- package/scripts/saf-mediastore-dependency.test.cjs +44 -44
- package/scripts/squeezeback-config.test.cjs +78 -78
- package/scripts/sync-files.js +120 -120
- package/scripts/system-bars-package.test.cjs +38 -38
- package/scripts/system-bars.test.cjs +93 -93
- package/scripts/uninstall.js +2 -2
- package/scripts/vite-build-settings.test.cjs +93 -92
|
@@ -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
|
+
});
|
|
@@ -1,99 +1,99 @@
|
|
|
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 { prepareIOSAdConsent } = require('../files/buildCodeplay/ios-ad-consent.cjs');
|
|
6
|
-
const { createRequire } = require('node:module');
|
|
7
|
-
const vm = require('node:vm');
|
|
8
|
-
const { install } = require('./sync-files.js');
|
|
9
|
-
|
|
10
|
-
function fixture(t, sources) {
|
|
11
|
-
const tempRoot = path.resolve(__dirname, '../agent-temp/ios-ad-consent-tests');
|
|
12
|
-
fs.mkdirSync(tempRoot, { recursive: true });
|
|
13
|
-
const root = fs.mkdtempSync(path.join(tempRoot, 'case-'));
|
|
14
|
-
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
15
|
-
for (const [name, content] of Object.entries(sources)) {
|
|
16
|
-
const file = path.join(root, 'ios/App/App', name);
|
|
17
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
18
|
-
fs.writeFileSync(file, content);
|
|
19
|
-
}
|
|
20
|
-
return { root, read: name => fs.readFileSync(path.join(root, 'ios/App/App', name), 'utf8') };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const legacyScene = `import UIKit
|
|
24
|
-
import AppTrackingTransparency
|
|
25
|
-
class SceneDelegate {
|
|
26
|
-
private var isTrackingAuthorizationRequestScheduled = false
|
|
27
|
-
func sceneDidBecomeActive() {
|
|
28
|
-
if ATTrackingManager.trackingAuthorizationStatus == .notDetermined &&
|
|
29
|
-
!isTrackingAuthorizationRequestScheduled {
|
|
30
|
-
isTrackingAuthorizationRequestScheduled = true
|
|
31
|
-
|
|
32
|
-
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
|
|
33
|
-
self?.isTrackingAuthorizationRequestScheduled = false
|
|
34
|
-
|
|
35
|
-
guard UIApplication.shared.applicationState == .active,
|
|
36
|
-
ATTrackingManager.trackingAuthorizationStatus == .notDetermined else { return }
|
|
37
|
-
|
|
38
|
-
ATTrackingManager.requestTrackingAuthorization { _ in }
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
keepOtherStartupCode()
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
`;
|
|
45
|
-
|
|
46
|
-
test('removes the known scene startup request with LF, CRLF and changed indentation', t => {
|
|
47
|
-
for (const source of [legacyScene, legacyScene.replace(/\n/g, '\r\n'), legacyScene.replace(/ /g, '\t')]) {
|
|
48
|
-
const f = fixture(t, { 'SceneDelegate.swift': source });
|
|
49
|
-
assert.equal(prepareIOSAdConsent(f.root, () => {}).length, 1);
|
|
50
|
-
assert.doesNotMatch(f.read('SceneDelegate.swift'), /ATTrackingManager|AppTrackingTransparency|isTrackingAuthorizationRequestScheduled/);
|
|
51
|
-
assert.match(f.read('SceneDelegate.swift'), /keepOtherStartupCode\(\)/);
|
|
52
|
-
assert.deepEqual(prepareIOSAdConsent(f.root, () => {}), [], 'Migration is idempotent');
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('rejects an AppDelegate ATT request even without a SceneDelegate', t => {
|
|
57
|
-
const source = 'ATTrackingManager\n .requestTrackingAuthorization { _ in }';
|
|
58
|
-
const f = fixture(t, { 'AppDelegate.swift': source });
|
|
59
|
-
assert.throws(() => prepareIOSAdConsent(f.root, () => {}), /AppDelegate.swift requests ATT/);
|
|
60
|
-
assert.equal(f.read('AppDelegate.swift'), source);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('checks nested app code and validates everything before migrating the scene', t => {
|
|
64
|
-
const f = fixture(t, {
|
|
65
|
-
'SceneDelegate.swift': legacyScene,
|
|
66
|
-
'Startup/Permissions.m': '[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:handler];',
|
|
67
|
-
});
|
|
68
|
-
assert.throws(() => prepareIOSAdConsent(f.root, () => {}), /Permissions.m requests ATT/);
|
|
69
|
-
assert.equal(f.read('SceneDelegate.swift'), legacyScene, 'No partial edits when validation fails');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('preserves custom native code and ignores commented ATT examples', t => {
|
|
73
|
-
const source = '// ATTrackingManager.requestTrackingAuthorization { _ in }\n/* ATTrackingManager.requestTrackingAuthorization */\nkeepOtherStartupCode()';
|
|
74
|
-
const f = fixture(t, { 'AppDelegate.swift': source });
|
|
75
|
-
assert.deepEqual(prepareIOSAdConsent(f.root, () => {}), []);
|
|
76
|
-
assert.equal(f.read('AppDelegate.swift'), source);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('installer ships the guard and generated before-build invokes it from the consuming app', t => {
|
|
80
|
-
const f = fixture(t, { 'SceneDelegate.swift': legacyScene });
|
|
81
|
-
fs.writeFileSync(path.join(f.root, 'package.json'), JSON.stringify({ name: 'consent-fixture', scripts: {} }));
|
|
82
|
-
fs.writeFileSync(path.join(f.root, 'capacitor.config.json'), JSON.stringify({ appId: 'fixture.app' }));
|
|
83
|
-
install({ projectRoot: f.root, copyAssets: false });
|
|
84
|
-
const beforeBuild = path.join(f.root, 'buildCodeplay/codeplayBeforeBuild.js');
|
|
85
|
-
const source = fs.readFileSync(beforeBuild, 'utf8').replace(/\r\n/g, '\n');
|
|
86
|
-
const start = source.indexOf('function updateIOSStartupForAdConsent() {');
|
|
87
|
-
const end = source.indexOf('\n\n\ntry {', start);
|
|
88
|
-
assert.ok(start >= 0 && end > start);
|
|
89
|
-
assert.ok(fs.existsSync(path.join(f.root, 'buildCodeplay/ios-ad-consent.cjs')));
|
|
90
|
-
vm.runInNewContext(source.slice(start, end) + '\nupdateIOSStartupForAdConsent();', {
|
|
91
|
-
require: createRequire(beforeBuild), process: { cwd: () => f.root },
|
|
92
|
-
});
|
|
93
|
-
assert.doesNotMatch(f.read('SceneDelegate.swift'), /requestTrackingAuthorization/);
|
|
94
|
-
assert.match(f.read('SceneDelegate.swift'), /keepOtherStartupCode\(\)/);
|
|
95
|
-
fs.writeFileSync(path.join(f.root, 'ios/App/App/AppDelegate.swift'), 'ATTrackingManager.requestTrackingAuthorization { _ in }');
|
|
96
|
-
assert.throws(() => vm.runInNewContext(source.slice(start, end) + '\nupdateIOSStartupForAdConsent();', {
|
|
97
|
-
require: createRequire(beforeBuild), process: { cwd: () => f.root },
|
|
98
|
-
}), /AppDelegate.swift requests ATT/);
|
|
99
|
-
});
|
|
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 { prepareIOSAdConsent } = require('../files/buildCodeplay/ios-ad-consent.cjs');
|
|
6
|
+
const { createRequire } = require('node:module');
|
|
7
|
+
const vm = require('node:vm');
|
|
8
|
+
const { install } = require('./sync-files.js');
|
|
9
|
+
|
|
10
|
+
function fixture(t, sources) {
|
|
11
|
+
const tempRoot = path.resolve(__dirname, '../agent-temp/ios-ad-consent-tests');
|
|
12
|
+
fs.mkdirSync(tempRoot, { recursive: true });
|
|
13
|
+
const root = fs.mkdtempSync(path.join(tempRoot, 'case-'));
|
|
14
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
15
|
+
for (const [name, content] of Object.entries(sources)) {
|
|
16
|
+
const file = path.join(root, 'ios/App/App', name);
|
|
17
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
18
|
+
fs.writeFileSync(file, content);
|
|
19
|
+
}
|
|
20
|
+
return { root, read: name => fs.readFileSync(path.join(root, 'ios/App/App', name), 'utf8') };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const legacyScene = `import UIKit
|
|
24
|
+
import AppTrackingTransparency
|
|
25
|
+
class SceneDelegate {
|
|
26
|
+
private var isTrackingAuthorizationRequestScheduled = false
|
|
27
|
+
func sceneDidBecomeActive() {
|
|
28
|
+
if ATTrackingManager.trackingAuthorizationStatus == .notDetermined &&
|
|
29
|
+
!isTrackingAuthorizationRequestScheduled {
|
|
30
|
+
isTrackingAuthorizationRequestScheduled = true
|
|
31
|
+
|
|
32
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
|
|
33
|
+
self?.isTrackingAuthorizationRequestScheduled = false
|
|
34
|
+
|
|
35
|
+
guard UIApplication.shared.applicationState == .active,
|
|
36
|
+
ATTrackingManager.trackingAuthorizationStatus == .notDetermined else { return }
|
|
37
|
+
|
|
38
|
+
ATTrackingManager.requestTrackingAuthorization { _ in }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
keepOtherStartupCode()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
test('removes the known scene startup request with LF, CRLF and changed indentation', t => {
|
|
47
|
+
for (const source of [legacyScene, legacyScene.replace(/\n/g, '\r\n'), legacyScene.replace(/ /g, '\t')]) {
|
|
48
|
+
const f = fixture(t, { 'SceneDelegate.swift': source });
|
|
49
|
+
assert.equal(prepareIOSAdConsent(f.root, () => {}).length, 1);
|
|
50
|
+
assert.doesNotMatch(f.read('SceneDelegate.swift'), /ATTrackingManager|AppTrackingTransparency|isTrackingAuthorizationRequestScheduled/);
|
|
51
|
+
assert.match(f.read('SceneDelegate.swift'), /keepOtherStartupCode\(\)/);
|
|
52
|
+
assert.deepEqual(prepareIOSAdConsent(f.root, () => {}), [], 'Migration is idempotent');
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('rejects an AppDelegate ATT request even without a SceneDelegate', t => {
|
|
57
|
+
const source = 'ATTrackingManager\n .requestTrackingAuthorization { _ in }';
|
|
58
|
+
const f = fixture(t, { 'AppDelegate.swift': source });
|
|
59
|
+
assert.throws(() => prepareIOSAdConsent(f.root, () => {}), /AppDelegate.swift requests ATT/);
|
|
60
|
+
assert.equal(f.read('AppDelegate.swift'), source);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('checks nested app code and validates everything before migrating the scene', t => {
|
|
64
|
+
const f = fixture(t, {
|
|
65
|
+
'SceneDelegate.swift': legacyScene,
|
|
66
|
+
'Startup/Permissions.m': '[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:handler];',
|
|
67
|
+
});
|
|
68
|
+
assert.throws(() => prepareIOSAdConsent(f.root, () => {}), /Permissions.m requests ATT/);
|
|
69
|
+
assert.equal(f.read('SceneDelegate.swift'), legacyScene, 'No partial edits when validation fails');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('preserves custom native code and ignores commented ATT examples', t => {
|
|
73
|
+
const source = '// ATTrackingManager.requestTrackingAuthorization { _ in }\n/* ATTrackingManager.requestTrackingAuthorization */\nkeepOtherStartupCode()';
|
|
74
|
+
const f = fixture(t, { 'AppDelegate.swift': source });
|
|
75
|
+
assert.deepEqual(prepareIOSAdConsent(f.root, () => {}), []);
|
|
76
|
+
assert.equal(f.read('AppDelegate.swift'), source);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('installer ships the guard and generated before-build invokes it from the consuming app', t => {
|
|
80
|
+
const f = fixture(t, { 'SceneDelegate.swift': legacyScene });
|
|
81
|
+
fs.writeFileSync(path.join(f.root, 'package.json'), JSON.stringify({ name: 'consent-fixture', scripts: {} }));
|
|
82
|
+
fs.writeFileSync(path.join(f.root, 'capacitor.config.json'), JSON.stringify({ appId: 'fixture.app' }));
|
|
83
|
+
install({ projectRoot: f.root, copyAssets: false });
|
|
84
|
+
const beforeBuild = path.join(f.root, 'buildCodeplay/codeplayBeforeBuild.js');
|
|
85
|
+
const source = fs.readFileSync(beforeBuild, 'utf8').replace(/\r\n/g, '\n');
|
|
86
|
+
const start = source.indexOf('function updateIOSStartupForAdConsent() {');
|
|
87
|
+
const end = source.indexOf('\n\n\ntry {', start);
|
|
88
|
+
assert.ok(start >= 0 && end > start);
|
|
89
|
+
assert.ok(fs.existsSync(path.join(f.root, 'buildCodeplay/ios-ad-consent.cjs')));
|
|
90
|
+
vm.runInNewContext(source.slice(start, end) + '\nupdateIOSStartupForAdConsent();', {
|
|
91
|
+
require: createRequire(beforeBuild), process: { cwd: () => f.root },
|
|
92
|
+
});
|
|
93
|
+
assert.doesNotMatch(f.read('SceneDelegate.swift'), /requestTrackingAuthorization/);
|
|
94
|
+
assert.match(f.read('SceneDelegate.swift'), /keepOtherStartupCode\(\)/);
|
|
95
|
+
fs.writeFileSync(path.join(f.root, 'ios/App/App/AppDelegate.swift'), 'ATTrackingManager.requestTrackingAuthorization { _ in }');
|
|
96
|
+
assert.throws(() => vm.runInNewContext(source.slice(start, end) + '\nupdateIOSStartupForAdConsent();', {
|
|
97
|
+
require: createRequire(beforeBuild), process: { cwd: () => f.root },
|
|
98
|
+
}), /AppDelegate.swift requests ATT/);
|
|
99
|
+
});
|