Skip to content

Commit 3098097

Browse files
authored
Update file watcher and remove elide lines (onlook-dev#1693)
* Remove elide lines * Remove atomic write and update file watcher
1 parent 8ad6bc1 commit 3098097

File tree

8 files changed

+175
-198
lines changed

8 files changed

+175
-198
lines changed

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env sh
2-
bun run lint:precommit && bun run format:precommit && git add .
2+
bun run lint && bun run format && git add .

apps/studio/electron/main/assets/images.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { DefaultSettings } from '@onlook/models/constants';
33
import { promises as fs, readFileSync } from 'fs';
44
import mime from 'mime-lite';
55
import path from 'path';
6-
import writeFileAtomic from 'write-file-atomic';
76

87
async function scanImagesDirectory(projectRoot: string): Promise<ImageContentData[]> {
98
const imagesPath = path.join(projectRoot, DefaultSettings.IMAGE_FOLDER);
@@ -167,7 +166,7 @@ async function updateImageReferences(
167166
return;
168167
}
169168
const updatedContent = content.replace(pattern, newImageUrl);
170-
await writeFileAtomic(file, updatedContent, { encoding: 'utf8' });
169+
await fs.writeFile(file, updatedContent, 'utf8');
171170
}),
172171
);
173172
}

apps/studio/electron/main/code/files.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { existsSync, promises as fs } from 'fs';
22
import * as path from 'path';
33
import prettier from 'prettier';
4-
import writeFileAtomic from 'write-file-atomic';
54

65
export async function readFile(filePath: string): Promise<string | null> {
76
try {
@@ -48,9 +47,7 @@ export async function writeFile(
4847
// Ensure parent directory exists
4948
const parentDir = path.dirname(fullPath);
5049
await fs.mkdir(parentDir, { recursive: true });
51-
52-
// Perform atomic write with proper error handling
53-
await writeFileAtomic(fullPath, fileContent, { encoding });
50+
await fs.writeFile(fullPath, fileContent, { encoding });
5451

5552
if (isNewFile) {
5653
console.log('New file created:', fullPath);

apps/studio/electron/main/run/index.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class RunManager {
1414
private static instance: RunManager;
1515
private mapping = new Map<string, TemplateNode>();
1616
private subscription: AsyncSubscription | null = null;
17+
private selfModified = new Set<string>();
1718
state: RunState = RunState.STOPPED;
1819
runningDirs = new Set<string>();
1920
createdFiles = new Set<string>();
@@ -129,23 +130,21 @@ class RunManager {
129130

130131
this.subscription = await subscribe(
131132
folderPath,
132-
(err, events) => {
133+
async (err, events) => {
133134
if (err) {
134135
console.error(`Watcher error: ${err}`);
135136
return;
136137
}
137138

138139
for (const event of events) {
139-
if (event.type === 'update') {
140+
if (this.selfModified.has(event.path)) {
141+
this.selfModified.delete(event.path);
142+
continue;
143+
}
144+
if (event.type === 'update' || event.type === 'create') {
140145
if (this.isAllowedExtension(event.path)) {
141-
this.processFileForMapping(event.path);
142-
}
143-
} else if (event.type === 'create') {
144-
if (!this.createdFiles.has(event.path)) {
145-
if (this.isAllowedExtension(event.path)) {
146-
this.processFileForMapping(event.path);
147-
}
148-
this.createdFiles.add(event.path);
146+
this.selfModified.add(event.path);
147+
await this.processFileForMapping(event.path);
149148
}
150149
}
151150
}
@@ -182,6 +181,7 @@ class RunManager {
182181
}
183182

184183
await writeFile(filePath, content);
184+
185185
for (const [key, value] of Object.entries(newMapping)) {
186186
this.mapping.set(key, value);
187187
}
@@ -195,6 +195,7 @@ class RunManager {
195195
await this.clearSubscription();
196196
this.runningDirs.clear();
197197
this.mapping.clear();
198+
this.selfModified.clear();
198199
}
199200

200201
async cleanProjectDir(folderPath: string): Promise<void> {

apps/studio/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
"ts-morph": "^25.0.0",
8686
"type-fest": "^4.26.1",
8787
"use-resize-observer": "^9.1.0",
88-
"write-file-atomic": "^6.0.0",
8988
"zod": "^3.23.8"
9089
},
9190
"devDependencies": {
@@ -105,7 +104,6 @@
105104
"@types/react": "^18.2.64",
106105
"@types/react-dom": "^18.2.21",
107106
"@types/shell-quote": "^1.7.5",
108-
"@types/write-file-atomic": "^4.0.3",
109107
"@vitejs/plugin-react": "^4.2.1",
110108
"autoprefixer": "^10.4.20",
111109
"css-tree": "^3.1.0",

bun.lock

Lines changed: 148 additions & 164 deletions
Large diffs are not rendered by default.

bun.lockb

-641 KB
Binary file not shown.

package.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,21 @@
1616
],
1717
"scripts": {
1818
"build:foundation": "bun --filter @onlook/foundation build",
19-
"build:cli": "bun build:foundation && bun --elide-lines 0 --filter onlook typecheck && bun --elide-lines 0 --filter onlook build",
20-
"build:studio": "bun build:foundation && bun --elide-lines 0 --filter @onlook/studio build",
19+
"build:cli": "bun build:foundation && bun --filter onlook typecheck && bun --filter onlook build",
20+
"build:studio": "bun build:foundation && bun --filter @onlook/studio build",
2121
"clean": "git clean -xdf node_modules",
22-
"clean:workspaces": "bun --elide-lines 0 --filter '*' clean",
23-
"db:gen": "bun --elide-lines 0 --filter @onlook/supabase db:gen",
24-
"db:gen:local": "bun --elide-lines 0 --filter @onlook/backend db:gen",
25-
"dev:foundation": "bun --elide-lines 0 --filter @onlook/foundation dev",
26-
"dev:studio": "bun --elide-lines 0 --filter @onlook/studio dev",
27-
"build": "bun --elide-lines 0 --filter '*' build",
22+
"clean:workspaces": "bun --filter '*' clean",
23+
"db:gen": "bun --filter @onlook/supabase db:gen",
24+
"db:gen:local": "bun --filter @onlook/backend db:gen",
25+
"dev:foundation": "bun --filter @onlook/foundation dev",
26+
"dev:studio": "bun --filter @onlook/studio dev",
27+
"build": "bun --filter '*' build",
2828
"ci:build": "bun run build:foundation && bun --filter '*' build",
29-
"dev": "bun --elide-lines 0 --filter '*' dev",
30-
"test": "bun --elide-lines 0 --filter '*' test",
31-
"format": "bun --elide-lines 0 --filter '*' format",
32-
"format:precommit": "bun --filter '*' format",
33-
"lint": "bun --elide-lines 0 --filter @onlook/studio lint",
34-
"lint:precommit": "bun --filter @onlook/studio lint",
35-
"typecheck": "bun --elide-lines 0 --filter '*' typecheck",
29+
"dev": "bun --filter '*' dev",
30+
"test": "bun --filter '*' test",
31+
"format": "bun --filter '*' format",
32+
"lint": "bun --filter @onlook/studio lint",
33+
"typecheck": "bun --filter '*' typecheck",
3634
"increment_tag": "./scripts/increment_tag.sh",
3735
"publish_tag": "./scripts/publish_tag.sh",
3836
"remove_tag": "./scripts/remove_tag.sh",

0 commit comments

Comments
 (0)