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

feat: use pnpm on projects that previously used pnpm #294

Merged
merged 1 commit into from
Aug 6, 2018
Merged

feat: use pnpm on projects that previously used pnpm #294

merged 1 commit into from
Aug 6, 2018

Conversation

zkochan
Copy link
Contributor

@zkochan zkochan commented Jun 24, 2018

If a project has a pnpm lockfile or it has a node_modules created
by pnpm then pnpm is used to update dependencies

close #291

Copy link
Collaborator

@LinusU LinusU left a comment

Choose a reason for hiding this comment

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

Neat 👍

@zkochan
Copy link
Contributor Author

zkochan commented Jun 27, 2018

@dylang could you have a look, please?

lib/cli.js Outdated
detectPreferredPM(options.cwd)
)
.then(preferredPM => {
options.installer = preferredPM && preferredPM.name === 'pnpm' ? 'pnpm' : 'npm';
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are potentially checking .name of a string here 🤔

Copy link
Collaborator

@LinusU LinusU Jun 27, 2018

Choose a reason for hiding this comment

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

Actually, not a super fan of this...

Could we do it like this:

  1. Change the default installer from npm to auto (on line 90/91)

installer: process.env.NPM_CHECK_INSTALLER || 'auto',

  1. Change the resolving to something like this:
Promise.resolve()
  .then(() => {
    if (options.installer === 'auto') {
      return detectPreferredPM(options.cwd).then(result => result.name)
    }

    return options.installer
  })
  .then((installer) => {
    return npmCheck(Object.assign(options, { installer }))
  })

@LinusU
Copy link
Collaborator

LinusU commented Jun 27, 2018

Saw some errors that should be fixed before merging ☺️

@zkochan
Copy link
Contributor Author

zkochan commented Jun 27, 2018

@LinusU PR updated

lib/cli.js Outdated
function detectPreferredInstaller(cwd) {
return detectPreferredPM(cwd)
.then(preferredPM => {
if (preferredPM && preferredPM.name === 'pnpm') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be nice if this would accept e.g. yarn as well, and not specifically check for one manager...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

supporting yarn requires additional efforts because it has a different CLI. I just tested and got an error

Command failed: yarn install --save @types/[email protected] --color=always
error `install` has been replaced with `add` to add new dependencies. Run "yarn add @types/[email protected]" instead.

lib/cli.js Outdated
(
options.installer === 'auto' ?
detectPreferredInstaller(options.cwd) :
Promise.resolve(process.env.NPM_CHECK_INSTALLER)
Copy link
Collaborator

Choose a reason for hiding this comment

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

process.env.NPM_CHECK_INSTALLER should already have been read into options.installer, this will override any specific installer given by a CLI flag.

lib/cli.js Outdated
@@ -98,7 +99,15 @@ if (options.debug) {
debug('cli.input', cli.input);
}

npmCheck(options)
(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally not a fan of this style with a wide tenary and then chaining of that expression. What do you think about starting a Promise chain instead?

Promise.resolve()
    .then(() => {
        return (options.installer === 'auto' ? detectPreferredInstaller(options.cwd) : options.installer)
    })

This will catch any potential synchrounous throws and move them to a rejected Promise, and thus to the .catch handler further down.

If a project has a pnpm lockfile or it has a node_modules created
by pnpm then pnpm is used to update dependencies

close #291
@@ -120,3 +130,13 @@ npmCheck(options)
}
process.exit(1);
});

var SUPPORTED_INSTALLERS = ['npm', 'pnpm', 'ied'];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The readme mentions ied, so I added it as well. Although, currently preferred-pm cannot detect it. I am not sure it ever will. Ied seems to be not maintained anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yarn can be added but it will require additional work. Yarn's CLI is not compatible with npm's

@zkochan
Copy link
Contributor Author

zkochan commented Jun 29, 2018

@LinusU updated

@zkochan
Copy link
Contributor Author

zkochan commented Jul 7, 2018

should I change something?

Copy link
Collaborator

@LinusU LinusU left a comment

Choose a reason for hiding this comment

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

LGTM

@zkochan
Copy link
Contributor Author

zkochan commented Aug 5, 2018

@dylang would you please merge/publish this?

@LinusU LinusU merged commit 042c7f6 into dylang:master Aug 6, 2018
@LinusU
Copy link
Collaborator

LinusU commented Aug 6, 2018

Published as 5.8.0, sorry for the delay

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.

pnpm integration
2 participants