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

Avoid the assumption of Buffer in browser envs #3452

Merged
merged 8 commits into from Mar 24, 2020
7 changes: 5 additions & 2 deletions src/utils/FileEmitter.ts
Expand Up @@ -24,6 +24,8 @@ interface OutputSpecificFileData {
bundle: OutputBundleWithPlaceholders;
}

const isBrowser = typeof window !== 'undefined';
JoviDeCroock marked this conversation as resolved.
Show resolved Hide resolved

function generateAssetFileName(
name: string | undefined,
source: string | Buffer,
Expand Down Expand Up @@ -110,7 +112,8 @@ function getValidSource(
emittedFile: { fileName?: string; name?: string },
fileReferenceId: string | null
): string | Buffer {
if (typeof source !== 'string' && !Buffer.isBuffer(source)) {
// Since buffer isn't available in browser and the source isn't a string this should throw.
if (typeof source !== 'string' && (isBrowser || !Buffer.isBuffer(source))) {
const assetName = emittedFile.fileName || emittedFile.name || fileReferenceId;
return error(
errFailedValidation(
Expand Down Expand Up @@ -349,7 +352,7 @@ export class FileEmitter {
const outputFile = bundle[fileName];
if (
outputFile.type === 'asset' &&
(Buffer.isBuffer(source) && Buffer.isBuffer(outputFile.source)
(!isBrowser && Buffer.isBuffer(source) && Buffer.isBuffer(outputFile.source)
? source.equals(outputFile.source)
: source === outputFile.source)
)
Expand Down