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

Support custom packageManager other than npm/yarn/pnpm. #4483

Closed
zyy7259 opened this issue Aug 22, 2019 · 10 comments
Closed

Support custom packageManager other than npm/yarn/pnpm. #4483

zyy7259 opened this issue Aug 22, 2019 · 10 comments

Comments

@zyy7259
Copy link
Contributor

zyy7259 commented Aug 22, 2019

What problem does this feature solve?

Currently the --packageManager only supports npm/yarn/pnpm.

This feature will let the end user specify a custom node package manager.

The company I worked at uses a private packageManager. Right now I cannot find a way to use it with vue-cli to create my project.

What does the proposed API look like?

--packageManager xxx

@zyy7259
Copy link
Contributor Author

zyy7259 commented Aug 22, 2019

happy to send a PR

@Alex-Sokolov
Copy link
Collaborator

Alex-Sokolov commented Aug 28, 2019

It would also be nice to be able to configure per-project package manager via vue.config.js. For example, you usually use yarn everywhere, but sometimes you support projects where npm is used. And you don't want to delete yarn.lock and reinstall node_modules to avoid side-effects because of the different folders structure

@LinusBorg
Copy link
Member

@zyy7259 how would you tackle the possibly different commands that some custom package manager might have? These would have to be mapped somehow, i.e. what command is the qeuivalent of "npm install"?

@haoqunjiang
Copy link
Member

@Alex-Sokolov in v4 we've refactored the package manager related stuff and it now infers the project manager from project lockfiles

if (forcePackageManager) {
this.bin = forcePackageManager
} else if (context) {
this.bin = hasProjectYarn(context) ? 'yarn' : hasProjectPnpm(context) ? 'pnpm' : 'npm'
} else {
this.bin = loadOptions().packageManager || (hasYarn() ? 'yarn' : hasPnpm3OrLater() ? 'pnpm' : 'npm')
}

@haoqunjiang
Copy link
Member

If the subcommands are identical to npm, just use command-line alias (like, alias npm="tnpm".

If not, it will surely increase our maintenance burden. We are not going to support custom package managers without a clear plan of future maintenance.

@zyy7259
Copy link
Contributor Author

zyy7259 commented Sep 26, 2019

alias won't work with execa sindresorhus/execa#100

@haoqunjiang
Copy link
Member

Okay…
Then we can make it a warning rather than an error for unknown package manager.

@haoqunjiang haoqunjiang reopened this Sep 26, 2019
@zyy7259
Copy link
Contributor Author

zyy7259 commented Sep 26, 2019

@haoqunjiang
Copy link
Member

Not necessary.
See the above snippets. We have 3 ways to determine the package manager to use, in the following order:

  1. the command line --packageManager option
  2. infer the command from the lockfile name in the project
  3. the packageManager field in ~/.vuerc

The problem of custom package manager is not how to specify it, but how to map the subcommands:

const PACKAGE_MANAGER_CONFIG = {
npm: {
install: ['install', '--loglevel', 'error'],
add: ['install', '--loglevel', 'error'],
upgrade: ['update', '--loglevel', 'error'],
remove: ['uninstall', '--loglevel', 'error']
},
pnpm: {
install: ['install', '--loglevel', 'error', '--shamefully-flatten'],
add: ['install', '--loglevel', 'error', '--shamefully-flatten'],
upgrade: ['update', '--loglevel', 'error'],
remove: ['uninstall', '--loglevel', 'error']
},
yarn: {
install: [],
add: ['add'],
upgrade: ['upgrade'],
remove: ['remove']
}
}

So if we want to support such a feature, we need to turn this error into a warning and then use the npm subcommands as fallbacks.

if (!SUPPORTED_PACKAGE_MANAGERS.includes(this.bin)) {
throw new Error(`Unknown package manager: ${this.bin}`)
}
}

@zyy7259
Copy link
Contributor Author

zyy7259 commented Sep 26, 2019

How about this #4621

haoqunjiang pushed a commit that referenced this issue Sep 30, 2019
Closes #4483

* feat: support custom package manager

* feat: refine warning msg for unknown package manager

* feat: refine blank lines

* feat: refine warning msg for unknown package manager

* feat: refine warning msg for unknown package manager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants