codeplay-common 4.11.27 → 4.11.28

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,5 +1,10 @@
1
1
  # codeplay-common
2
2
 
3
+ When `cordova-plugin-saf-mediastore` is installed, setup, before-build and Capacitor
4
+ sync/update hooks add its missing AndroidX DocumentFile dependency to plugin metadata.
5
+ Existing dependency versions are preserved. After upgrading from an affected version,
6
+ run `npx cap sync android` once to regenerate the native dependencies.
7
+
3
8
  ## VK / RuStore builds (4.11.23)
4
9
 
5
10
  Before-build 7.8 preserves the original Vite build settings when adding tree-shaking
@@ -1,3 +1,4 @@
1
+ // Version 8.2: declare the installed SAF plugin's DocumentFile dependency before native sync.
1
2
  // Version 8.1: prevent native app startup from requesting ATT before regional consent.
2
3
  // Version 8.0: restore AdMob native settings when switching back to an AdMob store.
3
4
  // Version 7.9: remove stale AdMob native settings and SDKs for non-AdMob stores.
@@ -4681,6 +4682,7 @@ function syncAndroidCordovaResourceKeep() {
4681
4682
  }
4682
4683
 
4683
4684
  async function main() {
4685
+ require('./saf-mediastore-dependency.cjs').syncSafMediastoreDependency(process.cwd());
4684
4686
  const buildPackage = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
4685
4687
  const buildScripts = updateBuildEntrypoints(buildPackage.scripts || {});
4686
4688
  if (JSON.stringify(buildScripts) !== JSON.stringify(buildPackage.scripts)) {
@@ -32,6 +32,12 @@ function updateBuildScripts(scripts) {
32
32
  next['build:ios'] = next['build:ios'] || 'cross-env CODEPLAY_BUILD_PLATFORM=ios VITE_STORE_ID=6 npm run build';
33
33
  if (!/VITE_STORE_ID=6\b/.test(next['build:ios'])) next['build:ios'] = next['build:ios'].replace('CODEPLAY_BUILD_PLATFORM=ios ', 'CODEPLAY_BUILD_PLATFORM=ios VITE_STORE_ID=6 ');
34
34
  next['capacitor:sync:after'] = next['capacitor:sync:after'] || syncAfter;
35
+ const safDependency = 'node buildCodeplay/saf-mediastore-dependency.cjs';
36
+ for (const hook of ['capacitor:sync:before', 'capacitor:update:before']) {
37
+ if (!(next[hook] || '').includes(safDependency)) {
38
+ next[hook] = next[hook] ? `${safDependency} && ${next[hook]}` : safDependency;
39
+ }
40
+ }
35
41
  next['build-capacitor-android'] = next['build-capacitor-android'] || 'npm run build && npx cap copy android';
36
42
  next['build-capacitor-ios'] = next['build-capacitor-ios']
37
43
  ? next['build-capacitor-ios'].replace(/^(?:cross-env\s+NODE_ENV=production\s+)?vite\s+build(?=\s*&&\s*npx\s+cap\s+copy\s+ios\b)/, 'npm run build:ios')
@@ -0,0 +1,21 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function syncSafMediastoreDependency(projectRoot = process.cwd()) {
5
+ const file = path.join(projectRoot, 'node_modules', 'cordova-plugin-saf-mediastore', 'plugin.xml');
6
+ if (!fs.existsSync(file)) return false;
7
+ const original = fs.readFileSync(file, 'utf8');
8
+ // Mask comments without changing offsets so commented declarations do not count.
9
+ const active = original.replace(/<!--[\s\S]*?-->/g, comment => comment.replace(/[^\r\n]/g, ' '));
10
+ const android = /<platform\b[^>]*\bname\s*=\s*(['"])android\1[^>]*>[\s\S]*?<\/platform\s*>/.exec(active);
11
+ if (!android) throw new Error('SAF plugin.xml has no Android platform; cannot declare DocumentFile dependency.');
12
+ if (/<framework\b[^>]*\bsrc\s*=\s*(['"])androidx\.documentfile:documentfile:[^'"]+\1/.test(android[0])) return false;
13
+ const newline = original.includes('\r\n') ? '\r\n' : '\n';
14
+ const offset = android.index + android[0].indexOf('>') + 1;
15
+ const dependency = `${newline}\t\t<framework src="androidx.documentfile:documentfile:1.1.0" />`;
16
+ fs.writeFileSync(file, original.slice(0, offset) + dependency + original.slice(offset), 'utf8');
17
+ return true;
18
+ }
19
+
20
+ module.exports = { syncSafMediastoreDependency };
21
+ if (require.main === module) syncSafMediastoreDependency();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "4.11.27",
3
+ "version": "4.11.28",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",
@@ -0,0 +1,44 @@
1
+ const assert = require('node:assert/strict');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const { test } = require('node:test');
5
+ const { syncSafMediastoreDependency } = require('../files/buildCodeplay/saf-mediastore-dependency.cjs');
6
+ const { updateBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
7
+
8
+ test('SAF metadata repair is conditional, preserves versions and survives repeated sync preparation', () => {
9
+ const temp = path.resolve(process.cwd(), 'agent-temp');
10
+ fs.mkdirSync(temp, { recursive: true });
11
+ const root = fs.mkdtempSync(path.join(temp, 'saf-dependency-'));
12
+ try {
13
+ assert.equal(syncSafMediastoreDependency(root), false);
14
+ assert.deepEqual(fs.readdirSync(root), []);
15
+ const file = path.join(root, 'node_modules/cordova-plugin-saf-mediastore/plugin.xml');
16
+ fs.mkdirSync(path.dirname(file), { recursive: true });
17
+ const original = '<plugin>\r\n<!-- <platform name="android"></platform> -->\r\n'
18
+ + '<platform name="ios"></platform>\r\n<platform name="android">\r\n'
19
+ + '<!-- <framework src="androidx.documentfile:documentfile:0.0.0" /> -->\r\n'
20
+ + '<source-file src="SafMediastore.java" />\r\n</platform>\r\n</plugin>';
21
+ fs.writeFileSync(file, original);
22
+ assert.equal(syncSafMediastoreDependency(root), true);
23
+ const repaired = fs.readFileSync(file, 'utf8');
24
+ assert.ok(repaired.includes('<platform name="android">\r\n\t\t<framework src="androidx.documentfile:documentfile:1.1.0" />'));
25
+ assert.equal(repaired.replace('\r\n\t\t<framework src="androidx.documentfile:documentfile:1.1.0" />', ''), original);
26
+ assert.equal(syncSafMediastoreDependency(root), false);
27
+ assert.equal(fs.readFileSync(file, 'utf8'), repaired);
28
+ const custom = repaired.replace('documentfile:1.1.0', 'documentfile:1.0.1');
29
+ fs.writeFileSync(file, custom);
30
+ assert.equal(syncSafMediastoreDependency(root), false);
31
+ assert.equal(fs.readFileSync(file, 'utf8'), custom);
32
+ fs.writeFileSync(file, '<plugin><platform name="ios"></platform></plugin>');
33
+ assert.throws(() => syncSafMediastoreDependency(root), /no Android platform/);
34
+ } finally {
35
+ fs.rmSync(root, { recursive: true, force: true });
36
+ }
37
+ });
38
+
39
+ test('sync and update hooks preserve custom commands without duplicating repair', () => {
40
+ const scripts = updateBuildScripts({ 'capacitor:sync:before': 'node custom.js' });
41
+ assert.equal(scripts['capacitor:sync:before'], 'node buildCodeplay/saf-mediastore-dependency.cjs && node custom.js');
42
+ assert.equal(scripts['capacitor:update:before'], 'node buildCodeplay/saf-mediastore-dependency.cjs');
43
+ assert.deepEqual(updateBuildScripts(scripts), scripts);
44
+ });
@@ -106,6 +106,7 @@ function install(options = {}) {
106
106
  require('../files/buildCodeplay/migrate-system-bars.cjs').migrateSystemBars(projectRoot);
107
107
  syncAndroidR8Rules(projectRoot, { installGradleHook: true });
108
108
  pkg.scripts = scripts;
109
+ require('../files/buildCodeplay/saf-mediastore-dependency.cjs').syncSafMediastoreDependency(projectRoot);
109
110
  fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n');
110
111
  // Cleanup happens only after replacement assets and package commands exist.
111
112
  removeVersionedBuildScripts(projectRoot);