-
Notifications
You must be signed in to change notification settings - Fork 172
CB-12142: Move windows-specific logic from cordova-common #207
CB-12142: Move windows-specific logic from cordova-common #207
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM apart the comments and assuming the tests will pass.
Do I get it right that it will require us to release cordova-common before platform release?
// Demux 'package.appxmanifest' into relevant platform-specific appx manifests. | ||
// Only spend the cycles if there are version-specific plugin settings | ||
if (changes.some(function(change) { | ||
return change.target === 'package.appxmanifest'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matrosov-nikita could you explain the code change here from
changes.some(function(change) {
return ((typeof change.versions !== 'undefined') ||
(typeof change.deviceTarget !== 'undefined'));
}))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes w/ target 'package.appxmanifest' and w/o versions and deviceTarget used to demux into manifests in remove_plugin_changes and munge_helper methods. This logic is moved in PluginInfo.js (see also b101ded?diff=unified#diff-93a26ea6e269125a5b151c4176a3b42bR54).
Once windows-specific logic is completed there aren't any changes with 'package.appxmanifest' target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In cordova-common we'll get ready changes and push them again. (see also https://github.com/apache/cordova-lib/blob/master/cordova-common/src/ConfigChanges/ConfigChanges.js#L365). So, I suppose, that we needn't release cordova-common before platform release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thank you!
Could you update the code so that it passes for node@0.x (as we a still supporting it)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(windows81AppxManifest.parents['/Parent/Capabilities'][0].xml).toBe('<Capability Note="should-exist-for-all-appxmanifest-target-files" />'); | ||
expect(windows81AppxManifest.parents['/Parent/Capabilities'][1].xml).toBe('<Capability Note="should-exist-for-win81-win-and-phone" />'); | ||
expect(windows81AppxManifest.parents['/Parent/Capabilities'][2].xml).toBe('<Capability Note="should-exist-for-win81-win-only" />'); | ||
expect(windows81AppxManifest.parents['/Parent/Capabilities'][3].xml).toBe('<Capability Note="should-exist-for-win10-and-win81-win-and-phone" />'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add checks for capabilities count back - they could prevent situation when we have something extraneous.
expect(windows81AppxManifest.parents['/Parent/Capabilities'][0].count).toBe(3);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daserge, done.
@matrosov-nikita, I think the idea was to make it so updated cordova-windows will continue to work w/ current cordova-common, right? |
@vladimir-kotikov, yes, you are right. Have you any questions or concerns about this matter? |
@@ -187,12 +187,14 @@ describe('generate_plugin_config_munge for windows project', function() { | |||
// 1 comes from versions="=8.1.0" + 1 from versions="=8.1.0" device-target="windows" | |||
expect(windows81AppxManifest.parents['/Parent/Capabilities'][0].xml).toBe('<Capability Note="should-exist-for-all-appxmanifest-target-files" />'); | |||
expect(windows81AppxManifest.parents['/Parent/Capabilities'][1].xml).toBe('<Capability Note="should-exist-for-win81-win-and-phone" />'); | |||
expect(windows81AppxManifest.parents['/Parent/Capabilities'][1].count).toBe(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matrosov-nikita is this a right element to check count?
Should not it be expect(windows81AppxManifest.parents['/Parent/Capabilities'].count).toBe(4);
?
I know it was this way in the original code, but it just looks strange.
Also, @matrosov-nikita could you please create a Jira issue for tracking (http://issues.cordova.io), rename the PR title and add the commit prefix? |
* @return {[Object]} plugin's munge | ||
*/ | ||
PlatformMunger.prototype.generate_plugin_config_munge = function (pluginInfo, vars, edit_config_changes) { | ||
var self = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be requried - calling a prototype is not a closure so you can safely use this
*/ | ||
function PluginInfo(dirname) { | ||
CommonPluginInfo.apply(this, arguments); | ||
var parentGetConfigFiles = this.getConfigFiles; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than saving this into a variable i'd propose to call ThisClass.super_.prototype.generate_plugin_config_munge
method directly
var parentGetConfigFiles = this.getConfigFiles; | ||
this.getConfigFiles = function(platform) { | ||
var changes = parentGetConfigFiles(platform); | ||
var editChanges = this.getEditConfigs(platform); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that we should do something with <edit-config>
tags here. You'd probably need to override parent getEditConfigs
method in a same way as getConfigFiles
possibly sharing the similar logic between them.
} | ||
// Demux 'package.appxmanifest' into relevant platform-specific appx manifests. | ||
// Only spend the cycles if there are version-specific plugin settings | ||
if (changes.some(function(change) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: could you please invert if
condition here? Also it might be more convenient to assign this condition to intermediate variable, something like var hasManifestChanges = changes.some(function(change) { return change.target === 'package.appxmanifest' })
// Demux 'package.appxmanifest' into relevant platform-specific appx manifests. | ||
// Only spend the cycles if there are version-specific plugin settings | ||
if (changes.some(function(change) { | ||
return change.target === 'package.appxmanifest'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes = changes.concat(substs.map(function(subst) { | ||
return Object.assign({}, change, {target: subst}); | ||
})); | ||
return changes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you can just return
here - result of this function is not used anywhere
In addition it overrides getConfigFiles method to use windows-specific logic | ||
*/ | ||
function PluginInfo(dirname) { | ||
CommonPluginInfo.apply(this, arguments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls add a comment, clarifying why you're not using util.inherit
to build a children class
var oldChanges = changes; | ||
changes = []; | ||
|
||
oldChanges.forEach(function(change, changeIndex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general comment - can you please divide this function into smaller pieces, so it'd be easier to review and test?
Current coverage is 75.28% (diff: 100%)@@ master #207 diff @@
==========================================
Files 15 16 +1
Lines 2067 2120 +53
Methods 390 401 +11
Messages 0 0
Branches 403 410 +7
==========================================
+ Hits 1543 1596 +53
Misses 524 524
Partials 0 0
|
6019414
to
32c9f82
Compare
@vladimir-kotikov @daserge, I've created a Jira issue: https://issues.apache.org/jira/browse/CB-12142, fixed all your comments. Also I think it would be better to add prefix to commit after squashing. Pls, review. |
return processChanges(configFiles); | ||
}; | ||
|
||
function processChanges(changes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to move this out of PluginInfo
- this way it'd be possible to use this function in tests (using rewire
)
return changes; | ||
} | ||
|
||
function checkManifestChanges(changes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're calling this only once - is there a real need to wrap this into function?
return change.target === 'package.appxmanifest'; | ||
}); | ||
} | ||
function hasChangeVersion(change) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
return (typeof change.versions !== 'undefined'); | ||
} | ||
|
||
function hasChangeTarget(change) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
} | ||
|
||
var targetDeviceSet = getDeviceTargetSetForChange(change); | ||
changes = replaceChangeTarget(targetDeviceSet, change, changes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider renaming replaceChangeTarget
to something more appropriate as it doesn't really replace anything in the original array
|
||
// This is a local function that creates the new replacement representing the | ||
// mutation. Used to save code further down. | ||
function createReplacement(manifestFile, originalChange) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very similar to createChangeWithNewTarget
function - consider merging into one function
87d886a
to
600ac0b
Compare
This logic is associated with demuxing 'package.appxmanifest' into relevant platform-specific appx manifests. Also auto-test was moved and edited according changes
034a6b3
to
519016f
Compare
141e52c
to
00b6fa7
Compare
Looks good. Let's wait for tomorrow and merge it. |
What does this PR do?
This PR moves windows-specific logic from cordova-common to cordova-windows. This logic is associated with demuxing 'package.appxmanifest' into relevant platform-specific appx manifests. Also auto-test was moved and edited according changes.
What testing has been done on this change?
Auto test
Checklist