erisu commented on code in PR #1515: URL: https://github.com/apache/cordova-ios/pull/1515#discussion_r2078773311
########## lib/SwiftPackage.js: ########## @@ -0,0 +1,110 @@ +/** + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ + +const fs = require('node:fs'); +const path = require('node:path'); +const CordovaError = require('cordova-common').CordovaError; + +const ROOT = path.join(__dirname, '..'); + +class SwiftPackage { + constructor (projectRoot) { + this.root = projectRoot; + this.path = path.join(this.root, 'packages', 'cordova-ios-plugins', 'Package.swift'); + + if (!fs.existsSync(this.path)) { + throw new CordovaError('Package.swift is not found.'); + } + } + + _pluginReference (plugin, pluginPath) { + return ` +package.dependencies.append(.package(name: "${plugin.id}", path: "${pluginPath.replaceAll(path.sep, path.posix.sep)}")) +package.targets.first?.dependencies.append(.product(name: "${plugin.id}", package: "${plugin.id}")) +`; + } + + addPlugin (plugin, opts = {}) { + let pluginPath = path.relative(path.dirname(this.path), path.join(this.root, 'packages', plugin.id)); + if (opts.link) { + pluginPath = path.relative(path.dirname(this.path), plugin.dir); + } else { + // Copy the plugin into the packages directory + const localPluginPath = path.join(this.root, 'packages', plugin.id); + fs.cpSync(plugin.dir, localPluginPath, { recursive: true }); + + const pkgSwiftPath = path.join(localPluginPath, 'Package.swift'); + + let cordovaPath = path.relative(localPluginPath, path.join(this.root, 'packages', 'cordova-ios')); + if (!fs.existsSync(path.join(localPluginPath, cordovaPath))) { + cordovaPath = path.relative(localPluginPath, ROOT); + } + + const pkg_fd = fs.openSync(pkgSwiftPath, 'r+'); + let packageContent = fs.readFileSync(pkg_fd, 'utf8'); + packageContent = packageContent.replace(/package\(.+cordova-ios.+\)/gm, `package(name: "cordova-ios", path: "${cordovaPath.replaceAll(path.sep, path.posix.sep)}")`); Review Comment: ```suggestion // Note: May match unintended packages, e.g. 'cordova-ios-plugin', due to flexible patterns. Strict filtering would risk valid exclusions. packageContent = packageContent.replace(/package\(.+cordova-ios.+\)/gm, `package(name: "cordova-ios", path: "${cordovaPath.replaceAll(path.sep, path.posix.sep)}")`); ``` Should we add a comment about the pattern detection and why it can not be strict? ########## lib/prepare.js: ########## @@ -154,7 +154,6 @@ function updateConfigFile (sourceConfig, configMunger, locations) { const config = new ConfigParser(locations.configXml); xmlHelpers.mergeXml(sourceConfig.doc.getroot(), config.doc.getroot(), 'ios', /* clobber= */true); - Review Comment: This line deletion could be reverted so there is no file changes. ########## lib/SwiftPackage.js: ########## @@ -0,0 +1,110 @@ +/** + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ + +const fs = require('node:fs'); +const path = require('node:path'); +const CordovaError = require('cordova-common').CordovaError; Review Comment: ```suggestion const { CordovaError } = require('cordova-common'); ``` Preference? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org