Skip to content

Generate yarn.lock if cdk --init is used with yarn #4795

@nmussy

Description

@nmussy

Use Case

$ yarn global add cdk
$ cdk init --language=typescript
Executing npm install...

The expected behavior would be to run yarn install, to generate a yarn.lock instead of a package-lock.json

Proposed Solution

The issue is detecting whether cdk init was called from a npm or yarn global directory. Simply checking that yarn is installed is a tad overeager.

The cleanest solution would be to attempt to run yarn global bin. If this returns a valid path, and that path.join(yarnBinPath, 'cdk') exists, we can assume that the user yarn global install cdkd.

EDIT : We could be even stricter and match path.join(yarnBinPath, 'cdk') with process.argv[1], since it should look something like ['node', 'path/to/cdk', 'init']

After that, swap 'npm' with 'yarn', done:

const command = 'npm';

We could also add an option to init to forcefully provide command.

Other

Related to #871. Proposed yarn create @aws-cdk/deploy shouldn't generate a package-lock.json.

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Metadata

Metadata

Assignees

Labels

feature-requestA feature should be added or improved.in-progressThis issue is being actively worked on.package/toolsRelated to AWS CDK Tools or CLI

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions