fix(core): allow buffers for nonexistent files
MODIFY
internal/core/server/Server.ts
internal/core/server/Server.ts
@@ -130,6 +130,10 @@ export type ServerRefreshFile =
| {
type: "BUFFER_UPDATE";
path: AbsoluteFilePath;
+ }
+ | {
+ type: "BUFFER_CLEARED";
+ path: AbsoluteFilePath;
};
export default class Server {

MODIFY
internal/core/server/ServerRequest.ts
internal/core/server/ServerRequest.ts
@@ -933,11 +933,12 @@ export default class ServerRequest {
): Promise<void> {
this.checkCancelled();
+ const mtimeNs = this.server.memoryFs.addBuffer(path, content);
+
await this.wrapRequestDiagnostic(
"updateBuffer",
path,
async (bridge, ref) => {
- const mtimeNs = this.server.memoryFs.addBuffer(path, content);
await bridge.events.updateBuffer.call({
ref,
buffer: {
@@ -986,7 +987,7 @@ export default class ServerRequest {
await bridge.events.clearBuffer.call({ref});
this.server.memoryFs.clearBuffer(path);
this.server.refreshFileEvent.push({
- type: "BUFFER_UPDATE",
+ type: "BUFFER_CLEARED",
path,
});
},

MODIFY
internal/core/server/fs/FileAllocator.ts
internal/core/server/fs/FileAllocator.ts
@@ -165,7 +165,7 @@ export default class FileAllocator {
const {path} = event;
// Workers handle cache eviction internally when updating buffers
- if (event.type === "BUFFER_UPDATE") {
+ if (event.type === "BUFFER_UPDATE" || event.type === "BUFFER_CLEARED") {
continue;
}

MODIFY
internal/core/server/fs/MemoryFileSystem.ts
internal/core/server/fs/MemoryFileSystem.ts
@@ -640,7 +640,7 @@ export default class MemoryFileSystem {
}
public getFileStats(path: AbsoluteFilePath): undefined | SimpleStats {
- return this.files.get(path);
+ return this.buffers.get(path) ?? this.files.get(path);
}
public getFileStatsAssert(path: AbsoluteFilePath): SimpleStats {
@@ -901,7 +901,11 @@ export default class MemoryFileSystem {
public exists(path: AbsoluteFilePath): undefined | boolean {
// if we have this in our cache then the file exists
- if (this.files.has(path) || this.directories.has(path)) {
+ if (
+ this.buffers.has(path) ||
+ this.files.has(path) ||
+ this.directories.has(path)
+ ) {
return true;
}

MODIFY
internal/core/server/project/ProjectManager.ts
internal/core/server/project/ProjectManager.ts
@@ -107,7 +107,7 @@ export default class ProjectManager {
this.server.resources.add(
this.server.refreshFileEvent.subscribe((events) => {
for (const {path, type} of events) {
- if (type === "DELETED") {
+ if (type === "DELETED" || type === "BUFFER_CLEARED") {
this.handleDeleted(path);
}
}

fix(core): allow buffers for nonexistent files (#1629)