From 84e800e02a189b89cf2732be5efeb497ecf284f8 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Sat, 30 Sep 2023 10:23:10 +0900 Subject: [PATCH 1/5] feat!: rewrite env features --- packages/shared-lib-node/src/env.ts | 6 +++--- packages/wb/src/commands/setup.ts | 4 ++-- packages/wb/src/commands/start.ts | 19 +++++++++++++------ packages/wb/src/index.ts | 4 ++-- .../scripts/execution/baseExecutionScripts.ts | 8 +++++--- .../scripts/execution/httpServerScripts.ts | 6 ++++-- .../wb/src/scripts/execution/remixScripts.ts | 8 +++----- 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/packages/shared-lib-node/src/env.ts b/packages/shared-lib-node/src/env.ts index 406be7d2..fb6fc526 100644 --- a/packages/shared-lib-node/src/env.ts +++ b/packages/shared-lib-node/src/env.ts @@ -26,7 +26,7 @@ export const yargsOptionsBuilderForEnv = { type: 'boolean', }, 'auto-cascade-env': { - description: 'Same with --cascade-env=.', + description: 'Same with --cascade-env=.', type: 'boolean', default: true, }, @@ -47,7 +47,7 @@ export function loadEnvironmentVariables(argv: Options, cwd: string, orgCwd?: st (argv.cascadeNodeEnv ? process.env.NODE_ENV || 'development' : argv.autoCascadeEnv - ? process.env.WB_ENV || process.env.APP_ENV || process.env.NODE_ENV || 'development' + ? process.env.WB_ENV || 'development' : undefined); if (typeof cascade === 'string') { if (envPaths.length === 0) envPaths.push(path.join(cwd, '.env')); @@ -74,7 +74,7 @@ export function loadEnvironmentVariables(argv: Options, cwd: string, orgCwd?: st } } if (count > 0) { - console.info(`Updated ${count} environment variables:`, envPath); + console.info(`Loaded ${count} environment variables:`, envPath); } } diff --git a/packages/wb/src/commands/setup.ts b/packages/wb/src/commands/setup.ts index 85d47944..474ebe0f 100644 --- a/packages/wb/src/commands/setup.ts +++ b/packages/wb/src/commands/setup.ts @@ -53,9 +53,9 @@ export async function setup(argv: Partial Date: Sat, 30 Sep 2023 10:49:20 +0900 Subject: [PATCH 2/5] . --- packages/shared-lib-node/src/env.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared-lib-node/src/env.ts b/packages/shared-lib-node/src/env.ts index 73e08d48..fb6fc526 100644 --- a/packages/shared-lib-node/src/env.ts +++ b/packages/shared-lib-node/src/env.ts @@ -28,7 +28,7 @@ export const yargsOptionsBuilderForEnv = { 'auto-cascade-env': { description: 'Same with --cascade-env=.', type: 'boolean', - default: false, + default: true, }, 'check-env': { description: 'Check whether the keys of the loaded .env files are same with the given .env file.', From 91669dc2a2bcf7a18939a3621e486d495efb1e3e Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Sat, 30 Sep 2023 10:54:43 +0900 Subject: [PATCH 3/5] . --- packages/shared-lib-node/src/env.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/shared-lib-node/src/env.ts b/packages/shared-lib-node/src/env.ts index fb6fc526..072dac0c 100644 --- a/packages/shared-lib-node/src/env.ts +++ b/packages/shared-lib-node/src/env.ts @@ -26,7 +26,7 @@ export const yargsOptionsBuilderForEnv = { type: 'boolean', }, 'auto-cascade-env': { - description: 'Same with --cascade-env=.', + description: 'Same with --cascade-env=.', type: 'boolean', default: true, }, @@ -47,7 +47,7 @@ export function loadEnvironmentVariables(argv: Options, cwd: string, orgCwd?: st (argv.cascadeNodeEnv ? process.env.NODE_ENV || 'development' : argv.autoCascadeEnv - ? process.env.WB_ENV || 'development' + ? process.env.WB_ENV || process.env.NODE_ENV || 'development' : undefined); if (typeof cascade === 'string') { if (envPaths.length === 0) envPaths.push(path.join(cwd, '.env')); From 4da95b75ec85a320fd7cefa6a856182934d46f57 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Sat, 30 Sep 2023 11:16:16 +0900 Subject: [PATCH 4/5] . --- packages/shared-lib-node/test-fixtures/app1/.env | 1 + .../test-fixtures/{app => app1}/.env.development | 0 .../test-fixtures/{app => app1}/.env.production | 0 .../test-fixtures/{app => app1}/.env.test | 0 packages/shared-lib-node/test-fixtures/app2/.env | 1 + .../{another-app => app2}/.env.development | 0 .../{another-app => app2}/.env.production | 0 .../{another-app => app2}/.env.test | 0 packages/shared-lib-node/tests/env.test.ts | 16 ++++++++-------- packages/wb/src/commands/start.ts | 2 +- .../scripts/execution/baseExecutionScripts.ts | 2 +- .../src/scripts/execution/httpServerScripts.ts | 2 +- .../wb/src/scripts/execution/plainAppScripts.ts | 2 +- 13 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 packages/shared-lib-node/test-fixtures/app1/.env rename packages/shared-lib-node/test-fixtures/{app => app1}/.env.development (100%) rename packages/shared-lib-node/test-fixtures/{app => app1}/.env.production (100%) rename packages/shared-lib-node/test-fixtures/{app => app1}/.env.test (100%) create mode 100644 packages/shared-lib-node/test-fixtures/app2/.env rename packages/shared-lib-node/test-fixtures/{another-app => app2}/.env.development (100%) rename packages/shared-lib-node/test-fixtures/{another-app => app2}/.env.production (100%) rename packages/shared-lib-node/test-fixtures/{another-app => app2}/.env.test (100%) diff --git a/packages/shared-lib-node/test-fixtures/app1/.env b/packages/shared-lib-node/test-fixtures/app1/.env new file mode 100644 index 00000000..b9759296 --- /dev/null +++ b/packages/shared-lib-node/test-fixtures/app1/.env @@ -0,0 +1 @@ +NAME=app1 diff --git a/packages/shared-lib-node/test-fixtures/app/.env.development b/packages/shared-lib-node/test-fixtures/app1/.env.development similarity index 100% rename from packages/shared-lib-node/test-fixtures/app/.env.development rename to packages/shared-lib-node/test-fixtures/app1/.env.development diff --git a/packages/shared-lib-node/test-fixtures/app/.env.production b/packages/shared-lib-node/test-fixtures/app1/.env.production similarity index 100% rename from packages/shared-lib-node/test-fixtures/app/.env.production rename to packages/shared-lib-node/test-fixtures/app1/.env.production diff --git a/packages/shared-lib-node/test-fixtures/app/.env.test b/packages/shared-lib-node/test-fixtures/app1/.env.test similarity index 100% rename from packages/shared-lib-node/test-fixtures/app/.env.test rename to packages/shared-lib-node/test-fixtures/app1/.env.test diff --git a/packages/shared-lib-node/test-fixtures/app2/.env b/packages/shared-lib-node/test-fixtures/app2/.env new file mode 100644 index 00000000..59707862 --- /dev/null +++ b/packages/shared-lib-node/test-fixtures/app2/.env @@ -0,0 +1 @@ +NAME=app2 diff --git a/packages/shared-lib-node/test-fixtures/another-app/.env.development b/packages/shared-lib-node/test-fixtures/app2/.env.development similarity index 100% rename from packages/shared-lib-node/test-fixtures/another-app/.env.development rename to packages/shared-lib-node/test-fixtures/app2/.env.development diff --git a/packages/shared-lib-node/test-fixtures/another-app/.env.production b/packages/shared-lib-node/test-fixtures/app2/.env.production similarity index 100% rename from packages/shared-lib-node/test-fixtures/another-app/.env.production rename to packages/shared-lib-node/test-fixtures/app2/.env.production diff --git a/packages/shared-lib-node/test-fixtures/another-app/.env.test b/packages/shared-lib-node/test-fixtures/app2/.env.test similarity index 100% rename from packages/shared-lib-node/test-fixtures/another-app/.env.test rename to packages/shared-lib-node/test-fixtures/app2/.env.test diff --git a/packages/shared-lib-node/tests/env.test.ts b/packages/shared-lib-node/tests/env.test.ts index 138751ae..d0c98f7d 100644 --- a/packages/shared-lib-node/tests/env.test.ts +++ b/packages/shared-lib-node/tests/env.test.ts @@ -9,39 +9,39 @@ describe('loadEnvironmentVariables()', () => { }); it('should load no env vars with empty options', () => { - const envVars = loadEnvironmentVariables({}, 'test-fixtures/app'); + const envVars = loadEnvironmentVariables({}, 'test-fixtures/app1'); expect(envVars).toEqual({}); }); it('should load env vars with --auto-cascade-env', () => { - const envVars = loadEnvironmentVariables({ autoCascadeEnv: true }, 'test-fixtures/app'); + const envVars = loadEnvironmentVariables({ autoCascadeEnv: true }, 'test-fixtures/app1'); expect(envVars).toEqual({ NAME: 'app1', ENV: 'development1' }); }); it('should load env vars with --cascade-env=production', () => { - const envVars = loadEnvironmentVariables({ cascadeEnv: 'production', env: ['.env'] }, 'test-fixtures/app'); + const envVars = loadEnvironmentVariables({ cascadeEnv: 'production', env: ['.env'] }, 'test-fixtures/app1'); expect(envVars).toEqual({ NAME: 'app1', ENV: 'production1' }); }); it('should load env vars with --cascade-node-env and NODE_ENV=""', () => { process.env.NODE_ENV = ''; - const envVars = loadEnvironmentVariables({ cascadeNodeEnv: true, env: ['.env'] }, 'test-fixtures/app'); + const envVars = loadEnvironmentVariables({ cascadeNodeEnv: true, env: ['.env'] }, 'test-fixtures/app1'); expect(envVars).toEqual({ NAME: 'app1', ENV: 'development1' }); }); it('should load env vars with --cascade-node-env and NODE_ENV=test', () => { process.env.NODE_ENV = 'test'; - const envVars = loadEnvironmentVariables({ cascadeNodeEnv: true, env: ['.env'] }, 'test-fixtures/app'); + const envVars = loadEnvironmentVariables({ cascadeNodeEnv: true, env: ['.env'] }, 'test-fixtures/app1'); expect(envVars).toEqual({ NAME: 'app1', ENV: 'test1' }); }); - it('should load env vars with --env=test-fixtures/another-app/.env --auto-cascade-env, WB_ENV=test and NODE_ENV=production', () => { + it('should load env vars with --env=test-fixtures/app2/.env --auto-cascade-env, WB_ENV=test and NODE_ENV=production', () => { process.env.WB_ENV = 'test'; process.env.NODE_ENV = 'production'; const envVars = loadEnvironmentVariables( { autoCascadeEnv: true, env: ['.env'] }, - 'test-fixtures/app', - 'test-fixtures/another-app' + 'test-fixtures/app1', + 'test-fixtures/app2' ); expect(envVars).toEqual({ NAME: 'app2', ENV: 'test2' }); }); diff --git a/packages/wb/src/commands/start.ts b/packages/wb/src/commands/start.ts index 5bb953cd..2b3ca77b 100644 --- a/packages/wb/src/commands/start.ts +++ b/packages/wb/src/commands/start.ts @@ -22,7 +22,7 @@ const builder = { export const startCommand: CommandModule> = { command: 'start [args..]', - describe: 'Start app', + describe: 'Start app1', builder, async handler(argv) { normalizeArgs(argv); diff --git a/packages/wb/src/scripts/execution/baseExecutionScripts.ts b/packages/wb/src/scripts/execution/baseExecutionScripts.ts index cea5f785..4a2c5587 100644 --- a/packages/wb/src/scripts/execution/baseExecutionScripts.ts +++ b/packages/wb/src/scripts/execution/baseExecutionScripts.ts @@ -12,7 +12,7 @@ export interface TestE2EOptions extends TestE2EDevOptions { } /** - * A collection of scripts for executing an app. + * A collection of scripts for executing an app1. * Note that YARN zzz` is replaced with `yarn zzz` or `node_modules/.bin/zzz`. */ export abstract class BaseExecutionScripts { diff --git a/packages/wb/src/scripts/execution/httpServerScripts.ts b/packages/wb/src/scripts/execution/httpServerScripts.ts index a5817cae..2806a684 100644 --- a/packages/wb/src/scripts/execution/httpServerScripts.ts +++ b/packages/wb/src/scripts/execution/httpServerScripts.ts @@ -6,7 +6,7 @@ import type { TestE2EDevOptions, TestE2EOptions } from './baseExecutionScripts.j import { BaseExecutionScripts } from './baseExecutionScripts.js'; /** - * A collection of scripts for executing an app that utilizes an HTTP server like express. + * A collection of scripts for executing an app1 that utilizes an HTTP server like express. * Note that `YARN zzz` is replaced with `yarn zzz` or `node_modules/.bin/zzz`. */ class HttpServerScripts extends BaseExecutionScripts { diff --git a/packages/wb/src/scripts/execution/plainAppScripts.ts b/packages/wb/src/scripts/execution/plainAppScripts.ts index d481f7e8..be3f9e42 100644 --- a/packages/wb/src/scripts/execution/plainAppScripts.ts +++ b/packages/wb/src/scripts/execution/plainAppScripts.ts @@ -5,7 +5,7 @@ import { dockerScripts } from '../dockerScripts.js'; import { BaseExecutionScripts } from './baseExecutionScripts.js'; /** - * A collection of scripts for executing an app that utilizes an HTTP server like express. + * A collection of scripts for executing an app1 that utilizes an HTTP server like express. * Note that `YARN zzz` is replaced with `yarn zzz` or `node_modules/.bin/zzz`. */ class PlainAppScripts extends BaseExecutionScripts { From 54f3a9b6c65bed93380f0882314203d073d463a6 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Sat, 30 Sep 2023 11:17:43 +0900 Subject: [PATCH 5/5] . --- packages/wb/src/commands/start.ts | 2 +- packages/wb/src/scripts/execution/baseExecutionScripts.ts | 2 +- packages/wb/src/scripts/execution/httpServerScripts.ts | 2 +- packages/wb/src/scripts/execution/plainAppScripts.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/wb/src/commands/start.ts b/packages/wb/src/commands/start.ts index 2b3ca77b..5bb953cd 100644 --- a/packages/wb/src/commands/start.ts +++ b/packages/wb/src/commands/start.ts @@ -22,7 +22,7 @@ const builder = { export const startCommand: CommandModule> = { command: 'start [args..]', - describe: 'Start app1', + describe: 'Start app', builder, async handler(argv) { normalizeArgs(argv); diff --git a/packages/wb/src/scripts/execution/baseExecutionScripts.ts b/packages/wb/src/scripts/execution/baseExecutionScripts.ts index 4a2c5587..cea5f785 100644 --- a/packages/wb/src/scripts/execution/baseExecutionScripts.ts +++ b/packages/wb/src/scripts/execution/baseExecutionScripts.ts @@ -12,7 +12,7 @@ export interface TestE2EOptions extends TestE2EDevOptions { } /** - * A collection of scripts for executing an app1. + * A collection of scripts for executing an app. * Note that YARN zzz` is replaced with `yarn zzz` or `node_modules/.bin/zzz`. */ export abstract class BaseExecutionScripts { diff --git a/packages/wb/src/scripts/execution/httpServerScripts.ts b/packages/wb/src/scripts/execution/httpServerScripts.ts index 2806a684..a5817cae 100644 --- a/packages/wb/src/scripts/execution/httpServerScripts.ts +++ b/packages/wb/src/scripts/execution/httpServerScripts.ts @@ -6,7 +6,7 @@ import type { TestE2EDevOptions, TestE2EOptions } from './baseExecutionScripts.j import { BaseExecutionScripts } from './baseExecutionScripts.js'; /** - * A collection of scripts for executing an app1 that utilizes an HTTP server like express. + * A collection of scripts for executing an app that utilizes an HTTP server like express. * Note that `YARN zzz` is replaced with `yarn zzz` or `node_modules/.bin/zzz`. */ class HttpServerScripts extends BaseExecutionScripts { diff --git a/packages/wb/src/scripts/execution/plainAppScripts.ts b/packages/wb/src/scripts/execution/plainAppScripts.ts index be3f9e42..d481f7e8 100644 --- a/packages/wb/src/scripts/execution/plainAppScripts.ts +++ b/packages/wb/src/scripts/execution/plainAppScripts.ts @@ -5,7 +5,7 @@ import { dockerScripts } from '../dockerScripts.js'; import { BaseExecutionScripts } from './baseExecutionScripts.js'; /** - * A collection of scripts for executing an app1 that utilizes an HTTP server like express. + * A collection of scripts for executing an app that utilizes an HTTP server like express. * Note that `YARN zzz` is replaced with `yarn zzz` or `node_modules/.bin/zzz`. */ class PlainAppScripts extends BaseExecutionScripts {