in src/server/live-reload/live-reload.js [49:97]
LiveReload.prototype._onFileChanged = function (fileRelativePath, parentDir) {
fileRelativePath = fileRelativePath.replace(/\\/g, '/');
var propagateChangePromise;
if (this._forcePrepare) {
// Sometimes, especially on Windows, prepare will fail because the modified file is locked for a short duration
// after modification, so we try to prepare twice.
propagateChangePromise = this._project.prepare()
.then(function () {
return false;
});
} else {
var sourceAbsolutePath = path.join(this._project.projectRoot, parentDir, fileRelativePath);
var destAbsolutePath = path.join(this._project.platformRoot, fileRelativePath);
if (!fs.existsSync(sourceAbsolutePath)) {
propagateChangePromise = deleteFile(destAbsolutePath)
.then(function () {
return false;
});
} else {
propagateChangePromise = this._copyFileWithDelay(sourceAbsolutePath, destAbsolutePath, this._reloadDelay)
.then(function () {
return true;
});
}
}
// Notify app-host. The delay is needed as a workaround on Windows, because shortly after copying the file, it is
// typically locked by the Firewall and can't be correctly sent by the server.
propagateChangePromise.then((shouldUpdateModifTime) => {
return utils.delay(this._reloadDelay)
.then(() => {
let props = { fileType: path.extname(fileRelativePath) };
if (shouldUpdateModifTime) {
this._project.updateTimeStampForFile(fileRelativePath, parentDir);
}
this._socket.emit('lr-file-changed', { fileRelativePath: fileRelativePath });
this._telemetry.sendTelemetry('live-reload', props);
});
})
.catch(function (err) {
// Fail gracefully if live reload fails for some reason
log.warning('Error in live reload processing changed file: ' + utils.stripErrorColon(err));
});
};