Set up setImmediate for browsers.

This commit is contained in:
Richard Moore 2018-06-22 02:07:57 -04:00
parent dde33aa5a5
commit b2be7c807f
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
4 changed files with 9 additions and 2 deletions

@ -33,7 +33,9 @@ var empty = "module.exports = {};";
// @TODO: Use path construction instead of ../.. // @TODO: Use path construction instead of ../..
var brorand = "var randomBytes = require('../../src.ts/utils').randomBytes; module.exports = function(length) { return randomBytes(length); };"; var brorand = "var randomBytes = require('../../src.ts/utils').randomBytes; module.exports = function(length) { return randomBytes(length); };";
var process = "if (!global.setImmediate) { global.setImmedaite = setTimeout; };"; // setImmediate is installed globally by our src.browser/shims.ts, loaded from src.ts/index.ts
var process = "module.exports = { };";
var timers = "module.exports = { setImmediate: global.setImmediate }; ";
var transforms = { var transforms = {
// 'ethers.js/package.json': JSON.stringify({ version: version }), // 'ethers.js/package.json': JSON.stringify({ version: version }),
@ -61,7 +63,7 @@ var transforms = {
// Used by sha3 if it exists; (so make it no exist) // Used by sha3 if it exists; (so make it no exist)
// "process/.*": undef, // "process/.*": undef,
"process/browser.js": process, "process/browser.js": process,
"timers-browserify/main.js": empty, "timers-browserify/main.js": timers,
}; };
function transformFile(path) { function transformFile(path) {

1
src.browser/shims.ts Normal file

@ -0,0 +1 @@
require('setimmediate');

@ -1,5 +1,8 @@
'use strict'; 'use strict';
// This is empty in node, and used by browserify to inject extra goodies
import './utils/shims';
import { Contract, Interface } from './contracts'; import { Contract, Interface } from './contracts';
import * as providers from './providers'; import * as providers from './providers';
import * as errors from './utils/errors'; import * as errors from './utils/errors';

1
src.ts/utils/shims.ts Normal file

@ -0,0 +1 @@
/* no shims for node */