From b04f90c47efc6a7a6f114fbfbdb7d9ff4b4e7861 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Thu, 14 Nov 2024 22:32:55 +0300 Subject: [PATCH] $mol_build_server keep bundle files between reloads --- build/build.node.ts | 41 ++++++++++++++++++++++--------------- build/server/server.node.ts | 23 ++++++++++++--------- file/base/base.ts | 4 ++-- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/build/build.node.ts b/build/build.node.ts index 1e1cf6ba09..f00e182721 100644 --- a/build/build.node.ts +++ b/build/build.node.ts @@ -37,27 +37,34 @@ namespace $ { const build = this.$.$mol_build.relative( '.', paths ) if( paths.length > 0 ) { - process.exit(build.start() ? 0 : 1) + try { + for (const path_raw of paths) { + const path = build.root().resolve( path_raw ).path() + build.bundleAll( path ) + } + process.exit(0) + } catch( error: any ) { + if( $mol_fail_catch( error ) ) { + this.$.$mol_log3_fail({ + place: '$mol_build_start' , + message: error.message, + trace: error.stack, + }) + } + + process.exit(1) + } } else { - Promise.resolve().then( ()=> build.server().start() ) + Promise.resolve().then( ()=> { + try { + build.server().start() + } catch (error) { + $mol_fail_log(error) + } + } ) } } - start() { - try { - return this.paths().map( path => this.bundleAll( this.root().resolve( path ).path() ) ) - } catch (error: any) { - if ($mol_fail_catch(error)) { - this.$.$mol_log3_fail({ - place: `${this}.start()` , - message: error.message, - trace: error.stack, - }) - } - return null - } - } - @ $mol_mem_key metaTreeTranspile( path : string ) { diff --git a/build/server/server.node.ts b/build/server/server.node.ts index b318481bb3..9196a0bb03 100644 --- a/build/server/server.node.ts +++ b/build/server/server.node.ts @@ -248,22 +248,20 @@ namespace $ { return socket } - + @ $mol_mem_key - notify( [ line, path ]: [ InstanceType<$node['ws']['WebSocket']>, string ] ) { - + bundle_changed_at( path: string ) { + $mol_wire_solid() try { const build = this.build() const bundle = build.root().resolve( path ) - + const sources = build.sourcesAll([ bundle.path() , [ 'node' ] ]) + const resources = build.bundleFiles([ bundle.path() , [ 'node' ] ]) // watch changes - const sources = [ - ...build.sourcesAll([ bundle.path() , [ 'node' ] ]), - ...build.bundleFiles([ bundle.path() , [ 'node' ] ]) - ] + // прописанные в meta.tree ресурсы, должны при изменении триггерить location.reload - for( const src of sources ) src.version() + for( const src of [...sources, ...resources] ) src.version() } catch (error) { if ($mol_fail_catch(error)) { this.$.$mol_log3_fail({ @@ -273,7 +271,12 @@ namespace $ { }) } } - + return new Date() + } + + @ $mol_mem_key + notify( [ line, path ]: [ InstanceType<$node['ws']['WebSocket']>, string ] ) { + this.bundle_changed_at(path) // ignore initial if( !$mol_mem_cached( ()=> this.notify([ line, path ]) ) ) return true diff --git a/file/base/base.ts b/file/base/base.ts index 60c53553c6..150b0582cb 100644 --- a/file/base/base.ts +++ b/file/base/base.ts @@ -304,7 +304,7 @@ namespace $ { const exists = Boolean( this.stat() ) - console.log('exists current', exists, 'next', next, this.path()) + // console.log('exists current', exists, 'next', next, this.path()) if( next === undefined ) return exists if( next === exists ) return exists @@ -341,7 +341,7 @@ namespace $ { // то надо снова его обновить, вызвать логику, которая делала пуш в text. // Например файл удалили, потом снова создали, версия поменялась - перезаписываем // Если использовать version, то вновь созданный файл, через вотчер запустит свое пересоздание - if (next !== undefined) this.version() + if (next !== undefined) this.exists() return this.text_int(next, virt) }