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): init templates not initialized when running the CLI from source #11731

Merged
merged 2 commits into from
Nov 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/aws-cdk/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,13 @@ interface ProjectInfo {

function versionedTemplatesDir(): Promise<string> {
return new Promise(async resolve => {
const majorVersion = semver.major(versionNumber());
let currentVersion = versionNumber();
// If the CLI is invoked from source (i.e., developement), rather than from a packaged distribution,
// the version number will be '0.0.0'. We will (currently) default to the v1 templates in this case.
if (currentVersion === '0.0.0') {
currentVersion = '1.0.0';
}
const majorVersion = semver.major(currentVersion);
resolve(path.join(__dirname, 'init-templates', `v${majorVersion}`));
});
}
Expand Down
7 changes: 7 additions & 0 deletions packages/aws-cdk/test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ describe.each(['1', '2'])('v%s tests', (majorVersion) => {
});
});

test('when no version number is present (e.g., local development), the v1 templates are chosen by default', async () => {
mockMajorVersion = '0.0.0';
jest.resetAllMocks();

expect((await availableInitTemplates()).length).toBeGreaterThan(0);
});

function cliTest(name: string, handler: (dir: string) => void | Promise<any>): void {
test(name, () => withTempDir(handler));
}
Expand Down