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 2020/10/28 07:59:12 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_r513236895



##########
File path: src/cordova/util.js
##########
@@ -301,14 +301,23 @@ 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 {
         PlatformApi = exports.requireNoCache(dir);

Review comment:
       ```suggestion
           // First try to load the platform API from the platform project
           // This is necessary to support older platform API versions
           PlatformApi = exports.requireNoCache(dir);
   ```

##########
File path: src/cordova/util.js
##########
@@ -301,14 +301,23 @@ 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 {
         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}`;
+            }
+
+            PlatformApi = exports.requireNoCache(cdvPlatform);

Review comment:
       ```suggestion
               // Load the platform API directly from node_modules
               PlatformApi = exports.requireNoCache(cdvPlatform);
   ```
   
   Do we need `requireNoCache` here? I guess not. But I'm not entirely sure.

##########
File path: src/cordova/util.js
##########
@@ -301,14 +301,23 @@ 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 {
         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 {

Review comment:
       Maybe only retry if `err.code === 'MODULE_NOT_FOUND'`? Not sure what would be better here.




----------------------------------------------------------------
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.

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