build
build copied to clipboard
Wrong expectations on `constants` existence
The PUBLISH_DIR
constant reflects the "publish" directory as set in netlify.toml
or in the UI build settings. When unset, it defaults to the build directory. However, when set, it is possible that the user is targeting a publish directory that does not exist yet. For example, the directory might be created by build.command
but a plugin might run on onPreBuild
.
This has created several plugin bugs already, due to plugins expecting PUBLISH_DIR
to point to an existing directory (for example https://github.com/Munter/netlify-plugin-subfont/issues/41). We could create that directory if it does not exist. However, this might break some builds since the build.command
might behave differently depending on whether it already exists or not. But for onPostBuild
, maybe the expectations are different?
This problem also exists for the following constants:
-
FUNCTIONS_DIST
: always defined. In local builds, it is./.netlify/functions
, which might not have been created yet. -
FUNCTIONS_SRC
: can beundefined
if the user has not set any Functions directory. Knowing whether the user has set a Functions directory is actually useful to skip Functions bundling logic (for example). But it creates issues with Plugins assuming this directory is defined or points to an existing directory. -
CONFIG_PATH
: can beundefined
if nonetlify.toml
is used
One way to improve this is with better documentation, which I have done in #1330. However do you have any other ideas to prevent this common source of plugin bugs?
https://github.com/netlify/build/issues/763 can help make the APIs more clear
This issue has been automatically marked as stale because it has not had activity in 1 year. It will be closed in 14 days if no further activity occurs. Thanks!
This issue was closed because it had no activity for over 1 year.