Skip to content

Build every configured input CSS, not just the first - #137

Merged
bocharsky-bw merged 3 commits into
SymfonyCasts:1.xfrom
Amoifr:fix-78-build-all-input-css
Oct 23, 2026
Merged

bocharsky-bw merged 3 commits into
SymfonyCasts:1.xfrom
Amoifr:fix-78-build-all-input-css

Conversation

@Amoifr

@Amoifr Amoifr commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #78, fixes #46

runBuild() takes a single input, and the command passed it $this->inputPaths[0], so configuring several input_css files built only the first one. That is why @kniziol's workaround was to run tailwind:build once per file.

You called it a problem upstream, and the binary part is true: Tailwind takes one -i/-o pair per run. The consequence is not that nothing can be done though, only that it needs one run per input, which is what the command now does: a plain build runs one process per configured input, one after the other. sass-bundle does not have this problem only because Dart Sass accepts input:output pairs in a single pass.

Two things fall out of it:

  • --watch now covers every input: the watchers are started together, and the command polls all of them so that the output (and the errors) of every input is shown, where only the first one was watched before. With several inputs, each chunk of output is prefixed with the file it comes from.
  • a failing input no longer hides the others: every input is attempted, and the command fails if any of them did.

Passing input_css explicitly still builds that one file only.

The new tests fail on 1.x (v4-second.built.css missing, the error of an invalid input not reported). Suite is green at 55 tests, and php-cs-fixer is clean.

runBuild() takes a single input and the command passed it
$this->inputPaths[0], so configuring several input_css files built only the
first one. The reported workaround was to run tailwind:build once per file.

Tailwind takes one -i/-o pair per run, so the command now starts one
process per configured input and waits on all of them. Starting them
together is also what makes --watch cover every file. An explicit
input_css argument still builds that one file only.

@bocharsky-bw bocharsky-bw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for tackling this, the approach (one process per input) makes sense, and the non-watch build works as expected.

There is one blocking issue with --watch though, see the inline comment on the wait() loop. A couple of smaller things are in the other comments.

Also, not introduced by this PR, but I see that now more likely to bite: getInternalOutputCssPath() uses only the basename, so assets/app.css and assets/admin/app.css both write to var/tailwind/app.built.css, now concurrently. Same if a path is listed twice. It probably would be great to fix with a follow-up PR (not here), what do you think?

Comment thread src/Command/TailwindBuildCommand.php Outdated
$failed = false;

foreach ($processes as $process) {
$process->wait(static function ($type, $buffer) use ($io) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem is that in --watch mode the first process never exits, so wait() on it blocks forever, and the other processes are never read from. That has a few consequences:

  • output (including compile errors) of inputs 2..N is never shown
  • Symfony Process only reads a process’s pipes when one of its methods is called, so their stdout/stderr pipes eventually fill up (Tailwind writes Done in xx ms on every rebuild) and those watchers block on write() and silently stop rebuilding
  • a failure in inputs 2..N is not detected

I think we should try polling all processes in a loop instead - that should work for both watch and non-watch modes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! I could reproduce it: with two inputs in --watch, an error in the second file never showed up. The command now polls every process in a loop (non-blocking reads, plus checkTimeout() so the non-watch timeout still applies), so all outputs are drained and a failure in any input is reported. Checked by hand with --watch on two files: the error in the second one is shown, and fixing it rebuilds it.

Comment thread src/Command/TailwindBuildCommand.php Outdated
$processes = [];

foreach ($inputFiles as $file) {
$processes[] = $this->tailwindBuilder->runBuild(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With several inputs, the "Executing Tailwind" message is printed N times, and it’s hard to tell which output/error belongs to which file. Could we mention the input file, e.g. Executing Tailwind for "assets/styles/admin.css"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, the note now reads Executing Tailwind for "assets/styles/admin.css" (path relative to the project). Since the outputs of several watchers interleave, I also print the input path before a chunk of output when it comes from another file than the previous one (only with several inputs). Happy to drop that part if you find it noisy.

$this->assertFileExists($builtCss);
}

public function testBuildEveryConfiguredInput(): void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the PR says that a failing input no longer hides the others, but there is no test for it. Could you add one where the second input is invalid and assert the command fails?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added testBuildFailsWhenAnInputIsInvalid, with the invalid file both last and first: the command fails, the Tailwind error is displayed, and the valid file is still built.

'tailwind_config' => [
'input_css' => [
self::FIXTURES_DIR.'/assets/styles/v4.css',
self::FIXTURES_DIR.'/assets/styles/second.css',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this second.css is v3 syntax. If so, probably better create a new fixture for v4 and use both for v4 as you're running it on v4.0.7

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that was v3 syntax. Added a v4-second.css fixture and used it here.

@Amoifr

Amoifr commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the thorough review! Everything is addressed in the new commit, see the replies in each thread.

About the basename collision: agreed, two watchers writing the same app.built.css is worse than before. I'd be happy to take it in a follow-up PR once this one is merged.

@bocharsky-bw bocharsky-bw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks great the polling loop reads nicely.

One thing before merging: test_windows / PHP 8.5, highest deps fails. Seems v4.built.css was not created, so the valid input didn’t build. The other Windows jobs pass, so it might be a race between the two Tailwind processes running at the same time on Windows. Could you take a look, please?

Comment thread src/Command/TailwindBuildCommand.php Outdated

foreach ($processes as $i => $process) {
$process->checkTimeout();
$running = $process->isRunning() || $running;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cheaper to check in reverse order:

Suggested change
$running = $process->isRunning() || $running;
$running = $running || $process->isRunning();

Check bool var would be faster than a method call. But's pretty nit, feel free to ignore

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks! (Safe to skip the call: reading the incremental output refreshes the status of each process anyway.)

Comment thread src/TailwindBuilder.php Outdated
{
$projectRootDir = realpath($this->projectRootDir) ?: $this->projectRootDir;

return str_starts_with($inputPath, $projectRootDir.'/') ? substr($inputPath, \strlen($projectRootDir) + 1) : $inputPath;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we check for / separator here - I suppose on Windows it may be a backslash \ that will cause problems in this logic. I think we can leverage symfony/filesystem here and use Path::makeRelative() - that's already a dependency

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done with Path::isBasePath() and Path::makeRelative(), and a test that uses a realpath() (so backslashes on the Windows jobs). One thing: symfony/filesystem was only in require-dev, so I moved it to require. It was already installed through symfony/asset-mapper, but now the bundle uses it directly.

@Amoifr

Amoifr commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking the Windows jobs! I couldn't reproduce it here (no Windows box at hand), and I couldn't find a known Tailwind issue about two instances starting at the same time. In that job the exit code and the error message were as expected, only v4.built.css was missing, so it does look like the two processes got in each other's way.

Rather than guessing, I removed the concurrency where it isn't needed: without --watch, the inputs are now built one after the other. Only --watch still starts them together, as it has to. I also pass the command output as the message of that assertFileExists(), so if it ever fails again on Windows we'll see what Tailwind said.

@Amoifr

Amoifr commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Good news: test_windows / PHP 8.5, highest deps is green now. 🎉

This time it's test_windows / PHP 8.2, lowest deps that failed, but in testBuild, which builds a single input, and only in its tearDown(): Windows still had tailwindcss-windows-x64.exe locked when the temp directory was removed (Failed to remove file ... Resource temporarily unavailable). The same job passed on the previous commit.

It looks like the Windows flakiness that the scheduled runs on 1.x already show: they failed on and off on the same commit (9b0afba) on Jul 26, Aug 23 and Sep 6, and passed the other weeks. I can't check why, the logs have expired.

Could you re-run the failed job, please? If you think it's worth it, I can also send a separate PR that retries the removal in BaseCommandTestCase::tearDown() for a moment when the binary is still locked on Windows, so these runs stop failing randomly.

@bocharsky-bw bocharsky-bw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, failed tests are random. I will take a look.

Thanks for working on this feature!

@bocharsky-bw
bocharsky-bw merged commit 75a286b into SymfonyCasts:1.x Oct 23, 2026
133 of 144 checks passed
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

Successfully merging this pull request may close these issues.

Tailwind stylesheets are not generated for stylesheets other than app.css Working with multiple entrypoints

2 participants