Repository navigation
[WIP] Refactors to support running in node - #9440
davepagurek wants to merge 13 commits into
Conversation
| import { _globalInit } from './core/init'; | ||
| import { waitForDocumentReady } from '#platform'; |
There was a problem hiding this comment.
The idea for is to use the app.node.js entry point instead of reusing this one. The other entry point simply don't have the global mode stuff. Would that solution work instead?
If some kind of global mode sketch is preferred, I think the experimental new instance mode p5.ni.js probably can fit in for it?
There was a problem hiding this comment.
that can work, but might not solve the whole problem, because currently the platform-specific calls are scattered kind of everywhere. Having one #platform file to import from works around that. An alternative could be to have app.node.js put an object on the p5 global with those, so that the references everywhere in p5 could grab it from e.g. p5.platform.handleUncaughtErrors?
There was a problem hiding this comment.
I think we can still use the #platform import idea with the app.node.js approach. The question is more around the intended usage pattern:
- What import would a node.js app use vs a browser. The idea for the
app.node.jsis toimport p5 from "p5/node"and frontend appsimport p5 from "p5"which bundlers can treeshake. - The node.js build don't need to be bundled, just transformed where necessary, meaning
app.node.esm.jswon't be needed as node.js can import the transformedapp.node.jsfromp5/nodeexports and resolve normally from there. Unless the idea is to support kinda Deno style URL import where a singled bundled file would be more straightforward?
There was a problem hiding this comment.
oh I see. remind me, how does it work currently if you import p5 from an environment that does tree shaking? iirc we still serve built files to some degree to have things like the GLSL imports work? If so, is that system flexible enough to be used for node too, possibly just through an alternate entrypoint if we think initialization would be easier?
If some kind of global mode sketch is preferred, I think the experimental new instance mode p5.ni.js probably can fit in for it?
I think supporting something something like that would be good. I also wonder how possible it is for "true" global mode to work in node. Does globalThis work similarly in node where if you make a function setup() {} it's accessible on globalThis like in the browser? If we hit any weirdness then a p5.ni approach sounds like the right call and we can move that into the core.
WIP! Trying out some stuff to get a nodejs build to work.
platformfile for methods that should have separate implementations on node. Just doing the quick thing for now, these APIs probably need more considerationp5.Imageis gonna be a big one so I'm just avoiding it