Closed montchr closed 1 year ago
bud.js doesn't ignore errors thrown by build dependencies.
The warning message you're seeing is emitted during bootstrapping when bud.js attempts to import config modules. At this very early stage bud.js will proceed even if a module can't be imported unless the module has bud
in its filename. Since bud.js requires zero configuration it is important to throw early if a bud config is messed up. Otherwise, assuming zero config requirements are met (an entrypoint at @src/index.js
), the build could succeed without any user config actually being applied.
In the case of a tailwind.config.js
or tailwind.config.ts
file with a syntax or import error, yes, bud.js will move beyond bootstrapping even without the module having been successfully loaded. But, tailwindcss/postcss should still throw. bud.js does nothing to mask a build error here.
For example, let's say we add a bad import statement:
import foo from './foo.js'; // does not exist
const config = {
content: ['./index.php', './app/**/*.php', './resources/**/*.{php,vue,js}'],
theme: {
extend: {
colors: {},
},
},
plugins: [foo],
};
export default config;
As you point out, we can see that bud can't import this module but still keeps going:
[env] › registering expanded values /Users/kellymears/code/git/roots/docker/bedrock/web/app/themes/sage/.env
[env] › ◼ sourcing .env values Timer run for: 3ms
[fs] › ▶ Initializing filesystem Initialized timer...
[fs] › ▶ loading .pnpmfile.cjs Initialized timer...
[fs] › ◼ loading .pnpmfile.cjs Timer run for: 1ms
[fs] › ▶ loading tailwind.config.js Initialized timer...
[fs] [tailwind.config.js] › ⚠ tailwind.config.js causes an exception when imported.
Since tailwind.config.js does not appear to be a bud configuration file, bud.js is not throwing. Original error follows:
BudError: Cannot find module '/Users/kellymears/code/git/roots/docker/bedrock/web/app/themes/sage/foo.js' imported from /Users/kellymears/code/git/roots/docker/bedrock/web/app/themes/sage/tailwind.config.js
[fs] › ◼ Initializing filesystem Timer run for: 11ms
[bootstrap] › 🏗️ building sage
However, the build itself fails because tailwind throws:
╭─ ✘ sage ./public [5ecab747f4778a527a32]
│
├─ ✘ error
│
│ Cannot find module './foo.js'
│ Require stack:
│ - ./tailwind.config.ts
│
│
├─ ✘ error
│
│ Cannot find module './foo.js'
│ Require stack:
│ - ./tailwind.config.ts
│
│
├─ entrypoints
│ ├─ app
│ │ ├─ js/runtime.06fab3.js 1.05 kB
│ │ ├─ js/407.814868.js 314 bytes
│ │ └─ js/app.c4614b.js 8.17 kB
│ └─ editor
│ ├─ js/runtime.06fab3.js 1.05 kB
│ ├─ js/407.814868.js 314 bytes
│ └─ js/editor.fa098a.js 8.4 kB
│
╰─ compiled 12 modules in 537ms
[sage] [hooks] › ▶ compiler.close Initialized timer...
[sage] [hooks] › … executing callback 1/2
[sage] [hooks] › … executing callback 2/2
[sage] [hooks] › ✔ executing callback 1/2
[fs] › ▶ writing new checksums Initialized timer...
[fs] › ◼ writing new checksums Timer run for: 0ms
[sage] [hooks] › ✔ executing callback 2/2
[sage] [hooks] › ◼ compiler.close Timer run for: 3ms
error Command failed with exit code 1.
I think this is the correct behavior. A person may have a module lying around in the root of their project that is broken and cannot be imported. It shouldn't cause a total failure unless:
An example of the second case is calling bud.wpjson.useTailwindColors()
or a similar function. In this case we see a different error:
[sage] › processing base configuration bud.config.js
[sage] › processing as dynamic configuration: bud.config.js
[fs] › ▶ loading bud.config.js Initialized timer...
[fs] › ◼ loading bud.config.js Timer run for: 0ms
ConfigError
✘ Error in bud.config.js
BudError
✘ Cannot read properties of undefined (reading 'default')
☰ Stack trace
at get config [as config] (node_modules/@roots/bud-tailwindcss/lib/extension/index.js:46:48)
at BudTailwindCss.resolveThemeValue (node_modules/@roots/bud-tailwindcss/lib/extension/index.js:61:39)
at WordPressThemeJSON.useTailwindColors
(node_modules/@roots/bud-tailwindcss-theme-json/lib/extension.js:24:78)
at default (bud.config.js:62:6)
ℹ See file /Users/kellymears/code/git/roots/docker/bedrock/web/app/themes/sage/bud.config.js
error Command failed with exit code 1.
I can't reproduce a JS runtime error originating from the tailwind config that doesn't cause the process to exit with a non-zero error code. Do you mind sharing the tailwind config that should throw but doesn't?
Thanks for the detailed response. Based on your logs, it certainly looks like Bud is doing what I would expect.
I'll follow up soon with a minimal example if I can re-reproduce the issue. After changing course away from attempting to importing a module (which did actually exist), I found that some of my changes to the Tailwind config were being heavily cached. I suspect that this caching issue may have prevented Tailwind from throwing an error properly.
For context, this happened when attempting to override the CSS output by the Tailwind Typography plugin, which generally needs to be done in the config file. That caching caused a lot of frustration but after realizing what was going on I made sure to clear cache and built assets each time I made a change (very slow, do not recommend).
The issue you encountered with the sticky tailwind config caching is addressed in 6.12.1.
Agreement
Describe the issue
If an exception is thrown by a dependent tool, it should cause builds to fail. That's why they throw exceptions. In my particular case, I have an error in
tailwind.config.ts
which would totally break generated CSS. Bud "ignores" the error and turns it into a short message at the beginning of output, then somehow continues running. If I know that my Tailwind config is broken, then I can assume that the resulting build will render my site in an undesireable state. Whenbud build
intentionally tries to "help" by continuing to run despite the error, I cannot trust it to run without very close monitoring for hidden errors. Because of that, I can't trust it in a CI environment without some way of disabling the default behavior or, better yet, changing the default behavior.Expected Behavior
Bud should do absolutely nothing to prevent errors/exceptions thrown by dependencies. Exit codes should be preserved. Bud should not make decisions about which configuration files are important.
If some safety-handling is still considered a useful feature for
bud
, it should absolutely not be the default behavior.Actual Behavior
With an error in my TailwindCSS configuration,
bud build
says the following and returns exit code 0:Steps To Reproduce
tailwind.config.ts
in my case)bud build
echo $?
version
6.12.0
Logs
Configuration
No response
Relevant .budfiles
No response