mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
Skip file removal on HMR interface
Summary: public We're not planning to accept file removals in the short term on the HMR interface so lets bail when a file is removed (before this this we were throwing when trying to get the shallow dependencies). Reviewed By: yungsters Differential Revision: D2810534 fb-gh-sync-id: f2733382f4a2619e22bdf1163aa4180694fff9f8
This commit is contained in:
committed by
facebook-github-bot-3
parent
a45219966c
commit
2b09614068
@@ -106,80 +106,85 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||
shallowDependencies,
|
||||
};
|
||||
|
||||
packagerServer.setHMRFileChangeListener(filename => {
|
||||
packagerServer.setHMRFileChangeListener((filename, stat) => {
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
return packagerServer.getShallowDependencies(filename)
|
||||
.then(deps => {
|
||||
if (!client) {
|
||||
return [];
|
||||
}
|
||||
stat.then(() => {
|
||||
return packagerServer.getShallowDependencies(filename)
|
||||
.then(deps => {
|
||||
if (!client) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// if the file dependencies have change we need to invalidate the
|
||||
// dependencies caches because the list of files we need to send
|
||||
// to the client may have changed
|
||||
const oldDependencies = client.shallowDependencies[filename];
|
||||
if (arrayEquals(deps, oldDependencies)) {
|
||||
return [packagerServer.getModuleForPath(filename)];
|
||||
}
|
||||
// if the file dependencies have change we need to invalidate the
|
||||
// dependencies caches because the list of files we need to send
|
||||
// to the client may have changed
|
||||
const oldDependencies = client.shallowDependencies[filename];
|
||||
if (arrayEquals(deps, oldDependencies)) {
|
||||
return [packagerServer.getModuleForPath(filename)];
|
||||
}
|
||||
|
||||
// if there're new dependencies compare the full list of
|
||||
// dependencies we used to have with the one we now have
|
||||
return getDependencies(client.platform, client.bundleEntry)
|
||||
.then(({
|
||||
dependenciesCache,
|
||||
dependenciesModulesCache,
|
||||
shallowDependencies,
|
||||
}) => {
|
||||
if (!client) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// build list of modules for which we'll send HMR updates
|
||||
const modulesToUpdate = [];
|
||||
Object.keys(dependenciesModulesCache).forEach(module => {
|
||||
if (!client.dependenciesModulesCache[module]) {
|
||||
modulesToUpdate.push(dependenciesModulesCache[module]);
|
||||
// if there're new dependencies compare the full list of
|
||||
// dependencies we used to have with the one we now have
|
||||
return getDependencies(client.platform, client.bundleEntry)
|
||||
.then(({
|
||||
dependenciesCache,
|
||||
dependenciesModulesCache,
|
||||
shallowDependencies,
|
||||
}) => {
|
||||
if (!client) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// build list of modules for which we'll send HMR updates
|
||||
const modulesToUpdate = [];
|
||||
Object.keys(dependenciesModulesCache).forEach(module => {
|
||||
if (!client.dependenciesModulesCache[module]) {
|
||||
modulesToUpdate.push(dependenciesModulesCache[module]);
|
||||
}
|
||||
});
|
||||
|
||||
// invalidate caches
|
||||
client.dependenciesCache = dependenciesCache;
|
||||
client.dependenciesModulesCache = dependenciesModulesCache;
|
||||
client.shallowDependencies = shallowDependencies;
|
||||
|
||||
return modulesToUpdate;
|
||||
});
|
||||
})
|
||||
.then(modulesToUpdate => {
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
// invalidate caches
|
||||
client.dependenciesCache = dependenciesCache;
|
||||
client.dependenciesModulesCache = dependenciesModulesCache;
|
||||
client.shallowDependencies = shallowDependencies;
|
||||
// make sure the file was modified is part of the bundle
|
||||
if (!client.shallowDependencies[filename]) {
|
||||
return;
|
||||
}
|
||||
|
||||
return modulesToUpdate;
|
||||
return packagerServer.buildBundleForHMR({
|
||||
entryFile: client.bundleEntry,
|
||||
platform: client.platform,
|
||||
modules: modulesToUpdate,
|
||||
});
|
||||
})
|
||||
.then(modulesToUpdate => {
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
})
|
||||
.then(bundle => {
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the file was modified is part of the bundle
|
||||
if (!client.shallowDependencies[filename]) {
|
||||
return;
|
||||
}
|
||||
|
||||
return packagerServer.buildBundleForHMR({
|
||||
entryFile: client.bundleEntry,
|
||||
platform: client.platform,
|
||||
modules: modulesToUpdate,
|
||||
// check we actually want to send an HMR update
|
||||
if (bundle) {
|
||||
client.ws.send(bundle);
|
||||
}
|
||||
});
|
||||
})
|
||||
.then(bundle => {
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check we actually want to send an HMR update
|
||||
if (bundle) {
|
||||
client.ws.send(bundle);
|
||||
}
|
||||
})
|
||||
.done();
|
||||
},
|
||||
() => {
|
||||
// do nothing, file was removed
|
||||
},
|
||||
).done();
|
||||
});
|
||||
|
||||
client.ws.on('error', e => {
|
||||
|
||||
Reference in New Issue
Block a user