Skip to content

Commit

Permalink
android: fix Api.js access for cordova-android 10 (#14)
Browse files Browse the repository at this point in the history
* Fixed for Api.js specification changes in Cordova-Android@10

* fix: delete space
  • Loading branch information
okhiroyuki committed Aug 23, 2021
1 parent c72d9f1 commit 69b0122
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
Expand Up @@ -2,11 +2,15 @@ const fs = require('fs');
const path = require('path');

// Gets the platform's www path.
function getPlatformWWWPath(context, platform)
{
var platformPath = path.join(context.opts.projectRoot, 'platforms', platform);
var platformAPI = require(path.join(platformPath, 'cordova', 'Api'));
var platformAPIInstance = new platformAPI();
function getPlatformWWWPath(context, platform) {
const platformPath = path.join(context.opts.projectRoot, 'platforms', platform);
const platformAPI = require(path.join(platformPath, 'cordova', 'Api'));
let platformAPIInstance;
try {
platformAPIInstance = new platformAPI();
} catch (e) {
platformAPIInstance = new platformAPI(platform, platformPath);
}
return platformAPIInstance.locations.www;
}

Expand Down
14 changes: 9 additions & 5 deletions install/hooks/both/after-prepare-native-modules-preference.js
Expand Up @@ -2,11 +2,15 @@ const fs = require('fs');
const path = require('path');

// Gets the platform's www path.
function getPlatformWWWPath(context, platform)
{
var platformPath = path.join(context.opts.projectRoot, 'platforms', platform);
var platformAPI = require(path.join(platformPath, 'cordova', 'Api'));
var platformAPIInstance = new platformAPI();
function getPlatformWWWPath(context, platform) {
const platformPath = path.join(context.opts.projectRoot, 'platforms', platform);
const platformAPI = require(path.join(platformPath, 'cordova', 'Api'));
let platformAPIInstance;
try {
platformAPIInstance = new platformAPI();
} catch (e) {
platformAPIInstance = new platformAPI(platform, platformPath);
}
return platformAPIInstance.locations.www;
}

Expand Down
18 changes: 11 additions & 7 deletions install/hooks/both/after-prepare-patch-npm-packages.js
Expand Up @@ -50,13 +50,17 @@ function visitPackageJSON(folderPath)
}

// Applies the patch to the selected platform
function patchTargetPlatform(context, platform)
{
var platformPath = path.join(context.opts.projectRoot, 'platforms', platform);
var platformAPI = require(path.join(platformPath, 'cordova', 'Api'));
var platformAPIInstance = new platformAPI();
var wwwPath = platformAPIInstance.locations.www;
var nodeModulesPathToPatch = path.join(wwwPath, 'nodejs-project', 'node_modules');
function patchTargetPlatform(context, platform) {
const platformPath = path.join(context.opts.projectRoot, 'platforms', platform);
const platformAPI = require(path.join(platformPath, 'cordova', 'Api'));
let platformAPIInstance;
try {
platformAPIInstance = new platformAPI();
} catch (e) {
platformAPIInstance = new platformAPI(platform, platformPath);
}
const wwwPath = platformAPIInstance.locations.www;
const nodeModulesPathToPatch = path.join(wwwPath, 'nodejs-project', 'node_modules');
if (fs.existsSync(nodeModulesPathToPatch)) {
visitPackageJSON(nodeModulesPathToPatch);
}
Expand Down

0 comments on commit 69b0122

Please sign in to comment.