Skip to content

Commit

Permalink
handle plugin buffer response (#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott authored Aug 31, 2020
1 parent d484739 commit b112148
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions snowpack/src/build/build-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function runPipelineLoadStep(

validatePluginLoadResult(step, result);

if (typeof result === 'string') {
if (typeof result === 'string' || Buffer.isBuffer(result)) {
const mainOutputExt = step.resolve.output[0];
return {
[mainOutputExt]: {
Expand Down Expand Up @@ -139,7 +139,7 @@ async function runPipelineTransformStep(
});
logger.debug(`✔ transform() success [${debugPath}]`, {name: step.name});
// if step returned a value, only update code (don’t touch .map)
if (typeof result === 'string') {
if (typeof result === 'string' || Buffer.isBuffer(result)) {
output[destExt].code = result;
output[destExt].map = undefined;
} else if (result && typeof result === 'object' && (result as {result: string}).result) {
Expand Down
2 changes: 1 addition & 1 deletion snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import isCompressible from 'compressible';
import merge from 'deepmerge';
import etag from 'etag';
import {EventEmitter} from 'events';
import {existsSync, promises as fs, readFileSync, statSync, createReadStream} from 'fs';
import {createReadStream, existsSync, promises as fs, readFileSync, statSync} from 'fs';
import http from 'http';
import HttpProxy from 'http-proxy';
import http2 from 'http2';
Expand Down
3 changes: 2 additions & 1 deletion snowpack/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ export function validatePluginLoadResult(
if (!result) {
return;
}
if (typeof result === 'string' && plugin.resolve!.output.length !== 1) {
const isValidSingleResultType = typeof result === 'string' || Buffer.isBuffer(result);
if (isValidSingleResultType && plugin.resolve!.output.length !== 1) {
handleConfigError(
`[plugin=${pluginName}] "load()" returned a string, but "resolve.output" contains multiple possible outputs. If multiple outputs are expected, the object return format is required.`,
);
Expand Down

0 comments on commit b112148

Please sign in to comment.