-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appcomposer): load and save from VS Code buffer
## Problem - Application Composer works directly off of the workspace files. Changes in VS Code will only be detected by App Composer when the user saves, and changes in Composer will immediately be saved to disk. This does not follow the standard VS Code pattern. ## Solution - This updates Application Composer to read from and write to VS Code text documents when possible, ensuring that Composer is synced with the latest user changes and giving the user more control over what changes are saved.
- Loading branch information
Jacob Largent
committed
Feb 29, 2024
1 parent
82b6a9b
commit 46904dd
Showing
10 changed files
with
151 additions
and
40 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
.changes/next-release/Feature-1a6b555a-5d90-4fef-9679-cb03c9175d7b.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "Feature", | ||
"description": "Application Composer: Change file management to work with unsaved files" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const bufferTimeMs = 1000 | ||
|
||
export const localhost = 'http://127.0.0.1:3000' | ||
export const cdn = 'https://d29yvv2j7swt8n.cloudfront.net' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/toolkit/src/applicationcomposer/utils/templateShouldBeUpdated.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { loadByContents } from '../../shared/cloudformation/cloudformation' | ||
import equal from 'fast-deep-equal/es6' | ||
|
||
/** | ||
* Checks whether a template needs to be updated. This is eiter when the template is out of sync, or | ||
* when at least one of the templates cannot be parsed. Comments and whitespace should not result | ||
* in a template update. | ||
*/ | ||
export async function templateShouldBeUpdated(oldTemplate: string, newTemplate: string) { | ||
try { | ||
const oldParsedTemplate = await loadByContents(oldTemplate, false) | ||
const newParsedTemplate = await loadByContents(newTemplate, false) | ||
return !equal(oldParsedTemplate, newParsedTemplate) | ||
} catch (e) { | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/toolkit/src/test/applicationcomposer/utils/templateShouldBeUpdated.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { templateShouldBeUpdated } from '../../../applicationcomposer/utils/templateShouldBeUpdated' | ||
import assert from 'assert' | ||
|
||
describe('templateShouldBeUpdated', async function () { | ||
const before = ` | ||
Resources: | ||
SomeResource: | ||
Key: value` | ||
|
||
it('template has meaningful changes, returns true', async function () { | ||
const after = ` | ||
Resources: | ||
SomeResource: | ||
Key: value2` | ||
|
||
const result = await templateShouldBeUpdated(before, after) | ||
assert.strictEqual(result, true) | ||
}) | ||
|
||
it('template cannot be parsed, returns true', async function () { | ||
const unparseable = ` | ||
Resources: | ||
SomeResource | ||
Key: value` | ||
|
||
const result = await templateShouldBeUpdated(unparseable, unparseable) | ||
assert.strictEqual(result, true) | ||
}) | ||
|
||
it('template is identical, returns false', async function () { | ||
const result = await templateShouldBeUpdated(before, before) | ||
assert.strictEqual(result, false) | ||
}) | ||
|
||
it('template only has whitespace change, returns false', async function () { | ||
const after = ` | ||
# Some comment | ||
Resources: | ||
SomeResource: | ||
Key: value` | ||
const result = await templateShouldBeUpdated(before, after) | ||
assert.strictEqual(result, false) | ||
}) | ||
}) |