From fc4b04fab9b97cf4a66b740bb14db0e3c44d72ab Mon Sep 17 00:00:00 2001 From: Olup Date: Sun, 4 Apr 2021 09:15:25 +0200 Subject: [PATCH] fix(package): fix google provider --- src/helper.ts | 12 +++++++----- src/pack.ts | 6 ++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/helper.ts b/src/helper.ts index 58359bef..9d20aac5 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -23,15 +23,15 @@ export function extractFileNames( // Either grab the package.json:main field, or use the index.ts file. // (This will be transpiled to index.js). - const main = packageFile.main ? packageFile.main.replace(/\.js$/, '.ts') : 'index.ts'; + const entry = packageFile.main ? packageFile.main.replace(/\.js$/, '.ts') : 'index.ts'; // Check that the file indeed exists. - if (!fs.existsSync(path.join(cwd, main))) { - console.log(`Cannot locate entrypoint, ${main} not found`); + if (!fs.existsSync(path.join(cwd, entry))) { + console.log(`Cannot locate entrypoint, ${entry} not found`); throw new Error('Compilation failed'); } - return [main]; + return [{ entry, func: null }]; } } @@ -54,7 +54,9 @@ export function extractFileNames( // Can't find the files. Watch will have an exception anyway. So throw one with error. console.log(`Cannot locate handler - ${fileName} not found`); - throw new Error('Compilation failed. Please ensure handlers exists with ext .ts or .js'); + throw new Error( + 'Compilation failed. Please ensure you have an index file with ext .ts or .js, or have a path listed as main key in package.json' + ); }); } diff --git a/src/pack.ts b/src/pack.ts index 043627a3..6ba764c4 100644 --- a/src/pack.ts +++ b/src/pack.ts @@ -31,6 +31,12 @@ export async function pack(this: EsbuildPlugin) { const isGoogleProvider = this.serverless?.service?.provider?.name === 'google'; const excludedFiles = isGoogleProvider ? [] : excludedFilesDefault; + // Google provider cannot use individual packaging for now - this could be built in a future release + if (isGoogleProvider && this.serverless?.service?.package?.individually) + throw new Error( + 'Packaging failed: cannot package function individually when using Google provider' + ); + // get a list of all path in build const files: { localPath: string; rootPath: string }[] = glob .sync('**', {