codeplay-common 4.11.21 → 4.11.22

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/README.md CHANGED
@@ -1,4 +1,12 @@
1
- # codeplay-common
1
+ # codeplay-common
2
+
3
+ ## Android system bars (4.11.22)
4
+
5
+ Installation and before-build migrate installed `capacitor-codeplay-system-bars` 1.0.1 to avoid calling `Window.setNavigationBarColor` on Android 15+. Existing inset protection views, keyboard handling, icon appearance and older Android compatibility remain intact. Missing plugins are skipped; unexpected native source requires review. Before-build removes `@capacitor/status-bar` only when parsed app sources confirm modern `SystemBars` usage without legacy references. Apps with active legacy calls or unparseable source retain the dependency and report why. The existing app parser is reused; no dependency is added. Run normal Capacitor sync after dependency cleanup. Native changes require a rebuilt install; older Android compatibility code can still trigger Play static warnings.
6
+
7
+ Dependency cleanup also runs `npx --no-install cap update android` when an Android platform exists and removes the standard stale iOS Podfile declaration. It does not build or install an APK. Run normal iOS sync on the supported build system before the next iOS build.
8
+
9
+ This source update is not an npm publication. Existing apps receive future releases through their normal package update process.
2
10
 
3
11
  ## Optional IAP configuration (4.11.21)
4
12
 
@@ -1,3 +1,4 @@
1
+ // Version 7.2: migrate Android 15 navigation-bar colors and remove unused legacy StatusBar plugins.
1
2
  // Version 7.1: require confirmation before continuing with local versions when the server check fails.
2
3
  // Version 7.0: prepare shared splash readiness and migrate the legacy splash theme.
3
4
  // Version 6.9: preserve configured notification icons during Android resource shrinking.
@@ -4709,7 +4710,10 @@ async function main() {
4709
4710
  await saveToGalleryAndSaveFileCheck_iOS();
4710
4711
 
4711
4712
  await syncAdmobNextgenMigration();
4712
- syncCodeplaySystemBarsPackage();
4713
+ syncCodeplaySystemBarsPackage();
4714
+ require('./migrate-system-bars.cjs').migrateSystemBars();
4715
+ const legacyStatusBar = await require('./migrate-system-bars.cjs').migrateLegacyStatusBar();
4716
+ if (legacyStatusBar.status === 'retained') console.warn('Legacy StatusBar plugin retained:', legacyStatusBar.references.join(', '));
4713
4717
  syncSystemBarsSafeAreaMigration();
4714
4718
  ensureIapStartupOnHomePage();
4715
4719
  syncRevenueCatIapSetup();
@@ -0,0 +1,115 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { createRequire } = require('module');
4
+ const { execSync } = require('child_process');
5
+
6
+ // Keep legacy color support below Android 15; modern Android uses the existing
7
+ // inset-sized protection views and WindowInsetsController icon appearance.
8
+ function migrateSystemBars(projectRoot = process.cwd()) {
9
+ const pluginPath = path.join(projectRoot, 'node_modules/capacitor-codeplay-system-bars/android/src/main/java/com/codeplay/systembars/CodeplaySystemBarsPlugin.java');
10
+ if (!fs.existsSync(pluginPath)) return false;
11
+ const original = fs.readFileSync(pluginPath, 'utf8');
12
+ const newline = original.includes('\r\n') ? '\r\n' : '\n';
13
+ const marker = '// Codeplay: navigation bar colors are supplied by protection views on Android 15+.';
14
+ if (original.includes(marker)) return false;
15
+
16
+ const oldLine = ' window.setNavigationBarColor(Color.TRANSPARENT);';
17
+ if (original.split(oldLine).length !== 2 || !original.includes('window.getDecorView().post(this::updateNavigationBarProtection);')) {
18
+ throw new Error('System-bars plugin structure changed; review the Android 15 migration before building.');
19
+ }
20
+
21
+ const replacement = [
22
+ ` ${marker}`,
23
+ ' if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {',
24
+ ' window.setNavigationBarColor(Color.TRANSPARENT);',
25
+ ' }'
26
+ ].join(newline);
27
+ fs.writeFileSync(pluginPath, original.replace(oldLine, replacement), 'utf8');
28
+ return true;
29
+ }
30
+
31
+ function sourceFiles(directory, extensions, files = []) {
32
+ if (!fs.existsSync(directory)) return files;
33
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
34
+ if (entry.isSymbolicLink() || ['node_modules', '.git', 'agent-temp', 'test-results', 'www', 'public', 'Pods', 'build', 'dist'].includes(entry.name)) continue;
35
+ const file = path.join(directory, entry.name);
36
+ if (entry.isDirectory()) sourceFiles(file, extensions, files);
37
+ else if (extensions.test(entry.name)) files.push(file);
38
+ }
39
+ return files;
40
+ }
41
+
42
+ async function auditLegacyStatusBar(projectRoot = process.cwd()) {
43
+ const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
44
+ const dependency = '@capacitor/status-bar';
45
+ if (!pkg.dependencies?.[dependency] && !pkg.devDependencies?.[dependency] && !fs.existsSync(path.join(projectRoot, 'node_modules', dependency))) {
46
+ return { status: 'absent', references: [] };
47
+ }
48
+ let minify;
49
+ try {
50
+ ({ minify } = createRequire(path.join(projectRoot, 'package.json'))('terser'));
51
+ } catch {
52
+ return { status: 'retained', references: ['JavaScript parser unavailable; cannot prove the plugin is unused.'] };
53
+ }
54
+ const files = sourceFiles(path.join(projectRoot, 'src'), /\.(?:js|cjs|mjs|ts|tsx|jsx|f7|vue|html)$/);
55
+ for (const entry of fs.readdirSync(projectRoot, { withFileTypes: true })) {
56
+ if (entry.isFile() && /\.(?:js|mjs|cjs|ts|tsx|jsx)$/.test(entry.name)) files.push(path.join(projectRoot, entry.name));
57
+ }
58
+ const references = [];
59
+ let modern = false;
60
+ for (const file of files) {
61
+ let code = fs.readFileSync(file, 'utf8');
62
+ if (!/StatusBar|@capacitor\/status-bar|\bSystemBars\b/.test(code)) continue;
63
+ try {
64
+ if (/\.(?:f7|vue|html)$/.test(file)) {
65
+ code = Array.from(code.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi), match => match[1]).join('\n');
66
+ }
67
+ code = (await minify(code, { compress: false, mangle: false, module: true, format: { comments: false } })).code;
68
+ if (/\bSystemBars\b/.test(code) && /from["']@capacitor\/core["']/.test(code)) modern = true;
69
+ // This is the modern Capacitor enum, not the legacy StatusBar plugin.
70
+ code = code.replace(/\bSystemBarType\.StatusBar\b/g, '');
71
+ if (/\bStatusBar\b|@capacitor\/status-bar/.test(code)) references.push(path.relative(projectRoot, file));
72
+ } catch {
73
+ references.push(`${path.relative(projectRoot, file)} (parse review required)`);
74
+ }
75
+ }
76
+ const native = [
77
+ ...sourceFiles(path.join(projectRoot, 'android/app/src/main/java'), /\.(?:java|kt)$/),
78
+ ...sourceFiles(path.join(projectRoot, 'ios/App/App'), /\.(?:swift|m|mm)$/)
79
+ ];
80
+ for (const file of native) {
81
+ if (/StatusBarPlugin|com\.capacitorjs\.plugins\.statusbar|CapacitorStatusBar/.test(fs.readFileSync(file, 'utf8'))) references.push(path.relative(projectRoot, file));
82
+ }
83
+ if (!modern) references.push('Modern Capacitor SystemBars usage not confirmed.');
84
+ return { status: references.length ? 'retained' : 'unused', references };
85
+ }
86
+
87
+ async function migrateLegacyStatusBar(projectRoot = process.cwd(), options = {}) {
88
+ const result = await auditLegacyStatusBar(projectRoot);
89
+ if (result.status !== 'unused') return result;
90
+ const runNpm = options.runNpm || (command => execSync(command, { cwd: projectRoot, stdio: 'pipe' }));
91
+ // Suppress lifecycle hooks: removing this plugin must not reinstall shared
92
+ // templates, run a build, or change app-owned configuration.
93
+ runNpm('npm uninstall @capacitor/status-bar --ignore-scripts --no-audit --no-fund');
94
+ if (fs.existsSync(path.join(projectRoot, 'android/capacitor.settings.gradle'))) {
95
+ runNpm('npx --no-install cap update android');
96
+ }
97
+ const podfile = path.join(projectRoot, 'ios/App/Podfile');
98
+ if (fs.existsSync(podfile)) {
99
+ const original = fs.readFileSync(podfile, 'utf8');
100
+ const updated = original.replace(/^[ \t]*pod ['"]CapacitorStatusBar['"], :path => ['"]\.\.\/\.\.\/node_modules\/@capacitor\/status-bar['"][ \t]*\r?\n/gm, '');
101
+ if (updated !== original) fs.writeFileSync(podfile, updated, 'utf8');
102
+ }
103
+ return { status: 'removed', references: [] };
104
+ }
105
+
106
+ module.exports = { migrateSystemBars, auditLegacyStatusBar, migrateLegacyStatusBar };
107
+ if (require.main === module) {
108
+ migrateSystemBars();
109
+ if (process.argv.includes('--remove-unused')) {
110
+ migrateLegacyStatusBar().then(result => console.log(JSON.stringify(result))).catch(error => {
111
+ console.error(error.message);
112
+ process.exitCode = 1;
113
+ });
114
+ }
115
+ }
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
- {
2
- "name": "codeplay-common",
3
- "version": "4.11.21",
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.22",
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
+ }
@@ -98,7 +98,8 @@ function install(options = {}) {
98
98
  }
99
99
  }
100
100
  require('../files/buildCodeplay/splash-setup.cjs').syncSplashSetup(projectRoot);
101
- migrateAppConfigurator(projectRoot);
101
+ migrateAppConfigurator(projectRoot);
102
+ require('../files/buildCodeplay/migrate-system-bars.cjs').migrateSystemBars(projectRoot);
102
103
  syncAndroidR8Rules(projectRoot, { installGradleHook: true });
103
104
  pkg.scripts = scripts;
104
105
  fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n');
@@ -0,0 +1,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('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
+ });