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(cli-create): fix scoped creation #6239

Merged
merged 3 commits into from
Aug 13, 2018

Conversation

iamstarkov
Copy link
Contributor

@iamstarkov iamstarkov commented Aug 6, 2018

This one works as it should:
yarn create @scope/name => @scope/create-name

There were problems when name was omitted:

Before:
yarn create @scope => create-
yarn create @scope/ => @scope/create-

After:
yarn create @scope => @scope/create
yarn create @scope/ => @scope/create

Fixes #6233

Summary

it Is not substantial feature request.

Existing behaviour is a bit odd and not aligned with npm. This PR aims to fix it.

Test plan

~/projects/oss/yarn fix/scoped-create
☯ ./bin/yarn create name
{ packageName: 'create-name',
  packageDir: '',
  commandName: 'create-name' }

~/projects/oss/yarn fix/scoped-create
☯ ./bin/yarn create @scope/name
{ packageName: '@scope/create-name',
  packageDir: '@scope',
  commandName: 'create-name' }

~/projects/oss/yarn fix/scoped-create
☯ ./bin/yarn create @scope/
{ packageName: '@scope/create',
  packageDir: '@scope',
  commandName: 'create' }

~/projects/oss/yarn fix/scoped-create
☯ ./bin/yarn create @scope
{ packageName: '@scope/create',
  packageDir: '@scope',
  commandName: 'create' }

Disclaimer:

  • I didnt manage to adjust existing RegExps to fix bug: whenever I fixed one use case another one was breaking.
  • Due to difficulties with RegExps I streamlined package's scope and name extraction with few helpers.
  • Couldn't find a place to add test for helper, so I inlined working test assertions.
  • Also I couldn't find documentation in a repository, thus couldn't update it and sadly contribution guide doesnt describe how to update docs.

If tests or documentation are required to be added/updated in the same PR please let me know how to do it.

@buildsize
Copy link

buildsize bot commented Aug 6, 2018

File name Previous Size New Size Change
yarn-[version].noarch.rpm 920.27 KB 920.56 KB 294 bytes (0%)
yarn-[version].js 4.02 MB 4.02 MB 1.41 KB (0%)
yarn-legacy-[version].js 4.18 MB 4.18 MB 1.39 KB (0%)
yarn-v[version].tar.gz 925.92 KB 925.46 KB -468 bytes (0%)
yarn_[version]all.deb 675.38 KB 675.53 KB 154 bytes (0%)

This one works as it should:
yarn create @scope/name => @scope/create-name

There were problems when name was omitted:

Before:
yarn create @scope => create-
yarn create @scope/ => @scope/create-

After:
yarn create @scope => @scope/create
yarn create @scope/ => @scope/create

Fixes yarnpkg#6233
@iamstarkov
Copy link
Contributor Author

ci/circleci: test-pkg-tests-linux-node10 failed I believe due to some network glitch:

error https://registry.yarnpkg.com/ws/-/ws-4.0.0.tgz: Integrity check failed for "ws" (computed integrity doesn't match our records, got "sha512-o0lyLXKExgoAAX5h3jesLVi7vSGrwFJGpy+Zc+/gil3UWQz2jnGkhD84rpkIJmYE3DIsOnuoojk2CqO19D653g==")

@iamstarkov
Copy link
Contributor Author

@arcanis @torifat, please take a look when you have time

* ## edge cases
* parseBuilderName('@/name').packageName === 'create-name'
* parseBuilderName('/name').packageName === 'create-name'
* parseBuilderName('@/').packageName === 'create'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if you could put this in a file called __tests__/commands/create.js (you can just export the parseBuilderName symbol and require the file), so that they are actually ran. Otherwise the comment can just be removed, since it will never be run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, will do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added tests

*/
const parseBuilderName = str => {
const parts = str.split('/');
if (parts.length === 1 && !str.includes('@')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str.charAt(0) === '@' would be more correct, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* parseBuilderName('@/').packageName === 'create'
*/
const parseBuilderName = str => {
const parts = str.split('/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should reject as invalid if there's more than two parts, or if the first part doesn't start with a '@'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed parseBuilderName to parsePackageName and it throws error if first character is . or /. It also throws if scope equals @.

About throwing id there are more than 2 parts: and i want yarn to be robust so I just put that extra part into path field of pkgNameObject¹ and ignore it in rest of create command.

[1]:

'@scope/name/path/to/file.js' => pkgNameObject {
  fullName: '@scope/name',
  name: 'name',
  scope: '@scope',
  path: 'path/to/file.js',
  full: '@scope/name/path/to/file.js',
}

@iamstarkov
Copy link
Contributor Author

@aracarie updated PR with respect to requested changes

@iamstarkov
Copy link
Contributor Author

@arcanis had any chance to review it?

@arcanis
Copy link
Member

arcanis commented Aug 13, 2018

Looks great, thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

yarn create @scope doesnt work as expected
3 participants