codeplay-common 4.11.34 → 4.11.35

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.
@@ -1,53 +1,53 @@
1
- // Shared ad interface for builds with both native providers disabled.
2
- const ignore = () => {};
3
- const unavailable = async () => false;
4
- const hidden = async () => true;
5
- export const _isVideoLoad = false;
6
- export const _isRewardInterstitialLoad = false;
7
- export const _isNativeAdLoaded = false;
8
- export const _bannerAdHeight = 0;
9
- export const adjustWebViewForBanner = ignore;
10
- export const hideGoogleBannerAd = hidden;
11
- export const showGoogleBannerAd = unavailable;
12
- export const canRequestAppAds = () => false;
13
- export const getAdPrivacyOptionsState = () => ({ supported: false, requirementStatus: 'NOT_REQUIRED', loading: false, error: false, canRetry: false });
14
- export const isAdPrivacyOptionsRequired = () => false;
15
- export const requestAppAdConsent = unavailable;
16
- export const adsOnDeviceReady = unavailable;
17
- export const showAppAdPrivacyOptions = unavailable;
18
- export const refreshAppAdConsent = showAppAdPrivacyOptions;
19
- export async function withAdPrivacyChoices(callback) {
20
- if (typeof callback === 'function') await callback();
21
- }
22
- export const disableFor_IAP_Subscription = ignore;
23
- export const enableFor_IAP_Subscription = ignore;
24
- export const disableFor_CREDIT_Subscription = ignore;
25
- export const showRewardVideo = unavailable;
26
- export async function levelWinInterstitial(callback) {
27
- if (typeof callback === 'function') await callback();
28
- return false;
29
- }
30
- export const runInterstitialTaskTransition = levelWinInterstitial;
31
- export const disableAppOpenAd = ignore;
32
- export const enableAppOpenAd = ignore;
33
- export const noAppOpenShowUntilResume = ignore;
34
- export const showRewardInterstitial = unavailable;
35
- export const showNativeAd = unavailable;
36
- export const showNativeAdInElement = showNativeAd;
37
- export const hideNativeAd = hidden;
38
- export const hideNativeAdInElement = hideNativeAd;
39
- export const loadPictureInPictureAd = unavailable;
40
- export const showPictureInPictureAd = loadPictureInPictureAd;
41
- export const hidePictureInPictureAd = hidden;
42
- export const destroyPictureInPictureAd = hidePictureInPictureAd;
43
- export const removePictureInPictureAd = destroyPictureInPictureAd;
44
- export const getPictureInPictureAdState = () => ({ loading: false, loaded: false, showing: false, fullscreen: false, adUnitId: '', error: null });
45
- export const addPictureInPictureAdListener = () => ({ remove: ignore });
46
-
47
- export const loadSqueezebackAd = async () => false;
48
- export const showSqueezebackAd = async () => false;
49
- export const hideSqueezebackAd = async () => true;
50
- export const destroySqueezebackAd = async () => true;
51
- export const getSqueezebackAdState = () => ({
52
- loading: false, loaded: false, showing: false, fullscreen: false, adUnitId: '', error: null
53
- });
1
+ // Shared ad interface for builds with both native providers disabled.
2
+ const ignore = () => {};
3
+ const unavailable = async () => false;
4
+ const hidden = async () => true;
5
+ export const _isVideoLoad = false;
6
+ export const _isRewardInterstitialLoad = false;
7
+ export const _isNativeAdLoaded = false;
8
+ export const _bannerAdHeight = 0;
9
+ export const adjustWebViewForBanner = ignore;
10
+ export const hideGoogleBannerAd = hidden;
11
+ export const showGoogleBannerAd = unavailable;
12
+ export const canRequestAppAds = () => false;
13
+ export const getAdPrivacyOptionsState = () => ({ supported: false, requirementStatus: 'NOT_REQUIRED', loading: false, error: false, canRetry: false });
14
+ export const isAdPrivacyOptionsRequired = () => false;
15
+ export const requestAppAdConsent = unavailable;
16
+ export const adsOnDeviceReady = unavailable;
17
+ export const showAppAdPrivacyOptions = unavailable;
18
+ export const refreshAppAdConsent = showAppAdPrivacyOptions;
19
+ export async function withAdPrivacyChoices(callback) {
20
+ if (typeof callback === 'function') await callback();
21
+ }
22
+ export const disableFor_IAP_Subscription = ignore;
23
+ export const enableFor_IAP_Subscription = ignore;
24
+ export const disableFor_CREDIT_Subscription = ignore;
25
+ export const showRewardVideo = unavailable;
26
+ export async function levelWinInterstitial(callback) {
27
+ if (typeof callback === 'function') await callback();
28
+ return false;
29
+ }
30
+ export const runInterstitialTaskTransition = levelWinInterstitial;
31
+ export const disableAppOpenAd = ignore;
32
+ export const enableAppOpenAd = ignore;
33
+ export const noAppOpenShowUntilResume = ignore;
34
+ export const showRewardInterstitial = unavailable;
35
+ export const showNativeAd = unavailable;
36
+ export const showNativeAdInElement = showNativeAd;
37
+ export const hideNativeAd = hidden;
38
+ export const hideNativeAdInElement = hideNativeAd;
39
+ export const loadPictureInPictureAd = unavailable;
40
+ export const showPictureInPictureAd = loadPictureInPictureAd;
41
+ export const hidePictureInPictureAd = hidden;
42
+ export const destroyPictureInPictureAd = hidePictureInPictureAd;
43
+ export const removePictureInPictureAd = destroyPictureInPictureAd;
44
+ export const getPictureInPictureAdState = () => ({ loading: false, loaded: false, showing: false, fullscreen: false, adUnitId: '', error: null });
45
+ export const addPictureInPictureAdListener = () => ({ remove: ignore });
46
+
47
+ export const loadSqueezebackAd = async () => false;
48
+ export const showSqueezebackAd = async () => false;
49
+ export const hideSqueezebackAd = async () => true;
50
+ export const destroySqueezebackAd = async () => true;
51
+ export const getSqueezebackAdState = () => ({
52
+ loading: false, loaded: false, showing: false, fullscreen: false, adUnitId: '', error: null
53
+ });
@@ -78,13 +78,21 @@ function syncIapAliases(projectRoot = process.cwd(), files = []) {
78
78
  (match, quote) => quote ? match : match.replace(/[^\r\n]/g, ' '));
79
79
  const header = /\balias\s*:\s*([\[{])/.exec(code);
80
80
  if (!header) throw new Error('Cannot configure @iap: Vite needs a resolve.alias object or array.');
81
- if (/['"]@iap['"]\s*[:,]/.test(code)) throw new Error('Cannot replace a custom @iap alias automatically; use codeplayIapAliases.findLatestIapDirectory().');
81
+ // Migrate only the standard versioned app directory; never evaluate config code.
82
+ const existing = /['"]@iap['"]\s*[:,]/.test(code);
83
+ const standard = /(['"]@iap['"]\s*:\s*|\bfind\s*:\s*['"]@iap['"]\s*,\s*replacement\s*:\s*)((?:path\.)?resolve\s*\(\s*__dirname\s*,\s*(['"])(?:\.\/)?src\/js\/Ads\/IAP-\d+(?:\.\d+)*\/?\3\s*\))(?=\s*[,}])/g;
84
+ const matches = [...code.matchAll(standard)];
85
+ if (existing && matches.length !== 1) throw new Error('Cannot replace a custom @iap alias automatically; use codeplayIapAliases.findLatestIapDirectory().');
82
86
  const entry = header[1] === '{'
83
87
  ? "'@iap': codeplayIapAliases.findLatestIapDirectory(),"
84
88
  : "{ find: '@iap', replacement: codeplayIapAliases.findLatestIapDirectory() },";
85
89
  const offset = header.index + header[0].length;
86
90
  const newline = original.includes('\r\n') ? '\r\n' : '\n';
87
- const updated = original.slice(0, offset) + newline + ' ' + entry + original.slice(offset);
91
+ const match = matches[0];
92
+ const start = match && match.index + match[1].length;
93
+ const updated = existing
94
+ ? original.slice(0, start) + 'codeplayIapAliases.findLatestIapDirectory()' + original.slice(start + match[2].length)
95
+ : original.slice(0, offset) + newline + ' ' + entry + original.slice(offset);
88
96
  original = `import codeplayIapAliases from './buildCodeplay/iap-alias.cjs';${newline}${updated}`;
89
97
  }
90
98
  if (!original.includes('codeplayIapAliases.legacyIapPlugin(')) {
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "codeplay-common",
3
- "version": "4.11.34",
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
- "terser": "^5.51.4"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/merbin2012/codeplay-common.git"
17
- },
18
- "author": "Codeplay Technologies",
19
- "license": "MIT",
20
- "files": [
21
- "files/",
22
- "scripts/",
23
- "README.md",
24
- "CHANGELOG.md",
25
- "RELEASE_NOTES.md",
26
- "LICENSE",
27
- "runtime/"
28
- ]
29
- }
1
+ {
2
+ "name": "codeplay-common",
3
+ "version": "4.11.35",
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
+ "terser": "^5.51.4"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/merbin2012/codeplay-common.git"
17
+ },
18
+ "author": "Codeplay Technologies",
19
+ "license": "MIT",
20
+ "files": [
21
+ "files/",
22
+ "scripts/",
23
+ "README.md",
24
+ "CHANGELOG.md",
25
+ "RELEASE_NOTES.md",
26
+ "LICENSE",
27
+ "runtime/"
28
+ ]
29
+ }
@@ -58,6 +58,45 @@ test('missing IAP modules fail before any source or Vite changes', () => {
58
58
  assert.equal(fs.readFileSync(path.join(f.root, 'vite.config.mjs'), 'utf8'), vite);
59
59
  });
60
60
 
61
+ test('existing standard versioned aliases migrate for object and array configurations', async () => {
62
+ const previous = process.cwd();
63
+ try {
64
+ for (const aliases of [
65
+ "{'@iap': path.resolve(__dirname, './src/js/Ads/IAP-5.2'), '@existing': '/unchanged'}",
66
+ "[{ find: '@iap', replacement: path.resolve(__dirname, './src/js/Ads/IAP-5.2') }, { find: '@existing', replacement: '/unchanged' }]",
67
+ ]) {
68
+ const f = fixture(aliases);
69
+ const vite = path.join(f.root, 'vite.config.mjs');
70
+ fs.writeFileSync(vite, "import path from 'node:path';\nconst __dirname = '/old';\n" + fs.readFileSync(vite, 'utf8'));
71
+ assert.deepEqual(syncIapAliases(f.root), ['vite.config.mjs']);
72
+ process.chdir(f.root);
73
+ const { default: configure } = await import(pathToFileURL(vite).href);
74
+ const config = await configure();
75
+ const entries = Array.isArray(config.resolve.alias) ? Object.fromEntries(config.resolve.alias.map(a => [a.find, a.replacement])) : config.resolve.alias;
76
+ assert.equal(entries['@iap'], path.join(f.root, 'src/js/Ads/IAP-4.8'));
77
+ assert.equal(entries['@existing'], '/unchanged');
78
+ assert.ok(config.plugins.some(plugin => plugin.name === 'codeplay-legacy-iap-imports'));
79
+ assert.deepEqual(syncIapAliases(f.root), []);
80
+ }
81
+ } finally { process.chdir(previous); }
82
+ });
83
+
84
+ test('custom IAP aliases fail without changing source or Vite configuration', () => {
85
+ for (const aliases of [
86
+ "{'@iap': path.resolve(__dirname, './custom/IAP-5.2')}",
87
+ "[{ find: '@iap', replacement: customIapDirectory() }]",
88
+ ]) {
89
+ const f = fixture(aliases);
90
+ const source = "import { x } from '../IAP-4.9/IAP-state.js';";
91
+ const file = f.write('src/caller.js', source);
92
+ const vite = path.join(f.root, 'vite.config.mjs');
93
+ const original = fs.readFileSync(vite, 'utf8');
94
+ assert.throws(() => syncIapAliases(f.root, [file]), /Cannot replace a custom @iap alias/);
95
+ assert.equal(fs.readFileSync(vite, 'utf8'), original);
96
+ assert.equal(fs.readFileSync(file, 'utf8'), source);
97
+ }
98
+ });
99
+
61
100
  test('apps without IAP are left unchanged', () => {
62
101
  const f = fixture(); fs.unlinkSync(path.join(f.root, 'src/js/Ads/IAP-4.8/IAP-state.js'));
63
102
  assert.equal(findLatestIapDirectory(f.root), null);
@@ -1,78 +1,78 @@
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
- const script = fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/codeplayBeforeBuild.js'), 'utf8');
7
- const defaults = script.slice(script.indexOf('const ADMOB_NEXTGEN_DEFAULTS ='), script.indexOf('function getAdmobJsonPath()'));
8
- const merge = script.slice(script.indexOf('const mergeObjects ='), script.indexOf('const syncAdmobNextgenPackage ='));
9
- const context = vm.createContext({ compareVersionStrings: (a, b) => a.localeCompare(b, undefined, { numeric: true }) });
10
- vm.runInContext(defaults + merge, context);
11
- const migrate = (template = {}, app = {}, old = {}) => JSON.parse(JSON.stringify(vm.runInContext(
12
- `buildNextgenAdmobConfigFromOldConfig(${JSON.stringify(template)},${JSON.stringify(app)},${JSON.stringify(old)})`, context)));
13
-
14
- test('old app configs acquire the new properties and a dedicated test unit', () => {
15
- const result = migrate({}, { VERSION: '1.8', android: { bannerid: 'app-banner' } });
16
- assert.equal(result.VERSION, '1.9');
17
- assert.equal(result.config.setCoarseLocationCollectionEnabled, true);
18
- assert.equal(result.config.squeezebackEnabled, false);
19
- assert.equal(result.config.squeezebackRetryIntervalMs, 5000);
20
- assert.deepEqual(result.config.squeezebackPages, []);
21
- assert.equal(result.android.squeezebackid, '');
22
- assert.equal(result.ios.squeezebackid, '');
23
- assert.equal(result.testid.squeezebackid, 'ca-app-pub-3940256099942544/9983381271');
24
- assert.equal(result.android.bannerid, 'app-banner');
25
- });
26
-
27
- test('migration preserves explicit false, placement lists, custom IDs and newer schemas', () => {
28
- const app = { VERSION: '2.0', config: { setCoarseLocationCollectionEnabled: false,
29
- squeezebackEnabled: true, squeezebackPages: ['quizresult'], squeezebackRetryIntervalMs: 9000 },
30
- android: { squeezebackid: 'app-live' }, testid: { squeezebackid: 'app-test' } };
31
- const result = migrate({}, app);
32
- assert.equal(result.VERSION, '2.0');
33
- for (const [key, value] of Object.entries(app.config)) assert.deepEqual(result.config[key], value);
34
- assert.equal(result.android.squeezebackid, 'app-live');
35
- assert.equal(result.testid.squeezebackid, 'app-test');
36
- assert.deepEqual(migrate({}, result), result);
37
- });
38
-
39
- test('downloaded templates cannot opt apps into squeezeback or import publisher IDs', () => {
40
- const template = { config: { squeezebackEnabled: true, squeezebackPages: ['home'],
41
- setCoarseLocationCollectionEnabled: false }, android: { squeezebackid: 'foreign-live' },
42
- testid: { squeezebackid: 'foreign-test' } };
43
- const result = migrate(template);
44
- assert.equal(result.config.squeezebackEnabled, false);
45
- assert.deepEqual(result.config.squeezebackPages, []);
46
- assert.equal(result.config.setCoarseLocationCollectionEnabled, true);
47
- assert.equal(result.android.squeezebackid, '');
48
- assert.equal(result.testid.squeezebackid, 'ca-app-pub-3940256099942544/9983381271');
49
- });
50
-
51
- test('legacy app settings are retained with current app settings taking priority', () => {
52
- const result = migrate({}, { android: { squeezebackid: '' } }, {
53
- android: { squeezebackid: 'old-live' }, config: { squeezebackEnabled: true, setCoarseLocationCollectionEnabled: false }
54
- });
55
- assert.equal(result.android.squeezebackid, '');
56
- assert.equal(result.config.squeezebackEnabled, true);
57
- assert.equal(result.config.setCoarseLocationCollectionEnabled, false);
58
- });
59
-
60
- for (const enabled of [undefined, false, true]) {
61
- for (const installed of [null, '1.6.0', '1.6.1-beta', '1.7.0']) {
62
- test(`native plugin: installed=${installed}, squeezebackEnabled=${enabled}`, () => {
63
- const commands = [];
64
- const start = script.indexOf('const syncAdmobNextgenPackage =');
65
- const code = script.slice(start, script.indexOf('const downloadOptionalCodeplayFile', start));
66
- vm.runInNewContext(code + '\nsyncAdmobNextgenPackage();', {
67
- fs: { existsSync: () => true }, packageJsonPath: 'package.json',
68
- isPackageAvailable: () => false, getInstalledVersion: () => installed,
69
- getAdmobJsonPath: () => 'config.json', readJsonSafe: () => ({ config: { squeezebackEnabled: enabled } }),
70
- compareVersionStrings: (a, b) => a.localeCompare(b, undefined, { numeric: true }),
71
- runNpmCommand: command => commands.push(command), console: { log() {}, warn() {} }
72
- });
73
- const update = !installed || (enabled === true && installed === '1.6.0');
74
- assert.deepEqual(commands, update
75
- ? [`npm install capacitor-admob-nextgen${enabled === true ? '@^1.6.1-beta' : ''}`] : []);
76
- });
77
- }
78
- }
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
+ const script = fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/codeplayBeforeBuild.js'), 'utf8');
7
+ const defaults = script.slice(script.indexOf('const ADMOB_NEXTGEN_DEFAULTS ='), script.indexOf('function getAdmobJsonPath()'));
8
+ const merge = script.slice(script.indexOf('const mergeObjects ='), script.indexOf('const syncAdmobNextgenPackage ='));
9
+ const context = vm.createContext({ compareVersionStrings: (a, b) => a.localeCompare(b, undefined, { numeric: true }) });
10
+ vm.runInContext(defaults + merge, context);
11
+ const migrate = (template = {}, app = {}, old = {}) => JSON.parse(JSON.stringify(vm.runInContext(
12
+ `buildNextgenAdmobConfigFromOldConfig(${JSON.stringify(template)},${JSON.stringify(app)},${JSON.stringify(old)})`, context)));
13
+
14
+ test('old app configs acquire the new properties and a dedicated test unit', () => {
15
+ const result = migrate({}, { VERSION: '1.8', android: { bannerid: 'app-banner' } });
16
+ assert.equal(result.VERSION, '1.9');
17
+ assert.equal(result.config.setCoarseLocationCollectionEnabled, true);
18
+ assert.equal(result.config.squeezebackEnabled, false);
19
+ assert.equal(result.config.squeezebackRetryIntervalMs, 5000);
20
+ assert.deepEqual(result.config.squeezebackPages, []);
21
+ assert.equal(result.android.squeezebackid, '');
22
+ assert.equal(result.ios.squeezebackid, '');
23
+ assert.equal(result.testid.squeezebackid, 'ca-app-pub-3940256099942544/9983381271');
24
+ assert.equal(result.android.bannerid, 'app-banner');
25
+ });
26
+
27
+ test('migration preserves explicit false, placement lists, custom IDs and newer schemas', () => {
28
+ const app = { VERSION: '2.0', config: { setCoarseLocationCollectionEnabled: false,
29
+ squeezebackEnabled: true, squeezebackPages: ['quizresult'], squeezebackRetryIntervalMs: 9000 },
30
+ android: { squeezebackid: 'app-live' }, testid: { squeezebackid: 'app-test' } };
31
+ const result = migrate({}, app);
32
+ assert.equal(result.VERSION, '2.0');
33
+ for (const [key, value] of Object.entries(app.config)) assert.deepEqual(result.config[key], value);
34
+ assert.equal(result.android.squeezebackid, 'app-live');
35
+ assert.equal(result.testid.squeezebackid, 'app-test');
36
+ assert.deepEqual(migrate({}, result), result);
37
+ });
38
+
39
+ test('downloaded templates cannot opt apps into squeezeback or import publisher IDs', () => {
40
+ const template = { config: { squeezebackEnabled: true, squeezebackPages: ['home'],
41
+ setCoarseLocationCollectionEnabled: false }, android: { squeezebackid: 'foreign-live' },
42
+ testid: { squeezebackid: 'foreign-test' } };
43
+ const result = migrate(template);
44
+ assert.equal(result.config.squeezebackEnabled, false);
45
+ assert.deepEqual(result.config.squeezebackPages, []);
46
+ assert.equal(result.config.setCoarseLocationCollectionEnabled, true);
47
+ assert.equal(result.android.squeezebackid, '');
48
+ assert.equal(result.testid.squeezebackid, 'ca-app-pub-3940256099942544/9983381271');
49
+ });
50
+
51
+ test('legacy app settings are retained with current app settings taking priority', () => {
52
+ const result = migrate({}, { android: { squeezebackid: '' } }, {
53
+ android: { squeezebackid: 'old-live' }, config: { squeezebackEnabled: true, setCoarseLocationCollectionEnabled: false }
54
+ });
55
+ assert.equal(result.android.squeezebackid, '');
56
+ assert.equal(result.config.squeezebackEnabled, true);
57
+ assert.equal(result.config.setCoarseLocationCollectionEnabled, false);
58
+ });
59
+
60
+ for (const enabled of [undefined, false, true]) {
61
+ for (const installed of [null, '1.6.0', '1.6.1-beta', '1.7.0']) {
62
+ test(`native plugin: installed=${installed}, squeezebackEnabled=${enabled}`, () => {
63
+ const commands = [];
64
+ const start = script.indexOf('const syncAdmobNextgenPackage =');
65
+ const code = script.slice(start, script.indexOf('const downloadOptionalCodeplayFile', start));
66
+ vm.runInNewContext(code + '\nsyncAdmobNextgenPackage();', {
67
+ fs: { existsSync: () => true }, packageJsonPath: 'package.json',
68
+ isPackageAvailable: () => false, getInstalledVersion: () => installed,
69
+ getAdmobJsonPath: () => 'config.json', readJsonSafe: () => ({ config: { squeezebackEnabled: enabled } }),
70
+ compareVersionStrings: (a, b) => a.localeCompare(b, undefined, { numeric: true }),
71
+ runNpmCommand: command => commands.push(command), console: { log() {}, warn() {} }
72
+ });
73
+ const update = !installed || (enabled === true && installed === '1.6.0');
74
+ assert.deepEqual(commands, update
75
+ ? [`npm install capacitor-admob-nextgen${enabled === true ? '@^1.6.1-beta' : ''}`] : []);
76
+ });
77
+ }
78
+ }
@@ -35,4 +35,4 @@ test('installs a missing package', () => assert.equal(run({ installed: null }).c
35
35
  test('replaces a local plugin reference', () => assert.equal(run({ declared: 'file:../plugin' }).commands.length, 1));
36
36
  test('offline builds skip the registry check', () => assert.deepEqual(run({ offline: true }), { commands: [], queries: 0 }));
37
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/));
38
+ test('installation failure stops the build', () => assert.throws(() => run({ fail: true }), /install failed/));