From 029dc453e53d33280d4300687d2e6b6fa713d203 Mon Sep 17 00:00:00 2001 From: Dirk de Visser Date: Fri, 1 Mar 2019 10:07:33 +0100 Subject: [PATCH] Fix writing buffers Buffers are not stringified before passed to the archive. The archiver handles Buffers just fine. Fixed a typo in .gitignore Pass ncc options in the same object instead of as a separate argument. --- .gitignore | 2 +- src/compiler.ts | 4 ++-- src/index.ts | 5 ++--- src/zipper.ts | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index c0f07d5..50c37dd 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,7 @@ typings/ # Optional npm cache directory .npm -# Optional efslint cache +# Optional eslint cache .eslintcache # Optional REPL history diff --git a/src/compiler.ts b/src/compiler.ts index 6bbff65..4186917 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1,5 +1,5 @@ import zeitNcc from '@zeit/ncc'; -export default async function compile({ inputFilePath }: { inputFilePath: string }, opts: any) { - return zeitNcc(inputFilePath, { minify: false, ...opts }); +export default async function compile({ inputFilePath, ...options }: { inputFilePath: string, [key: string]: any }) { + return zeitNcc(inputFilePath, { minify: false, ...options }); } diff --git a/src/index.ts b/src/index.ts index 524e877..746e246 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,7 +38,7 @@ export default class ServerlessPlugin { const packagingPromises = packageFilesConfig.map(async ({ zip, files }) => { // For now pass all ncc options directly to ncc. This has the benefit of testing out new // ncc releases and changes quickly. Later it would be nice to add a validation step in between. - const codeCompilePromises = files.map(({ absPath }) => compiler({ inputFilePath: absPath }, ncc)); + const codeCompilePromises = files.map(({ absPath }) => compiler({ inputFilePath: absPath, ...ncc})); const compiledCodes = await Promise.all(codeCompilePromises); const zipperFiles = createZipperFiles(files, compiledCodes); await zipper({ zipPath: zip.absPath, zipContents: zipperFiles }); @@ -87,8 +87,7 @@ function createZipperFiles(files: IFileNameAndPath[], compiledCodes: CompiledOut } content.push({ - // Not sure if utf8 is ok, Assets can be of any format... - data: compilerOutput.assets![assetName].source.toString('utf8'), + data: compilerOutput.assets![assetName].source, name: `${path}${ assetName }`, }) }) diff --git a/src/zipper.ts b/src/zipper.ts index db57701..3b27c0f 100644 --- a/src/zipper.ts +++ b/src/zipper.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import archiver from 'archiver'; export type ZipContent = { - data: string; + data: string | Buffer; name: string; }