diff --git a/.github/workflows/publish-gitea.yaml b/.github/workflows/publish-gitea.yaml new file mode 100644 index 0000000000..51b9c53bbd --- /dev/null +++ b/.github/workflows/publish-gitea.yaml @@ -0,0 +1,32 @@ +name: Publish npm package to gitea +on: + release: + types: [published] +jobs: + npm_publish: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [ 16.x ] + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: yarn + - name: Run yarn build + run: | + yarn build + - name: Configure git.vdb.to npm registry + run: | + npm config set registry https://git.vdb.to/api/packages/cerc-io/npm/ + - name: Authenticate to git.vdb.to registry + run: | + npm config set -- '//git.vdb.to/api/packages/cerc-io/npm/:_authToken' "${{ secrets.GITEA_PUBLISH_TOKEN }}" + - name: npm publish + run: | + npm publish diff --git a/lib/loader/index.d.ts b/lib/loader/index.d.ts index ce2dc2ef3a..40977b5a19 100644 --- a/lib/loader/index.d.ts +++ b/lib/loader/index.d.ts @@ -85,20 +85,20 @@ export interface ASUtil { /** Tests whether a managed object is an instance of the class represented by the specified base id. */ __instanceof(ptr: number, baseId: number): boolean; /** Allocates a new string in the module's memory and returns a reference (pointer) to it. */ - __newString(str: string): number; + __newString(str: string): Promise; /** Allocates a new ArrayBuffer in the module's memory and returns a reference (pointer) to it. */ - __newArrayBuffer(buf: ArrayBuffer): number; + __newArrayBuffer(buf: ArrayBuffer): Promise; /** Allocates a new array in the module's memory and returns a reference (pointer) to it. */ - __newArray(id: number, values: ArrayLike): number; + __newArray(id: number, values: ArrayLike): Promise; /** Allocates an instance of the class represented by the specified id. */ - __new(size: number, id: number): number; + __new(size: number, id: number): Promise; /** Pins a managed object externally, preventing it from becoming garbage collected. */ - __pin(ptr: number): number; + __pin(ptr: number): Promise; /** Unpins a managed object externally, allowing it to become garbage collected. */ - __unpin(ptr: number): void; + __unpin(ptr: number): Promise; /** Performs a full garbage collection cycle. */ - __collect(incremental?: boolean): void; + __collect(incremental?: boolean): Promise; } /** Asynchronously instantiates an AssemblyScript module from anything that can be instantiated. */ diff --git a/lib/loader/index.js b/lib/loader/index.js index f0bfca90fa..d015390466 100644 --- a/lib/loader/index.js +++ b/lib/loader/index.js @@ -1,3 +1,5 @@ +import { instantiate as asyncInstantiate } from 'asyncify-wasm'; + // Runtime header offsets const ID_OFFSET = -8; const SIZE_OFFSET = -4; @@ -139,10 +141,10 @@ function postInstantiate(extendedExports, instance) { // } /** Allocates a new string in the module's memory and returns its pointer. */ - function __newString(str) { + async function __newString(str) { if (str == null) return 0; const length = str.length; - const ptr = __new(length << 1, STRING_ID); + const ptr = await __new(length << 1, STRING_ID); const U16 = new Uint16Array(memory.buffer); for (var i = 0, p = ptr >>> 1; i < length; ++i) U16[p + i] = str.charCodeAt(i); return ptr; @@ -193,18 +195,18 @@ function postInstantiate(extendedExports, instance) { } /** Allocates a new array in the module's memory and returns its pointer. */ - function __newArray(id, values) { + async function __newArray(id, values) { const info = getArrayInfo(id); const align = getValueAlign(info); const length = values.length; - const buf = __new(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID); + const buf = await __new(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID); let result; if (info & STATICARRAY) { result = buf; } else { - __pin(buf); - const arr = __new(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id); - __unpin(buf); + await __pin(buf); + const arr = await __new(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id); + await __unpin(buf); const U32 = new Uint32Array(memory.buffer); U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = buf; U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2] = buf; @@ -338,7 +340,7 @@ export async function instantiate(source, imports = {}) { if (isResponse(source = await source)) return instantiateStreaming(source, imports); const module = isModule(source) ? source : await WebAssembly.compile(source); const extended = preInstantiate(imports); - const instance = await WebAssembly.instantiate(module, imports); + const instance = await asyncInstantiate(module, imports); const exports = postInstantiate(extended, instance); return { module, instance, exports }; } @@ -395,6 +397,9 @@ export function demangle(exports, extendedExports = {}) { ctor.prototype = { valueOf() { return this[THIS]; } }; + ctor.__new = async function(...args) { + return ctor.wrap(await ctor.prototype.constructor(0, ...args)); + }; ctor.wrap = function(thisValue) { return Object.create(ctor.prototype, { [THIS]: { value: thisValue, writable: false } }); }; diff --git a/lib/loader/package.json b/lib/loader/package.json index 2092906ae5..f6d8dc4834 100644 --- a/lib/loader/package.json +++ b/lib/loader/package.json @@ -46,5 +46,8 @@ ], "devDependencies": { "esm2umd": "^0.1.2" + }, + "dependencies": { + "asyncify-wasm": "^1.2.1" } } diff --git a/lib/loader/umd/index.js b/lib/loader/umd/index.js index 44a6fe11a0..134cc953d8 100644 --- a/lib/loader/umd/index.js +++ b/lib/loader/umd/index.js @@ -10,6 +10,9 @@ var loader = (function(exports) { exports.instantiateStreaming = instantiateStreaming; exports.demangle = demangle; exports.default = void 0; + + var _asyncifyWasm = require("asyncify-wasm"); + // Runtime header offsets const ID_OFFSET = -8; const SIZE_OFFSET = -4; // Runtime ids @@ -171,12 +174,10 @@ var loader = (function(exports) { /** Allocates a new string in the module's memory and returns its pointer. */ - function __newString(str) { + async function __newString(str) { if (str == null) return 0; const length = str.length; - - const ptr = __new(length << 1, STRING_ID); - + const ptr = await __new(length << 1, STRING_ID); const U16 = new Uint16Array(memory.buffer); for (var i = 0, p = ptr >>> 1; i < length; ++i) U16[p + i] = str.charCodeAt(i); @@ -230,24 +231,19 @@ var loader = (function(exports) { /** Allocates a new array in the module's memory and returns its pointer. */ - function __newArray(id, values) { + async function __newArray(id, values) { const info = getArrayInfo(id); const align = getValueAlign(info); const length = values.length; - - const buf = __new(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID); - + const buf = await __new(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID); let result; if (info & STATICARRAY) { result = buf; } else { - __pin(buf); - - const arr = __new(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id); - - __unpin(buf); - + await __pin(buf); + const arr = await __new(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id); + await __unpin(buf); const U32 = new Uint32Array(memory.buffer); U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = buf; U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2] = buf; @@ -377,7 +373,7 @@ var loader = (function(exports) { if (isResponse(source = await source)) return instantiateStreaming(source, imports); const module = isModule(source) ? source : await WebAssembly.compile(source); const extended = preInstantiate(imports); - const instance = await WebAssembly.instantiate(module, imports); + const instance = await (0, _asyncifyWasm.instantiate)(module, imports); const exports = postInstantiate(extended, instance); return { module, @@ -455,6 +451,10 @@ var loader = (function(exports) { }; + ctor.__new = async function (...args) { + return ctor.wrap(await ctor.prototype.constructor(0, ...args)); + }; + ctor.wrap = function (thisValue) { return Object.create(ctor.prototype, { [THIS]: { diff --git a/package-lock.json b/package-lock.json index 403438e4fe..7b2abfb5b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,15 @@ { "name": "assemblyscript", - "version": "0.0.0", + "version": "0.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.0.0", + "name": "assemblyscript", + "version": "0.0.1", "license": "Apache-2.0", "dependencies": { + "asyncify-wasm": "^1.2.1", "binaryen": "101.0.0-nightly.20210723", "long": "^4.0.0", "source-map-support": "^0.5.19", @@ -712,6 +714,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -725,6 +728,11 @@ "node": ">=8" } }, + "node_modules/asyncify-wasm": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/asyncify-wasm/-/asyncify-wasm-1.2.1.tgz", + "integrity": "sha512-ZS7tZ8H8EVbUxAZnkKHvMt9UkYoALue2jwrVl7cnLByjq+1MRrbq7rL5TS+EHQduwkfXD/cNZNa+I0ZyLEBBRQ==" + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -787,7 +795,8 @@ "node_modules/buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true }, "node_modules/callsites": { "version": "3.1.0", @@ -1813,7 +1822,8 @@ "node_modules/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", - "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true }, "node_modules/merge-stream": { "version": "2.0.0", @@ -1888,12 +1898,14 @@ "node_modules/minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true }, "node_modules/mkdirp": { "version": "0.5.5", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dev": true, "dependencies": { "minimist": "^1.2.5" }, @@ -2430,6 +2442,7 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -2438,6 +2451,7 @@ "version": "0.5.19", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "dev": true, "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -2647,6 +2661,7 @@ "version": "6.2.0", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-6.2.0.tgz", "integrity": "sha512-ZNT+OEGfUNVMGkpIaDJJ44Zq3Yr0bkU/ugN1PHbU+/01Z7UV1fsELRiTx1KuQNvQ1A3pGh3y25iYF6jXgxV21A==", + "dev": true, "dependencies": { "arrify": "^1.0.0", "buffer-from": "^1.1.0", @@ -2668,6 +2683,7 @@ "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true, "engines": { "node": ">=0.3.1" } @@ -2941,6 +2957,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=", + "dev": true, "engines": { "node": ">=4" } @@ -3482,7 +3499,8 @@ "arrify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=" + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true }, "astral-regex": { "version": "2.0.0", @@ -3490,6 +3508,11 @@ "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", "dev": true }, + "asyncify-wasm": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/asyncify-wasm/-/asyncify-wasm-1.2.1.tgz", + "integrity": "sha512-ZS7tZ8H8EVbUxAZnkKHvMt9UkYoALue2jwrVl7cnLByjq+1MRrbq7rL5TS+EHQduwkfXD/cNZNa+I0ZyLEBBRQ==" + }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -3536,7 +3559,8 @@ "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true }, "callsites": { "version": "3.1.0", @@ -4325,7 +4349,8 @@ "make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", - "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true }, "merge-stream": { "version": "2.0.0", @@ -4382,12 +4407,14 @@ "minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true }, "mkdirp": { "version": "0.5.5", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dev": true, "requires": { "minimist": "^1.2.5" } @@ -4754,12 +4781,14 @@ "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true }, "source-map-support": { "version": "0.5.19", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "dev": true, "requires": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -4916,6 +4945,7 @@ "version": "6.2.0", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-6.2.0.tgz", "integrity": "sha512-ZNT+OEGfUNVMGkpIaDJJ44Zq3Yr0bkU/ugN1PHbU+/01Z7UV1fsELRiTx1KuQNvQ1A3pGh3y25iYF6jXgxV21A==", + "dev": true, "requires": { "arrify": "^1.0.0", "buffer-from": "^1.1.0", @@ -4930,7 +4960,8 @@ "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==" + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true } } }, @@ -5119,7 +5150,8 @@ "yn": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", - "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=" + "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=", + "dev": true }, "yocto-queue": { "version": "0.1.0", diff --git a/package.json b/package.json index 3567e682e3..a3b189f2d3 100644 --- a/package.json +++ b/package.json @@ -8,19 +8,20 @@ "assemblyscript", "wasm" ], - "version": "0.0.0", + "version": "0.0.1", "author": "Daniel Wirtz ", "contributors": [], "license": "Apache-2.0", "homepage": "https://assemblyscript.org", "repository": { "type": "git", - "url": "https://github.com/AssemblyScript/assemblyscript.git" + "url": "https://github.com/vulcanize/assemblyscript.git" }, "bugs": { "url": "https://github.com/AssemblyScript/assemblyscript/issues" }, "dependencies": { + "asyncify-wasm": "^1.2.1", "binaryen": "101.0.0-nightly.20210723", "long": "^4.0.0", "source-map-support": "^0.5.19", @@ -128,5 +129,8 @@ "funding": { "type": "opencollective", "url": "https://opencollective.com/assemblyscript" + }, + "publishConfig": { + "registry": "https://git.vdb.to/api/packages/cerc-io/npm/" } }