@capacitor/cli 9.0.0-alpha.5 → 9.0.0-alpha.6

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.
Binary file
Binary file
Binary file
@@ -206,10 +206,7 @@ if (hasProperty('postBuildExtras')) {
206
206
  }
207
207
  exports.installGradlePlugins = installGradlePlugins;
208
208
  async function handleCordovaPluginsGradle(config, cordovaPlugins) {
209
- var _a, _b, _c;
210
209
  const pluginsGradlePath = (0, path_1.join)(config.android.cordovaPluginsDirAbs, 'build.gradle');
211
- const kotlinNeeded = await kotlinNeededCheck(config, cordovaPlugins);
212
- const kotlinVersionString = (_c = (_b = (_a = config.app.extConfig.cordova) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.GradlePluginKotlinVersion) !== null && _c !== void 0 ? _c : '2.4.0';
213
210
  const frameworksArray = [];
214
211
  let prefsArray = [];
215
212
  const applyArray = [];
@@ -241,21 +238,10 @@ async function handleCordovaPluginsGradle(config, cordovaPlugins) {
241
238
  })
242
239
  .join('\n');
243
240
  frameworkString = await replaceFrameworkVariables(config, prefsArray, frameworkString);
244
- if (kotlinNeeded) {
245
- frameworkString += `\n implementation "androidx.core:core-ktx:$androidxCoreKTXVersion"`;
246
- frameworkString += `\n implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"`;
247
- }
248
241
  const applyString = applyArray.join('\n');
249
242
  let buildGradle = await (0, fs_extra_1.readFile)(pluginsGradlePath, { encoding: 'utf-8' });
250
243
  buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + frameworkString.concat('\n') + ' $2');
251
244
  buildGradle = buildGradle.replace(/(PLUGIN GRADLE EXTENSIONS START)[\s\S]*(\/\/ PLUGIN GRADLE EXTENSIONS END)/, '$1\n' + applyString.concat('\n') + '$2');
252
- if (kotlinNeeded) {
253
- buildGradle = buildGradle.replace(/(buildscript\s{\n(\t|\s{4})repositories\s{\n((\t{2}|\s{8}).+\n)+(\t|\s{4})}\n(\t|\s{4})dependencies\s{\n(\t{2}|\s{8}).+)\n((\t|\s{4})}\n}\n)/, `$1\n classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"\n$8`);
254
- buildGradle = buildGradle.replace(/(ext\s{)/, `$1\n androidxCoreKTXVersion = project.hasProperty('androidxCoreKTXVersion') ? rootProject.ext.androidxCoreKTXVersion : '1.8.0'`);
255
- buildGradle = buildGradle.replace(/(buildscript\s{)/, `$1\n ext.kotlin_version = project.hasProperty('kotlin_version') ? rootProject.ext.kotlin_version : '${kotlinVersionString}'`);
256
- buildGradle = buildGradle.replace(/(apply\splugin:\s'com\.android\.library')/, `$1\napply plugin: 'kotlin-android'`);
257
- buildGradle = buildGradle.replace(/(compileOptions\s{\n((\t{2}|\s{8}).+\n)+(\t|\s{4})})\n(})/, `$1\n sourceSets {\n main.java.srcDirs += 'src/main/kotlin'\n }\n$5`);
258
- }
259
245
  await (0, fs_extra_1.writeFile)(pluginsGradlePath, buildGradle);
260
246
  const cordovaVariables = `// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
261
247
  ext {
@@ -267,26 +253,6 @@ ext {
267
253
  await (0, fs_extra_1.writeFile)((0, path_1.join)(config.android.cordovaPluginsDirAbs, 'cordova.variables.gradle'), cordovaVariables);
268
254
  }
269
255
  exports.handleCordovaPluginsGradle = handleCordovaPluginsGradle;
270
- async function kotlinNeededCheck(config, cordovaPlugins) {
271
- var _a, _b;
272
- if (((_b = (_a = config.app.extConfig.cordova) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.GradlePluginKotlinEnabled) !== 'true') {
273
- for (const plugin of cordovaPlugins) {
274
- const androidPlatform = (0, plugin_1.getPluginPlatform)(plugin, platform);
275
- const sourceFiles = androidPlatform['source-file'];
276
- if (sourceFiles) {
277
- for (const srcFile of sourceFiles) {
278
- if (/^.*\.kt$/.test(srcFile['$'].src)) {
279
- return true;
280
- }
281
- }
282
- }
283
- }
284
- return false;
285
- }
286
- else {
287
- return true;
288
- }
289
- }
290
256
  async function copyPluginsNativeFiles(config, cordovaPlugins) {
291
257
  const pluginsPath = (0, path_1.join)(config.android.cordovaPluginsDirAbs, 'src', 'main');
292
258
  for (const p of cordovaPlugins) {
@@ -4,7 +4,7 @@ exports.setAllStringIn = exports.migrateCommand = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs_extra_1 = require("fs-extra");
6
6
  const path_1 = require("path");
7
- const rimraf_1 = tslib_1.__importDefault(require("rimraf"));
7
+ const rimraf_1 = require("rimraf");
8
8
  const semver_1 = require("semver");
9
9
  const colors_1 = tslib_1.__importDefault(require("../colors"));
10
10
  const common_1 = require("../common");
@@ -44,23 +44,22 @@ const plugins = [
44
44
  '@capacitor/text-zoom',
45
45
  '@capacitor/toast',
46
46
  ];
47
- const coreVersion = '^8.0.0';
48
- const pluginVersion = '^8.0.0';
47
+ const coreVersion = 'next';
48
+ const pluginVersion = 'next';
49
49
  const gradleVersion = '9.5.1';
50
50
  const iOSVersion = '16';
51
- const kotlinVersion = '2.4.0';
52
51
  let installFailed = false;
53
52
  async function migrateCommand(config, noprompt, packagemanager) {
54
53
  if (config === null) {
55
54
  (0, errors_1.fatal)('Config data missing');
56
55
  }
57
56
  const capMajor = await checkCapacitorMajorVersion(config);
58
- if (capMajor < 7) {
59
- (0, errors_1.fatal)('Migrate can only be used on Capacitor 7, please use the CLI in Capacitor 7 to upgrade to 7 first');
57
+ if (capMajor < 8) {
58
+ (0, errors_1.fatal)('Migrate can only be used on Capacitor 8, please use the CLI in Capacitor 8 to upgrade to 8 first');
60
59
  }
61
60
  const jdkMajor = await (0, common_1.checkJDKMajorVersion)();
62
61
  if (jdkMajor < 21) {
63
- log_1.logger.warn('Capacitor 8 requires JDK 21 or higher. Some steps may fail.');
62
+ log_1.logger.warn('Capacitor 9 requires JDK 21 or higher. Some steps may fail.');
64
63
  }
65
64
  const variablesAndClasspaths = await getAndroidVariablesAndClasspaths(config);
66
65
  if (!variablesAndClasspaths) {
@@ -70,11 +69,11 @@ async function migrateCommand(config, noprompt, packagemanager) {
70
69
  ...config.app.package.dependencies,
71
70
  ...config.app.package.devDependencies,
72
71
  };
73
- const monorepoWarning = 'Please note this tool is not intended for use in a mono-repo environment, you should migrate manually instead. Refer to https://capacitorjs.com/docs/next/updating/8-0';
72
+ const monorepoWarning = 'Please note this tool is not intended for use in a mono-repo environment, you should migrate manually instead. Refer to https://capacitorjs.com/docs/next/updating/9-0';
74
73
  log_1.logger.info(monorepoWarning);
75
74
  const { migrateconfirm } = noprompt
76
75
  ? { migrateconfirm: 'y' }
77
- : await (0, log_1.logPrompt)(`Capacitor 8 sets a deployment target of iOS ${iOSVersion} and Android 17 (SDK 37). \n`, {
76
+ : await (0, log_1.logPrompt)(`Capacitor 9 sets a deployment target of iOS ${iOSVersion} and Android 17 (SDK 37). \n`, {
78
77
  type: 'text',
79
78
  name: 'migrateconfirm',
80
79
  message: `Are you sure you want to migrate? (Y/n)`,
@@ -136,6 +135,9 @@ async function migrateCommand(config, noprompt, packagemanager) {
136
135
  else {
137
136
  log_1.logger.warn('Skipped updating deployment target');
138
137
  }
138
+ await (0, common_1.runTask)(`Migrating AppDelegate.swift`, () => {
139
+ return updateAppDelegate((0, path_1.join)(config.ios.nativeTargetDirAbs, 'AppDelegate.swift'));
140
+ });
139
141
  }
140
142
  if (!installFailed) {
141
143
  await (0, common_1.runTask)(`Running cap sync.`, () => {
@@ -179,6 +181,19 @@ async function migrateCommand(config, noprompt, packagemanager) {
179
181
  await (0, common_1.runTask)(`Migrating app build.gradle file.`, () => {
180
182
  return updateAppBuildGradle((0, path_1.join)(config.android.appDirAbs, 'build.gradle'));
181
183
  });
184
+ // settings.gradle
185
+ await (0, common_1.runTask)(`Migrating settings.gradle file.`, () => {
186
+ return (async () => {
187
+ const settingsPath = (0, path_1.join)(config.android.platformDirAbs, 'settings.gradle');
188
+ let txt = readFile(settingsPath);
189
+ if (!txt) {
190
+ return;
191
+ }
192
+ txt = txt.replace(`include ':capacitor-cordova-android-plugins'\n`, '');
193
+ txt = txt.replace(`project(':capacitor-cordova-android-plugins').projectDir = new File('./capacitor-cordova-android-plugins/')\n`, '');
194
+ (0, fs_extra_1.writeFileSync)(settingsPath, txt, { encoding: 'utf-8' });
195
+ })();
196
+ });
182
197
  // Variables gradle
183
198
  await (0, common_1.runTask)(`Migrating variables.gradle file.`, () => {
184
199
  return (async () => {
@@ -233,7 +248,7 @@ async function migrateCommand(config, noprompt, packagemanager) {
233
248
  }
234
249
  })();
235
250
  });
236
- rimraf_1.default.sync((0, path_1.join)(config.android.appDirAbs, 'build'));
251
+ rimraf_1.rimraf.sync((0, path_1.join)(config.android.appDirAbs, 'build'));
237
252
  }
238
253
  // Write all breaking changes
239
254
  await (0, common_1.runTask)(`Writing breaking changes.`, () => {
@@ -273,7 +288,9 @@ async function installLatestLibs(dependencyManager, runInstall, config) {
273
288
  if (libs.includes(devDepKey)) {
274
289
  pkgJson['devDependencies'][devDepKey] = coreVersion;
275
290
  }
276
- else if (plugins.includes(devDepKey)) {
291
+ else if (plugins.includes(devDepKey) &&
292
+ !(pkgJson['devDependencies'][devDepKey].startsWith('file:') ||
293
+ pkgJson['devDependencies'][devDepKey].startsWith('workspace:'))) {
277
294
  pkgJson['devDependencies'][devDepKey] = pluginVersion;
278
295
  }
279
296
  }
@@ -281,7 +298,8 @@ async function installLatestLibs(dependencyManager, runInstall, config) {
281
298
  if (libs.includes(depKey)) {
282
299
  pkgJson['dependencies'][depKey] = coreVersion;
283
300
  }
284
- else if (plugins.includes(depKey)) {
301
+ else if (plugins.includes(depKey) &&
302
+ !(pkgJson['dependencies'][depKey].startsWith('file:') || pkgJson['dependencies'][depKey].startsWith('workspace:'))) {
285
303
  pkgJson['dependencies'][depKey] = pluginVersion;
286
304
  }
287
305
  }
@@ -289,7 +307,7 @@ async function installLatestLibs(dependencyManager, runInstall, config) {
289
307
  encoding: 'utf-8',
290
308
  });
291
309
  if (runInstall) {
292
- rimraf_1.default.sync((0, path_1.join)(config.app.rootDir, 'node_modules/@capacitor/!(cli)'));
310
+ rimraf_1.rimraf.sync((0, path_1.join)(config.app.rootDir, 'node_modules/@capacitor/!(cli)'));
293
311
  await (0, subprocess_1.runCommand)(dependencyManager, ['install']);
294
312
  if (dependencyManager == 'yarn') {
295
313
  await (0, subprocess_1.runCommand)(dependencyManager, ['upgrade']);
@@ -303,18 +321,7 @@ async function installLatestLibs(dependencyManager, runInstall, config) {
303
321
  }
304
322
  }
305
323
  async function writeBreakingChanges() {
306
- const breaking = [
307
- '@capacitor/action-sheet',
308
- '@capacitor/barcode-scanner',
309
- '@capacitor/browser',
310
- '@capacitor/camera',
311
- '@capacitor/geolocation',
312
- '@capacitor/google-maps',
313
- '@capacitor/push-notifications',
314
- '@capacitor/screen-orientation',
315
- '@capacitor/splash-screen',
316
- '@capacitor/status-bar',
317
- ];
324
+ const breaking = ['@capacitor/push-notifications', '@capacitor/splash-screen'];
318
325
  const broken = [];
319
326
  for (const lib of breaking) {
320
327
  if (allDependencies[lib]) {
@@ -322,7 +329,7 @@ async function writeBreakingChanges() {
322
329
  }
323
330
  }
324
331
  if (broken.length > 0) {
325
- log_1.logger.info(`IMPORTANT: Review https://capacitorjs.com/docs/next/updating/8-0#plugins for breaking changes in these plugins that you use: ${broken.join(', ')}.`);
332
+ log_1.logger.info(`IMPORTANT: Review https://capacitorjs.com/docs/next/updating/9-0#plugins for breaking changes in these plugins that you use: ${broken.join(', ')}.`);
326
333
  }
327
334
  }
328
335
  async function getAndroidVariablesAndClasspaths(config) {
@@ -402,38 +409,24 @@ async function updateBuildGradle(filename, variablesAndClasspaths) {
402
409
  }
403
410
  }
404
411
  }
405
- const beforeKotlinVersionUpdate = replaced;
406
- replaced = replaceVersion(replaced, /(ext\.kotlin_version\s*=\s*['"])([^'"]+)(['"])/, kotlinVersion);
407
- replaced = replaceVersion(replaced, /(org\.jetbrains\.kotlin:kotlin[^:]*:)([\d.]+)(['"])/, kotlinVersion);
408
- if (beforeKotlinVersionUpdate !== replaced) {
409
- log_1.logger.info(`Set Kotlin version to ${kotlinVersion}`);
410
- }
411
412
  (0, fs_extra_1.writeFileSync)(filename, replaced, 'utf-8');
412
413
  }
413
- function replaceVersion(text, regex, newVersion) {
414
- return text.replace(regex, (match, prefix, currentVersion, suffix) => {
415
- var _a;
416
- const semVer = (_a = (0, semver_1.coerce)(currentVersion)) === null || _a === void 0 ? void 0 : _a.version;
417
- if ((0, semver_1.gte)(newVersion, semVer ? semVer : '0.0.0')) {
418
- return `${prefix || ''}${newVersion}${suffix || ''}`;
419
- }
420
- return match;
421
- });
422
- }
423
414
  async function updateAppBuildGradle(filename) {
424
415
  const txt = readFile(filename);
425
416
  if (!txt) {
426
417
  return;
427
418
  }
428
419
  let replaced = txt;
429
- const gradlePproperties = ['compileSdk', 'namespace', 'ignoreAssetsPattern'];
430
- for (const prop of gradlePproperties) {
431
- // Use updated Groovy DSL syntax with " = " assignment
432
- const regex = new RegExp(`(^\\s*${prop})\\s+(?!=)(.+)$`, 'gm');
433
- replaced = replaced.replace(regex, (_match, key, value) => {
434
- return `${key} = ${value.trim()}`;
435
- });
420
+ replaced = replaced.replace(`proguard-android.txt`, `proguard-android-optimize.txt`);
421
+ replaced = replaced.replace(' targetSdkVersion rootProject.ext.targetSdkVersion\n', '');
422
+ replaced = replaced.replace(` implementation project(':capacitor-cordova-android-plugins')\n`, '');
423
+ replaced = replaced.replace(`repositories {
424
+ flatDir{
425
+ dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
436
426
  }
427
+ }
428
+
429
+ `, '');
437
430
  (0, fs_extra_1.writeFileSync)(filename, replaced, 'utf-8');
438
431
  }
439
432
  async function updateFile(config, filename, textStart, textEnd, replacement, skipIfNotFound) {
@@ -517,3 +510,19 @@ async function updateAndroidManifest(filename) {
517
510
  (0, fs_extra_1.writeFileSync)(filename, replaced, 'utf-8');
518
511
  }
519
512
  }
513
+ async function updateAppDelegate(filename) {
514
+ const txt = readFile(filename);
515
+ if (!txt) {
516
+ return;
517
+ }
518
+ if (txt.includes('@main')) {
519
+ return; // Probably already updated
520
+ }
521
+ const replaced = txt.replace('@UIApplicationMain', '@main');
522
+ if (!replaced.includes('@main')) {
523
+ log_1.logger.error(`Unable to replace @UIApplicationMain to @main in ${filename}. Try replacing it manually`);
524
+ }
525
+ else {
526
+ (0, fs_extra_1.writeFileSync)(filename, replaced, 'utf-8');
527
+ }
528
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/cli",
3
- "version": "9.0.0-alpha.5",
3
+ "version": "9.0.0-alpha.6",
4
4
  "description": "Capacitor: Cross-platform apps with JavaScript and the web",
5
5
  "homepage": "https://capacitorjs.com",
6
6
  "author": "Ionic Team <hi@ionic.io> (https://ionic.io)",