MCPcopy Create free account
hub / github.com/codesandbox/codesandbox-client / updateData

Method updateData

packages/sandpack-core/src/manager.ts:1205–1304  ·  view source on GitHub ↗

* Find all changed, added and deleted modules. Update trees and * delete caches accordingly

(modules: {
    [path: string]: Module;
  })

Source from the content-addressed store, hash-verified

1203 * delete caches accordingly
1204 */
1205 async updateData(modules: {
1206 [path: string]: Module;
1207 }): Promise<Array<TranspiledModule>> {
1208 this.transpileJobs = {};
1209 this.hardReload = false;
1210
1211 this.modules = modules;
1212
1213 const addedModules: Array<Module> = [];
1214 const updatedModules: Array<Module> = [];
1215
1216 // File structure likely changed, reset resolver cache
1217 this.resetResolverCache();
1218
1219 Object.keys(modules).forEach(k => {
1220 const module: Module = modules[k];
1221 const mirrorModule = this.transpiledModules[k];
1222
1223 if (!mirrorModule) {
1224 addedModules.push(module);
1225 } else if (mirrorModule.module.code !== module.code) {
1226 updatedModules.push(module);
1227 }
1228 });
1229
1230 this.getModules().forEach(m => {
1231 if (
1232 !m.path.startsWith('/node_modules') &&
1233 m.path !== '/var/task/node_modules/browser-resolve/empty.js' &&
1234 !isUrl(m.path) &&
1235 !modules[m.path] &&
1236 !(m as ChildModule).parent // not an emitted module
1237 ) {
1238 this.removeModule(m);
1239 }
1240 });
1241
1242 addedModules.forEach(m => {
1243 this.addTranspiledModule(m);
1244 });
1245
1246 const modulesToUpdate: Array<Module> = uniq([
1247 ...addedModules,
1248 ...updatedModules,
1249 ]);
1250
1251 // We eagerly transpile changed files,
1252 // this way we don't have to traverse the whole
1253 // dependency graph each time a file changes
1254 const tModulesToUpdate = modulesToUpdate.map(m => this.updateModule(m));
1255
1256 if (tModulesToUpdate.length > 0 && this.configurations.sandbox) {
1257 this.hardReload =
1258 this.hardReload ||
1259 this.configurations.sandbox.parsed.hardReloadOnChange;
1260 }
1261
1262 const modulesWithErrors = this.getTranspiledModules().filter(t => {

Callers 1

updateManagerFunction · 0.80

Calls 15

resetResolverCacheMethod · 0.95
getModulesMethod · 0.95
removeModuleMethod · 0.95
addTranspiledModuleMethod · 0.95
updateModuleMethod · 0.95
getTranspiledModulesMethod · 0.95
isUrlFunction · 0.90
resetTranspilationMethod · 0.80
shouldTranspileMethod · 0.80
transpileMethod · 0.80
forEachMethod · 0.65
keysMethod · 0.65

Tested by

no test coverage detected