From 198881839b2760c4ae8345f8c3a450f5c0c6445d Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sat, 16 Dec 2023 22:39:11 +0300 Subject: [PATCH] $mol_build separate sourcemap file --- build/build.node.ts | 30 +++++++++++-------------- sourcemap/dataurl.ts | 7 +++--- sourcemap/url/url.ts | 10 +++++++++ tree2/text/to/file/file.ts | 15 +++++++++++++ view/tree2/prop/parts.test.ts | 4 ++-- view/tree2/to/js/test/js.bidi.test.ts | 2 +- view/tree2/to/js/test/js.simple.test.ts | 8 +++---- 7 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 sourcemap/url/url.ts create mode 100644 tree2/text/to/file/file.ts diff --git a/build/build.node.ts b/build/build.node.ts index 71ed8633bc0..5773489ddd9 100644 --- a/build/build.node.ts +++ b/build/build.node.ts @@ -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 @@ -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 } diff --git a/sourcemap/dataurl.ts b/sourcemap/dataurl.ts index 99bc1fac094..3c32fe0c016 100644 --- a/sourcemap/dataurl.ts +++ b/sourcemap/dataurl.ts @@ -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) { @@ -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) } } diff --git a/sourcemap/url/url.ts b/sourcemap/url/url.ts new file mode 100644 index 00000000000..8039f5689df --- /dev/null +++ b/sourcemap/url/url.ts @@ -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}` + } + +} diff --git a/tree2/text/to/file/file.ts b/tree2/text/to/file/file.ts new file mode 100644 index 00000000000..db3384c180d --- /dev/null +++ b/tree2/text/to/file/file.ts @@ -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 } + } + +} diff --git a/view/tree2/prop/parts.test.ts b/view/tree2/prop/parts.test.ts index d4a5df5b7a6..e255bd2ac8d 100644 --- a/view/tree2/prop/parts.test.ts +++ b/view/tree2/prop/parts.test.ts @@ -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'($) { diff --git a/view/tree2/to/js/test/js.bidi.test.ts b/view/tree2/to/js/test/js.bidi.test.ts index 51f9a0aa48a..63122d9b7f8 100644 --- a/view/tree2/to/js/test/js.bidi.test.ts +++ b/view/tree2/to/js/test/js.bidi.test.ts @@ -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'( $ ) { diff --git a/view/tree2/to/js/test/js.simple.test.ts b/view/tree2/to/js/test/js.simple.test.ts index 95aed5d2d47..afeca1c8871 100644 --- a/view/tree2/to/js/test/js.simple.test.ts +++ b/view/tree2/to/js/test/js.simple.test.ts @@ -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'( $ ) { @@ -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'( $ ) { @@ -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') }, })