This is an automated email from the ASF dual-hosted git repository.

dpogue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-ios.git


The following commit(s) were added to refs/heads/master by this push:
     new 0c7cfe71 refactor: replace util.format w/ template literals (#1553)
0c7cfe71 is described below

commit 0c7cfe71b144d6eb5116a43e6c728fb37743b563
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Wed Aug 6 02:12:39 2025 +0900

    refactor: replace util.format w/ template literals (#1553)
---
 lib/Api.js                       |  7 +++--
 lib/Podfile.js                   | 56 +++++++++++++++++++---------------------
 lib/PodsJson.js                  | 11 ++++----
 lib/build.js                     |  7 +++--
 lib/plugman/pluginHandlers.js    |  9 +++----
 lib/projectFile.js               |  3 +--
 tests/spec/unit/Podfile.spec.js  | 12 ++++-----
 tests/spec/unit/PodsJson.spec.js |  3 +--
 8 files changed, 48 insertions(+), 60 deletions(-)

diff --git a/lib/Api.js b/lib/Api.js
index 897f1683..fb178c00 100644
--- a/lib/Api.js
+++ b/lib/Api.js
@@ -23,7 +23,6 @@ const VERSION = require('../package.json').version;
 
 const fs = require('node:fs');
 const path = require('node:path');
-const util = require('node:util');
 const projectFile = require('./projectFile');
 const check_reqs = require('./check_reqs');
 const {
@@ -461,7 +460,7 @@ class Api {
                         if (val) {
                             podsjsonFile.decrementDeclaration(declaration);
                         } else {
-                            const message = util.format('plugin \"%s\" 
declaration \"%s\" does not seem to be in pods.json, nothing to remove. Will 
attempt to remove from Podfile.', plugin.id, podJson.declaration);
+                            const message = `plugin "${plugin.id}" declaration 
"${podJson.declaration}" does not seem to be in pods.json, nothing to remove. 
Will attempt to remove from Podfile.`;
                             events.emit('verbose', message);
                         }
                         if (!val || val.count === 0) {
@@ -478,7 +477,7 @@ class Api {
                     if (val) {
                         podsjsonFile.decrementSource(key);
                     } else {
-                        const message = util.format('plugin \"%s\" source 
\"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to 
remove from Podfile.', plugin.id, podJson.source);
+                        const message = `plugin "${plugin.id}" source 
"${podJson.source}" does not seem to be in pods.json, nothing to remove. Will 
attempt to remove from Podfile.`;
                         events.emit('verbose', message);
                     }
                     if (!val || val.count === 0) {
@@ -495,7 +494,7 @@ class Api {
                         if (val) {
                             podsjsonFile.decrementLibrary(key);
                         } else {
-                            const message = util.format('plugin \"%s\" podspec 
\"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to 
remove from Podfile.', plugin.id, podJson.name);
+                            const message = `plugin "${plugin.id}" podspec 
"${podJson.name}" does not seem to be in pods.json, nothing to remove. Will 
attempt to remove from Podfile.`;
                             events.emit('verbose', message);
                         }
                         if (!val || val.count === 0) {
diff --git a/lib/Podfile.js b/lib/Podfile.js
index 9fcb84b1..55b88eda 100644
--- a/lib/Podfile.js
+++ b/lib/Podfile.js
@@ -20,7 +20,6 @@
 
 const fs = require('node:fs');
 const path = require('node:path');
-const util = require('node:util');
 const execa = require('execa');
 const { CordovaError, events } = require('cordova-common');
 
@@ -47,11 +46,11 @@ function Podfile (podFilePath, projectName, 
minDeploymentTarget) {
     // check whether it is named Podfile
     const filename = this.path.split(path.sep).pop();
     if (filename !== Podfile.FILENAME) {
-        throw new CordovaError(util.format('Podfile: The file at %s is not 
`%s`.', this.path, Podfile.FILENAME));
+        throw new CordovaError(`Podfile: The file at ${this.path} is not 
\`${Podfile.FILENAME}\`.`);
     }
 
     if (!fs.existsSync(this.path)) {
-        events.emit('verbose', util.format('Podfile: The file at %s does not 
exist.', this.path));
+        events.emit('verbose', `Podfile: The file at ${this.path} does not 
exist.`);
         events.emit('verbose', 'Creating new Podfile in platforms/ios');
         this.clear();
         this.write();
@@ -164,16 +163,14 @@ Podfile.prototype.escapeSingleQuotes = function (string) {
 };
 
 Podfile.prototype.getTemplate = function () {
-    return util.format(
-        '# DO NOT MODIFY -- auto-generated by Apache Cordova\n' +
-            '%s\n' +
-            'platform :ios, \'%s\'\n' +
-            '%s\n' +
-            'target \'App\' do\n' +
-            '\tproject \'App.xcodeproj\'\n' +
-            '%s\n' +
-            'end\n',
-        this.sourceToken, this.minDeploymentTarget, this.declarationToken, 
this.podToken);
+    return '# DO NOT MODIFY -- auto-generated by Apache Cordova\n' +
+        `${this.sourceToken}\n` +
+        `platform :ios, '${this.minDeploymentTarget}'\n` +
+        `${this.declarationToken}\n` +
+        'target \'App\' do\n' +
+        '\tproject \'App.xcodeproj\'\n' +
+        `${this.podToken}\n` +
+        'end\n';
 };
 
 Podfile.prototype.addSpec = function (name, spec) {
@@ -194,7 +191,7 @@ Podfile.prototype.addSpec = function (name, spec) {
     this.pods[name] = spec;
     this.__dirty = true;
 
-    events.emit('verbose', util.format('Added pod line for `%s`', name));
+    events.emit('verbose', `Added pod line for \`${name}\``);
 };
 
 Podfile.prototype.removeSpec = function (name) {
@@ -203,7 +200,7 @@ Podfile.prototype.removeSpec = function (name) {
         this.__dirty = true;
     }
 
-    events.emit('verbose', util.format('Removed pod line for `%s`', name));
+    events.emit('verbose', `Removed pod line for \`${name}\``);
 };
 
 Podfile.prototype.getSpec = function (name) {
@@ -218,7 +215,7 @@ Podfile.prototype.addSource = function (src) {
     this.sources[src] = src;
     this.__dirty = true;
 
-    events.emit('verbose', util.format('Added source line for `%s`', src));
+    events.emit('verbose', `Added source line for \`${src}\``);
 };
 
 Podfile.prototype.removeSource = function (src) {
@@ -227,7 +224,7 @@ Podfile.prototype.removeSource = function (src) {
         this.__dirty = true;
     }
 
-    events.emit('verbose', util.format('Removed source line for `%s`', src));
+    events.emit('verbose', `Removed source line for \`${src}\``);
 };
 
 Podfile.prototype.existsSource = function (src) {
@@ -238,7 +235,7 @@ Podfile.prototype.addDeclaration = function (declaration) {
     this.declarations[declaration] = declaration;
     this.__dirty = true;
 
-    events.emit('verbose', util.format('Added declaration line for `%s`', 
declaration));
+    events.emit('verbose', `Added declaration line for \`${declaration}\``);
 };
 
 Podfile.prototype.removeDeclaration = function (declaration) {
@@ -247,7 +244,7 @@ Podfile.prototype.removeDeclaration = function 
(declaration) {
         this.__dirty = true;
     }
 
-    events.emit('verbose', util.format('Removed source line for `%s`', 
declaration));
+    events.emit('verbose', `Removed source line for \`${declaration}\``);
 };
 
 Podfile.proofDeclaration = declaration => {
@@ -274,7 +271,7 @@ Podfile.prototype.clear = function () {
 
 Podfile.prototype.destroy = function () {
     fs.unlinkSync(this.path);
-    events.emit('verbose', util.format('Deleted `%s`', this.path));
+    events.emit('verbose', `Deleted \`${this.path}\``);
 };
 
 Podfile.prototype.write = function () {
@@ -290,13 +287,13 @@ Podfile.prototype.write = function () {
             if (spec.length) {
                 if (spec.indexOf(':') === 0) {
                     // don't quote it, it's a specification (starts with ':')
-                    return util.format('\tpod \'%s\', %s', name, spec);
+                    return `\tpod '${name}', ${spec}`;
                 } else {
                     // quote it, it's a version
-                    return util.format('\tpod \'%s\', \'%s\'', name, spec);
+                    return `\tpod '${name}', '${spec}'`;
                 }
             } else {
-                return util.format('\tpod \'%s\'', name);
+                return `\tpod '${name}'`;
             }
         } else {
             const list = [`'${name}'`];
@@ -317,14 +314,14 @@ Podfile.prototype.write = function () {
             if (options.length > 0) {
                 list.push(options.join(', '));
             }
-            return util.format('\tpod %s', list.join(', '));
+            return `\tpod ${list.join(', ')}`;
         }
     }).join('\n');
 
     const sourcesString =
     Object.keys(this.sources).map(key => {
         const source = this.sources[key];
-        return util.format('source \'%s\'', source);
+        return `source '${source}'`;
     }).join('\n');
 
     const declarationString =
@@ -351,12 +348,11 @@ Podfile.prototype.before_install = function (toolOptions) 
{
     toolOptions = toolOptions || {};
 
     // Template tokens in order: project name, project name, debug | release
-    const template =
-    '// DO NOT MODIFY -- auto-generated by Apache Cordova\n' +
-    '#include "Pods/Target Support Files/Pods-App/Pods-App.%s.xcconfig"';
+    const createXConfigContent = buildType => '// DO NOT MODIFY -- 
auto-generated by Apache Cordova\n' +
+        `#include "Pods/Target Support 
Files/Pods-App/Pods-App.${buildType}.xcconfig"`;
 
-    const debugContents = util.format(template, 'debug');
-    const releaseContents = util.format(template, 'release');
+    const debugContents = createXConfigContent('debug');
+    const releaseContents = createXConfigContent('release');
 
     const debugConfigPath = path.join(this.path, '..', 'pods-debug.xcconfig');
     const releaseConfigPath = path.join(this.path, '..', 
'pods-release.xcconfig');
diff --git a/lib/PodsJson.js b/lib/PodsJson.js
index c35ff09e..25bf0fd8 100644
--- a/lib/PodsJson.js
+++ b/lib/PodsJson.js
@@ -19,7 +19,6 @@
 
 const fs = require('node:fs');
 const path = require('node:path');
-const util = require('node:util');
 const xcode = require('xcode');
 const check_reqs = require('./check_reqs');
 const events = require('cordova-common').events;
@@ -37,11 +36,11 @@ function PodsJson (podsJsonPath) {
 
     const filename = this.path.split(path.sep).pop();
     if (filename !== PodsJson.FILENAME) {
-        throw new CordovaError(util.format('PodsJson: The file at %s is not 
`%s`.', this.path, PodsJson.FILENAME));
+        throw new CordovaError(`PodsJson: The file at ${this.path} is not 
\`${PodsJson.FILENAME}\`.`);
     }
 
     if (!fs.existsSync(this.path)) {
-        events.emit('verbose', util.format('pods.json: The file at %s does not 
exist.', this.path));
+        events.emit('verbose', `pods.json: The file at ${this.path} does not 
exist.`);
         events.emit('verbose', 'Creating new pods.json in platforms/ios');
         this.clear();
         this.write();
@@ -101,7 +100,7 @@ PodsJson.prototype.__remove = function (kind, name) {
     if (this.contents[kind][name]) {
         delete this.contents[kind][name];
         this.__dirty = true;
-        events.emit('verbose', util.format('Remove from pods.json for `%s` - 
`%s`', name));
+        events.emit('verbose', `Remove from pods.json for \`${name}\` - 
\`%s\``);
     }
 };
 
@@ -128,7 +127,7 @@ PodsJson.prototype.clear = function () {
 
 PodsJson.prototype.destroy = function () {
     fs.unlinkSync(this.path);
-    events.emit('verbose', util.format('Deleted `%s`', this.path));
+    events.emit('verbose', `Deleted \`${this.path}\``);
 };
 
 PodsJson.prototype.write = function () {
@@ -183,7 +182,7 @@ PodsJson.prototype.decrementDeclaration = function (name) {
 PodsJson.prototype.__setJson = function (kind, name, json) {
     this.contents[kind][name] = Object.assign({}, json);
     this.__dirty = true;
-    events.emit('verbose', util.format('Set pods.json for `%s` - `%s`', kind, 
name));
+    events.emit('verbose', `Set pods.json for \`${kind}\` - \`${name}\``);
 };
 
 // sample json for library
diff --git a/lib/build.js b/lib/build.js
index 5f722af6..f06c8c1f 100644
--- a/lib/build.js
+++ b/lib/build.js
@@ -19,7 +19,6 @@
 
 const fs = require('node:fs');
 const path = require('node:path');
-const util = require('node:util');
 const nopt = require('nopt');
 const which = require('which');
 const execa = require('execa');
@@ -475,7 +474,7 @@ function parseBuildFlag (buildFlag, args) {
             matched = true;
             // found[0] is the whole match, found[1] is the first match in 
parentheses.
             args[key] = found[1];
-            events.emit('warn', util.format('Overriding xcodebuildArg: %s', 
buildFlag));
+            events.emit('warn', `Overriding xcodebuildArg: ${buildFlag}`);
         }
     }
 
@@ -485,10 +484,10 @@ function parseBuildFlag (buildFlag, args) {
         // setting that is wrapped in quotes.
         if (buildFlag[0] === '-' && 
!buildFlag.match(/^[^=]+=(["'])(.*?[^\\])\1$/)) {
             args.otherFlags = args.otherFlags.concat(buildFlag.split(' '));
-            events.emit('warn', util.format('Adding xcodebuildArg: %s', 
buildFlag.split(' ')));
+            events.emit('warn', `Adding xcodebuildArg: ${buildFlag.split(' 
')}`);
         } else {
             args.otherFlags.push(buildFlag);
-            events.emit('warn', util.format('Adding xcodebuildArg: %s', 
buildFlag));
+            events.emit('warn', `Adding xcodebuildArg: ${buildFlag}`);
         }
     }
 }
diff --git a/lib/plugman/pluginHandlers.js b/lib/plugman/pluginHandlers.js
index d9aec4c1..a465cd3f 100644
--- a/lib/plugman/pluginHandlers.js
+++ b/lib/plugman/pluginHandlers.js
@@ -17,7 +17,6 @@
 'use strict';
 const fs = require('node:fs');
 const path = require('node:path');
-const util = require('node:util');
 const events = require('cordova-common').events;
 const CordovaError = require('cordova-common').CordovaError;
 const { isSwiftPackagePlugin } = require('../SwiftPackage');
@@ -117,9 +116,9 @@ const handlers = {
                         project.frameworks[src] = project.frameworks[src] || 0;
                         project.frameworks[src]++;
                         const opt = { customFramework: false, embed: false, 
link: true, weak: obj.weak };
-                        events.emit('verbose', util.format('Adding non-custom 
framework to project... %s -> %s', src, JSON.stringify(opt)));
+                        events.emit('verbose', `Adding non-custom framework to 
project... ${src} -> ${JSON.stringify(opt)}`);
                         project.xcode.addFramework(src, opt);
-                        events.emit('verbose', util.format('Non-custom 
framework added to project. %s -> %s', src, JSON.stringify(opt)));
+                        events.emit('verbose', `Non-custom framework added to 
project. ${src} -> ${JSON.stringify(opt)}`);
                     }
                 }
                 return;
@@ -139,9 +138,9 @@ const handlers = {
                 project.xcode.addBuildPhase([], 'PBXCopyFilesBuildPhase', 
'Embed Frameworks', null, 'frameworks');
             }
             const opt = { customFramework: true, embed, link, sign: true };
-            events.emit('verbose', util.format('Adding custom framework to 
project... %s -> %s', src, JSON.stringify(opt)));
+            events.emit('verbose', `Adding custom framework to project... 
${src} -> ${JSON.stringify(opt)}`);
             project.xcode.addFramework(project_relative, opt);
-            events.emit('verbose', util.format('Custom framework added to 
project. %s -> %s', src, JSON.stringify(opt)));
+            events.emit('verbose', `Custom framework added to project. ${src} 
-> ${JSON.stringify(opt)}`);
         },
         uninstall: function (obj, plugin, project, options) {
             if (isSwiftPackagePlugin(plugin)) return;
diff --git a/lib/projectFile.js b/lib/projectFile.js
index 1e9fa06d..ef838c9c 100644
--- a/lib/projectFile.js
+++ b/lib/projectFile.js
@@ -113,7 +113,6 @@ 
xcode.project.prototype.removeFromPbxEmbedFrameworksBuildPhase = function (file)
 
 // special handlers to add frameworks to the 'Embed Frameworks' build phase, 
needed for custom frameworks
 // see CB-9517. should probably be moved to node-xcode.
-const util = require('util');
 function pbxBuildPhaseObj (file) {
     const obj = Object.create(null);
     obj.value = file.uuid;
@@ -122,5 +121,5 @@ function pbxBuildPhaseObj (file) {
 }
 
 function longComment (file) {
-    return util.format('%s in %s', file.basename, file.group);
+    return `${file.basename} in ${file.group}`;
 }
diff --git a/tests/spec/unit/Podfile.spec.js b/tests/spec/unit/Podfile.spec.js
index 98a9a23c..1fed2f9b 100644
--- a/tests/spec/unit/Podfile.spec.js
+++ b/tests/spec/unit/Podfile.spec.js
@@ -18,7 +18,6 @@
 */
 
 const path = require('node:path');
-const util = require('node:util');
 const fs = require('node:fs');
 const CordovaError = require('cordova-common').CordovaError;
 
@@ -37,7 +36,7 @@ describe('unit tests for Podfile module', () => {
             const dummyPath = 'NotAPodfile';
             expect(() => {
                 new Podfile(dummyPath); /* eslint no-new : 0 */
-            }).toThrow(new CordovaError(util.format('Podfile: The file at %s 
is not `%s`.', dummyPath, Podfile.FILENAME)));
+            }).toThrow(new CordovaError(`Podfile: The file at ${dummyPath} is 
not \`${Podfile.FILENAME}\`.`));
         });
 
         it('Test 003 : throws CordovaError when no pod name provided when 
adding a spec', () => {
@@ -121,12 +120,11 @@ describe('unit tests for Podfile module', () => {
             podfile.before_install();
 
             // Template tokens in order: project name, project name, debug | 
release
-            const template =
-            '// DO NOT MODIFY -- auto-generated by Apache Cordova\n' +
-            '#include "Pods/Target Support 
Files/Pods-App/Pods-App.%s.xcconfig"';
+            const createXConfigContent = buildType => '// DO NOT MODIFY -- 
auto-generated by Apache Cordova\n' +
+                `#include "Pods/Target Support 
Files/Pods-App/Pods-App.${buildType}.xcconfig"`;
 
-            const expectedDebugContents = util.format(template, 'debug');
-            const expectedReleaseContents = util.format(template, 'release');
+            const expectedDebugContents = createXConfigContent('debug');
+            const expectedReleaseContents = createXConfigContent('release');
 
             const actualDebugContents = 
fs.readFileSync(fixturePodXcconfigDebug, 'utf8');
             const actualReleaseContents = 
fs.readFileSync(fixturePodXcconfigRelease, 'utf8');
diff --git a/tests/spec/unit/PodsJson.spec.js b/tests/spec/unit/PodsJson.spec.js
index 424e012a..ce0bf8cb 100644
--- a/tests/spec/unit/PodsJson.spec.js
+++ b/tests/spec/unit/PodsJson.spec.js
@@ -19,7 +19,6 @@
 
 const fs = require('node:fs');
 const path = require('node:path');
-const util = require('node:util');
 const CordovaError = require('cordova-common').CordovaError;
 
 const PodsJson = require(path.resolve(__dirname, '..', '..', '..', 'lib', 
'PodsJson.js')).PodsJson;
@@ -40,7 +39,7 @@ describe('unit tests for Podfile module', () => {
             const dummyPath = 'NotPodsJson';
             expect(() => {
                 new PodsJson(dummyPath); /* eslint no-new : 0 */
-            }).toThrow(new CordovaError(util.format('PodsJson: The file at %s 
is not `%s`.', dummyPath, PodsJson.FILENAME)));
+            }).toThrow(new CordovaError(`PodsJson: The file at ${dummyPath} is 
not \`${PodsJson.FILENAME}\`.`));
         });
 
         it('Test 002 : setsJson and gets pod test', () => {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to