@@ -59,12 +59,12 @@ namespace $ {
59
59
const file = $mol_file . absolute ( path )
60
60
const name = file . name ( )
61
61
62
- const tree = $mol_tree . fromString ( file . text ( ) , file . path ( ) )
62
+ const tree = this . $ . $mol_tree2_from_string ( file . text ( ) , file . path ( ) )
63
63
64
64
let content = ''
65
- for ( const step of tree . select ( 'build' , '' ) . sub ) {
65
+ for ( const step of tree . select ( 'build' , '' ) . kids ) {
66
66
67
- const res = this . $ . $mol_exec ( file . parent ( ) . path ( ) , step . value ) . stdout . toString ( ) . trim ( )
67
+ const res = this . $ . $mol_exec ( file . parent ( ) . path ( ) , step . text ( ) ) . stdout . toString ( ) . trim ( )
68
68
if ( step . type ) content += `let ${ step . type } = ${ JSON . stringify ( res ) } `
69
69
70
70
}
@@ -76,26 +76,37 @@ namespace $ {
76
76
return [ script ]
77
77
78
78
}
79
-
79
+
80
80
@ $mol_mem_key
81
81
viewTreeTranspile ( path : string ) {
82
82
83
- const file = $mol_file . absolute ( path )
84
- const name = file . name ( )
83
+ const source = $mol_file . absolute ( path )
84
+ const target = source . parent ( ) . resolve ( `-view.tree` )
85
+
86
+ const tree = this . $ . $mol_tree2_from_string ( source . text ( ) , source . relate ( this . root ( ) ) )
87
+
88
+ const js = target . resolve ( source . name ( ) + '.js' )
89
+ const js_map = target . resolve ( js . name ( ) + '.map' )
90
+ const dts = target . resolve ( source . name ( ) + '.d.ts' )
91
+ const dts_map = target . resolve ( dts . name ( ) + '.map' )
92
+
93
+ const js_text = this . $ . $mol_tree2_js_to_text ( this . $ . $mol_view_tree2_to_js ( tree ) )
94
+ js . text ( this . $ . $mol_tree2_text_to_string ( js_text ) + '\n//# sourceMappingURL=' + js_map . relate ( target ) )
95
+ js_map . text ( JSON . stringify ( this . $ . $mol_tree2_text_to_sourcemap ( js_text ) , null , '\t' ) )
85
96
86
- const script = file . parent ( ) . resolve ( `-view.tree/${ name } .ts` )
87
- const sourceMap = file . parent ( ) . resolve ( `-view.tree/${ name } .map` )
88
- const locale = file . parent ( ) . resolve ( `-view.tree/${ name } .locale=en.json` )
97
+ const dts_text = this . $ . $mol_view_tree2_to_dts ( tree )
98
+ dts . text ( this . $ . $mol_tree2_text_to_string ( dts_text ) + '\n//# sourceMappingURL=' + dts_map . relate ( target ) )
89
99
90
- const text = file . text ( )
91
- const tree = this . $ . $mol_tree2_from_string ( text , file . path ( ) )
92
- const res = this . $ . $mol_view_tree2_ts_compile ( tree )
100
+ const dts_map_raw = this . $ . $mol_tree2_text_to_sourcemap ( dts_text )
101
+ delete dts_map_raw . sourcesContent
102
+ dts_map_raw . file = dts . relate ( target )
103
+ dts_map_raw . sourceRoot = this . root ( ) . relate ( target )
104
+ dts_map . text ( JSON . stringify ( dts_map_raw , null , '\t' ) )
93
105
94
- script . text ( res . script )
95
- // sourceMap.text( res.map )
96
- locale . text ( JSON . stringify ( res . locales , null , '\t' ) )
97
-
98
- return [ script , locale ]
106
+ const locale_file = target . resolve ( source . name ( ) + `.locale=en.json` )
107
+ locale_file . text ( JSON . stringify ( this . $ . $mol_view_tree2_to_locale ( tree ) , null , '\t' ) )
108
+
109
+ return [ js , js_map , dts , dts_map , locale_file ]
99
110
}
100
111
101
112
@ $mol_mem_key
@@ -292,8 +303,8 @@ namespace $ {
292
303
if ( sources . length && bundle === 'node' ) {
293
304
const types = [ ] as string [ ]
294
305
295
- for ( let dep of this . nodeDeps ( { path , exclude } ) ) {
296
- types . push ( '\t' + JSON . stringify ( dep ) + ' : typeof import\( ' + JSON . stringify ( dep ) + ' )' )
306
+ for ( let [ dep , src ] of this . nodeDeps ( { path , exclude } ) ) {
307
+ types . push ( '\t' + JSON . stringify ( dep ) + ' : typeof import\( ' + JSON . stringify ( dep ) + ' ) // ' + src )
297
308
}
298
309
299
310
const node_types = $mol_file . absolute ( path ) . resolve ( `-node/deps.d.ts` )
@@ -385,9 +396,10 @@ namespace $ {
385
396
this . js_error ( diagnostic . file . getSourceFile ( ) . fileName , error )
386
397
387
398
} else {
399
+ const text = diagnostic . messageText
388
400
this . $ . $mol_log3_fail ( {
389
401
place : `${ this } .tsService()` ,
390
- message : String ( diagnostic . messageText ) ,
402
+ message : typeof text === 'string' ? text : text . messageText ,
391
403
} )
392
404
}
393
405
@@ -455,17 +467,16 @@ namespace $ {
455
467
map . sources = [ src . relate ( ) ]
456
468
457
469
return {
458
- text : res . outputText . replace ( / ^ \/ \/ # \s s o u r c e M a p p i n g U R L = [ ^ \n ] * / mg , '//' + src . relate ( ) ) + '\n' ,
470
+ text : this . $ . $mol_sourcemap_strip ( res . outputText ) ,
471
+ // .replace( /^\/\/#\ssourceMappingURL=[^\n]*/mg , '//' + src.relate() )+'\n',
459
472
map : map ,
460
473
}
461
474
462
475
} else {
463
476
464
- const srcMap = src . parent ( ) . resolve ( src . name ( ) + '.map' ) ;
465
-
466
477
return {
467
- text : src . text ( ) . replace ( / ^ \/ \/ # \s s o u r c e M a p p i n g U R L = / mg , '//' ) + '\n' ,
468
- map : srcMap . exists ( ) ? JSON . parse ( srcMap . text ( ) ) as $mol_sourcemap_raw : undefined
478
+ text : this . $ . $mol_sourcemap_strip ( src . text ( ) ) ,
479
+ map : this . $ . $mol_sourcemap_from_file ( src )
469
480
}
470
481
471
482
}
@@ -590,7 +601,8 @@ namespace $ {
590
601
if ( mod !== this . root ( ) ) this . modEnsure ( parent . path ( ) )
591
602
592
603
var mapping = mod === this . root ( )
593
- ? $mol_tree . fromString ( `pack ${ mod . name ( ) } git \\https://github.com/hyoo-ru/mam.git\n` )
604
+ ? this . $ . $mol_tree2_from_string ( `pack ${ mod . name ( ) } git \\https://github.com/hyoo-ru/mam.git
605
+ ` )
594
606
: this . modMeta ( parent . path ( ) )
595
607
596
608
if ( mod . exists ( ) ) {
@@ -609,17 +621,17 @@ namespace $ {
609
621
return false
610
622
}
611
623
612
- for ( let repo of mapping . select ( 'pack' , mod . name ( ) , 'git' ) . sub ) {
624
+ for ( let repo of mapping . select ( 'pack' , mod . name ( ) , 'git' ) . kids ) {
613
625
614
626
this . $ . $mol_exec ( mod . path ( ) , 'git' , 'init' )
615
627
616
- const res = this . $ . $mol_exec ( mod . path ( ) , 'git' , 'remote' , 'show' , repo . value )
628
+ const res = this . $ . $mol_exec ( mod . path ( ) , 'git' , 'remote' , 'show' , repo . text ( ) )
617
629
const matched = res . stdout . toString ( ) . match ( / H E A D b r a n c h : ( .* ?) \n / )
618
630
const head_branch_name = res instanceof Error || matched === null || ! matched [ 1 ]
619
631
? 'master'
620
632
: matched [ 1 ]
621
633
622
- this . $ . $mol_exec ( mod . path ( ) , 'git' , 'remote' , 'add' , '--track' , head_branch_name ! , 'origin' , repo . value )
634
+ this . $ . $mol_exec ( mod . path ( ) , 'git' , 'remote' , 'add' , '--track' , head_branch_name ! , 'origin' , repo . text ( ) )
623
635
this . $ . $mol_exec ( mod . path ( ) , 'git' , 'pull' , '--deepen=1' )
624
636
mod . reset ( )
625
637
for ( const sub of mod . sub ( ) ) {
@@ -641,8 +653,8 @@ namespace $ {
641
653
return false
642
654
}
643
655
644
- for ( let repo of mapping . select ( 'pack' , mod . name ( ) , 'git' ) . sub ) {
645
- this . $ . $mol_exec ( this . root ( ) . path ( ) , 'git' , 'clone' , '--depth' , '1' , repo . value , mod . relate ( this . root ( ) ) )
656
+ for ( let repo of mapping . select ( 'pack' , mod . name ( ) , 'git' ) . kids ) {
657
+ this . $ . $mol_exec ( this . root ( ) . path ( ) , 'git' , 'clone' , '--depth' , '1' , repo . text ( ) , mod . relate ( this . root ( ) ) )
646
658
mod . reset ( )
647
659
return true
648
660
}
@@ -672,16 +684,14 @@ namespace $ {
672
684
@ $mol_mem_key
673
685
modMeta ( path : string ) {
674
686
675
- const decls = [ ] as $mol_tree [ ]
687
+ const decls = [ ] as $mol_tree2 [ ]
676
688
677
689
const pack = $mol_file . absolute ( path )
678
690
for ( const file of pack . sub ( ) ) {
679
691
if ( ! / \. m e t a \. t r e e $ / . test ( file . name ( ) ) ) continue
680
- decls . push ( ... $mol_tree . fromString ( file . text ( ) , file . path ( ) ) . sub )
692
+ decls . push ( ... this . $ . $mol_tree2_from_string ( file . text ( ) , file . path ( ) ) . kids )
681
693
}
682
-
683
- return new $mol_tree ( { sub : decls } )
684
-
694
+ return this . $ . $mol_tree2 . list ( decls , decls [ 0 ] ?. span )
685
695
}
686
696
687
697
@ $mol_mem_key
@@ -698,7 +708,7 @@ namespace $ {
698
708
const checkDep = ( p : string ) => {
699
709
700
710
const isFile = / \. \w + $ / . test ( p )
701
-
711
+
702
712
var dep = ( p [ 0 ] === '/' )
703
713
? this . root ( ) . resolve ( p + ( isFile ? '' : '/' + p . replace ( / .* \/ / , '' ) ) )
704
714
: ( p [ 0 ] === '.' )
@@ -1117,6 +1127,7 @@ namespace $ {
1117
1127
var pack = $mol_file . absolute ( path )
1118
1128
1119
1129
var target = pack . resolve ( `-/${ bundle } .d.ts` )
1130
+ var targetMap = pack . resolve ( `-/${ bundle } .d.ts.map` )
1120
1131
1121
1132
var sources = this . sourcesDTS ( { path , exclude } )
1122
1133
if ( sources . length === 0 ) return [ ]
@@ -1130,11 +1141,12 @@ namespace $ {
1130
1141
}
1131
1142
)
1132
1143
1133
- target . text ( concater . content + '\nexport = $;' )
1144
+ target . text ( concater . content + '\nexport = $;\n//# sourceMappingURL=' + targetMap . relate ( target . parent ( ) ) + '\n' )
1145
+ targetMap . text ( concater . toString ( ) )
1134
1146
1135
1147
this . logBundle ( target , Date . now ( ) - start )
1136
1148
1137
- return [ target ]
1149
+ return [ target , targetMap ]
1138
1150
}
1139
1151
1140
1152
@ $mol_mem_key
@@ -1165,39 +1177,39 @@ namespace $ {
1165
1177
1166
1178
const sortedPaths = this . graph ( { path , exclude } ) . sorted
1167
1179
1168
- const namedMetas : $mol_tree [ ] = [ ]
1180
+ const namedMetas : $mol_tree2 [ ] = [ ]
1169
1181
sortedPaths . forEach ( path => {
1170
1182
const meta = this . modMeta ( this . root ( ) . resolve ( path ) . path ( ) )
1171
- if ( meta . sub . length > 0 ) {
1172
- namedMetas . push ( meta . clone ( { value : '/' + path } ) )
1183
+ if ( meta . kids . length > 0 ) {
1184
+ namedMetas . push ( meta . data ( '/' + path , meta . kids ) )
1173
1185
}
1174
1186
} )
1175
-
1187
+
1176
1188
if ( namedMetas . length === 0 ) return [ ]
1177
1189
1178
- target . text ( new $mol_tree ( { sub : namedMetas } ) . toString ( ) )
1190
+ target . text ( this . $ . $mol_tree2 . list ( namedMetas , namedMetas [ 0 ] ?. span ) . toString ( ) )
1179
1191
1180
1192
this . logBundle ( target , Date . now ( ) - start )
1181
1193
1182
1194
return [ target ]
1183
1195
}
1184
1196
1185
1197
@ $mol_mem_key
1186
- nodeDeps ( { path , exclude } : { path : string , exclude : string [ ] } ) : string [ ] {
1198
+ nodeDeps ( { path , exclude } : { path : string , exclude : string [ ] } ) {
1187
1199
1188
- var res = new Set < string > ( )
1200
+ var res = new Map < string , string > ( )
1189
1201
var sources = this . sourcesAll ( { path , exclude } )
1190
1202
1191
1203
for ( let src of sources ) {
1192
1204
let deps = this . srcDeps ( src . path ( ) )
1193
1205
for ( let dep in deps ) {
1194
1206
if ( ! / ^ \/ n o d e (?: _ m o d u l e s ) ? \/ / . test ( dep ) ) continue
1195
1207
let mod = dep . replace ( / ^ \/ n o d e (?: _ m o d u l e s ) ? \/ / , '' ) . replace ( / \/ .* / g , '' )
1196
- res . add ( mod )
1208
+ res . set ( mod , src . relate ( ) )
1197
1209
}
1198
1210
}
1199
1211
1200
- return [ ... res ]
1212
+ return res
1201
1213
1202
1214
}
1203
1215
@@ -1291,7 +1303,7 @@ namespace $ {
1291
1303
1292
1304
json . version = version . join ( '.' )
1293
1305
1294
- for ( let dep of this . nodeDeps ( { path , exclude } ) ) {
1306
+ for ( let dep of this . nodeDeps ( { path , exclude } ) . keys ( ) ) {
1295
1307
if ( require ( 'module' ) . builtinModules . includes ( dep ) ) continue
1296
1308
json . dependencies [ dep ] = `*`
1297
1309
}
@@ -1346,9 +1358,8 @@ namespace $ {
1346
1358
. filter ( src => / m e t a .t r e e $ / . test ( src . ext ( ) ) )
1347
1359
1348
1360
const targets : $mol_file [ ] = [ ]
1349
-
1350
1361
sources . forEach ( source => {
1351
- const tree = $mol_tree . fromString ( source . text ( ) , source . path ( ) )
1362
+ const tree = this . $ . $mol_tree2_from_string ( source . text ( ) , source . path ( ) )
1352
1363
1353
1364
const pushFile = ( file :$mol_file ) => {
1354
1365
const start = Date . now ( )
@@ -1371,9 +1382,8 @@ namespace $ {
1371
1382
}
1372
1383
1373
1384
}
1374
-
1375
- tree . select ( 'deploy' ) . sub . forEach ( deploy => {
1376
- addFilesRecursive ( root . resolve ( deploy . value . replace ( / ^ \/ / , '' ) ) )
1385
+ tree . select ( 'deploy' ) . kids . forEach ( deploy => {
1386
+ addFilesRecursive ( root . resolve ( deploy . text ( ) . replace ( / ^ \/ / , '' ) ) )
1377
1387
} )
1378
1388
1379
1389
} )
@@ -1615,7 +1625,7 @@ namespace $ {
1615
1625
return depends
1616
1626
}
1617
1627
1618
- $mol_build . dependors [ 'ts' ] = $mol_build . dependors [ 'tsx' ] = $mol_build . dependors [ 'jam.js' ] = source => {
1628
+ $mol_build . dependors [ 'ts' ] = $mol_build . dependors [ 'tsx' ] = $mol_build . dependors [ 'jam.js' ] = $mol_build . dependors [ 'tree.js' ] = source => {
1619
1629
var depends : { [ index : string ] : number } = { }
1620
1630
1621
1631
var lines = String ( source . text ( ) )
@@ -1652,20 +1662,13 @@ namespace $ {
1652
1662
return depends
1653
1663
}
1654
1664
1655
- // $mol_build.dependors[ 'test.ts' ] = source => {
1656
- // var ts = './' + source.name().replace( /\.test\./ , '.' )
1657
- // var depends : { [ index : string ] : number } = { [ ts ] : 0 }
1658
- // $mol_build_depsMerge( depends , $mol_build.dependors[ 'ts' ]!( source ) )
1659
- // return depends
1660
- // }
1661
-
1662
1665
$mol_build . dependors [ 'view.ts' ] = source => {
1663
1666
var treeName = './' + source . name ( ) . replace ( / t s $ / , 'tree' )
1664
1667
var depends : { [ index : string ] : number } = { [ treeName ] : 0 }
1665
1668
$mol_build_depsMerge ( depends , $mol_build . dependors [ 'ts' ] ! ( source ) )
1666
1669
return depends
1667
1670
}
1668
-
1671
+
1669
1672
$mol_build . dependors [ 'node.ts' ] = $mol_build . dependors [ 'web.ts' ] = source => {
1670
1673
var common = './' + source . name ( ) . replace ( / \. ( n o d e | w e b ) \. t s $ / , '.ts' )
1671
1674
var depends : { [ index : string ] : number } = { [ common ] : 0 }
@@ -1746,22 +1749,23 @@ namespace $ {
1746
1749
$mol_build . dependors [ 'meta.tree' ] = source => {
1747
1750
const depends : { [ index : string ] : number } = { }
1748
1751
1749
- const tree = $mol_tree . fromString ( source . text ( ) , source . path ( ) )
1750
-
1751
- tree . select ( 'require' ) . sub . forEach ( leaf => {
1752
- depends [ leaf . value ] = 0
1752
+ const tree = $$ . $mol_tree2_from_string ( source . text ( ) , source . path ( ) )
1753
+
1754
+ tree . select ( 'require' ) . kids . forEach ( leaf => {
1755
+ depends [ leaf . text ( ) ] = 0
1753
1756
} )
1754
1757
1755
- tree . select ( 'include' ) . sub . forEach ( leaf => {
1756
- depends [ leaf . value ] = - 9000
1758
+ tree . select ( 'include' ) . kids . forEach ( leaf => {
1759
+ depends [ leaf . text ( ) ] = - 9000
1757
1760
} )
1758
1761
1759
1762
return depends
1760
1763
}
1761
1764
1762
1765
$mol_build . dependors [ 'view.tree' ] = source => {
1763
1766
return {
1764
- [ `/${ source . parent ( ) . relate ( ) } /-view.tree/${ source . name ( ) } .ts` ] : 0 ,
1767
+ [ `/${ source . parent ( ) . relate ( ) } /-view.tree/${ source . name ( ) } .js` ] : 0 ,
1768
+ [ `/${ source . parent ( ) . relate ( ) } /-view.tree/${ source . name ( ) } .d.ts` ] : 0 ,
1765
1769
}
1766
1770
}
1767
1771
0 commit comments