-
Notifications
You must be signed in to change notification settings - Fork 12k
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(tracking): Third party NPM replacements #4321
Conversation
Can you come up with a way to add some tests around this? |
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.
Good start! thanks a lot.
@@ -31,9 +34,11 @@ export default function initRun(commandOptions: any, rawArgs: string[]) { | |||
|
|||
let npmInstall: any; | |||
if (!commandOptions.skipNpm) { | |||
const packageManager = CliConfig.fromProject().get('packageManager') || 'npm'; |
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.
No need to ||
for values in the config, you should set a default
value in the schema.json instead.
@@ -293,6 +293,9 @@ | |||
}, | |||
"additionalProperties": false | |||
}, | |||
"packageManager": { | |||
"enum": [ "npm", "cnpm", "yarn" ] |
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.
There should be another value here, "default"
, which enables the check. People might want to use npm
without having the warning shown up.
} | ||
|
||
export function checkYarnOrCNPM() { | ||
return new Promise((resolve, reject) => { |
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.
No need to create a new promise (and it's kinda awkward). Just return the Promise.all().then().catch()
directly.
} | ||
|
||
function checkYarn() { | ||
return new Promise(function(resolve, reject) { |
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.
You can use Promise.denodeify
for this (look up elsewhere in the code where we use it);
const exec = Promise.denodeify(fs.exec);
function checkYarn() {
return exec('yarn --version')
.then(() => true, () => false);
}
Much cleaner :)
} | ||
resolve(); | ||
}) | ||
.catch(resolve); |
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.
I don't think we should swallow errors.
In case you didn't know, using a catch on a Promise and not throwing an error will just swallow the rejection. So you can do something like:
Promise.resolve()
.then(() => doSomething()) // this throws
.catch(() => {}); // this will swallow the error and the promise returned here will be resolved properly.
Again though, if the code above generates an error I think we should propagate it back to the user.
Promise | ||
.all([checkYarn(), checkCNPM()]) | ||
.then((data) => { | ||
if (packageManager === 'npm') { |
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.
If this checks is done by the function calling this, it would reduce the code duplication and make the overall structure easier to understand.
return new Promise((resolve, reject) => { | ||
Promise | ||
.all([checkYarn(), checkCNPM()]) | ||
.then((data) => { |
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.
You can use destructuring, like .then(([isYarnInstalled, isCnpmInstalled]) => { /* ... */ })
here, saving a few lines of code and making the general reading flow better.
@@ -1,7 +1,10 @@ | |||
import * as chalk from 'chalk'; | |||
import * as check from '../utilities/check-package-manager'; |
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.
Normally unless there's a conflict you should import {functionName} from '...'
.
d105844
to
620c118
Compare
3d7f5a0
to
23c7286
Compare
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.
Few more nits. Getting close!
@@ -292,6 +292,10 @@ | |||
}, | |||
"additionalProperties": false | |||
}, | |||
"packageManager": { | |||
"enum": [ "npm", "cnpm", "yarn" ], |
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.
I would like the default to be a fourth value, so that people who forces it to npm
don't get the message.
if (packageManager === 'npm') { | ||
const [isYarnInstalled, isCNPMInstalled] = data; | ||
if (isYarnInstalled && isCNPMInstalled) { | ||
console.log(chalk.yellow('you can `ng set --global packageManager=yarn` ' + |
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.
Phrases should start with a capital letter and ends with a dot. Same for other logging messages.
9b87dd1
to
75b61e7
Compare
@@ -292,6 +292,10 @@ | |||
}, | |||
"additionalProperties": false | |||
}, | |||
"packageManager": { | |||
"enum": [ "npm", "cnpm", "yarn", "default" ], | |||
"default": "npm" |
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.
default
should be default
.
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.
@hansl I tried but then it always picks value as default and it fails install as there is nothing for default install
. Am I missing how it should be done ?
if (packageManager === 'npm') { | ||
const [isYarnInstalled, isCNPMInstalled] = data; | ||
if (isYarnInstalled && isCNPMInstalled) { | ||
console.log(chalk.yellow('You can `ng set --global packageManager=yarn` ' + |
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.
Operators go to the start of the next line.
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.
More comments.
const Promise = require('../ember-cli/lib/ext/promise'); | ||
const SilentError = require('silent-error'); | ||
const normalizeBlueprint = require('../ember-cli/lib/utilities/normalize-blueprint-option'); | ||
const GitInit = require('../tasks/git-init'); | ||
const config = CliConfig.fromProject(); |
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.
The project's config will never exist in new
. You probably want fromGlobal()
?
@@ -31,9 +35,14 @@ export default function initRun(commandOptions: any, rawArgs: string[]) { | |||
|
|||
let npmInstall: any; | |||
if (!commandOptions.skipNpm) { | |||
let packageManager = 'npm'; |
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.
I don't think you need this here, since config.get(...)
will give you the default value.
return Promise | ||
.all([checkYarn(), checkCNPM()]) | ||
.then((data: Array<boolean>) => { | ||
if (packageManager === 'npm') { |
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.
So you're checking both yarn and cnpm EVEN if the user asked for a specific one? That's a lot of unnecessary work (and will slow down the bootstrapping time significantly).
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.
How is user asking? If I have yarn/cnpm installed I just check for any and use whichever I found. Use just does ng new foo
As part of this change, can you update the name of the option in new & init from |
1e3c341
to
034c501
Compare
ui.writeLine(chalk.green('Installing packages for tooling via npm.')); | ||
exec('npm install', | ||
ui.writeLine(chalk.green(`Installing packages for tooling via ${packageManager}.`)); | ||
exec(`${packageManager} install`, |
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.
No need to change now, but if we do add support for another package manager that may not use install
as the command, this code will need updated.
Please add breaking change info to the PR message so that it's included in the changelog with the release. You can find that info here: https://github.com/angular/angular-cli/blob/master/CONTRIBUTING.md#commit |
9179c35
to
746f09b
Compare
@sumitarora you need to change the tests who are also using |
@hansl yeap doing so 👍 |
deab013
to
6fe08e6
Compare
.then(() => ng('set', '--global', 'packageManager=default')) | ||
.then(() => ng('new', 'foo')) | ||
.then((stdout) => { | ||
// assuming yarn is installed and checking for message with yarn |
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.
Comments should start with a capital letter and end with a dot.
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.
One nit, but approved. Good work!
ddbc295
to
d0dfed8
Compare
BREAKING CHANGE: `--skip-npm` flag is now named `--skip-install`
d0dfed8
to
e486bc2
Compare
…lar#4321) BREAKING CHANGE: `--skip-npm` flag is now named `--skip-install`
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
ng set --global packageManager=yarn
orng set --global packageManager=cnpm
to checkFixes: #3886