Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only require fast-text-encoding when needed #740

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/crypto/browser/crypto.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
});
});