Skip to content

Commit 9bd3fe1

Browse files
authored
feat: upgrade dependencies (assemblyscript, loader, as-bind) (#24)
BREAKING CHANGE: require Node >= 14 (because of as-bind update)
1 parent ce3e272 commit 9bd3fe1

File tree

15 files changed

+1714
-3440
lines changed

15 files changed

+1714
-3440
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module.exports = {
3232
files: ["test/e2e/fixtures/**/*.ts"],
3333
rules: {
3434
"node/no-missing-import": "off",
35+
"node/no-extraneous-import": "off"
3536
},
3637
},
3738
],

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
needs: build
4646
strategy:
4747
matrix:
48-
node: [12, 14]
48+
node: [14, 16]
4949
os: [ubuntu-latest, macos-latest, windows-latest]
5050
steps:
5151
- uses: actions/checkout@v1
@@ -100,7 +100,7 @@ jobs:
100100
- name: Setup node
101101
uses: actions/setup-node@v1
102102
with:
103-
node-version: 12
103+
node-version: 14
104104

105105
- name: Get yarn cache
106106
id: yarn-cache

.husky/pre-commit

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn build
5+
yarn lint
6+
yarn test unit

README.md

+3-13
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,6 @@ export interface BoundWasmModuleInstance<TModule, TImports> {
181181
importObject: TImports;
182182
module: WebAssembly.Module;
183183
instance: WebAssembly.Instance;
184-
enableExportFunctionTypeCaching(): void;
185-
disableExportFunctionTypeCaching(): void;
186-
enableExportFunctionUnsafeReturnValue(): void;
187-
disableExportFunctionUnsafeReturnValue(): void;
188-
enableImportFunctionTypeCaching(): void;
189-
disableImportFunctionTypeCaching(): void;
190184
}
191185
192186
export interface JsModuleInstance<TModule> {
@@ -205,8 +199,6 @@ export function instantiate<TModule, TImports>(
205199
fallback: boolean = false,
206200
supports?: () => boolean
207201
): Promise<BoundModuleInstance<TModule, TImports>>
208-
209-
export const RETURN_TYPES: AsBindReturnTypes;
210202
```
211203

212204
<details>
@@ -220,14 +212,12 @@ export function sayHello(firstName: string, lastName: string): string {
220212
221213
// ./src/sayHello.ts
222214
import * as sayHelloModule from "./assembly/sayHello";
223-
import { instantiate, RETURN_TYPES } from "as-loader/runtime/bind";
215+
import { instantiate } from "as-loader/runtime/bind";
224216
225217
export async function loadModule(): Promise<typeof sayHelloModule> {
226-
const { exports } = await instantiate(sayHelloModule, fetch);
227-
const { sayHello } = exports;
228-
sayHello.returnType = RETURN_TYPES.STRING;
218+
const module = await instantiate(sayHelloModule, fetch);
229219
230-
return { sayHello };
220+
return { sayHello: module.exports.sayHello };
231221
}
232222
```
233223

package.json

+24-27
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,43 @@
1717
"build": "tsc",
1818
"lint": "eslint src test",
1919
"test": "jest",
20-
"release": "auto shipit"
20+
"release": "auto shipit",
21+
"prepare": "husky install"
2122
},
2223
"files": [
2324
"loader/*",
2425
"runtime/*"
2526
],
2627
"peerDependencies": {
27-
"assemblyscript": "~0.18.0",
28+
"assemblyscript": "^0.19.0",
2829
"webpack": "^4.0.0 || ^5.0.0"
2930
},
3031
"dependencies": {
31-
"@assemblyscript/loader": "~0.18.0",
32-
"as-bind": "^0.6.0",
32+
"@assemblyscript/loader": "^0.19.0",
33+
"as-bind": "^0.8.0",
3334
"loader-utils": "^2.0.0",
34-
"schema-utils": "^3.0.0"
35+
"schema-utils": "^3.1.1"
3536
},
3637
"devDependencies": {
37-
"@types/loader-utils": "^2.0.1",
38-
"@types/webpack": "^4.0.0",
39-
"@typescript-eslint/eslint-plugin": "^4.15.1",
40-
"@typescript-eslint/parser": "^4.15.1",
41-
"assemblyscript": "^0.18.0",
42-
"auto": "^10.16.5",
43-
"eslint": "^7.20.0",
44-
"eslint-config-prettier": "^8.0.0",
38+
"@types/jest": "^26.0.24",
39+
"@types/loader-utils": "^2.0.3",
40+
"@types/webpack": "^5.28.0",
41+
"@typescript-eslint/eslint-plugin": "^4.29.0",
42+
"@typescript-eslint/parser": "^4.29.0",
43+
"assemblyscript": "^0.19.0",
44+
"auto": "^10.30.0",
45+
"eslint": "^7.32.0",
46+
"eslint-config-prettier": "^8.3.0",
4547
"eslint-plugin-node": "^11.1.0",
46-
"eslint-plugin-prettier": "^3.3.1",
47-
"husky": "^4.0.0",
48-
"jest": "^26.6.3",
48+
"eslint-plugin-prettier": "^3.4.0",
49+
"husky": "^7.0.0",
50+
"jest": "^27.0.6",
4951
"karton": "^0.4.1",
50-
"lint-staged": "^10.5.4",
51-
"prettier": "^2.2.1",
52-
"ts-jest": "^26.5.1",
53-
"typescript": "^4.1.5",
54-
"webpack": "^4.0.0"
52+
"lint-staged": "^11.1.2",
53+
"prettier": "^2.3.2",
54+
"ts-jest": "^27.0.4",
55+
"typescript": "^4.3.5",
56+
"webpack": "^5.0.0"
5557
},
5658
"auto": {
5759
"plugins": [
@@ -62,11 +64,6 @@
6264
"noChangelog": true
6365
}
6466
},
65-
"husky": {
66-
"hooks": {
67-
"pre-commit": "lint-staged && yarn build"
68-
}
69-
},
7067
"lint-staged": {
7168
"*.ts": "eslint --fix"
7269
},
@@ -75,6 +72,6 @@
7572
"testEnvironment": "node"
7673
},
7774
"engines": {
78-
"node": ">=12"
75+
"node": ">=14"
7976
}
8077
}

src/loader/compiler-host.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import path from "path";
22
import asc, { DiagnosticMessage, APIOptions } from "assemblyscript/cli/asc";
33

4-
type CompilerHost = Required<APIOptions> & {
4+
type CompilerHost = Required<
5+
Pick<
6+
APIOptions,
7+
| "stdout"
8+
| "stderr"
9+
| "readFile"
10+
| "writeFile"
11+
| "listFiles"
12+
| "reportDiagnostic"
13+
>
14+
> & {
515
getDiagnostics(): DiagnosticMessage[];
616
};
717

src/loader/index.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function loader(this: any, buffer: Buffer) {
6868
if (bind && name.endsWith(".wasm")) {
6969
// overwrite options for bind
7070
ascOptions.exportRuntime = true;
71+
ascOptions.transform = "as-bind";
7172
}
7273

7374
if (name.endsWith(".js")) {
@@ -109,10 +110,6 @@ function loader(this: any, buffer: Buffer) {
109110
outFileName,
110111
...mapAscOptionsToArgs(ascOptions),
111112
];
112-
if (bind && name.endsWith(".wasm")) {
113-
// add required by as-bind file to compilation
114-
args.unshift(require.resolve("as-bind/lib/assembly/as-bind.ts"));
115-
}
116113

117114
asc.ready
118115
.then(() => {

src/runtime/bind.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import type { Imports } from "@assemblyscript/loader";
2-
import { AsBind } from "as-bind";
2+
import * as AsBind from "as-bind";
33
import type {
44
BoundWasmModuleInstance,
55
JsModuleInstance,
66
BoundModuleInstance,
77
AsLoaderModule,
88
} from "./types";
99
import { context } from "./context";
10-
import { AsBindReturnTypes } from "./types/ref-types";
1110
import "./types/std";
1211

1312
async function instantiate<
@@ -46,6 +45,8 @@ async function instantiate<
4645
// WebAssembly is supported
4746
return {
4847
type: "wasm-bound",
48+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
49+
// @ts-ignore - invalid as-bind typings
4950
...(await AsBind.instantiate(load(moduleURL as string), imports)),
5051
};
5152
} else if (fallback && moduleURL.fallback) {
@@ -60,11 +61,8 @@ async function instantiate<
6061
);
6162
}
6263

63-
const RETURN_TYPES: AsBindReturnTypes = AsBind.RETURN_TYPES;
64-
6564
export {
6665
instantiate,
67-
RETURN_TYPES,
6866
Imports,
6967
BoundWasmModuleInstance,
7068
JsModuleInstance,

src/runtime/types/bound.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
PointerCastFunction,
77
PointerCast,
88
} from "./pointer";
9-
import { AsBindReturnTypes, RefType } from "./ref-types";
109

1110
export type BoundNonPointerTypes =
1211
| NonPointerTypes
@@ -30,17 +29,9 @@ export type BoundNonPointerTypes =
3029
| BigInt64Array
3130
| BigUint64Array;
3231

33-
export type BoundFunction<T extends (...args: any) => any> = T extends (
34-
...args: any
35-
) => infer R
36-
? PointerCastFunction<T, BoundNonPointerTypes> & {
37-
shouldCacheTypes?: boolean;
38-
returnType?: R extends NonPointerTypes
39-
? AsBindReturnTypes["NUMBER"]
40-
: RefType<R>;
41-
unsafeReturnValue?: boolean;
42-
}
43-
: never;
32+
export type BoundFunction<T extends (...args: any) => any> =
33+
PointerCastFunction<T, BoundNonPointerTypes>;
34+
4435
export type BoundExports<T extends Record<any, any>> = T extends Record<
4536
string | symbol | number,
4637
any

src/runtime/types/index.ts

-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ export interface BoundWasmModuleInstance<TModule, TImports> {
1919
importObject: TImports;
2020
module: WebAssembly.Module;
2121
instance: WebAssembly.Instance;
22-
enableExportFunctionTypeCaching(): void;
23-
disableExportFunctionTypeCaching(): void;
24-
enableExportFunctionUnsafeReturnValue(): void;
25-
disableExportFunctionUnsafeReturnValue(): void;
26-
enableImportFunctionTypeCaching(): void;
27-
disableImportFunctionTypeCaching(): void;
2822
}
2923
export interface JsModuleInstance<TModule> {
3024
type: "js";

src/runtime/types/ref-types.ts

-55
This file was deleted.

src/runtime/types/std.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
13
// Types
24
declare type bool = boolean;
35
declare type i8 = number;

test/e2e/fixtures/main/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"dist/*"
1111
],
1212
"dependencies": {
13-
"assemblyscript": "0.18.11",
14-
"@assemblyscript/loader": "0.18.11",
13+
"assemblyscript": "0.19.10",
1514
"ts-loader": "8.0.17",
1615
"typescript": "4.2.2",
1716
"webpack": "4.46.0",

test/e2e/fixtures/main/src/bind.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as fs from 'fs';
2-
import { instantiate, RETURN_TYPES } from "as-loader/runtime/bind";
2+
import { instantiate } from "as-loader/runtime/bind";
33

44
import * as assembly from "./assembly/correct/bind";
55

@@ -10,7 +10,6 @@ async function loadAndRun() {
1010
);
1111

1212
const { hello } = module.exports;
13-
hello.returnType = RETURN_TYPES.STRING;
1413

1514
console.log(hello('world'));
1615
}

0 commit comments

Comments
 (0)