Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update to support google cloud functions
  • Loading branch information
debanjanbasu committed Oct 30, 2017
commit 8ede2a738e10463a3004e551db04a1e0ba7a3644
31 changes: 17 additions & 14 deletions lib/packExternalModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,23 @@ module.exports = {
addModulesToPackageJson(prodModules, modulePackage);
this.serverless.utils.writeFileSync(modulePackageJson, JSON.stringify(modulePackage, null, 2));

// Copy modules
// const startCopy = _.now();
// return BbPromise.fromCallback(callback => fse.copy(path.join(compositeModulePath, 'node_modules'), path.join(modulePath, 'node_modules'), callback))
// .tap(() => this.options.verbose && this.serverless.cli.log(`Copy modules: ${modulePath} [${_.now() - startCopy} ms]`))
// .then(() => {
// // Prune extraneous packages - removes not needed ones
// const startPrune = _.now();
// return BbPromise.fromCallback(callback => {
// childProcess.exec('npm prune', {
// cwd: modulePath
// }, callback);
// })
// .tap(() => this.options.verbose && this.serverless.cli.log(`Prune: ${modulePath} [${_.now() - startPrune} ms]`));
// });
// Copy modules only if not google-cloud-functions
// GCF Auto installs the package json
if (_.get(this.serverless, 'service.provider.name') !== 'google') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer an early exit here if the provider is google instead of putting the default case into the if.

if (_.get(this.serverless, 'service.provider.name') === 'google') {
  return BbPromise.resolve();
}
...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this. I will add unit tests for the new behavior to restore coverage.

const startCopy = _.now();
return BbPromise.fromCallback(callback => fse.copy(path.join(compositeModulePath, 'node_modules'), path.join(modulePath, 'node_modules'), callback))
.tap(() => this.options.verbose && this.serverless.cli.log(`Copy modules: ${modulePath} [${_.now() - startCopy} ms]`))
.then(() => {
// Prune extraneous packages - removes not needed ones
const startPrune = _.now();
return BbPromise.fromCallback(callback => {
childProcess.exec('npm prune', {
cwd: modulePath
}, callback);
})
.tap(() => this.options.verbose && this.serverless.cli.log(`Prune: ${modulePath} [${_.now() - startPrune} ms]`));
});
}
})
.return();
});
Expand Down