-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore backup files before changing to new dependency set for new scenarios. #451
Conversation
Codecov Report
@@ Coverage Diff @@
## master #451 +/- ##
==========================================
- Coverage 96.91% 96.90% -0.02%
==========================================
Files 17 17
Lines 584 581 -3
==========================================
- Hits 566 563 -3
Misses 18 18
Continue to review full report at Codecov.
|
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.
Can you please describe the issue you are seeing in more detail (like step by step, explaining where things go wrong)? I don't fully understand what you are trying to solve, so it is somewhat hard to tell if this PR fixes it...
|
||
debug('Write package.json with: \n', JSON.stringify(newPackageJSON)); | ||
return this._restoreOriginalDependencies().then(() => { |
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.
It seems very bizarre to restore before applying the depSet changes here.
Any cleanup/restore that was supposed to happen should have happened before the next scenario runs it's applyDependencySet
.
versionSeen: adapter._findCurrentVersionOf(dep), | ||
packageManager: adapter.useYarnCommand ? 'yarn' : 'npm', | ||
}; | ||
return adapter.applyDependencySet(depSet).then(() => { |
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.
We absolutely should have been entangling this all along, this fix seems good regardless of the changes within applyDependencySet
itself.
let appliedDependencies = this._packageAdapters.map(adapter => | ||
adapter.applyDependencySet(depSet) | ||
); | ||
|
||
return RSVP.all(appliedDependencies).then(() => { |
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.
Like above, this seems like a great fundamental fix. Are you certain that these fixes to properly entangle applyDependencySet
aren't all that is needed to solve the issue you described?
@@ -59,6 +59,43 @@ describe('npmAdapter', () => { | |||
}); | |||
}); | |||
|
|||
describe('#changeToDependencySet', () => { | |||
it('restores the backup before changing to the new dependency set', () => { |
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 am fairly opposed to this 😸, setting up a new scenario to run should not itself require resetting to the backup first. This resetting seems to be masking another fundamental problem..
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.
Yea, I agree. It does feel a bit strange to reset to the backup first, instead, it should restore the backup at the end of each scenario. Let me look into our particular use case more closely and will get back to you.
@rwjblue The issue is the following: A project was using
And the ember-try scenario was:
The ask is to make sure that |
@dnachev - This PR (at the moment) is resetting the various files before starting a scenario, when instead it should be ensuring that the resetting happens when the current scenario is completed. Specifically, in your timeline:
Once the scenario passes, the
The original |
@rwjblue yea, I agree. I will refactor the code and move the logic for backup into the try-each. |
I did a bit more digging, and I think the issue is here: ember-try/lib/dependency-manager-adapters/npm.js Lines 145 to 158 in bff5859
As you can see, the original When using IMHO, the best fix would be to update here: ember-try/lib/tasks/try-each.js Lines 51 to 81 in bff5859
To ensure that we run We should also deprecate the |
@rwjblue Yea, I don't have enough context to understand why I think the easiest thing to do is to call return task._runCommand({ commandArgs: command, commandOptions: task._commandOptions(scenario.env) }).then((result) => {
if (task._canceling) { return; }
runResults.result = result;
task._writeFooter(`Result: ${result}`);
// add our change here
return task._restoreOriginalDependencies().then(() => RSVP.resolve(runResults));
}); This is a much easier change and won't affect current behavior. Let me know what you think. edit: minor edit to the code so that runResults gets return last. You could even remove the RSVP.resolve as I don't think that really adds anything since you're returning a promise no matter what. |
@huyphamily In general that seems fine (only restoring the |
@rwjblue Code updated. I have added an API to ScenarioManger for restoring the original backup and calling it at the end of each scenario. |
I thought you mentioned that you didn't want to restore the |
@rwjblue yea, you're right, we don't want to restore the |
@rwjblue or we can pass a parameter into |
Hmm, I thought it we already had a method that restored the manifest and lockfiles but not the fully |
@rwjblue we do not...unless I miss something? |
I guess I was assuming that the fix here would be to modify ember-try/lib/dependency-manager-adapters/npm.js Lines 145 to 158 in bff5859
|
@huyphamily - Friendly ping 😃😃 |
@rwjblue Apologies for the super late replies. For try:one, we properly restore the backup files, so we can ignore this case. For try:each, the current behavior is to restore the backup files at the end of all scenarios, which is where our issue lies. We want to restore at the end of each scenario, hence why the change to try-each.js. We do not want to restore any of the associated backup files in This change will restore the backup files at the end of each scenario in try:each |
@rwjblue any thoughts on this? |
The thing is, I don't really want to restore the |
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.
There are still a few changes needed here to ensure that all of the built in managers work properly with the main change.
- Update the
bower
adapter to implementrestoreOriginalDependencies
(would need to be extracted from currentcleanup
logic):
ember-try/lib/dependency-manager-adapters/bower.js
Lines 93 to 110 in aa4e3ff
cleanup() { | |
let adapter = this; | |
if (this.hasBowerFileInitially) { | |
return adapter._restoreOriginalBowerFile().then(() => { | |
debug('Remove backup bower.json'); | |
return rimraf(path.join(adapter.cwd, adapter.bowerJSONBackupFileName)); | |
}).catch((e) => { | |
console.log('Error cleaning up bower scenario:', e); // eslint-disable-line no-console | |
}) | |
.then(() => { | |
return adapter._install(); | |
}); | |
} else { | |
return rimraf(path.join(adapter.cwd, adapter.bowerJSONFileName)).then(() => { | |
return rimraf(path.join(adapter.cwd, 'bower_components')); | |
}); | |
} | |
}, |
- Update
workspace
manager to implementrestoreOriginalDependencies
, this will look basically the same as thecleanup
method (but forrestoreOriginalDependencies
):
ember-try/lib/dependency-manager-adapters/workspace.js
Lines 88 to 90 in aa4e3ff
cleanup() { | |
return RSVP.all(this._packageAdapters.map(adapter => adapter.cleanup())); | |
}, |
I just got back from paternity leave and things got a little hectic, so sorry for the late reply. I made the changes to add restoreOriginalDependencies in workplace adapter. However, I did not add restoreOriginalDependencies for bower since you mention in the past that not to add to bower as it's going away. Is this not still true? |
Ya, it is true in general, but without doing something here we are going to throw an error if you have Bower scenarios and that is not ok... |
…cenarios. When there is only a single scenario to run (e.g. `ember try:one`) we should not be cleaning up as part of running the scenario itself because in that case we would immediately cleanup _anyways_. If we forced cleanup to happen during the scenario run, then it would be impossible to have `--skip-cleanup` work at all.
I've rebased and made a tweak to ensure that when running I'll be working on finalizing this PR today, I think at this point we just need lots of tests:
|
Closing for now. |
This PR is created to fix an issue we are having when using
buildManagerOptions
and removing the default--no-lockfile
option in order to use our yarn.lock file. In the current behavior, when switching between scenarios, versions from the previous scenario gets carried over to the next scenario, which is not the ideal behavior that we want. We want to reset the yarn.lock to the original version, before changing the dependencies of the new scenario.In order to accomplish this, we will restore all backups before installing new dependencies for the new scenario. This will not affect the current default behavior for those with default settings, but will greatly improve the experience of those who are using
buildManagerOptions
to override the default--no-lockfile
.