Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit d600811

Browse files
author
Akim
authored
feat(npm-aqua-compiler): create package (#401)
* Add npm-aqua-compiler package * Release new package * Remove noUncheckedIndexedAccess from tsconfig.json * Fix a test script * Fix length checks * Fix * Update error description * Try to choose a nicer err message * New import format and API * Fix error message * Improve test * Don't add empty string key when globalImports prop is empty * Fix exports
1 parent ac407c2 commit d600811

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1652
-153
lines changed

.eslintrc.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020
],
2121
"ignorePatterns": ["**/node_modules/", "**/dist/", "**/build/", "**/public/"],
2222
"rules": {
23-
"eqeqeq": [
24-
"error",
25-
"always",
26-
{
27-
"null": "ignore"
28-
}
29-
],
23+
"eqeqeq": ["error", "always"],
3024
"no-console": ["error"],
3125
"arrow-body-style": ["error", "always"],
3226
"no-empty": [

.github/release-please/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"packages/core/js-client-isomorphic": {},
1313
"packages/core/marine-worker": {},
1414
"packages/core/aqua-to-js": {},
15-
"packages/core/interfaces": {}
15+
"packages/core/interfaces": {},
16+
"packages/core/npm-aqua-compiler": {}
1617
}
1718
}

.github/release-please/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"packages/core/marine-worker": "0.5.0",
44
"packages/core/aqua-to-js": "0.3.4",
55
"packages/core/js-client-isomorphic": "0.3.0",
6-
"packages/core/interfaces": "0.9.0"
6+
"packages/core/interfaces": "0.9.0",
7+
"packages/core/npm-aqua-compiler": "0.0.0"
78
}

packages/@tests/smoke/web/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import assert from "node:assert";
1718
import { dirname, join } from "path";
1819
import { fileURLToPath } from "url";
1920

@@ -45,6 +46,8 @@ const test = async () => {
4546
const browser = await puppeteer.launch();
4647
const page = (await browser.pages())[0];
4748

49+
assert(page);
50+
4851
page.on("console", (message) => {
4952
console.log(`${message.type().toUpperCase()}: ${message.text()}`);
5053
});
@@ -77,7 +80,7 @@ const test = async () => {
7780
await browser.close();
7881
await stopServer(localServer);
7982

80-
if (content == null) {
83+
if (content === null || content === undefined) {
8184
throw new Error("smoke test failed!");
8285
}
8386
};

packages/core/aqua-to-js/src/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function genTypeName(
3535
const args =
3636
item.tag === "labeledProduct" ? Object.values(item.fields) : item.items;
3737

38-
if (args.length === 1) {
38+
if (args.length === 1 && "0" in args) {
3939
return genTypeName(args[0], name);
4040
}
4141

@@ -112,7 +112,7 @@ export function typeToTs(t: NonArrowType | ArrowType): string {
112112
const retType =
113113
codomain.tag === "nil"
114114
? "void"
115-
: codomain.items.length === 1
115+
: codomain.items.length === 1 && "0" in codomain.items
116116
? typeToTs(codomain.items[0])
117117
: typeToTs(codomain);
118118

packages/core/aqua-to-js/src/generate/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class TSTypeGenerator implements TypeGenerator {
132132
];
133133

134134
const registerServiceArgs =
135-
srvDef.defaultServiceId == null
135+
srvDef.defaultServiceId === undefined
136136
? functionOverloadsWithoutDefaultServiceId
137137
: functionOverloadsWithDefaultServiceId;
138138

packages/core/aqua-to-js/src/utils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import assert from "assert";
1817
import { readFile } from "fs/promises";
1918
import { join } from "path";
2019

@@ -86,7 +85,7 @@ export function recursiveRenameLaquaProps(obj: JSONValue): unknown {
8685
// Last part of the property separated by "_" is a correct name
8786
const refinedProperty = prop.split("_").pop();
8887

89-
if (refinedProperty == null) {
88+
if (refinedProperty === undefined) {
9089
throw new Error(`Bad property name: ${prop}.`);
9190
}
9291

@@ -95,11 +94,15 @@ export function recursiveRenameLaquaProps(obj: JSONValue): unknown {
9594
}
9695
}
9796

98-
assert(accessProp in obj);
97+
const laquaProp = obj[accessProp];
98+
99+
if (laquaProp === undefined) {
100+
return acc;
101+
}
99102

100103
return {
101104
...acc,
102-
[accessProp]: recursiveRenameLaquaProps(obj[accessProp]),
105+
[accessProp]: recursiveRenameLaquaProps(laquaProp),
103106
};
104107
}, {});
105108
}

packages/core/aqua-to-js/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "../../../tsconfig.json",
33
"compilerOptions": {
4-
"esModuleInterop": true,
54
"resolveJsonModule": true,
65
"outDir": "./dist"
76
},

packages/core/js-client-isomorphic/src/fetchers/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const fetchResource: FetchResourceFn = async (pkg, assetPath) => {
3636

3737
const packagePath = matches?.[0];
3838

39-
if (packagePath == null) {
39+
if (packagePath === undefined) {
4040
throw new Error(`Cannot find dependency ${name} in path ${posixPath}`);
4141
}
4242

packages/core/js-client/src/api.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { fileURLToPath } from "url";
1818

1919
import { compileFromPath } from "@fluencelabs/aqua-api";
2020
import { ServiceDef } from "@fluencelabs/interfaces";
21-
import { describe, expect, it } from "vitest";
21+
import { assert, describe, expect, it } from "vitest";
2222

2323
import { v5_registerService } from "./api.js";
2424
import { callAquaFunction } from "./compilerSupport/callFunction.js";
@@ -65,8 +65,12 @@ describe("User API methods", () => {
6565

6666
const typedServices: Record<string, ServiceDef> = services;
6767

68+
assert("demoCalc" in functions);
69+
6870
const { script } = functions["demoCalc"];
6971

72+
assert("Calc" in typedServices);
73+
7074
v5_registerService([peer, "calc", calcService], {
7175
defaultServiceId: "calc",
7276
functions: typedServices["Calc"].functions,

0 commit comments

Comments
 (0)