Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,37 @@ export function withTrimmedWhitespace(ioHost: IIoHost): IIoHost {
notify: async <T>(msg: IoMessage<T>) => {
await ioHost.notify({
...msg,
message: msg.message.trim(),
message: trimWhitespace(msg.message),
});
},
requestResponse: async <T, U>(msg: IoRequest<T, U>) => {
return ioHost.requestResponse({
...msg,
message: msg.message.trim(),
message: trimWhitespace(msg.message),
});
},
};
}

/**
* Trims whitespace at both ends of a message, also when it sits inside
* ANSI style codes (e.g. a colored message that starts with a newline).
* The style codes themselves are kept.
*/
function trimWhitespace(msg: string): string {
// Even indices are text, odd indices are the style codes between them
const parts = msg.split(/(\u001b\[[0-9;]*m)/);
for (let i = 0; i < parts.length; i += 2) {
parts[i] = parts[i].trimStart();
if (parts[i]) {
break;
}
}
for (let i = parts.length - 1; i >= 0; i -= 2) {
parts[i] = parts[i].trimEnd();
if (parts[i]) {
break;
}
}
return parts.join('');
}
17 changes: 17 additions & 0 deletions packages/@aws-cdk/toolkit-lib/test/toolkit/toolkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ describe('message formatting', () => {
message: 'test message',
}));
});

test('whitespace inside color codes is trimmed from a message', async () => {
toolkit = new Toolkit({ ioHost });

await toolkit.ioHost.notify({
message: '\u001b[1m\n\u001b[32m test message \u001b[39m\n\u001b[22m',
action: 'deploy',
level: 'info',
code: 'CDK_TOOLKIT_I0000',
time: new Date(),
data: undefined,
});

expect(ioHost.notifySpy).toHaveBeenCalledWith(expect.objectContaining({
message: '\u001b[1m\u001b[32mtest message\u001b[39m\u001b[22m',
}));
});
});

test('outputs of assembly are measured', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"seq":0,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1000","message":"Starting Synthesis ..."}
{"seq":1,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":2,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7100","message":"Test-Stack-B: destroying... [1/1]"}
{"seq":3,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"\n✅ Test-Stack-B: destroyed"}
{"seq":3,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"✅ Test-Stack-B: destroyed"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{"seq":0,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1000","message":"Starting Synthesis ..."}
{"seq":1,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":2,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7100","message":"Test-Stack-B: destroying... [1/1]"}
{"seq":3,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"\n✅ Test-Stack-B: destroyed"}
{"seq":4,"type":"notify","action":"destroy","level":"warn","code":"CDK_TOOLKIT_W7902","message":"⚠️ Stack deleted using Express Mode. Resources still tearing down: MyResource\n"}
{"seq":3,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"✅ Test-Stack-B: destroyed"}
{"seq":4,"type":"notify","action":"destroy","level":"warn","code":"CDK_TOOLKIT_W7902","message":"⚠️ Stack deleted using Express Mode. Resources still tearing down: MyResource"}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
{"seq":1,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":2,"type":"request","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7010","message":"Are you sure you want to delete: Test-Stack-B","response":true}
{"seq":3,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7100","message":"Test-Stack-B: destroying... [1/1]"}
{"seq":4,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"\n✅ Test-Stack-B: destroyed"}
{"seq":4,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"✅ Test-Stack-B: destroyed"}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"seq":0,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1000","message":"Starting Synthesis ..."}
{"seq":1,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":2,"type":"notify","action":"deploy","level":"info","code":"CDK_TOOLKIT_I7100","message":"Test-Stack-A/Test-Stack-C: destroying... [1/1]"}
{"seq":3,"type":"notify","action":"deploy","level":"info","code":"CDK_TOOLKIT_I7900","message":"\n✅ Test-Stack-A/Test-Stack-C: deployed"}
{"seq":3,"type":"notify","action":"deploy","level":"info","code":"CDK_TOOLKIT_I7900","message":"✅ Test-Stack-A/Test-Stack-C: deployed"}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{"seq":1,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":2,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7100","message":"Test-Stack-A-Display-Name: destroying... [1/2]"}
{"seq":3,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7100","message":"Test-Stack-B: destroying... [2/2]"}
{"seq":4,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"\n✅ Test-Stack-A-Display-Name: destroyed"}
{"seq":5,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"\n✅ Test-Stack-B: destroyed"}
{"seq":4,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"✅ Test-Stack-A-Display-Name: destroyed"}
{"seq":5,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"✅ Test-Stack-B: destroyed"}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"seq":0,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1000","message":"Starting Synthesis ..."}
{"seq":1,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":2,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7100","message":"Test-Stack-B: destroying... [1/1]"}
{"seq":3,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"\n✅ Test-Stack-B: destroyed"}
{"seq":3,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"✅ Test-Stack-B: destroyed"}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{"seq":0,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1000","message":"Starting Synthesis ..."}
{"seq":1,"type":"notify","action":"destroy","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":2,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7100","message":"Test-Stack-D: destroying... [1/2]"}
{"seq":3,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"\n✅ Test-Stack-D: destroyed"}
{"seq":3,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"✅ Test-Stack-D: destroyed"}
{"seq":4,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7100","message":"Test-Stack-C: destroying... [2/2]"}
{"seq":5,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"\n✅ Test-Stack-C: destroyed"}
{"seq":5,"type":"notify","action":"destroy","level":"info","code":"CDK_TOOLKIT_I7900","message":"✅ Test-Stack-C: destroyed"}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{"seq":1,"type":"notify","action":"refactor","level":"trace","code":"CDK_CLI_I1000","message":"Starting Synthesis ..."}
{"seq":2,"type":"notify","action":"refactor","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":3,"type":"notify","action":"refactor","level":"info","code":"CDK_TOOLKIT_I1000","message":"✨ Synthesis time: <DURATION>"}
{"seq":4,"type":"notify","action":"refactor","level":"info","code":null,"message":"aws://123456789012/bermuda-triangle-1\n"}
{"seq":5,"type":"notify","action":"refactor","level":"result","code":"CDK_TOOLKIT_I8900","message":"The following resources were moved or renamed:\n┌─────────────────┬───────────────────────────┬───────────────────────────┐\n│ Resource Type │ Old Construct Path │ New Construct Path │\n├─────────────────┼───────────────────────────┼───────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/OldBucket/Resource │ Stack1/NewBucket/Resource │\n└─────────────────┴───────────────────────────┴───────────────────────────┘\n "}
{"seq":4,"type":"notify","action":"refactor","level":"info","code":null,"message":"aws://123456789012/bermuda-triangle-1"}
{"seq":5,"type":"notify","action":"refactor","level":"result","code":"CDK_TOOLKIT_I8900","message":"The following resources were moved or renamed:\n┌─────────────────┬───────────────────────────┬───────────────────────────┐\n│ Resource Type │ Old Construct Path │ New Construct Path │\n├─────────────────┼───────────────────────────┼───────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/OldBucket/Resource │ Stack1/NewBucket/Resource │\n└─────────────────┴───────────────────────────┴───────────────────────────┘"}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{"seq":1,"type":"notify","action":"refactor","level":"trace","code":"CDK_CLI_I1000","message":"Starting Synthesis ..."}
{"seq":2,"type":"notify","action":"refactor","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":3,"type":"notify","action":"refactor","level":"info","code":"CDK_TOOLKIT_I1000","message":"✨ Synthesis time: <DURATION>"}
{"seq":4,"type":"notify","action":"refactor","level":"info","code":null,"message":"aws://123456789012/bermuda-triangle-1\n"}
{"seq":5,"type":"notify","action":"refactor","level":"result","code":"CDK_TOOLKIT_I8900","message":"The following resources were moved or renamed:\n┌─────────────────┬──────────────────────────┬──────────────────────────┐\n│ Resource Type │ Old Construct Path │ New Construct Path │\n├─────────────────┼──────────────────────────┼──────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/MyBucket/Resource │ Stack2/MyBucket/Resource │\n└─────────────────┴──────────────────────────┴──────────────────────────┘\n "}
{"seq":4,"type":"notify","action":"refactor","level":"info","code":null,"message":"aws://123456789012/bermuda-triangle-1"}
{"seq":5,"type":"notify","action":"refactor","level":"result","code":"CDK_TOOLKIT_I8900","message":"The following resources were moved or renamed:\n┌─────────────────┬──────────────────────────┬──────────────────────────┐\n│ Resource Type │ Old Construct Path │ New Construct Path │\n├─────────────────┼──────────────────────────┼──────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/MyBucket/Resource │ Stack2/MyBucket/Resource │\n└─────────────────┴──────────────────────────┴──────────────────────────┘"}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{"seq":1,"type":"notify","action":"refactor","level":"trace","code":"CDK_CLI_I1000","message":"Starting Synthesis ..."}
{"seq":2,"type":"notify","action":"refactor","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":3,"type":"notify","action":"refactor","level":"info","code":"CDK_TOOLKIT_I1000","message":"✨ Synthesis time: <DURATION>"}
{"seq":4,"type":"notify","action":"refactor","level":"info","code":null,"message":"aws://123456789012/bermuda-triangle-1\n"}
{"seq":5,"type":"notify","action":"refactor","level":"result","code":"CDK_TOOLKIT_I8900","message":"The following resources were moved or renamed:\n┌─────────────────┬─────────────────────────┬─────────────────────────┐\n│ Resource Type │ Old Construct Path │ New Construct Path │\n├─────────────────┼─────────────────────────┼─────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/Bucket3/Resource │ Stack1/Bucket1/Resource │\n├─────────────────┼─────────────────────────┼─────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/Bucket4/Resource │ Stack1/Bucket2/Resource │\n└─────────────────┴─────────────────────────┴─────────────────────────┘\n "}
{"seq":4,"type":"notify","action":"refactor","level":"info","code":null,"message":"aws://123456789012/bermuda-triangle-1"}
{"seq":5,"type":"notify","action":"refactor","level":"result","code":"CDK_TOOLKIT_I8900","message":"The following resources were moved or renamed:\n┌─────────────────┬─────────────────────────┬─────────────────────────┐\n│ Resource Type │ Old Construct Path │ New Construct Path │\n├─────────────────┼─────────────────────────┼─────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/Bucket3/Resource │ Stack1/Bucket1/Resource │\n├─────────────────┼─────────────────────────┼─────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/Bucket4/Resource │ Stack1/Bucket2/Resource │\n└─────────────────┴─────────────────────────┴─────────────────────────┘"}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{"seq":1,"type":"notify","action":"refactor","level":"trace","code":"CDK_CLI_I1000","message":"Starting Synthesis ..."}
{"seq":2,"type":"notify","action":"refactor","level":"trace","code":"CDK_CLI_I1001","message":"\n✨ Synthesis time: <DURATION>\n"}
{"seq":3,"type":"notify","action":"refactor","level":"info","code":"CDK_TOOLKIT_I1000","message":"✨ Synthesis time: <DURATION>"}
{"seq":4,"type":"notify","action":"refactor","level":"info","code":null,"message":"aws://123456789012/bermuda-triangle-1\n"}
{"seq":5,"type":"notify","action":"refactor","level":"result","code":"CDK_TOOLKIT_I8900","message":"The following resources were moved or renamed:\n┌─────────────────┬─────────────────────────┬─────────────────────────┐\n│ Resource Type │ Old Construct Path │ New Construct Path │\n├─────────────────┼─────────────────────────┼─────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/Bucket1/Resource │ Stack1/Bucket3/Resource │\n├─────────────────┼─────────────────────────┼─────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/Bucket2/Resource │ Stack1/Bucket4/Resource │\n└─────────────────┴─────────────────────────┴─────────────────────────┘\n "}
{"seq":4,"type":"notify","action":"refactor","level":"info","code":null,"message":"aws://123456789012/bermuda-triangle-1"}
{"seq":5,"type":"notify","action":"refactor","level":"result","code":"CDK_TOOLKIT_I8900","message":"The following resources were moved or renamed:\n┌─────────────────┬─────────────────────────┬─────────────────────────┐\n│ Resource Type │ Old Construct Path │ New Construct Path │\n├─────────────────┼─────────────────────────┼─────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/Bucket1/Resource │ Stack1/Bucket3/Resource │\n├─────────────────┼─────────────────────────┼─────────────────────────┤\n│ AWS::S3::Bucket │ Stack1/Bucket2/Resource │ Stack1/Bucket4/Resource │\n└─────────────────┴─────────────────────────┴─────────────────────────┘"}
Loading
Loading