Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$mol_build refactor extracted graph #708

Merged
merged 80 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
3d0537b
$mol_build refactor extracted graph
zerkalica Oct 9, 2024
82975ca
$mol_build_graph fixes
zerkalica Oct 10, 2024
dcbd80d
$mol_build_grap fix
zerkalica Oct 10, 2024
d864bca
$mol_file no watch if mol_run affects something in wathing path deep
zerkalica Oct 11, 2024
0b600ab
$mol_file lock watcher while running dirty command
zerkalica Oct 12, 2024
4d1438d
$mol_file locking variant 2
zerkalica Oct 12, 2024
65160b0
$mol_build_graph fix checkdep: used mol_mem_key
zerkalica Oct 12, 2024
3b029b4
$mol_build object keys to tuple keys
zerkalica Oct 12, 2024
1c839a9
$mol_run waits running $mol_file resets, file resets waiting dirty $m…
zerkalica Oct 13, 2024
eb8bbaa
$mol_file run locking improved
zerkalica Oct 14, 2024
a9926f0
$mol_file run locking improved 2
zerkalica Oct 14, 2024
8bff094
$mol_run, $mol_file locks alt
zerkalica Oct 16, 2024
0a91631
$mol_run lock fixed
zerkalica Oct 16, 2024
8d72bf2
$mol_file safe push-style reset
zerkalica Oct 16, 2024
f45c3b8
$mol_run_lock type fix
zerkalica Oct 16, 2024
9904ccb
$mol_run graph improvement fixes
zerkalica Oct 18, 2024
48d0c91
$mol_file fix place name
zerkalica Oct 18, 2024
787b316
$mol_build_server simplify middleware
zerkalica Oct 18, 2024
f02cf61
$mol_build reload fixes
zerkalica Oct 20, 2024
f6bc8fa
$mol_build, refactor
zerkalica Oct 20, 2024
e34f24a
$mol_build minimal refactor, support git bisect
zerkalica Oct 20, 2024
43126ad
$mol_build refactor repo text
zerkalica Oct 21, 2024
545650f
$mol_lock refactor, moved to mol root
zerkalica Oct 21, 2024
e420598
$mol_build, fix process exit code
zerkalica Oct 21, 2024
d95f397
$mol_build_server fix reload page on files changed
zerkalica Oct 21, 2024
24da36d
$mol_build copy sync
zerkalica Oct 21, 2024
87435ef
$mol_file improve copy api
zerkalica Oct 21, 2024
d745dd3
$mol_file improve copy api 2
zerkalica Oct 21, 2024
ff38c94
$mol_file improve copy api 3
zerkalica Oct 21, 2024
7701c8a
$mol_file use stat, not buffer
zerkalica Oct 21, 2024
10ac8b2
$mol_file copy api refactor
zerkalica Oct 21, 2024
b4a0e28
$mol_file copy api refactor 2
zerkalica Oct 21, 2024
93bd347
$mol_build web.js restart fix
zerkalica Oct 22, 2024
a8896b6
$mol_build refactor extracted $mol_build_ensure
zerkalica Oct 23, 2024
ae6976b
$mol_run fallback to sync spawn otside fiber
zerkalica Oct 23, 2024
c385d04
$mol_run fallback to sync spawn otside fiber - fix
zerkalica Oct 23, 2024
680ede4
$mol_run more error handling
zerkalica Oct 23, 2024
19019d8
$mol_exec fix type
zerkalica Oct 23, 2024
fa8897c
$mol_build_ensurer plugins, async fixes
zerkalica Oct 23, 2024
7cafb64
$mol_build_ensure fix reset after clone
zerkalica Oct 23, 2024
2626c91
$mol_build refactor, better git pull
zerkalica Oct 25, 2024
6639b3b
$mol_build_server wait middleware promise groupped by url
zerkalica Oct 25, 2024
92fefe7
$mol_build git ensure fixes
zerkalica Nov 7, 2024
2ce6e03
$mol_run, check env
zerkalica Nov 7, 2024
f85d863
$mol_file fix remove directory
zerkalica Nov 10, 2024
a011a48
$mol_file refactor
zerkalica Nov 11, 2024
03baf24
$mol_file use this type
zerkalica Nov 12, 2024
a039ae2
$mol_file webdav
zerkalica Nov 12, 2024
d9648f3
$mol_file webdav
zerkalica Nov 13, 2024
30c5ac3
$mol_file webdav 2
zerkalica Nov 13, 2024
0b98ef2
$mol_build refactor git pull
zerkalica Nov 14, 2024
2d6216e
$mol_build_server refactor, restart bugs with request
zerkalica Nov 14, 2024
c7666cb
$mol_build_server fixes
zerkalica Nov 14, 2024
ce72866
$mol_view_tre2_to_dts fix idempotency, this? fix
zerkalica Nov 14, 2024
9540ab3
tmp
zerkalica Nov 14, 2024
565164f
$mol_view_tree2_to_dts fix unique prefix
zerkalica Nov 14, 2024
24ab884
$mol_build fixes
zerkalica Nov 14, 2024
30bc340
$mol_view_tree2_to_dts fix simplify args
zerkalica Nov 14, 2024
b04f90c
$mol_build_server keep bundle files between reloads
zerkalica Nov 14, 2024
48301eb
$mol_build fix naming, better keep bundle
zerkalica Nov 14, 2024
1e3f94f
Merge branch 'master' of github.com:hyoo-ru/mam_mol into fix-run
zerkalica Nov 15, 2024
1742d9e
Merge branch 'master' of github.com:hyoo-ru/mam_mol into fix-run
zerkalica Nov 15, 2024
8186ecc
$mol_file watcher native fix
zerkalica Nov 15, 2024
47ef4b4
$mol_file fix root dir detection
zerkalica Nov 15, 2024
8b8cef1
Merge branch 'master' of github.com:hyoo-ru/mam_mol into fix-run
zerkalica Nov 17, 2024
bd93d41
$mol_file comments
zerkalica Nov 19, 2024
e3a232e
$mol_build_server keep bundles if page opened
zerkalica Nov 19, 2024
71c539e
$mol_build_server comment change
zerkalica Nov 20, 2024
a8a8612
Merge branch 'master' of github.com:hyoo-ru/mam_mol into fix-run
zerkalica Nov 20, 2024
84c1e4a
Merge branch 'master' of github.com:hyoo-ru/mam_mol into fix-run
zerkalica Nov 25, 2024
237a60e
Merge branch 'master' of github.com:hyoo-ru/mam_mol into fix-run
zerkalica Nov 26, 2024
12aab4d
$mol_build git version fix
zerkalica Nov 26, 2024
d0270c8
Merge branch 'master' of github.com:hyoo-ru/mam_mol into fix-run
zerkalica Dec 13, 2024
419ca32
Merge branch 'master' of github.com:hyoo-ru/mam_mol into fix-run
zerkalica Dec 17, 2024
2281465
Merge branch 'master' of github.com:hyoo-ru/mam_mol into fix-run
zerkalica Dec 18, 2024
4a0d062
$mol_file fix ts 5.7 typings
zerkalica Dec 18, 2024
bb93e68
$mol_file disabe verbose logs, fix typings
zerkalica Dec 18, 2024
4555a7a
$mol_file_transaction added
zerkalica Dec 19, 2024
0dbeaff
Merge branch 'master' of github.com:hyoo-ru/mam_mol into fix-run
zerkalica Dec 19, 2024
e75f34c
$mol_file_transaction write support array of buffer and string
zerkalica Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
829 changes: 323 additions & 506 deletions build/build.node.ts

Large diffs are not rendered by default.

40 changes: 26 additions & 14 deletions build/client/client.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
function $mol_build_client() {

const origin = document.location.origin.replace( /^http/ , 'ws' )
const path = document.location.pathname
const uri = origin + path
// @ts-check

const socket = new WebSocket( uri )

socket.onclose = ()=> setTimeout( ()=> $mol_build_client() , 1000 )

socket.onmessage = message => {
if( message.data !== '$mol_build_obsolete' ) return
location.reload()
}
class $mol_build_client {
static closed = false
static run() {
const origin = document.location.origin.replace( /^http/ , 'ws' )
const path = document.location.pathname
const uri = origin + path

const socket = new WebSocket( uri )

socket.onclose = ()=> {
this.closed = true
setTimeout( ()=> $mol_build_client.run() , 1000 )
}

socket.onopen = () => {
if (this.closed) location.reload()
this.closed = false
}

socket.onmessage = message => {
if( message.data !== '$mol_build_obsolete' ) return
location.reload()
}

}
}

$mol_build_client()
$mol_build_client.run()

72 changes: 72 additions & 0 deletions build/ensure/ensure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
namespace $ {
export interface $mol_build_ensure_plugin {
ensure(path: string): boolean
}

export class $mol_build_ensure extends $mol_object {
root() { return $mol_file.absolute('') }

interactive() { return process.stdout.isTTY }
pull_timeout() { return 120000 }

@ $mol_mem_key
meta( path : string ) {

let decls = [] as $mol_tree2[]

const pack = this.$.$mol_file.absolute( path )

for( const file of pack.sub() ) {
if( !/\.meta\.tree$/.test( file.name() ) ) continue
decls = decls.concat( this.$.$mol_tree2_from_string( file.text() , file.path() ).kids )
}

return decls.length ? this.$.$mol_tree2.list(decls, decls[0]?.span) : null
}

@ $mol_mem
ensurer_git(): $mol_build_ensure_plugin {
return this.$.$mol_build_ensure_git.make({
root: () => this.root(),
meta: path => this.meta(path),
pull_timeout: () => this.pull_timeout(),
interactive: () => this.interactive(),
})
}

@ $mol_mem
ensurer_fallback(): $mol_build_ensure_plugin {
return this.$.$mol_build_ensure_npm.make({
root: () => this.root(),
})
}

@ $mol_mem
ensurers() {
return [
this.ensurer_git()
] as readonly ($mol_build_ensure_plugin | null)[]
}

@ $mol_mem_key
ensure( path : string ): boolean {
const mod = $mol_file.absolute( path )
const parent = mod.parent()

if( mod !== this.root() ) this.ensure( parent.path() )

if (mod.exists() && mod.type() !== 'dir') return false

for (const ensurer of this.ensurers()) {
if (ensurer?.ensure(path)) return true
}
if (mod.exists()) return false

if( parent === this.root() ) {
throw new Error( `Root package "${ mod.relate( this.root() ) }" not found` )
}

return this.ensurer_fallback().ensure(path)
}
}
}
118 changes: 118 additions & 0 deletions build/ensure/git/git.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
namespace $ {
export class $mol_build_ensure_git extends $mol_build_ensure_vcs {
override vcs_type() { return 'git' }
override root_repo() { return 'https://github.com/hyoo-ru/mam.git' }

@ $mol_mem
protected version() {
$mol_wire_solid()
return this.$.$mol_run.spawn({ command: 'git version', dir: this.root().path() })
.stdout.toString().trim().match(/.*\s+([\d\.]+\d+)/)?.[1] ?? ''
}

protected deepen_supported() {
return $mol_compare_text()(this.version(), '2.42.0') >= 0
}

protected override update(dir: string) {
const out = this.$.$mol_run.spawn({
command: 'git rev-parse --abbrev-ref --symbolic-full-name HEAD', dir,
})
const current_branch = out.stdout.toString().trim()
// когда не на ветке - не надо пулить, например сборка во время git bisect
if (! current_branch) return false

const command = ['git', 'pull']

if ( ! this.interactive() && this.deepen_supported()) {
/**
depth и deepen не годятся для локальной разработки, поэтому оставляем ограничение глубины пула только для CI

--depth=1 в сочетании с сабмодулями обрезает историю, кроме первого коммита

--deepen=1 если не сделать unset GIT_DIR
в git-конфиге сабмодуля выставляет bare=true, после этого все команды падают с сообщением
warning: core.bare and core.worktree do not make sense
fatal: unable to set up work tree using invalid config
*/
command.push( '--deepen=1' )
}

const timeout = this.pull_timeout()
this.$.$mol_run.spawn( { command, dir, timeout }).stdout.toString().trim()
return true
}

protected is_git(path: string) {
const mod = this.$.$mol_file.absolute( path )
const git_dir = mod.resolve( '.git' )

return git_dir.exists() && git_dir.type() === 'dir'
}

@ $mol_mem
protected submodules() {
const dir = this.root().path()
if (! this.is_git( dir ) ) return new Set<string>()

const command = 'git submodule status --recursive'
const output = this.$.$mol_run.spawn({ command, dir }).stdout.toString().trim()

const dirs = output
.split('\n')
.map( str => str.match( /^\s*[^ ]+\s+([^ ]*).*/ )?.[1]?.trim() )
.filter($mol_guard_defined)
.map(str => `${dir}/${str}`)

return new Set(dirs)
}

protected override inited(path: string) {
return this.is_git(path) || this.submodules().has(path)
}

@ $mol_mem_key
protected branch_remote(dir: string) {
const repo = this.repo(dir)
if (! repo) return 'master'

const res = this.$.$mol_run.spawn( { command: ['git', 'remote', 'show', repo.url ], dir } )

return res.stdout.toString().match( /HEAD branch: (.*?)\n/ )?.[1] ?? 'master'
}

protected override init_existing(dir: string) {
const repo = this.repo(dir)
if (! repo) throw new Error(`"${dir}" not a repo`)
const { url, branch } = repo
this.$.$mol_run.spawn( { command: ['git', 'init'], dir } )

const branch_norm = branch ?? this.branch_remote(dir)

this.$.$mol_run.spawn( { command: ['git', 'remote', 'add', '--track', branch_norm, 'origin' , url ], dir } )
this.$.$mol_run.spawn( { command: [ 'git', 'pull', 'origin', branch_norm ], dir } )

return null
}

protected override init(path: string) {
const mod = this.$.$mol_file.absolute( path )
const repo = this.repo(path)
if (! repo) throw new Error(`"${path}" not a repo`)

const command = [
'git', 'clone' , '--depth', '1',
...( repo.branch ? [ '-b', repo.branch ] : [] ),
' --single-branch',
repo.url ,
mod.relate( this.root() )
]

const dir = this.root().path()
this.$.$mol_run.spawn( { command, dir } )

return null
}

}
}
33 changes: 33 additions & 0 deletions build/ensure/npm/npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace $ {
export class $mol_build_ensure_npm extends $mol_object implements $mol_build_ensure_plugin {
root() { return $mol_file.absolute('') }

@ $mol_mem_key
ensure( path : string ) {
const mod = this.$.$mol_file.absolute( path )
const parent = mod.parent()
const node = this.root().resolve( 'node' )
const node_modules = this.root().resolve( 'node_modules' )

if(
[ node, node_modules ].includes( parent )
&& mod.name() !== 'node'
&& ! mod.name().startsWith('@')
) {
$node [ mod.name() ] // force autoinstall through npm
return true
}

if(
[ node, node_modules ].includes( parent.parent() )
&& parent.name().startsWith('@')
) {
$node [ `${parent.name()}/${mod.name()}` ] // force autoinstall through npm
return true
}
return false
}

}
}

103 changes: 103 additions & 0 deletions build/ensure/vcs/vcs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
namespace $ {
export class $mol_build_ensure_vcs extends $mol_object implements $mol_build_ensure_plugin {
root() { return $mol_file.absolute('') }
interactive() { return process.stdout.isTTY }
pull_timeout() { return 120000 }

root_repo() { return null as null | string }
vcs_type() { return null as null | string }

protected inited(path: string) { return false }
protected init_existing(path: string) { return null }
protected update(path: string) { return false }
protected init(path: string) { return null }

@ $mol_mem_key
meta( path : string ) {
return null as $mol_tree2 | null
}

@ $mol_mem_key
protected repo( path : string ) {
const vcs_type = this.vcs_type()
if (! vcs_type) return null

const mod = $mol_file.absolute( path )
const root_url = this.root_repo()
if (mod === this.root()) return ! root_url ? null : { url: root_url, branch: null as null | string }

const parent = mod.parent()
const mapping = this.meta( parent.path() )

const url_branch = mapping?.select( 'pack' , mod.name(), vcs_type).kids
.find($mol_guard_defined)?.kids[0]

const url = url_branch?.value ?? null
const branch = url_branch?.kids[0]?.value ?? null

return url ? { url, branch } : null
}

protected update_disabled = false

@ $mol_action
protected update_safe(dir: string) {
if (this.update_disabled) return false

try {
return this.$.$mol_file.unwatched(() => this.update(dir), dir)
} catch (e) {
if (e instanceof $mol_run_error && e.cause.timeout_kill) {

this.$.$mol_log3_warn({
place: `${this}.update_safe()`,
message: `Timeout - pull disabled`,
hint: 'Check connection',
})

this.update_disabled = true
return true
}

if (e instanceof Error) {
this.$.$mol_fail_log(e)
return false
}

$mol_fail_hidden(e)
}
}

@ $mol_mem_key
ensure( path : string ) {
const mod = $mol_file.absolute( path )

if( mod.exists()) {
if (! this.inited(path)) {
if (! this.repo(path) ) return false

this.$.$mol_file.unwatched(() => this.init_existing(path), path)
return true
}

this.update_safe( path )

// mod.reset()
// for ( const sub of mod.sub() ) sub.reset()

return true
}

if (this.repo(path)) {

this.$.$mol_file.unwatched(() => this.init(path), path)

// mod.reset()
// for ( const sub of mod.sub() ) sub.reset()
return true
}

return false
}
}
}
Loading
Loading