MCPcopy
hub / github.com/stackblitz/bolt.new / saveFile

Method saveFile

app/lib/stores/files.ts:83–114  ·  view source on GitHub ↗
(filePath: string, content: string)

Source from the content-addressed store, hash-verified

81 }
82
83 async saveFile(filePath: string, content: string) {
84 const webcontainer = await this.#webcontainer;
85
86 try {
87 const relativePath = nodePath.relative(webcontainer.workdir, filePath);
88
89 if (!relativePath) {
90 throw new Error(`EINVAL: invalid file path, write '${relativePath}'`);
91 }
92
93 const oldContent = this.getFile(filePath)?.content;
94
95 if (!oldContent) {
96 unreachable('Expected content to be defined');
97 }
98
99 await webcontainer.fs.writeFile(relativePath, content);
100
101 if (!this.#modifiedFiles.has(filePath)) {
102 this.#modifiedFiles.set(filePath, oldContent);
103 }
104
105 // we immediately update the file and don't rely on the `change` event coming from the watcher
106 this.files.setKey(filePath, { type: 'file', content, isBinary: false });
107
108 logger.info('File updated');
109 } catch (error) {
110 logger.error('Failed to update file content\n\n', error);
111
112 throw error;
113 }
114 }
115
116 async #init() {
117 const webcontainer = await this.#webcontainer;

Callers

nothing calls this directly

Calls 2

getFileMethod · 0.95
unreachableFunction · 0.90

Tested by

no test coverage detected