Skip to content

Commit

Permalink
$mol_build separate sourcemap file
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Dec 16, 2023
1 parent e06f089 commit 1988818
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 28 deletions.
30 changes: 13 additions & 17 deletions build/build.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,19 @@ namespace $ {
const text = file.text()
const tree = this.$.$mol_tree2_from_string( text , '../' + name )

const js_path = parent.resolve( prefix ).path()

const dts_text = this.$.$mol_view_tree2_to_dts( tree )
const dts_data = this.$.$mol_tree2_text_to_string_mapped_js( dts_text )
const dts_file = parent.resolve( `${ prefix }.d.ts` )
dts_file.text(dts_data)

// const dts_map = this.$.$mol_tree2_text_to_sourcemap( dts_text )
// const dts_map_file = parent.resolve( `${ prefix }.d.ts.map` )
// dts_map_file.text(JSON.stringify(dts_map))
const dts = this.$.$mol_tree2_text_to_file(dts_text, js_path + '.d.ts')

const js_tree = this.$.$mol_view_tree2_to_js(tree)
const js_text = this.$.$mol_tree2_js_to_text(js_tree)
const js_data = this.$.$mol_tree2_text_to_string_mapped_js( js_text )
const js_file = parent.resolve( `${ prefix }.js` )
js_file.text(js_data)

// const js_map = this.$.$mol_tree2_text_to_sourcemap( js_text )
// const js_map_file = parent.resolve( `${ prefix }.js.map` )
// js_map_file.text(JSON.stringify(js_map))
const js_text = this.$.$mol_tree2_js_to_text(this.$.$mol_view_tree2_to_js(tree))
const js = this.$.$mol_tree2_text_to_file(js_text, js_path + '.js')

const locale_file = parent.resolve( `${ prefix }.locale=en.json` )
const locales = this.$.$mol_view_tree2_to_locale(tree)
locale_file.text( JSON.stringify( locales , null , '\t' ) )

return [ js_file, dts_file, locale_file ]
return [ js.src, js.map, dts.src, dts.map, locale_file ]
}

@ $mol_mem_key
Expand Down Expand Up @@ -1648,6 +1637,13 @@ namespace $ {
return depends
}

$mol_build.dependors[ 'view.ts' ] = source => {
var treeName = './' + source.name().replace( /ts$/ , 'tree' )
var depends : { [ index : string ] : number } = { [ treeName ] : 0 }
$mol_build_depsMerge( depends , $mol_build.dependors[ 'ts' ]!( source ) )
return depends
}

$mol_build.dependors[ 'node.ts' ] = $mol_build.dependors[ 'web.ts' ] = source => {
var common = './' + source.name().replace( /\.(node|web)\.ts$/ , '.ts' )
var depends : { [ index : string ] : number } = { [ common ] : 0 }
Expand Down
7 changes: 3 additions & 4 deletions sourcemap/dataurl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace $ {

const prefix = '# sourceMappingURL=data:application/json,'
const data_url_prefix = 'data:application/json,'
const prefix = $mol_sourcemap_url_prefix + data_url_prefix
const end_comment = ' */'

export function $mol_sourcemap_dataurl_decode(this: $, data: string) {
Expand Down Expand Up @@ -32,9 +33,7 @@ namespace $ {

export function $mol_sourcemap_dataurl_encode(this: $, map: $mol_sourcemap_raw, type = 'js' as 'js' | 'css') {
const str = JSON.stringify( { ...map, mappings: ';;' + map.mappings } )
const encoded = this.encodeURIComponent( str )
const uri = `${prefix}${encoded}`

return type === 'js' ? `\n//${uri}` : `\n/*${uri}${end_comment}`
return this.$mol_sourcemap_url(data_url_prefix + this.encodeURIComponent( str ), type)
}
}
10 changes: 10 additions & 0 deletions sourcemap/url/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace $ {

export const $mol_sourcemap_url_prefix = '# sourceMappingURL='

export function $mol_sourcemap_url(this: $, uri: string, type = 'js' as 'js' | 'css') {
if (type === 'css') return `\n/*${$mol_sourcemap_url_prefix}${uri}*/`
return `\n//${$mol_sourcemap_url_prefix}${uri}`
}

}
15 changes: 15 additions & 0 deletions tree2/text/to/file/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace $ {

export function $mol_tree2_text_to_file( this: $, text: $mol_tree2, pathname: string ) {
const map = this.$mol_file.absolute(pathname + '.map')
const map_data = JSON.stringify( this.$mol_tree2_text_to_sourcemap( text ) )
map.text(map_data)

const src = this.$mol_file.absolute(pathname)
const src_data = this.$mol_tree2_text_to_string( text ) + this.$mol_sourcemap_url(map.name())
src.text( src_data )

return { src, map }
}

}
4 changes: 2 additions & 2 deletions view/tree2/prop/parts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace $ {
'wrong order'($) {
$mol_assert_fail(() => {
get_parts('some_bla?*')
})
}, '`Cyrillic symbol in some_bla?*? `Required prop like some*? at `?#1:1/0`')
},

'empty'($) {
$mol_assert_fail(() => {
get_parts('')
})
}, '``Required prop like some*? at `?#1:1/0`')
},

'prop in upper case'($) {
Expand Down
2 changes: 1 addition & 1 deletion view/tree2/to/js/test/js.bidi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace $ {
a!? $mol_view
expanded <=> cell_test_expanded!? null
`)
}, `Cannot destructure property 'name' of 'prop_parts(...)' as it is undefined. at ?#3:7/3` )
}, '`Cyrillic symbol in a!?? `Required prop like some*? at `.view.tree#3:7/3` at .view.tree#3:7/3' )
},

'Bidi bind with default object'( $ ) {
Expand Down
8 changes: 4 additions & 4 deletions view/tree2/to/js/test/js.simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace $ {
Foo $mol_object
sub / <= Сlose_icon $mol_object
`)
})
}, '`Cyrillic symbol in Сlose_icon? `Required prop like some*? at `.view.tree#3:16/10`\n<=\n.view.tree#3:13/2\n/\n.view.tree#3:11/1 at .view.tree#3:7/3')
},

'simple empty legacy indexed channel throws error'( $ ) {
Expand All @@ -83,14 +83,14 @@ namespace $ {
Foo $mol_object
a!? null
`)
}, `Cannot destructure property 'name' of 'prop_parts(...)' as it is undefined. at ?#3:7/3` )
}, '`Cyrillic symbol in a!?? `Required prop like some*? at `.view.tree#3:7/3` at .view.tree#3:7/3' )

$mol_assert_fail(() => {
$mol_view_tree2_to_js_test_run(`
Foo $mol_object
b! 1
`)
}, `Cannot destructure property 'name' of 'prop_parts(...)' as it is undefined. at ?#3:7/2` )
}, '`Cyrillic symbol in b!? `Required prop like some*? at `.view.tree#3:7/2` at .view.tree#3:7/2' )
},

'simple two classes'( $ ) {
Expand Down Expand Up @@ -163,7 +163,7 @@ namespace $ {
Foo $mol_object
item_чount 50
`)
})
}, '`Cyrillic symbol in item_чount? `Required prop like some*? at `.view.tree#3:7/10` at .view.tree#3:7/10')
},
})

Expand Down

0 comments on commit 1988818

Please sign in to comment.