diff --git a/.eslintrc.js b/.eslintrc.js index 4894b07432..9343fb6300 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,7 +6,8 @@ const base = require('@polkadot/dev/config/eslint.cjs'); module.exports = { ...base, ignorePatterns: [ - ...base.ignorePatterns + ...base.ignorePatterns, + '**/deno/*.ts' ], parserOptions: { ...base.parserOptions, diff --git a/.github/workflows/pr-any.yml b/.github/workflows/pr-any.yml index ca6d909406..03abe457c8 100644 --- a/.github/workflows/pr-any.yml +++ b/.github/workflows/pr-any.yml @@ -5,14 +5,18 @@ jobs: pr: strategy: matrix: - step: ['lint', 'test', 'build'] + step: ['lint', 'test', 'build', 'deno'] name: ${{ matrix.step }} runs-on: ubuntu-latest env: YARN_ENABLE_SCRIPTS: false steps: - uses: actions/checkout@v2 + - uses: denoland/setup-deno@v1 + with: + deno-version: vx.x.x - name: ${{ matrix.step }} + if: always() run: | yarn install --immutable | grep -v 'YN0013' yarn ${{ matrix.step }} diff --git a/deno/check.ts b/deno/check.ts new file mode 100644 index 0000000000..0e5d9165b7 --- /dev/null +++ b/deno/check.ts @@ -0,0 +1,18 @@ +// Copyright 2019-2022 @polkadot/api authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +// auto-generated via deno/setup.ts, do not edit + +export * as api from 'https://deno.land/x/polkadot/api/mod.ts'; +export * as apiAugment from 'https://deno.land/x/polkadot/api-augment/mod.ts'; +export * as apiBase from 'https://deno.land/x/polkadot/api-base/mod.ts'; +export * as apiContract from 'https://deno.land/x/polkadot/api-contract/mod.ts'; +export * as apiDerive from 'https://deno.land/x/polkadot/api-derive/mod.ts'; +export * as rpcAugment from 'https://deno.land/x/polkadot/rpc-augment/mod.ts'; +export * as rpcCore from 'https://deno.land/x/polkadot/rpc-core/mod.ts'; +export * as rpcProvider from 'https://deno.land/x/polkadot/rpc-provider/mod.ts'; +export * as types from 'https://deno.land/x/polkadot/types/mod.ts'; +export * as typesAugment from 'https://deno.land/x/polkadot/types-augment/mod.ts'; +export * as typesCodec from 'https://deno.land/x/polkadot/types-codec/mod.ts'; +export * as typesCreate from 'https://deno.land/x/polkadot/types-create/mod.ts'; +export * as typesKnown from 'https://deno.land/x/polkadot/types-known/mod.ts'; diff --git a/deno/import_map.json b/deno/import_map.json new file mode 100644 index 0000000000..8e0655cab2 --- /dev/null +++ b/deno/import_map.json @@ -0,0 +1,17 @@ +{ + "imports": { + "https://deno.land/x/polkadot/rpc-core/": "../packages/rpc-core/build-deno/", + "https://deno.land/x/polkadot/types-augment/": "../packages/types-augment/build-deno/", + "https://deno.land/x/polkadot/types-create/": "../packages/types-create/build-deno/", + "https://deno.land/x/polkadot/types/": "../packages/types/build-deno/", + "https://deno.land/x/polkadot/api-base/": "../packages/api-base/build-deno/", + "https://deno.land/x/polkadot/types-known/": "../packages/types-known/build-deno/", + "https://deno.land/x/polkadot/rpc-provider/": "../packages/rpc-provider/build-deno/", + "https://deno.land/x/polkadot/api-augment/": "../packages/api-augment/build-deno/", + "https://deno.land/x/polkadot/api/": "../packages/api/build-deno/", + "https://deno.land/x/polkadot/rpc-augment/": "../packages/rpc-augment/build-deno/", + "https://deno.land/x/polkadot/types-codec/": "../packages/types-codec/build-deno/", + "https://deno.land/x/polkadot/api-contract/": "../packages/api-contract/build-deno/", + "https://deno.land/x/polkadot/api-derive/": "../packages/api-derive/build-deno/" + } +} diff --git a/deno/setup.ts b/deno/setup.ts new file mode 100644 index 0000000000..505b187726 --- /dev/null +++ b/deno/setup.ts @@ -0,0 +1,27 @@ +// Copyright 2017-2022 @polkadot/api authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +/* eslint-disable sort-keys */ + +import { stringCamelCase } from 'https://deno.land/x/polkadot/util/mod.ts'; + +const exports: string[] = []; +const imports: Record = {}; + +for await (const entry of Deno.readDir('packages')) { + if (entry.isDirectory) { + try { + await Deno.readTextFile(`packages/${entry.name}/src/mod.ts`); + + exports.push(`export * as ${stringCamelCase(entry.name)} from 'https://deno.land/x/polkadot/${entry.name}/mod.ts';`); + + imports[`https://deno.land/x/polkadot/${entry.name}/`] = `../packages/${entry.name}/build-deno/`; + } catch { + // ignore + } + } +} + +await Deno.writeTextFile('deno/check.ts', `// Copyright 2017-${new Date().getFullYear()} @polkadot/api authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\n// auto-generated via deno/setup.ts, do not edit\n\n${exports.sort().join('\n')}\n`); + +await Deno.writeTextFile('deno/import_map.json', `${JSON.stringify({ imports }, null, 2)}\n`); diff --git a/package.json b/package.json index d7f37dc149..a7526d5ed8 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,9 @@ "build:rollup": "polkadot-exec-rollup --config", "chain:info": "polkadot-types-chain-info", "clean": "polkadot-dev-clean-build", - "docs:metadata": "polkadot-types-internal-metadata", + "deno": "yarn build && yarn deno:setup && yarn deno:check", + "deno:check": "deno check --import-map=deno/import_map.json deno/check.ts", + "deno:setup": "deno run --import-map=deno/import_map.json --allow-read --allow-write deno/setup.ts", "lint": "polkadot-dev-run-lint", "postinstall": "polkadot-dev-yarn-only", "test": "polkadot-dev-run-test --coverage --forceExit --runInBand --testPathIgnorePatterns e2e", diff --git a/packages/rpc-provider/src/ws/index.ts b/packages/rpc-provider/src/ws/index.ts index aacbfa78d4..805a764b6c 100644 --- a/packages/rpc-provider/src/ws/index.ts +++ b/packages/rpc-provider/src/ws/index.ts @@ -214,10 +214,12 @@ export class WsProvider implements ProviderInterface { maxReceivedMessageSize: 24 * MEGABYTE }); - this.#websocket.onclose = this.#onSocketClose; - this.#websocket.onerror = this.#onSocketError; - this.#websocket.onmessage = this.#onSocketMessage; - this.#websocket.onopen = this.#onSocketOpen; + if (this.#websocket) { + this.#websocket.onclose = this.#onSocketClose; + this.#websocket.onerror = this.#onSocketError; + this.#websocket.onmessage = this.#onSocketMessage; + this.#websocket.onopen = this.#onSocketOpen; + } // timeout any handlers that have not had a response this.#timeoutId = setInterval(() => this.#timeoutHandlers(), TIMEOUT_INTERVAL);