144Implement a browser IDE with syntax highlighting, files, tabs, and isolated code execution
hardAbout 90 minutesCodingidetokenizerweb-workersfile-systemarchitecture
Problem
Build the core of a CodeSandbox-style IDE: the parts behind the UI.
- File system
createFileSystem():writeFile(path, content)(creating parent folders),readFile(path),mkdir(path),rename(from, to)(moving a folder moves everything inside),remove(path)(recursive),exists(path),list(dir)(entry names, folders first, then alphabetical), andfiles()(every file path). Paths are absolute (/src/app.js); throw anErrorfor missing paths. - Tabs
createTabs():open(path)(no duplicates; activates it),close(path)(activates the tab to the right, else the left),setDirty(path, dirty),closeOthers(path),reopenClosed()(the most recently closed), andstate()returning{ tabs: [{ path, dirty }], active }. - Syntax highlighting
tokenize(code): an array of{ type, value }with typeskeyword,string(single, double and template quotes),number,comment(line and block),identifier,punctuationandwhitespace. Joining allvalues must give back the exact input. - Isolated execution
runProject(fs, entry, { timeout = 1000 }): run the project's JavaScript in a fresh Web Worker with a CommonJSrequirethat resolves relative paths between project files (require("./utils")→/src/utils.js), capturingconsole.loglines. Resolve{ logs }, or{ logs, error }if the code throws, or reject with an error named"TimeoutError"(terminating the worker) aftertimeoutms.
Try it yourself
Write your solution, run it, then submit to check it against the tests.
App.jsxReact + DOM
Step-by-step
Store a root folder { type: "dir", children: Map }. Resolving a path splits it on / and walks the maps. writeFile walks while creating missing folders; remove deletes the entry from its parent's map; rename detaches the node from the old parent and attaches it under the new name, so a folder's whole subtree moves in O(depth).
Unlock the full solution
What's inside
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Tests
Includes 2 code listings, 5 edge cases, 4 follow-up questions.
One-time payment by UPI, card or net banking. Launch price.