From de8122070a674ccd5bf9a8585acbbe358867768e Mon Sep 17 00:00:00 2001 From: DieMyst Date: Mon, 12 Jun 2023 16:17:42 +0200 Subject: [PATCH 1/2] make compilation to js\ts works with files without exports --- .../.js/src/main/scala/api/AquaAPI.scala | 88 ++++++++----------- 1 file changed, 35 insertions(+), 53 deletions(-) diff --git a/api/aqua-api/.js/src/main/scala/api/AquaAPI.scala b/api/aqua-api/.js/src/main/scala/api/AquaAPI.scala index daa83963a..61ba53d0d 100644 --- a/api/aqua-api/.js/src/main/scala/api/AquaAPI.scala +++ b/api/aqua-api/.js/src/main/scala/api/AquaAPI.scala @@ -71,17 +71,18 @@ object AquaAPI extends App with Logging { .map(cjs => AquaConfig.fromJS(cjs)) .getOrElse( validNec(AquaAPIConfig()) - ).map { config => - val importsList = imports.toList + ) + .map { config => + val importsList = imports.toList - input match { - case i: (types.Input | types.Path) => - compileAll(i, importsList, config) - case c: types.Call => - compileCall(c, importsList, config) + input match { + case i: (types.Input | types.Path) => + compileAll(i, importsList, config) + case c: types.Call => + compileCall(c, importsList, config) - } - } match { + } + } match { case Valid(v) => v.unsafeToFuture().toJSPromise case Invalid(errs) => js.Promise.resolve(CompilationResult.errs(errs.toChain.toList)) } @@ -100,15 +101,15 @@ object AquaAPI extends App with Logging { } extension (res: IO[ValidatedNec[String, Chain[AquaCompiled[FileModuleId]]]]) - def toResult: IO[CompilationResult] = res.map( - _.andThen { compiled => + def toResult: IO[CompilationResult] = res.map { compiledV => + compiledV.map { compiled => config.targetType match { - case AirType => validNec(generatedToAirResult(compiled)) + case AirType => generatedToAirResult(compiled) case TypeScriptType => compiledToTsSourceResult(compiled) case JavaScriptType => compiledToJsSourceResult(compiled) } }.leftMap(errorsToResult).merge - ) + } input match { case i: types.Input => @@ -161,55 +162,36 @@ object AquaAPI extends App with Logging { CompilationResult.errs(errors.toChain.toList) } - private def findBySuffix( - compiled: Seq[Generated], - suffix: String, - errorMsg: String - ): ValidatedNec[String, String] = { - Validated - .fromOption( - compiled.find(_.suffix == suffix).map(_.content), { - logger.error(errorMsg) - NonEmptyChain.one(errorMsg) - } - ) - } + extension (res: List[GeneratedSource]) - extension (res: Chain[Validated[NonEmptyChain[String], GeneratedSource]]) - def toSourcesResult: ValidatedNec[String, CompilationResult] = - res.sequence.map(_.toList.toJSArray).map(sources => CompilationResult.result(sources = sources)) + def toSourcesResult: CompilationResult = + CompilationResult.result(sources = res.toJSArray) private def compiledToTsSourceResult( compiled: Chain[AquaCompiled[FileModuleId]] - ): ValidatedNec[String, CompilationResult] = { - compiled.map { c => - findBySuffix( - c.compiled, - TypeScriptBackend.ext, - "Unreachable. TypeScript backend must generate content." + ): CompilationResult = + compiled.toList + .flatMap(c => + c.compiled + .find(_.suffix == TypeScriptBackend.ext) + .map(_.content) + .map(GeneratedSource.tsSource(c.sourceId.toString, _)) ) - .map(GeneratedSource.tsSource(c.sourceId.toString, _)) - }.toSourcesResult - } + .toSourcesResult private def compiledToJsSourceResult( compiled: Chain[AquaCompiled[FileModuleId]] - ): ValidatedNec[String, CompilationResult] = { - compiled.map { c => - findBySuffix( - c.compiled, - JavaScriptBackend.dtsExt, - "Unreachable. JavaScript backend must generate '.d.ts' content." - ).andThen { tsTypes => - findBySuffix( - c.compiled, - JavaScriptBackend.ext, - "Unreachable. JavaScript backend must generate '.js' content." - ).map(jsSource => GeneratedSource.jsSource(c.sourceId.toString, jsSource, tsTypes)) - } - + ): CompilationResult = + compiled.toList.flatMap { c => + for { + dtsContent <- c.compiled + .find(_.suffix == JavaScriptBackend.dtsExt) + .map(_.content) + jsContent <- c.compiled + .find(_.suffix == JavaScriptBackend.dtsExt) + .map(_.content) + } yield GeneratedSource.jsSource(c.sourceId.toString, jsContent, dtsContent) }.toSourcesResult - } private def generatedToAirResult( compiled: Chain[AquaCompiled[FileModuleId]] From 52526d7c9a4aa4ebe0dfa2d69be0a3281f787810 Mon Sep 17 00:00:00 2001 From: Anatoly Laskaris Date: Mon, 12 Jun 2023 17:45:26 +0300 Subject: [PATCH 2/2] Do not run fluence-cli checks --- .github/workflows/e2e.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ad6c423d5..c46abed5a 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -46,12 +46,6 @@ jobs: with: aqua-version: "${{ needs.aqua.outputs.aqua-version }}" - fluence-cli: - needs: aqua - uses: fluencelabs/fluence-cli/.github/workflows/tests.yml@main - with: - aqua-version: "${{ needs.aqua.outputs.aqua-version }}" - aqua-native: name: "aqua" strategy: