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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]