codeplay-common 4.11.28 → 4.11.30
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 +1 -0
- package/README.md +89 -89
- package/RELEASE_NOTES.md +13 -13
- package/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -0
- package/files/buildCodeplay/add-splash-screen.js +1 -1
- package/files/buildCodeplay/codeplayBeforeBuild.js +4756 -4755
- package/files/buildCodeplay/disabled-ads.mjs +45 -45
- package/files/buildCodeplay/ensure-current-build.cjs +42 -42
- package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -31
- package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -28
- package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -9
- package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -30
- package/files/buildCodeplay/huawei-privacy-entry.js +135 -0
- package/files/buildCodeplay/huawei-privacy.cjs +92 -0
- package/files/buildCodeplay/huawei-privacy.css +22 -0
- package/files/buildCodeplay/iap-alias.cjs +116 -108
- package/files/buildCodeplay/ios-ad-consent.cjs +56 -56
- package/files/buildCodeplay/ios-emi-admob-modification.js +25 -25
- package/files/buildCodeplay/migrate-system-bars.cjs +115 -115
- package/files/buildCodeplay/newly added.txt +89 -89
- package/files/buildCodeplay/non-google-billing.pro +3 -3
- package/files/buildCodeplay/release-sync.config.json +4 -4
- package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
- package/files/buildCodeplay/ruads.cjs +211 -211
- package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -21
- package/files/buildCodeplay/setSplashAnimation.js +2 -2
- package/files/buildCodeplay/setup-ruads.cjs +55 -55
- package/files/buildCodeplay/splash-setup.cjs +88 -88
- package/files/buildCodeplay/store-billing.cjs +43 -43
- package/files/buildCodeplay/tests/huawei-privacy.test.cjs +49 -0
- package/files/buildCodeplay/tests/huawei-vite.test.cjs +35 -0
- package/files/scripts-common/generate-baseline-profile.js +46 -46
- package/files/take-screen-image.js +4414 -4414
- package/package.json +28 -28
- package/runtime/splash-ready.mjs +52 -52
- package/runtime/vk-ads/vk-ad-configuration.json +39 -39
- package/scripts/ensure-current-build.test.cjs +76 -76
- package/scripts/iap-alias.test.cjs +117 -78
- package/scripts/ios-ad-consent.test.cjs +99 -99
- package/scripts/ruads-install.test.cjs +180 -180
- package/scripts/ruads-policy.test.cjs +174 -174
- package/scripts/saf-mediastore-dependency.test.cjs +44 -44
- package/scripts/splash-setup.test.cjs +142 -142
- package/scripts/sync-files.js +1 -1
- package/scripts/system-bars.test.cjs +77 -77
- package/scripts/vite-build-settings.test.cjs +92 -92
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "codeplay-common",
|
|
3
|
-
"version": "4.11.
|
|
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
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "https://github.com/merbin2012/codeplay-common.git"
|
|
16
|
-
},
|
|
17
|
-
"author": "Codeplay Technologies",
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"files": [
|
|
20
|
-
"files/",
|
|
21
|
-
"scripts/",
|
|
22
|
-
"README.md",
|
|
23
|
-
"CHANGELOG.md",
|
|
24
|
-
"RELEASE_NOTES.md",
|
|
25
|
-
"LICENSE",
|
|
26
|
-
"runtime/"
|
|
27
|
-
]
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "codeplay-common",
|
|
3
|
+
"version": "4.11.30",
|
|
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
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/merbin2012/codeplay-common.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "Codeplay Technologies",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"files": [
|
|
20
|
+
"files/",
|
|
21
|
+
"scripts/",
|
|
22
|
+
"README.md",
|
|
23
|
+
"CHANGELOG.md",
|
|
24
|
+
"RELEASE_NOTES.md",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"runtime/"
|
|
27
|
+
]
|
|
28
|
+
}
|
package/runtime/splash-ready.mjs
CHANGED
|
@@ -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,39 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"VERSION": "1.2",
|
|
3
|
-
"android": {
|
|
4
|
-
"HuaweiStore": {
|
|
5
|
-
"appId": 0,
|
|
6
|
-
"bannerSlotId": 0,
|
|
7
|
-
"interstitialSlotId": 0,
|
|
8
|
-
"rewardedSlotId": 0
|
|
9
|
-
},
|
|
10
|
-
"RuStore": {
|
|
11
|
-
"appId": 0,
|
|
12
|
-
"bannerSlotId": 0,
|
|
13
|
-
"interstitialSlotId": 0,
|
|
14
|
-
"rewardedSlotId": 0
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"config": {
|
|
18
|
-
"isTesting": false,
|
|
19
|
-
"bannerEnabled": true,
|
|
20
|
-
"bannerSize": "320x50",
|
|
21
|
-
"bannerDisabledPages": [],
|
|
22
|
-
"bannerStartupDelayMs": 3000,
|
|
23
|
-
"interstitialEnabled": true,
|
|
24
|
-
"interstitialStartupDelayMs": 30000,
|
|
25
|
-
"minimumClick": 2,
|
|
26
|
-
"interstitialFirstTimeOutMs": 252000,
|
|
27
|
-
"interstitialTimeOutMs": 360000,
|
|
28
|
-
"interstitialPerSession": 8,
|
|
29
|
-
"rewardVideoEnabled": true,
|
|
30
|
-
"userAgeRestricted": false,
|
|
31
|
-
"retryDelayMs": 30000,
|
|
32
|
-
"debug": false
|
|
33
|
-
},
|
|
34
|
-
"testid": {
|
|
35
|
-
"bannerSlotId": 794557,
|
|
36
|
-
"interstitialSlotId": 6481,
|
|
37
|
-
"rewardedSlotId": 45101
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"VERSION": "1.2",
|
|
3
|
+
"android": {
|
|
4
|
+
"HuaweiStore": {
|
|
5
|
+
"appId": 0,
|
|
6
|
+
"bannerSlotId": 0,
|
|
7
|
+
"interstitialSlotId": 0,
|
|
8
|
+
"rewardedSlotId": 0
|
|
9
|
+
},
|
|
10
|
+
"RuStore": {
|
|
11
|
+
"appId": 0,
|
|
12
|
+
"bannerSlotId": 0,
|
|
13
|
+
"interstitialSlotId": 0,
|
|
14
|
+
"rewardedSlotId": 0
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"config": {
|
|
18
|
+
"isTesting": false,
|
|
19
|
+
"bannerEnabled": true,
|
|
20
|
+
"bannerSize": "320x50",
|
|
21
|
+
"bannerDisabledPages": [],
|
|
22
|
+
"bannerStartupDelayMs": 3000,
|
|
23
|
+
"interstitialEnabled": true,
|
|
24
|
+
"interstitialStartupDelayMs": 30000,
|
|
25
|
+
"minimumClick": 2,
|
|
26
|
+
"interstitialFirstTimeOutMs": 252000,
|
|
27
|
+
"interstitialTimeOutMs": 360000,
|
|
28
|
+
"interstitialPerSession": 8,
|
|
29
|
+
"rewardVideoEnabled": true,
|
|
30
|
+
"userAgeRestricted": false,
|
|
31
|
+
"retryDelayMs": 30000,
|
|
32
|
+
"debug": false
|
|
33
|
+
},
|
|
34
|
+
"testid": {
|
|
35
|
+
"bannerSlotId": 794557,
|
|
36
|
+
"interstitialSlotId": 6481,
|
|
37
|
+
"rewardedSlotId": 45101
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
const { test } = require('node:test');
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const { ensureCurrentBuild } = require('../files/buildCodeplay/ensure-current-build.cjs');
|
|
7
|
-
const { removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
|
|
8
|
-
|
|
9
|
-
function fixture(t, names = []) {
|
|
10
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'codeplay-legacy-build-'));
|
|
11
|
-
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
12
|
-
fs.mkdirSync(path.join(root, 'buildCodeplay'));
|
|
13
|
-
for (const name of ['codeplayBeforeBuild.js', ...names]) fs.writeFileSync(path.join(root, 'buildCodeplay', name), '');
|
|
14
|
-
return root;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
test('current structure continues without npm commands', t => {
|
|
18
|
-
const projectRoot = fixture(t, ['versions.json', 'custom-helper.js']);
|
|
19
|
-
assert.equal(ensureCurrentBuild({ projectRoot, runNpm: () => assert.fail('unexpected npm command') }), false);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('legacy files force ordered reinstall and fresh preparation before continuing', t => {
|
|
23
|
-
const projectRoot = fixture(t, ['codeplayBeforeBuild-6.7.js', 'setSplashAnimation-1.2.mjs']);
|
|
24
|
-
const calls = [];
|
|
25
|
-
assert.equal(ensureCurrentBuild({
|
|
26
|
-
projectRoot,
|
|
27
|
-
runNpm(command) {
|
|
28
|
-
calls.push(command);
|
|
29
|
-
if (command === 'npm install codeplay-common') removeVersionedBuildScripts(projectRoot);
|
|
30
|
-
},
|
|
31
|
-
runBeforeBuild(script) {
|
|
32
|
-
assert.equal(script, path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js'));
|
|
33
|
-
calls.push('fresh preparation');
|
|
34
|
-
},
|
|
35
|
-
}), true);
|
|
36
|
-
assert.deepEqual(calls, ['npm uninstall codeplay-common', 'npm install codeplay-common', 'fresh preparation']);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
for (const failedCommand of ['npm uninstall codeplay-common', 'npm install codeplay-common']) {
|
|
40
|
-
test(`failure of ${failedCommand} stops preparation`, t => {
|
|
41
|
-
const projectRoot = fixture(t, ['add-splash-screen-1.0.js']);
|
|
42
|
-
const calls = [];
|
|
43
|
-
assert.throws(() => ensureCurrentBuild({
|
|
44
|
-
projectRoot,
|
|
45
|
-
runNpm(command) {
|
|
46
|
-
calls.push(command);
|
|
47
|
-
if (command === failedCommand) throw new Error('npm failed');
|
|
48
|
-
},
|
|
49
|
-
runBeforeBuild: () => assert.fail('must not continue'),
|
|
50
|
-
}), /npm failed/);
|
|
51
|
-
assert.equal(calls.at(-1), failedCommand);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
test('unknown versioned files trigger reinstall but stop without deleting app files or looping', t => {
|
|
56
|
-
const projectRoot = fixture(t, ['custom-helper-1.0.js']);
|
|
57
|
-
const calls = [];
|
|
58
|
-
assert.throws(() => ensureCurrentBuild({
|
|
59
|
-
projectRoot,
|
|
60
|
-
runNpm: command => calls.push(command),
|
|
61
|
-
runBeforeBuild: () => assert.fail('must not continue'),
|
|
62
|
-
}), /Legacy buildCodeplay files remain/);
|
|
63
|
-
assert.deepEqual(calls, ['npm uninstall codeplay-common', 'npm install codeplay-common']);
|
|
64
|
-
assert.ok(fs.existsSync(path.join(projectRoot, 'buildCodeplay', 'custom-helper-1.0.js')));
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('failed refreshed preparation propagates to stop the build', t => {
|
|
68
|
-
const projectRoot = fixture(t, ['packageidBaseModification-1.0.js']);
|
|
69
|
-
assert.throws(() => ensureCurrentBuild({
|
|
70
|
-
projectRoot,
|
|
71
|
-
runNpm(command) {
|
|
72
|
-
if (command === 'npm install codeplay-common') removeVersionedBuildScripts(projectRoot);
|
|
73
|
-
},
|
|
74
|
-
runBeforeBuild() { throw Object.assign(new Error('preparation failed'), { status: 7 }); },
|
|
75
|
-
}), { message: 'preparation failed', status: 7 });
|
|
76
|
-
});
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { ensureCurrentBuild } = require('../files/buildCodeplay/ensure-current-build.cjs');
|
|
7
|
+
const { removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
|
|
8
|
+
|
|
9
|
+
function fixture(t, names = []) {
|
|
10
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'codeplay-legacy-build-'));
|
|
11
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
12
|
+
fs.mkdirSync(path.join(root, 'buildCodeplay'));
|
|
13
|
+
for (const name of ['codeplayBeforeBuild.js', ...names]) fs.writeFileSync(path.join(root, 'buildCodeplay', name), '');
|
|
14
|
+
return root;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('current structure continues without npm commands', t => {
|
|
18
|
+
const projectRoot = fixture(t, ['versions.json', 'custom-helper.js']);
|
|
19
|
+
assert.equal(ensureCurrentBuild({ projectRoot, runNpm: () => assert.fail('unexpected npm command') }), false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('legacy files force ordered reinstall and fresh preparation before continuing', t => {
|
|
23
|
+
const projectRoot = fixture(t, ['codeplayBeforeBuild-6.7.js', 'setSplashAnimation-1.2.mjs']);
|
|
24
|
+
const calls = [];
|
|
25
|
+
assert.equal(ensureCurrentBuild({
|
|
26
|
+
projectRoot,
|
|
27
|
+
runNpm(command) {
|
|
28
|
+
calls.push(command);
|
|
29
|
+
if (command === 'npm install codeplay-common') removeVersionedBuildScripts(projectRoot);
|
|
30
|
+
},
|
|
31
|
+
runBeforeBuild(script) {
|
|
32
|
+
assert.equal(script, path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js'));
|
|
33
|
+
calls.push('fresh preparation');
|
|
34
|
+
},
|
|
35
|
+
}), true);
|
|
36
|
+
assert.deepEqual(calls, ['npm uninstall codeplay-common', 'npm install codeplay-common', 'fresh preparation']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
for (const failedCommand of ['npm uninstall codeplay-common', 'npm install codeplay-common']) {
|
|
40
|
+
test(`failure of ${failedCommand} stops preparation`, t => {
|
|
41
|
+
const projectRoot = fixture(t, ['add-splash-screen-1.0.js']);
|
|
42
|
+
const calls = [];
|
|
43
|
+
assert.throws(() => ensureCurrentBuild({
|
|
44
|
+
projectRoot,
|
|
45
|
+
runNpm(command) {
|
|
46
|
+
calls.push(command);
|
|
47
|
+
if (command === failedCommand) throw new Error('npm failed');
|
|
48
|
+
},
|
|
49
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
50
|
+
}), /npm failed/);
|
|
51
|
+
assert.equal(calls.at(-1), failedCommand);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
test('unknown versioned files trigger reinstall but stop without deleting app files or looping', t => {
|
|
56
|
+
const projectRoot = fixture(t, ['custom-helper-1.0.js']);
|
|
57
|
+
const calls = [];
|
|
58
|
+
assert.throws(() => ensureCurrentBuild({
|
|
59
|
+
projectRoot,
|
|
60
|
+
runNpm: command => calls.push(command),
|
|
61
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
62
|
+
}), /Legacy buildCodeplay files remain/);
|
|
63
|
+
assert.deepEqual(calls, ['npm uninstall codeplay-common', 'npm install codeplay-common']);
|
|
64
|
+
assert.ok(fs.existsSync(path.join(projectRoot, 'buildCodeplay', 'custom-helper-1.0.js')));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('failed refreshed preparation propagates to stop the build', t => {
|
|
68
|
+
const projectRoot = fixture(t, ['packageidBaseModification-1.0.js']);
|
|
69
|
+
assert.throws(() => ensureCurrentBuild({
|
|
70
|
+
projectRoot,
|
|
71
|
+
runNpm(command) {
|
|
72
|
+
if (command === 'npm install codeplay-common') removeVersionedBuildScripts(projectRoot);
|
|
73
|
+
},
|
|
74
|
+
runBeforeBuild() { throw Object.assign(new Error('preparation failed'), { status: 7 }); },
|
|
75
|
+
}), { message: 'preparation failed', status: 7 });
|
|
76
|
+
});
|
|
@@ -1,78 +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('
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
});
|