You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2021/09/26 15:28:07 UTC

[GitHub] [cordova-lib] raphinesse commented on a change in pull request #860: fix(cordova/util): Support requiring PlatformAPI from node_modules

raphinesse commented on a change in pull request #860:
URL: https://github.com/apache/cordova-lib/pull/860#discussion_r716220531



##########
File path: src/cordova/util.js
##########
@@ -301,14 +301,26 @@ function isDirectory (dir) {
 
 // Returns the API of the platform contained in `dir`.
 // Potential errors : module isn't found, can't load or doesn't implement the expected interface.
-function getPlatformApiFunction (dir) {
+function getPlatformApiFunction (dir, platform) {
     let PlatformApi;
     try {
+        // First try to load the platform API from the platform project
+        // This is necessary to support older platform API versions
         PlatformApi = exports.requireNoCache(dir);
     } catch (err) {
-        // Module not found or threw error during loading
-        err.message = `Unable to load Platform API from ${dir}:\n${err.message}`;
-        throw err;
+        try {
+            let cdvPlatform = platform;
+            if (!platform.startsWith('cordova-')) {
+                cdvPlatform = `cordova-${platform}`;
+            }

Review comment:
       Different way to do the same thing:
   ```suggestion
               const cdvPlatform = platform.replace(/^(?:cordova-)?/, 'cordova-');
   ```




-- 
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-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org