cordova-lib
cordova-lib copied to clipboard
Prevent updating package.json if there are no actual changes
I use several additional tools with Cordova for build management. Some of those watch for changes in files in order to rebuild/redistribute. Many hard-code watching the package.json file for changes. When running cordova serve
, that calls cordova prepare
, and package.json gets updated (so does config.xml), whether there are actually changes to it or not (e.g., no results from a diff). This causes those build watchers to fire, rebuild, copy some files to www, which causes Cordova's auto-reload to kick in, which updates package.json again, which continues this infinite cycle.
Is there a way to avoid writing the exact same content to package.json that already exists in that file on every restart/reload? I get we need config.xml and package.json to "jive" but if there's no diff between what Cordova is about to write to package.json and what's already in package.json, can we skip the write?
Here is a Gist with my 2 files.
On a related note, when I run cordova serve
, the config.xml file has the engine tags listed before the plugin tags, near the end of the file. However, when I run cordova run android --device
, the config.xml file has the engine tags listed after the plugin tags, at the very bottom of the file.
Again, the contents of config.xml didn't really change, just the order of tags. Whereas, package.json had zero changes (even to the order of properties), yet was written to, thus updating its modified date.