-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Use an alias system instead of camelCase function #3101
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* @flow */ | ||
|
||
import unsupportedAliases from '../../src/cli/unsupported-aliases.js'; | ||
|
||
test('shorthands and affordances', () => { | ||
expect(unsupportedAliases['run-script']).toBe('run'); | ||
expect(unsupportedAliases['c']).toBe('config'); | ||
expect(unsupportedAliases['i']).toBe('install'); | ||
expect(unsupportedAliases['ls']).toBe('list'); | ||
expect(unsupportedAliases['rb']).toBe('rebuild'); | ||
expect(unsupportedAliases['runScript']).toBe('run'); | ||
expect(unsupportedAliases['t']).toBe('test'); | ||
expect(unsupportedAliases['tst']).toBe('test'); | ||
expect(unsupportedAliases['un']).toBe('remove'); | ||
expect(unsupportedAliases['up']).toBe('upgrade'); | ||
expect(unsupportedAliases['v']).toBe('version'); | ||
expect(unsupportedAliases['add-user']).toBe('login'); | ||
expect(unsupportedAliases['dist-tag']).toBe('tag'); | ||
expect(unsupportedAliases['dist-tags']).toBe('tag'); | ||
expect(unsupportedAliases['adduser']).toBe('login'); | ||
expect(unsupportedAliases['author']).toBe('owner'); | ||
expect(unsupportedAliases['isntall']).toBe('install'); | ||
expect(unsupportedAliases['la']).toBe('list'); | ||
expect(unsupportedAliases['ll']).toBe('list'); | ||
expect(unsupportedAliases['r']).toBe('remove'); | ||
expect(unsupportedAliases['rm']).toBe('remove'); | ||
expect(unsupportedAliases['show']).toBe('info'); | ||
expect(unsupportedAliases['uninstall']).toBe('remove'); | ||
expect(unsupportedAliases['update']).toBe('upgrade'); | ||
expect(unsupportedAliases['verison']).toBe('version'); | ||
expect(unsupportedAliases['view']).toBe('info'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "test_generate_lock_entry", | ||
"version": "1.0.0", | ||
"license": "UNLICENSED" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,6 @@ | ||
/* @flow */ | ||
|
||
const shorthands: { [key: string]: string } = { | ||
c: 'config', | ||
i: 'install', | ||
la: 'list', | ||
ll: 'list', | ||
ln: 'link', | ||
ls: 'list', | ||
r: 'remove', | ||
rb: 'rebuild', | ||
rm: 'remove', | ||
t: 'test', | ||
tst: 'test', | ||
un: 'remove', | ||
up: 'upgrade', | ||
v: 'version', | ||
}; | ||
|
||
const affordances: { [key: string]: string } = { | ||
'add-user': 'login', | ||
adduser: 'login', | ||
author: 'owner', | ||
'dist-tag': 'tag', | ||
'dist-tags': 'tag', | ||
isntall: 'install', | ||
'run-script': 'run', | ||
runScript: 'run', | ||
show: 'info', | ||
uninstall: 'remove', | ||
update: 'upgrade', | ||
verison: 'version', | ||
view: 'info', | ||
}; | ||
|
||
export default ({ | ||
...shorthands, | ||
...affordances, | ||
export default({ | ||
'upgrade-interactive': 'upgradeInteractive', | ||
'generate-lock-entry': 'generateLockEntry', | ||
}: { [key: string]: string }); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,88 @@ | ||
/* @flow */ | ||
import {ConsoleReporter, JSONReporter} from '../../reporters/index.js'; | ||
import * as constants from '../../constants.js'; | ||
import {MessageError} from '../../errors.js'; | ||
import Config from '../../config.js'; | ||
|
||
import * as access from './access.js'; export {access}; | ||
import * as add from './add.js'; export {add}; | ||
import * as bin from './bin.js'; export {bin}; | ||
import * as cache from './cache.js'; export {cache}; | ||
import * as check from './check.js'; export {check}; | ||
import * as clean from './clean.js'; export {clean}; | ||
import * as config from './config.js'; export {config}; | ||
import * as generateLockEntry from './generate-lock-entry.js'; export {generateLockEntry}; | ||
import * as global from './global.js'; export {global}; | ||
import * as help from './help.js'; export {help}; | ||
import * as import_ from './import.js'; export {import_ as import}; | ||
import * as info from './info.js'; export {info}; | ||
import * as init from './init.js'; export {init}; | ||
import * as install from './install.js'; export {install}; | ||
import * as licenses from './licenses.js'; export {licenses}; | ||
import * as link from './link.js'; export {link}; | ||
import * as login from './login.js'; export {login}; | ||
import * as logout from './logout.js'; export {logout}; | ||
import * as list from './list.js'; export {list}; | ||
import * as outdated from './outdated.js'; export {outdated}; | ||
import * as owner from './owner.js'; export {owner}; | ||
import * as pack from './pack.js'; export {pack}; | ||
import * as publish from './publish.js'; export {publish}; | ||
import * as remove from './remove.js'; export {remove}; | ||
import * as run from './run.js'; export {run}; | ||
import * as tag from './tag.js'; export {tag}; | ||
import * as team from './team.js'; export {team}; | ||
import * as unlink from './unlink.js'; export {unlink}; | ||
import * as upgrade from './upgrade.js'; export {upgrade}; | ||
import * as version from './version.js'; export {version}; | ||
import * as versions from './versions.js'; export {versions}; | ||
import * as why from './why.js'; export {why}; | ||
import * as upgradeInteractive from './upgrade-interactive.js'; export {upgradeInteractive}; | ||
const chalk = require('chalk'); | ||
|
||
const getDocsLink = (name) => `${constants.YARN_DOCS}${name || ''}`; | ||
const getDocsInfo = (name) => 'Visit ' + chalk.bold(getDocsLink(name)) + ' for documentation about this command.'; | ||
|
||
const commands = {}; | ||
|
||
import * as access from './access.js'; commands['access'] = access; | ||
import * as add from './add.js'; commands['add'] = add; | ||
import * as bin from './bin.js'; commands['bin'] = bin; | ||
import * as cache from './cache.js'; commands['cache'] = cache; | ||
import * as check from './check.js'; commands['check'] = check; | ||
import * as clean from './clean.js'; commands['clean'] = clean; | ||
import * as config from './config.js'; commands['config'] = config; | ||
import * as generateLockEntry from './generate-lock-entry.js'; commands['generateLockEntry'] = generateLockEntry; | ||
import * as global from './global.js'; commands['global'] = global; | ||
import * as help from './help.js'; commands['help'] = help; | ||
import * as import_ from './import.js'; commands['import'] = import_; | ||
import * as info from './info.js'; commands['info'] = info; | ||
import * as init from './init.js'; commands['init'] = init; | ||
import * as install from './install.js'; commands['install'] = install; | ||
import * as licenses from './licenses.js'; commands['licenses'] = licenses; | ||
import * as link from './link.js'; commands['link'] = link; | ||
import * as login from './login.js'; commands['login'] = login; | ||
import * as logout from './logout.js'; commands['logout'] = logout; | ||
import * as list from './list.js'; commands['list'] = list; | ||
import * as outdated from './outdated.js'; commands['outdated'] = outdated; | ||
import * as owner from './owner.js'; commands['owner'] = owner; | ||
import * as pack from './pack.js'; commands['pack'] = pack; | ||
import * as publish from './publish.js'; commands['publish'] = publish; | ||
import * as remove from './remove.js'; commands['remove'] = remove; | ||
import * as run from './run.js'; commands['run'] = run; | ||
import * as tag from './tag.js'; commands['tag'] = tag; | ||
import * as team from './team.js'; commands['team'] = team; | ||
import * as unlink from './unlink.js'; commands['unlink'] = unlink; | ||
import * as upgrade from './upgrade.js'; commands['upgrade'] = upgrade; | ||
import * as version from './version.js'; commands['version'] = version; | ||
import * as versions from './versions.js'; commands['versions'] = versions; | ||
import * as why from './why.js'; commands['why'] = why; | ||
import * as upgradeInteractive from './upgrade-interactive.js'; commands['upgradeInteractive'] = upgradeInteractive; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be clearer to do something like this: import * as bar from './bar';
import * as foo from './foo';
...
let commands = {
bar,
foo,
...
}; What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is A LOT clearer; i will change it! |
||
|
||
import buildUseless from './_useless.js'; | ||
|
||
export const lockfile = buildUseless( | ||
commands['lockfile'] = buildUseless( | ||
"The lockfile command isn't necessary. `yarn install` will produce a lockfile.", | ||
); | ||
|
||
export const dedupe = buildUseless( | ||
commands['dedupe'] = buildUseless( | ||
"The dedupe command isn't necessary. `yarn install` will already dedupe.", | ||
); | ||
|
||
export const prune = buildUseless( | ||
commands['prune'] = buildUseless( | ||
"The prune command isn't necessary. `yarn install` will prune extraneous packages.", | ||
); | ||
|
||
for (const key in commands) { | ||
commands[key].getDocsInfo = getDocsInfo(key); | ||
} | ||
|
||
import aliases from '../aliases.js'; | ||
|
||
for (const key in aliases) { | ||
commands[key] = commands[aliases[key]]; | ||
commands[key].getDocsInfo = getDocsInfo(key); | ||
} | ||
|
||
import unsupportedAliases from '../unsupported-aliases.js'; | ||
|
||
for (const key in unsupportedAliases) { | ||
commands[key] = { | ||
run(config: Config, reporter: ConsoleReporter | JSONReporter): Promise<void> { | ||
throw new MessageError(`Did you mean \`yarn ${unsupportedAliases[key]}\`?`); | ||
}, | ||
setFlags: () => {}, | ||
hasWrapper: () => true, | ||
getDocsInfo: getDocsInfo(unsupportedAliases[key]), | ||
}; | ||
} | ||
|
||
export default ({ | ||
...commands, | ||
}: { [key: string]: Object }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsopported
? :p(same typo on 214 and 221 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaaah thanks and sorry XD