Skip to content

Commit

Permalink
fix(package): fix google provider (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
olup authored Apr 5, 2021
1 parent 527d17f commit 353ecd5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }];
}
}

Expand All @@ -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'
);
});
}

Expand Down
6 changes: 6 additions & 0 deletions src/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('**', {
Expand Down

0 comments on commit 353ecd5

Please sign in to comment.