Skip to content
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

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

Open
nicolaskopp opened this issue Dec 14, 2021 · 12 comments

Comments

@nicolaskopp
Copy link

nicolaskopp commented Dec 14, 2021

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: #116 (comment)

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 nicolaskopp changed the title getOutputPaths() as well as getPages() do not deliver paths for generated html files. getOutputPaths() as well as getPages() Event Listeners do not deliver paths for generated html files. Dec 14, 2021
@bakerkretzmar
Copy link
Collaborator

bakerkretzmar commented Dec 14, 2021

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

@nicolaskopp
Copy link
Author

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.

@bakerkretzmar
Copy link
Collaborator

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

@nicolaskopp
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

@bakerkretzmar
Copy link
Collaborator

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.

@nicolaskopp
Copy link
Author

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

@bakerkretzmar
Copy link
Collaborator

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.

@nicolaskopp
Copy link
Author

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

@bakerkretzmar
Copy link
Collaborator

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

@nicolaskopp
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants