Skip to content

Commit

Permalink
[TIMOB-24722] Handle unresolved modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Oct 4, 2017
1 parent e7e5ae6 commit d6fc1a1
Showing 1 changed file with 45 additions and 30 deletions.
75 changes: 45 additions & 30 deletions android/cli/commands/_buildModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,48 +288,63 @@ AndroidModuleBuilder.prototype.initialize = function initialize(next) {
this.globalModulesDir = path.join(this.globalModulesPath, 'android');

// process module dependencies
this.modules = this.timodule && !Array.isArray(this.timodule.modules) ? [] : this.timodule.modules.filter(function(m) {
if (!m.platform || /^android$/.test(m.platform)) {
var localPath = path.join(this.modulesDir, m.id),
globalPath = path.join(this.globalModulesDir, m.id),
getModulePath = function(modulePath) {
var items = fs.readdirSync(modulePath);
if (m.version) {
for (var item of items) {
if (item === m.version) {
m.path = path.join(modulePath, m.version);
return true;
}
}
} else if (items.length) {
var latest = items[items.length - 1];
if (!latest.startsWith('.')) {
m.version = latest;
m.path = path.join(modulePath, m.version);
return true;
}
}
return false;
}.bind(this);

if ((fs.existsSync(localPath) && getModulePath(localPath)) ||
(fs.existsSync(globalPath) && getModulePath(globalPath))) {
var setModulePath = function(module, modulePath) {
var items = fs.readdirSync(modulePath);
if (module.version) {
for (var item of items) {
if (item === module.version) {
module.path = path.join(modulePath, module.version);
return true;
}
}
} else if (items.length) {
var latest = items[items.length - 1];
if (!latest.startsWith('.')) {
module.version = latest;
module.path = path.join(modulePath, module.version);
return true;
}
}
return false;
}.bind(this));
};
this.unresolvedModules = [];
this.modules = this.timodule && !Array.isArray(this.timodule.modules) ? [] : this.timodule.modules.filter(function(module) {
if (!module.platform || /^android$/.test(module.platform)) {
var localPath = path.join(this.modulesDir, module.id),
globalPath = path.join(this.globalModulesDir, module.id);

if ((fs.existsSync(localPath) && setModulePath(module, localPath)) ||
(fs.existsSync(globalPath) && setModulePath(module, globalPath))) {
return true;
} else {
this.unresolvedModules.push(module);
}
}
return false;
}, this);

// check for any unresolved modules required for build
if (this.unresolvedModules.length) {
var msg = 'could not find required modules:';
for (var module of this.unresolvedModules) {
msg += __('\n id: %s version: %s platform: %s',
module.id,
module.version ? module.version : 'latest',
module.platform ? module.platform : 'all');
}
return next(new Error(msg));
}

// obtain module dependency android archives for aar-transform to find
this.moduleAndroidLibraries = [];
for (var module of this.modules) {
var libPath = path.join(module.path, 'lib');
fs.existsSync(libPath) && fs.readdirSync(libPath).forEach(function (name) {
fs.existsSync(libPath) && fs.readdirSync(libPath).forEach(function(name) {
var file = path.join(libPath, name);
if (/\.aar$/.test(name) && fs.existsSync(file)) {
this.moduleAndroidLibraries.push({
aarPathAndFilename: String(file),
originType: 'Module'
aarPathAndFilename: file,
originType: 'Module' // TODO: grab this from 'aar-transform.js'
});
}
}, this);
Expand Down

0 comments on commit d6fc1a1

Please sign in to comment.