Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): multiple library copies lead to 'Assets must be defined within Stage or App' error #11113

Merged
merged 3 commits into from Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/@aws-cdk/core/lib/stage.ts
Expand Up @@ -7,6 +7,8 @@ import { synthesize } from './private/synthesis';
// eslint-disable-next-line
import { Construct as CoreConstruct } from './construct-compat';

const STAGE_SYMBOL = Symbol.for('@aws-cdk/core.Stage');

/**
* Initialization props for a stage.
*/
Expand Down Expand Up @@ -85,7 +87,7 @@ export class Stage extends CoreConstruct {
* @experimental
*/
public static isStage(x: any ): x is Stage {
return x !== null && x instanceof Stage;
return x !== null && typeof(x) === 'object' && STAGE_SYMBOL in x;
}

/**
Expand Down Expand Up @@ -137,6 +139,8 @@ export class Stage extends CoreConstruct {
throw new Error(`invalid stage name "${id}". Stage name must start with a letter and contain only alphanumeric characters, hypens ('-'), underscores ('_') and periods ('.')`);
}

Object.defineProperty(this, STAGE_SYMBOL, { value: true });

this.parentStage = Stage.of(this);

this.region = props.env?.region ?? this.parentStage?.region;
Expand Down
29 changes: 29 additions & 0 deletions packages/@aws-cdk/core/test/stage.test.ts
Expand Up @@ -280,6 +280,35 @@ nodeunitShim({
test.throws(() => new Stage(app, 'mystage', { outdir: '/tmp/foo/bar' }), /"outdir" cannot be specified for nested stages/);
test.done();
},

'Stage.isStage indicates that a construct is a stage'(test: Test) {
// WHEN
const app = new App();
const stack = new Stack();
const stage = new Stage(app, 'Stage');

// THEN
test.ok(Stage.isStage(stage));
test.ok(Stage.isStage(app));
test.ok(!Stage.isStage(stack));
test.done();
},

'Stage.isStage indicates that a construct is a stage based on symbol'(test: Test) {
// WHEN
const app = new App();
const stage = new Stage(app, 'Stage');

const externalStage = {};
const STAGE_SYMBOL = Symbol.for('@aws-cdk/core.Stage');
Object.defineProperty(externalStage, STAGE_SYMBOL, { value: true });

// THEN
test.ok(Stage.isStage(stage));
test.ok(Stage.isStage(app));
test.ok(Stage.isStage(externalStage));
test.done();
},
});

class TouchingAspect implements IAspect {
Expand Down