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(server-cache): must match exact alias #4388

Merged
merged 1 commit into from
Jun 30, 2020

Conversation

curbengh
Copy link
Contributor

@curbengh curbengh commented Jun 29, 2020

What does it do?

Improve compatibility with 3rd-party console plugins that start with an 's'.

By default, server command has the following alias (using abbrev):

  • 's'
  • 'se'
  • 'ser'
  • ...
  • 'server'

However, if there is a 3rd-party console that also starts with an 's', like 'save', 'server' will no longer have 's' alias; instead, its alias will start with 'se'. Another example is 'selenium', 'server' alias will start with 'ser'.

These examples illustrate cmd.startsWith('s') might match other commands than the intended 'server'.

How to test

git clone -b abbrev-compat https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@coveralls
Copy link

coveralls commented Jun 29, 2020

Coverage Status

Coverage remained the same at 97.828% when pulling e98d9ed on curbengh:abbrev-compat into 65961d3 on hexojs:master.

@curbengh curbengh marked this pull request as ready for review June 29, 2020 02:57

if (this.env.cmd.startsWith('s') && cache) {
if (Object.keys(alias).filter(key => alias[key] === 'server').includes(this.env.cmd) && cache) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (Object.keys(alias).filter(key => alias[key] === 'server').includes(this.env.cmd) && cache) {
if (alias[this.env.cmd] === 'server' && cache) {

It is much simpler, and could do the same job.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

there might a 3rd-party console registered that also
starts with 's', e.g. 'save'
@SukkaW SukkaW merged commit 11d57b5 into hexojs:master Jun 30, 2020
@curbengh curbengh deleted the abbrev-compat branch July 2, 2020 05:14
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.

3 participants