codeplay-common 4.11.26 → 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 +5 -0
- package/files/buildCodeplay/codeplayBeforeBuild.js +2 -0
- package/files/buildCodeplay/project-scripts.cjs +6 -0
- package/files/buildCodeplay/ruads.cjs +3 -2
- package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -0
- package/package.json +1 -1
- package/scripts/ruads-policy.test.cjs +44 -0
- package/scripts/saf-mediastore-dependency.test.cjs +44 -0
- package/scripts/sync-files.js +1 -0
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')
|
|
@@ -74,7 +74,8 @@ function syncAndroidAdmobPolicy(projectRoot, storeId, platform = 'android') {
|
|
|
74
74
|
let next = original;
|
|
75
75
|
const ensureMeta = (name, value) => {
|
|
76
76
|
const escapedName = name.replace(/\./g, '\\.');
|
|
77
|
-
|
|
77
|
+
// Stop at a self-closing tag before considering a later closing tag.
|
|
78
|
+
const existing = new RegExp(`<meta-data\\b(?=[^>]*\\bandroid:name\\s*=\\s*(['"])${escapedName}\\1)[^>]*?(?:/\\s*>|>[\\s\\S]*?</meta-data\\s*>)`);
|
|
78
79
|
const tag = `<meta-data android:name="${name}" android:value="${value}" />`;
|
|
79
80
|
next = existing.test(next) ? next.replace(existing, tag)
|
|
80
81
|
: next.replace(/<application\b[^>]*>/, match => `${match}${newline} ${tag}`);
|
|
@@ -91,7 +92,7 @@ function syncAndroidAdmobPolicy(projectRoot, storeId, platform = 'android') {
|
|
|
91
92
|
return changed;
|
|
92
93
|
}
|
|
93
94
|
update(path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml'), original =>
|
|
94
|
-
original.replace(/^[ \t]*<(meta-data|activity|service|provider|receiver|uses-library)\b(?=[^>]*\bandroid:name\s*=\s*(['"])(?:com\.google\.android\.gms\.ads\.|com\.google\.ads\.|com\.google\.android\.ump\.)[^'"]*\2)[^>]
|
|
95
|
+
original.replace(/^[ \t]*<(meta-data|activity|service|provider|receiver|uses-library)\b(?=[^>]*\bandroid:name\s*=\s*(['"])(?:com\.google\.android\.gms\.ads\.|com\.google\.ads\.|com\.google\.android\.ump\.)[^'"]*\2)[^>]*?(?:\/\s*>|>[\s\S]*?<\/\1\s*>)[ \t]*(?:\r?\n)?/gm, ''));
|
|
95
96
|
update(path.join(projectRoot, 'android/app/src/main/assets/capacitor.config.json'), original => {
|
|
96
97
|
const generated = JSON.parse(original);
|
|
97
98
|
removeAdmobPluginConfig(generated);
|
|
@@ -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
|
@@ -4,6 +4,21 @@ const fs = require('node:fs');
|
|
|
4
4
|
const path = require('node:path');
|
|
5
5
|
const { syncAndroidAdmobPolicy, withNativeAdProvider, admobConfigPlugin } = require('../files/buildCodeplay/ruads.cjs');
|
|
6
6
|
|
|
7
|
+
// Capacitor's paired FileProvider metadata previously let a self-closing AdMob
|
|
8
|
+
// entry consume the app components up to a later closing tag.
|
|
9
|
+
const appComponents = ` <activity android:name=".MainActivity" android:exported="true">
|
|
10
|
+
<intent-filter>
|
|
11
|
+
<action android:name="android.intent.action.MAIN" />
|
|
12
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
13
|
+
</intent-filter>
|
|
14
|
+
</activity>
|
|
15
|
+
<provider android:name="androidx.core.content.FileProvider"
|
|
16
|
+
android:authorities="\${applicationId}.fileprovider" android:exported="false"
|
|
17
|
+
android:grantUriPermissions="true">
|
|
18
|
+
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
|
|
19
|
+
android:resource="@xml/file_paths"></meta-data>
|
|
20
|
+
</provider>`;
|
|
21
|
+
|
|
7
22
|
function fixture(enabled = true) {
|
|
8
23
|
const temp = path.resolve(__dirname, '../agent-temp');
|
|
9
24
|
fs.mkdirSync(temp, { recursive: true });
|
|
@@ -22,6 +37,7 @@ function fixture(enabled = true) {
|
|
|
22
37
|
<provider android:name="com.google.android.gms.ads.MobileAdsInitProvider" />
|
|
23
38
|
<activity android:name="com.my.target.ads.MyTargetActivity" />
|
|
24
39
|
<meta-data android:name="firebase_analytics_collection_enabled" android:value="true" />
|
|
40
|
+
${appComponents}
|
|
25
41
|
</application>
|
|
26
42
|
</manifest>
|
|
27
43
|
`;
|
|
@@ -40,6 +56,34 @@ function fixture(enabled = true) {
|
|
|
40
56
|
return { root, write, manifest, read: name => fs.readFileSync(path.join(root, name), 'utf8') };
|
|
41
57
|
}
|
|
42
58
|
|
|
59
|
+
for (const pairedMetadata of [false, true]) {
|
|
60
|
+
for (const storeId of [1, 10]) {
|
|
61
|
+
test(`store ${storeId}: preserve launcher and FileProvider with ${pairedMetadata ? 'paired' : 'self-closing'} ad entries`, () => {
|
|
62
|
+
const f = fixture();
|
|
63
|
+
const manifestPath = 'android/app/src/main/AndroidManifest.xml';
|
|
64
|
+
const manifest = pairedMetadata ? f.manifest
|
|
65
|
+
.replace('android:name="com.google.android.gms.ads.APPLICATION_ID" />',
|
|
66
|
+
'android:name="com.google.android.gms.ads.APPLICATION_ID"></meta-data>')
|
|
67
|
+
.replace('<provider android:name="com.google.android.gms.ads.MobileAdsInitProvider" />',
|
|
68
|
+
'<provider android:name="com.google.android.gms.ads.MobileAdsInitProvider"></provider>') : f.manifest
|
|
69
|
+
.replace("android:value='true'></meta-data>", "android:value='true' />")
|
|
70
|
+
.replace('<activity android:name="com.google.android.gms.ads.AdActivity"><intent-filter /></activity>',
|
|
71
|
+
'<activity android:name="com.google.android.gms.ads.AdActivity" />');
|
|
72
|
+
f.write(manifestPath, manifest);
|
|
73
|
+
for (const targetStore of [storeId, storeId === 1 ? 10 : 1, storeId]) {
|
|
74
|
+
syncAndroidAdmobPolicy(f.root, targetStore);
|
|
75
|
+
const updated = f.read(manifestPath);
|
|
76
|
+
assert.ok(updated.includes(appComponents), 'App components must remain byte-for-byte identical');
|
|
77
|
+
assert.match(updated, /firebase_analytics_collection_enabled/);
|
|
78
|
+
assert.match(updated, /MyTargetActivity/);
|
|
79
|
+
assert.equal(updated.includes('com.google.android.gms.ads.APPLICATION_ID'), targetStore === 1);
|
|
80
|
+
assert.equal(syncAndroidAdmobPolicy(f.root, targetStore), false);
|
|
81
|
+
assert.equal(f.read(manifestPath), updated);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
43
87
|
for (const storeId of [4, 10]) {
|
|
44
88
|
test(`store ${storeId}: clean synced config, stale manifest and SDKs; repeat safely`, () => {
|
|
45
89
|
const f = fixture();
|
|
@@ -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
|
+
});
|
package/scripts/sync-files.js
CHANGED
|
@@ -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);
|