@@ -13,7 +13,7 @@ import workerpool from 'workerpool';
1313import { LRUCache } from 'lru-cache' ;
1414
1515import { FileContent , getEnv , isNativeSupported , SchemaFileRepository } from '@cubejs-backend/shared' ;
16- import { NativeInstance , PythonCtx , transpileJs } from '@cubejs-backend/native' ;
16+ import { NativeInstance , PythonCtx , transpileJs , transpileYaml } from '@cubejs-backend/native' ;
1717import { UserError } from './UserError' ;
1818import { ErrorReporter , ErrorReporterOptions , SyntaxErrorInterface } from './ErrorReporter' ;
1919import { CONTEXT_SYMBOLS , CubeDefinition , CubeSymbols } from './CubeSymbols' ;
@@ -634,10 +634,13 @@ export class DataSchemaCompiler {
634634 return undefined ;
635635 }
636636
637+ // We update the yaml file content to the transpiled js content
638+ // and raise related flag so it will go JS transpilation flow afterward
639+ // avoiding costly YAML/Python parsing again.
637640 private async transpileYamlFile (
638641 file : FileContent ,
639642 errorsReport : ErrorReporter ,
640- { cubeNames, cubeSymbols, contextSymbols , transpilerNames , compilerId, stage } : TranspileOptions
643+ { cubeNames, cubeSymbols, compilerId } : TranspileOptions
641644 ) : Promise < ( FileContent | undefined ) > {
642645 const cacheKey = crypto . createHash ( 'md5' ) . update ( JSON . stringify ( file . content ) ) . digest ( 'hex' ) ;
643646
@@ -648,9 +651,27 @@ export class DataSchemaCompiler {
648651 return { ...file } ;
649652 }
650653
651- /* if (getEnv('transpilationNative')) {
654+ if ( getEnv ( 'transpilationNative' ) ) {
655+ const reqData = {
656+ fileName : file . fileName ,
657+ fileContent : file . content ,
658+ transpilers : [ ] ,
659+ compilerId : compilerId || '' ,
660+ } ;
661+
662+ errorsReport . inFile ( file ) ;
663+ const res = await transpileYaml ( [ reqData ] ) ;
664+ errorsReport . addErrors ( res [ 0 ] . errors ) ;
665+ errorsReport . addWarnings ( res [ 0 ] . warnings as unknown as SyntaxErrorInterface [ ] ) ;
666+ errorsReport . exitFile ( ) ;
667+
668+ file . content = res [ 0 ] . code ;
669+ file . convertedToJs = true ;
670+
671+ this . compiledYamlCache . set ( cacheKey , res [ 0 ] . code ) ;
652672
653- } else */ if ( getEnv ( 'transpilationWorkerThreads' ) ) {
673+ return { ...file } ;
674+ } else if ( getEnv ( 'transpilationWorkerThreads' ) ) {
654675 const data = {
655676 fileName : file . fileName ,
656677 content : file . content ,
@@ -668,14 +689,11 @@ export class DataSchemaCompiler {
668689
669690 this . compiledYamlCache . set ( cacheKey , res . content ) ;
670691
671- return { ...file , content : res . content } ;
692+ return { ...file } ;
672693 } else {
673694 const transpiledFile = this . yamlCompiler . transpileYamlFile ( file , errorsReport ) ;
674695
675696 if ( transpiledFile ) {
676- // We update the yaml file content to the transpiled js content
677- // and raise related flag so it will go JS transpilation flow afterward
678- // avoiding costly YAML/Python parsing again.
679697 file . content = transpiledFile . content ;
680698 file . convertedToJs = true ;
681699 }
0 commit comments