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
Print out yarn install
when yarn.lock file is present
#6888
Print out yarn install
when yarn.lock file is present
#6888
Conversation
[1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... Done in 9.74s. rather than when yarn.lock file is present
lib/models/command.js
Outdated
@@ -288,7 +288,11 @@ let Command = CoreObject.extend({ | |||
|
|||
if (this.works === 'insideProject') { | |||
if (!this.project.hasDependencies()) { | |||
throw new SilentError('node_modules appears empty, you may need to run `npm install`'); | |||
let installInstuction = '`npm install`'; | |||
if (this.project.hasYarnLockFile()) { |
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'd prefer to check it here directly, and not add another method to project
.
If however, we do keep the project method around, we should update other locations that search for yarn.lock
to use it (example here).
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.
@rwjblue, we only use it in /lib/commands/init.js:64 and lib/tasks/npm-task.js:45
I can take it out and check it directly if you like.
Than I just need another approach to test it, ATM, we overwrite the hasYarnLockFile
function in the project class:
command.project.hasYarnLockFile = function() { return true; };
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.
@rwjblue, in this commit I will check it directly. To test this behaviour, I am renaming the ember-cli
project's actual yarn.lock
file before the test runs and after the test, rewrite it back to the original name.
Could you advise me if this is a good approach, or might it be to risky? If so, what would you suggest for testing?
ea2f6dc
to
ae62776
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.
nice work!
lib/models/command.js
Outdated
throw new SilentError('node_modules appears empty, you may need to run `npm install`'); | ||
let installInstuction = '`npm install`'; | ||
if (existsSync(path.join(this.project.root, 'yarn.lock'))) { | ||
installInstuction = '`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.
can we make this yarn install
to make it a bit easier to understand?
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.
@Turbo87, sure, no prob.
[1/4] Resolving packages... success Already up-to-date. Done in 0.56s. to yarn install v0.21.3 [1/4] Resolving packages... success Already up-to-date. Done in 0.56s.
tests/unit/commands/generate-test.js
Outdated
|
||
return expect(command.validateAndRun(['controller', 'foo'])).to.be.rejected.then(reason => { | ||
expect(reason.message).to.eql('node_modules appears empty, you may need to run `npm install`'); | ||
}).then(() => fs.renameSync(dummyYarnLockPath, originalYarnLockPath)); |
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.
this renameSync
will not run if the assertion above fails. you could wrap it in a describe() block though:
describe('without yarn.lock file', function() {
let originalYarnLockPath, dummyYarnLockPath;
beforeEach(function() {
originalYarnLockPath = path.join(command.project.root, 'yarn.lock');
dummyYarnLockPath = path.join(command.project.root, 'foo.bar');
fs.renameSync(originalYarnLockPath, dummyYarnLockPath);
});
afterEach(function() {
fs.renameSync(dummyYarnLockPath, originalYarnLockPath);
});
it('runs GenerateFromBlueprint but with null nodeModulesPath', function() {
command.project.hasDependencies = function() { return false; };
return expect(command.validateAndRun(['controller', 'foo'])).to.be.rejected.then(reason => {
expect(reason.message).to.eql('node_modules appears empty, you may need to run `npm 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.
Thanks @Turbo87, makes sense!
Question, would you typically destroy the global variables in the afterEach
function?
afterEach(function() {
fs.renameSync(dummyYarnLockPath, originalYarnLockPath);
originalYarnLockPath = dummyYarnLockPath = null;
});
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.
since they are reassigned in every beforeEach()
block there is IMHO no need to reset them in afterEach()
@homu r+ |
📌 Commit bc1241f has been approved by |
…bo87 Print out `yarn install` when yarn.lock file is present As some might know, when you are using yarn and you remove `/node_modules`, you will have a comment when you try to run `ember server` ``` node_modules appears empty, you may need to run `npm install` ``` <img width="497" alt="screen shot 2017-03-22 at 16 21 42" src="https://cloud.githubusercontent.com/assets/7160913/24209231/9c9c5124-0f1d-11e7-92f7-53387a56fdeb.png"> I fixed something similar in [ember-cli-dependency-checker](quaertym/ember-cli-dependency-checker#68). It's quite confusing for people who are not that familiar with the package managers. As this is my first PR to ember-cli, I am guessing that there might be a better way for this fix. But at least the idea is out there now. In this PR, I will print out ``` node_modules appears empty, you may need to run `yarn` ``` <img width="446" alt="screen shot 2017-03-22 at 16 35 18" src="https://cloud.githubusercontent.com/assets/7160913/24209262/aea23474-0f1d-11e7-8af4-c63efe7036e2.png"> when there is a `yarn.lock` file present. I know that yarn is not used by ember-cli by default yet, but it might be ok to check this as in the team I am working in, it got confusing for some people .. 😅
☀️ Test successful - status |
As some might know, when you are using yarn and you remove
/node_modules
, you will have a comment when you try to runember server
I fixed something similar in ember-cli-dependency-checker.
It's quite confusing for people who are not that familiar with the package managers.
As this is my first PR to ember-cli, I am guessing that there might be a better way for this fix. But at least the idea is out there now.
In this PR, I will print out
when there is a
yarn.lock
file present.I know that yarn is not used by ember-cli by default yet, but it might be ok to check this as in the team I am working in, it got confusing for some people .. 😅