@@ -6,29 +6,37 @@ const fs = require('fs');
66const  path  =  require ( 'path' ) ; 
77const  assert  =  require ( 'assert' ) ; 
88
9- const  babel  =  require ( '@babel/core ' ) ; 
9+ const  ts  =  require ( 'typescript ' ) ; 
1010
11- const  {  rmdirRecursive,  readdirRecursive,  showStats }  =  require ( './utils' ) ; 
11+ const  tsConfig  =  require ( '../tsconfig.json' ) ; 
12+ 
13+ const  { 
14+  transformLoadFileStaticallyFromNPM, 
15+ }  =  require ( './load-statically-from-npm' ) ; 
16+ const  { 
17+  exec, 
18+  rmdirRecursive, 
19+  readdirRecursive, 
20+  showStats, 
21+ }  =  require ( './utils' ) ; 
1222
1323if  ( require . main  ===  module )  { 
1424 rmdirRecursive ( './dist' ) ; 
1525 fs . mkdirSync ( './dist' ) ; 
1626
1727 const  srcFiles  =  readdirRecursive ( './src' ,  {  ignoreDir : / ^ _ _ .* _ _ $ / } ) ; 
18-  for  ( const  filepath  of  srcFiles )  { 
19-  const  srcPath  =  path . join ( './src' ,  filepath ) ; 
20-  const  destPath  =  path . join ( './dist' ,  filepath ) ; 
21- 
22-  fs . mkdirSync ( path . dirname ( destPath ) ,  {  recursive : true  } ) ; 
23-  if  ( filepath . endsWith ( '.js' ) )  { 
24-  fs . copyFileSync ( srcPath ,  destPath  +  '.flow' ) ; 
25- 
26-  const  cjs  =  babelBuild ( srcPath ,  {  envName : 'cjs'  } ) ; 
27-  fs . writeFileSync ( destPath ,  cjs ) ; 
28-  }  else  if  ( filepath . endsWith ( 'd.ts' ) )  { 
29-  fs . copyFileSync ( srcPath ,  destPath ) ; 
30-  } 
31-  } 
28+  const  {  options }  =  ts . convertCompilerOptionsFromJson ( 
29+  tsConfig . compilerOptions , 
30+  process . cwd ( ) , 
31+  ) ; 
32+  const  program  =  ts . createProgram ( { 
33+  rootNames : srcFiles . map ( ( filepath )  =>  path . join ( './src' ,  filepath ) ) , 
34+  options, 
35+  } ) ; 
36+  program . emit ( undefined ,  undefined ,  undefined ,  undefined ,  { 
37+  after : [ transformLoadFileStaticallyFromNPM ] , 
38+  } ) ; 
39+  exec ( 'npx downlevel-dts ./dist ./dist/ts3.4' ) ; 
3240
3341 fs . copyFileSync ( './LICENSE' ,  './dist/LICENSE' ) ; 
3442 fs . copyFileSync ( './README.md' ,  './dist/README.md' ) ; 
@@ -40,10 +48,6 @@ if (require.main === module) {
4048 showStats ( ) ; 
4149} 
4250
43- function  babelBuild ( srcPath ,  options )  { 
44-  return  babel . transformFileSync ( srcPath ,  options ) . code  +  '\n' ; 
45- } 
46- 
4751function  buildPackageJSON ( )  { 
4852 const  packageJSON  =  require ( '../package.json' ) ; 
4953 delete  packageJSON . private ; 
0 commit comments