@capacitor/cli 9.0.0-rc.0 → 9.0.0

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
@@ -252,7 +252,7 @@ async function handleCordovaPluginsGradle(config, cordovaPlugins) {
252
252
  await (0, fs_extra_1.writeFile)(pluginsGradlePath, buildGradle);
253
253
  const cordovaVariables = `// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
254
254
  ext {
255
- cdvMinSdkVersion = project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : ${config.android.minVersion}
255
+ cdvMinSdkVersion = rootProject.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : ${config.android.minVersion}
256
256
  // Plugin gradle extensions can append to this to have code run at the end.
257
257
  cdvPluginPostBuildExtras = []
258
258
  cordovaConfig = [:]
@@ -55,7 +55,6 @@ async function updatePluginFiles(config, plugins, deployment) {
55
55
  const iosPlatformVersion = await (0, common_1.getCapacitorPackageVersion)(config, config.ios.name);
56
56
  const majorCapVersion = (0, semver_1.major)(iosPlatformVersion);
57
57
  const capacitorPackagePath = await (0, capacitor_package_1.resolveCapacitorPackagePath)(config);
58
- const iosVersion = (0, common_2.getMajoriOSVersion)(config);
59
58
  await Promise.all(validSPMPackages.map(async (plugin) => {
60
59
  const packageSwiftPath = (0, path_1.join)(plugin.rootPath, 'Package.swift');
61
60
  const content = await (0, fs_extra_1.readFile)(packageSwiftPath, { encoding: 'utf-8' });
@@ -66,7 +65,7 @@ async function updatePluginFiles(config, plugins, deployment) {
66
65
  // The plugin has to resolve to the same package identity as the app, or SPM ends up with
67
66
  // two packages that both vend a Capacitor product.
68
67
  let rewritten = (0, capacitor_package_1.rewriteCapacitorDependency)(content, capacitorPackagePath, plugin.rootPath);
69
- rewritten = (0, capacitor_package_1.patchPackageSwiftDeploymentTarget)(rewritten, iosVersion).content;
68
+ rewritten = (0, capacitor_package_1.patchPackageSwiftDeploymentTarget)(rewritten, config.ios.minVersion).content;
70
69
  if (rewritten !== content) {
71
70
  await (0, fs_extra_1.writeFile)(packageSwiftPath, rewritten);
72
71
  }
@@ -49,8 +49,20 @@ const plugins = [
49
49
  '@capacitor/text-zoom',
50
50
  '@capacitor/toast',
51
51
  ];
52
- const coreVersion = 'next';
53
- const pluginVersion = 'next';
52
+ const versionedPlugins = {
53
+ '@capacitor/background-runner': '^4.0.0',
54
+ '@capacitor/barcode-scanner': '^4.0.0',
55
+ '@capacitor/calendar': '^2.0.0',
56
+ '@capacitor/contacts': '^2.0.0',
57
+ '@capacitor/file-transfer': '^3.0.0',
58
+ '@capacitor/file-viewer': '^3.0.0',
59
+ '@capacitor/health-fitness': '^2.0.0',
60
+ '@capacitor/inappbrowser': '^5.0.0',
61
+ '@capacitor/privacy-screen': '^3.0.0',
62
+ };
63
+ const coreVersion = '9.0.0';
64
+ const coreNPMVersion = (0, semver_1.valid)(coreVersion) ? `^${coreVersion}` : 'next';
65
+ const pluginVersion = '^9.0.0';
54
66
  const gradleVersion = '9.8.2';
55
67
  const iOSVersion = '16';
56
68
  let installFailed = false;
@@ -351,24 +363,25 @@ async function installLatestLibs(dependencyManager, runInstall, config) {
351
363
  if (!pkgJsonFile) {
352
364
  return;
353
365
  }
366
+ const allPlugins = plugins.concat(Object.keys(versionedPlugins));
354
367
  const pkgJson = JSON.parse(pkgJsonFile);
355
368
  for (const devDepKey of Object.keys(pkgJson['devDependencies'] || {})) {
356
369
  if (libs.includes(devDepKey)) {
357
- pkgJson['devDependencies'][devDepKey] = coreVersion;
370
+ pkgJson['devDependencies'][devDepKey] = coreNPMVersion;
358
371
  }
359
- else if (plugins.includes(devDepKey) &&
372
+ else if (allPlugins.includes(devDepKey) &&
360
373
  !(pkgJson['devDependencies'][devDepKey].startsWith('file:') ||
361
374
  pkgJson['devDependencies'][devDepKey].startsWith('workspace:'))) {
362
- pkgJson['devDependencies'][devDepKey] = pluginVersion;
375
+ pkgJson['devDependencies'][devDepKey] = versionedPlugins[devDepKey] ? versionedPlugins[devDepKey] : pluginVersion;
363
376
  }
364
377
  }
365
378
  for (const depKey of Object.keys(pkgJson['dependencies'] || {})) {
366
379
  if (libs.includes(depKey)) {
367
- pkgJson['dependencies'][depKey] = coreVersion;
380
+ pkgJson['dependencies'][depKey] = coreNPMVersion;
368
381
  }
369
- else if (plugins.includes(depKey) &&
382
+ else if (allPlugins.includes(depKey) &&
370
383
  !(pkgJson['dependencies'][depKey].startsWith('file:') || pkgJson['dependencies'][depKey].startsWith('workspace:'))) {
371
- pkgJson['dependencies'][depKey] = pluginVersion;
384
+ pkgJson['dependencies'][depKey] = versionedPlugins[depKey] ? versionedPlugins[depKey] : pluginVersion;
372
385
  }
373
386
  }
374
387
  (0, fs_extra_1.writeFileSync)(pkgJsonPath, JSON.stringify(pkgJson, null, 2), {
@@ -6,15 +6,26 @@ const path_1 = require("path");
6
6
  const errors_1 = require("../errors");
7
7
  const fs_1 = require("./fs");
8
8
  const node_1 = require("./node");
9
- const SOURCE_PACKAGE_URL = 'https://github.com/ionic-team/capacitor';
10
- exports.SOURCE_PACKAGE_IDENTITY = 'capacitor';
11
- const SOURCE_PACKAGE_NAME = new RegExp(`name:\\s*"${exports.SOURCE_PACKAGE_IDENTITY}"`);
9
+ exports.SOURCE_PACKAGE_IDENTITY = 'capacitor-ios';
10
+ /** Matches the source package's git URL, with or without `.git`, but not repos sharing its prefix. */
11
+ const SOURCE_PACKAGE_URL = /url:\s*"https:\/\/github\.com\/ionic-team\/capacitor(?:\.git)?\/?"/i;
12
+ /**
13
+ * Names a path dependency on Capacitor may carry: the current identity, and the one syncs before
14
+ * the `capacitor-ios` rename pinned. A plugin rewritten by such a sync keeps the old name until
15
+ * it is synced again.
16
+ */
17
+ const PINNED_PACKAGE_NAMES = [exports.SOURCE_PACKAGE_IDENTITY, 'capacitor'];
12
18
  /** Product providing the Cordova compatibility layer. */
13
19
  exports.CORDOVA_PRODUCT = 'CapacitorCordova';
14
20
  /** The npm package the Swift package ships inside. */
15
21
  const PLATFORM_PACKAGE = '@capacitor/ios';
16
22
  /** Plugins published before Capacitor 9 depend on the platform as a prebuilt xcframework. */
17
23
  const BINARY_PACKAGE_IDENTITY = 'capacitor-swift-pm';
24
+ /**
25
+ * Cordova plugins that ship their own `Package.swift` depend on `apache/cordova-ios` for the
26
+ * `Cordova` product, which the Capacitor source package also vends.
27
+ */
28
+ const CORDOVA_PACKAGE_URL = /url:\s*"https:\/\/github\.com\/apache\/cordova-ios(?:\.git)?\/?"/i;
18
29
  /**
19
30
  * Resolves the Capacitor Swift package generated `Package.swift` files should depend on: the
20
31
  * `@capacitor/ios` npm already installed in the app, which ships the package alongside the sources.
@@ -83,10 +94,57 @@ exports.renderCapacitorPackage = renderCapacitorPackage;
83
94
  * copy of the framework. Rewriting keeps the whole graph on one identity.
84
95
  */
85
96
  function rewriteCapacitorDependency(content, absolutePath, fromDir) {
86
- const rewritten = replacePackageCalls(content, renderCapacitorPackage(absolutePath, fromDir));
87
- return rewritten.split(`package: "${BINARY_PACKAGE_IDENTITY}"`).join(`package: "${exports.SOURCE_PACKAGE_IDENTITY}"`);
97
+ const capacitorCalls = findPackageCalls(content).filter((call) => referencesCapacitor(call.text));
98
+ if (capacitorCalls.length === 0) {
99
+ return content;
100
+ }
101
+ // Collected before the calls are replaced: once they are, every one reads `capacitor-ios` and
102
+ // the name each target's `.product(package:)` was written against is gone. The pinned names are
103
+ // included because a sync that renamed only the `.package(...)` entry left products on the old
104
+ // name behind.
105
+ const previousNames = new Set([...capacitorCalls.flatMap((call) => packageReferenceNames(call.text)), ...PINNED_PACKAGE_NAMES].filter((name) => name !== exports.SOURCE_PACKAGE_IDENTITY));
106
+ let rewritten = replacePackageCalls(content, renderCapacitorPackage(absolutePath, fromDir));
107
+ // A name some other dependency still answers to belongs to that dependency, not Capacitor. SPM
108
+ // resolves `.product(package:)` against a dependency's pinned name and its derived identity alike,
109
+ // so both are reserved.
110
+ const remainingNames = new Set(findPackageCalls(rewritten)
111
+ .filter((call) => !referencesCapacitor(call.text))
112
+ .flatMap((call) => packageReferenceNames(call.text)));
113
+ for (const name of previousNames) {
114
+ if (remainingNames.has(name)) {
115
+ continue;
116
+ }
117
+ rewritten = rewritten.replace(new RegExp(`(package:\\s*)"${escapeRegExp(name)}"`, 'gi'), `$1"${exports.SOURCE_PACKAGE_IDENTITY}"`);
118
+ }
119
+ return rewritten;
88
120
  }
89
121
  exports.rewriteCapacitorDependency = rewriteCapacitorDependency;
122
+ /**
123
+ * The names a `.product(package:)` may use to refer to the dependency a `.package(...)` call
124
+ * declares, lowercased: its explicit `name:` when it pins one, and the identity SPM derives from
125
+ * the last component of its URL or path. SPM accepts either, so a pinned name does not retire the
126
+ * derived identity.
127
+ */
128
+ function packageReferenceNames(call) {
129
+ var _a;
130
+ const names = new Set();
131
+ const explicit = call.match(/name:\s*"([^"]+)"/);
132
+ if (explicit) {
133
+ names.add(explicit[1].toLowerCase());
134
+ }
135
+ const location = call.match(/(?:url|path):\s*"([^"]+)"/);
136
+ if (location) {
137
+ const lastComponent = (_a = location[1].replace(/\/+$/, '').split('/').pop()) !== null && _a !== void 0 ? _a : '';
138
+ const identity = lastComponent.replace(/\.git$/i, '').toLowerCase();
139
+ if (identity) {
140
+ names.add(identity);
141
+ }
142
+ }
143
+ return [...names];
144
+ }
145
+ function escapeRegExp(value) {
146
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
147
+ }
90
148
  /** Reads the version an existing `Package.swift` pins Capacitor to, if it pins one. */
91
149
  function findCapacitorDependencyVersion(content) {
92
150
  for (const call of findPackageCalls(content)) {
@@ -134,7 +192,11 @@ exports.patchPackageSwiftDeploymentTarget = patchPackageSwiftDeploymentTarget;
134
192
  * the app, or the package it points at, has moved.
135
193
  */
136
194
  function referencesCapacitor(call) {
137
- return call.includes(BINARY_PACKAGE_IDENTITY) || call.includes(SOURCE_PACKAGE_URL) || SOURCE_PACKAGE_NAME.test(call);
195
+ if (call.includes(BINARY_PACKAGE_IDENTITY) || SOURCE_PACKAGE_URL.test(call) || CORDOVA_PACKAGE_URL.test(call)) {
196
+ return true;
197
+ }
198
+ const pinned = call.match(/name:\s*"([^"]+)"/);
199
+ return pinned !== null && PINNED_PACKAGE_NAMES.includes(pinned[1].toLowerCase());
138
200
  }
139
201
  /**
140
202
  * Locates `.package(...)` calls in code, skipping any inside a comment or string literal.
@@ -4,7 +4,6 @@ exports.generateCordovaPackageFile = exports.generateCordovaPackageFiles = expor
4
4
  const fs_extra_1 = require("fs-extra");
5
5
  const path_1 = require("path");
6
6
  const cordova_1 = require("../cordova");
7
- const common_1 = require("../ios/common");
8
7
  const log_1 = require("../log");
9
8
  const plugin_1 = require("../plugin");
10
9
  const capacitor_package_1 = require("../util/capacitor-package");
@@ -440,7 +439,6 @@ ${entries.join(',\n')}
440
439
  async function generateCordovaPackageFile(p, config) {
441
440
  var _a;
442
441
  const capacitorPackagePath = await (0, capacitor_package_1.resolveCapacitorPackagePath)(config);
443
- const iosVersion = (0, common_1.getMajoriOSVersion)(config);
444
442
  const headerFiles = (0, plugin_1.getPlatformElement)(p, platform, 'header-file');
445
443
  let headersText = '';
446
444
  if (headerFiles.length > 0) {
@@ -451,9 +449,8 @@ async function generateCordovaPackageFile(p, config) {
451
449
  if ((_a = platformTag.$) === null || _a === void 0 ? void 0 : _a.package) {
452
450
  const packageSwiftPath = (0, path_1.join)(p.rootPath, 'Package.swift');
453
451
  let content = await (0, fs_extra_1.readFile)(packageSwiftPath, { encoding: 'utf-8' });
454
- content = content.replace(`apache`, `ionic-team`).replaceAll(`cordova-ios`, capacitor_package_1.SOURCE_PACKAGE_IDENTITY);
455
452
  content = (0, capacitor_package_1.rewriteCapacitorDependency)(content, capacitorPackagePath, p.rootPath);
456
- content = (0, capacitor_package_1.patchPackageSwiftDeploymentTarget)(content, iosVersion).content;
453
+ content = (0, capacitor_package_1.patchPackageSwiftDeploymentTarget)(content, config.ios.minVersion).content;
457
454
  await (0, fs_extra_1.writeFile)(packageSwiftPath, content);
458
455
  }
459
456
  else {
@@ -483,7 +480,7 @@ import PackageDescription
483
480
 
484
481
  let package = Package(
485
482
  name: "${p.name}",
486
- platforms: [.iOS(.v${iosVersion})],
483
+ platforms: [.iOS(.v${Math.trunc(parseFloat(config.ios.minVersion))})],
487
484
  products: [
488
485
  .library(
489
486
  name: "${p.name}",${libraryTypeText}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/cli",
3
- "version": "9.0.0-rc.0",
3
+ "version": "9.0.0",
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)",