Make sure next picks up the correct config file when called by nextjs_standalone_build()#2778
Make sure next picks up the correct config file when called by nextjs_standalone_build()#2778MatrixFrog wants to merge 1 commit intoaspect-build:mainfrom
Conversation
|
|
|
||
| copy_file( | ||
| name = "_%s.original_config_file" % name, | ||
| src = config, |
There was a problem hiding this comment.
What if config is also in data via js_library(srcs)? Then it might still end up in the runfiles|bindir and the bug might still occur?
That makes me wonder if we should instead just disallow nextjs_*build(config) from using the standard names. It would be a breaking change, but the entire change can just be an if config-is-standard-name: fail() at the top of the macro....
There was a problem hiding this comment.
I guess so. What name would be recommended instead?
Alternatively, can we detect if the same file appears in both config and data, and fail() if it does?
There was a problem hiding this comment.
We can't truly detect what is in data when we're in a macro, it would have to be within a rule that launches an action with data as input or maybe does data.to_list() to convert depset()s to a list that can be inspected. All things I wouldn't want to do.
We could maybe just do:
write_file(out = "next.config.js", content = "throw new Error(...)")
then if the user also has a file of that same name they will get a bazel error saying "conflicting file outputs" - however that will be a generic bazel error and the user won't understand it. That might be good to do regardless actually, just to be 100% sure, while also doing the if path.basename(config) == "next.config.js": fail("nicer error message)...?



Without this change, there are two next config files available to the
nextbinary: the one the user passed in, and next.bazel.mjs, which has been renamed tonext.config.mjsby copy_file(). We want it to use the next.bazel.mjs one as the config file, but if the one from the user is named next.config.js, then it gets picked up by the next CLI instead.By renaming the user's config (prefixing it with
__original), we ensure thatnextwill pick up the one we want it to.Changes are visible to end-users: yes
Test plan
[TODO: need to add a test where the config file that's passed in is named
next.config.jsand should maybe do anext.config.tsone too]