update electron to v43

This commit is contained in:
olcxja 2026-07-09 22:38:33 +02:00
commit fb6c8b6ee9
5385 changed files with 513060 additions and 123058 deletions

View file

@ -4,6 +4,7 @@ exports.installCocoaPodsPlugins = exports.updateIOS = void 0;
const tslib_1 = require("tslib");
const fs_extra_1 = require("fs-extra");
const path_1 = require("path");
const semver_1 = require("semver");
const colors_1 = tslib_1.__importDefault(require("../colors"));
const common_1 = require("../common");
const cordova_1 = require("../cordova");
@ -11,6 +12,7 @@ const errors_1 = require("../errors");
const log_1 = require("../log");
const plugin_1 = require("../plugin");
const copy_1 = require("../tasks/copy");
const migrate_1 = require("../tasks/migrate");
const fs_1 = require("../util/fs");
const iosplugin_1 = require("../util/iosplugin");
const node_1 = require("../util/node");
@ -43,6 +45,22 @@ async function updatePluginFiles(config, plugins, deployment) {
if ((await config.ios.packageManager) === 'SPM') {
await generateCordovaPackageFiles(cordovaPlugins, config);
const validSPMPackages = await (0, spm_1.checkPluginsForPackageSwift)(config, plugins);
await Promise.all(validSPMPackages.map(async (plugin) => {
var _a;
const iosPlatformVersion = await (0, common_1.getCapacitorPackageVersion)(config, config.ios.name);
const packageSwiftPath = (0, path_1.join)(plugin.rootPath, 'Package.swift');
let content = await (0, fs_extra_1.readFile)(packageSwiftPath, { encoding: 'utf-8' });
const regex = new RegExp('url:\\s*"https://github.com/ionic-team/capacitor-swift-pm\\.git",\\s*from:\\s*"([^"]+)"');
const version = (_a = content.match(regex)) === null || _a === void 0 ? void 0 : _a[1];
const majorCapVersion = (0, semver_1.major)(iosPlatformVersion);
if (version && (0, semver_1.major)(version) != majorCapVersion) {
const preCapVersion = (0, semver_1.prerelease)(iosPlatformVersion);
const forceVersion = preCapVersion ? iosPlatformVersion : `${majorCapVersion}.0.0`;
content = (0, migrate_1.setAllStringIn)(content, `url: "https://github.com/ionic-team/capacitor-swift-pm.git",`, `)`, ` from: "${forceVersion}"`);
await (0, fs_extra_1.writeFile)(packageSwiftPath, content);
log_1.logger.warn(`${plugin.id} is built for Capacitor ${(0, semver_1.major)(version)}, it might cause issues`);
}
}));
await (0, spm_1.generatePackageFile)(config, validSPMPackages.concat(cordovaPlugins));
}
else {
@ -59,14 +77,159 @@ async function generateCordovaPackageFiles(cordovaPlugins, config) {
});
}
async function generateCordovaPackageFile(p, config) {
var _a;
const iosPlatformVersion = await (0, common_1.getCapacitorPackageVersion)(config, config.ios.name);
const platformTag = (0, plugin_1.getPluginPlatform)(p, platform);
if ((_a = platformTag.$) === null || _a === void 0 ? void 0 : _a.package) {
const packageSwiftPath = (0, path_1.join)(p.rootPath, 'Package.swift');
let content = await (0, fs_extra_1.readFile)(packageSwiftPath, { encoding: 'utf-8' });
content = content.replace(`apache`, `ionic-team`).replaceAll(`cordova-ios`, `capacitor-swift-pm`);
content = (0, migrate_1.setAllStringIn)(content, `url: "https://github.com/ionic-team/capacitor-swift-pm.git",`, `)`, ` from: "${iosPlatformVersion}"`);
await (0, fs_extra_1.writeFile)(packageSwiftPath, content);
}
else {
await writeGeneratedPackageSwift(p, config, iosPlatformVersion);
}
}
function buildBinaryTargetEntries(p, frameworks) {
const customXcframeworks = frameworks.filter((f) => f.$.custom === 'true' && f.$.src.endsWith('.xcframework'));
const customFrameworks = frameworks.filter((f) => f.$.custom === 'true' && f.$.src.endsWith('.framework'));
if (customFrameworks.length > 0) {
customFrameworks.forEach((f) => {
log_1.logger.warn(`${p.id}: custom .framework files are not supported as binaryTarget in SPM (${f.$.src}). Convert to .xcframework for SPM compatibility.`);
});
}
const binaryTargetsText = customXcframeworks
.map((f) => {
const name = f.$.src.split('/').pop().replace('.xcframework', '');
return `,
.binaryTarget(
name: "${name}",
path: "${f.$.src}"
)`;
})
.join('');
const binaryDepsText = customXcframeworks
.map((f) => {
const name = f.$.src.split('/').pop().replace('.xcframework', '');
return `,\n .target(name: "${name}")`;
})
.join('');
return { binaryTargetsText, binaryDepsText };
}
function buildResourcesText(resources) {
const resourceEntry = [];
for (const resource of resources) {
resourceEntry.push(`.copy("resources/${resource.$.src.split('/').pop()}")`);
}
return resources.length > 0
? `,
resources: [
${resourceEntry.join(',\n ')}
]`
: '';
}
async function buildDependencyTexts(p, config) {
let allDependencies = (0, plugin_1.getPlatformElement)(p, platform, 'dependency');
if (p.xml['dependency']) {
allDependencies = allDependencies.concat(p.xml['dependency']);
}
let packageText = '';
let productText = '';
await Promise.all(allDependencies.map(async (dep) => {
let plugin = dep.$.id;
if (plugin.includes('@') && plugin.indexOf('@') !== 0) {
[plugin] = plugin.split('@');
}
const depPlugin = await (0, plugin_1.resolvePlugin)(config, plugin);
if (depPlugin) {
const headerFiles = (0, plugin_1.getPlatformElement)(depPlugin, platform, 'header-file');
const resources = (0, plugin_1.getPlatformElement)(depPlugin, platform, 'resource-file');
const sourceFiles = (0, plugin_1.getPlatformElement)(depPlugin, platform, 'source-file');
if (sourceFiles.length === 0 && headerFiles.length === 0 && resources.length === 0) {
return;
}
packageText += `,\n .package(name: "${depPlugin.name}", path: "../${depPlugin.name}")`;
productText += `,\n .product(name: "${depPlugin.name}", package: "${depPlugin.name}")`;
}
}));
return { packageText, productText };
}
function buildCSettingsText(p, sourceFiles) {
var _a;
const pluginId = p.id;
const allFlags = new Set();
for (const sourceFile of sourceFiles) {
const flags = (_a = sourceFile.$) === null || _a === void 0 ? void 0 : _a['compiler-flags'];
if (flags) {
flags
.split(/\s+/)
.map((f) => f.trim())
.filter((f) => f.length > 0)
.forEach((f) => allFlags.add(f));
}
}
if (allFlags.size === 0) {
return '';
}
const entries = [];
const unsupportedFlags = [];
for (const flag of allFlags) {
if (flag.startsWith('-D')) {
const definition = flag.slice(2);
const eqIndex = definition.indexOf('=');
if (eqIndex !== -1) {
const name = definition.slice(0, eqIndex);
const value = definition.slice(eqIndex + 1);
entries.push(` .define("${name}", to: "${value}")`);
}
else {
entries.push(` .define("${definition}")`);
}
}
else {
unsupportedFlags.push(flag);
}
}
if (unsupportedFlags.length > 0) {
log_1.logger.warn(`${pluginId}: the following compiler flags are not supported in SPM and were ignored: ${unsupportedFlags.join(', ')}. ` +
`This might cause the plugin to fail to compile.`);
}
if (entries.length === 0) {
return '';
}
return `,
cSettings: [
${entries.join(',\n')}
]`;
}
async function writeGeneratedPackageSwift(p, config, iosPlatformVersion) {
const iosVersion = (0, common_2.getMajoriOSVersion)(config);
const headerFiles = (0, plugin_1.getPlatformElement)(p, platform, 'header-file');
let headersText = '';
if (headerFiles.length > 0) {
headersText = `,
publicHeadersPath: "."`;
const headersText = headerFiles.length > 0
? `,
publicHeadersPath: "."`
: '';
const resources = (0, plugin_1.getPlatformElement)(p, platform, 'resource-file');
const sourceFiles = (0, plugin_1.getPlatformElement)(p, platform, 'source-file');
if (sourceFiles.length === 0 && headerFiles.length === 0 && resources.length === 0) {
return;
}
const frameworks = (0, plugin_1.getPlatformElement)(p, platform, 'framework');
const { binaryTargetsText, binaryDepsText } = buildBinaryTargetEntries(p, frameworks);
const cSettingsText = buildCSettingsText(p, sourceFiles);
const systemFrameworks = frameworks.filter((f) => !f.$.custom && f.$.src.endsWith('.framework'));
const hasWeakFrameworks = systemFrameworks.some((f) => f.$.weak === 'true');
const requiredSystemFrameworks = systemFrameworks.filter((f) => f.$.weak !== 'true');
const resourcesText = buildResourcesText(resources);
const libraryTypeText = hasWeakFrameworks ? `\n type: .dynamic,` : '';
const linkerSettingsText = requiredSystemFrameworks.length > 0
? `,
linkerSettings: [
${requiredSystemFrameworks.map((f) => ` .linkedFramework("${f.$.src.replace('.framework', '')}")`).join(',\n')}
]`
: '';
const { packageText, productText } = await buildDependencyTexts(p, config);
const content = `// swift-tools-version: 5.9
import PackageDescription
@ -76,21 +239,21 @@ let package = Package(
platforms: [.iOS(.v${iosVersion})],
products: [
.library(
name: "${p.name}",
name: "${p.name}",${libraryTypeText}
targets: ["${p.name}"]
)
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "${iosPlatformVersion}")
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "${iosPlatformVersion}")${packageText}
],
targets: [
.target(
name: "${p.name}",
dependencies: [
.product(name: "Cordova", package: "capacitor-swift-pm")
.product(name: "Cordova", package: "capacitor-swift-pm")${binaryDepsText}${productText}
],
path: "."${headersText}
)
path: "."${resourcesText}${headersText}${cSettingsText}${linkerSettingsText}
)${binaryTargetsText}
]
)`;
await (0, fs_extra_1.writeFile)((0, path_1.join)(config.ios.cordovaPluginsDirAbs, 'sources', p.name, 'Package.swift'), content);
@ -354,13 +517,19 @@ function getLinkerFlags(config) {
return '';
}
async function copyPluginsNativeFiles(config, cordovaPlugins) {
var _a;
const isSPM = (await config.ios.packageManager) === 'SPM';
for (const p of cordovaPlugins) {
const platformTag = (0, plugin_1.getPluginPlatform)(p, platform);
if (isSPM && ((_a = platformTag.$) === null || _a === void 0 ? void 0 : _a.package)) {
continue;
}
const sourceFiles = (0, plugin_1.getPlatformElement)(p, platform, 'source-file');
const headerFiles = (0, plugin_1.getPlatformElement)(p, platform, 'header-file');
const codeFiles = sourceFiles.concat(headerFiles);
const frameworks = (0, plugin_1.getPlatformElement)(p, platform, 'framework');
let sourcesFolderName = 'sources';
if ((0, cordova_1.needsStaticPod)(p)) {
if (!isSPM && (0, cordova_1.needsStaticPod)(p)) {
sourcesFolderName += 'static';
}
const sourcesFolder = (0, path_1.join)(config.ios.cordovaPluginsDirAbs, sourcesFolderName, p.name);
@ -371,7 +540,7 @@ async function copyPluginsNativeFiles(config, cordovaPlugins) {
fileName = 'lib' + fileName;
}
let destFolder = sourcesFolderName;
if (codeFile.$['compiler-flags'] && codeFile.$['compiler-flags'] === '-fno-objc-arc') {
if (!isSPM && codeFile.$['compiler-flags'] && codeFile.$['compiler-flags'] === '-fno-objc-arc') {
destFolder = 'noarc';
}
const filePath = (0, plugin_1.getFilePath)(config, p, codeFile.$.src);
@ -390,8 +559,13 @@ async function copyPluginsNativeFiles(config, cordovaPlugins) {
}
if (fileContent.includes('[NSBundle bundleForClass:[self class]]') ||
fileContent.includes('[NSBundle bundleForClass:[CDVCapture class]]')) {
fileContent = fileContent.replace('[NSBundle bundleForClass:[self class]]', '[NSBundle mainBundle]');
fileContent = fileContent.replace('[NSBundle bundleForClass:[CDVCapture class]]', '[NSBundle mainBundle]');
const bundleName = isSPM ? 'SWIFTPM_MODULE_BUNDLE' : '[NSBundle mainBundle]';
fileContent = fileContent.replace('[NSBundle bundleForClass:[self class]]', bundleName);
fileContent = fileContent.replace('[NSBundle bundleForClass:[CDVCapture class]]', bundleName);
await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
}
if (isSPM && fileContent.includes('[NSBundle mainBundle] URLForResource')) {
fileContent = fileContent.replace('[NSBundle mainBundle] URLForResource', 'SWIFTPM_MODULE_BUNDLE URLForResource');
await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
}
if (fileContent.includes('[self.webView superview]') || fileContent.includes('self.webView.superview')) {
@ -405,7 +579,8 @@ async function copyPluginsNativeFiles(config, cordovaPlugins) {
const resourceFiles = (0, plugin_1.getPlatformElement)(p, platform, 'resource-file');
for (const resourceFile of resourceFiles) {
const fileName = resourceFile.$.src.split('/').pop();
await (0, fs_extra_1.copy)((0, plugin_1.getFilePath)(config, p, resourceFile.$.src), (0, path_1.join)(config.ios.cordovaPluginsDirAbs, 'resources', fileName));
const rootResFolder = isSPM ? sourcesFolder : config.ios.cordovaPluginsDirAbs;
await (0, fs_extra_1.copy)((0, plugin_1.getFilePath)(config, p, resourceFile.$.src), (0, path_1.join)(rootResFolder, 'resources', fileName));
}
for (const framework of frameworks) {
if (framework.$.custom && framework.$.custom === 'true') {
@ -416,6 +591,9 @@ async function copyPluginsNativeFiles(config, cordovaPlugins) {
}
async function removePluginsNativeFiles(config) {
await (0, fs_extra_1.remove)(config.ios.cordovaPluginsDirAbs);
if ((await config.ios.packageManager) === 'SPM') {
await (0, fs_extra_1.remove)((0, path_1.join)(config.ios.nativeProjectDirAbs, 'CapApp-SPM', 'symlinks'));
}
await (0, template_1.extractTemplate)(config.cli.assets.ios.cordovaPluginsTemplateArchiveAbs, config.ios.cordovaPluginsDirAbs);
}
function filterResources(plugin) {