Skip to content
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

[legacy-framework] Load env variables based on APP_ENV or -e flag #2878

Merged
merged 34 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
eb0eeb7
Load env variables based on APP_ENV or -e flag
beerose Oct 25, 2021
16887e0
Remove private: true, add missing build step
beerose Oct 26, 2021
d6d8341
Merge branch 'canary' into env-variables-loading
beerose Oct 28, 2021
9f2ef38
Merge branch 'canary' into env-variables-loading
beerose Oct 28, 2021
f4e2bcf
set process.env.APP_NAME in root cli
beerose Nov 1, 2021
d633088
minor fixes
beerose Nov 1, 2021
d80549d
Merge branch 'env-variables-loading' of https://github.com/blitz-js/b…
beerose Nov 1, 2021
3274140
remove not needed flag
beerose Nov 1, 2021
f62fcb2
Merge branch 'canary' into env-variables-loading
beerose Nov 1, 2021
0b1ded6
Remove dotenv-flow
beerose Nov 3, 2021
d3d207e
Merge branch 'env-variables-loading' of https://github.com/blitz-js/b…
beerose Nov 3, 2021
d41e2d6
Merge branch 'canary' into env-variables-loading
beerose Nov 11, 2021
54848df
rename package, set env var in entry points
beerose Nov 16, 2021
6a24e64
Merge branch 'canary' into env-variables-loading
beerose Nov 16, 2021
188bdb8
publish setup for @blitzjs/env
flybayer Nov 18, 2021
232c919
Merge branch 'canary' into env-variables-loading
beerose Nov 26, 2021
4d05710
add tests
beerose Nov 26, 2021
88d5f19
Merge branch 'canary' into env-variables-loading
beerose Nov 29, 2021
ed0b4c0
Add -e to install, codegen, generate
beerose Nov 29, 2021
be9407f
Update nextjs/packages/next-env/index.ts
beerose Nov 30, 2021
d65d9ec
update cache key and fix next config
beerose Nov 30, 2021
4d0fc53
Merge branch 'env-variables-loading' of https://github.com/blitz-js/b…
beerose Nov 30, 2021
4069e51
update name
beerose Dec 1, 2021
0c49e43
update jest global setup
beerose Dec 1, 2021
b1faff2
revert the change
beerose Dec 2, 2021
82306a0
try to update cahce key again
beerose Dec 2, 2021
b35fb7b
Update version
beerose Dec 2, 2021
b6a4ed1
revert workflow changes
beerose Dec 2, 2021
2e72e8b
trying things out
beerose Dec 2, 2021
5761310
update cache key yet again
beerose Dec 2, 2021
35750ec
Set node version to 14
beerose Dec 2, 2021
5e81742
Uncomments deps tarball path for next-env
beerose Dec 2, 2021
e020594
update commands flags
beerose Dec 3, 2021
538db59
Merge branch 'canary' into env-variables-loading
beerose Dec 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions nextjs/packages/next-env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export function loadEnvConfig(
if (combinedEnv) return { combinedEnv, loadedEnvFiles: cachedLoadedEnvFiles }

const isTest = process.env.NODE_ENV === 'test'
const mode = isTest ? 'test' : dev ? 'development' : 'production'
let mode = isTest ? 'test' : dev ? 'development' : 'production'
beerose marked this conversation as resolved.
Show resolved Hide resolved
if (process.env.APP_ENV) {
mode = process.env.APP_ENV
}
const dotenvFiles = [
`.env.${mode}.local`,
// Don't include `.env.local` for `test` environment
Expand Down Expand Up @@ -106,7 +109,7 @@ export function loadEnvConfig(
path: envFile,
contents,
})
} catch (err) {
} catch (err: any) {
if (err.code !== 'ENOENT') {
log.error(`Failed to load env from ${envFile}`, err)
}
Expand Down
3 changes: 1 addition & 2 deletions nextjs/packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"private": true,
"name": "@next/env",
beerose marked this conversation as resolved.
Show resolved Hide resolved
"version": "11.1.0",
"version": "0.41.2-canary.4",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion nextjs/packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@babel/helper-module-imports": "^7.0.0",
"@babel/runtime": "7.12.5",
"@hapi/accept": "5.0.2",
"@next/env": "11.1.0",
"@next/env": "0.41.2-canary.4",
"@next/polyfill-module": "11.1.0",
"@next/react-dev-overlay": "11.1.0",
"@next/react-refresh-utils": "11.1.0",
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"nextjs/packages/next-mdx",
"nextjs/packages/eslint-config-next",
"nextjs/packages/eslint-plugin-next",
"nextjs/packages/next-env",
"examples/*",
"recipes/*"
],
Expand All @@ -28,14 +29,16 @@
"wait:nextjs": "wait-on -d 1000 nextjs/packages/next/dist/build/index.js",
"wait:nextjs-types": "wait-on -d 1000 nextjs/packages/next/dist/build/index.d.ts",
"dev:nextjs": "yarn workspace next dev",
"dev:next-env": "yarn workspace @next/env dev",
"dev:nextjs-types": "yarn wait:nextjs && yarn workspace next types && echo 'Finished building nextjs types'",
"dev:blitz": "cross-env BLITZ_PROD_BUILD=true preconstruct watch",
"dev:tsc": "yarn dev:nextjs-types && tsc --watch --pretty --preserveWatchOutput",
"dev:cli": "yarn wait:nextjs-types && yarn workspace @blitzjs/cli dev",
"dev:templates": "yarn workspace @blitzjs/generator dev",
"dev": "concurrently --names \"nextjs,blitz,typecheck,cli,templates\" -c \"magenta,cyan,green,yellow,black\" -p \"{name}\" \"npm:dev:nextjs\" \"npm:dev:blitz\" \"npm:dev:tsc\" \"npm:dev:cli\" \"npm:dev:templates\"",
"dev": "concurrently --names \"nextjs,blitz,typecheck,cli,templates,next-env\" -c \"magenta,cyan,green,yellow,black,blue\" -p \"{name}\" \"npm:dev:nextjs\" \"npm:dev:blitz\" \"npm:dev:tsc\" \"npm:dev:cli\" \"npm:dev:templates\" \"npm:dev:next-env\"",
"build:nextjs": "yarn workspace next prepublish",
"build": "yarn build:nextjs && cross-env BLITZ_PROD_BUILD=true preconstruct build && ultra -r --filter \"packages/*\" buildpkg && tsc",
"build:next-env": "yarn workspace @next/env prepublish",
"build": "yarn build:nextjs && yarn build:next-env && cross-env BLITZ_PROD_BUILD=true preconstruct build && ultra -r --filter \"packages/*\" buildpkg && tsc",
"lint": "eslint --ext \".js,.ts,.tsx\" .",
"link-cli": "yarn workspace blitz link",
"unlink-cli": "yarn workspace blitz unlink",
Expand Down
4 changes: 4 additions & 0 deletions packages/blitz/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ async function main() {

const cli = require(cliPkgPath)

if (options.e || options.env) {
process.env.APP_ENV = options.e || options.env
}

const hasVersionFlag = options._.length === 0 && (options.v || options.version)
const hasVerboseFlag = options._.length === 0 && (options.V || options.verbose)

Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export class Build extends Command {

static flags = {
help: flags.help({char: "h"}),
env: flags.string({
char: "e",
description: "Set app environment name",
}),
}

async run() {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class Console extends Command {

static flags = {
help: flags.help({char: "h"}),
env: flags.string({
char: "e",
description: "Set app environment name",
}),
}

async run() {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class Dev extends Command {
"no-incremental-build": flags.boolean({
description: "Disable incremental build and start from a fresh cache",
}),
env: flags.string({
char: "e",
description: "Set app environment name",
}),
}

async run() {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export class Export extends Command {
char: "o",
description: "set the output dir (defaults to 'out')",
}),
env: flags.string({
char: "e",
description: "Set app environment name",
}),
}

async run() {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class Start extends Command {
inspect: flags.boolean({
description: "Enable the Node.js inspector",
}),
env: flags.string({
char: "e",
description: "Set app environment name",
}),
}

async run() {
Expand Down
24 changes: 18 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2958,11 +2958,6 @@
dependencies:
webpack-bundle-analyzer "4.3.0"

"@next/[email protected]":
version "11.1.0"
resolved "https://registry.yarnpkg.com/@next/env/-/env-11.1.0.tgz#cae83d8e0a65aa9f2af3368f8269ffd9d911746a"
integrity sha512-zPJkMFRenSf7BLlVee8987G0qQXAhxy7k+Lb/5hLAGkPVHAHm+oFFeL+2ipbI2KTEFlazdmGY0M+AlLQn7pWaw==

"@next/[email protected]":
version "11.1.0"
resolved "https://registry.yarnpkg.com/@next/polyfill-module/-/polyfill-module-11.1.0.tgz#ee6b9117a1f9bb137479dfa51d5a9e38e066a62f"
Expand Down Expand Up @@ -4395,6 +4390,13 @@
resolved "https://registry.yarnpkg.com/@types/dotenv-flow/-/dotenv-flow-3.1.0.tgz#e9ba53f95f3d40bbc0df99b206f649b2acfca0c6"
integrity sha512-qaWT42KDePdAGZFryYoV7EZnuuYZAO4KPVDWUV9OBOyJx7xCgKKERtVB7jBCM2mtKVI+OMMDK2ef11PWcHJz3g==

"@types/[email protected]":
version "8.2.0"
resolved "https://registry.yarnpkg.com/@types/dotenv/-/dotenv-8.2.0.tgz#5cd64710c3c98e82d9d15844375a33bf1b45d053"
integrity sha512-ylSC9GhfRH7m1EUXBXofhgx4lUWmFeQDINW5oLuS+gxWdfUeW4zJdeVTYVkexEW+e2VUvlZR2kGnGGipAWR7kw==
dependencies:
dotenv "*"

"@types/duplexify@*":
version "3.6.0"
resolved "https://registry.yarnpkg.com/@types/duplexify/-/duplexify-3.6.0.tgz#dfc82b64bd3a2168f5bd26444af165bf0237dcd8"
Expand Down Expand Up @@ -5627,6 +5629,11 @@
async-retry "1.2.3"
lru-cache "5.1.1"

"@zeit/[email protected]":
version "0.20.4"
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.20.4.tgz#00f0a25a88cac3712af4ba66561d9e281c6f05c9"
integrity sha512-fmq+F/QxPec+k/zvT7HiVpk7oiGFseS6brfT/AYqmCUp6QFRK7vZf2Ref46MImsg/g2W3g5X6SRvGRmOAvEfdA==

"@zeit/[email protected]":
version "1.0.2-canary.2"
resolved "https://registry.yarnpkg.com/@zeit/next-css/-/next-css-1.0.2-canary.2.tgz#0eeb877e7469892b65471c1ec7c14346b8f240df"
Expand Down Expand Up @@ -9706,7 +9713,12 @@ dotenv-flow@^3.2.0:
dependencies:
dotenv "^8.0.0"

dotenv@^8.0.0, dotenv@^8.2.0:
dotenv@*:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==

[email protected], dotenv@^8.0.0, dotenv@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==
Expand Down