codeplay-common 4.11.30 → 4.11.32

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 (58) hide show
  1. package/CHANGELOG.md +115 -115
  2. package/LICENSE +21 -21
  3. package/README.md +368 -368
  4. package/RELEASE_NOTES.md +97 -97
  5. package/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -9
  6. package/files/buildCodeplay/add-splash-screen.js +255 -255
  7. package/files/buildCodeplay/apk-store-builder.js +97 -97
  8. package/files/buildCodeplay/codeplayBeforeBuild.js +4769 -4756
  9. package/files/buildCodeplay/disabled-ads.mjs +45 -45
  10. package/files/buildCodeplay/ensure-current-build.cjs +42 -42
  11. package/files/buildCodeplay/fix-onesignal-plugin.js +96 -96
  12. package/files/buildCodeplay/huawei-privacy-entry.js +135 -135
  13. package/files/buildCodeplay/huawei-privacy.cjs +92 -92
  14. package/files/buildCodeplay/huawei-privacy.css +22 -22
  15. package/files/buildCodeplay/iap-alias.cjs +108 -116
  16. package/files/buildCodeplay/ios-ad-consent.cjs +56 -56
  17. package/files/buildCodeplay/ios-emi-admob-modification.js +49 -49
  18. package/files/buildCodeplay/manifestModification.js +38 -38
  19. package/files/buildCodeplay/migrate-system-bars.cjs +122 -115
  20. package/files/buildCodeplay/newly added.txt +89 -89
  21. package/files/buildCodeplay/non-google-billing.pro +3 -3
  22. package/files/buildCodeplay/packageidBaseModification.js +528 -528
  23. package/files/buildCodeplay/project-scripts.cjs +69 -69
  24. package/files/buildCodeplay/release-sync.config.json +4 -4
  25. package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
  26. package/files/buildCodeplay/ruads.cjs +211 -211
  27. package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -21
  28. package/files/buildCodeplay/setSplashAnimation.js +226 -226
  29. package/files/buildCodeplay/setup-ruads.cjs +55 -55
  30. package/files/buildCodeplay/splashxml/codeplay_splashScreen.xml +11 -11
  31. package/files/buildCodeplay/store-billing.cjs +43 -43
  32. package/files/buildCodeplay/sync-admob-nextgen.js +219 -219
  33. package/files/buildCodeplay/tests/huawei-privacy.test.cjs +49 -49
  34. package/files/buildCodeplay/tests/huawei-vite.test.cjs +35 -35
  35. package/files/buildCodeplay/versions.json +28 -28
  36. package/files/finalrelease +1365 -1365
  37. package/files/generate-ai-promo-video.js +23 -23
  38. package/files/ionic.config.json +6 -6
  39. package/files/scripts-common/generate-baseline-profile.js +46 -46
  40. package/files/scripts-common/run-codeplay-sync-after.js +21 -21
  41. package/files/scripts-common/screenshot/background-decorations.js +120 -120
  42. package/files/scripts-common/screenshot/frame-samples.js +117 -117
  43. package/files/scripts-common/setup-baseline-profile.js +291 -291
  44. package/files/take-screen-image.js +4414 -4414
  45. package/files/take-screen-video.js +644 -644
  46. package/package.json +3 -2
  47. package/runtime/vk-ads/vk-ad-configuration.json +39 -39
  48. package/scripts/ensure-current-build.test.cjs +76 -76
  49. package/scripts/iap-alias.test.cjs +78 -117
  50. package/scripts/ios-ad-consent.test.cjs +99 -99
  51. package/scripts/ruads-install.test.cjs +180 -180
  52. package/scripts/ruads-policy.test.cjs +174 -174
  53. package/scripts/saf-mediastore-dependency.test.cjs +44 -44
  54. package/scripts/sync-files.js +120 -120
  55. package/scripts/system-bars-package.test.cjs +38 -0
  56. package/scripts/system-bars.test.cjs +93 -77
  57. package/scripts/uninstall.js +2 -2
  58. package/scripts/vite-build-settings.test.cjs +92 -92
@@ -1,120 +1,120 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { updateBuildScripts, removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
4
- const { syncAndroidR8Rules } = require('../files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs');
5
-
6
- function migrateAppScripts(projectRoot) {
7
- const root = path.resolve(projectRoot);
8
- const source = path.resolve(root, 'scripts');
9
- const destination = path.resolve(root, 'scripts-common');
10
- if (path.dirname(source) !== root || path.dirname(destination) !== root) throw new Error('Invalid app scripts path.');
11
- if (!fs.existsSync(source)) return;
12
- // Preflight the entire tree before moving anything. Never overwrite a
13
- // different existing file or follow a linked directory.
14
- function check(from, to) {
15
- if (fs.lstatSync(from).isSymbolicLink() || (fs.existsSync(to) && fs.lstatSync(to).isSymbolicLink())) throw new Error('Cannot migrate linked script paths.');
16
- if (!fs.existsSync(to)) return;
17
- if (fs.statSync(from).isDirectory() && fs.statSync(to).isDirectory()) {
18
- for (const name of fs.readdirSync(from)) check(path.join(from, name), path.join(to, name));
19
- } else if (!fs.statSync(from).isFile() || !fs.statSync(to).isFile() || !fs.readFileSync(from).equals(fs.readFileSync(to))) {
20
- throw new Error(`Scripts folder conflict; both files preserved: ${to}`);
21
- }
22
- }
23
- function move(from, to) {
24
- if (!fs.existsSync(to)) { fs.renameSync(from, to); return; }
25
- if (fs.statSync(from).isDirectory()) {
26
- for (const name of fs.readdirSync(from)) move(path.join(from, name), path.join(to, name));
27
- fs.rmdirSync(from);
28
- } else fs.unlinkSync(from); // Identical existing file, verified above.
29
- }
30
- check(source, destination);
31
- move(source, destination);
32
- }
33
-
34
- function migrateAppConfigurator(projectRoot) {
35
- const filePath = path.join(projectRoot, 'scripts-common', 'configure-codeplay-common.js');
36
- if (!fs.existsSync(filePath)) return;
37
- const original = fs.readFileSync(filePath, 'utf8');
38
- let updated = original;
39
- // Preserve app-specific configuration; extend only the known legacy lookups.
40
- for (const [variable, script] of [
41
- ['buildFile', 'codeplayBeforeBuild.js'],
42
- ['packageIdFile', 'packageidBaseModification.js'],
43
- ]) {
44
- updated = updated.replace(
45
- `const ${variable} = fs.readdirSync(buildDir)`,
46
- `const ${variable} = fs.existsSync(path.join(buildDir, '${script}'))\n` +
47
- ` ? '${script}'\n` +
48
- ` : fs.readdirSync(buildDir)`
49
- );
50
- }
51
- updated = updated.replace(
52
- "packageJson.scripts['capacitor:sync:after'] = 'node scripts/run-codeplay-sync-after.js';",
53
- "packageJson.scripts['capacitor:sync:after'] = 'node scripts-common/run-codeplay-sync-after.js';"
54
- );
55
- if (updated !== original) fs.writeFileSync(filePath, updated, 'utf8');
56
- }
57
-
58
- function findProjectRoot() {
59
- // npm may execute a file: dependency's lifecycle in its source directory.
60
- // INIT_CWD identifies the app that invoked npm in that case.
61
- for (const candidate of [process.env.INIT_CWD, path.join(__dirname, '../../..')]) {
62
- if (!candidate) continue;
63
- const root = path.resolve(candidate);
64
- const file = path.join(root, 'package.json');
65
- if (!fs.existsSync(file)) continue;
66
- if (JSON.parse(fs.readFileSync(file, 'utf8')).name !== 'codeplay-common' && fs.existsSync(path.join(root, 'capacitor.config.json'))) return root;
67
- }
68
- return null;
69
- }
70
-
71
- function install(options = {}) {
72
- const resolved = options.projectRoot || findProjectRoot();
73
- if (!resolved) {
74
- console.log('codeplay-common: no consuming Capacitor app found; skipping source-package setup.');
75
- return null;
76
- }
77
- const projectRoot = path.resolve(resolved);
78
- const commonFiles = path.resolve(__dirname, '../files');
79
- const packagePath = path.join(projectRoot, 'package.json');
80
- if (!fs.existsSync(packagePath)) throw new Error('Consuming application package.json was not found.');
81
- const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
82
- const scripts = updateBuildScripts(pkg.scripts || {});
83
- migrateAppScripts(projectRoot);
84
- // Copy the common templates into each application for local testing.
85
- const buildSource = path.join(commonFiles, 'buildCodeplay');
86
- const buildTarget = path.join(projectRoot, 'buildCodeplay');
87
- fs.mkdirSync(buildTarget, { recursive: true });
88
- for (const name of fs.readdirSync(buildSource)) {
89
- const target = path.join(buildTarget, name);
90
- if ((name === 'release-sync.config.json' || name === 'splashxml') && fs.existsSync(target)) continue;
91
- fs.cpSync(path.join(buildSource, name), target, { recursive: true });
92
- }
93
- fs.copyFileSync(path.join(commonFiles, 'finalrelease'), path.join(projectRoot, 'finalrelease'));
94
- if (options.copyAssets !== false) {
95
- for (const name of fs.readdirSync(commonFiles)) {
96
- if (name === 'buildCodeplay' || name === 'scripts-screenshot') continue;
97
- fs.cpSync(path.join(commonFiles, name), path.join(projectRoot, name), { recursive: true });
98
- }
99
- }
100
- require('../files/buildCodeplay/splash-setup.cjs').syncSplashSetup(projectRoot);
101
- require('../files/buildCodeplay/setup-ruads.cjs').syncRuAdsSetup(projectRoot, {
102
- runtimeRoot: path.resolve(__dirname, '../runtime/vk-ads'),
103
- });
104
- require('../files/buildCodeplay/iap-alias.cjs').syncIapAliases(projectRoot);
105
- migrateAppConfigurator(projectRoot);
106
- require('../files/buildCodeplay/migrate-system-bars.cjs').migrateSystemBars(projectRoot);
107
- syncAndroidR8Rules(projectRoot, { installGradleHook: true });
108
- pkg.scripts = scripts;
109
- require('../files/buildCodeplay/saf-mediastore-dependency.cjs').syncSafMediastoreDependency(projectRoot);
110
- fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n');
111
- // Cleanup happens only after replacement assets and package commands exist.
112
- removeVersionedBuildScripts(projectRoot);
113
- console.log('codeplay-common: unversioned build scripts copied to app buildCodeplay; app-owned settings preserved.');
114
- // Coupled IAP/AdMob/Home migrations run together during before-build.
115
- return pkg;
116
- }
117
- module.exports = { install, findProjectRoot, migrateAppScripts, migrateAppConfigurator };
118
- if (require.main === module) {
119
- try { install(); } catch (error) { console.error(error.message); process.exitCode = 1; }
120
- }
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { updateBuildScripts, removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
4
+ const { syncAndroidR8Rules } = require('../files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs');
5
+
6
+ function migrateAppScripts(projectRoot) {
7
+ const root = path.resolve(projectRoot);
8
+ const source = path.resolve(root, 'scripts');
9
+ const destination = path.resolve(root, 'scripts-common');
10
+ if (path.dirname(source) !== root || path.dirname(destination) !== root) throw new Error('Invalid app scripts path.');
11
+ if (!fs.existsSync(source)) return;
12
+ // Preflight the entire tree before moving anything. Never overwrite a
13
+ // different existing file or follow a linked directory.
14
+ function check(from, to) {
15
+ if (fs.lstatSync(from).isSymbolicLink() || (fs.existsSync(to) && fs.lstatSync(to).isSymbolicLink())) throw new Error('Cannot migrate linked script paths.');
16
+ if (!fs.existsSync(to)) return;
17
+ if (fs.statSync(from).isDirectory() && fs.statSync(to).isDirectory()) {
18
+ for (const name of fs.readdirSync(from)) check(path.join(from, name), path.join(to, name));
19
+ } else if (!fs.statSync(from).isFile() || !fs.statSync(to).isFile() || !fs.readFileSync(from).equals(fs.readFileSync(to))) {
20
+ throw new Error(`Scripts folder conflict; both files preserved: ${to}`);
21
+ }
22
+ }
23
+ function move(from, to) {
24
+ if (!fs.existsSync(to)) { fs.renameSync(from, to); return; }
25
+ if (fs.statSync(from).isDirectory()) {
26
+ for (const name of fs.readdirSync(from)) move(path.join(from, name), path.join(to, name));
27
+ fs.rmdirSync(from);
28
+ } else fs.unlinkSync(from); // Identical existing file, verified above.
29
+ }
30
+ check(source, destination);
31
+ move(source, destination);
32
+ }
33
+
34
+ function migrateAppConfigurator(projectRoot) {
35
+ const filePath = path.join(projectRoot, 'scripts-common', 'configure-codeplay-common.js');
36
+ if (!fs.existsSync(filePath)) return;
37
+ const original = fs.readFileSync(filePath, 'utf8');
38
+ let updated = original;
39
+ // Preserve app-specific configuration; extend only the known legacy lookups.
40
+ for (const [variable, script] of [
41
+ ['buildFile', 'codeplayBeforeBuild.js'],
42
+ ['packageIdFile', 'packageidBaseModification.js'],
43
+ ]) {
44
+ updated = updated.replace(
45
+ `const ${variable} = fs.readdirSync(buildDir)`,
46
+ `const ${variable} = fs.existsSync(path.join(buildDir, '${script}'))\n` +
47
+ ` ? '${script}'\n` +
48
+ ` : fs.readdirSync(buildDir)`
49
+ );
50
+ }
51
+ updated = updated.replace(
52
+ "packageJson.scripts['capacitor:sync:after'] = 'node scripts/run-codeplay-sync-after.js';",
53
+ "packageJson.scripts['capacitor:sync:after'] = 'node scripts-common/run-codeplay-sync-after.js';"
54
+ );
55
+ if (updated !== original) fs.writeFileSync(filePath, updated, 'utf8');
56
+ }
57
+
58
+ function findProjectRoot() {
59
+ // npm may execute a file: dependency's lifecycle in its source directory.
60
+ // INIT_CWD identifies the app that invoked npm in that case.
61
+ for (const candidate of [process.env.INIT_CWD, path.join(__dirname, '../../..')]) {
62
+ if (!candidate) continue;
63
+ const root = path.resolve(candidate);
64
+ const file = path.join(root, 'package.json');
65
+ if (!fs.existsSync(file)) continue;
66
+ if (JSON.parse(fs.readFileSync(file, 'utf8')).name !== 'codeplay-common' && fs.existsSync(path.join(root, 'capacitor.config.json'))) return root;
67
+ }
68
+ return null;
69
+ }
70
+
71
+ function install(options = {}) {
72
+ const resolved = options.projectRoot || findProjectRoot();
73
+ if (!resolved) {
74
+ console.log('codeplay-common: no consuming Capacitor app found; skipping source-package setup.');
75
+ return null;
76
+ }
77
+ const projectRoot = path.resolve(resolved);
78
+ const commonFiles = path.resolve(__dirname, '../files');
79
+ const packagePath = path.join(projectRoot, 'package.json');
80
+ if (!fs.existsSync(packagePath)) throw new Error('Consuming application package.json was not found.');
81
+ const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
82
+ const scripts = updateBuildScripts(pkg.scripts || {});
83
+ migrateAppScripts(projectRoot);
84
+ // Copy the common templates into each application for local testing.
85
+ const buildSource = path.join(commonFiles, 'buildCodeplay');
86
+ const buildTarget = path.join(projectRoot, 'buildCodeplay');
87
+ fs.mkdirSync(buildTarget, { recursive: true });
88
+ for (const name of fs.readdirSync(buildSource)) {
89
+ const target = path.join(buildTarget, name);
90
+ if ((name === 'release-sync.config.json' || name === 'splashxml') && fs.existsSync(target)) continue;
91
+ fs.cpSync(path.join(buildSource, name), target, { recursive: true });
92
+ }
93
+ fs.copyFileSync(path.join(commonFiles, 'finalrelease'), path.join(projectRoot, 'finalrelease'));
94
+ if (options.copyAssets !== false) {
95
+ for (const name of fs.readdirSync(commonFiles)) {
96
+ if (name === 'buildCodeplay' || name === 'scripts-screenshot') continue;
97
+ fs.cpSync(path.join(commonFiles, name), path.join(projectRoot, name), { recursive: true });
98
+ }
99
+ }
100
+ require('../files/buildCodeplay/splash-setup.cjs').syncSplashSetup(projectRoot);
101
+ require('../files/buildCodeplay/setup-ruads.cjs').syncRuAdsSetup(projectRoot, {
102
+ runtimeRoot: path.resolve(__dirname, '../runtime/vk-ads'),
103
+ });
104
+ require('../files/buildCodeplay/iap-alias.cjs').syncIapAliases(projectRoot);
105
+ migrateAppConfigurator(projectRoot);
106
+ require('../files/buildCodeplay/migrate-system-bars.cjs').migrateSystemBars(projectRoot);
107
+ syncAndroidR8Rules(projectRoot, { installGradleHook: true });
108
+ pkg.scripts = scripts;
109
+ require('../files/buildCodeplay/saf-mediastore-dependency.cjs').syncSafMediastoreDependency(projectRoot);
110
+ fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n');
111
+ // Cleanup happens only after replacement assets and package commands exist.
112
+ removeVersionedBuildScripts(projectRoot);
113
+ console.log('codeplay-common: unversioned build scripts copied to app buildCodeplay; app-owned settings preserved.');
114
+ // Coupled IAP/AdMob/Home migrations run together during before-build.
115
+ return pkg;
116
+ }
117
+ module.exports = { install, findProjectRoot, migrateAppScripts, migrateAppConfigurator };
118
+ if (require.main === module) {
119
+ try { install(); } catch (error) { console.error(error.message); process.exitCode = 1; }
120
+ }
@@ -0,0 +1,38 @@
1
+ const { test } = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const vm = require('vm');
6
+
7
+ const source = fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/codeplayBeforeBuild.js'), 'utf8');
8
+ const start = source.indexOf('const syncCodeplaySystemBarsPackage =');
9
+ const code = source.slice(start, source.indexOf('\n};', start) + 3);
10
+
11
+ function run({ installed = '1.0.1', latest = '1.0.2', declared = '^1.0.1', offline = false, fail = false } = {}) {
12
+ const commands = [];
13
+ let queries = 0;
14
+ const context = {
15
+ fs: { existsSync: () => true, readFileSync: () => JSON.stringify({ dependencies: { 'capacitor-codeplay-system-bars': declared } }) },
16
+ packageJsonPath: 'package.json',
17
+ CODEPLAY_SYSTEM_BARS_PLUGIN: 'capacitor-codeplay-system-bars',
18
+ getInstalledVersion: () => installed,
19
+ getLatestVersion: () => { queries++; return latest; },
20
+ compareVersionStrings: (a, b) => a.localeCompare(b, undefined, { numeric: true }),
21
+ runNpmCommand: command => { if (fail) throw new Error('install failed'); commands.push(command); },
22
+ skipOnlineVersionChecks: offline,
23
+ console: { log() {}, warn() {} }
24
+ };
25
+ vm.runInNewContext(code + '\nsyncCodeplaySystemBarsPackage();', context);
26
+ return { commands, queries };
27
+ }
28
+
29
+ test('updates an older installed release', () => {
30
+ assert.deepEqual(run(), { commands: ['npm install capacitor-codeplay-system-bars@latest'], queries: 1 });
31
+ });
32
+ test('keeps the latest installed release', () => assert.deepEqual(run({ installed: '1.0.2' }).commands, []));
33
+ test('does not downgrade a newer installed release', () => assert.deepEqual(run({ installed: '1.0.3' }).commands, []));
34
+ test('installs a missing package', () => assert.equal(run({ installed: null }).commands.length, 1));
35
+ test('replaces a local plugin reference', () => assert.equal(run({ declared: 'file:../plugin' }).commands.length, 1));
36
+ test('offline builds skip the registry check', () => assert.deepEqual(run({ offline: true }), { commands: [], queries: 0 }));
37
+ test('registry failure preserves the installed package', () => assert.deepEqual(run({ latest: null }).commands, []));
38
+ test('installation failure stops the build', () => assert.throws(() => run({ fail: true }), /install failed/));
@@ -1,77 +1,93 @@
1
- const { test } = require('node:test');
2
- const assert = require('node:assert/strict');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { migrateSystemBars, auditLegacyStatusBar, migrateLegacyStatusBar } = require('../files/buildCodeplay/migrate-system-bars.cjs');
6
-
7
- function fixture() {
8
- const base = path.resolve(process.env.CODEPLAY_TEST_ROOT || path.join(__dirname, '../agent-temp'));
9
- fs.mkdirSync(base, { recursive: true });
10
- const root = fs.mkdtempSync(path.join(base, 'system-bars-'));
11
- const write = (relative, content) => {
12
- const file = path.join(root, relative);
13
- fs.mkdirSync(path.dirname(file), { recursive: true });
14
- fs.writeFileSync(file, content);
15
- };
16
- write('package.json', JSON.stringify({ name: 'fixture', dependencies: { '@capacitor/status-bar': '^8.0.4' } }));
17
- return { root, write };
18
- }
19
- const modern = 'import {SystemBars,SystemBarType} from "@capacitor/core"; SystemBars.setStyle({style:"DARK",bar:SystemBarType.StatusBar});';
20
-
21
- test('legacy dependency is removed only after confirming modern usage; native references are refreshed', async () => {
22
- const { root, write } = fixture();
23
- write('src/app.js', modern + '\n/* StatusBar.hide(); */');
24
- assert.equal((await auditLegacyStatusBar(root)).status, 'unused');
25
- write('android/capacitor.settings.gradle', "include ':capacitor-status-bar'\n");
26
- write('ios/App/Podfile', "# App pods\n pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'\n pod 'CapacitorApp'\n");
27
- const commands = [];
28
- const result = await migrateLegacyStatusBar(root, { runNpm: command => commands.push(command) });
29
- assert.equal(result.status, 'removed');
30
- assert.deepEqual(commands, ['npm uninstall @capacitor/status-bar --ignore-scripts --no-audit --no-fund', 'npx --no-install cap update android']);
31
- assert.equal(fs.readFileSync(path.join(root, 'ios/App/Podfile'), 'utf8'), "# App pods\n pod 'CapacitorApp'\n");
32
- });
33
-
34
- for (const [name, code] of [
35
- ['active import', modern + 'import {StatusBar} from "@capacitor/status-bar"; StatusBar.hide();'],
36
- ['URL followed by a legacy call', modern + 'const url="https://localhost"; StatusBar.hide();'],
37
- ['unparseable code', modern + 'const invalid=;'],
38
- ['no confirmed replacement API', 'console.log("app");']
39
- ]) {
40
- test(`preserves dependency for ${name}`, async () => {
41
- const { root, write } = fixture();
42
- write('src/app.js', code);
43
- const result = await migrateLegacyStatusBar(root, { runNpm: () => assert.fail('must retain the dependency') });
44
- assert.equal(result.status, 'retained');
45
- });
46
- }
47
-
48
- test('Framework7 script handling ignores old generated diagnostics and retains custom native registration', async () => {
49
- const { root, write } = fixture();
50
- write('src/page.f7', `<template><div></div></template><script>${modern}</script>`);
51
- write('src/agent-temp/old.js', 'StatusBar.hide();');
52
- assert.equal((await auditLegacyStatusBar(root)).status, 'unused');
53
- write('android/app/src/main/java/App.java', 'bridge.registerPlugin(StatusBarPlugin.class);');
54
- assert.equal((await auditLegacyStatusBar(root)).status, 'retained');
55
- });
56
-
57
- test('native patch preserves surrounding code, is idempotent, and fails closed for unexpected sources', () => {
58
- const { root, write } = fixture();
59
- const relative = 'node_modules/capacitor-codeplay-system-bars/android/src/main/java/com/codeplay/systembars/CodeplaySystemBarsPlugin.java';
60
- const original = 'controller.setAppearanceLightNavigationBars(useDarkIcons);\r\n window.setNavigationBarColor(Color.TRANSPARENT);\r\nwindow.getDecorView().post(this::updateNavigationBarProtection);\r\n';
61
- write(relative, original);
62
- assert.equal(migrateSystemBars(root), true);
63
- const patched = fs.readFileSync(path.join(root, relative), 'utf8');
64
- assert(patched.includes('Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM'));
65
- assert(patched.startsWith(original.split('\r\n')[0] + '\r\n'));
66
- assert(patched.endsWith(original.split('\r\n').slice(-2).join('\r\n')));
67
- assert.equal(migrateSystemBars(root), false);
68
- assert.equal(fs.readFileSync(path.join(root, relative), 'utf8'), patched);
69
- write(relative, 'unexpected implementation');
70
- assert.throws(() => migrateSystemBars(root), /structure changed/);
71
- assert.equal(fs.readFileSync(path.join(root, relative), 'utf8'), 'unexpected implementation');
72
- });
73
-
74
- test('missing navigation-bar plugin is allowed during installation', () => {
75
- const { root } = fixture();
76
- assert.equal(migrateSystemBars(root), false);
77
- });
1
+ const { test } = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { migrateSystemBars, auditLegacyStatusBar, migrateLegacyStatusBar } = require('../files/buildCodeplay/migrate-system-bars.cjs');
6
+
7
+ function fixture() {
8
+ const base = path.resolve(process.env.CODEPLAY_TEST_ROOT || path.join(__dirname, '../agent-temp'));
9
+ fs.mkdirSync(base, { recursive: true });
10
+ const root = fs.mkdtempSync(path.join(base, 'system-bars-'));
11
+ const write = (relative, content) => {
12
+ const file = path.join(root, relative);
13
+ fs.mkdirSync(path.dirname(file), { recursive: true });
14
+ fs.writeFileSync(file, content);
15
+ };
16
+ write('package.json', JSON.stringify({ name: 'fixture', dependencies: { '@capacitor/status-bar': '^8.0.4' } }));
17
+ return { root, write };
18
+ }
19
+ const modern = 'import {SystemBars,SystemBarType} from "@capacitor/core"; SystemBars.setStyle({style:"DARK",bar:SystemBarType.StatusBar});';
20
+
21
+ test('copied helper resolves the package-owned parser in a nested npm layout', async () => {
22
+ const { root, write } = fixture();
23
+ write('src/app.js', modern + '\n/* StatusBar.hide(); */');
24
+ write('node_modules/codeplay-common/package.json', JSON.stringify({ name: 'codeplay-common' }));
25
+ const parserPath = require.resolve('terser');
26
+ write('node_modules/codeplay-common/node_modules/terser/index.js',
27
+ `module.exports = require(${JSON.stringify(parserPath)});`);
28
+ const copiedHelper = path.join(root, 'buildCodeplay/migrate-system-bars.cjs');
29
+ write('buildCodeplay/migrate-system-bars.cjs',
30
+ fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/migrate-system-bars.cjs'), 'utf8'));
31
+ const { auditLegacyStatusBar: auditCopiedHelper } = require(copiedHelper);
32
+ assert.equal((await auditCopiedHelper(root)).status, 'unused');
33
+ write('src/app.js', modern + ' StatusBar.hide();');
34
+ assert.equal((await auditCopiedHelper(root)).status, 'retained');
35
+ });
36
+
37
+ test('legacy dependency is removed only after confirming modern usage; native references are refreshed', async () => {
38
+ const { root, write } = fixture();
39
+ write('src/app.js', modern + '\n/* StatusBar.hide(); */');
40
+ assert.equal((await auditLegacyStatusBar(root)).status, 'unused');
41
+ write('android/capacitor.settings.gradle', "include ':capacitor-status-bar'\n");
42
+ write('ios/App/Podfile', "# App pods\n pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'\n pod 'CapacitorApp'\n");
43
+ const commands = [];
44
+ const result = await migrateLegacyStatusBar(root, { runNpm: command => commands.push(command) });
45
+ assert.equal(result.status, 'removed');
46
+ assert.deepEqual(commands, ['npm uninstall @capacitor/status-bar --ignore-scripts --no-audit --no-fund', 'npx --no-install cap update android']);
47
+ assert.equal(fs.readFileSync(path.join(root, 'ios/App/Podfile'), 'utf8'), "# App pods\n pod 'CapacitorApp'\n");
48
+ });
49
+
50
+ for (const [name, code] of [
51
+ ['active import', modern + 'import {StatusBar} from "@capacitor/status-bar"; StatusBar.hide();'],
52
+ ['URL followed by a legacy call', modern + 'const url="https://localhost"; StatusBar.hide();'],
53
+ ['unparseable code', modern + 'const invalid=;'],
54
+ ['no confirmed replacement API', 'console.log("app");']
55
+ ]) {
56
+ test(`preserves dependency for ${name}`, async () => {
57
+ const { root, write } = fixture();
58
+ write('src/app.js', code);
59
+ const result = await migrateLegacyStatusBar(root, { runNpm: () => assert.fail('must retain the dependency') });
60
+ assert.equal(result.status, 'retained');
61
+ });
62
+ }
63
+
64
+ test('Framework7 script handling ignores old generated diagnostics and retains custom native registration', async () => {
65
+ const { root, write } = fixture();
66
+ write('src/page.f7', `<template><div></div></template><script>${modern}</script>`);
67
+ write('src/agent-temp/old.js', 'StatusBar.hide();');
68
+ assert.equal((await auditLegacyStatusBar(root)).status, 'unused');
69
+ write('android/app/src/main/java/App.java', 'bridge.registerPlugin(StatusBarPlugin.class);');
70
+ assert.equal((await auditLegacyStatusBar(root)).status, 'retained');
71
+ });
72
+
73
+ test('native patch preserves surrounding code, is idempotent, and fails closed for unexpected sources', () => {
74
+ const { root, write } = fixture();
75
+ const relative = 'node_modules/capacitor-codeplay-system-bars/android/src/main/java/com/codeplay/systembars/CodeplaySystemBarsPlugin.java';
76
+ const original = 'controller.setAppearanceLightNavigationBars(useDarkIcons);\r\n window.setNavigationBarColor(Color.TRANSPARENT);\r\nwindow.getDecorView().post(this::updateNavigationBarProtection);\r\n';
77
+ write(relative, original);
78
+ assert.equal(migrateSystemBars(root), true);
79
+ const patched = fs.readFileSync(path.join(root, relative), 'utf8');
80
+ assert(patched.includes('Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM'));
81
+ assert(patched.startsWith(original.split('\r\n')[0] + '\r\n'));
82
+ assert(patched.endsWith(original.split('\r\n').slice(-2).join('\r\n')));
83
+ assert.equal(migrateSystemBars(root), false);
84
+ assert.equal(fs.readFileSync(path.join(root, relative), 'utf8'), patched);
85
+ write(relative, 'unexpected implementation');
86
+ assert.throws(() => migrateSystemBars(root), /structure changed/);
87
+ assert.equal(fs.readFileSync(path.join(root, relative), 'utf8'), 'unexpected implementation');
88
+ });
89
+
90
+ test('missing navigation-bar plugin is allowed during installation', () => {
91
+ const { root } = fixture();
92
+ assert.equal(migrateSystemBars(root), false);
93
+ });
@@ -1,3 +1,3 @@
1
- // Preserve working app files during preinstall. Postinstall migrates commands
2
- // first, then removes only recognized copied build scripts.
1
+ // Preserve working app files during preinstall. Postinstall migrates commands
2
+ // first, then removes only recognized copied build scripts.
3
3
  console.log('codeplay-common: preserving app files until installation completes.');