diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ba27b986..b379e69b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -41,7 +41,7 @@ jobs: apps: sbt - name: scala-js build - run: sbt ";language-server-apiJS/fullOptJS;aqua-apiJS/fullOptJS" + run: sbt ";language-server-apiJS/fullOptJS;aqua-apiJS/fullLinkJS" - name: Import secrets uses: hashicorp/vault-action@v2.7.3 diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 27873d21..075b54d4 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -51,7 +51,7 @@ jobs: - name: scala-js build env: SNAPSHOT: ${{ steps.version.outputs.id }} - run: sbt ";language-server-apiJS/fastOptJS;aqua-apiJS/fastOptJS" + run: sbt ";language-server-apiJS/fastOptJS;aqua-apiJS/fastLinkJS" - name: Import secrets uses: hashicorp/vault-action@v2.7.3 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 89a77a79..8fe8a35e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -82,7 +82,7 @@ jobs: apps: sbt - name: aqua-api build - run: sbt "aqua-apiJS/fastOptJS" + run: sbt "aqua-apiJS/fastLinkJS" - name: Setup pnpm uses: pnpm/action-setup@v2.4.0 diff --git a/.gitignore b/.gitignore index a9ddc60a..e2219a84 100644 --- a/.gitignore +++ b/.gitignore @@ -9,9 +9,8 @@ project/target .DS_Store -cli/cli-npm/aqua.j* language-server/language-server-npm/aqua-lsp-api.j* -api/api-npm/aqua-api.j* +api/api-npm/api-dist-js integration-tests/src/compiled/* diff --git a/api/api-npm/aqua-api.d.ts b/api/api-npm/aqua-api.d.ts deleted file mode 100644 index c47922e7..00000000 --- a/api/api-npm/aqua-api.d.ts +++ /dev/null @@ -1,69 +0,0 @@ -import type { FunctionCallDef, ServiceDef } from "@fluencelabs/interfaces"; - -export class AquaConfig { - constructor( - logLevel?: string, - constants?: string[], - noXor?: boolean, - noRelay?: boolean, - targetType?: string, - tracing?: boolean, - ); - - logLevel?: string; - constants?: string[]; - noXor?: boolean; - noRelay?: boolean; - targetType?: string; - tracing?: boolean; -} - -export class AquaFunction { - funcDef: FunctionCallDef; - script: string; -} - -export class GeneratedSource { - name: string; - tsSource?: string; - jsSource?: string; - tsTypes?: string; -} - -export class CompilationResult { - services: Record; - functions: Record; - functionCall?: AquaFunction; - errors: string[]; - generatedSources: GeneratedSource[]; -} - -export class Input { - constructor(input: string); - - input: string; -} - -export class Path { - constructor(path: string); - - path: string; -} - -export class Call { - constructor(functionCall: string, arguments: any, input: Input | Path); - - functionCall: string; - arguments: any; - input: Input | Path; -} - -export class Compiler { - compile( - input: Input | Path | Call, - imports: string[], - config?: AquaConfig, - ): Promise; -} - -export var Aqua: Compiler; diff --git a/api/api-npm/index.d.ts b/api/api-npm/index.d.ts index ab3f15b2..10346ace 100644 --- a/api/api-npm/index.d.ts +++ b/api/api-npm/index.d.ts @@ -1,4 +1,24 @@ -import { type CompilationResult } from "./aqua-api.js"; +import { ServiceDef, FunctionCallDef } from "@fluencelabs/interfaces"; + +class AquaFunction { + funcDef: FunctionCallDef; + script: string; +} + +class GeneratedSource { + name: string; + tsSource?: string; + jsSource?: string; + tsTypes?: string; +} + +class CompilationResult { + services: Record; + functions: Record; + functionCall?: AquaFunction; + errors: string[]; + generatedSources: GeneratedSource[]; +} /** Common arguments for all compile functions */ type CommonArgs = { @@ -21,30 +41,38 @@ type CommonArgs = { type CodeString = { /** Aqua code to be compiled */ code: string; -} +}; /** Compile aqua code from a string */ -export declare function compileFromString(args: CommonArgs & CodeString): Promise> +export declare function compileFromString( + args: CommonArgs & CodeString, +): Promise>; type FilePath = { /** Path to the aqua file to be compiled */ filePath: string; -} +}; /** Compile aqua code from a file */ -export declare function compileFromPath(args: CommonArgs & FilePath): Promise> +export declare function compileFromPath( + args: CommonArgs & FilePath, +): Promise>; type FuncCall = { /** Function call you want to compile. Example: someFunc("someArg") */ funcCall: string; /** Args to be passed to the function (record with keys named as args you want to pass to the function) Example: { someArg: 1 } */ data?: Record | undefined; -} +}; /** Compile aqua function call from a string */ -export declare function compileAquaCallFromString(args: CommonArgs & CodeString & FuncCall): Promise> +export declare function compileAquaCallFromString( + args: CommonArgs & CodeString & FuncCall, +): Promise>; /** Compile aqua function call from a file */ -export declare function compileAquaCallFromPath(args: CommonArgs & FilePath & FuncCall): Promise> +export declare function compileAquaCallFromPath( + args: CommonArgs & FilePath & FuncCall, +): Promise>; -export {} +export {}; diff --git a/api/api-npm/index.js b/api/api-npm/index.js index 7cad664c..2bb0d9bf 100644 --- a/api/api-npm/index.js +++ b/api/api-npm/index.js @@ -1,5 +1,4 @@ -// @ts-check -import { AquaConfig, Aqua, Call, Input, Path } from "./aqua-api.js"; +import { AquaConfig, Aqua, Call, Input, Path } from "./api-dist-js/main.js"; function getConfig({ constants = [], diff --git a/api/api-npm/package.json b/api/api-npm/package.json index ebdb5560..33b34fc9 100644 --- a/api/api-npm/package.json +++ b/api/api-npm/package.json @@ -7,8 +7,7 @@ "files": [ "index.js", "index.d.ts", - "aqua-api.js", - "aqua-api.d.ts", + "api-dist-js/main.js", "meta-utils.js" ], "prettier": {}, diff --git a/build.sbt b/build.sbt index 0d31110d..d2482776 100644 --- a/build.sbt +++ b/build.sbt @@ -74,6 +74,7 @@ lazy val `language-server-api` = crossProject(JSPlatform, JVMPlatform) lazy val `language-server-apiJS` = `language-server-api`.js .settings( + // TODO: move to fast/fullLinkJS here Compile / fastOptJS / artifactPath := baseDirectory.value / "../../language-server-npm" / "aqua-lsp-api.js", Compile / fullOptJS / artifactPath := baseDirectory.value / "../../language-server-npm" / "aqua-lsp-api.js", scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)), @@ -103,11 +104,11 @@ lazy val `aqua-api` = crossProject(JSPlatform, JVMPlatform) lazy val `aqua-apiJS` = `aqua-api`.js .settings( - Compile / fastOptJS / artifactPath := baseDirectory.value / "../../api-npm" / "aqua-api.js", - Compile / fullOptJS / artifactPath := baseDirectory.value / "../../api-npm" / "aqua-api.js", - scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.ESModule)), - scalaJSUseMainModuleInitializer := true, - Test / test := {} + Compile / fastLinkJS / scalaJSLinkerOutputDirectory := baseDirectory.value / "../../api-npm/api-dist-js", + Compile / fullLinkJS / scalaJSLinkerOutputDirectory := baseDirectory.value / "../../api-npm/api-dist-js", + scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.ESModule)), + scalaJSUseMainModuleInitializer := true, + Test / test := {} ) .enablePlugins(ScalaJSPlugin) .dependsOn(`js-exports`) diff --git a/js/js-imports/src/main/scala/aqua/js/Npm.scala b/js/js-imports/src/main/scala/aqua/js/Npm.scala index e93fc021..d8e15bd0 100644 --- a/js/js-imports/src/main/scala/aqua/js/Npm.scala +++ b/js/js-imports/src/main/scala/aqua/js/Npm.scala @@ -7,8 +7,9 @@ object Meta { // get `import`.meta.url info from javascript // it is needed for `createRequire` function + // TODO: Investigate if it is really needed @js.native - @JSImport("./meta-utils.js", "metaUrl") + @JSImport("../meta-utils.js", "metaUrl") val metaUrl: String = js.native }