-
Notifications
You must be signed in to change notification settings - Fork 73
inline project env files in worker #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
commit: |
packages/cloudflare/src/cli/build/utils/extract-project-env-vars.ts
Outdated
Show resolved
Hide resolved
b8c29e4
to
782f0d1
Compare
A few thoughts (I'll do a deeper review later today) I find "build time" to be confusing. Looking at the next docs there are 2 things: Non- Does the current code support referencing other vars - maybe add a test. It looks like we should support To be more consistent with how Open Next work, we might want to generate |
782f0d1
to
a0ca689
Compare
Removed the reference to 'build-time'.
Yeah, that was actually why i used the newer dotenvx instead of dotenv :). Added a test.
Sorry I hadn't realised it was an intentional part of the design. I've undone that change. Instead, it's not putting all of them into an |
packages/cloudflare/src/cli/build/patches/investigated/copy-package-cli-files.ts
Outdated
Show resolved
Hide resolved
packages/cloudflare/src/cli/build/patches/investigated/copy-env-files.ts
Show resolved
Hide resolved
packages/cloudflare/src/cli/build/utils/extract-project-env-vars.ts
Outdated
Show resolved
Hide resolved
* In a monorepo, the env files in an app's directory will take precedence over | ||
* the env files at the root of the monorepo. | ||
*/ | ||
export function extractProjectEnvVars(mode: string, options: BuildOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't that mean that we will always use the .local
files while we only want to use them for wrangler dev
but not in prod?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. How come you wouldn't want them in production? Next.js would use those files. I suppose you're talking about if someone builds it locally and then deploys, but in that case, you could make the argument that we shouldnt include any .env files at all because technically they're all local to the machine. I'm not quite sure what else you could do here - open to suggestions though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@james-elicx I did a quick test and you are right, .local
files are used if present, regardless if it is a prod or dev build. I was wrong to think that they would only be used in dev.
…ckage-cli-files.ts
8beee04
to
c43a925
Compare
packages/cloudflare/src/cli/build/patches/investigated/copy-env-files.ts
Outdated
Show resolved
Hide resolved
Do you think you can add a simple test, maybe to the api example app? |
f8ce991
to
a5268a7
Compare
packages/cloudflare/src/cli/build/patches/investigated/compile-env-files.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome PR, thanks!
I would move the code out of patch*, I think it should be part of the build.
Approving the PR, you can pick whatever your prefer.
🙏
* extract env vars from file system * combine variables from a global with the request-scoped env * inline build-time env vars in the worker script * for some reason the tests failed in the pipeline but not locally * switch between modes at runtime and apply on process.env * add test for referencing variables * use a .env.mjs file for the vars * Update packages/cloudflare/src/cli/build/patches/investigated/copy-package-cli-files.ts * move the merging to extractProjectEnvVars * rename secrets to nextEnvVars * add missing mode when retrieving value * add link to nextjs var load order * rename to compile * change function to read a single file * move the readEnvFile call inside the flatMap * remove process.env.node_env usage * add e2e test for env vars * move locations
* extract env vars from file system * combine variables from a global with the request-scoped env * inline build-time env vars in the worker script * for some reason the tests failed in the pipeline but not locally * switch between modes at runtime and apply on process.env * add test for referencing variables * use a .env.mjs file for the vars * Update packages/cloudflare/src/cli/build/patches/investigated/copy-package-cli-files.ts * move the merging to extractProjectEnvVars * rename secrets to nextEnvVars * add missing mode when retrieving value * add link to nextjs var load order * rename to compile * change function to read a single file * move the readEnvFile call inside the flatMap * remove process.env.node_env usage * add e2e test for env vars * move locations
Changes