codeplay-common 4.8.8 → 4.8.9

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.
@@ -1366,7 +1366,7 @@ function syncAndroidCodeOptimization() {
1366
1366
  }
1367
1367
 
1368
1368
  const currentContent = fs.readFileSync(androidAppBuildGradlePath, 'utf8');
1369
- const nextContent = currentContent.replace(
1369
+ let nextContent = currentContent.replace(
1370
1370
  /getDefaultProguardFile\(\s*(['"])proguard-android\.txt\1\s*\)/g,
1371
1371
  "getDefaultProguardFile('proguard-android-optimize.txt')"
1372
1372
  );
@@ -1375,6 +1375,27 @@ function syncAndroidCodeOptimization() {
1375
1375
  throw new Error('Android code optimisation setup failed: expected default ProGuard configuration was not found.');
1376
1376
  }
1377
1377
 
1378
+ const newline = currentContent.includes('\r\n') ? '\r\n' : '\n';
1379
+ nextContent = nextContent.replace(/^([ \t]*release[ \t]*\{)([\s\S]*?)(?=^[ \t]*\})/m, (match, header, body) => {
1380
+ const comments = body.match(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g) || [];
1381
+ if (comments.some(comment => /\bshrinkResources\b/.test(comment))) return match;
1382
+
1383
+ const activeBody = body.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g, '');
1384
+ const minifyEnabled = /^[ \t]*minifyEnabled\s*(?:=\s*)?true\b/m.test(activeBody);
1385
+ const shrinkPattern = /^([ \t]*shrinkResources\s*(?:=\s*)?)(true|false)\b/m;
1386
+ if (shrinkPattern.test(body)) {
1387
+ return minifyEnabled ? match : header + body.replace(shrinkPattern, '$1false');
1388
+ }
1389
+ return `${header}${newline} shrinkResources ${minifyEnabled}${body}`;
1390
+ });
1391
+
1392
+ const propertiesPath = path.join(androidPlatformPath, 'gradle.properties');
1393
+ const properties = fs.readFileSync(propertiesPath, 'utf8');
1394
+ // An explicit false value or a commented setting is an app-specific opt-out.
1395
+ if (!/^[ \t]*[#!]?[ \t]*android\.r8\.optimizedResourceShrinking(?:[ \t]*[=:]|[ \t]+|[ \t]*$)/m.test(properties)) {
1396
+ fs.writeFileSync(propertiesPath, `${properties.trimEnd()}${newline}android.r8.optimizedResourceShrinking=true${newline}`, 'utf8');
1397
+ }
1398
+
1378
1399
  if (nextContent !== currentContent) {
1379
1400
  fs.writeFileSync(androidAppBuildGradlePath, nextContent, 'utf8');
1380
1401
  }
@@ -4343,6 +4364,7 @@ await main();
4343
4364
  Release Notes
4344
4365
 
4345
4366
  6.5
4367
+ Release resource shrinking is configured automatically; commented settings and explicit false values preserve app-specific opt-outs.
4346
4368
  Android builds use the optimisation-enabled default ProGuard rules without changing minification settings or custom keep rules.
4347
4369
  Kids ad configuration disables iOS ATT prompts and excludes Android AD_ID during builds.
4348
4370
  Non-kids apps retain tracking prompts and normal permission behavior.
@@ -748,17 +748,39 @@ function ensureReleaseCodeOptimization() {
748
748
  if (!releaseBlock) throw new Error('Release build configuration was not found.');
749
749
 
750
750
  const releaseContent = currentContent.slice(releaseBlock.start, releaseBlock.end);
751
- const optimizedContent = releaseContent.replace(
751
+ let optimizedContent = releaseContent.replace(
752
752
  /getDefaultProguardFile\(\s*(['"])proguard-android\.txt\1\s*\)/g,
753
753
  "getDefaultProguardFile('proguard-android-optimize.txt')"
754
754
  );
755
755
  if (!/getDefaultProguardFile\(\s*(['"])proguard-android-optimize\.txt\1\s*\)/.test(optimizedContent)) {
756
756
  throw new Error('Release build must use the optimisation-enabled default ProGuard rules.');
757
757
  }
758
+ const newline = currentContent.includes('\r\n') ? '\r\n' : '\n';
759
+ // Preserve commented settings and explicit false values as app-specific opt-outs.
760
+ const comments = optimizedContent.match(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g) || [];
761
+ if (!comments.some(comment => /\bshrinkResources\b/.test(comment))) {
762
+ const activeContent = optimizedContent.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g, '');
763
+ const shrinkResources = /^[ \t]*minifyEnabled\s*(?:=\s*)?true\b/m.test(activeContent);
764
+ const shrinkPattern = /^([ \t]*shrinkResources\s*(?:=\s*)?)(true|false)\b/m;
765
+ if (shrinkPattern.test(optimizedContent)) {
766
+ if (!shrinkResources) optimizedContent = optimizedContent.replace(shrinkPattern, '$1false');
767
+ } else {
768
+ optimizedContent = `${newline} shrinkResources ${shrinkResources}${optimizedContent}`;
769
+ }
770
+ }
758
771
  if (optimizedContent !== releaseContent) {
759
772
  writeFileSync(gradleFilePath, currentContent.slice(0, releaseBlock.start)
760
773
  + optimizedContent + currentContent.slice(releaseBlock.end), 'utf8');
761
774
  }
775
+
776
+ const propertiesPath = join(__dirname, 'android', 'gradle.properties');
777
+ const properties = readFileSync(propertiesPath, 'utf8');
778
+ const propertyPattern = /^[ \t]*[#!]?[ \t]*android\.r8\.optimizedResourceShrinking(?:[ \t]*[=:]|[ \t]+|[ \t]*$)/m;
779
+ const property = 'android.r8.optimizedResourceShrinking=true';
780
+ const nextProperties = propertyPattern.test(properties)
781
+ ? properties
782
+ : `${properties.trimEnd()}${newline}${property}${newline}`;
783
+ if (nextProperties !== properties) writeFileSync(propertiesPath, nextProperties, 'utf8');
762
784
  }
763
785
 
764
786
  function signReleaseBundleWithSha256() {
@@ -893,21 +915,23 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
893
915
  // Determine desired minify value
894
916
  const desiredMinify = !_isffmpegUsed;
895
917
 
896
- // Check if minifyEnabled is already present
897
- if (/minifyEnabled\s+(true|false)/.test(updatedGradleContent)) {
918
+ // Limit minification changes to release; debug may have its own test settings.
919
+ const minificationBlock = findGradleBlock(updatedGradleContent, /buildTypes\s*\{[\s\S]*?\brelease\s*/);
920
+ if (!minificationBlock) {
921
+ throw new Error('Release build configuration was not found.');
922
+ }
923
+ let minificationContent = updatedGradleContent.slice(minificationBlock.start, minificationBlock.end);
924
+ if (/\bminifyEnabled\s*(?:=\s*)?(true|false)\b/.test(minificationContent)) {
898
925
  // Replace existing value with desired
899
- updatedGradleContent = updatedGradleContent.replace(/minifyEnabled\s+(true|false)/, `minifyEnabled ${desiredMinify}`);
926
+ minificationContent = minificationContent.replace(/\bminifyEnabled\s*(?:=\s*)?(true|false)\b/, `minifyEnabled ${desiredMinify}`);
900
927
  console.log(`Replaced minifyEnabled with ${desiredMinify}.`);
901
- } else if (/buildTypes\s*{[\s\S]*?release\s*{/.test(updatedGradleContent)) {
928
+ } else {
902
929
  // Insert minifyEnabled if not present
903
- updatedGradleContent = updatedGradleContent.replace(
904
- /(buildTypes\s*{[\s\S]*?release\s*{)/,
905
- `$1\n minifyEnabled ${desiredMinify}`
906
- );
930
+ minificationContent = `\n minifyEnabled ${desiredMinify}${minificationContent}`;
907
931
  console.log(`✅ Inserted minifyEnabled ${desiredMinify} into release block.`);
908
- } else {
909
- console.log('⚠️ Warning: buildTypes > release block not found. minifyEnabled was not added.');
910
932
  }
933
+ updatedGradleContent = updatedGradleContent.slice(0, minificationBlock.start)
934
+ + minificationContent + updatedGradleContent.slice(minificationBlock.end);
911
935
 
912
936
  // Add native debug symbols for release AABs, but leave any existing setting untouched.
913
937
  const releaseBlock = findGradleBlock(updatedGradleContent, /buildTypes\s*\{[\s\S]*?\brelease\s*/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "4.8.8",
3
+ "version": "4.8.9",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",