From 83790f458e109091e35f16c4e4a458045a341dda Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 2 Jul 2018 09:59:53 +0200 Subject: [PATCH] Cleanup startup scripts --- packages/client-wasm/src/create/index.ts | 8 ++++---- packages/client/scripts/polkadot.js | 15 +++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/client-wasm/src/create/index.ts b/packages/client-wasm/src/create/index.ts index 3df88cee..a5ba32c2 100644 --- a/packages/client-wasm/src/create/index.ts +++ b/packages/client-wasm/src/create/index.ts @@ -31,16 +31,16 @@ export default function wasm ({ config: { wasm: { heapSize = defaults.HEAP_SIZE_ const env = instrument('runtime', elapsed, (): WasmInstanceExports => createEnv(runtime, createMemory(0, 0)) ); - const proxy = instrument('chain', elapsed, (): WasmInstanceExports => + const chain = instrument('chain', elapsed, (): WasmInstanceExports => createExports(chainCode, { env }) ); const instance = instrument('proxy', elapsed, (): WasmInstanceExports => - createExports(chainProxy, { proxy }, createMemory(0, 0)) + createExports(chainProxy, { proxy: chain }, createMemory(0, 0)) ); - const offset = proxy.memory.grow(Math.ceil(heapSize / 64)); + const offset = chain.memory.grow(Math.ceil(heapSize / 64)); - runtime.environment.heap.setWasmMemory(proxy.memory, offset * 64 * 1024); + runtime.environment.heap.setWasmMemory(chain.memory, offset * 64 * 1024); l.debug(() => `WASM created ${elapsed.join(', ')}`); diff --git a/packages/client/scripts/polkadot.js b/packages/client/scripts/polkadot.js index a4f1de99..48ec2475 100755 --- a/packages/client/scripts/polkadot.js +++ b/packages/client/scripts/polkadot.js @@ -3,9 +3,16 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -try { - require('../index'); -} catch (error) { +const fs = require('fs'); +const path = require('path'); + +const [compiled] = ['../index.js'] + .map((file) => path.join(__dirname, file)) + .filter((file) => fs.existsSync(file)); + +if (compiled) { + require(compiled); +} else { require('@babel/register')({ extensions: ['.js', '.ts'], plugins: [ @@ -16,5 +23,5 @@ try { }] ] }); - require('../src'); + require('../src/index.ts'); }