jigsaw icon indicating copy to clipboard operation
jigsaw copied to clipboard

getOutputPaths() as well as getPages() Event Listeners do not deliver paths for generated html files.

Open nicolaskopp opened this issue 3 years ago • 12 comments

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 :)

nicolaskopp avatar Dec 14 '21 19:12 nicolaskopp

What exactly do they return for you? Please share the entire output of both of those methods if possible. Are you on Windows?

bakerkretzmar avatar Dec 14 '21 20:12 bakerkretzmar

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: Screen Shot 2021-12-14 at 21 44 56

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.

nicolaskopp avatar Dec 14 '21 20:12 nicolaskopp

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()));

bakerkretzmar avatar Dec 14 '21 22:12 bakerkretzmar

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!

nicolaskopp avatar Dec 14 '21 22:12 nicolaskopp

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?

nicolaskopp avatar Dec 15 '21 11:12 nicolaskopp

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);
                }
            }
        });

nicolaskopp avatar Dec 15 '21 12:12 nicolaskopp

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.

bakerkretzmar avatar Dec 15 '21 14:12 bakerkretzmar

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:

Screen Shot 2021-12-16 at 11 18 57

nicolaskopp avatar Dec 16 '21 10:12 nicolaskopp

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.

bakerkretzmar avatar Dec 16 '21 15:12 bakerkretzmar

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:

Screen Shot 2021-12-16 at 11 18 57

serve: does not start server. Hangs.

Screen Shot 2021-12-16 at 21 58 14

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:

Screen Shot 2021-12-16 at 21 59 16

serve: Starts server, with the following output: Screen Shot 2021-12-16 at 22 00 31

nicolaskopp avatar Dec 16 '21 21:12 nicolaskopp

Weird... are you calling dump() anywhere else, or manually var_dumping or echoing other stuff?

bakerkretzmar avatar Dec 17 '21 17:12 bakerkretzmar

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.

nicolaskopp avatar Dec 18 '21 09:12 nicolaskopp