Repository navigation
feat(Packaging): Add patterns setting and deprecate include/exclude - #8581
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8581 +/- ##
=======================================
Coverage 87.15% 87.16%
=======================================
Files 304 304
Lines 11467 11474 +7
=======================================
+ Hits 9994 10001 +7
Misses 1473 1473
Continue to review full report at Codecov.
|
60cdd6e to
8f5775d
Compare
medikoo
left a comment
There was a problem hiding this comment.
@juanjoDiaz great thanks for that! Can you ensure that branch is up to date with master and that CI passes(?) I see that packing tests failed (those run through npm run integration-test-run-package)
8f5775d to
4acb8b6
Compare
|
Rebased on top of master and fixed the broken test. Let me know if there is anything else pending. |
medikoo
left a comment
There was a problem hiding this comment.
@juanjoDiaz great thanks for that! It looks very promising, still see my comments.
I believe we need to narrow down scope of this purely, so it's purely about introduction of patterns, and doesn't touch any functionality that processes resolved patterns (this can be in scope of other PR)
There was a problem hiding this comment.
We need to also define it on functions level, here:
serverless/lib/plugins/aws/provider/awsProvider.js
Lines 961 to 968 in b12d565
There was a problem hiding this comment.
New deprecation should always be added on top
There was a problem hiding this comment.
Let's title it New way to define packaging patterns
There was a problem hiding this comment.
Let's also update all the docs (in docs folder, all references to package.include and package.exclude - simply remove those references and document package.patterns)
Then also let's link here packaging docs section that documents package.patterns
There was a problem hiding this comment.
I can tackle this once we are happy with the implementation 🙂
There was a problem hiding this comment.
I suggest to add it in simpler way, with less changes to the file:
package.pattern can be treat as an alias (or rather suplement) to package.includes (note that currently in package.includes we support negation patterns)
So simple way to add recognition of patterns, and pave path for future removal of include and exclude could be:
- Rename
getIncludestogetPatterns - Upgrade signature of
getPatternsto accept options object (that may containincludeandpattern) property - update all invocations to function, so options are passed instead - In
getPatterns, construct final patterns collection by ensuring thatpatternsin all cases are handled last, so in following order:service.includefunction.includeservice.patternfunction.patterns
And that should be all changes I think needed for this functionality to work as expected - we should not interfere with the logic that processes patterns as returned by getPatterns
There was a problem hiding this comment.
That's essentially what I've done.
There are 3 functions that gather the patterns: resolveFilePathsAll, resolveFilePathsFunction and resolveFilePathsLayer`.
The three of them do the same:
return this.getExcludes(funcPackageConfig.exclude, true)
.then(exclude => {
const params = { exclude, include: this.getIncludes(funcPackageConfig.include) };
return params;
})
.then(params => this.excludeDevDependencies(params))
.then(params => this.resolveFilePathsFromPatterns(params));So I've abstracted that logic to a getPatterns function which calls getExcludes and getIncludes.
getIncludes does exactly as you suggested.
getExcludes only change is that it adds the dependencies from devDependencies, instead of doing a separate call to the function in zipService that would add it to the exclude property as I explained in a different comment.
Does that make sense?
I understand that you want to minimize changes, but I think that the code was getting a little bit spaghetti and the implementation in this PR really simplifies things.
There was a problem hiding this comment.
That's essentially what I've done.
Changes I see now, look as way more than needed to accomplish what's described above, and here we deal with really sensitive functionality, that's why I'm pushing for minimal needed changeset
I wouldn't touch getExcludes and I don't think any changes are needed in zipService. I've elaborated on that a bit more here: #8581 (comment)
Also, sorry I don't want to sound dismissive, in overall you've done a really great work.
There was a problem hiding this comment.
Let's configure this deprecation in initialization hook here:
serverless/lib/plugins/package/package.js
Line 57 in b12d565
Example on how it's done elsewhere:
It will allow the deprecation to surface at earliest convenience (before any eventual error is reported)
There was a problem hiding this comment.
Why are there any changes in this file?
There was a problem hiding this comment.
This excludeDevDependencies method received the package config and updated the exclude property with the dev dependencies.
- It shouldn't be in
zipServicebut inpackageService(I didn't change it to don't make the review even more complicated.) - The method is really tightly coupled with the include/exclude format. Now, it simple returns the list of devDependencies' patterns so the calling method can add them to the patterns in any way (future-proffness).
There was a problem hiding this comment.
Thanks for clarifications. Actually excludeDevDependencies doesn't really receive package config directly.
The actual packaging config is consumed in two places:
serverless/lib/plugins/package/lib/packageService.js
Lines 197 to 201 in 8545268
Then this.getIncludes and this.getExcludes resolve internal include and exclude patterns collections (which are not package config objects) which are processed further.
Technically to implement this functionality, all we need is to tweak this.getIncludes so it combines package.patterns into returned include patterns, and otherwise nothing else is needed to be done I think.
Of course it'll be also nice to clear internals so they also process single patterns collections and not both include and exclude, but as it can be seen a separate concern, and it's best if it's addressed with other PR (ideally PR's should be minimal and focus on one thing, especially that we deal here with really sensitive functionality).
Additionally we have a refactor planned to how we resolve files in a service and dev dependencies: #8586 and that will replace some of the logic in zipService and packageService, so it may not be worth to imply any refactors to it at this point
There was a problem hiding this comment.
Let's not change the way in which patterns are handled (this if needed should be handled in separate PR)
There was a problem hiding this comment.
I can do a separate commit or a separate PR if you'd rather that.
I've put micromatch back as it was and just added a comment.
There was a problem hiding this comment.
I can do a separate commit or a separate PR if you'd rather that.
Yes, that'll be great, and ideally if such change is first discussed, so before jumping into implementation we have full agreement that given refactor is justified. Please check #8586 it's probably a good point for discussing this
There was a problem hiding this comment.
Let's not update existing tests - technically they should remain passing without any changes.
I've proposed a refactor of them so they do not depend on internals: #8594, and I think we should address that first (so we don't fight with failing tests)
There was a problem hiding this comment.
With my latest changes, there are no changes in these tests anymore.
7a1d0d3 to
954a5a5
Compare
|
Ok, I think that I've tackled everything. Things left are:
Once we agree on those, and in any other that I've missed, I'll update the docs. |
954a5a5 to
1da0016
Compare
2d0e7aa to
8548cdf
Compare
|
This is now 3 commits.
Let me know if I still miss anything. All the internals are still working with include/exclude so I'd really suggest doing a separate PR once this is merged to consolidate the internals to use just |
medikoo
left a comment
There was a problem hiding this comment.
@juanjoDiaz It looks great! I've just suggested a more permissive adaptation (so we support all three forms together with deprecation notice).
Also we need some tests, and for that ideally if #8594 is addressed first. Having that it'll be very easy to add few tests that confirm on patterns support
There was a problem hiding this comment.
This is actually a component template which is handled by @servereless/components, and changes we do here do influence that package. So we should not change that template
There was a problem hiding this comment.
If @servereless/components uses serverless, this will work just as it used to.
This will need to change for the next major version update anyway.
I think that keeping it is creating future trouble.
Do you disagree?
There was a problem hiding this comment.
If @servereless/components uses serverless,
It' doesn't use serverless(package internals), it's a completely different CLI
There was a problem hiding this comment.
I think this pattern should stay as it was
There was a problem hiding this comment.
This is a readme example that use to do:
package:
include:
- src/*.js
- dist/*.js
- dist/*.js.mapbut I think that's a better example to exclude sources if we add the compiled files with their source-maps from dist and exclude the original files from src.
Do you dissagree?
There was a problem hiding this comment.
@juanjoDiaz this example intentionally includes sources in a bundle (note the sentence: To use a sourcemap, ensure that your packaging directory includes the compiled source)
Weather it's good example, and whether it could be improved it's the matter that's out of the scope of this PR. We may eventually open another issue to discuss it.
There was a problem hiding this comment.
I think this should not be changed
There was a problem hiding this comment.
This is example in aliyun, azure, google, kubeless, openwhisk and tencent.
So I think that it makes sense to use the same structure in aws for consistency (I fixed all the docs comparing them side by side).
Do you disagree?
There was a problem hiding this comment.
There was a problem hiding this comment.
Let's not update this header
There was a problem hiding this comment.
I believe no exclamations marks should be added here, but to below patterns
There was a problem hiding this comment.
I think we need to support both include and patterns, in a way I proposed in this comment: #8581 (comment)
Technically we stand between choice:
- If user provided
patterns, throw if anyincludeandexcludeconfigurations are found - Support all three
I think it's easier (and not harmful) to support all three
There was a problem hiding this comment.
You also suggested to crash if both are used in comment: #8093 (comment) 😅
The problem of supporting both include and patterns is that the order in which they are appended becomes non-evident to the user and can cause tickets simply because the user expects a different order.
The current implementation support using include/exclude at the service level and patterns at the function level or viceversa. It errors if you use include/exclude and patterns in the same package object (done during the initialization validation).
I think that it's safer to avoid user confusion.
Do you still think that we should allow using both at the same time?
There was a problem hiding this comment.
You also suggested to crash if both are used in comment: #8093 (comment) 😅
That's true. Sorry for confusion. At that point it was not deeply thought. Thing is that crashing is more obtrusive.
Firstly the easy approach to this is to upfront investigate all package configs (service-level, function-level, layer-level) and crash if we find that there's patterns somewhere and includes or excludes elsewhere`, and that's aggressive if e.g. user is switching gradually, e.g. refactor first function one, check how it works and then refactor others. It'll be nice to not break that.
Now trying to validate case by case, is confusing, as e.g. for function 1 config (which uses just include and exclude) may be valid and for function 2 (which uses just patterns) may be not (when on service level include or exclude is used)
I assume it's not harmful to support all (user will always be approached with deprecation notice anyway), and implementation wise it's simplest approach.
The problem of supporting both include and patterns is that the order in which they are appended becomes non-evident to the user and can cause tickets simply because the user expects a different order.
User should not reason about order in such case, but simply ensure that just patterns is used , also again deprecation notice will signal that config stands on quirky ground
There was a problem hiding this comment.
Now trying to validate case by case, is confusing, as e.g. for function 1 config (which uses just include and exclude) may be valid and for function 2 (which uses just patterns) may be not (when on service level include or exclude is used)
That's not how it's implemented in this final version of the implementation. Function 1 and 2 will be valid in that example.
Function 3 which uses patterns and exclude under the same package object would be invalid.
I.e, to get the error you need something like:
package:
patterns:
- my-file.js
include:
- my-other-file.jsI think that's reasonable. However, if you still disagree, let me know and I'll just remove it. I'm running out of the time I've allocated for this 😅
There was a problem hiding this comment.
Function 1 and 2 will be valid in that example.
I think if we invalidate it on function level, we should definitely also not support combining include and exclude on service level with patterns on function level. That would be even more confusing (what's the logical reason for rejecting just one case?)
Anyway have you read the arguments I've put for supporting all without throwing (?) I take it's simplest thing we can do, and really not harmful
There was a problem hiding this comment.
I'm not sure if we are understanding each other completely or getting a bit tangled up. 😅
The validation for service level is exactly the same at the function level.
Let's give it one more go and then do whatever change it needed 😄
Currently:
- You can use
patternsORinclude/excludeat the service level. - You can use
patternsORinclude/excludeat the function level. - It doesn't matter if you use pattern in
patternsat service andinclude/excludeat the function - It doesn't matter if you use pattern in
include/excludeat service andpatternsat the function - etc...
The only thing that fails, is to mix both patterns and include/exclude in the same config (regardless of whether it is in the service or function level).
Valid:
package:
patterns:
- my-file.js
functions:
myFunction:
package:
include:
- my-other-file.js
exclude:
- my-exclude-file.jsValid:
package:
include:
- my-other-file.js
exclude:
- my-exclude-file.js
functions:
myFunction:
patterns:
- my-file.jsValid:
package:
include:
- my-other-file.js
exclude:
- my-exclude-file.js
functions:
myFunction:
patterns:
- my-file.js
myOtherFunction:
package:
include:
- my-other-file.js
exclude:
- my-exclude-file.jsThrows:
package:
patterns:
- my-file.js
include:
- my-other-file.js
exclude:
- my-exclude-file.js
functions:
myFunction:
package:
include:
- my-other-file.js
exclude:
- my-exclude-file.jsThrows:
package:
patterns:
- my-file.js
functions:
myFunction:
package:
patterns:
- my-file.js
include:
- my-other-file.js
exclude:
- my-exclude-file.jsJust repeating myself, the reason to not allow that merging is that service goes before package regardless of whether it's patterns or include/exclude. And exclude goes before include.
However, if we mix include/exclude/pattern in the same config. We need to decide in which order to merge them.
It's trivial, I know, exclude -> include -> patterns, but users might expect otherwise and create confusion.
User should not reason about order in such case, but simply ensure that just patterns is used , also again deprecation notice will signal that config stands on quirky ground
That's right! That's why I thought that all combinations should be allowed, except for the one that combines both in the same object.
Was this already clear to you?
There was a problem hiding this comment.
You can use patterns OR include/exclude at the function level.
It doesn't matter if you use pattern in patterns at service and include/exclude at the function
In last comment, my point was that above feels confusing. If we already support mixing both include and patterns (coming from two configuration sources) to package given lambda, why restrict mixing of include and patterns coming from one configuration source.
However, if we mix include/exclude/pattern in the same config. We need to decide in which order to merge them.
Yes, I've proposed order in one of the first comments here: #8581 (comment)
It's trivial, I know, exclude -> include -> patterns, but users might expect otherwise and create confusion.
User should not investigate and debate on such order, instead should just use pattern. We'd allow mixing both sas temporary mean simply for ease of migration (no need to be too restrictive here)
9aa9040 to
bfdd385
Compare
|
Alright, error removed. |
|
@juanjoDiaz is this ready for re-review? If it's the case please re-request it (in reviewers box). Thank you! |
a08dcb6 to
1bb24b5
Compare
|
Could we get this merged asap? |
@juanjoDiaz Thanks for update. Sure, we'll look into that shortly. Note that it was stale for a long while, as review was not re-requested. I found that it has some new pushes, simply during my maintenance walk through over open PR's. |
medikoo
left a comment
There was a problem hiding this comment.
@juanjoDiaz Looks great to me!
@pgrzesik I've reviewed this PR back in December, and now just re-reviewed changes after merge update. It all looks good to me, but can you re-review this PR with a fresh eye (please merge if there are no doubts)
pgrzesik
left a comment
There was a problem hiding this comment.
Thanks @juanjoDiaz 🙇 I have only two small things - one about adding deprecation code to deprecations.md section that I've mentioned in other comment. Another thing is that I'd like you to ask to update serverless.yml.md reference file: https://github.com/serverless/serverless/blob/master/docs/providers/aws/guide/serverless.yml.md so it reflects changes introduced in this PR. After having these, we're good to go 💯
|
@juanjoDiaz do you plan to finalize this PR? If you lack resources we totally understand and we will happily take over, just let us know |
d609ff9 to
000bca0
Compare
|
Hi @medikoo , Can you clarified what's left? I've been attending all of your requests AFAIK. But then it goes stale and conflicts start arising as master moves forward. |
CI status was red, and we didn't have any notification that's ready for review. When it's ready for review, please re-request it in top right box. Thank you! |
|
Alright! |
pgrzesik
left a comment
There was a problem hiding this comment.
Thank you @juanjoDiaz 🙇 Looks good - @medikoo, could you also take a look at it before merging?
medikoo
left a comment
There was a problem hiding this comment.
Looks great! Thank you @juanjoDiaz
|
@juanjoDiaz @medikoo I have tried two ways:
But both are not working. I am just guessing the features you guys developed here are not applicable when using |
It could be the case. Best is to confirm with plugin directly (and I see you've opened AnomalyInnovations/serverless-bundle#363) |
|
A quick search of |
Closes: #8093