@@ -96,9 +96,7 @@ exports.compileString = (sources, options) => {
96
96
if ( typeof sources === "string" ) sources = { "input.ts" : sources } ;
97
97
const output = Object . create ( {
98
98
stdout : createMemoryStream ( ) ,
99
- stderr : createMemoryStream ( ) ,
100
- binary : null ,
101
- text : null
99
+ stderr : createMemoryStream ( )
102
100
} ) ;
103
101
var argv = [
104
102
"--binaryFile" , "binary" ,
@@ -270,7 +268,7 @@ exports.main = function main(argv, options, callback) {
270
268
}
271
269
for ( let j = 0 , l = libFiles . length ; j < l ; ++ j ) {
272
270
let libPath = libFiles [ j ] ;
273
- let libText = readFile ( path . join ( libDir , libPath ) ) ;
271
+ let libText = readFile ( libPath , libDir ) ;
274
272
if ( libText === null ) return callback ( Error ( "Library file '" + libPath + "' not found." ) ) ;
275
273
stats . parseCount ++ ;
276
274
stats . parseTime += measure ( ( ) => {
@@ -302,13 +300,12 @@ exports.main = function main(argv, options, callback) {
302
300
sourcePath = exports . libraryPrefix + indexName + ".ts" ;
303
301
} else {
304
302
for ( let i = 0 , k = customLibDirs . length ; i < k ; ++ i ) {
305
- const dir = customLibDirs [ i ] ;
306
- sourceText = readFile ( path . join ( dir , plainName + ".ts" ) ) ;
303
+ sourceText = readFile ( plainName + ".ts" , customLibDirs [ i ] ) ;
307
304
if ( sourceText !== null ) {
308
305
sourcePath = exports . libraryPrefix + plainName + ".ts" ;
309
306
break ;
310
307
} else {
311
- sourceText = readFile ( path . join ( dir , indexName + ".ts" ) ) ;
308
+ sourceText = readFile ( indexName + ".ts" , customLibDirs [ i ] ) ;
312
309
if ( sourceText !== null ) {
313
310
sourcePath = exports . libraryPrefix + indexName + ".ts" ;
314
311
break ;
@@ -321,11 +318,11 @@ exports.main = function main(argv, options, callback) {
321
318
} else {
322
319
const plainName = sourcePath ;
323
320
const indexName = sourcePath + "/index" ;
324
- sourceText = readFile ( path . join ( baseDir , plainName + ".ts" ) ) ;
321
+ sourceText = readFile ( plainName + ".ts" , baseDir ) ;
325
322
if ( sourceText !== null ) {
326
323
sourcePath = plainName + ".ts" ;
327
324
} else {
328
- sourceText = readFile ( path . join ( baseDir , indexName + ".ts" ) ) ;
325
+ sourceText = readFile ( indexName + ".ts" , baseDir ) ;
329
326
if ( sourceText !== null ) {
330
327
sourcePath = indexName + ".ts" ;
331
328
} else if ( ! plainName . startsWith ( "." ) ) {
@@ -338,12 +335,12 @@ exports.main = function main(argv, options, callback) {
338
335
} else {
339
336
for ( let i = 0 , k = customLibDirs . length ; i < k ; ++ i ) {
340
337
const dir = customLibDirs [ i ] ;
341
- sourceText = readFile ( path . join ( dir , plainName + ".ts" ) ) ;
338
+ sourceText = readFile ( plainName + ".ts" , customLibDirs [ i ] ) ;
342
339
if ( sourceText !== null ) {
343
340
sourcePath = exports . libraryPrefix + plainName + ".ts" ;
344
341
break ;
345
342
} else {
346
- sourceText = readFile ( path . join ( dir , indexName + ".ts" ) ) ;
343
+ sourceText = readFile ( indexName + ".ts" , customLibDirs [ i ] ) ;
347
344
if ( sourceText !== null ) {
348
345
sourcePath = exports . libraryPrefix + indexName + ".ts" ;
349
346
break ;
@@ -374,9 +371,9 @@ exports.main = function main(argv, options, callback) {
374
371
let sourcePath = String ( filename ) . replace ( / \\ / g, "/" ) . replace ( / ( \. t s | \/ ) $ / , "" ) ;
375
372
376
373
// Try entryPath.ts, then entryPath/index.ts
377
- let sourceText = readFile ( path . join ( baseDir , sourcePath ) + ".ts" ) ;
374
+ let sourceText = readFile ( sourcePath + ".ts" , baseDir ) ;
378
375
if ( sourceText === null ) {
379
- sourceText = readFile ( path . join ( baseDir , sourcePath , " index.ts") ) ;
376
+ sourceText = readFile ( sourcePath + "/ index.ts", baseDir ) ;
380
377
if ( sourceText === null ) {
381
378
return callback ( Error ( "Entry file '" + sourcePath + ".ts' not found." ) ) ;
382
379
} else {
@@ -574,7 +571,7 @@ exports.main = function main(argv, options, callback) {
574
571
} ) ;
575
572
576
573
if ( args . binaryFile . length ) {
577
- writeFile ( path . join ( baseDir , args . binaryFile ) , wasm . output ) ;
574
+ writeFile ( args . binaryFile , wasm . output , baseDir ) ;
578
575
} else {
579
576
writeStdout ( wasm . output ) ;
580
577
hasStdout = true ;
@@ -594,15 +591,12 @@ exports.main = function main(argv, options, callback) {
594
591
text = exports . libraryFiles [ stdName ] ;
595
592
} else {
596
593
for ( let i = 0 , k = customLibDirs . length ; i < k ; ++ i ) {
597
- text = readFile ( path . join (
598
- customLibDirs [ i ] ,
599
- name . substring ( exports . libraryPrefix . length ) )
600
- ) ;
594
+ text = readFile ( name . substring ( exports . libraryPrefix . length ) , customLibDirs [ i ] ) ;
601
595
if ( text !== null ) break ;
602
596
}
603
597
}
604
598
} else {
605
- text = readFile ( path . join ( baseDir , name ) ) ;
599
+ text = readFile ( name , baseDir ) ;
606
600
}
607
601
if ( text === null ) {
608
602
return callback ( Error ( "Source file '" + name + "' not found." ) ) ;
@@ -611,10 +605,9 @@ exports.main = function main(argv, options, callback) {
611
605
sourceMap . sourceContents [ index ] = text ;
612
606
} ) ;
613
607
writeFile ( path . join (
614
- baseDir ,
615
608
path . dirname ( args . binaryFile ) ,
616
609
path . basename ( sourceMapURL )
617
- ) , JSON . stringify ( sourceMap ) ) ;
610
+ ) . replace ( / ^ \. \/ / , "" ) , JSON . stringify ( sourceMap ) , baseDir ) ;
618
611
} else {
619
612
stderr . write ( "Skipped source map (stdout already occupied)" + EOL ) ;
620
613
}
@@ -629,7 +622,7 @@ exports.main = function main(argv, options, callback) {
629
622
stats . emitTime += measure ( ( ) => {
630
623
asm = module . toAsmjs ( ) ;
631
624
} ) ;
632
- writeFile ( path . join ( baseDir , args . asmjsFile ) , asm ) ;
625
+ writeFile ( args . asmjsFile , asm , baseDir ) ;
633
626
} else if ( ! hasStdout ) {
634
627
stats . emitCount ++ ;
635
628
stats . emitTime += measure ( ( ) => {
@@ -649,7 +642,7 @@ exports.main = function main(argv, options, callback) {
649
642
stats . emitTime += measure ( ( ) => {
650
643
idl = assemblyscript . buildIDL ( program ) ;
651
644
} ) ;
652
- writeFile ( path . join ( baseDir , args . idlFile ) , idl ) ;
645
+ writeFile ( args . idlFile , idl , baseDir ) ;
653
646
} else if ( ! hasStdout ) {
654
647
stats . emitCount ++ ;
655
648
stats . emitTime += measure ( ( ) => {
@@ -669,7 +662,7 @@ exports.main = function main(argv, options, callback) {
669
662
stats . emitTime += measure ( ( ) => {
670
663
tsd = assemblyscript . buildTSD ( program ) ;
671
664
} ) ;
672
- writeFile ( path . join ( baseDir , args . tsdFile ) , tsd ) ;
665
+ writeFile ( args . tsdFile , tsd , baseDir ) ;
673
666
} else if ( ! hasStdout ) {
674
667
stats . emitCount ++ ;
675
668
stats . emitTime += measure ( ( ) => {
@@ -689,7 +682,7 @@ exports.main = function main(argv, options, callback) {
689
682
stats . emitTime += measure ( ( ) => {
690
683
wat = module . toText ( ) ;
691
684
} ) ;
692
- writeFile ( path . join ( baseDir , args . textFile ) , wat ) ;
685
+ writeFile ( args . textFile , wat , baseDir ) ;
693
686
} else if ( ! hasStdout ) {
694
687
stats . emitCount ++ ;
695
688
stats . emitTime += measure ( ( ) => {
@@ -706,28 +699,28 @@ exports.main = function main(argv, options, callback) {
706
699
}
707
700
return callback ( null ) ;
708
701
709
- function readFileNode ( filename ) {
702
+ function readFileNode ( filename , baseDir ) {
710
703
try {
711
704
let text ;
712
705
stats . readCount ++ ;
713
706
stats . readTime += measure ( ( ) => {
714
- text = fs . readFileSync ( filename , { encoding : "utf8" } ) ;
707
+ text = fs . readFileSync ( path . join ( baseDir , filename ) , { encoding : "utf8" } ) ;
715
708
} ) ;
716
709
return text ;
717
710
} catch ( e ) {
718
711
return null ;
719
712
}
720
713
}
721
714
722
- function writeFileNode ( filename , contents ) {
715
+ function writeFileNode ( filename , contents , baseDir ) {
723
716
try {
724
717
stats . writeCount ++ ;
725
718
stats . writeTime += measure ( ( ) => {
726
- mkdirp ( path . dirname ( filename ) ) ;
719
+ mkdirp ( path . join ( baseDir , path . dirname ( filename ) ) ) ;
727
720
if ( typeof contents === "string" ) {
728
- fs . writeFileSync ( filename , contents , { encoding : "utf8" } ) ;
721
+ fs . writeFileSync ( path . join ( baseDir , filename ) , contents , { encoding : "utf8" } ) ;
729
722
} else {
730
- fs . writeFileSync ( filename , contents ) ;
723
+ fs . writeFileSync ( path . join ( baseDir , filename ) , contents ) ;
731
724
}
732
725
} ) ;
733
726
return true ;
@@ -736,11 +729,11 @@ exports.main = function main(argv, options, callback) {
736
729
}
737
730
}
738
731
739
- function listFilesNode ( dirname ) {
732
+ function listFilesNode ( dirname , baseDir ) {
740
733
var files ;
741
734
try {
742
735
stats . readTime += measure ( ( ) => {
743
- files = fs . readdirSync ( dirname ) . filter ( file => / ^ (? ! .* \. d \. t s $ ) .* \. t s $ / . test ( file ) ) ;
736
+ files = fs . readdirSync ( path . join ( baseDir , dirname ) ) . filter ( file => / ^ (? ! .* \. d \. t s $ ) .* \. t s $ / . test ( file ) ) ;
744
737
} ) ;
745
738
return files ;
746
739
} catch ( e ) {
0 commit comments