diff --git a/packages/backend/src/SelfhostedModule.js b/packages/backend/src/SelfhostedModule.js index 60b04716..563f029a 100644 --- a/packages/backend/src/SelfhostedModule.js +++ b/packages/backend/src/SelfhostedModule.js @@ -28,7 +28,7 @@ class SelfhostedModule extends AdvancedBase { command: 'npx', args: ['rollup', '-c', 'rollup.config.js', '--watch'], env: { - PUTER_JS_URL: config.origin + '/sdk/puter.dev.js', + PUTER_JS_URL: ({ global_config: config }) => config.origin + '/sdk/puter.dev.js', } }, { @@ -37,7 +37,7 @@ class SelfhostedModule extends AdvancedBase { command: 'npx', args: ['rollup', '-c', 'rollup.config.js', '--watch'], env: { - PUTER_JS_URL: config.origin + '/sdk/puter.dev.js', + PUTER_JS_URL: ({ global_config: config }) => config.origin + '/sdk/puter.dev.js', } }, ], diff --git a/packages/backend/src/services/DevWatcherService.js b/packages/backend/src/services/DevWatcherService.js index a62c0307..d8fcdae3 100644 --- a/packages/backend/src/services/DevWatcherService.js +++ b/packages/backend/src/services/DevWatcherService.js @@ -40,12 +40,20 @@ class DevWatcherService extends BaseService { } async _init (args) { - const { root, commands } = args; + this.args = args; process.on('exit', () => { this.exit_all_(); }) - + } + + // Oh geez we need to wait for the web server to initialize + // so that `config.origin` has the actual port in it if the + // port is set to `auto` - you have no idea how confusing + // this was to debug the first time, like Ahhhhhh!! + // but hey at least we have this convenient event listener. + async ['__on_ready.webserver'] () { + const { root, commands } = this.args; for ( const entry of commands ) { const { directory } = entry; const fullpath = this.modules.path.join( @@ -65,11 +73,18 @@ class DevWatcherService extends BaseService { async start_ ({ name, fullpath, command, args, env }) { this.log.info(`Starting ${name} in ${fullpath}`); + const env_processed = { ...(env ?? {}) }; + for ( const k in env_processed ) { + if ( typeof env_processed[k] !== 'function' ) continue; + env_processed[k] = env_processed[k]({ + global_config: this.global_config + }); + } const proc = this.modules.spawn(command, args, { shell: true, env: { ...process.env, - ...(env ?? {}), + ...env_processed, }, cwd: fullpath, });