feat(aqua-api): Use scala.js link instead of opt (#891)

* Add link settings

* fix

* Rename to api-dist-js

* Correct import

* Update CI

---------

Co-authored-by: Artsiom Shamsutdzinau <shamsartem@gmail.com>
This commit is contained in:
InversionSpaces 2023-09-15 15:42:04 +02:00 committed by GitHub
parent 6be2a3d5da
commit 3f916c78ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 51 additions and 93 deletions

View File

@ -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

View File

@ -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

View File

@ -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

3
.gitignore vendored
View File

@ -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/*

View File

@ -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<string, ServiceDef>;
functions: Record<string, AquaFunction>;
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<CompilationResult>;
}
export var Aqua: Compiler;

View File

@ -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<string, ServiceDef>;
functions: Record<string, AquaFunction>;
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<Omit<CompilationResult, 'funcCall'>>
export declare function compileFromString(
args: CommonArgs & CodeString,
): Promise<Omit<CompilationResult, "funcCall">>;
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<Omit<CompilationResult, 'funcCall'>>
export declare function compileFromPath(
args: CommonArgs & FilePath,
): Promise<Omit<CompilationResult, "funcCall">>;
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<string, unknown> | undefined;
}
};
/** Compile aqua function call from a string */
export declare function compileAquaCallFromString(args: CommonArgs & CodeString & FuncCall): Promise<Required<CompilationResult>>
export declare function compileAquaCallFromString(
args: CommonArgs & CodeString & FuncCall,
): Promise<Required<CompilationResult>>;
/** Compile aqua function call from a file */
export declare function compileAquaCallFromPath(args: CommonArgs & FilePath & FuncCall): Promise<Required<CompilationResult>>
export declare function compileAquaCallFromPath(
args: CommonArgs & FilePath & FuncCall,
): Promise<Required<CompilationResult>>;
export {}
export {};

View File

@ -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 = [],

View File

@ -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": {},

View File

@ -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`)

View File

@ -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
}