Skip to content

Commit

Permalink
fix: only require fast-text-encoding when needed (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Jun 25, 2019
1 parent 326ba7f commit 04fcd77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/crypto/browser/crypto.ts
Expand Up @@ -22,7 +22,7 @@ import * as base64js from 'base64-js';
// Not all browsers support `TextEncoder`. The following `require` will
// provide a fast UTF8-only replacement for those browsers that don't support
// text encoding natively.
if (typeof TextEncoder === 'undefined') {
if (typeof process === 'undefined' && typeof TextEncoder === 'undefined') {
require('fast-text-encoding');
}

Expand Down
6 changes: 6 additions & 0 deletions test/test.crypto.ts
Expand Up @@ -73,4 +73,10 @@ describe('Node.js crypto tests', () => {
const encodedString = crypto.encodeBase64StringUtf8(originalString);
assert.strictEqual(encodedString, base64String);
});

it('should not load fast-text-encoding while running in nodejs', () => {
const loadedModules = Object.keys(require('module')._cache);
const hits = loadedModules.filter(x => x.includes('fast-text-encoding'));
assert.strictEqual(hits.length, 0);
});
});

0 comments on commit 04fcd77

Please sign in to comment.