-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.4] Refactoring mix method (bis). #19666
Conversation
} | ||
|
||
return new HtmlString($manifestDirectory.$manifest[$path]); | ||
return app('mix')->mix($path, $manifestDirectory); |
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 think it looks strange to do (new Mix)->mix()
why not something more like (new Mix)->create()
..
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.
Yep or generate
maybe?
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.
Yeah I thought about that.
create
and generate
aren't good ones either because you don't create or generate anything, you just find the good path in a file, so find
? I didn't find something I liked, so I kept that because in any way, the method will always be called by the mix()
helper, as usual.
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.
What about load
?
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.
Could use resolve()
. If Taylor merges it, he could always rename it.
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 love resolve
thank you! 🎉
tests/View/Mix/MixTest.php
Outdated
{ | ||
public function setUp() | ||
{ | ||
app()->singleton('path.public', function () { |
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.
🤔
Yeah, it's true and I also could have created all the other files by the same way actually (file_put_content(json_encode(...))
), but I've done it like that.
I, personally, prefer commit two empty files to test a function than add some extra complexity to generate them.
But, anyway, does it really matter ??
src/Illuminate/View/Mix/Mix.php
Outdated
*/ | ||
protected function getManifest() | ||
{ | ||
if (! $this->manifest) { |
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 go further if $this->manifest
is not empty. You can favor an early return:
if ($this->manifest) {
return $this->manifest;
}
if (! file_exists($manifestPath = public_path($this->manifestDirectory.$this->manifestFilename))) {
throw new MixException('The Mix manifest does not exist.');
}
$this->manifest = json_decode(file_get_contents($manifestPath), true);
if (json_last_error() === JSON_ERROR_NONE) {
return $this->manifest;
}
throw new MixException("The Mix manifest isn't a proper json file.");
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.
It's your code right here, you made me change mine to yours for no valid reason, and now you're again changing your mind. It's just about a basic refactoring and you're commenting every line I'm writing for 3 days each time I make a new commit.
I have work to do, and I haven't not enough time to satisfy all your dreams on a basic function like this one. So, I don't know what's your goal, but please stop, or do it yourself!
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.
It's just about a basic refactoring
It's a great PR but a critical function.
src/Illuminate/View/Mix/Mix.php
Outdated
* | ||
* @param string $manifestFilename | ||
* | ||
* @return Mix |
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.
We use @return $this
src/Illuminate/View/Mix/Mix.php
Outdated
* | ||
* @param string $hmrFilename | ||
* | ||
* @return Mix |
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.
We use @return $this
tests/View/Mix/MixTest.php
Outdated
|
||
/** | ||
* @expectedException \Illuminate\View\Mix\MixException | ||
*/ |
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 exception message should also be tested 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.
Nope, we don't care about the message, it's just to check that is enabled.
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.
We care as your test fails with @expectedExceptionMessage Mix is disabled
If the same exception is used for different purposes within a context, then the exception message should be tested too.
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, not at all!
This exception message doesn't exists, we are not expecting any special exception, just check the mix method is enabled
.
Please read the code instead of commenting every line I'm writing!
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've read it for some days already - I think that I got the picture
When you run $this->getMix()->disable()->enable()->mix('foo.css');
is thrown \Illuminate\View\Mix\MixException
which is tested, and this exception comes with the message The Mix manifest does not exist.
So this exception message should be also tested.
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.
Ok, we don't suceed to understand each other, I'm just switching in our mutual native language, it will be easier for us. 😕
Ici on s'en fout de savoir ce qui arrive après, on veut juste s'assurer que la méthode enable
"marche" comme il faut. Dès l'instant où il y a autre chose que le comportement de disable
, donc une exception, peu importe laquelle dans ce cas là, ça veut dire que ça marche.
On peut rajouter le test du message, mais c'est une question de logique ici, on ne cherche pas à savoir quel message va être affiché, juste s'assurer que la fonction continue, et ne s'arrête pas sur le disable.
tests/View/Mix/MixTest.php
Outdated
|
||
private function getMix() | ||
{ | ||
return new \Illuminate\View\Mix\Mix; |
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 declare a useless method here.
$this->mix = new \Illuminate\View\Mix\Mix;
can be in setUp
method.
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.
Guy, I think you should make all the PRs just by yourself.
It's just about a basic refactoring, I've added here tests that didn't exist and you're commenting every line I'm writing for 3 days each time I make a new commit.
I have work to do, and I haven't not enough time to satisfy all your dreams on a basic function like this one. So, I don't know what's your goal, but please stop, or do it yourself!
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 believe there is some misunderstanding out there.
You plan to refactor a mix function that everyone is using on 5.4
impacting current users, and that will be soon merged to 5.5
.
This is a function loaded on each page request displaying a view, so it's expected to be performant and highly tested, right?
No need to be pissed and get personal
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.
Yeah, but you can understand that this is much better than before, and you agree that each commit I'm making, you add some things.
I'm ok to discuss, exchange some "good" practices, and I agree than I have not your experience about the coding style of this framework. It's why I used your advices and pieces of code, even if sometimes I don't agree with.
But please if we can just tell everything once, and don't come back each time on the same piece of code, we will save time both. Especially like here when it's here in a test, than even didn't exist!!
Imho you will have a lot more value to write tests than just make PRs to rewrite docblocks and code style of others!
I personally have a job, make opensource on my free time because I love it, and you are just disgusting me about that and it's a bit too bad...
If you want, you can make a PR to my branch I will merge it immediately, and so it's ok we're done and we can move to important stuffs!
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.
Hey Mathieu, pas de problème ;-)
I have a job too, and do this on my free-time too - I am just making sure that you're great PR will be merged and ready to rock
Next time I will PR you fork if you feels that easier, up to you
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.
Ok Lucas.
So, I'll do all the modifications tonight. Do you see now something else to update? I think it will be the last time, this is THE moment to tell me! 🙃
@lucasmichot it's ok for you? |
tests/View/Mix/MixTest.php
Outdated
|
||
public function testMixMethodWhenDisabled() | ||
{ | ||
$this->assertEquals(new HTMLString('Mix is disabled!'), $this->mix->disable()->resolve('foo.css')); |
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.
Casing of HTMLString
should be HtmlString
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.
Right! thx!
@taylorotwell I think we're ok, you can merge it! |
The object design on this seems weird. Why does the Mix object have this stateful |
At the end if the day, make sure we have a way to use a custom manifest file name. |
First off, really hope to see something like this merged in since it could drastically reduce build times on CI environments. If variables like |
@sebastiandedeyne But mix-manifest.json can be customized, https://github.com/JeffreyWay/laravel-mix/blob/9a3426b7ba2d317a4ec9c59d7051484a2d7852fc/src/Manifest.js#L12 |
@mathieutu , I believe this PR should be updated to comply #19764 which has been merged recently |
See above comment about conflicts and please send this to 5.5 and I will try to rewrite some of it. Thanks. |
@lucasmichot We agree that the PR you mentioned can't actually be working at all?! see #19764 (comment) I've fixed it in #19895. |
Some features added, and code style fixed from reviews of the previous PR:
#19639
@taylorotwell have fun, I'm waiting for your wisdom!
😊