@@ -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' ;
@@ -630,10 +630,13 @@ export class DataSchemaCompiler {
630630 return undefined ;
631631 }
632632
633+ // We update the yaml file content to the transpiled js content
634+ // and raise related flag so it will go JS transpilation flow afterward
635+ // avoiding costly YAML/Python parsing again.
633636 private async transpileYamlFile (
634637 file : FileContent ,
635638 errorsReport : ErrorReporter ,
636- { cubeNames, cubeSymbols, contextSymbols , transpilerNames , compilerId, stage } : TranspileOptions
639+ { cubeNames, cubeSymbols, compilerId } : TranspileOptions
637640 ) : Promise < ( FileContent | undefined ) > {
638641 const cacheKey = crypto . createHash ( 'md5' ) . update ( JSON . stringify ( file . content ) ) . digest ( 'hex' ) ;
639642
@@ -644,9 +647,27 @@ export class DataSchemaCompiler {
644647 return { ...file } ;
645648 }
646649
647- /* if (getEnv('transpilationNative')) {
650+ if ( getEnv ( 'transpilationNative' ) ) {
651+ const reqData = {
652+ fileName : file . fileName ,
653+ fileContent : file . content ,
654+ transpilers : [ ] ,
655+ compilerId : compilerId || '' ,
656+ } ;
657+
658+ errorsReport . inFile ( file ) ;
659+ const res = await transpileYaml ( [ reqData ] ) ;
660+ errorsReport . addErrors ( res [ 0 ] . errors ) ;
661+ errorsReport . addWarnings ( res [ 0 ] . warnings as unknown as SyntaxErrorInterface [ ] ) ;
662+ errorsReport . exitFile ( ) ;
663+
664+ file . content = res [ 0 ] . code ;
665+ file . convertedToJs = true ;
666+
667+ this . compiledYamlCache . set ( cacheKey , res [ 0 ] . code ) ;
648668
649- } else */ if ( getEnv ( 'transpilationWorkerThreads' ) ) {
669+ return { ...file } ;
670+ } else if ( getEnv ( 'transpilationWorkerThreads' ) ) {
650671 const data = {
651672 fileName : file . fileName ,
652673 content : file . content ,
@@ -664,14 +685,11 @@ export class DataSchemaCompiler {
664685
665686 this . compiledYamlCache . set ( cacheKey , res . content ) ;
666687
667- return { ...file , content : res . content } ;
688+ return { ...file } ;
668689 } else {
669690 const transpiledFile = this . yamlCompiler . transpileYamlFile ( file , errorsReport ) ;
670691
671692 if ( transpiledFile ) {
672- // We update the yaml file content to the transpiled js content
673- // and raise related flag so it will go JS transpilation flow afterward
674- // avoiding costly YAML/Python parsing again.
675693 file . content = transpiledFile . content ;
676694 file . convertedToJs = true ;
677695 }
0 commit comments