Skip to content

Commit

Permalink
Merge branch 'master' into benisrae/eks-fix-version-update
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Apr 23, 2020
2 parents 1be46b6 + 022eb66 commit d6a0d69
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 48 deletions.
30 changes: 0 additions & 30 deletions packages/aws-cdk/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ export class Configuration {
this._projectConfig = await loadAndLog(PROJECT_CONFIG);
this._projectContext = await loadAndLog(PROJECT_CONTEXT);

await this.migrateLegacyContext();

this.context = new Context(
this.commandLineContext,
this.projectConfig.subSettings([CONTEXT_KEY]).makeReadOnly(),
Expand Down Expand Up @@ -99,34 +97,6 @@ export class Configuration {

return this;
}

/**
* Migrate context from the 'context' field in the projectConfig object to the dedicated object
*
* Only migrate context whose key contains a ':', to migrate only context generated
* by context providers.
*/
private async migrateLegacyContext() {
const legacyContext = this.projectConfig.get([CONTEXT_KEY]);
if (legacyContext === undefined) { return; }

const toMigrate = Object.keys(legacyContext).filter(k => k.indexOf(':') > -1);
if (toMigrate.length === 0) { return; }

for (const key of toMigrate) {
this.projectContext.set([key], legacyContext[key]);
this.projectConfig.unset([CONTEXT_KEY, key]);
}

// If the source object is empty now, completely remove it
if (Object.keys(this.projectConfig.get([CONTEXT_KEY])).length === 0) {
this.projectConfig.unset([CONTEXT_KEY]);
}

// Save back
await this.projectConfig.save(PROJECT_CONFIG);
await this.projectContext.save(PROJECT_CONTEXT);
}
}

async function loadAndLog(fileName: string): Promise<Settings> {
Expand Down
21 changes: 3 additions & 18 deletions packages/aws-cdk/test/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@ test('load context from both files if available', async () => {
expect(config.context.get('boo')).toBe('far');
});

test('context with colons gets migrated to new file', async () => {
// GIVEN
await fs.writeJSON('cdk.context.json', { foo: 'bar' });
await fs.writeJSON('cdk.json', { context: { 'boo': 'far', 'boo:boo': 'far:far' } });
const config = await new Configuration().load();

// WHEN
config.context.set('baz', 'quux');
await config.saveContext();

// THEN
expect(await fs.readJSON('cdk.context.json')).toEqual({ 'foo': 'bar', 'boo:boo': 'far:far', 'baz': 'quux' });
expect(await fs.readJSON('cdk.json')).toEqual({ context: { boo: 'far'} });
});

test('deleted context disappears from new file', async () => {
// GIVEN
await fs.writeJSON('cdk.context.json', { foo: 'bar' });
Expand Down Expand Up @@ -84,7 +69,7 @@ test('clear deletes from new file', async () => {
expect(await fs.readJSON('cdk.json')).toEqual({ context: { boo: 'far' } });
});

test('surive missing new file', async () => {
test('context is preserved in the location from which it is read', async () => {
// GIVEN
await fs.writeJSON('cdk.json', { context: { 'boo:boo' : 'far' } });
const config = await new Configuration().load();
Expand All @@ -94,8 +79,8 @@ test('surive missing new file', async () => {
await config.saveContext();

// THEN
expect(await fs.readJSON('cdk.context.json')).toEqual({ 'boo:boo' : 'far' });
expect(await fs.readJSON('cdk.json')).toEqual({});
expect(await fs.readJSON('cdk.context.json')).toEqual({});
expect(await fs.readJSON('cdk.json')).toEqual({ context: { 'boo:boo' : 'far' } });
});

test('surive no context in old file', async () => {
Expand Down

0 comments on commit d6a0d69

Please sign in to comment.