-
Notifications
You must be signed in to change notification settings - Fork 73
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
Model Creation Side Effects #25
Comments
Let's split this problem to two parts: 1. missing newline at end of fileThis is IMO a bug we should definitely fix. 2. reordering of properties in package.json (and possibly other files)This is caused by the internal design of loopback-workspace and how it represents various configuration files. I am afraid we can't preserve the ordering of items in JSON files in general. However, it should be possible to detect the situation where the data was not changed (i.e. the canonical-json representation of what we have in memory and what is in the file yields the same content) and don't touch the file in such case. |
We are using |
Thank you for tracking down the newline issue and raising a feature request so quickly with Regarding the reordering of properties I understand why you are unable to preserve the order. I guess my confusion came from the fact the I briefly browsed the source for this project and loopback-workspace and was unable to easily determine where the Thanks again! |
The truth is, the current implementation of loopback-workspace always loads and writes all files it knows about, regardless of whether there was any change in them.
I'd rather implement a generic solution where any JSON file write is skipped if the content in the file is equivalent to what we have in memory. I am not sure if I manage to implement this today, before my two-weeks holiday. If you feel like contributing the change yourself, here is some info to get you started: JSON files are written by configFile.save. The write should be skipped when the data was not changed. A mockup of the change-detection algorithm: function isChanged(filePath, data) {
var cjson = require('canonical-json');
var originalData = fs.readJsonFile(filePath);
return cjson(newData) !== cjson(originalData);
} |
I may have time to explore a fixed based on your recommendations later this week. |
FWIW, |
@greaterweb is the reordering of properties still an issue for you? While loopback-workspace and yo loopback enforce order of certain properties, the order is changed only the first time you run the generator. Afterwards, the order "stabilises" and should not be changed. |
It's less of an issue now, I really just noticed it in some of the initial work done using the generator. Thanks for your efforts! |
ok, I'll close the issue for now. |
When running
yo loopback:model
a side effect of the model creation is minor updates to variousjson
config files read by the generator.package.json order of properties
My
package.json
file had thetitle
property listed before thename
property. After runningyo loopback:model
and adding a new model, the order was reversed.newline at end of file removed
My projects leverage an
.editorconfig
file with the ruleinsert_final_newline = true
. After runningyo loopback:model
and adding a new model, the following files had final newline removed:package.json
server/config.json
server/datasources.json
server/model-config.json
- other required updates to this file are made though the final newline is stripped in updatingWhile the changes seem insignificant, it will require attention when the files mentioned are in source control.
With the exception of
model-config.json
, is it necessary to write to these files?The text was updated successfully, but these errors were encountered: