-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with deploy package function #130
Integration with deploy package function #130
Conversation
Installed and tested this PR Although Lambda shows this when opening the function on AWS console:
The function does get packaged correctly and work. |
@HyperBrain |
@franciscocpg Ok. Then I will close my PR. |
Regarding the new label please check my comment #134 (comment) |
@franciscocpg Can you check if #91 is also replaced, as it also about hooking package function and on the first sight does something quite similar? |
@HyperBrain. Yes it replaces. |
lib/validate.js
Outdated
@@ -18,6 +18,9 @@ module.exports = { | |||
throw new this.serverless.classes | |||
.Error('The webpack plugin could not find the configuration file at: ' + webpackConfigFilePath); | |||
} | |||
if (this.options.function) { | |||
process.env.serverlessFunction = this.options.function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why an additional environment variable is set here? I would not set anything in the process' environment as it is global. Better would be to set it as member of the plugin object with this.XXX = ...
in case it is needed by the plugin itself.
If it is meant to be used in the vars of serverless.yml, you can reference it via options as ${opt:function}
there, even with specifying a default in case it is not set (${opt:function, 'none'}
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HyperBrain I'm using this env var with webpack.config.js
. But reading further comments I realized that you guys have suggested a better approach.
lib/copyFunctionArtifact.js
Outdated
resolve(); | ||
}); | ||
|
||
readStream.pipe(fs.createWriteStream(artifactFilePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this call itself throw, or does it delegate any errors to the 'error' event in any case?
Otherwise the pipe call itself should be wrapped into a try/catch and call reject() in the catch block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HyperBrain pipe emits an error event so the better approach would be:
readStream.pipe(fs.createWriteStream(artifactFilePath)).on('error', (err) => {
reject(err);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable 👍
I like this approach. I wonder though if we should provide a utility function. Something like const slsw = require('serverless-webpack');
module.exports = {
entry: slsw.entries(),
// other bits
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
}
}; |
@johnf Interesting idea 🙌 . @hassankhan Any thoughts on this? If we agree to have this extended in that way, we might delay the "deploy function" support to version 2.1.0, so that we can get the other things out in the meantime. |
I think having exported entries is a pretty cool idea 👍 . We (at work) don't really do single function deploys, so my experience is a bit limited 😅 . My only worry would be to inadvertently affect whole package deploys. That said, it would save a lot of trouble having to manually sync |
Ok. I'll tag it accordingly... we will do function deploys as soon as this is done 😄 |
@franciscocpg Do you need any help or more information with the entries fix? I could create a separate branch in the repository to consolidate the feature, so that we can add this with a separate PR before it finds its way to master. |
Hi @HyperBrain const entries = {};
const doc = yaml.safeLoad(fs.readFileSync('serverless.yml', 'utf8'));
// If we pass a function, package just it
// not all the functions listed on serverless.yml
const serverlessFunction = process.env.serverlessFunction;
const functions = serverlessFunction ?
{ serverlessFunction: doc.functions[serverlessFunction] }
: doc.functions;
for (const key in functions) { // eslint-disable-line guard-for-in
const handler = functions[key].handler;
const entryKey = handler.replace(handlerRegex, '');
entries[entryKey] = [include, `./${entryKey}.js`];
} to our plugin (a new file called const slsw = require('serverless-webpack');
module.exports = {
entry: slsw.lib.entries,
// other bits
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
}
}; Did I understand correctly? |
I understood it that way 😄 . The webpack config should have no knowledge of Serverless internals, so everything that interacts directly with the plugin or Serverless should be in the plugin. After a solution is finsihed we also should test the behavior with all possible configurations (may it be the entries retrieved from the plugin or statically set entries). |
Sorry for the late, guys. I was very busy these days. |
@franciscocpg Great stuff and a big thank you 🙌 . I will test it over the weekend and review the PR again. |
Yes, given that your fork's master is up-to-date with the webpack's master 👍 . |
According to the git docs (https://git-scm.com/docs/git-rebase) it should be |
9a83c9e
to
a89bd92
Compare
I managed to rebase the commits locally. If you agree, I can commit them back to your branch into the PR. |
Ok @HyperBrain |
Can you check if "enable edits by maintainers" is checked in the PR? |
I've just checked |
a89bd92
to
0a5d842
Compare
It worked 💯 You can now pull the branch again locally. It is now rebased onto the current master. |
0a5d842
to
a89bd92
Compare
"babel-polyfill": "6.13.0", | ||
"babel-preset-env": "^1.6.0", | ||
"serverless-webpack": "file:../../", | ||
"webpack": "^1.13.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we support any webpack version now, maybe using webpack 2 in the examples would be good. What do you think?
... or at least in some examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I'm going to update it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated all examples dependencies and tested all folders.
It looks like everything is working as expected.
Also I've added yarn
to examples.
- Adding yarn to examples - Fix typescript example
@HyperBrain |
I found an issue with handlers in arbitrary paths when testing with one of our bigger production projects. |
Nice @HyperBrain!
It looks like yarn isn't using |
@franciscocpg Yeah, at the moment it seems to be quite a mess with the different package lock mechanisms. Maybe we should remove the lock files completely for now, and use it as soon as the tools (npm and yarn) can work with the same one. |
@HyperBrain |
For this PR maybe we should keep |
That sounds good to me. This PR should not invent or change things other than the problem solved ;-) |
Fixes issue #107.
Also PR #110 seems incomplete and it looks like the author is not working on it anymore.
Here is a working
webpack.config.js