@@ -5,9 +5,6 @@ import fs from 'fs';
55import os from 'os' ;
66import path from 'path' ;
77import syntaxCheck from 'syntax-error' ;
8- import { parse } from '@babel/parser' ;
9- import babelGenerator from '@babel/generator' ;
10- import babelTraverse from '@babel/traverse' ;
118import R from 'ramda' ;
129import workerpool from 'workerpool' ;
1310import { LRUCache } from 'lru-cache' ;
@@ -275,12 +272,11 @@ export class DataSchemaCompiler {
275272 const errorsReport = new ErrorReporter ( null , [ ] , this . errorReportOptions ) ;
276273 this . errorsReporter = errorsReport ;
277274
278- const transpilationWorkerThreads = getEnv ( 'transpilationWorkerThreads' ) ;
279275 const transpilationNative = getEnv ( 'transpilationNative' ) ;
280276 const transpilationNativeThreadsCount = getThreadsCount ( ) ;
281277 const { compilerId } = this ;
282278
283- if ( transpilationWorkerThreads ) {
279+ if ( ! transpilationNative ) {
284280 const wc = getEnv ( 'transpilationWorkerThreadsCount' ) ;
285281 this . workerPool = workerpool . pool (
286282 path . join ( __dirname , 'transpilers/transpiler_worker' ) ,
@@ -292,11 +288,10 @@ export class DataSchemaCompiler {
292288 let cubeNames : string [ ] = [ ] ;
293289 let cubeSymbols : Record < string , Record < string , boolean > > = { } ;
294290 let transpilerNames : string [ ] = [ ] ;
295- let results : ( FileContent | undefined ) [ ] ;
296291
297- if ( transpilationNative || transpilationWorkerThreads ) {
298- ( { cubeNames , cubeSymbols , transpilerNames } = this . prepareTranspileSymbols ( ) ) ;
299- }
292+ ( { cubeNames , cubeSymbols , transpilerNames } = this . prepareTranspileSymbols ( ) ) ;
293+
294+ let results : ( FileContent | undefined ) [ ] ;
300295
301296 if ( transpilationNative ) {
302297 const jsFiles = originalJsFiles ;
@@ -325,28 +320,25 @@ export class DataSchemaCompiler {
325320 . map ( f => this . transpileJinjaFile ( f , errorsReport , { cubeNames, cubeSymbols, transpilerNames } ) ) ;
326321
327322 results = ( await Promise . all ( [ ...jsFilesTasks , ...yamlFilesTasks , ...jinjaFilesTasks ] ) ) . flat ( ) ;
328- } else if ( transpilationWorkerThreads ) {
329- results = await Promise . all ( toCompile . map ( f => this . transpileFile ( f , errorsReport , { cubeNames, cubeSymbols, transpilerNames } ) ) ) ;
330323 } else {
331- results = await Promise . all ( toCompile . map ( f => this . transpileFile ( f , errorsReport , { } ) ) ) ;
324+ results = await Promise . all ( toCompile . map ( f => this . transpileFile ( f , errorsReport , { cubeNames , cubeSymbols , transpilerNames } ) ) ) ;
332325 }
333326
334327 return results . filter ( f => ! ! f ) as FileContent [ ] ;
335328 } ;
336329
337330 const transpilePhase = async ( stage : CompileStage ) : Promise < FileContent [ ] > => {
338- let cubeNames : string [ ] = [ ] ;
339- let cubeSymbols : Record < string , Record < string , boolean > > = { } ;
340- let transpilerNames : string [ ] = [ ] ;
341331 let results : ( FileContent | undefined ) [ ] ;
342332
343333 if ( toCompile . length === 0 ) {
344334 return [ ] ;
345335 }
346336
347- if ( transpilationNative || transpilationWorkerThreads ) {
348- ( { cubeNames, cubeSymbols, transpilerNames } = this . prepareTranspileSymbols ( ) ) ;
349- }
337+ let cubeNames : string [ ] = [ ] ;
338+ let cubeSymbols : Record < string , Record < string , boolean > > = { } ;
339+ let transpilerNames : string [ ] = [ ] ;
340+
341+ ( { cubeNames, cubeSymbols, transpilerNames } = this . prepareTranspileSymbols ( ) ) ;
350342
351343 // After the first phase all files are with JS source code: original or transpiled
352344
@@ -363,10 +355,8 @@ export class DataSchemaCompiler {
363355 const jsFilesTasks = jsChunks . map ( chunk => this . transpileJsFilesNativeBulk ( chunk , errorsReport , { transpilerNames, compilerId } ) ) ;
364356
365357 results = ( await Promise . all ( jsFilesTasks ) ) . flat ( ) ;
366- } else if ( transpilationWorkerThreads ) {
367- results = await Promise . all ( toCompile . map ( f => this . transpileJsFile ( f , errorsReport , { cubeNames, cubeSymbols, transpilerNames } ) ) ) ;
368358 } else {
369- results = await Promise . all ( toCompile . map ( f => this . transpileJsFile ( f , errorsReport , { } ) ) ) ;
359+ results = await Promise . all ( toCompile . map ( f => this . transpileJsFile ( f , errorsReport , { cubeNames , cubeSymbols , transpilerNames } ) ) ) ;
370360 }
371361
372362 return results . filter ( f => ! ! f ) as FileContent [ ] ;
@@ -520,7 +510,7 @@ export class DataSchemaCompiler {
520510 errorsReport ,
521511 { cubeNames : [ ] , cubeSymbols : { } , transpilerNames : [ ] , contextSymbols : { } , compilerId : this . compilerId , stage : 0 }
522512 ) . then ( ( ) => undefined ) ;
523- } else if ( transpilationWorkerThreads && this . workerPool ) {
513+ } else if ( this . workerPool ) {
524514 this . workerPool . terminate ( ) ;
525515 }
526516 } ) ;
@@ -701,7 +691,7 @@ export class DataSchemaCompiler {
701691 errorsReport . exitFile ( ) ;
702692
703693 return { ...file , content : res [ 0 ] . code } ;
704- } else if ( getEnv ( 'transpilationWorkerThreads' ) ) {
694+ } else {
705695 const data = {
706696 fileName : file . fileName ,
707697 content : file . content ,
@@ -715,25 +705,6 @@ export class DataSchemaCompiler {
715705 errorsReport . addWarnings ( res . warnings ) ;
716706
717707 return { ...file , content : res . content } ;
718- } else {
719- const ast = parse (
720- file . content ,
721- {
722- sourceFilename : file . fileName ,
723- sourceType : 'module' ,
724- plugins : [ 'objectRestSpread' ] ,
725- } ,
726- ) ;
727-
728- errorsReport . inFile ( file ) ;
729- this . transpilers . forEach ( ( t ) => {
730- babelTraverse ( ast , t . traverseObject ( errorsReport ) ) ;
731- } ) ;
732- errorsReport . exitFile ( ) ;
733-
734- const content = babelGenerator ( ast , { } , file . content ) . code ;
735-
736- return { ...file , content } ;
737708 }
738709 } catch ( e : any ) {
739710 if ( e . toString ( ) . indexOf ( 'SyntaxError' ) !== - 1 ) {
@@ -778,7 +749,7 @@ export class DataSchemaCompiler {
778749 this . compiledYamlCache . set ( cacheKey , res [ 0 ] . code ) ;
779750
780751 return { ...file , content : res [ 0 ] . code } ;
781- } else if ( getEnv ( 'transpilationWorkerThreads' ) ) {
752+ } else {
782753 const data = {
783754 fileName : file . fileName ,
784755 content : file . content ,
@@ -794,12 +765,6 @@ export class DataSchemaCompiler {
794765 this . compiledYamlCache . set ( cacheKey , res . content ) ;
795766
796767 return { ...file , content : res . content } ;
797- } else {
798- const transpiledFile = this . yamlCompiler . transpileYamlFile ( file , errorsReport ) ;
799-
800- this . compiledYamlCache . set ( cacheKey , transpiledFile ?. content || '' ) ;
801-
802- return transpiledFile ;
803768 }
804769 }
805770
0 commit comments