@capacitor/cli 7.6.2 → 7.6.3

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
@@ -11,6 +11,7 @@ const errors_1 = require("../errors");
11
11
  const log_1 = require("../log");
12
12
  const plugin_1 = require("../plugin");
13
13
  const copy_1 = require("../tasks/copy");
14
+ const migrate_1 = require("../tasks/migrate");
14
15
  const fs_1 = require("../util/fs");
15
16
  const iosplugin_1 = require("../util/iosplugin");
16
17
  const node_1 = require("../util/node");
@@ -59,14 +60,159 @@ async function generateCordovaPackageFiles(cordovaPlugins, config) {
59
60
  });
60
61
  }
61
62
  async function generateCordovaPackageFile(p, config) {
63
+ var _a;
62
64
  const iosPlatformVersion = await (0, common_1.getCapacitorPackageVersion)(config, config.ios.name);
65
+ const platformTag = (0, plugin_1.getPluginPlatform)(p, platform);
66
+ if ((_a = platformTag.$) === null || _a === void 0 ? void 0 : _a.package) {
67
+ const packageSwiftPath = (0, path_1.join)(p.rootPath, 'Package.swift');
68
+ let content = await (0, fs_extra_1.readFile)(packageSwiftPath, { encoding: 'utf-8' });
69
+ content = content.replace(`apache`, `ionic-team`).replaceAll(`cordova-ios`, `capacitor-swift-pm`);
70
+ content = (0, migrate_1.setAllStringIn)(content, `url: "https://github.com/ionic-team/capacitor-swift-pm.git",`, `)`, ` from: "${iosPlatformVersion}"`);
71
+ await (0, fs_extra_1.writeFile)(packageSwiftPath, content);
72
+ }
73
+ else {
74
+ await writeGeneratedPackageSwift(p, config, iosPlatformVersion);
75
+ }
76
+ }
77
+ function buildBinaryTargetEntries(p, frameworks) {
78
+ const customXcframeworks = frameworks.filter((f) => f.$.custom === 'true' && f.$.src.endsWith('.xcframework'));
79
+ const customFrameworks = frameworks.filter((f) => f.$.custom === 'true' && f.$.src.endsWith('.framework'));
80
+ if (customFrameworks.length > 0) {
81
+ customFrameworks.forEach((f) => {
82
+ log_1.logger.warn(`${p.id}: custom .framework files are not supported as binaryTarget in SPM (${f.$.src}). Convert to .xcframework for SPM compatibility.`);
83
+ });
84
+ }
85
+ const binaryTargetsText = customXcframeworks
86
+ .map((f) => {
87
+ const name = f.$.src.split('/').pop().replace('.xcframework', '');
88
+ return `,
89
+ .binaryTarget(
90
+ name: "${name}",
91
+ path: "${f.$.src}"
92
+ )`;
93
+ })
94
+ .join('');
95
+ const binaryDepsText = customXcframeworks
96
+ .map((f) => {
97
+ const name = f.$.src.split('/').pop().replace('.xcframework', '');
98
+ return `,\n .target(name: "${name}")`;
99
+ })
100
+ .join('');
101
+ return { binaryTargetsText, binaryDepsText };
102
+ }
103
+ function buildResourcesText(resources) {
104
+ const resourceEntry = [];
105
+ for (const resource of resources) {
106
+ resourceEntry.push(`.copy("resources/${resource.$.src.split('/').pop()}")`);
107
+ }
108
+ return resources.length > 0
109
+ ? `,
110
+ resources: [
111
+ ${resourceEntry.join(',\n ')}
112
+ ]`
113
+ : '';
114
+ }
115
+ async function buildDependencyTexts(p, config) {
116
+ let allDependencies = (0, plugin_1.getPlatformElement)(p, platform, 'dependency');
117
+ if (p.xml['dependency']) {
118
+ allDependencies = allDependencies.concat(p.xml['dependency']);
119
+ }
120
+ let packageText = '';
121
+ let productText = '';
122
+ await Promise.all(allDependencies.map(async (dep) => {
123
+ let plugin = dep.$.id;
124
+ if (plugin.includes('@') && plugin.indexOf('@') !== 0) {
125
+ [plugin] = plugin.split('@');
126
+ }
127
+ const depPlugin = await (0, plugin_1.resolvePlugin)(config, plugin);
128
+ if (depPlugin) {
129
+ const headerFiles = (0, plugin_1.getPlatformElement)(depPlugin, platform, 'header-file');
130
+ const resources = (0, plugin_1.getPlatformElement)(depPlugin, platform, 'resource-file');
131
+ const sourceFiles = (0, plugin_1.getPlatformElement)(depPlugin, platform, 'source-file');
132
+ if (sourceFiles.length === 0 && headerFiles.length === 0 && resources.length === 0) {
133
+ return;
134
+ }
135
+ packageText += `,\n .package(name: "${depPlugin.name}", path: "../${depPlugin.name}")`;
136
+ productText += `,\n .product(name: "${depPlugin.name}", package: "${depPlugin.name}")`;
137
+ }
138
+ }));
139
+ return { packageText, productText };
140
+ }
141
+ function buildCSettingsText(p, sourceFiles) {
142
+ var _a;
143
+ const pluginId = p.id;
144
+ const allFlags = new Set();
145
+ for (const sourceFile of sourceFiles) {
146
+ const flags = (_a = sourceFile.$) === null || _a === void 0 ? void 0 : _a['compiler-flags'];
147
+ if (flags) {
148
+ flags
149
+ .split(/\s+/)
150
+ .map((f) => f.trim())
151
+ .filter((f) => f.length > 0)
152
+ .forEach((f) => allFlags.add(f));
153
+ }
154
+ }
155
+ if (allFlags.size === 0) {
156
+ return '';
157
+ }
158
+ const entries = [];
159
+ const unsupportedFlags = [];
160
+ for (const flag of allFlags) {
161
+ if (flag.startsWith('-D')) {
162
+ const definition = flag.slice(2);
163
+ const eqIndex = definition.indexOf('=');
164
+ if (eqIndex !== -1) {
165
+ const name = definition.slice(0, eqIndex);
166
+ const value = definition.slice(eqIndex + 1);
167
+ entries.push(` .define("${name}", to: "${value}")`);
168
+ }
169
+ else {
170
+ entries.push(` .define("${definition}")`);
171
+ }
172
+ }
173
+ else {
174
+ unsupportedFlags.push(flag);
175
+ }
176
+ }
177
+ if (unsupportedFlags.length > 0) {
178
+ log_1.logger.warn(`${pluginId}: the following compiler flags are not supported in SPM and were ignored: ${unsupportedFlags.join(', ')}. ` +
179
+ `This might cause the plugin to fail to compile.`);
180
+ }
181
+ if (entries.length === 0) {
182
+ return '';
183
+ }
184
+ return `,
185
+ cSettings: [
186
+ ${entries.join(',\n')}
187
+ ]`;
188
+ }
189
+ async function writeGeneratedPackageSwift(p, config, iosPlatformVersion) {
63
190
  const iosVersion = (0, common_2.getMajoriOSVersion)(config);
64
191
  const headerFiles = (0, plugin_1.getPlatformElement)(p, platform, 'header-file');
65
- let headersText = '';
66
- if (headerFiles.length > 0) {
67
- headersText = `,
68
- publicHeadersPath: "."`;
192
+ const headersText = headerFiles.length > 0
193
+ ? `,
194
+ publicHeadersPath: "."`
195
+ : '';
196
+ const resources = (0, plugin_1.getPlatformElement)(p, platform, 'resource-file');
197
+ const sourceFiles = (0, plugin_1.getPlatformElement)(p, platform, 'source-file');
198
+ if (sourceFiles.length === 0 && headerFiles.length === 0 && resources.length === 0) {
199
+ return;
69
200
  }
201
+ const frameworks = (0, plugin_1.getPlatformElement)(p, platform, 'framework');
202
+ const { binaryTargetsText, binaryDepsText } = buildBinaryTargetEntries(p, frameworks);
203
+ const cSettingsText = buildCSettingsText(p, sourceFiles);
204
+ const systemFrameworks = frameworks.filter((f) => !f.$.custom && f.$.src.endsWith('.framework'));
205
+ const hasWeakFrameworks = systemFrameworks.some((f) => f.$.weak === 'true');
206
+ const requiredSystemFrameworks = systemFrameworks.filter((f) => f.$.weak !== 'true');
207
+ const resourcesText = buildResourcesText(resources);
208
+ const libraryTypeText = hasWeakFrameworks ? `\n type: .dynamic,` : '';
209
+ const linkerSettingsText = requiredSystemFrameworks.length > 0
210
+ ? `,
211
+ linkerSettings: [
212
+ ${requiredSystemFrameworks.map((f) => ` .linkedFramework("${f.$.src.replace('.framework', '')}")`).join(',\n')}
213
+ ]`
214
+ : '';
215
+ const { packageText, productText } = await buildDependencyTexts(p, config);
70
216
  const content = `// swift-tools-version: 5.9
71
217
 
72
218
  import PackageDescription
@@ -76,21 +222,21 @@ let package = Package(
76
222
  platforms: [.iOS(.v${iosVersion})],
77
223
  products: [
78
224
  .library(
79
- name: "${p.name}",
225
+ name: "${p.name}",${libraryTypeText}
80
226
  targets: ["${p.name}"]
81
227
  )
82
228
  ],
83
229
  dependencies: [
84
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "${iosPlatformVersion}")
230
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "${iosPlatformVersion}")${packageText}
85
231
  ],
86
232
  targets: [
87
233
  .target(
88
234
  name: "${p.name}",
89
235
  dependencies: [
90
- .product(name: "Cordova", package: "capacitor-swift-pm")
236
+ .product(name: "Cordova", package: "capacitor-swift-pm")${binaryDepsText}${productText}
91
237
  ],
92
- path: "."${headersText}
93
- )
238
+ path: "."${resourcesText}${headersText}${cSettingsText}${linkerSettingsText}
239
+ )${binaryTargetsText}
94
240
  ]
95
241
  )`;
96
242
  await (0, fs_extra_1.writeFile)((0, path_1.join)(config.ios.cordovaPluginsDirAbs, 'sources', p.name, 'Package.swift'), content);
@@ -354,13 +500,19 @@ function getLinkerFlags(config) {
354
500
  return '';
355
501
  }
356
502
  async function copyPluginsNativeFiles(config, cordovaPlugins) {
503
+ var _a;
504
+ const isSPM = (await config.ios.packageManager) === 'SPM';
357
505
  for (const p of cordovaPlugins) {
506
+ const platformTag = (0, plugin_1.getPluginPlatform)(p, platform);
507
+ if ((_a = platformTag.$) === null || _a === void 0 ? void 0 : _a.package) {
508
+ continue;
509
+ }
358
510
  const sourceFiles = (0, plugin_1.getPlatformElement)(p, platform, 'source-file');
359
511
  const headerFiles = (0, plugin_1.getPlatformElement)(p, platform, 'header-file');
360
512
  const codeFiles = sourceFiles.concat(headerFiles);
361
513
  const frameworks = (0, plugin_1.getPlatformElement)(p, platform, 'framework');
362
514
  let sourcesFolderName = 'sources';
363
- if ((0, cordova_1.needsStaticPod)(p)) {
515
+ if (!isSPM && (0, cordova_1.needsStaticPod)(p)) {
364
516
  sourcesFolderName += 'static';
365
517
  }
366
518
  const sourcesFolder = (0, path_1.join)(config.ios.cordovaPluginsDirAbs, sourcesFolderName, p.name);
@@ -371,7 +523,7 @@ async function copyPluginsNativeFiles(config, cordovaPlugins) {
371
523
  fileName = 'lib' + fileName;
372
524
  }
373
525
  let destFolder = sourcesFolderName;
374
- if (codeFile.$['compiler-flags'] && codeFile.$['compiler-flags'] === '-fno-objc-arc') {
526
+ if (!isSPM && codeFile.$['compiler-flags'] && codeFile.$['compiler-flags'] === '-fno-objc-arc') {
375
527
  destFolder = 'noarc';
376
528
  }
377
529
  const filePath = (0, plugin_1.getFilePath)(config, p, codeFile.$.src);
@@ -390,8 +542,13 @@ async function copyPluginsNativeFiles(config, cordovaPlugins) {
390
542
  }
391
543
  if (fileContent.includes('[NSBundle bundleForClass:[self class]]') ||
392
544
  fileContent.includes('[NSBundle bundleForClass:[CDVCapture class]]')) {
393
- fileContent = fileContent.replace('[NSBundle bundleForClass:[self class]]', '[NSBundle mainBundle]');
394
- fileContent = fileContent.replace('[NSBundle bundleForClass:[CDVCapture class]]', '[NSBundle mainBundle]');
545
+ const bundleName = isSPM ? 'SWIFTPM_MODULE_BUNDLE' : '[NSBundle mainBundle]';
546
+ fileContent = fileContent.replace('[NSBundle bundleForClass:[self class]]', bundleName);
547
+ fileContent = fileContent.replace('[NSBundle bundleForClass:[CDVCapture class]]', bundleName);
548
+ await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
549
+ }
550
+ if (isSPM && fileContent.includes('[NSBundle mainBundle] URLForResource')) {
551
+ fileContent = fileContent.replace('[NSBundle mainBundle] URLForResource', 'SWIFTPM_MODULE_BUNDLE URLForResource');
395
552
  await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
396
553
  }
397
554
  if (fileContent.includes('[self.webView superview]') || fileContent.includes('self.webView.superview')) {
@@ -405,7 +562,8 @@ async function copyPluginsNativeFiles(config, cordovaPlugins) {
405
562
  const resourceFiles = (0, plugin_1.getPlatformElement)(p, platform, 'resource-file');
406
563
  for (const resourceFile of resourceFiles) {
407
564
  const fileName = resourceFile.$.src.split('/').pop();
408
- await (0, fs_extra_1.copy)((0, plugin_1.getFilePath)(config, p, resourceFile.$.src), (0, path_1.join)(config.ios.cordovaPluginsDirAbs, 'resources', fileName));
565
+ const rootResFolder = isSPM ? sourcesFolder : config.ios.cordovaPluginsDirAbs;
566
+ await (0, fs_extra_1.copy)((0, plugin_1.getFilePath)(config, p, resourceFile.$.src), (0, path_1.join)(rootResFolder, 'resources', fileName));
409
567
  }
410
568
  for (const framework of frameworks) {
411
569
  if (framework.$.custom && framework.$.custom === 'true') {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.patchOldCapacitorPlugins = exports.migrateCommand = void 0;
3
+ exports.patchOldCapacitorPlugins = 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");
@@ -507,6 +507,7 @@ function setAllStringIn(data, start, end, replacement) {
507
507
  }
508
508
  return result;
509
509
  }
510
+ exports.setAllStringIn = setAllStringIn;
510
511
  async function updateAndroidManifest(filename) {
511
512
  const txt = readFile(filename);
512
513
  if (!txt) {
package/dist/util/spm.js CHANGED
@@ -45,12 +45,12 @@ exports.generatePackageFile = generatePackageFile;
45
45
  async function checkPluginsForPackageSwift(config, plugins) {
46
46
  const iOSCapacitorPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, 'ios') === 0 /* PluginType.Core */);
47
47
  const packageSwiftPluginList = await pluginsWithPackageSwift(iOSCapacitorPlugins);
48
- if (plugins.length == packageSwiftPluginList.length) {
49
- log_1.logger.debug(`Found ${plugins.length} iOS plugins, ${packageSwiftPluginList.length} have a Package.swift file`);
50
- log_1.logger.info('All plugins have a Package.swift file and will be included in Package.swift');
48
+ if (iOSCapacitorPlugins.length == packageSwiftPluginList.length) {
49
+ log_1.logger.debug(`Found ${iOSCapacitorPlugins.length} Capacitor iOS plugins, ${packageSwiftPluginList.length} have a Package.swift file`);
50
+ log_1.logger.info('All Capacitor plugins have a Package.swift file and will be included in Package.swift');
51
51
  }
52
52
  else {
53
- log_1.logger.warn('Some installed packages are not compatable with SPM');
53
+ log_1.logger.warn('Some installed Capacitor plugins are not compatible with SPM');
54
54
  }
55
55
  return packageSwiftPluginList;
56
56
  }
@@ -84,7 +84,7 @@ async function removeCocoapodsFiles(config) {
84
84
  }
85
85
  exports.removeCocoapodsFiles = removeCocoapodsFiles;
86
86
  async function generatePackageText(config, plugins) {
87
- var _a, _b, _c;
87
+ var _a, _b, _c, _d, _e;
88
88
  const iosPlatformVersion = await (0, common_1.getCapacitorPackageVersion)(config, config.ios.name);
89
89
  const iosVersion = (0, common_2.getMajoriOSVersion)(config);
90
90
  let packageSwiftText = `// swift-tools-version: 5.9
@@ -103,11 +103,23 @@ let package = Package(
103
103
  .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", exact: "${iosPlatformVersion}")`;
104
104
  for (const plugin of plugins) {
105
105
  if ((0, plugin_1.getPluginType)(plugin, config.ios.name) === 1 /* PluginType.Cordova */) {
106
- packageSwiftText += `,\n .package(name: "${plugin.name}", path: "../../capacitor-cordova-ios-plugins/sources/${plugin.name}")`;
106
+ const platformTag = (0, plugin_1.getPluginPlatform)(plugin, config.ios.name);
107
+ if ((_a = platformTag.$) === null || _a === void 0 ? void 0 : _a.package) {
108
+ const relPath = (0, path_1.relative)(config.ios.nativeXcodeProjDirAbs, plugin.rootPath);
109
+ packageSwiftText += `,\n .package(name: "${plugin.id}", path: "${relPath}")`;
110
+ }
111
+ else {
112
+ const sourceFiles = (0, plugin_1.getPlatformElement)(plugin, config.ios.name, 'source-file');
113
+ const headerFiles = (0, plugin_1.getPlatformElement)(plugin, config.ios.name, 'header-file');
114
+ if (sourceFiles.length === 0 && headerFiles.length === 0) {
115
+ continue;
116
+ }
117
+ packageSwiftText += `,\n .package(name: "${plugin.name}", path: "../../capacitor-cordova-ios-plugins/sources/${plugin.name}")`;
118
+ }
107
119
  }
108
120
  else {
109
121
  const relPath = (0, path_1.relative)(config.ios.nativeXcodeProjDirAbs, plugin.rootPath);
110
- packageSwiftText += `,\n .package(name: "${(_a = plugin.ios) === null || _a === void 0 ? void 0 : _a.name}", path: "${relPath}")`;
122
+ packageSwiftText += `,\n .package(name: "${(_b = plugin.ios) === null || _b === void 0 ? void 0 : _b.name}", path: "${relPath}")`;
111
123
  }
112
124
  }
113
125
  packageSwiftText += `
@@ -119,7 +131,21 @@ let package = Package(
119
131
  .product(name: "Capacitor", package: "capacitor-swift-pm"),
120
132
  .product(name: "Cordova", package: "capacitor-swift-pm")`;
121
133
  for (const plugin of plugins) {
122
- packageSwiftText += `,\n .product(name: "${(_b = plugin.ios) === null || _b === void 0 ? void 0 : _b.name}", package: "${(_c = plugin.ios) === null || _c === void 0 ? void 0 : _c.name}")`;
134
+ let pluginText = `,\n .product(name: "${(_c = plugin.ios) === null || _c === void 0 ? void 0 : _c.name}", package: "${(_d = plugin.ios) === null || _d === void 0 ? void 0 : _d.name}")`;
135
+ if ((0, plugin_1.getPluginType)(plugin, config.ios.name) === 1 /* PluginType.Cordova */) {
136
+ const platformTag = (0, plugin_1.getPluginPlatform)(plugin, config.ios.name);
137
+ if ((_e = platformTag.$) === null || _e === void 0 ? void 0 : _e.package) {
138
+ pluginText = `,\n .product(name: "${plugin.id}", package: "${plugin.id}")`;
139
+ }
140
+ else {
141
+ const sourceFiles = (0, plugin_1.getPlatformElement)(plugin, config.ios.name, 'source-file');
142
+ const headerFiles = (0, plugin_1.getPlatformElement)(plugin, config.ios.name, 'header-file');
143
+ if (sourceFiles.length === 0 && headerFiles.length === 0) {
144
+ pluginText = '';
145
+ }
146
+ }
147
+ }
148
+ packageSwiftText += pluginText;
123
149
  }
124
150
  packageSwiftText += `
125
151
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/cli",
3
- "version": "7.6.2",
3
+ "version": "7.6.3",
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)",