Skip to content
Open
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
18 changes: 9 additions & 9 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ import Progress from './cli/progress';
import { languageSelection, listSelection } from './cli/selection';
import { logs } from './logs';
import { isInteractive } from './tty';
import { filterFiles, getEnv, loadFilesToRun, zip } from './utils';
import {
filterFiles,
getEnv,
loadFilesToRun,
streamToBuffer,
zip
} from './utils';
import { debug } from './cli/messages';

export enum ErrorCode {
Expand Down Expand Up @@ -68,14 +74,8 @@ export const deployPackage = async (
hide
);

// TODO: We should do something with the return value, for example
// check for error or show the output to the user
await api.upload(
name,
archive,
additionalJsons,
descriptor.runners
);
const blob = await streamToBuffer(archive);
await api.upload(name, blob, additionalJsons, descriptor.runners);

const env = await getEnv(rootPath, args['env'], args['envFile']);

Expand Down
14 changes: 14 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

import { MetaCallJSON } from '@metacall/protocol/deployment';
import archiver, { Archiver } from 'archiver';
import concat from 'concat-stream';
import { parse } from 'dotenv';
import { promises as fs } from 'fs';
import { prompt } from 'inquirer';
import { platform } from 'os';
import { basename, join, relative } from 'path';
import { Readable } from 'stream';
import { error, info, printLanguage, warn } from './cli/messages';
import { consentSelection, fileSelection } from './cli/selection';
import { isInteractive } from './tty';
Expand Down Expand Up @@ -146,6 +148,18 @@ export const zip = async (
return archive;
};

/**
* Collect a readable stream into a Buffer.
* Required for multipart uploads with axios 1.x - streams cause wrong Content-Length.
*/
export const streamToBuffer = (stream: Readable): Promise<Buffer> =>
new Promise((resolve, reject) => {
const collector = concat((buf: Buffer) => resolve(buf));
stream.on('error', reject);
collector.on('error', reject);
stream.pipe(collector);
});

/**
* Parse a single KEY=VALUE string into an object entry
*/
Expand Down