Skip to content

Commit

Permalink
Adjust bundles (no @polkadot/networks) (#3754)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr authored Jul 9, 2021
1 parent f0778b6 commit 081f223
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 113 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Changes:
- Add `BlockNumberFor` type mapping
- Add Westend 9080 upgrade block
- Add `derive.crowdloan.contributions(paraId)`
- Allow building as a completely stand-alone browser bundle
- Allow building as a completely stand-alone browser bundle (experimental)
- Update to latest `@polkadot/x-rxjs` with RxJs 7.2


Expand Down
2 changes: 1 addition & 1 deletion packages/api-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@babel/runtime": "^7.14.6",
"@polkadot/api": "4.17.2-17",
"@polkadot/types": "4.17.2-17",
"@polkadot/util": "^6.11.2-13",
"@polkadot/util": "^6.11.2-14",
"rxjs": "^7.2.0"
}
}
6 changes: 3 additions & 3 deletions packages/api-derive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"@polkadot/api": "4.17.2-17",
"@polkadot/rpc-core": "4.17.2-17",
"@polkadot/types": "4.17.2-17",
"@polkadot/util": "^6.11.2-13",
"@polkadot/util-crypto": "^6.11.2-13",
"@polkadot/util": "^6.11.2-14",
"@polkadot/util-crypto": "^6.11.2-14",
"rxjs": "^7.2.0"
},
"devDependencies": {
"@polkadot/keyring": "^6.11.2-13",
"@polkadot/keyring": "^6.11.2-14",
"@polkadot/rpc-provider": "4.17.2-17"
}
}
6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
"dependencies": {
"@babel/runtime": "^7.14.6",
"@polkadot/api-derive": "4.17.2-17",
"@polkadot/keyring": "^6.11.2-13",
"@polkadot/keyring": "^6.11.2-14",
"@polkadot/rpc-core": "4.17.2-17",
"@polkadot/rpc-provider": "4.17.2-17",
"@polkadot/types": "4.17.2-17",
"@polkadot/types-known": "4.17.2-17",
"@polkadot/util": "^6.11.2-13",
"@polkadot/util-crypto": "^6.11.2-13",
"@polkadot/util": "^6.11.2-14",
"@polkadot/util-crypto": "^6.11.2-14",
"eventemitter3": "^4.0.7",
"rxjs": "^7.2.0"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rpc-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"@babel/runtime": "^7.14.6",
"@polkadot/rpc-provider": "4.17.2-17",
"@polkadot/types": "4.17.2-17",
"@polkadot/util": "^6.11.2-13",
"@polkadot/util": "^6.11.2-14",
"rxjs": "^7.2.0"
},
"devDependencies": {
"@polkadot/keyring": "^6.11.2-13"
"@polkadot/keyring": "^6.11.2-14"
}
}
12 changes: 6 additions & 6 deletions packages/rpc-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"dependencies": {
"@babel/runtime": "^7.14.6",
"@polkadot/types": "4.17.2-17",
"@polkadot/util": "^6.11.2-13",
"@polkadot/util-crypto": "^6.11.2-13",
"@polkadot/x-fetch": "^6.11.2-13",
"@polkadot/x-global": "^6.11.2-13",
"@polkadot/x-ws": "^6.11.2-13",
"@polkadot/util": "^6.11.2-14",
"@polkadot/util-crypto": "^6.11.2-14",
"@polkadot/x-fetch": "^6.11.2-14",
"@polkadot/x-global": "^6.11.2-14",
"@polkadot/x-ws": "^6.11.2-14",
"eventemitter3": "^4.0.7"
},
"devDependencies": {
"@polkadot/keyring": "^6.11.2-13",
"@polkadot/keyring": "^6.11.2-14",
"@polkadot/types": "4.17.2-17",
"mock-socket": "^9.0.3",
"nock": "^13.1.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@polkadot/api": "4.17.2-17",
"@polkadot/rpc-provider": "4.17.2-17",
"@polkadot/types": "4.17.2-17",
"@polkadot/util": "^6.11.2-13",
"@polkadot/util": "^6.11.2-14",
"handlebars": "^4.7.7",
"websocket": "^1.0.34",
"yargs": "^17.0.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/types-known/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
"dependencies": {
"@babel/runtime": "^7.14.6",
"@polkadot/networks": "^6.11.2-13",
"@polkadot/networks": "^6.11.2-14",
"@polkadot/types": "4.17.2-17",
"@polkadot/util": "^6.11.2-13"
"@polkadot/util": "^6.11.2-14"
}
}
8 changes: 5 additions & 3 deletions packages/types-known/src/upgrades/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import type { ChainUpgrades } from '@polkadot/types/types';
import type { ChainUpgradesRaw } from './types';

import networks from '@polkadot/networks';
import { selectableNetworks } from '@polkadot/networks';
import { assert, BN, hexToU8a, stringify } from '@polkadot/util';

import kusama from './kusama';
import polkadot from './polkadot';
import westend from './westend';

const allKnown = { kusama, polkadot, westend };

// testnets are not available in the networks map
const NET_EXTRA: Record<string, { genesisHash: string[] }> = {
westend: {
Expand All @@ -35,7 +37,7 @@ function checkOrder (network: string, versions: ChainUpgradesRaw): [number, numb

/** @internal */
function mapRaw ([network, versions]: [string, ChainUpgradesRaw]): ChainUpgrades {
const chain = networks.find((n) => n.network === network) || NET_EXTRA[network];
const chain = selectableNetworks.find((n) => n.network === network) || NET_EXTRA[network];

assert(chain, () => `Unable to find info for chain ${network}`);

Expand All @@ -50,6 +52,6 @@ function mapRaw ([network, versions]: [string, ChainUpgradesRaw]): ChainUpgrades
}

// Type overrides for specific spec types & versions as given in runtimeVersion
const upgrades = Object.entries({ kusama, polkadot, westend }).map(mapRaw);
const upgrades = Object.entries(allKnown).map(mapRaw);

export default upgrades;
6 changes: 3 additions & 3 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
"dependencies": {
"@babel/runtime": "^7.14.6",
"@polkadot/util": "^6.11.2-13",
"@polkadot/util-crypto": "^6.11.2-13",
"@polkadot/util": "^6.11.2-14",
"@polkadot/util-crypto": "^6.11.2-14",
"rxjs": "^7.2.0"
},
"devDependencies": {
"@polkadot/keyring": "^6.11.2-13",
"@polkadot/keyring": "^6.11.2-14",
"@types/bn.js": "^4.11.6",
"bn.js": "^4.11.9"
}
Expand Down
6 changes: 4 additions & 2 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ const pkgs = [
const external = [
...pkgs,
'@polkadot/keyring',
'@polkadot/networks',
'@polkadot/util',
'@polkadot/util-crypto'
];

const entries = ['api-derive', 'rpc-core', 'rpc-provider', 'types-known'].reduce((all, p) => ({
...all,
[`@polkadot/${p}`]: path.resolve(process.cwd(), `packages/${p}/build/bundle.js`)
}), {});
}), {
// re-exported in @polkadot/util-crypto, map directly
'@polkadot/networks': '@polkadot/util-crypto'
});

const overrides = {};

Expand Down
35 changes: 25 additions & 10 deletions test-bundle.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,49 @@
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style></style>
<title>Bundler tests</title>
<style>
pre {
margin: 0.5rem 0;
}

pre.header {
background: #ddd;
margin-top: 1.5rem;
padding: 0.25rem 0.75rem;
}
</style>
</head>
<body>
Executing bundle tests, see the dev console for output ...
<script>
function log (label, result) {
label.startsWith('*')
? console.log(label)
: console.log(label.padStart(24), '=', result);
const pre = document.createElement('pre');

if (typeof result !== 'undefined') {
pre.innerHTML = `${label.padStart(24)} = ${result}`;
} else {
pre.innerHTML = label;
pre.className = 'header';
}

document.body.appendChild(pre);
}
</script>
<script src="node_modules/@polkadot/util/bundle-polkadot-util.js"></script>
<script src="node_modules/@polkadot/networks/bundle-polkadot-networks.js"></script>
<script src="node_modules/@polkadot/util-crypto/bundle-polkadot-util-crypto.js"></script>
<script src="node_modules/@polkadot/keyring/bundle-polkadot-keyring.js"></script>
<script src="packages/types/build/bundle-polkadot-types.js"></script>
<script>
log('*** polkadotTypes');
log('polkadotTypes');

const { TypeRegistry } = polkadotTypes;
const registry = new TypeRegistry();

console.log('createType', registry.createType('Balance', 1234567890).toHuman());
log('createType', registry.createType('Balance', 1234567890).toHuman());
</script>
<script src="packages/api/build/bundle-polkadot-api.js"></script>
<script>
log('*** polkadotApi');
log('polkadotApi');

const { ApiPromise, WsProvider } = polkadotApi;
const provider = new WsProvider('wss://rpc.polkadot.io');
Expand Down
Loading

0 comments on commit 081f223

Please sign in to comment.