Do not explicitly require modules from project directory (#713)

* Allow to pass-through projectPath to Builder

* Do not explicitly require modules from project directory
This commit is contained in:
Raphael von der Grün 2019-04-13 17:34:59 +02:00 committed by GitHub
parent b177f84825
commit 4cf3dcfaae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 8 deletions

View File

@ -142,8 +142,8 @@ function writeProjectProperties (projectPath, target_api) {
// This makes no sense, what if you're building with a different build system? // This makes no sense, what if you're building with a different build system?
function prepBuildFiles (projectPath) { function prepBuildFiles (projectPath) {
var buildModule = require(path.resolve(projectPath, 'cordova/lib/builders/builders')); var buildModule = require('../templates/cordova/lib/builders/builders');
buildModule.getBuilder().prepBuildFiles(); buildModule.getBuilder(projectPath).prepBuildFiles();
} }
function copyBuildRules (projectPath, isLegacy) { function copyBuildRules (projectPath, isLegacy) {

View File

@ -99,8 +99,7 @@ Api.createPlatform = function (destination, config, options, events) {
var result; var result;
try { try {
result = require('../../lib/create').create(destination, config, options, events).then(function (destination) { result = require('../../lib/create').create(destination, config, options, events).then(function (destination) {
var PlatformApi = require(path.resolve(destination, 'cordova/Api')); return new Api(PLATFORM, destination, events);
return new PlatformApi(PLATFORM, destination, events);
}); });
} catch (e) { } catch (e) {
events.emit('error', 'createPlatform is not callable from the android project API.'); events.emit('error', 'createPlatform is not callable from the android project API.');
@ -130,8 +129,7 @@ Api.updatePlatform = function (destination, options, events) {
var result; var result;
try { try {
result = require('../../lib/create').update(destination, options, events).then(function (destination) { result = require('../../lib/create').update(destination, options, events).then(function (destination) {
var PlatformApi = require(path.resolve(destination, 'cordova/Api')); return new Api(PLATFORM, destination, events);
return new PlatformApi('android', destination, events);
}); });
} catch (e) { } catch (e) {
events.emit('error', 'updatePlatform is not callable from the android project API, you will need to do this manually.'); events.emit('error', 'updatePlatform is not callable from the android project API, you will need to do this manually.');

View File

@ -24,10 +24,10 @@ const CordovaError = require('cordova-common').CordovaError;
* *
* @return {Builder} A builder instance for specified build type. * @return {Builder} A builder instance for specified build type.
*/ */
module.exports.getBuilder = function () { module.exports.getBuilder = function (projectPath) {
try { try {
const Builder = require('./ProjectBuilder'); const Builder = require('./ProjectBuilder');
return new Builder(); return new Builder(projectPath);
} catch (err) { } catch (err) {
throw new CordovaError('Failed to instantiate ProjectBuilder builder: ' + err); throw new CordovaError('Failed to instantiate ProjectBuilder builder: ' + err);
} }