Skip to content

Commit

Permalink
$mol_build_server keep bundle files between reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Nov 14, 2024
1 parent 30bc340 commit b04f90c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
41 changes: 24 additions & 17 deletions build/build.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand Down
23 changes: 13 additions & 10 deletions build/server/server.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions file/base/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -341,7 +341,7 @@ namespace $ {
// то надо снова его обновить, вызвать логику, которая делала пуш в text.
// Например файл удалили, потом снова создали, версия поменялась - перезаписываем
// Если использовать version, то вновь созданный файл, через вотчер запустит свое пересоздание
if (next !== undefined) this.version()
if (next !== undefined) this.exists()
return this.text_int(next, virt)
}

Expand Down

0 comments on commit b04f90c

Please sign in to comment.