Skip to content

Commit

Permalink
Merge pull request #731 from hyoo-ru/fix-builder2
Browse files Browse the repository at this point in the history
$mol_build fix no sources error informative
  • Loading branch information
zerkalica authored Feb 4, 2025
2 parents c8dd781 + 993033f commit 379c21e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 26 deletions.
24 changes: 18 additions & 6 deletions build/build.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,9 @@ namespace $ {
}

@ $mol_mem_key
bundle_test_js([ path , exclude , bundle ] : [ path : string , exclude : readonly string[] , bundle : string ]) {
bundle_test_js(
[ path , exclude , bundle ] : [ path : string , exclude : readonly string[] , bundle : string ]
) {
const start = this.now()
const pack = $mol_file.absolute( path )

Expand All @@ -951,7 +953,7 @@ namespace $ {
concater.add( 'function require'+'( path ){ return $node[ path ] }' )
}

if( sources.length === 0 ) return []
if( sources.length === 0 ) return null

const errors = [] as Error[]

Expand Down Expand Up @@ -979,25 +981,35 @@ namespace $ {
$mol_fail_hidden( error )
}

return [ target, targetMap ]
return { js: target, map: targetMap }
}

@ $mol_mem_key
bundleAndRunTestJS( { path , exclude , bundle } : { path : string , exclude : readonly string[] , bundle : string } ) : $mol_file[] {
const [ target , targetMap ] = this.bundle_test_js([ path, exclude, bundle ])
const target = this.bundle_test_js([ path, exclude, bundle ])
if (! target ) {
this.$.$mol_log3_fail({
place: `${this}.bundleAndRunTestJS` ,
message: 'No sources found' ,
hint: 'Wrong path?',
path ,
})
return []
}

if( bundle === 'node' ) {
const dir = this.root().path()

this.$.$mol_file.unwatched(() =>
this.$.$mol_run.spawn( {
command: ['node', '--enable-source-maps', '--trace-uncaught', target.relate( this.root() ) ],
command: ['node', '--enable-source-maps', '--trace-uncaught', target.js.relate( this.root() ) ],
dir
} ),
dir
)
}

return [ target , targetMap ]
return [ target.js , target.map ]
}

@ $mol_mem_key
Expand Down
30 changes: 18 additions & 12 deletions build/ensure/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,24 @@ namespace $ {
protected submodule_dirs(opts: { dir: string, recursive?: boolean }) {
const dir = this.$.$mol_file.absolute( opts.dir )

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

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

return dirs
try {
const output = this.$.$mol_run.spawn({
command: [ 'git', 'submodule', 'status', ...( opts.recursive ? ['--recursive'] : [] ) ],
dir: dir.path(),
}).stdout.toString().trim()

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

return dirs
} catch (e) {
if ($mol_promise_like(e)) $mol_fail_hidden(e)
this.$.$mol_fail_log(e)
return []
}
}

@ $mol_mem
Expand Down
36 changes: 28 additions & 8 deletions error/mix/mix.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
namespace $ {

function cause_serialize(cause: unknown) {
return JSON.stringify( cause, null, ' ' )
.replace(/\(/,'<')
.replace(/\)/,' >')
}

function frame_normalize(frame: string | Object) {
return ( typeof frame === 'string' ? frame : cause_serialize(frame) )
.trim()
.replace( /at /gm, ' at ' )
.replace( /^(?! +at )(.*)/gm, ' at | $1 (#)' )
}

export class $mol_error_mix< Cause extends {} = {} > extends AggregateError {

name = $$.$mol_func_name( this.constructor ).replace( /^\$/, '' ) + '_Error'

constructor(
message: string,
readonly cause = {} as Cause,
... errors: Error[]
... errors: readonly Error[]
) {

super( errors, message, { cause } )

const stack_get = Object.getOwnPropertyDescriptor( this, 'stack' )?.get ?? ( ()=> super.stack )
const desc = Object.getOwnPropertyDescriptor( this, 'stack' )
const stack_get = ()=> desc?.get?.() ?? super.stack ?? desc?.value ?? this.message

Object.defineProperty( this, 'stack', {
get: ()=> ( stack_get.call( this ) ?? this.message ) + '\n' + [ JSON.stringify( this.cause, null, ' ' ) ?? 'no cause', ... this.errors.map( e => e.stack ) ].map(
e => e.trim()
.replace( /at /gm, ' at ' )
.replace( /^(?! +at )(.*)/gm, ' at | $1 (#)' )
).join('\n')
get: ()=> stack_get() + '\n' + [
this.cause ?? 'no cause',
... this.errors.flatMap( e => [
e.stack,
... e instanceof $mol_error_mix || ! e.cause ? [] : [ e.cause ]
] )
].map(frame_normalize).join('\n')
} )


// в nodejs, что б не дублировалось cause в консоли
Object.defineProperty(this, 'cause', {
get: () => cause
})
}

static [ Symbol.toPrimitive ]() {
Expand Down

0 comments on commit 379c21e

Please sign in to comment.