forked from yarnpkg/yarn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli-create): fix scoped creation (yarnpkg#6239)
* fix(cli-create): fix scoped creation 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 * refactor(cli-create): make parsePackageName more robust and add tests * refactor(cli-create): add missing typyings
- Loading branch information
1 parent
77b8444
commit acf82e2
Showing
2 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// @flow | ||
|
||
import {parsePackageName, coerceCreatePackageName} from '../../src/cli/commands/create'; | ||
|
||
describe(`parsePackageName`, () => { | ||
test('invalid', () => { | ||
expect(() => { | ||
parsePackageName('@/name'); | ||
}).toThrowError(`Scope should not be empty, got "@/name"`); | ||
expect(() => { | ||
parsePackageName('/name'); | ||
}).toThrowError(`Name should not start with "/", got "/name"`); | ||
expect(() => { | ||
parsePackageName('./name'); | ||
}).toThrowError(`Name should not start with ".", got "./name"`); | ||
}); | ||
|
||
test('basic', () => { | ||
expect(parsePackageName('name')).toEqual({ | ||
fullName: 'name', | ||
name: 'name', | ||
scope: '', | ||
path: '', | ||
full: 'name', | ||
}); | ||
expect(parsePackageName('@scope/name')).toEqual({ | ||
fullName: '@scope/name', | ||
name: 'name', | ||
scope: '@scope', | ||
path: '', | ||
full: '@scope/name', | ||
}); | ||
expect(parsePackageName('@scope/name/path/to/file.js')).toEqual({ | ||
fullName: '@scope/name', | ||
name: 'name', | ||
scope: '@scope', | ||
path: 'path/to/file.js', | ||
full: '@scope/name/path/to/file.js', | ||
}); | ||
}); | ||
|
||
test('without name', () => { | ||
expect(parsePackageName('@scope/')).toEqual({ | ||
fullName: '@scope', | ||
name: '', | ||
scope: '@scope', | ||
path: '', | ||
full: '@scope', | ||
}); | ||
expect(parsePackageName('@scope')).toEqual({ | ||
fullName: '@scope', | ||
name: '', | ||
scope: '@scope', | ||
path: '', | ||
full: '@scope', | ||
}); | ||
}); | ||
}); | ||
|
||
describe(`coerceCreatePackageName`, () => { | ||
test('invalid', () => { | ||
expect(() => { | ||
coerceCreatePackageName('@/name'); | ||
}).toThrow(); | ||
expect(() => { | ||
coerceCreatePackageName('/name'); | ||
}).toThrow(); | ||
expect(() => { | ||
coerceCreatePackageName('./name'); | ||
}).toThrow(); | ||
}); | ||
|
||
test('basic', () => { | ||
expect(coerceCreatePackageName('name')).toEqual({ | ||
fullName: 'create-name', | ||
name: 'create-name', | ||
scope: '', | ||
path: '', | ||
full: 'create-name', | ||
}); | ||
expect(coerceCreatePackageName('@scope/name')).toEqual({ | ||
fullName: '@scope/create-name', | ||
name: 'create-name', | ||
scope: '@scope', | ||
path: '', | ||
full: '@scope/create-name', | ||
}); | ||
expect(coerceCreatePackageName('@scope/name/path/to/file.js')).toEqual({ | ||
fullName: '@scope/create-name', | ||
name: 'create-name', | ||
scope: '@scope', | ||
path: 'path/to/file.js', | ||
full: '@scope/create-name/path/to/file.js', | ||
}); | ||
}); | ||
|
||
test('not postfixing with "-" if name is emptu', () => { | ||
expect(coerceCreatePackageName('@scope/').fullName).toEqual('@scope/create'); | ||
expect(coerceCreatePackageName('@scope').fullName).toEqual('@scope/create'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters