MCPcopy Create free account
hub / github.com/dailydotdev/apps / rebuildFile

Function rebuildFile

packages/world-cli/src/dev.js:207–328  ·  view source on GitHub ↗
(file, why)

Source from the content-addressed store, hash-verified

205 };
206
207 const rebuildFile = async (file, why) => {
208 if (!(await exists(file))) {
209 return { upserts: [], removals: removeFile(file), reports: [] };
210 }
211
212 const source = await readFile(file, "utf8");
213 const sourceHash = hashSource(source);
214 if (fileHashes.get(file) === sourceHash) {
215 return { upserts: [], removals: [], reports: [] };
216 }
217
218 const realm = realmForFile(file);
219 const override = realm ? null : targetForOverride(file, targets);
220 if (!realm && !override) {
221 return { upserts: [], removals: [], reports: [] };
222 }
223 if (override?.error) {
224 process.stderr.write(`FAIL ${why}: ${file}\n${override.error}\n\n`);
225 return { upserts: [], removals: [], reports: [] };
226 }
227
228 const loaded = await loadModule(file, source);
229 const upserts = [];
230 const reports = [];
231 const removals = [];
232
233 if (loaded.error) {
234 const message = String(loaded.error.message || loaded.error).split(
235 "\n"
236 )[0];
237 const owned = [...builders.values()].filter(
238 (builder) => builder.file === file
239 );
240 /* A file that has never built still gets a failure report — a broken
241 file that reports nothing reads as "waiting" everywhere. Its exports
242 are unknowable before it evaluates, so the failure is pinned to one
243 well-known family. */
244 const failed = owned.length
245 ? owned.map((builder) => builder.target)
246 : [
247 override ?? {
248 scope: "realm",
249 realm,
250 niche: null,
251 family: "house",
252 level: null,
253 },
254 ];
255 for (const target of failed) {
256 const result = install(file, target, {
257 ok: false,
258 sourceHash,
259 realm: target.realm,
260 niche: target.niche ?? null,
261 family: target.family,
262 level: target.level ?? null,
263 errors: [message],
264 warnings: [],

Callers 2

flushFunction · 0.85
startDevFunction · 0.85

Calls 11

hashSourceFunction · 0.90
loadModuleFunction · 0.90
runRealmBuilderFunction · 0.90
runBuilderFunction · 0.90
realmForFileFunction · 0.85
targetForOverrideFunction · 0.85
installFunction · 0.85
getMethod · 0.80
pushMethod · 0.80
existsFunction · 0.70
removeFileFunction · 0.70

Tested by

no test coverage detected