Repository navigation
Add Cyclic Object Serialization Support - #4146
Conversation
…ng written to file using json-decycle.
|
you may want to reject the non-targeted package-lock.json changes |
|
@erikerikson thanks for that! if it's not much of a hassle, could you add unit test for the stringify util function? I think just a test that ensures circular object is correctly stringified or at least that the decycle package is used. Since other utils use that function, this test would cover them as well. |
pmuens
left a comment
There was a problem hiding this comment.
Thanks for the PR @erikerikson 👍
I'm not sure if Travis is lying here but the json-decycle package has a dependency on ES6 features (https://github.com/YChebotaev/json-decycle#es6-features).
Is there any chance to remove the package and e.g. copy and paste over the parts which are necessary as util functions?
This way we'd also remove one more dependency from our (already huge) dependencies list.
|
Both of these requests seem reasonable enough |
Thanks @erikerikson 👍. Do you have time to fix this or should we jump in here and help with this PR? |
|
I certainly hope I do. The responsibilities... I will not be offended if you do the work but will do it if I can find time to prioritize. |
|
@eahefnawy will probably have to fix the other issue noted on his PR though... I haven't been able to dive deeply enough to resolve the core issue there yet. |
|
Alright! Thanks for the update @erikerikson 👍 |
|
@erikerikson I just look into this and found the I updated the PR so that this package is used rather than Could you share a Thanks in advance 👍! |
|
Just a quick update on this one. I tested @eahefnawy PR #4144 with this service setup (this issue was linked in the PR description) which should trigger the error described here. (Un)fortunately I was not able to reproduce it since the packaging works fine when using #4144. Maybe @eahefnawy added something in the meantime which fixed this "circular JSON structure" as well? |
add parse self-reference test add writeFile self-reference test add writeFileSync self-reference test
| .then(() => { | ||
| if (filePath.indexOf('.json') !== -1 && typeof contents !== 'string') { | ||
| contents = JSON.stringify(contents, null, 2); | ||
| contents = jc.stringify(contents); |
There was a problem hiding this comment.
FWIW, the 2nd and 3rd parameters are not recognized by json-cycle so it doesn't yet make sense to pass them
There was a problem hiding this comment.
resolving this pends upon the acceptance of valery-barysok/json-cycle#4
There was a problem hiding this comment.
@erikerikson can't we just pass the values in for now (although they're ignored)? This way we could bump the package version number later on and it would work OOTB without the need to touch the code here again.
|
|
||
| if (filePath.indexOf('.json') !== -1 && typeof contents !== 'string') { | ||
| contents = JSON.stringify(contents, null, 2); | ||
| contents = jc.stringify(contents); |
There was a problem hiding this comment.
FWIW, the 2nd and 3rd parameters are not recognized by json-cycle so it doesn't yet make sense to pass them
|
@eahefnawy Tests have been added for all the affected modules |
Great! Thanks for updating the PR @erikerikson 👍. We'll give it another spin the upcoming days! |
pmuens
left a comment
There was a problem hiding this comment.
@erikerikson thanks for updating this PR 👍
I just gave it a spin today with the following service config (the one taken from the linked issue in the PR description):
service: self-reference
provider:
name: aws
runtime: nodejs4.3
custom:
newService: ${self:}
exportName: ${self:custom.newService.service}-export
functions:
hello:
handler: handler.hello
resources:
Outputs:
selfExport:
Value: 'A Value To Export'
Export:
Name: ${self:custom.exportName}
OptExport:
Value: 'Exported option variable'
Export:
Name: ${opt:}
EnvExport:
Value: 'Exported env variable'
Export:
Name: ${env:}In master the packaging process fails.
This PR seems to fix the problem. But I tested the exact same service with #4144 and #4144 solves the problem as well. If both solve the same problem then I'd be in favor of #4144 because it's a smaller fix (in terms of LOC) and doesn't introduce another dependency.
Other downside of json-cycle right now is that the JSON content is not formatted in a pretty way. But this is something which needs to be done in the json-cycle package (as @erikerikson already mentioned). I just left a comment for a potential code update there.
| .then(() => { | ||
| if (filePath.indexOf('.json') !== -1 && typeof contents !== 'string') { | ||
| contents = JSON.stringify(contents, null, 2); | ||
| contents = jc.stringify(contents); |
There was a problem hiding this comment.
@erikerikson can't we just pass the values in for now (although they're ignored)? This way we could bump the package version number later on and it would work OOTB without the need to touch the code here again.
|
Hi @pmuens I have tried this out. I observed the same as you with a simple script. So, I looked closer... First: here's the code that "solved" the issue for this PR: https://github.com/serverless/serverless/blob/circular-vars/lib/plugins/aws/package/lib/saveServiceState.js#L28 However, when I run this code against https://github.com/Nordstrom/hello-retail/blob/master/product-catalog/builder/serverless.yml, I get the reported problem: If I switch to #4146, the error does not occur. Probably there is some bug here: .. but I haven't looked deeper yet and need to sleep. |
|
Additional. I opened a PR against |
use pretty-print capability update tests
|
edits 4144 => 4146 as appropriate. Latest commit includes use of pretty printing and updates to tests Should be GTM |
|
It may be worth a PR to remove the code that isn't doing the job properly (https://github.com/serverless/serverless/blob/circular-vars/lib/plugins/aws/package/lib/saveServiceState.js#L28) |
pmuens
left a comment
There was a problem hiding this comment.
Thank you very much for the in-depth description and steps to reproduce @erikerikson 🥇! That was super helpful 👍
I was able to reproduce this and could validate that #4144 won't fix the issue with circular JSON structures.
I tested this thoroughly and it's GTM 💯
Thanks for taking the time to work on and fix this @erikerikson 💪
What did you implement:
Re-Closes #3509
Allow for the serialization and deserialization of cyclic objects being written to file using json-decycle. (in support of #4144)
How did you implement it:
Add
json-decycleand use and instance of it as the second parameter for JSON.stringify/JSON.parse for file writing and reading.How can we verify it:
A project with a
${self:}reference should be sufficient to evoke the issue. During serialization you would get the result:Todos:
Is this ready for review?: YES
Is it a breaking change?: NO