diff --git a/sea.js b/sea.js index c496e2df..92a0a0c6 100644 --- a/sea.js +++ b/sea.js @@ -3,9 +3,7 @@ /* UNBUILD */ var root; if(typeof window !== "undefined"){ root = window } - if(typeof Buffer === "undefined") { - global.Buffer = require("buffer").Buffer - } + if(typeof global !== "undefined"){ root = global } root = root || {}; var console = root.console || {log: function(){}}; @@ -50,10 +48,12 @@ })(USE, './https'); ;USE(function(module){ - if(typeof global !== "undefined"){ - var g = global; - g.btoa = function (data) { return Buffer.from(data, "binary").toString("base64"); }; - g.atob = function (data) { return Buffer.from(data, "base64").toString("binary"); }; + if(typeof Buffer === "undefined") { + root.Buffer = require("buffer").Buffer + } + if(typeof btoa !== "undefined"){ + root.btoa = function (data) { return Buffer.from(data, "binary").toString("base64"); }; + root.atob = function (data) { return Buffer.from(data, "base64").toString("binary"); }; } })(USE, './base64'); diff --git a/sea/base64.js b/sea/base64.js index 5a87f29e..48b78725 100644 --- a/sea/base64.js +++ b/sea/base64.js @@ -1,7 +1,9 @@ - if(typeof global !== "undefined"){ - var g = global; - g.btoa = function (data) { return Buffer.from(data, "binary").toString("base64"); }; - g.atob = function (data) { return Buffer.from(data, "base64").toString("binary"); }; + if(typeof Buffer === "undefined") { + root.Buffer = require("buffer").Buffer + } + if(typeof btoa !== "undefined"){ + root.btoa = function (data) { return Buffer.from(data, "binary").toString("base64"); }; + root.atob = function (data) { return Buffer.from(data, "base64").toString("binary"); }; } \ No newline at end of file diff --git a/sea/shim.js b/sea/shim.js index 6f73e259..42716477 100644 --- a/sea/shim.js +++ b/sea/shim.js @@ -6,9 +6,6 @@ if(SEA.window){ api.crypto = window.crypto || window.msCrypto || require('isomorphic-webcrypto'); - if(!api.crypto) { - api.crypto = require('isomorphic-webcrypto'); - } api.subtle = (api.crypto||o).subtle || (api.crypto||o).webkitSubtle; api.TextEncoder = window.TextEncoder; api.TextDecoder = window.TextDecoder;