Skip to content

Commit

Permalink
Change serialization method within tree-metadata.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
bmoffatt committed Sep 22, 2023
1 parent eea12ea commit 91edfec
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@
"aws-cdk-lib/table",
"aws-cdk-lib/table/**",
"aws-cdk-lib/yaml",
"aws-cdk-lib/yaml/**"
"aws-cdk-lib/yaml/**",
"aws-cdk-lib/json-stream-stringify",
"aws-cdk-lib/json-stream-stringify/**"
]
},
"dependencies": {
Expand Down
28 changes: 28 additions & 0 deletions packages/aws-cdk-lib/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -750,4 +750,32 @@ THIS SOFTWARE IS PROVIDED BY GARY COURT "AS IS" AND ANY EXPRESS OR IMPLIED WARRA
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Gary Court.


----------------

** json-stream-stringify - https://www.npmjs.com/package/json-stream-stringify/v/3.0.0 | MIT
The MIT License

Copyright (c) 2016 Faleij <[email protected]>

Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and
associated documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----------------
7 changes: 5 additions & 2 deletions packages/aws-cdk-lib/core/lib/private/tree-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';

import { Construct, IConstruct } from 'constructs';
import { JsonStreamStringify } from 'json-stream-stringify';
import { ConstructInfo, constructInfoFromConstruct } from './runtime-info';
import { ArtifactType } from '../../../cloud-assembly-schema';
import { Annotations } from '../annotations';
Expand Down Expand Up @@ -71,14 +72,16 @@ export class TreeMetadata extends Construct {
this._tree = lookup;

const builder = session.assembly;
fs.writeFileSync(path.join(builder.outdir, FILE_PATH), JSON.stringify(tree, (key: string, value: any) => {
const jsonStream = new JsonStreamStringify(tree, (key: string, value: any) => {
// we are adding in the `parent` attribute for internal use
// and it doesn't make much sense to include it in the
// tree.json
if (key === 'parent') return undefined;
return value;
}, 2), { encoding: 'utf-8' });
}, 2);

const out = fs.createWriteStream(path.join(builder.outdir, FILE_PATH), { encoding: 'utf-8' });
jsonStream.pipe(out);
builder.addArtifact('Tree', {
type: ArtifactType.CDK_TREE,
properties: {
Expand Down
5 changes: 4 additions & 1 deletion packages/aws-cdk-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
],
"attribution": [
"kubectl",
"helm"
"helm",
"json-stream-stringify"
]
},
"jsii": {
Expand Down Expand Up @@ -115,6 +116,7 @@
"case",
"fs-extra",
"ignore",
"json-stream-stringify",
"jsonschema",
"minimatch",
"punycode",
Expand All @@ -130,6 +132,7 @@
"case": "1.6.3",
"fs-extra": "^11.1.1",
"ignore": "^5.2.4",
"json-stream-stringify": "^3.0.0",
"jsonschema": "^1.4.1",
"minimatch": "^3.1.2",
"punycode": "^2.3.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9044,6 +9044,11 @@ json-stable-stringify-without-jsonify@^1.0.1:
resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
integrity sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==

json-stream-stringify@^3.0.0:
version "3.1.0"
resolved "https://registry.npmjs.org/json-stream-stringify/-/json-stream-stringify-3.1.0.tgz#821df0993f630b7bba8198b1c966e5aaf9ec7657"
integrity sha512-ilynhoPlWa29XqgWJTD8V3bOF8k4Ybm3U9Oc7o/CG8qvFMGUzPlh9P4mOj9Ss3VtisA6N2OYevCWa14VRpJtQQ==

json-stringify-nice@^1.1.4:
version "1.1.4"
resolved "https://registry.npmjs.org/json-stringify-nice/-/json-stringify-nice-1.1.4.tgz#2c937962b80181d3f317dd39aa323e14f5a60a67"
Expand Down

0 comments on commit 91edfec

Please sign in to comment.