build icon indicating copy to clipboard operation
build copied to clipboard

Wrong expectations on `constants` existence

Open ehmicky opened this issue 4 years ago • 1 comments

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 be undefined 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 be undefined if no netlify.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?

ehmicky avatar May 22 '20 12:05 ehmicky

https://github.com/netlify/build/issues/763 can help make the APIs more clear

erezrokah avatar Jul 27 '20 18:07 erezrokah

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!

github-actions[bot] avatar Mar 25 '23 14:03 github-actions[bot]

This issue was closed because it had no activity for over 1 year.

github-actions[bot] avatar Apr 08 '23 14:04 github-actions[bot]