raphaelameaume / fragment

[alpha] A web development environment for creative coding
https://fragment.tools
MIT License
828 stars 19 forks source link

Run multiple sketches in the same folder #88

Closed raphaelameaume closed 8 months ago

raphaelameaume commented 8 months ago

This PR fixes a conflict between servers and sketches when running multiple fragment commands from the same folder at the same time.

Details

When running a sketch fragment writes a file on start used for hot-reloading at node_modules/.fragment/sketches.js. But if two sketches shares this filepath, the second command will override the previously written file by the first command with path data for the second sketch. This issue would not be visible as long as the first sketch was open in the browser before running the second command and if the first browser window was never reloaded after that. Otherwise, the first server would load the second sketch after a hard reload, creating a mismatch between the sketch the server is supposed to render and what it is actually rendered.

This fixes this conflict by reusing the sketch filename to create the file needed for hot reloading. The file is now node_modules/.fragment/[sketch-filename].js, so two different sketches won't try to read from the same file when trying to hot-reload anymore.