jigsaw
jigsaw copied to clipboard
getOutputPaths() as well as getPages() Event Listeners do not deliver paths for generated html files.
As the title says.
if I start with an empty jigsaw project (no template), normally one index.html file is generated on build. Using said getOutputPaths()
or getPages()
Event Lsitener in boostrap.php does not deliver a collection entry for the generated index.html file, instead, the first array entry is empty, followed by the paths for the flatfiles (like png, css, js and so on).
I found this behaviour when I tried to use this function for implementing an HTML minifier for jigsaw: https://github.com/tighten/jigsaw/pull/116#issuecomment-993916984
If you need fruther info, please let me know. Installed jigsaw yesterday, so I think it's a pretty recent version.
oh, and if you have built-in nice error logging function, pleeeeeeeease let me know, for now I am using error_log on build and it feels so so so wrong. Documentation about deugging and logging would be really helpful :)
What exactly do they return for you? Please share the entire output of both of those methods if possible. Are you on Windows?
Hey @bakerkretzmar, I am on Mac OS Catalina, Using PHP 7.3.29 (cli) (built: Aug 15 2021 23:10:16) ( NTS )
here is the output of my build folder:
sample code 1:
$events->afterBuild(function ($jigsaw) {
$paths = $jigsaw->getOutputPaths();
$paths->each(function ($item) use ($jigsaw) {
error_log($item . "\n", 3, "/Users/Nico/Documents/Code/log/php-error.log");
});
});
output 1 (include white space):
/assets/images/favicon.png
/assets/images/jigsaw.png
/assets/build/css/main.css
/assets/build/js/main.js
/assets/build/mix-manifest.json
sample code 2:
$events->afterBuild(function ($jigsaw) {
$paths = $jigsaw->getPages();
$paths->each(function ( $item, $key) use ($jigsaw) {
error_log($key . "\n", 3, "/Users/Nico/Documents/Code/log/php-error.log");
});
});
output 2 (include white space):
/assets/images/favicon.png
/assets/images/jigsaw.png
/assets/build/css/main.css
/assets/build/js/main.js
/assets/build/mix-manifest.json
as you can see, index.html is missing in both cases.
Gotcha, thanks. /index.html
should be the only one that's ever missing, its relative 'pretty' path is /
which gets trimmed to ''
.
For now you should be able to safely assume that there will always be exactly one item in the output paths array that is an empty string, and that path is actually /index.html
, and likewise that there will be one item in the pages array with a key that's just an empty string, and it's actually the page at /index.html
. Not sure if this is intentional, I'll find out and follow up.
To get a better look at what's in those collections, you can dump()
them so they show up right in the build output and are highlighted:
$events->afterBuild(fn ($jigsaw) => dump($jigsaw->getOutputPaths()));
$events->afterBuild(fn ($jigsaw) => dump($jigsaw->getPages()));
dump
is a GameChanger!!! Makes life so much easier!
Okay, I will investigate and see if I can work around this bug and implement my Minifier in a more convenient way :)
Not sure if this is intentional, I'll find out and follow up.
doc states:
"getPages() (afterBuild only)
Returns a collection of all output files that were generated. "
So..I guess...Not intentional? :)
Thanks a lot!
one more thing, dump() does not output logs to the build outout for me, but maybe I am mistaken where to look - can you please point me into the right direction on where to find the results of dump(), please?
using something along the lines of this now and hope it does not break :)
$build_files = $jigsaw->getOutputPaths();
$build_files->each(function ($item) use ($jigsaw) {
if (gettype($item) == "string") {
if (strlen($item) == 0) {
$item = "/index.html";
}
if (str_contains($item, ".html")) {
minify($item, $jigsaw);
}
}
});
one more thing, dump() does not output logs to the build outout for me, but maybe I am mistaken where to look - can you please point me into the right direction on where to find the results of dump(), please?
It should just show up in your terminal, wherever you're running the build.
It should just show up in your terminal, wherever you're running the build.
it does not :-/ again, Mac OS, also recently upgraded to PHP 7.4, using zsh terminal.
I am getting this:
bootstrap.php:
$events->afterBuild(fn ($jigsaw) => dump($jigsaw->getOutputPaths()));
Terminal output:

It looks like there's other output missing there... does that build succeed? On a fresh install it should show the two lines you have there, then the dumps, then Build time: ...
and Site built successfully
.
Hope this helps:
Scenario 1:
bootstrap.php
<?php
use TightenCo\Jigsaw\Jigsaw;
/** @var $container \Illuminate\Container\Container */
/** @var $events \TightenCo\Jigsaw\Events\EventBus */
$events->afterBuild(fn ($jigsaw) => dump($jigsaw->getOutputPaths()));
Results:
build: builds normally, all files are built and copied as expected, with the following output:

serve: does not start server. Hangs.

Scenario 2:
bootstrap.php
<?php
use TightenCo\Jigsaw\Jigsaw;
/** @var $container \Illuminate\Container\Container */
/** @var $events \TightenCo\Jigsaw\Events\EventBus */
Results:
build: builds normally, all files are built and copied as expected, with the following output:

serve: Starts server, with the following output:
Weird... are you calling dump()
anywhere else, or manually var_dump
ing or echo
ing other stuff?
nope, fresh install. If you want, we can set up a quick call next week and you can investigate my setup remotely :)
If there is any other branch or thing I can test, please let me know.